lkml.org 
[lkml]   [2023]   [Aug]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 3/5] selftests/sgx: Ensure correct secinfo struct alignment in test enclave.
From
On 03.08.23 06:00, Huang, Kai wrote:> We already have __aligned.  Can 
you provide more information in what
> circumstances that __aligned isn't enough to guarantee the alignment?
>
> We have a lot of kernel code which has __aligned but doesn't have volatile.

Thank you. I also dug deeper into this and the proper fix is indeed not
to make the variable volatile.

The real problem is that the inline assembly does not have the "memory"
clobber to tell the compiler that the "assembly code performs memory
reads or writes to items other than those listed in the input and output
operands (for example, accessing the memory pointed to by one of the
input parameters)" [1].

I checked that, depending on the optimizations and compiler (gcc vs
clang), the compiler may indeed reorder the write to secinfo.flags to
_after_ the inline asm block. Declaring secinfo as volatile fixed that,
but the proper fix is of course to properly include a "memory" clobber
for the asm block.

I'll include a fix to include a "memory" clobber for the inline asm
block in the next patch revision.

[1]
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1

\
 
 \ /
  Last update: 2023-08-07 11:22    [W:0.080 / U:23.412 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site