All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/xen: support early interrupts in xen pv guests
@ 2017-11-24  8:42 Juergen Gross
  2017-11-24  8:52 ` Juergen Gross
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Juergen Gross @ 2017-11-24  8:42 UTC (permalink / raw)
  To: linux-kernel, xen-devel, x86
  Cc: boris.ostrovsky, hpa, tglx, mingo, Juergen Gross

Add early interrupt handlers activated by idt_setup_early_handler() to
the handlers supported by Xen pv guests. This will allow for early
WARN() calls not crashing the guest.

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/include/asm/segment.h | 12 ++++++++++++
 arch/x86/mm/extable.c          |  4 +++-
 arch/x86/xen/enlighten_pv.c    | 37 ++++++++++++++++++++++++-------------
 arch/x86/xen/xen-asm_64.S      | 14 ++++++++++++++
 4 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
index b20f9d623f9c..8f09012b92e7 100644
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -236,11 +236,23 @@
  */
 #define EARLY_IDT_HANDLER_SIZE 9
 
+/*
+ * xen_early_idt_handler_array is for Xen pv guests: for each entry in
+ * early_idt_handler_array it contains a prequel in the form of
+ * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
+ * max 8 bytes.
+ */
+#define XEN_EARLY_IDT_HANDLER_SIZE 8
+
 #ifndef __ASSEMBLY__
 
 extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE];
 extern void early_ignore_irq(void);
 
+#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
+extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE];
+#endif
+
 /*
  * Load a segment. Fall back on loading the zero segment if something goes
  * wrong.  This variant assumes that loading zero fully clears the segment.
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 3321b446b66c..88754bfd425f 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,6 +1,7 @@
 #include <linux/extable.h>
 #include <linux/uaccess.h>
 #include <linux/sched/debug.h>
+#include <xen/xen.h>
 
 #include <asm/fpu/internal.h>
 #include <asm/traps.h>
@@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
 	 * Old CPUs leave the high bits of CS on the stack
 	 * undefined.  I'm not sure which CPUs do this, but at least
 	 * the 486 DX works this way.
+	 * Xen pv domains are not using the default __KERNEL_CS.
 	 */
-	if (regs->cs != __KERNEL_CS)
+	if (!xen_pv_domain() && regs->cs != __KERNEL_CS)
 		goto fail;
 
 	/*
diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 5b2b3f3f6531..f2414c6c5e7c 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] = {
 	{ simd_coprocessor_error,      xen_simd_coprocessor_error,      false },
 };
 
-static bool get_trap_addr(void **addr, unsigned int ist)
+static bool __ref get_trap_addr(void **addr, unsigned int ist)
 {
 	unsigned int nr;
 	bool ist_okay = false;
@@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int ist)
 		}
 	}
 
+	if (nr == ARRAY_SIZE(trap_array) &&
+	    *addr >= (void *)early_idt_handler_array[0] &&
+	    *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) {
+		nr = (*addr - (void *)early_idt_handler_array[0]) /
+		     EARLY_IDT_HANDLER_SIZE;
+		*addr = (void *)xen_early_idt_handler_array[nr];
+	}
+
 	if (WARN_ON(ist != 0 && !ist_okay))
 		return false;
 
@@ -1262,6 +1270,21 @@ asmlinkage __visible void __init xen_start_kernel(void)
 	xen_setup_gdt(0);
 
 	xen_init_irq_ops();
+
+	/* Let's presume PV guests always boot on vCPU with id 0. */
+	per_cpu(xen_vcpu_id, 0) = 0;
+
+	/*
+	 * Setup xen_vcpu early because idt_setup_early_handler needs it for
+	 * local_irq_disable(), irqs_disabled().
+	 *
+	 * Don't do the full vcpu_info placement stuff until we have
+	 * the cpu_possible_mask and a non-dummy shared_info.
+	 */
+	xen_vcpu_info_reset(0);
+
+	idt_setup_early_handler();
+
 	xen_init_capabilities();
 
 #ifdef CONFIG_X86_LOCAL_APIC
@@ -1295,18 +1318,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
 	 */
 	acpi_numa = -1;
 #endif
-	/* Let's presume PV guests always boot on vCPU with id 0. */
-	per_cpu(xen_vcpu_id, 0) = 0;
-
-	/*
-	 * Setup xen_vcpu early because start_kernel needs it for
-	 * local_irq_disable(), irqs_disabled().
-	 *
-	 * Don't do the full vcpu_info placement stuff until we have
-	 * the cpu_possible_mask and a non-dummy shared_info.
-	 */
-	xen_vcpu_info_reset(0);
-
 	WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv));
 
 	local_irq_disable();
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index 8a10c9a9e2b5..417b339e5c8e 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -15,6 +15,7 @@
 
 #include <xen/interface/xen.h>
 
+#include <linux/init.h>
 #include <linux/linkage.h>
 
 .macro xen_pv_trap name
@@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat
 #endif
 xen_pv_trap hypervisor_callback
 
+	__INIT
+ENTRY(xen_early_idt_handler_array)
+	i = 0
+	.rept NUM_EXCEPTION_VECTORS
+	pop %rcx
+	pop %r11
+	jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
+	i = i + 1
+	.fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
+	.endr
+END(xen_early_idt_handler_array)
+	__FINIT
+
 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
 /*
  * Xen64 iret frame:
-- 
2.12.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] x86/xen: support early interrupts in xen pv guests
  2017-11-24  8:42 [PATCH] x86/xen: support early interrupts in xen pv guests Juergen Gross
  2017-11-24  8:52 ` Juergen Gross
@ 2017-11-24  8:52 ` Juergen Gross
  2017-11-24 15:50   ` Andy Lutomirski
  2017-11-24 15:50   ` Andy Lutomirski
  2017-11-27 23:34 ` [tip:x86/urgent] x86/xen: Support " tip-bot for Juergen Gross
  2 siblings, 2 replies; 9+ messages in thread
