Skip to contentSkip to conversation

x86, paravirt, xen: Remove the 64-bit irq_enable_sysexit pvop

PATCH Applied Andy Lutomirski 7 participants 16 messages Apr 3, 2015 – Apr 22, 2015

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

PATCH 1/1 x86, paravirt, xen: Remove the 64-bit irq_enable_sysexit pvop

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove all the paravirt and Xen machinery to support it on 64-bit kernels.

---

I haven't actually tested this on Xen, but it builds for me.

 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index 5d8f987a340d..eb1eb7b70f4b 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
 	swapgs
 	sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-	swapgs
-	sti
-	sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b369e4..38a0ff9ef06e 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
 	u64 (*read_pmc)(int counter);
 	unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
 	/*
 	 * Atomically enable interrupts and return to userspace.  This
-	 * is only ever used to return to 32-bit processes; in a
-	 * 64-bit kernel, it's used for 32-on-64 compat processes, but
-	 * never native 64-bit processes.  (Jump, not call.)
+	 * is only used in 32-bit kernels.  64-bit kernels use
+	 * usergs_sysret32 instead.
 	 */
 	void (*irq_enable_sysexit)(void);
+#endif
 
 	/*
 	 * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index 9f6b9341950f..2d27ebf0aed8 100644
@@ -49,7 +49,9 @@ void common(void) {
 	OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
 	OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
 	OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
 	OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
 	OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
 	OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f00c90..7563114d9c3a 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
 		ret = paravirt_patch_ident_64(insnbuf, len);
 
 	else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
 		 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
 		 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
 		 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
 		/* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
 	.load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
 	.irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da6737ba5b..0de21c62c348 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
 		PATCH_SITE(pv_irq_ops, save_fl);
 		PATCH_SITE(pv_irq_ops, irq_enable);
 		PATCH_SITE(pv_irq_ops, irq_disable);
-		PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
 		PATCH_SITE(pv_cpu_ops, usergs_sysret32);
 		PATCH_SITE(pv_cpu_ops, usergs_sysret64);
 		PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9f2132..3797b6b31f95 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
 	.read_tscp = native_read_tscp,
 
 	.iret = xen_iret,
-	.irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
 	.usergs_sysret32 = xen_sysret32,
 	.usergs_sysret64 = xen_sysret64,
+#else
+	.irq_enable_sysexit = xen_sysexit,
 #endif
 
 	.load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3ee0973..a2cabb8bd6bf 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-	pushq $__USER32_DS
-	pushq %rcx
-	pushq $X86_EFLAGS_IF
-	pushq $__USER32_CS
-	pushq %rdx
-
-	pushq $0
-1:	jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
 	/*
 	 * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -0
index 9e195c683549..c20fe29e65f4 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);
Signature · 1 line
2.3.0
#1 lore raw

[cc: Boris and Konrad. Whoops]

Quoted 167 lines · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove all the paravirt and Xen machinery to support it on 64-bit kernels.

---

I haven't actually tested this on Xen, but it builds for me.

 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index 5d8f987a340d..eb1eb7b70f4b 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
        swapgs
        sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-       swapgs
-       sti
-       sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b369e4..38a0ff9ef06e 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
        u64 (*read_pmc)(int counter);
        unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
        /*
         * Atomically enable interrupts and return to userspace.  This
-        * is only ever used to return to 32-bit processes; in a
-        * 64-bit kernel, it's used for 32-on-64 compat processes, but
-        * never native 64-bit processes.  (Jump, not call.)
+        * is only used in 32-bit kernels.  64-bit kernels use
+        * usergs_sysret32 instead.
         */
        void (*irq_enable_sysexit)(void);
