diff mbox series

[kvm-unit-tests,v2,4/5] x86: Dedup 32-bit vs. 64-bit ASM_TRY() by stealing kernel's __ASM_SEL()

Message ID 20220807142832.1576-5-mhal@rbox.co (mailing list archive)
State New
Headers show
Series Test for illegal LEA & related fixes | expand

Commit Message

Michal Luczaj Aug. 7, 2022, 2:28 p.m. UTC
From: Sean Christopherson <seanjc@google.com>

Steal the kernel's __ASM_SEL() implementation and use it to consolidate
ASM_TRY().  The only difference between the 32-bit and 64-bit versions is
the size of the address stored in the table.

No functional change intended.

Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
 lib/x86/desc.h      | 22 ++++++----------------
 lib/x86/processor.h | 12 ++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)

Comments

Sean Christopherson Aug. 8, 2022, 4:32 p.m. UTC | #1
On Sun, Aug 07, 2022, Michal Luczaj wrote:
> diff --git a/lib/x86/processor.h b/lib/x86/processor.h
> index 0324220..30e2de8 100644
> --- a/lib/x86/processor.h
> +++ b/lib/x86/processor.h
> @@ -19,6 +19,18 @@
>  #  define S "4"
>  #endif
>  
> +#ifdef __ASSEMBLY__
> +#define __ASM_FORM(x, ...)	x,## __VA_ARGS__
> +#else
> +#define __ASM_FORM(x, ...)	" " xstr(x,##__VA_ARGS__) " "
> +#endif
> +
> +#ifndef __x86_64__
> +#define __ASM_SEL(a,b)		__ASM_FORM(a)
> +#else
> +#define __ASM_SEL(a,b)		__ASM_FORM(b)
> +#endif

Argh, this can't go in processor.h, because processor.h includes desc.h (to use
ASM_TRY).  This patch "works" because emulator.c includes both process.or and
desc.h, but things go sideways if ASM_TRY_FEP() is moved into desc.h.

I'll post a new version of the entire series, the KVM_FEP macro and a helper to
check for FEP availability should really go in a common location, e.g. the PMU
test can use the common helper instead of requiring a separate unittest.cfg entry.
diff mbox series

Patch

diff --git a/lib/x86/desc.h b/lib/x86/desc.h
index 8854fcc..5bb6fcb 100644
--- a/lib/x86/desc.h
+++ b/lib/x86/desc.h
@@ -80,23 +80,13 @@  typedef struct  __attribute__((packed)) {
 	u16 iomap_base;
 } tss64_t;
 
-#ifdef __x86_64
-#define __ASM_TRY(prefix, catch)	\
-	"movl $0, %%gs:4 \n\t"		\
-	".pushsection .data.ex \n\t"	\
-	".quad 1111f, " catch "\n\t"	\
-	".popsection \n\t"		\
-	prefix				\
+#define __ASM_TRY(prefix, catch)				\
+	"movl $0, %%gs:4 \n\t"					\
+	".pushsection .data.ex \n\t"				\
+	__ASM_SEL(.long, .quad) " 1111f,  " catch "\n\t"	\
+	".popsection \n\t"					\
+	prefix							\
 	"1111:"
-#else
-#define __ASM_TRY(prefix, catch)	\
-	"movl $0, %%gs:4 \n\t"		\
-	".pushsection .data.ex \n\t"	\
-	".long 1111f, " catch "\n\t"	\
-	".popsection \n\t"		\
-	prefix				\
-	"1111:"
-#endif
 
 #define ASM_TRY(catch) __ASM_TRY("", catch)
 
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index 0324220..30e2de8 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -19,6 +19,18 @@ 
 #  define S "4"
 #endif
 
+#ifdef __ASSEMBLY__
+#define __ASM_FORM(x, ...)	x,## __VA_ARGS__
+#else
+#define __ASM_FORM(x, ...)	" " xstr(x,##__VA_ARGS__) " "
+#endif
+
+#ifndef __x86_64__
+#define __ASM_SEL(a,b)		__ASM_FORM(a)
+#else
+#define __ASM_SEL(a,b)		__ASM_FORM(b)
+#endif
+
 #define DB_VECTOR 1
 #define BP_VECTOR 3
 #define UD_VECTOR 6