From: Juergen Gross @ 2017-11-24  8:52 UTC (permalink / raw)
  To: linux-kernel, xen-devel, x86
  Cc: boris.ostrovsky, hpa, tglx, mingo, Andrew Lutomirski

Sorry, Andy, forgot to Cc: you...

On 24/11/17 09:42, Juergen Gross wrote:
> Add early interrupt handlers activated by idt_setup_early_handler() to
> the handlers supported by Xen pv guests. This will allow for early
> WARN() calls not crashing the guest.
> 
> Suggested-by: Andy Lutomirski <luto@kernel.org>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  arch/x86/include/asm/segment.h | 12 ++++++++++++
>  arch/x86/mm/extable.c          |  4 +++-
>  arch/x86/xen/enlighten_pv.c    | 37 ++++++++++++++++++++++++-------------
>  arch/x86/xen/xen-asm_64.S      | 14 ++++++++++++++
>  4 files changed, 53 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
> index b20f9d623f9c..8f09012b92e7 100644
> --- a/arch/x86/include/asm/segment.h
> +++ b/arch/x86/include/asm/segment.h
> @@ -236,11 +236,23 @@
>   */
>  #define EARLY_IDT_HANDLER_SIZE 9
>  
> +/*
> + * xen_early_idt_handler_array is for Xen pv guests: for each entry in
> + * early_idt_handler_array it contains a prequel in the form of
> + * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
> + * max 8 bytes.
> + */
> +#define XEN_EARLY_IDT_HANDLER_SIZE 8
> +
>  #ifndef __ASSEMBLY__
>  
>  extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE];
>  extern void early_ignore_irq(void);
>  
> +#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
> +extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE];
> +#endif
> +
>  /*
>   * Load a segment. Fall back on loading the zero segment if something goes
>   * wrong.  This variant assumes that loading zero fully clears the segment.
> diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
> index 3321b446b66c..88754bfd425f 100644
> --- a/arch/x86/mm/extable.c
> +++ b/arch/x86/mm/extable.c
> @@ -1,6 +1,7 @@
>  #include <linux/extable.h>
>  #include <linux/uaccess.h>
>  #include <linux/sched/debug.h>
> +#include <xen/xen.h>
>  
>  #include <asm/fpu/internal.h>
>  #include <asm/traps.h>
> @@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
>  	 * Old CPUs leave the high bits of CS on the stack
>  	 * undefined.  I'm not sure which CPUs do this, but at least
>  	 * the 486 DX works this way.
> +	 * Xen pv domains are not using the default __KERNEL_CS.
>  	 */
> -	if (regs->cs != __KERNEL_CS)
> +	if (!xen_pv_domain() && regs->cs != __KERNEL_CS)
>  		goto fail;
>  
>  	/*
> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
> index 5b2b3f3f6531..f2414c6c5e7c 100644
> --- a/arch/x86/xen/enlighten_pv.c
> +++ b/arch/x86/xen/enlighten_pv.c
> @@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] = {
>  	{ simd_coprocessor_error,      xen_simd_coprocessor_error,      false },
>  };
>  
> -static bool get_trap_addr(void **addr, unsigned int ist)
> +static bool __ref get_trap_addr(void **addr, unsigned int ist)
>  {
>  	unsigned int nr;
>  	bool ist_okay = false;
> @@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int ist)
>  		}
>  	}
>  
> +	if (nr == ARRAY_SIZE(trap_array) &&
> +	    *addr >= (void *)early_idt_handler_array[0] &&
> +	    *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) {
> +		nr = (*addr - (void *)early_idt_handler_array[0]) /
> +		     EARLY_IDT_HANDLER_SIZE;
> +		*addr = (void *)xen_early_idt_handler_array[nr];
> +	}
> +
>  	if (WARN_ON(ist != 0 && !ist_okay))
>  		return false;
>  
> @@ -1262,6 +1270,21 @@ asmlinkage __visible void __init xen_start_kernel(void)
>  	xen_setup_gdt(0);
>  
>  	xen_init_irq_ops();
> +
> +	/* Let's presume PV guests always boot on vCPU with id 0. */
> +	per_cpu(xen_vcpu_id, 0) = 0;
> +
> +	/*
> +	 * Setup xen_vcpu early because idt_setup_early_handler needs it for
> +	 * local_irq_disable(), irqs_disabled().
> +	 *
> +	 * Don't do the full vcpu_info placement stuff until we have
> +	 * the cpu_possible_mask and a non-dummy shared_info.
> +	 */
> +	xen_vcpu_info_reset(0);
> +
> +	idt_setup_early_handler();
> +
>  	xen_init_capabilities();
>  
>  #ifdef CONFIG_X86_LOCAL_APIC
> @@ -1295,18 +1318,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
>  	 */
>  	acpi_numa = -1;
>  #endif
> -	/* Let's presume PV guests always boot on vCPU with id 0. */
> -	per_cpu(xen_vcpu_id, 0) = 0;
> -
> -	/*
> -	 * Setup xen_vcpu early because start_kernel needs it for
> -	 * local_irq_disable(), irqs_disabled().
> -	 *
> -	 * Don't do the full vcpu_info placement stuff until we have
> -	 * the cpu_possible_mask and a non-dummy shared_info.
> -	 */
> -	xen_vcpu_info_reset(0);
> -
>  	WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv));
>  
>  	local_irq_disable();
> diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
> index 8a10c9a9e2b5..417b339e5c8e 100644
> --- a/arch/x86/xen/xen-asm_64.S
> +++ b/arch/x86/xen/xen-asm_64.S
> @@ -15,6 +15,7 @@
>  
>  #include <xen/interface/xen.h>
>  
> +#include <linux/init.h>
>  #include <linux/linkage.h>
>  
>  .macro xen_pv_trap name
> @@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat
>  #endif
>  xen_pv_trap hypervisor_callback
>  
> +	__INIT
> +ENTRY(xen_early_idt_handler_array)
> +	i = 0
> +	.rept NUM_EXCEPTION_VECTORS
> +	pop %rcx
> +	pop %r11
> +	jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
> +	i = i + 1
> +	.fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
> +	.endr
> +END(xen_early_idt_handler_array)
> +	__FINIT
> +
>  hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
>  /*
>   * Xen64 iret frame:
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] x86/xen: support early interrupts in xen pv guests
  2017-11-24  8:42 [PATCH] x86/xen: support early interrupts in xen pv guests Juergen Gross
@ 2017-11-24  8:52 ` Juergen Gross
  2017-11-24  8:52 ` Juergen Gross
  2017-11-27 23:34 ` [tip:x86/urgent] x86/xen: Support " tip-bot for Juergen Gross
  2 siblings, 0 replies; 9+ messages in thread
From: Juergen Gross @ 2017-11-24  8:52 UTC (permalink / raw)
  To: linux-kernel, xen-devel, x86
  Cc: boris.ostrovsky, mingo, tglx, Andrew Lutomirski, hpa

Sorry, Andy, forgot to Cc: you...

On 24/11/17 09:42, Juergen Gross wrote:
> Add early interrupt handlers activated by idt_setup_early_handler() to
> the handlers supported by Xen pv guests. This will allow for early
> WARN() calls not crashing the guest.
> 
> Suggested-by: Andy Lutomirski <luto@kernel.org>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  arch/x86/include/asm/segment.h | 12 ++++++++++++
>  arch/x86/mm/extable.c          |  4 +++-
>  arch/x86/xen/enlighten_pv.c    | 37 ++++++++++++++++++++++++-------------
>  arch/x86/xen/xen-asm_64.S      | 14 ++++++++++++++
>  4 files changed, 53 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
> index b20f9d623f9c..8f09012b92e7 100644
> --- a/arch/x86/include/asm/segment.h
> +++ b/arch/x86/include/asm/segment.h
> @@ -236,11 +236,23 @@
>   */
>  #define EARLY_IDT_HANDLER_SIZE 9
>  
> +/*
> + * xen_early_idt_handler_array is for Xen pv guests: for each entry in
> + * early_idt_handler_array it contains a prequel in the form of
> + * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
> + * max 8 bytes.
> + */
> +#define XEN_EARLY_IDT_HANDLER_SIZE 8
> +
>  #ifndef __ASSEMBLY__
>  
>  extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE];
>  extern void early_ignore_irq(void);
>  
> +#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
> +extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE];
> +#endif
> +
>  /*
>   * Load a segment. Fall back on loading the zero segment if something goes
>   * wrong.  This variant assumes that loading zero fully clears the segment.
> diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
> index 3321b446b66c..88754bfd425f 100644
> --- a/arch/x86/mm/extable.c
> +++ b/arch/x86/mm/extable.c
> @@ -1,6 +1,7 @@
>  #include <linux/extable.h>
>  #include <linux/uaccess.h>
>  #include <linux/sched/debug.h>
> +#include <xen/xen.h>
>  
>  #include <asm/fpu/internal.h>
>  #include <asm/traps.h>
> @@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
>  	 * Old CPUs leave the high bits of CS on the stack
>  	 * undefined.  I'm not sure which CPUs do this, but at least
>  	 * the 486 DX works this way.
> +	 * Xen pv domains are not using the default __KERNEL_CS.
>  	 */
> -	if (regs->cs != __KERNEL_CS)
> +	if (!xen_pv_domain() && regs->cs != __KERNEL_CS)
>  		goto fail;
>  
>  	/*
> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
> index 5b2b3f3f6531..f2414c6c5e7c 100644
> --- a/arch/x86/xen/enlighten_pv.c
> +++ b/arch/x86/xen/enlighten_pv.c
> @@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] = {
>  	{ simd_coprocessor_error,      xen_simd_coprocessor_error,      false },
>  };
>  
> -static bool get_trap_addr(void **addr, unsigned int ist)
> +static bool __ref get_trap_addr(void **addr, unsigned int ist)
>  {
>  	unsigned int nr;
>  	bool ist_okay = false;
> @@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int ist)
>  		}
>  	}
>  
> +	if (nr == ARRAY_SIZE(trap_array) &&
> +	    *addr >= (void *)early_idt_handler_array[0] &&
> +	    *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) {
> +		nr = (*addr - (void *)early_idt_handler_array[0]) /
> +		     EARLY_IDT_HANDLER_SIZE;
> +		*addr = (void *)xen_early_idt_handler_array[nr];
> +	}
> +
>  	if (WARN_ON(ist != 0 && !ist_okay))
>  		return false;
>  
> @@ -1262,6 +1270,21 @@ asmlinkage __visible void __init xen_start_kernel(void)
>  	xen_setup_gdt(0);
>  
>  	xen_init_irq_ops();
> +
> +	/* Let's presume PV guests always boot on vCPU with id 0. */
> +	per_cpu(xen_vcpu_id, 0) = 0;
> +
> +	/*
> +	 * Setup xen_vcpu early because idt_setup_early_handler needs it for
> +	 * local_irq_disable(), irqs_disabled().
> +	 *
> +	 * Don't do the full vcpu_info placement stuff until we have
> +	 * the cpu_possible_mask and a non-dummy shared_info.
> +	 */
> +	xen_vcpu_info_reset(0);
> +
> +	idt_setup_early_handler();
> +
>  	xen_init_capabilities();
>  
>  #ifdef CONFIG_X86_LOCAL_APIC
> @@ -1295,18 +1318,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
>  	 */
>  	acpi_numa = -1;
>  #endif
> -	/* Let's presume PV guests always boot on vCPU with id 0. */
> -	per_cpu(xen_vcpu_id, 0) = 0;
> -
> -	/*
> -	 * Setup xen_vcpu early because start_kernel needs it for
> -	 * local_irq_disable(), irqs_disabled().
> -	 *
> -	 * Don't do the full vcpu_info placement stuff until we have
> -	 * the cpu_possible_mask and a non-dummy shared_info.
> -	 */
> -	xen_vcpu_info_reset(0);
> -
>  	WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv));
>  
>  	local_irq_disable();
> diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
> index 8a10c9a9e2b5..417b339e5c8e 100644
> --- a/arch/x86/xen/xen-asm_64.S
> +++ b/arch/x86/xen/xen-asm_64.S
> @@ -15,6 +15,7 @@
>  
>  #include <xen/interface/xen.h>
>  
> +#include <linux/init.h>
>  #include <linux/linkage.h>
>  
>  .macro xen_pv_trap name
> @@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat
>  #endif
>  xen_pv_trap hypervisor_callback
>  
> +	__INIT
> +ENTRY(xen_early_idt_handler_array)
> +	i = 0
> +	.rept NUM_EXCEPTION_VECTORS
> +	pop %rcx
> +	pop %r11
> +	jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
> +	i = i + 1
> +	.fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
> +	.endr
> +END(xen_early_idt_handler_array)
> +	__FINIT
> +
>  hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
>  /*
>   * Xen64 iret frame:
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] x86/xen: support early interrupts in xen pv guests
  2017-11-24  8:52 ` Juergen Gross
  2017-11-24 15:50   ` Andy Lutomirski
@ 2017-11-24 15:50   ` Andy Lutomirski
  2017-11-24 23:25     ` Thomas Gleixner
  2017-11-24 23:25     ` Thomas Gleixner
  1 sibling, 2 replies; 9+ messages in thread
From: Andy Lutomirski @ 2017-11-24 15:50 UTC (permalink / raw)
  To: Juergen Gross
  Cc: linux-kernel, xen-devel, X86 ML, Boris Ostrovsky, H. Peter Anvin,
	Thomas Gleixner, Ingo Molnar, Andrew Lutomirski

On Fri, Nov 24, 2017 at 12:52 AM, Juergen Gross <jgross@suse.com> wrote:
> Sorry, Andy, forgot to Cc: you...
>
> On 24/11/17 09:42, Juergen Gross wrote:
>> Add early interrupt handlers activated by idt_setup_early_handler() to
>> the handlers supported by Xen pv guests. This will allow for early
>> WARN() calls not crashing the guest.

Nice!  It would be great to get this into 4.15.

>>
>> Suggested-by: Andy Lutomirski <luto@kernel.org>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> ---
>>  arch/x86/include/asm/segment.h | 12 ++++++++++++
>>  arch/x86/mm/extable.c          |  4 +++-
>>  arch/x86/xen/enlighten_pv.c    | 37 ++++++++++++++++++++++++-------------
>>  arch/x86/xen/xen-asm_64.S      | 14 ++++++++++++++
>>  4 files changed, 53 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
>> index b20f9d623f9c..8f09012b92e7 100644
>> --- a/arch/x86/include/asm/segment.h
>> +++ b/arch/x86/include/asm/segment.h
>> @@ -236,11 +236,23 @@
>>   */
>>  #define EARLY_IDT_HANDLER_SIZE 9
>>
>> +/*
>> + * xen_early_idt_handler_array is for Xen pv guests: for each entry in
>> + * early_idt_handler_array it contains a prequel in the form of
>> + * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
>> + * max 8 bytes.
>> + */
>> +#define XEN_EARLY_IDT_HANDLER_SIZE 8
>> +
>>  #ifndef __ASSEMBLY__
>>
>>  extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE];
>>  extern void early_ignore_irq(void);
>>
>> +#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
>> +extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE];
>> +#endif
>> +
>>  /*
>>   * Load a segment. Fall back on loading the zero segment if something goes
>>   * wrong.  This variant assumes that loading zero fully clears the segment.
>> diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
>> index 3321b446b66c..88754bfd425f 100644
>> --- a/arch/x86/mm/extable.c
>> +++ b/arch/x86/mm/extable.c
>> @@ -1,6 +1,7 @@
>>  #include <linux/extable.h>
>>  #include <linux/uaccess.h>
>>  #include <linux/sched/debug.h>
>> +#include <xen/xen.h>
>>
>>  #include <asm/fpu/internal.h>
>>  #include <asm/traps.h>
>> @@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
>>        * Old CPUs leave the high bits of CS on the stack
>>        * undefined.  I'm not sure which CPUs do this, but at least
>>        * the 486 DX works this way.
>> +      * Xen pv domains are not using the default __KERNEL_CS.
>>        */
>> -     if (regs->cs != __KERNEL_CS)
>> +     if (!xen_pv_domain() && regs->cs != __KERNEL_CS)
>>               goto fail;
>>
>>       /*
>> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
>> index 5b2b3f3f6531..f2414c6c5e7c 100644
>> --- a/arch/x86/xen/enlighten_pv.c
>> +++ b/arch/x86/xen/enlighten_pv.c
>> @@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] = {
>>       { simd_coprocessor_error,      xen_simd_coprocessor_error,      false },
>>  };
>>
>> -static bool get_trap_addr(void **addr, unsigned int ist)
>> +static bool __ref get_trap_addr(void **addr, unsigned int ist)
>>  {
>>       unsigned int nr;
>>       bool ist_okay = false;
>> @@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int ist)
>>               }
>>       }
>>
>> +     if (nr == ARRAY_SIZE(trap_array) &&
>> +         *addr >= (void *)early_idt_handler_array[0] &&
>> +         *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) {
>> +             nr = (*addr - (void *)early_idt_handler_array[0]) /
>> +                  EARLY_IDT_HANDLER_SIZE;
>> +             *addr = (void *)xen_early_idt_handler_array[nr];
>> +     }
>> +
>>       if (WARN_ON(ist != 0 && !ist_okay))
>>               return false;
>>
>> @@ -1262,6 +1270,21 @@ asmlinkage __visible void __init xen_start_kernel(void)
>>       xen_setup_gdt(0);
>>
>>       xen_init_irq_ops();
>> +
>> +     /* Let's presume PV guests always boot on vCPU with id 0. */
>> +     per_cpu(xen_vcpu_id, 0) = 0;
>> +
>> +     /*
>> +      * Setup xen_vcpu early because idt_setup_early_handler needs it for
>> +      * local_irq_disable(), irqs_disabled().
>> +      *
>> +      * Don't do the full vcpu_info placement stuff until we have
>> +      * the cpu_possible_mask and a non-dummy shared_info.
>> +      */
>> +     xen_vcpu_info_reset(0);
>> +
>> +     idt_setup_early_handler();
>> +
>>       xen_init_capabilities();
>>
>>  #ifdef CONFIG_X86_LOCAL_APIC
>> @@ -1295,18 +1318,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
>>        */
>>       acpi_numa = -1;
>>  #endif
>> -     /* Let's presume PV guests always boot on vCPU with id 0. */
>> -     per_cpu(xen_vcpu_id, 0) = 0;
>> -
>> -     /*
>> -      * Setup xen_vcpu early because start_kernel needs it for
>> -      * local_irq_disable(), irqs_disabled().
>> -      *
>> -      * Don't do the full vcpu_info placement stuff until we have
>> -      * the cpu_possible_mask and a non-dummy shared_info.
>> -      */
>> -     xen_vcpu_info_reset(0);
>> -
>>       WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv));
>>
>>       local_irq_disable();
>> diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
>> index 8a10c9a9e2b5..417b339e5c8e 100644
>> --- a/arch/x86/xen/xen-asm_64.S
>> +++ b/arch/x86/xen/xen-asm_64.S
>> @@ -15,6 +15,7 @@
>>
>>  #include <xen/interface/xen.h>
>>
>> +#include <linux/init.h>
>>  #include <linux/linkage.h>
>>
>>  .macro xen_pv_trap name
>> @@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat
>>  #endif
>>  xen_pv_trap hypervisor_callback
>>
>> +     __INIT
>> +ENTRY(xen_early_idt_handler_array)
>> +     i = 0
>> +     .rept NUM_EXCEPTION_VECTORS
>> +     pop %rcx
>> +     pop %r11
>> +     jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
>> +     i = i + 1
>> +     .fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
>> +     .endr
>> +END(xen_early_idt_handler_array)
>> +     __FINIT
>> +
>>  hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
>>  /*
>>   * Xen64 iret frame:
>>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] x86/xen: support early interrupts in xen pv guests
  2017-11-24  8:52 ` Juergen Gross
@ 2017-11-24 15:50   ` Andy Lutomirski
  2017-11-24 15:50   ` Andy Lutomirski
  1 sibling, 0 replies; 9+ messages in thread
From: Andy Lutomirski @ 2017-11-24 15:50 UTC (permalink / raw)
  To: Juergen Gross
  Cc: X86 ML, linux-kernel, Ingo Molnar, Andrew Lutomirski,
	H. Peter Anvin, xen-devel, Boris Ostrovsky, Thomas Gleixner

On Fri, Nov 24, 2017 at 12:52 AM, Juergen Gross <jgross@suse.com> wrote:
> Sorry, Andy, forgot to Cc: you...
>
> On 24/11/17 09:42, Juergen Gross wrote:
>> Add early interrupt handlers activated by idt_setup_early_handler() to
>> the handlers supported by Xen pv guests. This will allow for early
>> WARN() calls not crashing the guest.

Nice!  It would be great to get this into 4.15.

>>
>> Suggested-by: Andy Lutomirski <luto@kernel.org>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> ---
>>  arch/x86/include/asm/segment.h | 12 ++++++++++++
>>  arch/x86/mm/extable.c          |  4 +++-
>>  arch/x86/xen/enlighten_pv.c    | 37 ++++++++++++++++++++++++-------------
>>  arch/x86/xen/xen-asm_64.S      | 14 ++++++++++++++
>>  4 files changed, 53 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
>> index b20f9d623f9c..8f09012b92e7 100644
>> --- a/arch/x86/include/asm/segment.h
>> +++ b/arch/x86/include/asm/segment.h
>> @@ -236,11 +236,23 @@
>>   */
>>  #define EARLY_IDT_HANDLER_SIZE 9
>>
>> +/*
>> + * xen_early_idt_handler_array is for Xen pv guests: for each entry in
>> + * early_idt_handler_array it contains a prequel in the form of
>> + * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
>> + * max 8 bytes.
>> + */
>> +#define XEN_EARLY_IDT_HANDLER_SIZE 8
>> +
>>  #ifndef __ASSEMBLY__
>>
>>  extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE];
>>  extern void early_ignore_irq(void);
>>
>> +#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
>> +extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE];
>> +#endif
>> +
>>  /*
>>   * Load a segment. Fall back on loading the zero segment if something goes
>>   * wrong.  This variant assumes that loading zero fully clears the segment.
>> diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
>> index 3321b446b66c..88754bfd425f 100644
>> --- a/arch/x86/mm/extable.c
>> +++ b/arch/x86/mm/extable.c
>> @@ -1,6 +1,7 @@
>>  #include <linux/extable.h>
>>  #include <linux/uaccess.h>
>>  #include <linux/sched/debug.h>
>> +#include <xen/xen.h>
>>
>>  #include <asm/fpu/internal.h>
>>  #include <asm/traps.h>
>> @@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
>>        * Old CPUs leave the high bits of CS on the stack
>>        * undefined.  I'm not sure which CPUs do this, but at least
>>        * the 486 DX works this way.
>> +      * Xen pv domains are not using the default __KERNEL_CS.
>>        */
>> -     if (regs->cs != __KERNEL_CS)
>> +     if (!xen_pv_domain() && regs->cs != __KERNEL_CS)
>>               goto fail;
>>
>>       /*
>> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
>> index 5b2b3f3f6531..f2414c6c5e7c 100644
>> --- a/arch/x86/xen/enlighten_pv.c
>> +++ b/arch/x86/xen/enlighten_pv.c
>> @@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] = {
>>       { simd_coprocessor_error,      xen_simd_coprocessor_error,      false },
>>  };
>>
>> -static bool get_trap_addr(void **addr, unsigned int ist)
>> +static bool __ref get_trap_addr(void **addr, unsigned int ist)
>>  {
>>       unsigned int nr;
>>       bool ist_okay = false;
>> @@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int ist)
>>               }
>>       }
>>
>> +     if (nr == ARRAY_SIZE(trap_array) &&
>> +         *addr >= (void *)early_idt_handler_array[0] &&
>> +         *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) {
>> +             nr = (*addr - (void *)early_idt_handler_array[0]) /
>> +                  EARLY_IDT_HANDLER_SIZE;
>> +             *addr = (void *)xen_early_idt_handler_array[nr];
>> +     }
>> +
>>       if (WARN_ON(ist != 0 && !ist_okay))
>>               return false;
>>
>> @@ -1262,6 +1270,21 @@ asmlinkage __visible void __init xen_start_kernel(void)
>>       xen_setup_gdt(0);
>>
>>       xen_init_irq_ops();
>> +
>> +     /* Let's presume PV guests always boot on vCPU with id 0. */
>> +     per_cpu(xen_vcpu_id, 0) = 0;
>> +
>> +     /*
>> +      * Setup xen_vcpu early because idt_setup_early_handler needs it for
>> +      * local_irq_disable(), irqs_disabled().
>> +      *
>> +      * Don't do the full vcpu_info placement stuff until we have
>> +      * the cpu_possible_mask and a non-dummy shared_info.
>> +      */
>> +     xen_vcpu_info_reset(0);
>> +
>> +     idt_setup_early_handler();
>> +
>>       xen_init_capabilities();
>>
>>  #ifdef CONFIG_X86_LOCAL_APIC
>> @@ -1295,18 +1318,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
>>        */
>>       acpi_numa = -1;
>>  #endif
>> -     /* Let's presume PV guests always boot on vCPU with id 0. */
>> -     per_cpu(xen_vcpu_id, 0) = 0;
>> -
>> -     /*
>> -      * Setup xen_vcpu early because start_kernel needs it for
>> -      * local_irq_disable(), irqs_disabled().
>> -      *
>> -      * Don't do the full vcpu_info placement stuff until we have
>> -      * the cpu_possible_mask and a non-dummy shared_info.
>> -      */
>> -     xen_vcpu_info_reset(0);
>> -
>>       WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv));
>>
>>       local_irq_disable();
>> diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
>> index 8a10c9a9e2b5..417b339e5c8e 100644
>> --- a/arch/x86/xen/xen-asm_64.S
>> +++ b/arch/x86/xen/xen-asm_64.S
>> @@ -15,6 +15,7 @@
>>
>>  #include <xen/interface/xen.h>
>>
>> +#include <linux/init.h>
>>  #include <linux/linkage.h>
>>
>>  .macro xen_pv_trap name
>> @@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat
>>  #endif
>>  xen_pv_trap hypervisor_callback
>>
>> +     __INIT
>> +ENTRY(xen_early_idt_handler_array)
>> +     i = 0
>> +     .rept NUM_EXCEPTION_VECTORS
>> +     pop %rcx
>> +     pop %r11
>> +     jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
>> +     i = i + 1
>> +     .fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
>> +     .endr
>> +END(xen_early_idt_handler_array)
>> +     __FINIT
>> +
>>  hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
>>  /*
>>   * Xen64 iret frame:
>>
>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] x86/xen: support early interrupts in xen pv guests
  2017-11-24 15:50   ` Andy Lutomirski
  2017-11-24 23:25     ` Thomas Gleixner
@ 2017-11-24 23:25     ` Thomas Gleixner
  1 sibling, 0 replies; 9+ messages in thread
From: Thomas Gleixner @ 2017-11-24 23:25 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Juergen Gross, linux-kernel, xen-devel, X86 ML, Boris Ostrovsky,
	H. Peter Anvin, Ingo Molnar

On Fri, 24 Nov 2017, Andy Lutomirski wrote:

> On Fri, Nov 24, 2017 at 12:52 AM, Juergen Gross <jgross@suse.com> wrote:
> > Sorry, Andy, forgot to Cc: you...
> >
> > On 24/11/17 09:42, Juergen Gross wrote:
> >> Add early interrupt handlers activated by idt_setup_early_handler() to
> >> the handlers supported by Xen pv guests. This will allow for early
> >> WARN() calls not crashing the guest.
> 
> Nice!  It would be great to get this into 4.15.

I pick it up tomorrow morning

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] x86/xen: support early interrupts in xen pv guests
  2017-11-24 15:50   ` Andy Lutomirski
@ 2017-11-24 23:25     ` Thomas Gleixner
  2017-11-24 23:25     ` Thomas Gleixner
  1 sibling, 0 replies; 9+ messages in thread
From: Thomas Gleixner @ 2017-11-24 23:25 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Juergen Gross, X86 ML, linux-kernel, Ingo Molnar, H. Peter Anvin,
	xen-devel, Boris Ostrovsky

On Fri, 24 Nov 2017, Andy Lutomirski wrote:

> On Fri, Nov 24, 2017 at 12:52 AM, Juergen Gross <jgross@suse.com> wrote:
> > Sorry, Andy, forgot to Cc: you...
> >
> > On 24/11/17 09:42, Juergen Gross wrote:
> >> Add early interrupt handlers activated by idt_setup_early_handler() to
> >> the handlers supported by Xen pv guests. This will allow for early
> >> WARN() calls not crashing the guest.
> 
> Nice!  It would be great to get this into 4.15.

I pick it up tomorrow morning

Thanks,

	tglx

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip:x86/urgent] x86/xen: Support early interrupts in xen pv guests
  2017-11-24  8:42 [PATCH] x86/xen: support early interrupts in xen pv guests Juergen Gross
  2017-11-24  8:52 ` Juergen Gross
  2017-11-24  8:52 ` Juergen Gross
@ 2017-11-27 23:34 ` tip-bot for Juergen Gross
  2 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Juergen Gross @ 2017-11-27 23:34 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, luto, tglx, jgross

Commit-ID:  42b3a4cb5609de757f5445fcad18945ba9239a07
Gitweb:     https://git.kernel.org/tip/42b3a4cb5609de757f5445fcad18945ba9239a07
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri, 24 Nov 2017 09:42:21 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 28 Nov 2017 00:28:56 +0100

x86/xen: Support early interrupts in xen pv guests

Add early interrupt handlers activated by idt_setup_early_handler() to
the handlers supported by Xen pv guests. This will allow for early
WARN() calls not crashing the guest.

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: xen-devel@lists.xenproject.org
Cc: boris.ostrovsky@oracle.com
Link: https://lkml.kernel.org/r/20171124084221.30172-1-jgross@suse.com

---
 arch/x86/include/asm/segment.h | 12 ++++++++++++
 arch/x86/mm/extable.c          |  4 +++-
 arch/x86/xen/enlighten_pv.c    | 37 ++++++++++++++++++++++++-------------
 arch/x86/xen/xen-asm_64.S      | 14 ++++++++++++++
 4 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
index b20f9d6..8f09012b 100644
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -236,11 +236,23 @@
  */
 #define EARLY_IDT_HANDLER_SIZE 9
 
+/*
+ * xen_early_idt_handler_array is for Xen pv guests: for each entry in
+ * early_idt_handler_array it contains a prequel in the form of
+ * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
+ * max 8 bytes.
+ */
+#define XEN_EARLY_IDT_HANDLER_SIZE 8
+
 #ifndef __ASSEMBLY__
 
 extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE];
 extern void early_ignore_irq(void);
 
+#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
+extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE];
+#endif
+
 /*
  * Load a segment. Fall back on loading the zero segment if something goes
  * wrong.  This variant assumes that loading zero fully clears the segment.
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 3321b44..88754bf 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,6 +1,7 @@
 #include <linux/extable.h>
 #include <linux/uaccess.h>
 #include <linux/sched/debug.h>
+#include <xen/xen.h>
 
 #include <asm/fpu/internal.h>
 #include <asm/traps.h>
@@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
 	 * Old CPUs leave the high bits of CS on the stack
 	 * undefined.  I'm not sure which CPUs do this, but at least
 	 * the 486 DX works this way.
+	 * Xen pv domains are not using the default __KERNEL_CS.
 	 */
-	if (regs->cs != __KERNEL_CS)
+	if (!xen_pv_domain() && regs->cs != __KERNEL_CS)
 		goto fail;
 
 	/*
diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 5b2b3f3..f2414c6 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] = {
 	{ simd_coprocessor_error,      xen_simd_coprocessor_error,      false },
 };
 
-static bool get_trap_addr(void **addr, unsigned int ist)
+static bool __ref get_trap_addr(void **addr, unsigned int ist)
 {
 	unsigned int nr;
 	bool ist_okay = false;
@@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int ist)
 		}
 	}
 
+	if (nr == ARRAY_SIZE(trap_array) &&
+	    *addr >= (void *)early_idt_handler_array[0] &&
+	    *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) {
+		nr = (*addr - (void *)early_idt_handler_array[0]) /
+		     EARLY_IDT_HANDLER_SIZE;
+		*addr = (void *)xen_early_idt_handler_array[nr];
+	}
+
 	if (WARN_ON(ist != 0 && !ist_okay))
 		return false;
 
@@ -1262,6 +1270,21 @@ asmlinkage __visible void __init xen_start_kernel(void)
 	xen_setup_gdt(0);
 
 	xen_init_irq_ops();
+
+	/* Let's presume PV guests always boot on vCPU with id 0. */
+	per_cpu(xen_vcpu_id, 0) = 0;
+
+	/*
+	 * Setup xen_vcpu early because idt_setup_early_handler needs it for
+	 * local_irq_disable(), irqs_disabled().
+	 *
+	 * Don't do the full vcpu_info placement stuff until we have
+	 * the cpu_possible_mask and a non-dummy shared_info.
+	 */
+	xen_vcpu_info_reset(0);
+
+	idt_setup_early_handler();
+
 	xen_init_capabilities();
 
 #ifdef CONFIG_X86_LOCAL_APIC