+#endif
 
        /*
         * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index 9f6b9341950f..2d27ebf0aed8 100644
@@ -49,7 +49,9 @@ void common(void) {
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
        OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
        OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
        OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f00c90..7563114d9c3a 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
                ret = paravirt_patch_ident_64(insnbuf, len);
 
        else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
                 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
                /* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
        .load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
        .irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da6737ba5b..0de21c62c348 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, save_fl);
                PATCH_SITE(pv_irq_ops, irq_enable);
                PATCH_SITE(pv_irq_ops, irq_disable);
-               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
                PATCH_SITE(pv_cpu_ops, usergs_sysret32);
                PATCH_SITE(pv_cpu_ops, usergs_sysret64);
                PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9f2132..3797b6b31f95 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .read_tscp = native_read_tscp,
 
        .iret = xen_iret,
-       .irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
        .usergs_sysret32 = xen_sysret32,
        .usergs_sysret64 = xen_sysret64,
+#else
+       .irq_enable_sysexit = xen_sysexit,
 #endif
 
        .load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3ee0973..a2cabb8bd6bf 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-       pushq $__USER32_DS
-       pushq %rcx
-       pushq $X86_EFLAGS_IF
-       pushq $__USER32_CS
-       pushq %rdx
-
-       pushq $0
-1:     jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
        /*
         * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -1
index 9e195c683549..c20fe29e65f4 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);
--

2.3.0

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#2 lore raw
Quoted 4 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit kernels is unsavory?

Thank you!

Quoted 172 lines
Quoted 166 lines

all the paravirt and Xen machinery to support it on 64-bit kernels.

---

I haven't actually tested this on Xen, but it builds for me.

 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index 5d8f987a340d..eb1eb7b70f4b 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
        swapgs
        sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-       swapgs
-       sti
-       sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b369e4..38a0ff9ef06e 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
        u64 (*read_pmc)(int counter);
        unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
        /*
         * Atomically enable interrupts and return to userspace.  This
-        * is only ever used to return to 32-bit processes; in a
-        * 64-bit kernel, it's used for 32-on-64 compat processes, but
-        * never native 64-bit processes.  (Jump, not call.)
+        * is only used in 32-bit kernels.  64-bit kernels use
+        * usergs_sysret32 instead.
         */
        void (*irq_enable_sysexit)(void);
+#endif
 
        /*
         * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index 9f6b9341950f..2d27ebf0aed8 100644
@@ -49,7 +49,9 @@ void common(void) {
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
        OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
        OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
        OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f00c90..7563114d9c3a 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
                ret = paravirt_patch_ident_64(insnbuf, len);
 
        else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
                 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
                /* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
        .load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
        .irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da6737ba5b..0de21c62c348 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, save_fl);
                PATCH_SITE(pv_irq_ops, irq_enable);
                PATCH_SITE(pv_irq_ops, irq_disable);
-               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
                PATCH_SITE(pv_cpu_ops, usergs_sysret32);
                PATCH_SITE(pv_cpu_ops, usergs_sysret64);
                PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9f2132..3797b6b31f95 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .read_tscp = native_read_tscp,
 
        .iret = xen_iret,
-       .irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
        .usergs_sysret32 = xen_sysret32,
        .usergs_sysret64 = xen_sysret64,
+#else
+       .irq_enable_sysexit = xen_sysexit,
 #endif
 
        .load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3ee0973..a2cabb8bd6bf 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-       pushq $__USER32_DS
-       pushq %rcx
-       pushq $X86_EFLAGS_IF
-       pushq $__USER32_CS
-       pushq %rdx
-
-       pushq $0
-1:     jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
        /*
         * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -1
index 9e195c683549..c20fe29e65f4 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);
--

2.3.0

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#3 lore raw
In reply to Andy Lutomirski
Quoted 4 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit kernels is unsavory?

Thank you!

Quoted 172 lines
Quoted 166 lines

all the paravirt and Xen machinery to support it on 64-bit kernels.

---

I haven't actually tested this on Xen, but it builds for me.

 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index 5d8f987a340d..eb1eb7b70f4b 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
        swapgs
        sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-       swapgs
-       sti
-       sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b369e4..38a0ff9ef06e 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
        u64 (*read_pmc)(int counter);
        unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
        /*
         * Atomically enable interrupts and return to userspace.  This
-        * is only ever used to return to 32-bit processes; in a
-        * 64-bit kernel, it's used for 32-on-64 compat processes, but
-        * never native 64-bit processes.  (Jump, not call.)
+        * is only used in 32-bit kernels.  64-bit kernels use
+        * usergs_sysret32 instead.
         */
        void (*irq_enable_sysexit)(void);
