Re: [PATCH v4 1/2] x86/delay: Fix the wrong asm constraint in `delay_loop()`

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

 



On 3/1/22 6:33 PM, Alviro Iskandar Setiawan wrote:
hi sir, it might also be interesting to know that even if it never be
inlined, it's still potential to break.

for example this code (https://godbolt.org/z/xWMTxhTET)

   __attribute__((__noinline__)) static void x(int a)
   {
       asm("xorl\t%%r8d, %%r8d"::"a"(a));
   }

   extern int p(void);

   int f(void)
   {
       int ret = p();
       x(ret);
       return ret;
   }

translates to this asm

   x:
           movl    %edi, %eax
           xorl    %r8d, %r8d
           ret
   f:
           subq    $8, %rsp
           call    p
           movl    %eax, %r8d
           movl    %eax, %edi
           call    x
           movl    %r8d, %eax
           addq    $8, %rsp
           ret

See the %r8d? It should be clobbered by a function call too. But since
no one tells the compiler that we clobber %r8d, it assumes %r8d never
changes after that call. The compiler thinks x() is static and will
not clobber %r8d, even the ABI says %r8d will be clobbered by a
function call. So i think it should be backported to the stable
kernel, it's still a fix

Thanks. I will add CC stable in the v5.

--
Ammar Faizi



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux