x86/idt: Minor alloc_intr_gate() sanitization
Subsystems (3)
v2 cover x86/idt: Minor alloc_intr_gate() sanitization
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(-)
Signature · 1 line
2.25.3
PATCH v2 1/3 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.
--- 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(-)
arch/x86/xen/suspend_hvm.c +1 -1
@@ -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 (); }
arch/x86/xen/xen-ops.h +1 -1
@@ -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 );
drivers/xen/events/events_base.c +17 -11
@@ -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 ();
Signature · 1 line
2.25.3
[tip: x86/entry] x86/xen: Split HVM vector callback setup and interrupt gate allocation
The following commit has been merged into the x86/entry branch of tip:
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 <[email protected]> AuthorDate: Tue, 28 Apr 2020 11:38:22 +02:00 Committer: Thomas Gleixner <[email protected]> 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.
--- 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(-)
arch/x86/xen/suspend_hvm.c +1 -1
@@ -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 (); }
arch/x86/xen/xen-ops.h +1 -1
@@ -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 );
drivers/xen/events/events_base.c +17 -11
@@ -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 ();
PATCH v2 2/3 x86/idt: Annotate alloc_intr_gate() with __init
In reply to Vitaly KuznetsovThere 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.
--- arch/x86/kernel/idt.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
arch/x86/kernel/idt.c +13 -3
@@ -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); }
Signature · 1 line
2.25.3
[tip: x86/entry] x86/idt: Annotate alloc_intr_gate() with __init
The following commit has been merged into the x86/entry branch of tip:
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 <[email protected]> AuthorDate: Tue, 28 Apr 2020 11:38:23 +02:00 Committer: Thomas Gleixner <[email protected]> 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.
--- arch/x86/kernel/idt.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
arch/x86/kernel/idt.c +13 -3
@@ -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); }
PATCH v2 3/3 x86/idt: Keep spurious entries unset in system_vectors
In reply to Vitaly KuznetsovWith 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.
--- arch/x86/kernel/idt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kernel/idt.c +5 -1
@@ -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); }
Signature · 1 line
2.25.3
[tip: x86/entry] x86/idt: Keep spurious entries unset in system_vectors
The following commit has been merged into the x86/entry branch of tip:
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 <[email protected]> AuthorDate: Tue, 28 Apr 2020 11:38:24 +02:00 Committer: Thomas Gleixner <[email protected]> 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.
--- arch/x86/kernel/idt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kernel/idt.c +5 -1
@@ -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); }
Quoted 9 lines · Vitaly Kuznetsov
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/interruptsoutput 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 makingalloc_intr_gate()__init.
Quoted 5 lines
Vitaly Kuznetsov (3):
x86/xen: Split HVM vector callback setup and interrupt gate allocation x86/idt: Annotatealloc_intr_gate()with__init
x86/idt: Keep spurious entries unset insystem_vectors
Ping?
Signature · 1 line
Vitaly
Quoted 11 lines · Vitaly Kuznetsov
Quoted 9 lines · Vitaly Kuznetsov
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/interruptsoutput 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 makingalloc_intr_gate()__init.
Quoted 7 lines
Quoted 5 lines
Vitaly Kuznetsov (3):
x86/xen: Split HVM vector callback setup and interrupt gate allocation x86/idt: Annotatealloc_intr_gate()with__init
x86/idt: Keep spurious entries unset insystem_vectorsPing?
It's in my pile and I just did not come around to merge it.
Thanks,
tglx
Quoted 18 lines · Thomas Gleixner
Quoted 17 lines · Vitaly Kuznetsov
Quoted 14 lines · Vitaly Kuznetsov
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/interruptsoutput 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 makingalloc_intr_gate()__init.Vitaly Kuznetsov (3):
x86/xen: Split HVM vector callback setup and interrupt gate allocation x86/idt: Annotatealloc_intr_gate()with__init
x86/idt: Keep spurious entries unset insystem_vectors
Quoted 4 lines
Quoted 1 line
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!
Signature · 1 line
Vitaly