+#endif
 
        /*
         * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index 9f6b9341950f..2d27ebf0aed8 100644
@@ -49,7 +49,9 @@ void common(void) {
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
        OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
        OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
        OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f00c90..7563114d9c3a 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
                ret = paravirt_patch_ident_64(insnbuf, len);
 
        else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
                 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
                /* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
        .load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
        .irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da6737ba5b..0de21c62c348 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, save_fl);
                PATCH_SITE(pv_irq_ops, irq_enable);
                PATCH_SITE(pv_irq_ops, irq_disable);
-               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
                PATCH_SITE(pv_cpu_ops, usergs_sysret32);
                PATCH_SITE(pv_cpu_ops, usergs_sysret64);
                PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9f2132..3797b6b31f95 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .read_tscp = native_read_tscp,
 
        .iret = xen_iret,
-       .irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
        .usergs_sysret32 = xen_sysret32,
        .usergs_sysret64 = xen_sysret64,
+#else
+       .irq_enable_sysexit = xen_sysexit,
 #endif
 
        .load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3ee0973..a2cabb8bd6bf 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-       pushq $__USER32_DS
-       pushq %rcx
-       pushq $X86_EFLAGS_IF
-       pushq $__USER32_CS
-       pushq %rdx
-
-       pushq $0
-1:     jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
        /*
         * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -1
index 9e195c683549..c20fe29e65f4 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);
--

2.3.0

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#4 lore raw
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit kernels is unsavory?

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

See:

https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=4214a16b02971c60960afd675d03544e109e0d75

and

https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=47091e3c5b072daca29a15d2a3caf40359b0d140

--Andy

Quoted 174 lines

Thank you!

Quoted 172 lines
Quoted 164 lines

all the paravirt and Xen machinery to support it on 64-bit kernels.

---

I haven't actually tested this on Xen, but it builds for me.

 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index 5d8f987a340d..eb1eb7b70f4b 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
        swapgs
        sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-       swapgs
-       sti
-       sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b369e4..38a0ff9ef06e 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
        u64 (*read_pmc)(int counter);
        unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
        /*
         * Atomically enable interrupts and return to userspace.  This
-        * is only ever used to return to 32-bit processes; in a
-        * 64-bit kernel, it's used for 32-on-64 compat processes, but
-        * never native 64-bit processes.  (Jump, not call.)
+        * is only used in 32-bit kernels.  64-bit kernels use
+        * usergs_sysret32 instead.
         */
        void (*irq_enable_sysexit)(void);
+#endif
 
        /*
         * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index 9f6b9341950f..2d27ebf0aed8 100644
@@ -49,7 +49,9 @@ void common(void) {
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
        OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
        OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
        OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f00c90..7563114d9c3a 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
                ret = paravirt_patch_ident_64(insnbuf, len);
 
        else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
                 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
                /* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
        .load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
        .irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da6737ba5b..0de21c62c348 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, save_fl);
                PATCH_SITE(pv_irq_ops, irq_enable);
                PATCH_SITE(pv_irq_ops, irq_disable);
-               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
                PATCH_SITE(pv_cpu_ops, usergs_sysret32);
                PATCH_SITE(pv_cpu_ops, usergs_sysret64);
                PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9f2132..3797b6b31f95 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .read_tscp = native_read_tscp,
 
        .iret = xen_iret,
-       .irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
        .usergs_sysret32 = xen_sysret32,
        .usergs_sysret64 = xen_sysret64,
+#else
+       .irq_enable_sysexit = xen_sysexit,
 #endif
 
        .load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3ee0973..a2cabb8bd6bf 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-       pushq $__USER32_DS
-       pushq %rcx
-       pushq $X86_EFLAGS_IF
-       pushq $__USER32_CS
-       pushq %rdx
-
-       pushq $0
-1:     jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
        /*
         * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -1
index 9e195c683549..c20fe29e65f4 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);
--
Quoted 2 lines

2.3.0

--
Andy Lutomirski
AMA Capital Management, LLC

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#12 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit kernels is unsavory?

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

See:

https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=4214a16b02971c60960afd675d03544e109e0d75

and

https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=47091e3c5b072daca29a15d2a3caf40359b0d140

--Andy

Quoted 174 lines

Thank you!

Quoted 172 lines
Quoted 164 lines

all the paravirt and Xen machinery to support it on 64-bit kernels.

---

I haven't actually tested this on Xen, but it builds for me.

 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index 5d8f987a340d..eb1eb7b70f4b 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
        swapgs
        sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-       swapgs
-       sti
-       sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b369e4..38a0ff9ef06e 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
        u64 (*read_pmc)(int counter);
        unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
        /*
         * Atomically enable interrupts and return to userspace.  This
-        * is only ever used to return to 32-bit processes; in a
-        * 64-bit kernel, it's used for 32-on-64 compat processes, but
-        * never native 64-bit processes.  (Jump, not call.)
+        * is only used in 32-bit kernels.  64-bit kernels use
+        * usergs_sysret32 instead.
         */
        void (*irq_enable_sysexit)(void);
+#endif
 
        /*
         * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index 9f6b9341950f..2d27ebf0aed8 100644
@@ -49,7 +49,9 @@ void common(void) {
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
        OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
        OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
        OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f00c90..7563114d9c3a 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
                ret = paravirt_patch_ident_64(insnbuf, len);
 
        else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
                 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
                /* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
        .load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
        .irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da6737ba5b..0de21c62c348 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, save_fl);
                PATCH_SITE(pv_irq_ops, irq_enable);
                PATCH_SITE(pv_irq_ops, irq_disable);
-               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
                PATCH_SITE(pv_cpu_ops, usergs_sysret32);
                PATCH_SITE(pv_cpu_ops, usergs_sysret64);
                PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9f2132..3797b6b31f95 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .read_tscp = native_read_tscp,
 
        .iret = xen_iret,
-       .irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
        .usergs_sysret32 = xen_sysret32,
        .usergs_sysret64 = xen_sysret64,
+#else
+       .irq_enable_sysexit = xen_sysexit,
 #endif
 
        .load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3ee0973..a2cabb8bd6bf 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-       pushq $__USER32_DS
-       pushq %rcx
-       pushq $X86_EFLAGS_IF
-       pushq $__USER32_CS
-       pushq %rdx
-
-       pushq $0
-1:     jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
        /*
         * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -1
index 9e195c683549..c20fe29e65f4 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);
--
Quoted 2 lines

2.3.0

--
Andy Lutomirski
AMA Capital Management, LLC

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#5 lore raw
In reply to Andy Lutomirski
Quoted 9 lines · Andy Lutomirski
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit kernels is unsavory?

Quoted 8 lines

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

64bit PV kernels must bounce through Xen to switch from the kernel to the user pagetables (since both kernel and userspace are both actually running in ring3 with user pages).

As a result, exit to userspace ends up as a hypercall into Xen which has an effect very similar to an iret, but with some extra fixup in the background.

I can't forsee any Xen issues as a result of this patch.

~Andrew

#6 lore raw
Quoted 22 lines · Andrew Cooper
Quoted 9 lines · Andy Lutomirski
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit kernels is unsavory?

Quoted 8 lines

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

64bit PV kernels must bounce through Xen to switch from the kernel to the user pagetables (since both kernel and userspace are both actually running in ring3 with user pages).

Quoted 5 lines

As a result, exit to userspace ends up as a hypercall into Xen which has an effect very similar to an iret, but with some extra fixup in the background.

I can't forsee any Xen issues as a result of this patch.

I ran tip plus this patch (plus another patch that fixes an unrelated Xen regression in tip) through our test suite and it completed without problems.

I also ran some very simple 32-bit programs in a 64-bit PV guest and didn't see any problems there neither.

-boris

#7 lore raw
In reply to Andrew Cooper
Quoted 22 lines · Andrew Cooper
Quoted 9 lines · Andy Lutomirski
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit kernels is unsavory?

Quoted 8 lines

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

64bit PV kernels must bounce through Xen to switch from the kernel to the user pagetables (since both kernel and userspace are both actually running in ring3 with user pages).

Quoted 5 lines

As a result, exit to userspace ends up as a hypercall into Xen which has an effect very similar to an iret, but with some extra fixup in the background.

I can't forsee any Xen issues as a result of this patch.

I ran tip plus this patch (plus another patch that fixes an unrelated Xen regression in tip) through our test suite and it completed without problems.

I also ran some very simple 32-bit programs in a 64-bit PV guest and didn't see any problems there neither.

-boris

#8 lore raw
Quoted 42 lines · Boris Ostrovsky
Quoted 32 lines · Andrew Cooper
Quoted 17 lines · Andy Lutomirski
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit
kernels is unsavory?

Quoted 8 lines

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

64bit PV kernels must bounce through Xen to switch from the kernel to the user pagetables (since both kernel and userspace are both actually running in ring3 with user pages).

Quoted 5 lines

As a result, exit to userspace ends up as a hypercall into Xen which has an effect very similar to an iret, but with some extra fixup in the background.

I can't forsee any Xen issues as a result of this patch.

Quoted 5 lines

I ran tip plus this patch (plus another patch that fixes an unrelated Xen regression in tip) through our test suite and it completed without problems.

I also ran some very simple 32-bit programs in a 64-bit PV guest and didn't see any problems there neither.

At the risk of redundancy, did you test on Intel hardware? At least on native systems, the code in question never executes on AMD systems.

--Andy

Quoted 3 lines

-boris

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#9 lore raw
In reply to Boris Ostrovsky
Quoted 42 lines · Boris Ostrovsky
Quoted 32 lines · Andrew Cooper
Quoted 17 lines · Andy Lutomirski
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit
kernels is unsavory?

Quoted 8 lines

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

64bit PV kernels must bounce through Xen to switch from the kernel to the user pagetables (since both kernel and userspace are both actually running in ring3 with user pages).

Quoted 5 lines

As a result, exit to userspace ends up as a hypercall into Xen which has an effect very similar to an iret, but with some extra fixup in the background.

I can't forsee any Xen issues as a result of this patch.

Quoted 5 lines

I ran tip plus this patch (plus another patch that fixes an unrelated Xen regression in tip) through our test suite and it completed without problems.

I also ran some very simple 32-bit programs in a 64-bit PV guest and didn't see any problems there neither.

At the risk of redundancy, did you test on Intel hardware? At least on native systems, the code in question never executes on AMD systems.

--Andy

Quoted 3 lines

-boris

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#10 lore raw
Quoted 34 lines · Andy Lutomirski
Quoted 32 lines · Boris Ostrovsky
Quoted 29 lines · Andrew Cooper
Quoted 11 lines · Andy Lutomirski
Quoted 9 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit
kernels is unsavory?

Quoted 8 lines

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

64bit PV kernels must bounce through Xen to switch from the kernel to the user pagetables (since both kernel and userspace are both actually running in ring3 with user pages).

As a result, exit to userspace ends up as a hypercall into Xen which has an effect very similar to an iret, but with some extra fixup in the background.

I can't forsee any Xen issues as a result of this patch.

Quoted 7 lines
Quoted 5 lines

I ran tip plus this patch (plus another patch that fixes an unrelated Xen regression in tip) through our test suite and it completed without problems.

I also ran some very simple 32-bit programs in a 64-bit PV guest and didn't see any problems there neither.

At the risk of redundancy, did you test on Intel hardware? At least on native systems, the code in question never executes on AMD systems.

Yes, the tests ran on Intel. I left them scheduled for overnight runs too and that will be executed on both AMD and Intel.

-boris

#11 lore raw
In reply to Andy Lutomirski
Quoted 34 lines · Andy Lutomirski
Quoted 32 lines · Boris Ostrovsky
Quoted 29 lines · Andrew Cooper
Quoted 11 lines · Andy Lutomirski
Quoted 9 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Andy Lutomirski

[cc: Boris and Konrad. Whoops]

Quoted 1 line · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove

Is there an commit (or name of patch) that explains why 32-bit-user-space-on-64-bit
kernels is unsavory?

Quoted 8 lines

sysexit never tasted very good :-p

We're (hopefully) not breaking 32-bit-user-space-on-64-bit, but we're trying an unconventional approach to making the code faster and less scary. As a result, 64-bit kernels won't use sysexit any more. Hopefully Xen is okay with the slightly sneaky thing we're doing. AFAICT Xen thinks of sysretl and sysexit as slightly funny irets, so I don't expect there to be any problem.

64bit PV kernels must bounce through Xen to switch from the kernel to the user pagetables (since both kernel and userspace are both actually running in ring3 with user pages).

As a result, exit to userspace ends up as a hypercall into Xen which has an effect very similar to an iret, but with some extra fixup in the background.

I can't forsee any Xen issues as a result of this patch.

Quoted 7 lines
Quoted 5 lines

I ran tip plus this patch (plus another patch that fixes an unrelated Xen regression in tip) through our test suite and it completed without problems.

I also ran some very simple 32-bit programs in a 64-bit PV guest and didn't see any problems there neither.

At the risk of redundancy, did you test on Intel hardware? At least on native systems, the code in question never executes on AMD systems.

Yes, the tests ran on Intel. I left them scheduled for overnight runs too and that will be executed on both AMD and Intel.

-boris

#13 lore raw
In reply to Andy Lutomirski
Quoted 4 lines · Andy Lutomirski

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove all the paravirt and Xen machinery to support it on 64-bit kernels.

Hi, Ingo,

Can you pick this up in -tip? It cleans up code that would otherwise be unreachable in 4.1, but it doesn't fix any bugs, so waiting for 4.2 would be fine as well.

--Andy

Quoted 163 lines

---

I haven't actually tested this on Xen, but it builds for me.

 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index 5d8f987a340d..eb1eb7b70f4b 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
        swapgs
        sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-       swapgs
-       sti
-       sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b369e4..38a0ff9ef06e 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
        u64 (*read_pmc)(int counter);
        unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
        /*
         * Atomically enable interrupts and return to userspace.  This
-        * is only ever used to return to 32-bit processes; in a
-        * 64-bit kernel, it's used for 32-on-64 compat processes, but
-        * never native 64-bit processes.  (Jump, not call.)
+        * is only used in 32-bit kernels.  64-bit kernels use
+        * usergs_sysret32 instead.
         */
        void (*irq_enable_sysexit)(void);
