selftests/sgx: Ensure test enclave buffer is entirely preserved
authorJo Van Bulck <jo.vanbulck@cs.kuleuven.be>
Thu, 5 Oct 2023 15:38:51 +0000 (17:38 +0200)
committerDave Hansen <dave.hansen@linux.intel.com>
Fri, 8 Dec 2023 18:05:27 +0000 (10:05 -0800)
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 <jo.vanbulck@cs.kuleuven.be>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Acked-by: Kai Huang <kai.huang@intel.com>
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
tools/testing/selftests/sgx/defines.h
tools/testing/selftests/sgx/test_encl.c

index d8587c971941a8ac40f9a284fc34d2993fa0d8af..b8f482667ce14be344991e1597cdd50d16522283 100644 (file)
@@ -13,6 +13,7 @@
 
 #define __aligned(x) __attribute__((__aligned__(x)))
 #define __packed __attribute__((packed))
+#define __used __attribute__((used))
 
 #include "../../../../arch/x86/include/asm/sgx.h"
 #include "../../../../arch/x86/include/asm/enclu.h"
index 649604c526e77536124f32391e7093f213afa271..7465f121fb7463fa27ff6c7121556ade113c2867 100644 (file)
@@ -5,11 +5,12 @@
 #include "defines.h"
 
 /*
- * Data buffer spanning two pages that will be placed first in .data
- * segment. Even if not used internally the second page is needed by
- * external test manipulating page permissions.
+ * Data buffer spanning two pages that will be placed first in the .data
+ * segment. Even if not used internally the second page is needed by external
+ * test manipulating page permissions, so mark encl_buffer as "used" to make
+ * sure it is entirely preserved by the compiler.
  */
-static uint8_t encl_buffer[8192] = { 1 };
+static uint8_t __used encl_buffer[8192] = { 1 };
 
 enum sgx_enclu_function {
        EACCEPT = 0x5,