All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization
@ 2020-04-28  9:38 Vitaly Kuznetsov
  2020-04-28  9:38 ` [PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation Vitaly Kuznetsov
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2020-04-28  9:38 UTC (permalink / raw)
  To: x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	linux-kernel, Juergen Gross, Stefano Stabellini

This series is a successor of "[PATCH] x86/idt: Keep spurious entries unset
in system_vectors".

The original issue I tried to address was that /proc/interrupts output
was always containing all possible system vectors, including non allocated
ones (e.g. 'Hypervisor callback interrupts' on bare metal). Thomas
suggested to expand this cosmetic change to making alloc_intr_gate()
__init.

Vitaly Kuznetsov (3):
  x86/xen: Split HVM vector callback setup and interrupt gate allocation
  x86/idt: Annotate alloc_intr_gate() with __init
  x86/idt: Keep spurious entries unset in system_vectors

 arch/x86/kernel/idt.c            | 22 ++++++++++++++++++----
 arch/x86/xen/suspend_hvm.c       |  2 +-
 arch/x86/xen/xen-ops.h           |  2 +-
 drivers/xen/events/events_base.c | 28 +++++++++++++++++-----------
 4 files changed, 37 insertions(+), 17 deletions(-)

-- 
2.25.3


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

* [PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation
  2020-04-28  9:38 [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
@ 2020-04-28  9:38 ` Vitaly Kuznetsov
  2020-05-13 19:16   ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
  2020-04-28  9:38 ` [PATCH v2 2/3] x86/idt: Annotate alloc_intr_gate() with __init Vitaly Kuznetsov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Vitaly Kuznetsov @ 2020-04-28  9:38 UTC (permalink / raw)
  To: x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	linux-kernel, Juergen Gross, Stefano Stabellini

As a preparatory change for making alloc_intr_gate() __init split
xen_callback_vector() into callback vector setup via hypercall
(xen_setup_callback_vector()) and interrupt gate allocation
(xen_alloc_callback_vector()).

xen_setup_callback_vector() is being called twice: on init and upon
system resume from xen_hvm_post_suspend(). alloc_intr_gate() only
needs to be called once.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/xen/suspend_hvm.c       |  2 +-
 arch/x86/xen/xen-ops.h           |  2 +-
 drivers/xen/events/events_base.c | 28 +++++++++++++++++-----------
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/arch/x86/xen/suspend_hvm.c b/arch/x86/xen/suspend_hvm.c
index e666b614cf6d..5152afe16876 100644
--- a/arch/x86/xen/suspend_hvm.c
+++ b/arch/x86/xen/suspend_hvm.c
@@ -13,6 +13,6 @@ void xen_hvm_post_suspend(int suspend_cancelled)
 		xen_hvm_init_shared_info();
 		xen_vcpu_restore();
 	}
-	xen_callback_vector();
+	xen_setup_callback_vector();
 	xen_unplug_emulated_devices();
 }
diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
index 45a441c33d6d..1cc1568bfe04 100644
--- a/arch/x86/xen/xen-ops.h
+++ b/arch/x86/xen/xen-ops.h
@@ -55,7 +55,7 @@ void xen_enable_sysenter(void);
 void xen_enable_syscall(void);
 void xen_vcpu_restore(void);
 
-void xen_callback_vector(void);
+void xen_setup_callback_vector(void);
 void xen_hvm_init_shared_info(void);
 void xen_unplug_emulated_devices(void);
 
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 3a791c8485d0..eb35c3cda9a6 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1639,26 +1639,30 @@ EXPORT_SYMBOL_GPL(xen_set_callback_via);
 /* Vector callbacks are better than PCI interrupts to receive event
  * channel notifications because we can receive vector callbacks on any
  * vcpu and we don't need PCI support or APIC interactions. */
-void xen_callback_vector(void)
+void xen_setup_callback_vector(void)
 {
-	int rc;
 	uint64_t callback_via;
 
 	if (xen_have_vector_callback) {
 		callback_via = HVM_CALLBACK_VECTOR(HYPERVISOR_CALLBACK_VECTOR);
-		rc = xen_set_callback_via(callback_via);
-		if (rc) {
+		if (xen_set_callback_via(callback_via)) {
 			pr_err("Request for Xen HVM callback vector failed\n");
 			xen_have_vector_callback = 0;
-			return;
 		}
-		pr_info_once("Xen HVM callback vector for event delivery is enabled\n");
-		alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,
-				xen_hvm_callback_vector);
 	}
 }
+
+static __init void xen_alloc_callback_vector(void)
+{
+	if (!xen_have_vector_callback)
+		return;
+
+	pr_info("Xen HVM callback vector for event delivery is enabled\n");
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, xen_hvm_callback_vector);
+}
 #else
-void xen_callback_vector(void) {}
+void xen_setup_callback_vector(void) {}
+static inline void xen_alloc_callback_vector(void) {}
 #endif
 
 #undef MODULE_PARAM_PREFIX
@@ -1692,8 +1696,10 @@ void __init xen_init_IRQ(void)
 		if (xen_initial_domain())
 			pci_xen_initial_domain();
 	}
-	if (xen_feature(XENFEAT_hvm_callback_vector))
-		xen_callback_vector();
+	if (xen_feature(XENFEAT_hvm_callback_vector)) {
+		xen_setup_callback_vector();
+		xen_alloc_callback_vector();
+	}
 
 	if (xen_hvm_domain()) {
 		native_init_IRQ();
-- 
2.25.3


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

* [PATCH v2 2/3] x86/idt: Annotate alloc_intr_gate() with __init
  2020-04-28  9:38 [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
  2020-04-28  9:38 ` [PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation Vitaly Kuznetsov
@ 2020-04-28  9:38 ` Vitaly Kuznetsov
  2020-05-13 19:16   ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
  2020-04-28  9:38 ` [PATCH v2 3/3] x86/idt: Keep spurious entries unset in system_vectors Vitaly Kuznetsov
  2020-05-13 12:57 ` [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
  3 siblings, 1 reply; 10+ messages in thread
From: Vitaly Kuznetsov @ 2020-04-28  9:38 UTC (permalink / raw)
  To: x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	linux-kernel, Juergen Gross, Stefano Stabellini

There seems to be no reason to allocate interrupt gates after init. Mark
alloc_intr_gate() as __init and add WARN_ON() checks making sure it is
only used before idt_setup_apic_and_irq_gates() finalizes IDT setup and
maps all un-allocated entries to spurious entries.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kernel/idt.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c
index 87ef69a72c52..f95c3be00e5a 100644
--- a/arch/x86/kernel/idt.c
+++ b/arch/x86/kernel/idt.c
@@ -51,6 +51,9 @@ struct idt_data {
 #define TSKG(_vector, _gdt)				\
 	G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3)
 
+
+static bool idt_setup_done __initdata;
+
 /*
  * Early traps running on the DEFAULT_STACK because the other interrupt
  * stacks work only after cpu_init().
@@ -323,6 +326,7 @@ void __init idt_setup_apic_and_irq_gates(void)
 		set_intr_gate(i, entry);
 	}
 #endif
+	idt_setup_done = true;
 }
 
 /**
@@ -352,6 +356,7 @@ void idt_invalidate(void *addr)
 	load_idt(&idt);
 }
 
+/* This goes away once ASYNC_PF is sanitized */
 void __init update_intr_gate(unsigned int n, const void *addr)
 {
 	if (WARN_ON_ONCE(!test_bit(n, system_vectors)))
@@ -359,9 +364,14 @@ void __init update_intr_gate(unsigned int n, const void *addr)
 	set_intr_gate(n, addr);
 }
 
-void alloc_intr_gate(unsigned int n, const void *addr)
+void __init alloc_intr_gate(unsigned int n, const void *addr)
 {
-	BUG_ON(n < FIRST_SYSTEM_VECTOR);
-	if (!test_and_set_bit(n, system_vectors))
+	if (WARN_ON(n < FIRST_SYSTEM_VECTOR))
+		return;
+
+	if (WARN_ON(idt_setup_done))
+		return;
+
+	if (!WARN_ON(test_and_set_bit(n, system_vectors)))
 		set_intr_gate(n, addr);
 }
-- 
2.25.3


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

* [PATCH v2 3/3] x86/idt: Keep spurious entries unset in system_vectors
  2020-04-28  9:38 [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
  2020-04-28  9:38 ` [PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation Vitaly Kuznetsov
  2020-04-28  9:38 ` [PATCH v2 2/3] x86/idt: Annotate alloc_intr_gate() with __init Vitaly Kuznetsov
@ 2020-04-28  9:38 ` Vitaly Kuznetsov
  2020-05-13 19:16   ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
  2020-05-13 12:57 ` [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
  3 siblings, 1 reply; 10+ messages in thread
From: Vitaly Kuznetsov @ 2020-04-28  9:38 UTC (permalink / raw)
  To: x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	linux-kernel, Juergen Gross, Stefano Stabellini

With commit dc20b2d52653 ("x86/idt: Move interrupt gate initialization to
IDT code") non assigned system vectors are also marked as used in
'used_vectors' (now 'system_vectors') bitmap. This makes checks in
arch_show_interrupts() whether a particular system vector is allocated to
always pass and e.g. 'Hyper-V reenlightenment interrupts' entry always
shows up in /proc/interrupts.

Another side effect of having all unassigned system vectors marked as used
is that irq_matrix_debug_show() will wrongly count them among 'System'
vectors.

As we now make sure alloc_intr_gate() is not called after init, it is
possible to leave unused entries in 'system_vectors' unset to fix the
issues.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kernel/idt.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c
index f95c3be00e5a..28500ccb835c 100644
--- a/arch/x86/kernel/idt.c
+++ b/arch/x86/kernel/idt.c
@@ -321,7 +321,11 @@ void __init idt_setup_apic_and_irq_gates(void)
 
 #ifdef CONFIG_X86_LOCAL_APIC
 	for_each_clear_bit_from(i, system_vectors, NR_VECTORS) {
-		set_bit(i, system_vectors);
+		/*
+		 * Don't set the non assigned system vectors in the
+		 * system_vectors bitmap. Otherwise they show up in
+		 * /proc/interrupts.
+		 */
 		entry = spurious_entries_start + 8 * (i - FIRST_SYSTEM_VECTOR);
 		set_intr_gate(i, entry);
 	}
-- 
2.25.3


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

* Re: [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization
  2020-04-28  9:38 [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
                   ` (2 preceding siblings ...)
  2020-04-28  9:38 ` [PATCH v2 3/3] x86/idt: Keep spurious entries unset in system_vectors Vitaly Kuznetsov
@ 2020-05-13 12:57 ` Vitaly Kuznetsov
  2020-05-13 19:02   ` Thomas Gleixner
  3 siblings, 1 reply; 10+ messages in thread
From: Vitaly Kuznetsov @ 2020-05-13 12:57 UTC (permalink / raw)
  To: x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	linux-kernel, Juergen Gross, Stefano Stabellini

Vitaly Kuznetsov <vkuznets@redhat.com> writes:

> This series is a successor of "[PATCH] x86/idt: Keep spurious entries unset
> in system_vectors".
>
> The original issue I tried to address was that /proc/interrupts output
> was always containing all possible system vectors, including non allocated
> ones (e.g. 'Hypervisor callback interrupts' on bare metal). Thomas
> suggested to expand this cosmetic change to making alloc_intr_gate()
> __init.
>
> Vitaly Kuznetsov (3):
>   x86/xen: Split HVM vector callback setup and interrupt gate allocation
>   x86/idt: Annotate alloc_intr_gate() with __init
>   x86/idt: Keep spurious entries unset in system_vectors
>

Ping?

-- 
Vitaly


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

* Re: [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization
  2020-05-13 12:57 ` [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
@ 2020-05-13 19:02   ` Thomas Gleixner
  2020-05-14  8:10     ` Vitaly Kuznetsov
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Gleixner @ 2020-05-13 19:02 UTC (permalink / raw)
  To: Vitaly Kuznetsov, x86
  Cc: Ingo Molnar, Borislav Petkov, H. Peter Anvin, linux-kernel,
	Juergen Gross, Stefano Stabellini

Vitaly Kuznetsov <vkuznets@redhat.com> writes:
> Vitaly Kuznetsov <vkuznets@redhat.com> writes:
>
>> This series is a successor of "[PATCH] x86/idt: Keep spurious entries unset
>> in system_vectors".
>>
>> The original issue I tried to address was that /proc/interrupts output
>> was always containing all possible system vectors, including non allocated
>> ones (e.g. 'Hypervisor callback interrupts' on bare metal). Thomas
>> suggested to expand this cosmetic change to making alloc_intr_gate()
>> __init.
>>
>> Vitaly Kuznetsov (3):
>>   x86/xen: Split HVM vector callback setup and interrupt gate allocation
>>   x86/idt: Annotate alloc_intr_gate() with __init
>>   x86/idt: Keep spurious entries unset in system_vectors
>>
>
> Ping?

It's in my pile and I just did not come around to merge it.

Thanks,

        tglx

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

* [tip: x86/entry] x86/idt: Keep spurious entries unset in system_vectors
  2020-04-28  9:38 ` [PATCH v2 3/3] x86/idt: Keep spurious entries unset in system_vectors Vitaly Kuznetsov
@ 2020-05-13 19:16   ` tip-bot2 for Vitaly Kuznetsov
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot2 for Vitaly Kuznetsov @ 2020-05-13 19:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Vitaly Kuznetsov, Thomas Gleixner, x86, LKML

The following commit has been merged into the x86/entry branch of tip:

Commit-ID:     82ff351052bcc4bf49dc966960f563d25f54d22b
Gitweb:        https://git.kernel.org/tip/82ff351052bcc4bf49dc966960f563d25f54d22b
Author:        Vitaly Kuznetsov <vkuznets@redhat.com>
AuthorDate:    Tue, 28 Apr 2020 11:38:24 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 13 May 2020 21:13:55 +02:00

x86/idt: Keep spurious entries unset in system_vectors

With commit dc20b2d52653 ("x86/idt: Move interrupt gate initialization to
IDT code") non assigned system vectors are also marked as used in
'used_vectors' (now 'system_vectors') bitmap. This makes checks in
arch_show_interrupts() whether a particular system vector is allocated to
always pass and e.g. 'Hyper-V reenlightenment interrupts' entry always
shows up in /proc/interrupts.

Another side effect of having all unassigned system vectors marked as used
is that irq_matrix_debug_show() will wrongly count them among 'System'
vectors.

As it is now ensured that alloc_intr_gate() is not called after init, it is
possible to leave unused entries in 'system_vectors' unset to fix these
issues.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200428093824.1451532-4-vkuznets@redhat.com

---
 arch/x86/kernel/idt.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c
index 0e92051..36fef90 100644
--- a/arch/x86/kernel/idt.c
+++ b/arch/x86/kernel/idt.c
@@ -321,7 +321,11 @@ void __init idt_setup_apic_and_irq_gates(void)
 
 #ifdef CONFIG_X86_LOCAL_APIC
 	for_each_clear_bit_from(i, system_vectors, NR_VECTORS) {
-		set_bit(i, system_vectors);
+		/*
+		 * Don't set the non assigned system vectors in the
+		 * system_vectors bitmap. Otherwise they show up in
+		 * /proc/interrupts.
+		 */
 		entry = spurious_entries_start + 8 * (i - FIRST_SYSTEM_VECTOR);
 		set_intr_gate(i, entry);
 	}

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

* [tip: x86/entry] x86/xen: Split HVM vector callback setup and interrupt gate allocation
  2020-04-28  9:38 ` [PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation Vitaly Kuznetsov
@ 2020-05-13 19:16   ` tip-bot2 for Vitaly Kuznetsov
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot2 for Vitaly Kuznetsov @ 2020-05-13 19:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Thomas Gleixner, Vitaly Kuznetsov, x86, LKML

The following commit has been merged into the x86/entry branch of tip:

Commit-ID:     fad1940a6a856f59b073e8650e02052ce531154c
Gitweb:        https://git.kernel.org/tip/fad1940a6a856f59b073e8650e02052ce531154c
Author:        Vitaly Kuznetsov <vkuznets@redhat.com>
AuthorDate:    Tue, 28 Apr 2020 11:38:22 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 13 May 2020 21:13:54 +02:00

x86/xen: Split HVM vector callback setup and interrupt gate allocation

As a preparatory change for making alloc_intr_gate() __init split
xen_callback_vector() into callback vector setup via hypercall
(xen_setup_callback_vector()) and interrupt gate allocation
(xen_alloc_callback_vector()).

xen_setup_callback_vector() is being called twice: on init and upon
system resume from xen_hvm_post_suspend(). alloc_intr_gate() only
needs to be called once.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200428093824.1451532-2-vkuznets@redhat.com

---
 arch/x86/xen/suspend_hvm.c       |  2 +-
 arch/x86/xen/xen-ops.h           |  2 +-
 drivers/xen/events/events_base.c | 28 +++++++++++++++++-----------
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/arch/x86/xen/suspend_hvm.c b/arch/x86/xen/suspend_hvm.c
index e666b61..5152afe 100644
--- a/arch/x86/xen/suspend_hvm.c
+++ b/arch/x86/xen/suspend_hvm.c
@@ -13,6 +13,6 @@ void xen_hvm_post_suspend(int suspend_cancelled)
 		xen_hvm_init_shared_info();
 		xen_vcpu_restore();
 	}
-	xen_callback_vector();
+	xen_setup_callback_vector();
 	xen_unplug_emulated_devices();
 }
diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
index 45a441c..1cc1568 100644
--- a/arch/x86/xen/xen-ops.h
+++ b/arch/x86/xen/xen-ops.h
@@ -55,7 +55,7 @@ void xen_enable_sysenter(void);
 void xen_enable_syscall(void);
 void xen_vcpu_restore(void);
 
-void xen_callback_vector(void);
+void xen_setup_callback_vector(void);
 void xen_hvm_init_shared_info(void);
 void xen_unplug_emulated_devices(void);
 
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 3a791c8..eb35c3c 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1639,26 +1639,30 @@ EXPORT_SYMBOL_GPL(xen_set_callback_via);
 /* Vector callbacks are better than PCI interrupts to receive event
  * channel notifications because we can receive vector callbacks on any
  * vcpu and we don't need PCI support or APIC interactions. */
-void xen_callback_vector(void)
+void xen_setup_callback_vector(void)
 {
-	int rc;
 	uint64_t callback_via;
 
 	if (xen_have_vector_callback) {
 		callback_via = HVM_CALLBACK_VECTOR(HYPERVISOR_CALLBACK_VECTOR);
-		rc = xen_set_callback_via(callback_via);
-		if (rc) {
+		if (xen_set_callback_via(callback_via)) {
 			pr_err("Request for Xen HVM callback vector failed\n");
 			xen_have_vector_callback = 0;
-			return;
 		}
-		pr_info_once("Xen HVM callback vector for event delivery is enabled\n");
-		alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,
-				xen_hvm_callback_vector);
 	}
 }
+
+static __init void xen_alloc_callback_vector(void)
+{
+	if (!xen_have_vector_callback)
+		return;
+
+	pr_info("Xen HVM callback vector for event delivery is enabled\n");
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, xen_hvm_callback_vector);
+}
 #else
-void xen_callback_vector(void) {}
+void xen_setup_callback_vector(void) {}
+static inline void xen_alloc_callback_vector(void) {}
 #endif
 
 #undef MODULE_PARAM_PREFIX
@@ -1692,8 +1696,10 @@ void __init xen_init_IRQ(void)
 		if (xen_initial_domain())
 			pci_xen_initial_domain();
 	}