@@ -1295,18 +1318,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
 	 */
 	acpi_numa = -1;
 #endif
-	/* Let's presume PV guests always boot on vCPU with id 0. */
-	per_cpu(xen_vcpu_id, 0) = 0;
-
-	/*
-	 * Setup xen_vcpu early because start_kernel needs it for
-	 * local_irq_disable(), irqs_disabled().
-	 *
-	 * Don't do the full vcpu_info placement stuff until we have
-	 * the cpu_possible_mask and a non-dummy shared_info.
-	 */
-	xen_vcpu_info_reset(0);
-
 	WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv));
 
 	local_irq_disable();
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index 8a10c9a..417b339 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -15,6 +15,7 @@
 
 #include <xen/interface/xen.h>
 
+#include <linux/init.h>
 #include <linux/linkage.h>
 
 .macro xen_pv_trap name
@@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat
 #endif
 xen_pv_trap hypervisor_callback
 
+	__INIT
+ENTRY(xen_early_idt_handler_array)
+	i = 0
+	.rept NUM_EXCEPTION_VECTORS
+	pop %rcx
+	pop %r11
+	jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
+	i = i + 1
+	.fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
+	.endr
+END(xen_early_idt_handler_array)
+	__FINIT
+
 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
 /*
  * Xen64 iret frame:

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] x86/xen: support early interrupts in xen pv guests
@ 2017-11-24  8:42 Juergen Gross
  0 siblings, 0 replies; 9+ messages in thread
From: Juergen Gross @ 2017-11-24  8:42 UTC (permalink / raw)
  To: linux-kernel, xen-devel, x86
  Cc: Juergen Gross, boris.ostrovsky, mingo, tglx, hpa

Add early interrupt handlers activated by idt_setup_early_handler() to
the handlers supported by Xen pv guests. This will allow for early
WARN() calls not crashing the guest.

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/include/asm/segment.h | 12 ++++++++++++
 arch/x86/mm/extable.c          |  4 +++-
 arch/x86/xen/enlighten_pv.c    | 37 ++++++++++++++++++++++++-------------
 arch/x86/xen/xen-asm_64.S      | 14 ++++++++++++++
 4 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
index b20f9d623f9c..8f09012b92e7 100644
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -236,11 +236,23 @@
  */
 #define EARLY_IDT_HANDLER_SIZE 9
 