+#endif
 
        /*
         * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index 9f6b9341950f..2d27ebf0aed8 100644
@@ -49,7 +49,9 @@ void common(void) {
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
        OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
        OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
        OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f00c90..7563114d9c3a 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
                ret = paravirt_patch_ident_64(insnbuf, len);
 
        else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
                 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
                 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
                /* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
        .load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
        .irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da6737ba5b..0de21c62c348 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, save_fl);
                PATCH_SITE(pv_irq_ops, irq_enable);
                PATCH_SITE(pv_irq_ops, irq_disable);
-               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
                PATCH_SITE(pv_cpu_ops, usergs_sysret32);
                PATCH_SITE(pv_cpu_ops, usergs_sysret64);
                PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9f2132..3797b6b31f95 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .read_tscp = native_read_tscp,
 
        .iret = xen_iret,
-       .irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
        .usergs_sysret32 = xen_sysret32,
        .usergs_sysret64 = xen_sysret64,
+#else
+       .irq_enable_sysexit = xen_sysexit,
 #endif
 
        .load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3ee0973..a2cabb8bd6bf 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-       pushq $__USER32_DS
-       pushq %rcx
-       pushq $X86_EFLAGS_IF
-       pushq $__USER32_CS
-       pushq %rdx
-
-       pushq $0
-1:     jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
        /*
         * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -1
index 9e195c683549..c20fe29e65f4 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);
--

2.3.0

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
maintainer Applied
#14 lore raw
Quoted 3 lines · Andy Lutomirski

Can you pick this up in -tip? It cleans up code that would otherwise be unreachable in 4.1, but it doesn't fix any bugs, so waiting for 4.2 would be fine as well.

Applied, thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#15 lore raw

[tip:x86/asm] x86, paravirt, xen: Remove the 64-bit -> irq_enable_sysexit() pvop

In reply to Andy Lutomirski
x86, paravirt, xen: Remove the 64-bit ->irq_enable_sysexit() pvop
Commit-ID:  aac82d319148c6a84e1bf90b86d3e0ec8bf0ee38
Gitweb:     http://git.kernel.org/tip/aac82d319148c6a84e1bf90b86d3e0ec8bf0ee38
Author:     Andy Lutomirski <[email protected]>
AuthorDate: Fri, 3 Apr 2015 15:51:54 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 22 Apr 2015 08:07:45 +0200

x86, paravirt, xen: Remove the 64-bit ->irq_enable_sysexit() pvop

We don't use irq_enable_sysexit on 64-bit kernels any more. Remove all the paravirt and Xen machinery to support it on 64-bit kernels.

---
 arch/x86/ia32/ia32entry.S             |  6 ------
 arch/x86/include/asm/paravirt_types.h |  7 ++++---
 arch/x86/kernel/asm-offsets.c         |  2 ++
 arch/x86/kernel/paravirt.c            |  4 +++-
 arch/x86/kernel/paravirt_patch_64.c   |  1 -
 arch/x86/xen/enlighten.c              |  3 ++-
 arch/x86/xen/xen-asm_64.S             | 16 ----------------
 arch/x86/xen/xen-ops.h                |  2 ++
 8 files changed, 13 insertions(+), 28 deletions(-)
arch/x86/ia32/ia32entry.S +0 -6
index a821b1c..3cdb9ea 100644
@@ -77,12 +77,6 @@ ENTRY(native_usergs_sysret32)
 	swapgs
 	sysretl
 ENDPROC(native_usergs_sysret32)
-
-ENTRY(native_irq_enable_sysexit)
-	swapgs
-	sti
-	sysexit
-ENDPROC(native_irq_enable_sysexit)
 #endif
 
 /*
arch/x86/include/asm/paravirt_types.h +4 -3
index 7549b8b..38a0ff9 100644
@@ -160,13 +160,14 @@ struct pv_cpu_ops {
 	u64 (*read_pmc)(int counter);
 	unsigned long long (*read_tscp)(unsigned int *aux);
 
+#ifdef CONFIG_X86_32
 	/*
 	 * Atomically enable interrupts and return to userspace.  This
-	 * is only ever used to return to 32-bit processes; in a
-	 * 64-bit kernel, it's used for 32-on-64 compat processes, but
-	 * never native 64-bit processes.  (Jump, not call.)
+	 * is only used in 32-bit kernels.  64-bit kernels use
+	 * usergs_sysret32 instead.
 	 */
 	void (*irq_enable_sysexit)(void);
