<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/tools/testing/selftests/sgx, branch v6.12.80</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.12.80</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.12.80'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2024-07-10T19:14:51+00:00</updated>
<entry>
<title>selftests: centralize -D_GNU_SOURCE= to CFLAGS in lib.mk</title>
<updated>2024-07-10T19:14:51+00:00</updated>
<author>
<name>Edward Liaw</name>
<email>edliaw@google.com</email>
</author>
<published>2024-06-25T22:34:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=cc937dad85aea4ab9e4f9827d7ea55932c86906b'/>
<id>urn:sha1:cc937dad85aea4ab9e4f9827d7ea55932c86906b</id>
<content type='text'>
Centralize the _GNU_SOURCE definition to CFLAGS in lib.mk.  Remove
redundant defines from Makefiles that import lib.mk.  Convert any usage of
"#define _GNU_SOURCE 1" to "#define _GNU_SOURCE".

This uses the form "-D_GNU_SOURCE=", which is equivalent to
"#define _GNU_SOURCE".

Otherwise using "-D_GNU_SOURCE" is equivalent to "-D_GNU_SOURCE=1" and
"#define _GNU_SOURCE 1", which is less commonly seen in source code and
would require many changes in selftests to avoid redefinition warnings.

Link: https://lkml.kernel.org/r/20240625223454.1586259-2-edliaw@google.com
Signed-off-by: Edward Liaw &lt;edliaw@google.com&gt;
Suggested-by: John Hubbard &lt;jhubbard@nvidia.com&gt;
Acked-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Reviewed-by: Muhammad Usama Anjum &lt;usama.anjum@collabora.com&gt;
Cc: Albert Ou &lt;aou@eecs.berkeley.edu&gt;
Cc: André Almeida &lt;andrealmeid@igalia.com&gt;
Cc: Darren Hart &lt;dvhart@infradead.org&gt;
Cc: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Cc: Davidlohr Bueso &lt;dave@stgolabs.net&gt;
Cc: David S. Miller &lt;davem@davemloft.net&gt;
Cc: Eric Dumazet &lt;edumazet@google.com&gt;
Cc: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Cc: Fenghua Yu &lt;fenghua.yu@intel.com&gt;
Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Cc: Jakub Kicinski &lt;kuba@kernel.org&gt;
Cc: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Cc: Jason Gunthorpe &lt;jgg@ziepe.ca&gt;
Cc: Kees Cook &lt;kees@kernel.org&gt;
Cc: Kevin Tian &lt;kevin.tian@intel.com&gt;
Cc: Palmer Dabbelt &lt;palmer@dabbelt.com&gt;
Cc: Paolo Abeni &lt;pabeni@redhat.com&gt;
Cc: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Cc: Paul Walmsley &lt;paul.walmsley@sifive.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Reinette Chatre &lt;reinette.chatre@intel.com&gt;
Cc: Sean Christopherson &lt;seanjc@google.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>Revert "selftests/sgx: Include KHDR_INCLUDES in Makefile"</title>
<updated>2024-05-20T15:00:06+00:00</updated>
<author>
<name>Shuah Khan</name>
<email>skhan@linuxfoundation.org</email>
</author>
<published>2024-05-17T02:58:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3da164023582969280df17636a9d829752787b1c'/>
<id>urn:sha1:3da164023582969280df17636a9d829752787b1c</id>
<content type='text'>
This reverts commit 2c3b8f8f37c6c0c926d584cf4158db95e62b960c.

The framework change to add D_GNU_SOURCE to KHDR_INCLUDES
to Makefile, lib.mk, and kselftest_harness.h is reverted
as it is causing build failures and warnings.

Revert this change as this change depends on the framework
change.