+/*
+ * xen_early_idt_handler_array is for Xen pv guests: for each entry in
+ * early_idt_handler_array it contains a prequel in the form of
+ * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
+ * max 8 bytes.
+ */
+#define XEN_EARLY_IDT_HANDLER_SIZE 8
+
 #ifndef __ASSEMBLY__
 
 extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE];
 extern void early_ignore_irq(void);
 
+#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
+extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE];
+#endif
+
 /*
  * Load a segment. Fall back on loading the zero segment if something goes
  * wrong.  This variant assumes that loading zero fully clears the segment.
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 3321b446b66c..88754bfd425f 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,6 +1,7 @@
 #include <linux/extable.h>
 #include <linux/uaccess.h>
 #include <linux/sched/debug.h>
+#include <xen/xen.h>
 
 #include <asm/fpu/internal.h>
 #include <asm/traps.h>
@@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
 	 * Old CPUs leave the high bits of CS on the stack
 	 * undefined.  I'm not sure which CPUs do this, but at least
 	 * the 486 DX works this way.
+	 * Xen pv domains are not using the default __KERNEL_CS.
 	 */
-	if (regs->cs != __KERNEL_CS)
+	if (!xen_pv_domain() && regs->cs != __KERNEL_CS)
 		goto fail;
 
 	/*
diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 5b2b3f3f6531..f2414c6c5e7c 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] = {
 	{ simd_coprocessor_error,      xen_simd_coprocessor_error,      false },
 };
 
-static bool get_trap_addr(void **addr, unsigned int ist)
+static bool __ref get_trap_addr(void **addr, unsigned int ist)
 {
 	unsigned int nr;
 	bool ist_okay = false;
@@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int ist)
 		}
 	}
 
+	if (nr == ARRAY_SIZE(trap_array) &&
+	    *addr >= (void *)early_idt_handler_array[0] &&
+	    *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) {
+		nr = (*addr - (void *)early_idt_handler_array[0]) /
+		     EARLY_IDT_HANDLER_SIZE;
+		*addr = (void *)xen_early_idt_handler_array[nr];
+	}
+
 	if (WARN_ON(ist != 0 && !ist_okay))
 		return false;
 
@@ -1262,6 +1270,21 @@ asmlinkage __visible void __init xen_start_kernel(void)
 	xen_setup_gdt(0);
 
 	xen_init_irq_ops();
+
+	/* Let's presume PV guests always boot on vCPU with id 0. */
+	per_cpu(xen_vcpu_id, 0) = 0;
+
+	/*
+	 * Setup xen_vcpu early because idt_setup_early_handler needs it for
+	 * local_irq_disable(), irqs_disabled().
+	 *
+	 * Don't do the full vcpu_info placement stuff until we have
+	 * the cpu_possible_mask and a non-dummy shared_info.
+	 */
+	xen_vcpu_info_reset(0);
+
+	idt_setup_early_handler();
+
 	xen_init_capabilities();
 
 #ifdef CONFIG_X86_LOCAL_APIC