-	if (xen_feature(XENFEAT_hvm_callback_vector))
-		xen_callback_vector();
+	if (xen_feature(XENFEAT_hvm_callback_vector)) {
+		xen_setup_callback_vector();
+		xen_alloc_callback_vector();
+	}
 
 	if (xen_hvm_domain()) {
 		native_init_IRQ();

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

* [tip: x86/entry] x86/idt: Annotate alloc_intr_gate() with __init
  2020-04-28  9:38 ` [PATCH v2 2/3] x86/idt: Annotate alloc_intr_gate() with __init Vitaly Kuznetsov
@ 2020-05-13 19:16   ` tip-bot2 for Vitaly Kuznetsov
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot2 for Vitaly Kuznetsov @ 2020-05-13 19:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Thomas Gleixner, Vitaly Kuznetsov, x86, LKML

The following commit has been merged into the x86/entry branch of tip:

Commit-ID:     4c74d51dab3dd655062a4740af150c1835e19cff
Gitweb:        https://git.kernel.org/tip/4c74d51dab3dd655062a4740af150c1835e19cff
Author:        Vitaly Kuznetsov <vkuznets@redhat.com>
AuthorDate:    Tue, 28 Apr 2020 11:38:23 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 13 May 2020 21:13:54 +02:00

x86/idt: Annotate alloc_intr_gate() with __init

There seems to be no reason to allocate interrupt gates after init. Mark
alloc_intr_gate() as __init and add WARN_ON() checks making sure it is
only used before idt_setup_apic_and_irq_gates() finalizes IDT setup and
maps all un-allocated entries to spurious entries.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200428093824.1451532-3-vkuznets@redhat.com

---
 arch/x86/kernel/idt.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c
index 98bcb50..0e92051 100644
--- a/arch/x86/kernel/idt.c
+++ b/arch/x86/kernel/idt.c
@@ -51,6 +51,9 @@ struct idt_data {
 #define TSKG(_vector, _gdt)				\
 	G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3)
 
+
+static bool idt_setup_done __initdata;
+
 /*
  * Early traps running on the DEFAULT_STACK because the other interrupt
  * stacks work only after cpu_init().
@@ -323,6 +326,7 @@ void __init idt_setup_apic_and_irq_gates(void)
 		set_intr_gate(i, entry);
 	}
 #endif
+	idt_setup_done = true;
 }
 
 /**
@@ -352,6 +356,7 @@ void idt_invalidate(void *addr)
 	load_idt(&idt);
 }
 
+/* This goes away once ASYNC_PF is sanitized */
 void __init update_intr_gate(unsigned int n, const void *addr)
 {
 	if (WARN_ON_ONCE(!test_bit(n, system_vectors)))
@@ -359,9 +364,14 @@ void __init update_intr_gate(unsigned int n, const void *addr)
 	set_intr_gate(n, addr);
 }
 
-void alloc_intr_gate(unsigned int n, const void *addr)
+void __init alloc_intr_gate(unsigned int n, const void *addr)
 {
-	BUG_ON(n < FIRST_SYSTEM_VECTOR);
-	if (!test_and_set_bit(n, system_vectors))
+	if (WARN_ON(n < FIRST_SYSTEM_VECTOR))
+		return;
+
+	if (WARN_ON(idt_setup_done))
+		return;
+
+	if (!WARN_ON(test_and_set_bit(n, system_vectors)))
 		set_intr_gate(n, addr);
 }

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

* Re: [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization
  2020-05-13 19:02   ` Thomas Gleixner
@ 2020-05-14  8:10     ` Vitaly Kuznetsov
  0 siblings, 0 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2020-05-14  8:10 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Ingo Molnar, Borislav Petkov, H. Peter Anvin, linux-kernel,
	Juergen Gross, Stefano Stabellini, x86

Thomas Gleixner <tglx@linutronix.de> writes:

> Vitaly Kuznetsov <vkuznets@redhat.com> writes:
>> Vitaly Kuznetsov <vkuznets@redhat.com> writes:
>>
>>> This series is a successor of "[PATCH] x86/idt: Keep spurious entries unset
>>> in system_vectors".
>>>
>>> The original issue I tried to address was that /proc/interrupts output
>>> was always containing all possible system vectors, including non allocated
>>> ones (e.g. 'Hypervisor callback interrupts' on bare metal). Thomas
>>> suggested to expand this cosmetic change to making alloc_intr_gate()
>>> __init.
>>>
>>> Vitaly Kuznetsov (3):
>>>   x86/xen: Split HVM vector callback setup and interrupt gate allocation
>>>   x86/idt: Annotate alloc_intr_gate() with __init
>>>   x86/idt: Keep spurious entries unset in system_vectors
>>>
>>
>> Ping?
>
> It's in my pile and I just did not come around to merge it.
>

No problem, just wanted to make sure it didn't slip through the
cracks. I see tip-bot already queued it, thanks!

-- 
Vitaly


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

end of thread, other threads:[~2020-05-14  8:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28  9:38 [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
2020-04-28  9:38 ` [PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation Vitaly Kuznetsov
2020-05-13 19:16   ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
2020-04-28  9:38 ` [PATCH v2 2/3] x86/idt: Annotate alloc_intr_gate() with __init Vitaly Kuznetsov
2020-05-13 19:16   ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
2020-04-28  9:38 ` [PATCH v2 3/3] x86/idt: Keep spurious entries unset in system_vectors Vitaly Kuznetsov
2020-05-13 19:16   ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
2020-05-13 12:57 ` [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
2020-05-13 19:02   ` Thomas Gleixner
2020-05-14  8:10     ` Vitaly Kuznetsov

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.