Skip to contentSkip to conversation

selftests/x86: x86/sgx: Minor selftest cleanup

PATCH In review Sean Christopherson 2 participants 6 messages Dec 20, 2019 – Jan 2, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover selftests/x86: x86/sgx: Minor selftest cleanup

Add a .gitignore entry for the selftests and cleanup the includes to remove some homebrewed definitions in sgx/defines.h.

Sean Christopherson (4):
selftests/x86: Fix INCLUDES definition in SGX Makefile x86/sgx: Add missing linux/bits.h include in sgx/arch.h selftests/x86: Add .gitignore for SGX selftest selftests/x86: Remove redundant kernel include

 arch/x86/kernel/cpu/sgx/arch.h             |  1 +
 tools/testing/selftests/x86/sgx/.gitignore |  3 +++
 tools/testing/selftests/x86/sgx/Makefile   |  3 ++-
 tools/testing/selftests/x86/sgx/defines.h  | 22 ----------------------
 tools/testing/selftests/x86/sgx/main.c     |  2 --
 5 files changed, 6 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/x86/sgx/.gitignore
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/4 selftests/x86: Fix INCLUDES definition in SGX Makefile

Define INCLUDES to reference the top-level tools/include when building SGX selftests in preparation of adding a missing linux/bits.h include in sgx/arch.h.

---
 tools/testing/selftests/x86/sgx/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/sgx/Makefile +2 -1
index a09ef5f965dc..f838700029e2 100644
@@ -6,6 +6,7 @@ ifndef OBJCOPY
 OBJCOPY := $(CROSS_COMPILE)objcopy
 endif
 
+INCLUDES := -I$(top_srcdir)/tools/include
 HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -z noexecstack
 ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \
 	       -fno-stack-protector -mrdrnd $(INCLUDES)
@@ -33,7 +34,7 @@ $(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin
 	$(OUTPUT)/sgxsign signing_key.pem $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
 
 $(OUTPUT)/sgxsign: sgxsign.c
-	$(CC) -o $@ $< -lcrypto
+	$(CC) $(INCLUDES) -o $@ $< -lcrypto
 
 EXTRA_CLEAN := \
 	$(OUTPUT)/encl.bin \
Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/4 x86/sgx: Add missing linux/bits.h include in sgx/arch.h

In reply to Sean Christopherson

Include linux/bits.h for its defitions of BIT() and GENMASK*().

---
 arch/x86/kernel/cpu/sgx/arch.h            |  1 +
 tools/testing/selftests/x86/sgx/defines.h | 22 ----------------------
 2 files changed, 1 insertion(+), 22 deletions(-)
arch/x86/kernel/cpu/sgx/arch.h +1 -0
index 7a5d24b4d1bb..dbd652be9b53 100644
@@ -8,6 +8,7 @@
 #ifndef _ASM_X86_SGX_ARCH_H
 #define _ASM_X86_SGX_ARCH_H
 
+#include <linux/bits.h>
 #include <linux/types.h>
 
 #define SGX_CPUID				0x12
tools/testing/selftests/x86/sgx/defines.h +0 -22
index 1e67f2f29f42..87264f85cb9f 100644
@@ -8,31 +8,9 @@
 
 #include <stdint.h>
 
-typedef uint8_t u8;
-typedef uint16_t u16;
-typedef uint32_t u32;
-typedef uint64_t u64;
-
 #define __aligned(x) __attribute__((__aligned__(x)))
 #define __packed __attribute__((packed))
 
-/* Derived from asm-generic/bitsperlong.h. */
-#if __x86_64__
-#define BITS_PER_LONG 64
-#else
-#define BITS_PER_LONG 32
-#endif
-#define BITS_PER_LONG_LONG 64
-
-/* Taken from linux/bits.h. */
-#define BIT(nr)	(1UL << (nr))
-#define BIT_ULL(nr) (1ULL << (nr))
-#define GENMASK(h, l) \
-	(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
-#define GENMASK_ULL(h, l) \
-	(((~0ULL) - (1ULL << (l)) + 1) & \
-	 (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
-
 #include "../../../../../arch/x86/kernel/cpu/sgx/arch.h"
 #include "../../../../../arch/x86/include/uapi/asm/sgx.h"
 
Signature · 1 line
2.24.1
#3 lore raw

PATCH 3/4 selftests/x86: Add .gitignore for SGX selftest

In reply to Sean Christopherson

Add a .gitignore for SGX to ignore its build output.

---
 tools/testing/selftests/x86/sgx/.gitignore | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 tools/testing/selftests/x86/sgx/.gitignore
tools/testing/selftests/x86/sgx/.gitignore new file +3 -0
new file mode 100644
index 000000000000..98eb2d439606
@@ -0,0 +1,3 @@
+encl.ss
+sgxsign
+test_sgx
Signature · 1 line
2.24.1
#4 lore raw

PATCH 4/4 selftests/x86: Remove redundant kernel include

In reply to Sean Christopherson

The SGX selftests incorporate any and all necessary kernel includes in defines.h, remove redundant includes from main.c so that the obnoxiously long paths don't need to be updated if the kernel files are renamed.

---
 tools/testing/selftests/x86/sgx/main.c | 2 --
 1 file changed, 2 deletions(-)
tools/testing/selftests/x86/sgx/main.c +0 -2
index a94ba894b020..d97cc3cf0093 100644
@@ -16,8 +16,6 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include "defines.h"
-#include "../../../../../arch/x86/kernel/cpu/sgx/arch.h"
-#include "../../../../../arch/x86/include/uapi/asm/sgx.h"
 #include "sgx_call.h"
 
 #define PAGE_SIZE  4096
Signature · 1 line
2.24.1
#5 lore raw
In reply to Sean Christopherson
Quoted 9 lines · Sean Christopherson

Add a .gitignore entry for the selftests and cleanup the includes to remove some homebrewed definitions in sgx/defines.h.

Sean Christopherson (4):
selftests/x86: Fix INCLUDES definition in SGX Makefile x86/sgx: Add missing linux/bits.h include in sgx/arch.h selftests/x86: Add .gitignore for SGX selftest selftests/x86: Remove redundant kernel include

Quoted 11 lines
 arch/x86/kernel/cpu/sgx/arch.h             |  1 +
 tools/testing/selftests/x86/sgx/.gitignore |  3 +++
 tools/testing/selftests/x86/sgx/Makefile   |  3 ++-
 tools/testing/selftests/x86/sgx/defines.h  | 22 ----------------------
 tools/testing/selftests/x86/sgx/main.c     |  2 --
 5 files changed, 6 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/x86/sgx/.gitignore
Signature · 1 line
2.24.1

Thank you. I merged everything.

/Jarkko