[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2] x86/atomic: Improvements and simplifications to assembly constraints


  • To: Jan Beulich <JBeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Mon, 18 Mar 2019 14:11:06 +0000
  • Autocrypt: addr=andrew.cooper3@xxxxxxxxxx; prefer-encrypt=mutual; keydata= mQINBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6/FOdEx4B8cMJt+cWwARAQABtClBbmRyZXcgQ29v cGVyIDxhbmRyZXcuY29vcGVyM0BjaXRyaXguY29tPokCOgQTAQgAJAIbAwULCQgHAwUVCgkI CwUWAgMBAAIeAQIXgAUCWKD95wIZAQAKCRBlw/kGpdefoHbdD/9AIoR3k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gooi+MG9SoZeV/arejDUrR6eFjEhnC//qxUIbjD7IVemBv Q4K0PFCjm4p0XjKDW2tqzkXG1N0h8dXw3D7/hs638RFbdvLCMNNizI2874/pYVHaQo1JXa4/ X8esVk+b1ATLBV3kGcSuaUm+iSZNLhXmaeXJrurMdnXvjV4HZHkhwmHPJ3k3dsV/fNFfb2/o jYs1hBrMM2+wrNBFgKE878wBR29UlbhdFVp09y4DJ0EIkLPOe9Sy9LmgDa9HX3ehcUJgiIz5 ypFJB6dEootaSSV8OYRP6ZvohKIzEI7ooDE1p9ZVErfv3j1C9fGbqhtyTNXG3tzT/nNmIXRI X3pEax10xF4Jm9pKlOm8l3YkfPP5v0/2hDOf8gNcfjldCGoDejdTL4RyEyq4pIlKmn7ezi0Z yBjFwysllgTYKe0w6kUfoEgD7YlLSoV72C6M8SGmx8ULpZyf+qZxpiSCbH4btaxh14byRR4o zyOWoJv72b6zHbFukZnJ39O1/mEYaXoK4wvR9+vZrl/oncdDWEfY5rRgCZRKKHKyRqp40ZQv WPcrLO2s49R2zbmQidzHWjnQoQvuMgCFpWcGSGC5PpdpYpIUgy6Hg7S+cKO7nUi7ROuNGetm OiPIIoyJkKzgW3MYIgC0pCbqDSxqOK0KrdWsX8GEE6GNQs9eYJk4mE+mjyPfdZ/VTnGZ1nMA wZFivf9SJLevPoJK/7vvNYQY0Moce4JkiTYt4IaYu7A1SmUvZtOElBA1ON+GSENYek7TTsUb AEb919v7d+dHcNowOfB/tuxYZX98EQzzKCxvGS/ioAoaBN7PRhXLqjYUJOC3PIHo2i0rHaB0 SgHPnPc6e1hMy70RlSMSY=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Openpgp: preference=signencrypt

On 18/03/2019 13:20, Jan Beulich wrote:
>  >>> On 18.03.19 at 12:27, <andrew.cooper3@xxxxxxxxxx> wrote:
>> * Some of the single-byte versions specify "=q" as the output.  This is a
>>    remnent of the 32bit build and can be relaxed to "=r" in 64bit builds.
> I have to admit that I don't understand the "relaxed" part of this:
> "q" and "r" represent the exact same set of registers on 64-bit.
> Unless the conversion allows further code folding, I think it wouldn't
> be a bad idea to retain the distinction, just for cases like code
> eventually getting shared via something like lib/x86/.

The change from =q to =r is specifically to allow the folding to +r

>
>> The reason the volatile cast in __cmpxchg_user() can't be dropped is because
>> without it, the compiler uses a stack copy rather than the in-memory copy,
>> which ends up tripping:
>>
>>   /* Allowed to change in Accessed/Dirty flags only. */
>>   BUG_ON((t ^ old) & ~(intpte_t)(_PAGE_ACCESSED|_PAGE_DIRTY));
> Isn't this hinting at some other shortcoming or even flaw then?
> If the compiler generally did such transformations, I'm afraid a
> lot of other code would be at risk too, including some of what
> you modify here.

I don't think there is any flaw or shortcoming.  Without the volatile,
the compiler doesn't know that there are any side effects, so can
legitimately operate on a local stack copy so long as it copies things
back later.

In practice, this is an operation on shared memory which has to happen
on the shared memory pointer.