Reported-by: Mark Brown &lt;broonie@kernel.org&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>selftests/sgx: Include KHDR_INCLUDES in Makefile</title>
<updated>2024-05-08T23:08:46+00:00</updated>
<author>
<name>Edward Liaw</name>
<email>edliaw@google.com</email>
</author>
<published>2024-05-07T21:38:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2c3b8f8f37c6c0c926d584cf4158db95e62b960c'/>
<id>urn:sha1:2c3b8f8f37c6c0c926d584cf4158db95e62b960c</id>
<content type='text'>
Add KHDR_INCLUDES to the CFLAGS to pull in the kselftest harness
dependencies (-D_GNU_SOURCE).

Also, remove redefinitions of _GNU_SOURCE in the source code.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Reported-by: kernel test robot &lt;oliver.sang@intel.com&gt;
Closes: https://lore.kernel.org/oe-lkp/202404301040.3bea5782-oliver.sang@intel.com
Signed-off-by: Edward Liaw &lt;edliaw@google.com&gt;
Reviewed-by: Muhammad Usama Anjum &lt;usama.anjum@collabora.com&gt;
Acked-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Tested-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Reviewed-by: John Hubbard &lt;jhubbard@nvidia.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>selftests/sgx: Skip non X86_64 platform</title>
<updated>2023-12-08T18:08:17+00:00</updated>
<author>
<name>Zhao Mengmeng</name>
<email>zhaomengmeng@kylinos.cn</email>
</author>
<published>2023-12-06T02:56:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=981cf568a8644161c2f15c02278ebc2834b51ba6'/>
<id>urn:sha1:981cf568a8644161c2f15c02278ebc2834b51ba6</id>
<content type='text'>
When building whole selftests on arm64, rsync gives an erorr about sgx:

rsync: [sender] link_stat "/root/linux-next/tools/testing/selftests/sgx/test_encl.elf" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1327) [sender=3.2.5]

The root casue is sgx only used on X86_64, and shall be skipped on other
platforms.

Fix this by moving TEST_CUSTOM_PROGS and TEST_FILES inside the if check,
then the build result will be "Skipping non-existent dir: sgx".

Fixes: 2adcba79e69d ("selftests/x86: Add a selftest for SGX")
Signed-off-by: Zhao Mengmeng &lt;zhaomengmeng@kylinos.cn&gt;
Signed-off-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Link: https://lore.kernel.org/all/20231206025605.3965302-1-zhaomzhao%40126.com
</content>
</entry>
<entry>
<title>selftests/sgx: Remove incomplete ABI sanitization code in test enclave</title>
<updated>2023-12-08T18:05:28+00:00</updated>
<author>
<name>Jo Van Bulck</name>
<email>jo.vanbulck@cs.kuleuven.be</email>
</author>
<published>2023-10-05T15:38:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=886c5be0b12e89b2905c26c4f24d50ae91f261da'/>
<id>urn:sha1:886c5be0b12e89b2905c26c4f24d50ae91f261da</id>
<content type='text'>
As the selftest enclave is *not* intended for production, simplify the
code by not initializing CPU configuration registers as expected by the
ABI on enclave entry or cleansing caller-save registers on enclave exit.

Signed-off-by: Jo Van Bulck &lt;jo.vanbulck@cs.kuleuven.be&gt;
Signed-off-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Link: https://lore.kernel.org/all/da0cfb1e-e347-f7f2-ac72-aec0ee0d867d@intel.com/
Link: https://lore.kernel.org/all/20231005153854.25566-14-jo.vanbulck%40cs.kuleuven.be
</content>
</entry>
<entry>
<title>selftests/sgx: Discard unsupported ELF sections</title>
<updated>2023-12-08T18:05:28+00:00</updated>
<author>
<name>Jo Van Bulck</name>
<email>jo.vanbulck@cs.kuleuven.be</email>
</author>
<published>2023-10-05T15:38:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ec44ca1e34bc3a9864a8c1bf8636066ec6d5d2e5'/>
<id>urn:sha1:ec44ca1e34bc3a9864a8c1bf8636066ec6d5d2e5</id>
<content type='text'>
Building the test enclave with -static-pie may produce a dynamic symbol
table, but this is not supported for enclaves and any relocations need to
happen manually (e.g., as for "encl_op_array"). Thus, opportunistically
discard ".dyn*" and ".gnu.hash" which the enclave loader cannot handle.

