Simplify initialization of IR on x86 platforms
cover Simplify initialization of IR on x86 platforms
This is a following-on patch set to simplify initialization of interrupt remapping subsystem on x86 platforms. Please refer to
https://lkml.org/lkml/2014/12/5/114
for the whole story.
With this patch set applied, there are three steps to initialize IR on x86:
1) "Detect" stage to detect ACPI table for IR at early booting stage
2) "Prepare" stage to allocate resources for IR
3) "Enable" stage to program hardware device to enable IR
Patch 1-3 clean up the code to initialize IR and X2APIC on x86 Patch 4-5 kill the irq_remapping_supported() and related code Patch 6-9 clean up IR code further.
It's based on tip/x86/apic branch and could be pulled from:
https://github.com/jiangliu/linux.git irq_remapping_v1
It has been tested on Intel platform with X2APIC enabled and disabled. It also passes Fengguang's 0day test suite. Tests on AMD platform are welcomed!
Jiang Liu (9):
x86, apic: Kill useless variable x2apic_enabled in function
enable_IR_x2apic()
x86, apic: Correctly detect X2APIC status in function enable_IR() x86, apic: Refine enable_IR_x2apic() and related functions iommu/vt-d: Prepare for killing function irq_remapping_supported() iommu/irq_remapping: Kill function irq_remapping_supported() and
related code
iommu/irq_remapping: Refine function irq_remapping_prepare() for
maintenance
iommu/irq_remapping: Change variable disable_irq_remap to be static iommu/irq_remapping: Normailize the way to detect whether IR is
enabled
iommu/irq_remapping: Kill unused function irq_remapping_print_chip()
arch/x86/include/asm/irq_remapping.h | 4 -- arch/x86/kernel/apic/apic.c | 89 +++++++++++++++------------------- drivers/iommu/amd_iommu.c | 1 - drivers/iommu/amd_iommu_init.c | 10 +--- drivers/iommu/amd_iommu_proto.h | 1 - drivers/iommu/intel_irq_remapping.c | 59 ++++++++-------------- drivers/iommu/irq_remapping.c | 74 +++++++++------------------- drivers/iommu/irq_remapping.h | 5 -- 8 files changed, 84 insertions(+), 159 deletions(-)
Signature · 1 line
1.7.10.4
RFC PATCH 1/9 x86, apic: Kill useless variable x2apic_enabled in function enable_IR_x2apic()
Local variable x2apic_enabled has been assigned to but never referred, so kill it.
--- arch/x86/kernel/apic/apic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/kernel/apic/apic.c +1 -3
@@ -1594,7 +1594,7 @@ int __init enable_IR(void)void __init enable_IR_x2apic (void ) {unsigned long flags; -int ret, x2apic_enabled =0 ; +int ret;int hardware_init_ret; hardware_init_ret =irq_remapping_prepare ();
@@ -1644,8 +1644,6 @@ void __init enable_IR_x2apic(void) goto skip_x2apic; } - x2apic_enabled =1 ; -if (x2apic_supported () && !x2apic_mode) { x2apic_mode =1 ;enable_x2apic ();
Signature · 1 line
1.7.10.4
RFC PATCH 2/9 x86, apic: Correctly detect X2APIC status in function enable_IR()
In reply to Jiang LiuX2APIC will be disabled if user specifies "nox2apic" on kernel command line, even when x2apic_preenabled is true. So correctly detect X2APIC status by using x2apic_enabled() instead of x2apic_preenabled.
--- arch/x86/kernel/apic/apic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/apic/apic.c +1 -1
@@ -1580,7 +1580,7 @@ int __init enable_IR(void)return -1 ; } -if (!x2apic_preenabled && skip_ioapic_setup) { +if (!x2apic_enabled () && skip_ioapic_setup) {pr_info ("Skipped enabling intr-remap because of skipping " "io-apic setup\n" );return -1 ;
Signature · 1 line
1.7.10.4
RFC PATCH 3/9 x86, apic: Refine enable_IR_x2apic() and related functions
In reply to Jiang LiuRefine enable_IR_x2apic() and related functions for better maintenence. It also changes the way to treat IR in XAPIC mode as the same as IR is disabled when enabling X2APIC.
--- arch/x86/kernel/apic/apic.c | 78 ++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 41 deletions(-)
arch/x86/kernel/apic/apic.c +37 -41
@@ -1572,7 +1572,7 @@ void enable_x2apic(void) }#endif /* CONFIG_X86_X2APIC */ -int __init enable_IR (void ) +static int __init try_to_enable_IR (void ) {#ifdef CONFIG_IRQ_REMAP if (!irq_remapping_supported ()) {
@@ -1585,44 +1585,18 @@ int __init enable_IR(void) "io-apic setup\n");return -1 ; } +#endif return irq_remapping_enable (); -#endif -return -1 ; } -void __init enable_IR_x2apic (void ) +static __init void try_to_enable_x2apic (int ir_stat) { -unsigned long flags; -int ret; -int hardware_init_ret; - - hardware_init_ret =irq_remapping_prepare (); -if (hardware_init_ret && !x2apic_supported ()) -return ; - - ret =save_ioapic_entries (); -if (ret) { -pr_info ("Saving IO-APIC state failed: %d\n" , ret); -return ; - } - -local_irq_save (flags); - legacy_pic->mask_all (); -mask_ioapic_entries (); - -if (x2apic_preenabled && nox2apic) -disable_x2apic (); - -if (hardware_init_ret) - ret =-1 ; -else - ret =enable_IR (); - +#ifdef CONFIG_X86_X2APIC if (!x2apic_supported ()) - goto skip_x2apic; +return ; -if (ret <0 ) { +if (ir_stat !=IRQ_REMAP_X2APIC_MODE ) {/* IR is required if there is APIC ID > 255 even when running * under KVM */
@@ -1630,8 +1604,9 @@ void __init enable_IR_x2apic(void) !hypervisor_x2apic_available()) {if (x2apic_preenabled)disable_x2apic (); - goto skip_x2apic; +return ; } +/* * without IR all CPUs can be addressed by IOAPIC/MSI * only in physical mode
@@ -1639,19 +1614,40 @@ void __init enable_IR_x2apic(void)x2apic_force_phys (); } -if (ret ==IRQ_REMAP_XAPIC_MODE ) { -pr_info ("x2apic not enabled, IRQ remapping is in xapic mode\n" ); - goto skip_x2apic; - } - -if (x2apic_supported () && !x2apic_mode) { +if (!x2apic_mode) { x2apic_mode =1 ;enable_x2apic ();pr_info ("Enabled x2apic\n" ); } +#endif +} + +void __init enable_IR_x2apic (void ) +{ +unsigned long flags; +int ret, ir_stat; + + ir_stat =irq_remapping_prepare (); +if (ir_stat <0 && !x2apic_supported ()) +return ; + + ret =save_ioapic_entries (); +if (ret) { +pr_info ("Saving IO-APIC state failed: %d\n" , ret); +return ; + } + +local_irq_save (flags); + legacy_pic->mask_all (); +mask_ioapic_entries (); + +if (x2apic_preenabled && nox2apic) +disable_x2apic (); +if (ir_stat >=0 ) + ir_stat =try_to_enable_IR (); +try_to_enable_x2apic (ir_stat); -skip_x2apic: -if (ret <0 )/* IR enabling failed */ +if (ir_stat <0 )/* IR enabling failed */ restore_ioapic_entries (); legacy_pic->restore_mask ();local_irq_restore (flags);
Signature · 1 line
1.7.10.4
RFC PATCH 4/9 iommu/vt-d: Prepare for killing function irq_remapping_supported()
In reply to Jiang LiuPrepare for killing function irq_remapping_supported() by moving code from intel_irq_remapping_supported() into intel_prepare_irq_remapping().
--- drivers/iommu/intel_irq_remapping.c | 54 ++++++++++++++--------------------- 1 file changed, 21 insertions(+), 33 deletions(-)
drivers/iommu/intel_irq_remapping.c +21 -33
@@ -512,30 +512,6 @@ static int __init dmar_x2apic_optout(void)static int __init intel_irq_remapping_supported (void ) { -struct dmar_drhd_unit *drhd; -struct intel_iommu *iommu; - -if (disable_irq_remap) -return 0 ; -if (irq_remap_broken) { -printk (KERN_WARNING -"This system BIOS has enabled interrupt remapping\n" -"on a chipset that contains an erratum making that\n" -"feature unstable. To maintain system stability\n" -"interrupt remapping is being disabled. Please\n" -"contact your BIOS vendor for an update\n" ); -add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK ); - disable_irq_remap =1 ; -return 0 ; - } - -if (!dmar_ir_support ()) -return 0 ; - -for_each_iommu (iommu, drhd) -if (!ecap_ir_support (iommu->ecap)) -return 0 ; -return 1 ; }
@@ -560,26 +536,38 @@ static int __init intel_prepare_irq_remapping(void)struct dmar_drhd_unit *drhd;struct intel_iommu *iommu; +if (irq_remap_broken) { +printk (KERN_WARNING +"This system BIOS has enabled interrupt remapping\n" +"on a chipset that contains an erratum making that\n" +"feature unstable. To maintain system stability\n" +"interrupt remapping is being disabled. Please\n" +"contact your BIOS vendor for an update\n" ); +add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK ); + disable_irq_remap =1 ; +return -ENODEV ; + } +if (dmar_table_init () <0 ) -return -1 ; +return -ENODEV ; + +if (!dmar_ir_support ()) +return -ENODEV ;if (parse_ioapics_under_ir () !=1 ) {printk (KERN_INFO "Not enabling interrupt remapping\n" ); goto error; } -for_each_iommu (iommu, drhd) { -if (!ecap_ir_support (iommu->ecap)) -continue ; - -/* Do the allocations early */ -if (intel_setup_irq_remapping (iommu)) +for_each_iommu (iommu, drhd) +if (!ecap_ir_support (iommu->ecap) || +intel_setup_irq_remapping (iommu)) goto error; - }return 0 ; + error:intel_cleanup_irq_remapping (); -return -1 ; +return -ENODEV ; }static int __init intel_enable_irq_remapping (void )
Signature · 1 line
1.7.10.4
RFC PATCH 5/9 iommu/irq_remapping: Kill function irq_remapping_supported() and related code
In reply to Jiang LiuSimplify irq_remapping code by killing irq_remapping_supported() and related interfaces.
--- arch/x86/include/asm/irq_remapping.h | 2 -- arch/x86/kernel/apic/apic.c | 7 +------ drivers/iommu/amd_iommu.c | 1 - drivers/iommu/amd_iommu_init.c | 5 ----- drivers/iommu/amd_iommu_proto.h | 1 - drivers/iommu/intel_irq_remapping.c | 6 ------ drivers/iommu/irq_remapping.c | 12 ++---------- drivers/iommu/irq_remapping.h | 3 --- 8 files changed, 3 insertions(+), 34 deletions(-)
arch/x86/include/asm/irq_remapping.h +0 -2
@@ -31,7 +31,6 @@ struct irq_alloc_info;#ifdef CONFIG_IRQ_REMAP -extern int irq_remapping_supported (void );extern void set_irq_remapping_broken (void );extern int irq_remapping_prepare (void );extern int irq_remapping_enable (void );
@@ -57,7 +56,6 @@ static inline struct irq_domain *arch_get_ir_parent_domain(void)#else /* CONFIG_IRQ_REMAP */ -static inline int irq_remapping_supported (void ) {return 0 ; }static inline void set_irq_remapping_broken (void ) { }static inline int irq_remapping_prepare (void ) {return -ENODEV ; }static inline int irq_remapping_enable (void ) {return -ENODEV ; }
arch/x86/kernel/apic/apic.c +1 -6
@@ -1574,12 +1574,7 @@ void enable_x2apic(void)static int __init try_to_enable_IR (void ) { -#ifdef CONFIG_IRQ_REMAP -if (!irq_remapping_supported ()) { -pr_debug ("intr-remapping not supported\n" ); -return -1 ; - } - +#ifdef CONFIG_X86_IO_APIC if (!x2apic_enabled () && skip_ioapic_setup) {pr_info ("Skipped enabling intr-remap because of skipping " "io-apic setup\n" );
drivers/iommu/amd_iommu.c +0 -1
@@ -4114,7 +4114,6 @@ static struct irq_domain *get_irq_domain(struct irq_alloc_info *info) }struct irq_remap_ops amd_iommu_irq_ops = { - .supported = amd_iommu_supported, .prepare = amd_iommu_prepare, .enable = amd_iommu_enable, .disable = amd_iommu_disable,
drivers/iommu/amd_iommu_init.c +0 -5
@@ -2130,11 +2130,6 @@ int __init amd_iommu_prepare(void)return iommu_go_to_state (IOMMU_ACPI_FINISHED ); } -int __init amd_iommu_supported (void ) -{ -return amd_iommu_irq_remap ?1 :0 ; -} -int __init amd_iommu_enable (void ) {int ret;
drivers/iommu/amd_iommu_proto.h +0 -1
@@ -33,7 +33,6 @@ extern void amd_iommu_init_notifier(void);extern void amd_iommu_init_api (void );/* Needed for interrupt remapping */ -extern int amd_iommu_supported (void );extern int amd_iommu_prepare (void );extern int amd_iommu_enable (void );extern void amd_iommu_disable (void );
drivers/iommu/intel_irq_remapping.c +0 -6
@@ -510,11 +510,6 @@ static int __init dmar_x2apic_optout(void)return dmar->flags &DMAR_X2APIC_OPT_OUT ; } -static int __init intel_irq_remapping_supported (void ) -{ -return 1 ; -} -static void __init intel_cleanup_irq_remapping (void ) {struct dmar_drhd_unit *drhd;
@@ -958,7 +953,6 @@ static struct irq_domain *intel_get_irq_domain(struct irq_alloc_info *info) }struct irq_remap_ops intel_irq_remap_ops = { - .supported = intel_irq_remapping_supported, .prepare = intel_prepare_irq_remapping, .enable = intel_enable_irq_remapping, .disable = disable_irq_remapping,
drivers/iommu/irq_remapping.c +2 -10
@@ -80,19 +80,11 @@ void set_irq_remapping_broken(void) irq_remap_broken =1 ; } -int irq_remapping_supported (void ) +int __init irq_remapping_prepare (void ) {if (disable_irq_remap) -return 0 ; - -if (!remap_ops || !remap_ops->supported) -return 0 ; +return -ENOSYS ; -return remap_ops->supported (); -} - -int __init irq_remapping_prepare (void ) -{ remap_ops = &intel_irq_remap_ops;#ifdef CONFIG_AMD_IOMMU
drivers/iommu/irq_remapping.h +0 -3
@@ -36,9 +36,6 @@ extern int no_x2apic_optout;extern int irq_remapping_enabled;struct irq_remap_ops { -/* Check whether Interrupt Remapping is supported */ -int (*supported)(void ); -/* Initializes hardware and makes it ready for remapping interrupts */ int (*prepare)(void );
Signature · 1 line
1.7.10.4
RFC PATCH 6/9 iommu/irq_remapping: Refine function irq_remapping_prepare() for maintenance
In reply to Jiang LiuDo not directly assign intel_irq_remap_ops to remap_ops.
--- drivers/iommu/irq_remapping.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/iommu/irq_remapping.c +8 -8
@@ -85,15 +85,15 @@ int __init irq_remapping_prepare(void)if (disable_irq_remap)return -ENOSYS ; - remap_ops = &intel_irq_remap_ops; - -#ifdef CONFIG_AMD_IOMMU -if (amd_iommu_irq_ops.prepare () ==0 ) { +if (intel_irq_remap_ops.prepare () ==0 ) + remap_ops = &intel_irq_remap_ops; +else if (IS_ENABLED (CONFIG_AMD_IOMMU ) && + amd_iommu_irq_ops.prepare () ==0 ) remap_ops = &amd_iommu_irq_ops; -return 0 ; - } -#endif -return remap_ops->prepare (); +else +return -ENOSYS ; + +return 0 ; }int __init irq_remapping_enable (void )
Signature · 1 line
1.7.10.4
RFC PATCH 7/9 iommu/irq_remapping: Change variable disable_irq_remap to be static
In reply to Jiang LiuChange variable disable_irq_remap to be static for easy maintenance.
--- drivers/iommu/amd_iommu_init.c | 5 ++--- drivers/iommu/intel_irq_remapping.c | 1 - drivers/iommu/irq_remapping.c | 3 +-- drivers/iommu/irq_remapping.h | 2 -- 4 files changed, 3 insertions(+), 8 deletions(-)
drivers/iommu/amd_iommu_init.c +2 -3
@@ -2018,9 +2018,6 @@ static bool detect_ivrs(void)/* Make sure ACS will be enabled during PCI probe */ pci_request_acs (); -if (!disable_irq_remap) - amd_iommu_irq_remap = true; -return true; }
@@ -2127,6 +2124,8 @@ static int __init iommu_go_to_state(enum iommu_init_state state)#ifdef CONFIG_IRQ_REMAP int __init amd_iommu_prepare (void ) { + amd_iommu_irq_remap = true; +return iommu_go_to_state (IOMMU_ACPI_FINISHED ); }
drivers/iommu/intel_irq_remapping.c +0 -1
@@ -539,7 +539,6 @@ static int __init intel_prepare_irq_remapping(void)"interrupt remapping is being disabled. Please\n" "contact your BIOS vendor for an update\n");add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK ); - disable_irq_remap =1 ;return -ENODEV ; }
drivers/iommu/irq_remapping.c +1 -2
@@ -18,12 +18,11 @@#include "irq_remapping.h" int irq_remapping_enabled; - -int disable_irq_remap;int irq_remap_broken;int disable_sourceid_checking;int no_x2apic_optout; +static int disable_irq_remap;static struct irq_remap_ops *remap_ops;static void irq_remapping_disable_io_apic (void )
drivers/iommu/irq_remapping.h +0 -2
@@ -29,7 +29,6 @@ struct msi_msg;struct irq_domain ;struct irq_alloc_info ; -extern int disable_irq_remap;extern int irq_remap_broken;extern int disable_sourceid_checking;extern int no_x2apic_optout;
@@ -66,7 +65,6 @@ extern void ir_ack_apic_edge(struct irq_data *data);#else /* CONFIG_IRQ_REMAP */ #define irq_remapping_enabled 0 -#define disable_irq_remap 1#define irq_remap_broken 0#endif /* CONFIG_IRQ_REMAP */
Signature · 1 line
1.7.10.4
RFC PATCH 8/9 iommu/irq_remapping: Normailize the way to detect whether IR is enabled
In reply to Jiang LiuRefine code by normailizing the way to detect whether IR is enabled.
--- drivers/iommu/irq_remapping.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/iommu/irq_remapping.c +12 -18
@@ -112,22 +112,16 @@ int __init irq_remapping_enable(void)void irq_remapping_disable (void ) { -if (!irq_remapping_enabled || - !remap_ops || - !remap_ops->disable) -return ; - - remap_ops->disable (); +if (irq_remapping_enabled && remap_ops->disable) + remap_ops->disable (); }int irq_remapping_reenable (int mode) { -if (!irq_remapping_enabled || - !remap_ops || - !remap_ops->reenable) -return 0 ; +if (irq_remapping_enabled && remap_ops->reenable) +return remap_ops->reenable (mode); -return remap_ops->reenable (mode); +return 0 ; }int __init irq_remap_enable_fault_handling (void )
@@ -135,7 +129,7 @@ int __init irq_remap_enable_fault_handling(void)if (!irq_remapping_enabled)return 0 ; -if (!remap_ops || !remap_ops->enable_faulting) +if (!remap_ops->enable_faulting)return -ENODEV ;return remap_ops->enable_faulting ();
@@ -176,10 +170,10 @@ void irq_remapping_print_chip(struct irq_data *data, struct seq_file *p)struct irq_domain *irq_remapping_get_ir_irq_domain (struct irq_alloc_info *info) { -if (!remap_ops || !remap_ops->get_ir_irq_domain) -return NULL ; +if (irq_remapping_enabled && remap_ops->get_ir_irq_domain) +return remap_ops->get_ir_irq_domain (info); -return remap_ops->get_ir_irq_domain (info); +return NULL ; }/**
@@ -194,8 +188,8 @@ irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)struct irq_domain *irq_remapping_get_irq_domain (struct irq_alloc_info *info) { -if (!remap_ops || !remap_ops->get_irq_domain) -return NULL ; +if (irq_remapping_enabled && remap_ops->get_irq_domain) +return remap_ops->get_irq_domain (info); -return remap_ops->get_irq_domain (info); +return NULL ; }
Signature · 1 line
1.7.10.4
RFC PATCH 9/9 iommu/irq_remapping: Kill unused function irq_remapping_print_chip()
In reply to Jiang LiuNow there's no user of irq_remapping_print_chip(), so kill it.
--- arch/x86/include/asm/irq_remapping.h | 2 -- drivers/iommu/irq_remapping.c | 13 ------------- 2 files changed, 15 deletions(-)
arch/x86/include/asm/irq_remapping.h +0 -2
@@ -43,7 +43,6 @@ extern struct irq_domain * irq_remapping_get_ir_irq_domain( struct irq_alloc_info *info);extern struct irq_domain *irq_remapping_get_irq_domain (struct irq_alloc_info *info); -extern void irq_remapping_print_chip (struct irq_data *data,struct seq_file *p);/* Create PCI MSI/MSIx irqdomain, use @parent as the parent irqdomain. */ extern struct irq_domain *arch_create_msi_irq_domain (struct irq_domain *parent);
@@ -79,6 +78,5 @@ irq_remapping_get_irq_domain(struct irq_alloc_info *info)return NULL ; } -#define irq_remapping_print_chip NULL#endif /* CONFIG_IRQ_REMAP */ #endif /* __X86_IRQ_REMAPPING_H */
drivers/iommu/irq_remapping.c +0 -13
@@ -146,19 +146,6 @@ void ir_ack_apic_edge(struct irq_data *data)ack_APIC_irq (); } -void irq_remapping_print_chip (struct irq_data *data,struct seq_file *p) -{ -/* -* Assume interrupt is remapped if the parent irqdomain isn't the -* vector domain, which is true for MSI, HPET and IOAPIC on x86 -* platforms. -*/ -if (data->domain && data->domain->parent !=arch_get_ir_parent_domain ()) -seq_printf (p," IR-%s" , data->chip->name); -else -seq_printf (p," %s" , data->chip->name); -} -/** * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU * device serving request @info
Signature · 1 line
1.7.10.4