+#endif
 
 	/*
 	 * Switch to usermode gs and return to 64-bit usermode using
arch/x86/kernel/asm-offsets.c +2 -0
index b27f6ec..8e3d22a1 100644
@@ -68,7 +68,9 @@ void common(void) {
 	OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
 	OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
 	OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
+#ifdef CONFIG_X86_32
 	OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
+#endif
 	OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
 	OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
arch/x86/kernel/paravirt.c +3 -1
index 548d25f..7563114 100644
@@ -154,7 +154,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
 		ret = paravirt_patch_ident_64(insnbuf, len);
 
 	else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
+#ifdef CONFIG_X86_32
 		 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+#endif
 		 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
 		 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
 		/* If operation requires a jmp, then jmp */
@@ -371,7 +373,7 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
 
 	.load_sp0 = native_load_sp0,
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+#if defined(CONFIG_X86_32)
 	.irq_enable_sysexit = native_irq_enable_sysexit,
 #endif
 #ifdef CONFIG_X86_64
arch/x86/kernel/paravirt_patch_64.c +0 -1
index a1da673..0de21c6 100644
@@ -49,7 +49,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
 		PATCH_SITE(pv_irq_ops, save_fl);
 		PATCH_SITE(pv_irq_ops, irq_enable);
 		PATCH_SITE(pv_irq_ops, irq_disable);