@@ -1295,18 +1318,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
 	 */
 	acpi_numa = -1;
 #endif
-	/* Let's presume PV guests always boot on vCPU with id 0. */
-	per_cpu(xen_vcpu_id, 0) = 0;
-
-	/*
-	 * Setup xen_vcpu early because start_kernel needs it for
-	 * local_irq_disable(), irqs_disabled().
-	 *
-	 * Don't do the full vcpu_info placement stuff until we have
-	 * the cpu_possible_mask and a non-dummy shared_info.
-	 */
-	xen_vcpu_info_reset(0);
-
 	WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv));
 
 	local_irq_disable();
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index 8a10c9a9e2b5..417b339e5c8e 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -15,6 +15,7 @@
 
 #include <xen/interface/xen.h>
 
+#include <linux/init.h>
 #include <linux/linkage.h>
 
 .macro xen_pv_trap name
@@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat
 #endif
 xen_pv_trap hypervisor_callback
 
+	__INIT
+ENTRY(xen_early_idt_handler_array)
+	i = 0
+	.rept NUM_EXCEPTION_VECTORS
+	pop %rcx
+	pop %r11
+	jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
+	i = i + 1
+	.fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
+	.endr
+END(xen_early_idt_handler_array)
+	__FINIT
+
 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
 /*
  * Xen64 iret frame:
-- 
2.12.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-11-27 23:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-24  8:42 [PATCH] x86/xen: support early interrupts in xen pv guests Juergen Gross
2017-11-24  8:52 ` Juergen Gross
2017-11-24  8:52 ` Juergen Gross
2017-11-24 15:50   ` Andy Lutomirski
2017-11-24 15:50   ` Andy Lutomirski
2017-11-24 23:25     ` Thomas Gleixner
2017-11-24 23:25     ` Thomas Gleixner
2017-11-27 23:34 ` [tip:x86/urgent] x86/xen: Support " tip-bot for Juergen Gross
2017-11-24  8:42 [PATCH] x86/xen: support " Juergen Gross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.