public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>,
	Hang SU <darcy.sh@antgroup.com>
Subject: [kvm-unit-tests PATCH 1/3] x86: Move descriptor table selector #defines to the top of desc.h
Date: Fri, 21 Feb 2025 14:54:04 -0800	[thread overview]
Message-ID: <20250221225406.2228938-2-seanjc@google.com> (raw)
In-Reply-To: <20250221225406.2228938-1-seanjc@google.com>

Hoist the selector #defines in desc.h to the very top so that they can be
exposed to assembly code with minimal #ifdefs.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 lib/x86/desc.h | 114 ++++++++++++++++++++++++-------------------------
 1 file changed, 57 insertions(+), 57 deletions(-)

diff --git a/lib/x86/desc.h b/lib/x86/desc.h
index 92c45a48..a4459127 100644
--- a/lib/x86/desc.h
+++ b/lib/x86/desc.h
@@ -1,7 +1,61 @@
 #ifndef _X86_DESC_H_
 #define _X86_DESC_H_
 
-#include <setjmp.h>
+/*
+ * selector     32-bit                        64-bit
+ * 0x00         NULL descriptor               NULL descriptor
+ * 0x08         ring-0 code segment (32-bit)  ring-0 code segment (64-bit)
+ * 0x10         ring-0 data segment (32-bit)  ring-0 data segment (32/64-bit)
+ * 0x18         ring-0 code segment (P=0)     ring-0 code segment (64-bit, P=0)
+ * 0x20         intr_alt_stack TSS            ring-0 code segment (32-bit)
+ * 0x28         ring-0 code segment (16-bit)  same
+ * 0x30         ring-0 data segment (16-bit)  same
+ * 0x38 (0x3b)  ring-3 code segment (32-bit)  same
+ * 0x40 (0x43)  ring-3 data segment (32-bit)  ring-3 data segment (32/64-bit)
+ * 0x48 (0x4b)  **unused**                    ring-3 code segment (64-bit)
+ * 0x50-0x78    free to use for test cases    same
+ * 0x80-0x870   primary TSS (CPU 0..254)      same
+ * 0x878-0x1068 percpu area (CPU 0..254)      not used
+ *
+ * Note that the same segment can be used for 32-bit and 64-bit data segments
+ * (the L bit is only defined for code segments)
+ *
+ * Selectors 0x08-0x10 and 0x3b-0x4b are set up for use with the SYSCALL
+ * and SYSRET instructions.
+ */
+
+#define KERNEL_CS   0x08
+#define KERNEL_DS   0x10
+#define NP_SEL      0x18
+#ifdef __x86_64__
+#define KERNEL_CS32 0x20
+#else
+#define TSS_INTR    0x20
+#endif
+#define KERNEL_CS16 0x28
+#define KERNEL_DS16 0x30
+#define USER_CS32   0x3b
+#define USER_DS     0x43
+#ifdef __x86_64__
+#define USER_CS64   0x4b
+#endif
+
+/* Synonyms */
+#define KERNEL_DS32 KERNEL_DS
+#define USER_DS32   USER_DS
+
+#ifdef __x86_64__
+#define KERNEL_CS64 KERNEL_CS
+#define USER_CS     USER_CS64
+#define KERNEL_DS64 KERNEL_DS
+#define USER_DS64   USER_DS
+#else
+#define KERNEL_CS32 KERNEL_CS
+#define USER_CS     USER_CS32
+#endif
+
+#define FIRST_SPARE_SEL 0x50
+#define TSS_MAIN 0x80
 
 #ifdef __ASSEMBLY__
 #define __ASM_FORM(x, ...)	x,## __VA_ARGS__
@@ -15,6 +69,8 @@
 #define __ASM_SEL(a,b)		__ASM_FORM(b)
 #endif
 
+#include <setjmp.h>
+
 void setup_idt(void);
 void load_idt(void);
 void setup_alt_stack(void);
@@ -120,62 +176,6 @@ fep_unavailable:
 	return false;
 }
 
-/*
- * selector     32-bit                        64-bit
- * 0x00         NULL descriptor               NULL descriptor
- * 0x08         ring-0 code segment (32-bit)  ring-0 code segment (64-bit)
- * 0x10         ring-0 data segment (32-bit)  ring-0 data segment (32/64-bit)
- * 0x18         ring-0 code segment (P=0)     ring-0 code segment (64-bit, P=0)
- * 0x20         intr_alt_stack TSS            ring-0 code segment (32-bit)
- * 0x28         ring-0 code segment (16-bit)  same
- * 0x30         ring-0 data segment (16-bit)  same
- * 0x38 (0x3b)  ring-3 code segment (32-bit)  same
- * 0x40 (0x43)  ring-3 data segment (32-bit)  ring-3 data segment (32/64-bit)
- * 0x48 (0x4b)  **unused**                    ring-3 code segment (64-bit)
- * 0x50-0x78    free to use for test cases    same
- * 0x80-0x870   primary TSS (CPU 0..254)      same
- * 0x878-0x1068 percpu area (CPU 0..254)      not used
- *
- * Note that the same segment can be used for 32-bit and 64-bit data segments
- * (the L bit is only defined for code segments)
- *
- * Selectors 0x08-0x10 and 0x3b-0x4b are set up for use with the SYSCALL
- * and SYSRET instructions.
- */
-
-#define KERNEL_CS   0x08
-#define KERNEL_DS   0x10
-#define NP_SEL      0x18
-#ifdef __x86_64__
-#define KERNEL_CS32 0x20
-#else
-#define TSS_INTR    0x20
-#endif
-#define KERNEL_CS16 0x28
-#define KERNEL_DS16 0x30
-#define USER_CS32   0x3b
-#define USER_DS     0x43
-#ifdef __x86_64__
-#define USER_CS64   0x4b
-#endif
-
-/* Synonyms */
-#define KERNEL_DS32 KERNEL_DS
-#define USER_DS32   USER_DS
-
-#ifdef __x86_64__
-#define KERNEL_CS64 KERNEL_CS
-#define USER_CS     USER_CS64
-#define KERNEL_DS64 KERNEL_DS
-#define USER_DS64   USER_DS
-#else
-#define KERNEL_CS32 KERNEL_CS
-#define USER_CS     USER_CS32
-#endif
-
-#define FIRST_SPARE_SEL 0x50
-#define TSS_MAIN 0x80
-
 typedef struct {
 	unsigned short offset0;
 	unsigned short selector;
-- 
2.48.1.601.g30ceb7b040-goog


  reply	other threads:[~2025-02-21 22:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 22:54 [kvm-unit-tests PATCH 0/3] x86: Use macros for selectors in asm Sean Christopherson
2025-02-21 22:54 ` Sean Christopherson [this message]
2025-02-21 22:54 ` [kvm-unit-tests PATCH 2/3] x86: Commit to using __ASSEMBLER__ instead of __ASSEMBLY__ Sean Christopherson
2025-02-21 22:54 ` [kvm-unit-tests PATCH 3/3] x86: replace segment selector magic number with macro definition Sean Christopherson
2025-02-21 23:34   ` Sean Christopherson
2025-02-24 17:24 ` [kvm-unit-tests PATCH 0/3] x86: Use macros for selectors in asm Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250221225406.2228938-2-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=darcy.sh@antgroup.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox