[Xen-devel] [PATCH 3/2] x86/desc: Drop __HYPERVISOR_CS32

Jan Beulich posted 2 patches 6 years, 6 months ago
Only 1 patches received!
[Xen-devel] [PATCH 3/2] x86/desc: Drop __HYPERVISOR_CS32
Posted by Andrew Cooper 6 years, 6 months ago
Xen, being 64bit only these days, has no use for a 32bit Ring 0 code segment.

Delete __HYPERVISOR_CS32 and remove it from the GDTs.  Also delete
__HYPERVISOR_CS64 and use __HYPERVISOR_CS uniformly.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wl@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/acpi/wakeup_prot.S |  2 +-
 xen/arch/x86/boot/x86_64.S      |  2 +-
 xen/arch/x86/desc.c             | 12 ++++--------
 xen/include/asm-x86/config.h    |  4 +---
 xen/include/asm-x86/desc.h      |  4 ++--
 5 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/xen/arch/x86/acpi/wakeup_prot.S b/xen/arch/x86/acpi/wakeup_prot.S
index 4a92627436..9e9fcc1ab6 100644
--- a/xen/arch/x86/acpi/wakeup_prot.S
+++ b/xen/arch/x86/acpi/wakeup_prot.S
@@ -74,7 +74,7 @@ ENTRY(__ret_point)
         LOAD_GREG(sp)
 
         /* Reload code selector */
-        pushq   $(__HYPERVISOR_CS64)
+        pushq   $__HYPERVISOR_CS
         leaq    1f(%rip),%rax
         pushq   %rax
         lretq
diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S
index f762dfea11..5ab24d73fc 100644
--- a/xen/arch/x86/boot/x86_64.S
+++ b/xen/arch/x86/boot/x86_64.S
@@ -23,7 +23,7 @@ ENTRY(__high_start)
         popf
 
         /* Reload code selector. */
-        pushq   $(__HYPERVISOR_CS64)
+        pushq   $__HYPERVISOR_CS
         leaq    1f(%rip),%rax
         pushq   %rax
         lretq
diff --git a/xen/arch/x86/desc.c b/xen/arch/x86/desc.c
index b5c9208164..7d9940d08a 100644
--- a/xen/arch/x86/desc.c
+++ b/xen/arch/x86/desc.c
@@ -31,7 +31,7 @@ __section(".data.page_aligned") __aligned(PAGE_SIZE)
 seg_desc_t boot_gdt[PAGE_SIZE / sizeof(seg_desc_t)] =
 {
     /* 0xe008 - Ring 0 code, 64bit mode */
-    [SEL2GDT(__HYPERVISOR_CS64)] = { 0x00af9b000000ffff },
+    [SEL2GDT(__HYPERVISOR_CS)] = { 0x00af9b000000ffff },
 
     /* 0xe010 - Ring 0 data */
     [SEL2GDT(__HYPERVISOR_DS32)] = { 0x00cf93000000ffff },
@@ -47,9 +47,7 @@ seg_desc_t boot_gdt[PAGE_SIZE / sizeof(seg_desc_t)] =
     /* 0xe033 - Ring 3 code, 64-bit mode */
     [SEL2GDT(FLAT_RING3_CS64)] = { 0x00affb000000ffff },
 
-    /* 0xe038 - Ring 0 code, compatibility */
-    [SEL2GDT(__HYPERVISOR_CS32)] = { 0x00cf9b000000ffff },
-
+    /* 0xe038 - reserved */
     /* 0xe040 - TSS */
     /* 0xe050 - LDT */
 
@@ -61,7 +59,7 @@ __section(".data.page_aligned") __aligned(PAGE_SIZE)
 seg_desc_t boot_compat_gdt[PAGE_SIZE / sizeof(seg_desc_t)] =
 {
     /* 0xe008 - Ring 0 code, 64bit mode */
-    [SEL2GDT(__HYPERVISOR_CS64)] = { 0x00af9b000000ffff },
+    [SEL2GDT(__HYPERVISOR_CS)] = { 0x00af9b000000ffff },
 
     /* 0xe010 - Ring 0 data */
     [SEL2GDT(__HYPERVISOR_DS32)] = { 0x00cf93000000ffff },
@@ -78,9 +76,7 @@ seg_desc_t boot_compat_gdt[PAGE_SIZE / sizeof(seg_desc_t)] =
     /* 0xe033 - Ring 3 data */
     [SEL2GDT(FLAT_COMPAT_RING3_DS)] = { 0x00cff3000000ffff },
 
-    /* 0xe038 - Ring 0 code, compatibility */
-    [SEL2GDT(__HYPERVISOR_CS32)] = { 0x00cf9b000000ffff },
-
+    /* 0xe038 - reserved */
     /* 0xe040 - TSS */
     /* 0xe050 - LDT */
 
diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h
index 6e4f28d934..22dc795eea 100644
--- a/xen/include/asm-x86/config.h
+++ b/xen/include/asm-x86/config.h
@@ -264,9 +264,7 @@ extern unsigned char boot_edid_info[128];
 
 #endif
 
-#define __HYPERVISOR_CS64 0xe008
-#define __HYPERVISOR_CS32 0xe038
-#define __HYPERVISOR_CS   __HYPERVISOR_CS64
+#define __HYPERVISOR_CS   0xe008
 #define __HYPERVISOR_DS64 0x0000
 #define __HYPERVISOR_DS32 0xe010
 #define __HYPERVISOR_DS   __HYPERVISOR_DS64
diff --git a/xen/include/asm-x86/desc.h b/xen/include/asm-x86/desc.h
index 80aa254206..4b29dac259 100644
--- a/xen/include/asm-x86/desc.h
+++ b/xen/include/asm-x86/desc.h
@@ -155,7 +155,7 @@ do {                                                     \
         ((unsigned long)(dpl) << 45) |                   \
         ((unsigned long)(type) << 40) |                  \
         ((unsigned long)(addr) & 0xFFFFUL) |             \
-        ((unsigned long)__HYPERVISOR_CS64 << 16) |       \
+        ((unsigned long)__HYPERVISOR_CS << 16) |         \
         (1UL << 47);                                     \
 } while (0)
 
@@ -169,7 +169,7 @@ static inline void _set_gate_lower(idt_entry_t *gate, unsigned long type,
         ((unsigned long)(dpl) << 45) |
         ((unsigned long)(type) << 40) |
         ((unsigned long)(addr) & 0xFFFFUL) |
-        ((unsigned long)__HYPERVISOR_CS64 << 16) |
+        ((unsigned long)__HYPERVISOR_CS << 16) |
         (1UL << 47);
     _write_gate_lower(gate, &idte);
 }
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/2] x86/desc: Drop __HYPERVISOR_CS32
Posted by Jan Beulich 6 years, 6 months ago
On 09.08.2019 14:39, Andrew Cooper wrote:
> Xen, being 64bit only these days, has no use for a 32bit Ring 0 code segment.
> 
> Delete __HYPERVISOR_CS32 and remove it from the GDTs.  Also delete
> __HYPERVISOR_CS64 and use __HYPERVISOR_CS uniformly.

Long, long ago we've been considering doing this. Agreed,
nothing has surfaced to actually use it, but I wouldn't
subscribe to "has no use": We will need it if we ever want
to be able to run on 32-bit EFI _and_ invoke runtime
services there. Back then through the consideration against
dropping it was that we may want to invoke 32-bit BIOS
services (PCI, VGA) from the hypervisor.

Of course it wouldn't be terribly difficult to re-instate
these selectors / descriptors, but still. Nevertheless, if
you're convinced of the move despite the remarks above ...

> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/2] x86/desc: Drop __HYPERVISOR_CS32
Posted by Andrew Cooper 6 years, 6 months ago
On 09/08/2019 13:50, Jan Beulich wrote:
> On 09.08.2019 14:39, Andrew Cooper wrote:
>> Xen, being 64bit only these days, has no use for a 32bit Ring 0 code
>> segment.
>>
>> Delete __HYPERVISOR_CS32 and remove it from the GDTs.  Also delete
>> __HYPERVISOR_CS64 and use __HYPERVISOR_CS uniformly.
>
> Long, long ago we've been considering doing this. Agreed,
> nothing has surfaced to actually use it, but I wouldn't
> subscribe to "has no use": We will need it if we ever want
> to be able to run on 32-bit EFI _and_ invoke runtime
> services there. Back then through the consideration against
> dropping it was that we may want to invoke 32-bit BIOS
> services (PCI, VGA) from the hypervisor.

I hadn't realised these had even been considered in the past.  I don't
think either of these are likely to happen now.

As for the text, Xen really does have no users of a 32bit R0 code
segment, and the statement does not preclude the fact that there may be
legitimate uses for CS32.

Would you be happier with "days, and does not use a 32bit Ring 0 code
segment." ?

There is specifically a good reason for taking it out (given that it
isn't used), to avoid cascade breakage from a stray far jump which
happens to start executing code in the wrong mode.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/2] x86/desc: Drop __HYPERVISOR_CS32
Posted by Jan Beulich 6 years, 6 months ago
On 09.08.2019 17:36, Andrew Cooper wrote:
> On 09/08/2019 13:50, Jan Beulich wrote:
>> On 09.08.2019 14:39, Andrew Cooper wrote:
>>> Xen, being 64bit only these days, has no use for a 32bit Ring 0 code
>>> segment.
>>>
>>> Delete __HYPERVISOR_CS32 and remove it from the GDTs.  Also delete
>>> __HYPERVISOR_CS64 and use __HYPERVISOR_CS uniformly.
>>
>> Long, long ago we've been considering doing this. Agreed,
>> nothing has surfaced to actually use it, but I wouldn't
>> subscribe to "has no use": We will need it if we ever want
>> to be able to run on 32-bit EFI _and_ invoke runtime
>> services there. Back then through the consideration against
>> dropping it was that we may want to invoke 32-bit BIOS
>> services (PCI, VGA) from the hypervisor.
> 
> I hadn't realised these had even been considered in the past.  I don't
> think either of these are likely to happen now.
> 
> As for the text, Xen really does have no users of a 32bit R0 code
> segment, and the statement does not preclude the fact that there may be
> legitimate uses for CS32.
> 
> Would you be happier with "days, and does not use a 32bit Ring 0 code
> segment." ?

Yes, "does not use" is definitely more correct imo, as would be
"has no user" (note the extra "r" compared to your original text;
your reply makes me wonder whether it was simply a typo).

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
  • [Xen-devel] [PATCH 3/2] x86/desc: Drop __HYPERVISOR_CS32