> In any event I think it would be a good idea to have a code
> comment for this as well.

I don't see how that would help.  The same applies to all atomic
operations, even test_bit().

>
>> @@ -40,28 +37,24 @@ static always_inline unsigned long __xchg(
>>      switch ( size )
>>      {
>>      case 1:
>> -        asm volatile ( "xchgb %b0,%1"
>> -                       : "=q" (x)
>> -                       : "m" (*__xg(ptr)), "0" (x)
>> -                       : "memory" );
>> +        asm volatile ( "xchg %b[x], %[ptr]"
>> +                       : [x] "+r" (x), [ptr] "+m" (*(uint8_t *)ptr)
>> +                       :: "memory" );
>>          break;
>>      case 2:
>> -        asm volatile ( "xchgw %w0,%1"
>> -                       : "=r" (x)
>> -                       : "m" (*__xg(ptr)), "0" (x)
>> -                       : "memory" );
>> +        asm volatile ( "xchg %w[x], %[ptr]"
>> +                       : [x] "+r" (x), [ptr] "+m" (*(uint16_t *)ptr)
>> +                       :: "memory" );
>>          break;
>>      case 4:
>> -        asm volatile ( "xchgl %k0,%1"
>> -                       : "=r" (x)
>> -                       : "m" (*__xg(ptr)), "0" (x)
>> -                       : "memory" );
>> +        asm volatile ( "xchg %k[x], %[ptr]"
>> +                       : [x] "+r" (x), [ptr] "+m" (*(uint32_t *)ptr)
>> +                       :: "memory" );
>>          break;
>>      case 8:
>> -        asm volatile ( "xchgq %0,%1"
>> -                       : "=r" (x)
>> -                       : "m" (*__xg(ptr)), "0" (x)
>> -                       : "memory" );
>> +        asm volatile ( "xchg %q[x], %[ptr]"
>> +                       : [x] "+r" (x), [ptr] "+m" (*(uint64_t *)ptr)
>> +                       :: "memory" );
>>          break;
> Is the q modifier really useful to have here (and elsewhere below)?

Yes - it is strictly necessary, because otherwise it gets derived from
the type of (x) which is unsigned long even in the smaller size constructs.

>
>> @@ -63,36 +65,38 @@ static always_inline __uint128_t cmpxchg16b_local_(
>>   * If no fault occurs then _o is updated to the value we saw at _p. If this
>>   * is the same as the initial value of _o then _n is written to location _p.
>>   */
>> -#define __cmpxchg_user(_p,_o,_n,_isuff,_oppre,_regtype)                 \
>> +#define __cmpxchg_user(_p, _o, _n, _oppre)                              \
>>      stac();                                                             \
>>      asm volatile (                                                      \
>> -        "1: lock; cmpxchg"_isuff" %"_oppre"2,%3\n"                      \
>> +        "1: lock cmpxchg %"_oppre"[new], %[ptr]\n"                      \
>>          "2:\n"                                                          \
>>          ".section .fixup,\"ax\"\n"                                      \
>> -        "3:     movl $1,%1\n"                                           \
>> +        "3:     movl $1, %[rc]\n"                                       \
>>          "       jmp 2b\n"                                               \
>>          ".previous\n"                                                   \
>>          _ASM_EXTABLE(1b, 3b)                                            \
>> -        : "=a" (_o), "=r" (_rc)                                         \
>> -        : _regtype (_n), "m" (*__xg((volatile void *)_p)), "0" (_o), "1" 
>> (0) \
>> +        : "+a" (_o), [rc] "=r" (_rc),                                   \
>> +          [ptr] "+m" (*(volatile typeof(*(_p)) *)(_p))                  \
>> +        : [new] "r" (_n), "[rc]" (0)                                    \
> Wouldn't it further help readability a little if _rc was initialized to zero
> right when getting declared, eliminating the last input arg here (the
> output then would need to be "+r" of course)?

I can do.

> And since then you
> actually touch all lines containing uses of _rc, it would be a good
> opportunity to also rename the variable to get rid of the leading
> underscore.

I'm not sure that is a sensible move.  Its a macro-scope variable from
cmpxchg_user() which still needs disambiguating from potential names of
parameters.

>
> Anyway, with at least the "relaxed" part of the description changed
> (e.g. to "converted") or explained verbally in a reply, with or without
> the other items taken care of
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Hopefully my reply is sufficient?

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.