Signed-off-by: Jo Van Bulck &lt;jo.vanbulck@cs.kuleuven.be&gt;
Signed-off-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Link: https://lore.kernel.org/all/20231005153854.25566-13-jo.vanbulck%40cs.kuleuven.be
</content>
</entry>
<entry>
<title>selftests/sgx: Ensure expected location of test enclave buffer</title>
<updated>2023-12-08T18:05:27+00:00</updated>
<author>
<name>Jo Van Bulck</name>
<email>jo.vanbulck@cs.kuleuven.be</email>
</author>
<published>2023-10-05T15:38:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=022416496008bd51cb7b33975cc0008749329a86'/>
<id>urn:sha1:022416496008bd51cb7b33975cc0008749329a86</id>
<content type='text'>
The external tests manipulating page permissions expect encl_buffer to be
placed at the start of the test enclave's .data section. As this is not
guaranteed per the C standard, explicitly place encl_buffer in a separate
section that is explicitly placed at the start of the .data segment in the
linker script to avoid the compiler placing it somewhere else in .data.

Signed-off-by: Jo Van Bulck &lt;jo.vanbulck@cs.kuleuven.be&gt;
Signed-off-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Acked-by: Kai Huang &lt;kai.huang@intel.com&gt;
Link: https://lore.kernel.org/all/20231005153854.25566-12-jo.vanbulck%40cs.kuleuven.be
</content>
</entry>
<entry>
<title>selftests/sgx: Ensure test enclave buffer is entirely preserved</title>
<updated>2023-12-08T18:05:27+00:00</updated>
<author>
<name>Jo Van Bulck</name>
<email>jo.vanbulck@cs.kuleuven.be</email>
</author>
<published>2023-10-05T15:38:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a4c39ef4ed43103caef80029cd30427a9ff342d8'/>
<id>urn:sha1:a4c39ef4ed43103caef80029cd30427a9ff342d8</id>
<content type='text'>
Attach the "used" attribute to instruct the compiler to preserve the static
encl_buffer, even if it appears it is not entirely referenced in the enclave
code, as expected by the external tests manipulating page permissions.

Signed-off-by: Jo Van Bulck &lt;jo.vanbulck@cs.kuleuven.be&gt;
Signed-off-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Acked-by: Kai Huang &lt;kai.huang@intel.com&gt;
Link: https://lore.kernel.org/all/a2732938-f3db-a0af-3d68-a18060f66e79@cs.kuleuven.be/
Link: https://lore.kernel.org/all/20231005153854.25566-11-jo.vanbulck%40cs.kuleuven.be
</content>
</entry>
<entry>
<title>selftests/sgx: Fix linker script asserts</title>
<updated>2023-12-08T18:05:27+00:00</updated>
<author>
<name>Jo Van Bulck</name>
<email>jo.vanbulck@cs.kuleuven.be</email>
</author>
<published>2023-10-05T15:38:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=9fd552ee32c6c1e27c125016b87d295bea6faea7'/>
<id>urn:sha1:9fd552ee32c6c1e27c125016b87d295bea6faea7</id>
<content type='text'>
DEFINED only considers symbols, not section names. Hence, replace the
check for .got.plt with the _GLOBAL_OFFSET_TABLE_ symbol and remove other
(non-essential) asserts.

Signed-off-by: Jo Van Bulck &lt;jo.vanbulck@cs.kuleuven.be&gt;
Signed-off-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Link: https://lore.kernel.org/all/20231005153854.25566-10-jo.vanbulck%40cs.kuleuven.be
</content>
</entry>
<entry>
<title>selftests/sgx: Handle relocations in test enclave</title>
<updated>2023-12-08T18:05:27+00:00</updated>
<author>
<name>Jo Van Bulck</name>
<email>jo.vanbulck@cs.kuleuven.be</email>
</author>
<published>2023-10-05T15:38:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d06978e8e47a348c0d33462a8c2bf8f46d2b7df5'/>
<id>urn:sha1:d06978e8e47a348c0d33462a8c2bf8f46d2b7df5</id>
<content type='text'>
Static-pie binaries normally include a startup routine to perform any ELF
relocations from .rela.dyn. Since the enclave loading process is different
and glibc is not included, do the necessary relocation for encl_op_array
entries manually at runtime relative to the enclave base to ensure correct
function pointers.