-		PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
 		PATCH_SITE(pv_cpu_ops, usergs_sysret32);
 		PATCH_SITE(pv_cpu_ops, usergs_sysret64);
 		PATCH_SITE(pv_cpu_ops, swapgs);
arch/x86/xen/enlighten.c +2 -1
index 81665c9..3797b6b 100644
@@ -1267,10 +1267,11 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
 	.read_tscp = native_read_tscp,
 
 	.iret = xen_iret,
-	.irq_enable_sysexit = xen_sysexit,
 #ifdef CONFIG_X86_64
 	.usergs_sysret32 = xen_sysret32,
 	.usergs_sysret64 = xen_sysret64,
+#else
+	.irq_enable_sysexit = xen_sysexit,
 #endif
 
 	.load_tr_desc = paravirt_nop,
arch/x86/xen/xen-asm_64.S +0 -16
index 985fc3e..a2cabb8 100644
@@ -47,22 +47,6 @@ ENTRY(xen_iret)
 ENDPATCH(xen_iret)
 RELOC(xen_iret, 1b+1)
 
-/*
- * sysexit is not used for 64-bit processes, so it's only ever used to
- * return to 32-bit compat userspace.
- */
-ENTRY(xen_sysexit)
-	pushq $__USER32_DS
-	pushq %rcx
-	pushq $X86_EFLAGS_IF
-	pushq $__USER32_CS
-	pushq %rdx
-
-	pushq $0
-1:	jmp hypercall_iret
-ENDPATCH(xen_sysexit)
-RELOC(xen_sysexit, 1b+1)
-
 ENTRY(xen_sysret64)
 	/*
 	 * We're already on the usermode stack at this point, but
arch/x86/xen/xen-ops.h +2 -0
index 9e195c6..c20fe29 100644
@@ -134,7 +134,9 @@ DECL_ASM(void, xen_restore_fl_direct, unsigned long);
 
 /* These are not functions, and cannot be called normally */
 __visible void xen_iret(void);
+#ifdef CONFIG_X86_32
 __visible void xen_sysexit(void);
+#endif
 __visible void xen_sysret32(void);
 __visible void xen_sysret64(void);
 __visible void xen_adjust_exception_frame(void);