linux-mips
[Top] [All Lists]

Re: [PATCH v2 09/13] MIPS: Add functions for hypervisor call

To: "Daney, David" <David.Daney@caviumnetworks.com>
Subject: Re: [PATCH v2 09/13] MIPS: Add functions for hypervisor call
From: "Pinski, Andrew" <Andrew.Pinski@caviumnetworks.com>
Date: Tue, 3 Jun 2014 16:45:00 +0000
Accept-language: en-US
Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Andrew.Pinski@caviumnetworks.com;
Cc: "Herrmann, Andreas" <Andreas.Herrmann@caviumnetworks.com>, Ralf Baechle <ralf@linux-mips.org>, "Pinski, Andrew" <Andrew.Pinski@caviumnetworks.com>, "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>, David Daney <ddaney.cavm@gmail.com>, James Hogan <james.hogan@imgtec.com>, "kvm@vger.kernel.org" <kvm@vger.kernel.org>, David Daney <david.daney@cavium.com>
In-reply-to: <538DFA61.4080100@caviumnetworks.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1401313936-11867-1-git-send-email-andreas.herrmann@caviumnetworks.com> <1401313936-11867-10-git-send-email-andreas.herrmann@caviumnetworks.com> <20140603083031.GP17197@linux-mips.org> <20140603150337.GA28045@alberich>,<538DFA61.4080100@caviumnetworks.com>
Sender: linux-mips-bounce@linux-mips.org
Thread-index: AQHPf0p6gDdohutE1E+d1JaWoWdLs5tfl72X
Thread-topic: [PATCH v2 09/13] MIPS: Add functions for hypervisor call

> On Jun 3, 2014, at 9:40 AM, "Daney, David" <David.Daney@caviumnetworks.com> 
> wrote:
> 
> In cases like this, I always wonder WWPD (What Would Pinski Do)...
> 
> Let's get him to opine.
> 
> Andrew, the patch in question is:
> 
> http://www.linux-mips.org/archives/linux-mips/2014-05/msg00309.html


Yes having two variables with the same register is safe as long as the only 
time the live ranges of them overlap is the inline-asm where they are used. 

Thanks,
Andrew

> 
> Thanks,
> David Daney
> 
>> On 06/03/2014 08:03 AM, Andreas Herrmann wrote:
>>> On Tue, Jun 03, 2014 at 10:30:31AM +0200, Ralf Baechle wrote:
>>>> On Wed, May 28, 2014 at 11:52:12PM +0200, Andreas Herrmann wrote:
>>>> 
>>>> +/*
>>>> + * Hypercalls for KVM.
>>>> + *
>>>> + * Hypercall number is passed in v0.
>>>> + * Return value will be placed in v0.
>>>> + * Up to 3 arguments are passed in a0, a1, and a2.
>>>> + */
>>>> +static inline unsigned long kvm_hypercall0(unsigned long num)
>>>> +{
>>>> +    register unsigned long n asm("v0");
>>>> +    register unsigned long r asm("v0");
>>> 
>>> Btw, is it safe to put two variables in the same register?
>> 
>> I think it's safe.
>> 
>> If we would have a matching constraint letter (say "v" for register v0) the
>> asm should translate to
>> 
>>         __asm__ __volatile__(
>>           KVM_HYPERCALL
>>                 : "=v" (n) : "v" (r) : "memory"
>>                 );
>> 
>> which isn't unusual on other archs. (Or maybe I am just biased from
>> x86 ... or missed something else.)
>> 
>>> The syscall wrappers that used to be in <asm/unistd.h> were occasionally
>>> hitting problems which eventually forced me to stop forcing variables
>>> into particular registers instead using a MOVE instruction to shove
>>> each variable into the right place.
>>> 
>>> Of course they were being used from non-PIC and PIC code, kernel and 
>>> userland
>>> so GCC had a much better chance to do evil than in the hypercall wrapper
>>> case - but it made me paranoid ...
>> 
>> 
>> 
>> Andreas
>> 

<Prev in Thread] Current Thread [Next in Thread>