When keeping encl_op_array as a local variable on the stack, gcc without
optimizations generates code that explicitly gets the right function
addresses and stores them to create the array on the stack:

encl_body:
    /* snipped */
    lea    do_encl_op_put_to_buf(%rip), %rax
    mov    %rax, -0x50(%rbp)
    lea    do_encl_op_get_from_buf(%rip), %rax
    mov    %rax,-0x48(%rbp)
    lea    do_encl_op_put_to_addr(%rip), %rax
    /* snipped */

However, gcc -Os or clang generate more efficient code that initializes
encl_op_array by copying a "prepared copy" containing the absolute
addresses of the functions (i.e., relative to the image base starting from
0) generated by the compiler/linker:

encl_body:
    /* snipped */
    lea    prepared_copy(%rip), %rsi
    lea    -0x48(%rsp), %rdi
    mov    $0x10,%ecx
    rep movsl %ds:(%rsi),%es:(%rdi)
    /* snipped */

When building the enclave with -static-pie, the compiler/linker includes
relocation entries for the function symbols in the "prepared copy":

Relocation section '.rela.dyn' at offset 0x4000 contains 12 entries:
  Offset          Info           Type         Symbol
/* snipped; "prepared_copy" starts at 0x6000 */
000000006000  000000000008 R_X86_64_RELATIVE  &lt;do_encl_emodpe&gt;
000000006008  000000000008 R_X86_64_RELATIVE  &lt;do_encl_eaccept&gt;
000000006010  000000000008 R_X86_64_RELATIVE  &lt;do_encl_op_put_to_buf&gt;
000000006018  000000000008 R_X86_64_RELATIVE  &lt;do_encl_op_get_from_buf&gt;
000000006020  000000000008 R_X86_64_RELATIVE  &lt;do_encl_op_put_to_addr&gt;
000000006028  000000000008 R_X86_64_RELATIVE  &lt;do_encl_op_get_from_addr&gt;
000000006030  000000000008 R_X86_64_RELATIVE  &lt;do_encl_op_nop&gt;
000000006038  000000000008 R_X86_64_RELATIVE  &lt;do_encl_init_tcs_page&gt;

Static-pie binaries normally include a glibc "_dl_relocate_static_pie"
routine that will perform these relocations as part of the startup.
However, since the enclave loading process is different and glibc is not
included, we cannot rely on these relocations to be performed. Without
relocations, the code would erroneously jump to the _absolute_ function
address loaded from the local copy.

Thus, declare "encl_op_array" as global and manually relocate the loaded
function-pointer entries relative to the enclave base at runtime. This
generates the following code:

encl_body:
    /* snipped */
    lea    encl_op_array(%rip), %rcx
    lea    __encl_base(%rip), %rax
    add    (%rcx,%rdx,8),%rax
    jmp    *%rax

Signed-off-by: Jo Van Bulck &lt;jo.vanbulck@cs.kuleuven.be&gt;
Signed-off-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Jarkko Sakkinen &lt;jarkko@kernel.org&gt;
Acked-by: Kai Huang &lt;kai.huang@intel.com&gt;
Link: https://lore.kernel.org/all/150d8ca8-2c66-60d1-f9fc-8e6279824e94@cs.kuleuven.be/
Link: https://lore.kernel.org/all/5c22de5a-4b3b-1f38-9771-409b4ec7f96d@cs.kuleuven.be/#r
Link: https://lore.kernel.org/all/20231005153854.25566-9-jo.vanbulck%40cs.kuleuven.be
</content>
</entry>
</feed>
