* [Patch v2 02/16] iommu/vt-d: Move iommu preparatory allocations to irq_remap_ops.prepare
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 03/16] iommu/vt-d: Convert allocations to GFP_KERNEL Jiang Liu
` (8 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
x86-DgEjT+Ai2ygdnm+yROfE0A, Jiang Liu,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
From: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
The whole iommu setup for irq remapping is a convoluted mess. The
iommu detect function gets called from mem_init() and the prepare
callback gets called from enable_IR_x2apic() for unknown reasons.
Of course AMD and Intel setup differs in nonsensical ways. Intels
prepare callback is explicit while AMDs prepare callback is implicit
in setup_irq_remapping_ops() just to be called in the prepare call
again.
Because all of this gets called from enable_IR_x2apic() and the dmar
prepare function merily parses the ACPI tables, but does not allocate
memory we end up with memory allocation from irq disabled context
later on.
AMDs iommu code at least allocates the required memory from the
prepare function. That has issues as well, but thats not scope of this
patch.
The goal of this change is to distangle the allocation from the actual
enablement. There is no point to allocate memory from irq disabled
regions with GFP_ATOMIC just because it does not matter at that point
in the boot stage. It matters with physical hotplug later on.
There is another issue with the current setup. Due to the conversion
to stacked irqdomains we end up with a call into the irqdomain
allocation code from irq disabled context, but that code does
GFP_KERNEL allocations rightfully as there is no reason to do
preperatory allocations with GFP_ATOMIC.
That change caused the allocator code to complain about GFP_KERNEL
allocations invoked in atomic context. Boris provided a temporary
hackaround which changed the GFP flags if irq_domain_add() got called
from atomic context. Not pretty and we really dont want to get this
into a mainline release for obvious reasons.
Move the ACPI table parsing and the resulting memory allocations from
the enable to the prepare function. That allows to get rid of the
horrible hackaround in irq_domain_add() later.
[Jiang] Rebased onto v3.19
Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Tested-by: Borislav Petkov <bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org>
Acked-by: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Link: http://lkml.kernel.org/r/20141205084147.313026156-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org
Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
drivers/iommu/intel_irq_remapping.c | 64 ++++++++++++++++++++++++-----------
1 file changed, 44 insertions(+), 20 deletions(-)
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index a55b207b9425..2360cb6a8896 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -595,22 +595,57 @@ static int __init intel_irq_remapping_supported(void)
return 1;
}
-static int __init intel_enable_irq_remapping(void)
+static void __init intel_cleanup_irq_remapping(void)
+{
+ struct dmar_drhd_unit *drhd;
+ struct intel_iommu *iommu;
+
+ for_each_iommu(iommu, drhd) {
+ if (ecap_ir_support(iommu->ecap)) {
+ iommu_disable_irq_remapping(iommu);
+ intel_teardown_irq_remapping(iommu);
+ }
+ }
+
+ if (x2apic_supported())
+ pr_warn("Failed to enable irq remapping. You are vulnerable to irq-injection attacks.\n");
+}
+
+static int __init intel_prepare_irq_remapping(void)
{
struct dmar_drhd_unit *drhd;
struct intel_iommu *iommu;
- bool x2apic_present;
- int setup = 0;
- int eim = 0;
- x2apic_present = x2apic_supported();
+ if (dmar_table_init() < 0)
+ return -1;
if (parse_ioapics_under_ir() != 1) {
- printk(KERN_INFO "Not enable interrupt remapping\n");
+ printk(KERN_INFO "Not enabling interrupt remapping\n");
goto error;
}
- if (x2apic_present) {
+ for_each_iommu(iommu, drhd) {
+ if (!ecap_ir_support(iommu->ecap))
+ continue;
+
+ /* Do the allocations early */
+ if (intel_setup_irq_remapping(iommu))
+ goto error;
+ }
+ return 0;
+error:
+ intel_cleanup_irq_remapping();
+ return -1;
+}
+
+static int __init intel_enable_irq_remapping(void)
+{
+ struct dmar_drhd_unit *drhd;
+ struct intel_iommu *iommu;
+ int setup = 0;
+ int eim = 0;
+
+ if (x2apic_supported()) {
pr_info("Queued invalidation will be enabled to support x2apic and Intr-remapping.\n");
eim = !dmar_x2apic_optout();
@@ -678,9 +713,6 @@ static int __init intel_enable_irq_remapping(void)
if (!ecap_ir_support(iommu->ecap))
continue;
- if (intel_setup_irq_remapping(iommu))
- goto error;
-
iommu_set_irq_remapping(iommu, eim);
setup = 1;
}
@@ -702,15 +734,7 @@ static int __init intel_enable_irq_remapping(void)
return eim ? IRQ_REMAP_X2APIC_MODE : IRQ_REMAP_XAPIC_MODE;
error:
- for_each_iommu(iommu, drhd)
- if (ecap_ir_support(iommu->ecap)) {
- iommu_disable_irq_remapping(iommu);
- intel_teardown_irq_remapping(iommu);
- }
-
- if (x2apic_present)
- pr_warn("Failed to enable irq remapping. You are vulnerable to irq-injection attacks.\n");
-
+ intel_cleanup_irq_remapping();
return -1;
}
@@ -1200,7 +1224,7 @@ static int intel_alloc_hpet_msi(unsigned int irq, unsigned int id)
struct irq_remap_ops intel_irq_remap_ops = {
.supported = intel_irq_remapping_supported,
- .prepare = dmar_table_init,
+ .prepare = intel_prepare_irq_remapping,
.enable = intel_enable_irq_remapping,
.disable = disable_irq_remapping,
.reenable = reenable_irq_remapping,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 03/16] iommu/vt-d: Convert allocations to GFP_KERNEL
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-01-07 7:31 ` [Patch v2 02/16] iommu/vt-d: Move iommu preparatory allocations to irq_remap_ops.prepare Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 04/16] x86/apic: Panic if kernel doesn't support x2apic but BIOS has enabled x2apic Jiang Liu
` (7 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
x86-DgEjT+Ai2ygdnm+yROfE0A, Jiang Liu,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
From: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
No reason anymore to do GFP_ATOMIC allocations which are not harmful
in the normal bootup case, but matter in the physical hotplug
scenario.
Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Tested-by: Borislav Petkov <bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org>
Acked-by: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Link: http://lkml.kernel.org/r/20141205084147.472428339-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org
Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
drivers/iommu/intel_irq_remapping.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 2360cb6a8896..1e7e09327753 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -481,11 +481,11 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
if (iommu->ir_table)
return 0;
- ir_table = kzalloc(sizeof(struct ir_table), GFP_ATOMIC);
+ ir_table = kzalloc(sizeof(struct ir_table), GFP_KERNEL);
if (!ir_table)
return -ENOMEM;
- pages = alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO,
+ pages = alloc_pages_node(iommu->node, GFP_KERNEL | __GFP_ZERO,
INTR_REMAP_PAGE_ORDER);
if (!pages) {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 04/16] x86/apic: Panic if kernel doesn't support x2apic but BIOS has enabled x2apic
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-01-07 7:31 ` [Patch v2 02/16] iommu/vt-d: Move iommu preparatory allocations to irq_remap_ops.prepare Jiang Liu
2015-01-07 7:31 ` [Patch v2 03/16] iommu/vt-d: Convert allocations to GFP_KERNEL Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 05/16] x86/apic: Kill useless variable x2apic_enabled in function enable_IR_x2apic() Jiang Liu
` (6 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov,
x86-DgEjT+Ai2ygdnm+yROfE0A, Jiang Liu, David Rientjes,
HATAYAMA Daisuke, Jan Beulich, Richard Weinberger, Oren Twaig
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Ingo Molnar
When kernel doesn't support X2APIC but BIOS has enabled X2APIC, system
may panic or hang without useful messages. On the other hand, it's
hard to dynamically disable X2APIC when CONFIG_X86_X2APIC is disabled.
So panic with a clear message in such a case.
System panics as below when X2APIC is disabled and interrupt remapping
is enabled:
[ 0.316118] LAPIC pending interrupts after 512 EOI
[ 0.322126] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[ 0.368655] Kernel panic - not syncing: timer doesn't work through Interrupt-remapped IO-APIC
[ 0.378300] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.18.0+ #340
[ 0.385300] Hardware name: Intel Corporation BRICKLAND/BRICKLAND, BIOS BRIVTIN1.86B.0051.L05.1406240953 06/24/2014
[ 0.396997] ffff88046dc03000 ffff88046c307dd8 ffffffff8179dada 00000000000043f2
[ 0.405629] ffffffff81a92158 ffff88046c307e58 ffffffff8179b757 0000000000000002
[ 0.414261] 0000000000000008 ffff88046c307e68 ffff88046c307e08 ffffffff813ad82b
[ 0.422890] Call Trace:
[ 0.425711] [<ffffffff8179dada>] dump_stack+0x45/0x57
[ 0.431533] [<ffffffff8179b757>] panic+0xc1/0x1f5
[ 0.436978] [<ffffffff813ad82b>] ? delay_tsc+0x3b/0x70
[ 0.442910] [<ffffffff8166fa2c>] panic_if_irq_remap+0x1c/0x20
[ 0.449524] [<ffffffff81d73645>] setup_IO_APIC+0x405/0x82e
[ 0.464979] [<ffffffff81d6fcc2>] native_smp_prepare_cpus+0x2d9/0x31c
[ 0.472274] [<ffffffff81d5d0ac>] kernel_init_freeable+0xd6/0x223
[ 0.479170] [<ffffffff81792ad0>] ? rest_init+0x80/0x80
[ 0.485099] [<ffffffff81792ade>] kernel_init+0xe/0xf0
[ 0.490932] [<ffffffff817a537c>] ret_from_fork+0x7c/0xb0
[ 0.497054] [<ffffffff81792ad0>] ? rest_init+0x80/0x80
[ 0.502983] ---[ end Kernel panic - not syncing: timer doesn't work through Interrupt-remapped IO-APIC
System hangs as below when X2APIC and interrupt remapping are both disabled:
[ 1.102782] pci 0000:00:02.0: System wakeup disabled by ACPI
[ 1.109351] pci 0000:00:03.0: System wakeup disabled by ACPI
[ 1.115915] pci 0000:00:03.2: System wakeup disabled by ACPI
[ 1.122479] pci 0000:00:03.3: System wakeup disabled by ACPI
[ 1.132274] pci 0000:00:1c.0: Enabling MPC IRBNCE
[ 1.137620] pci 0000:00:1c.0: Intel PCH root port ACS workaround enabled
[ 1.145239] pci 0000:00:1c.0: System wakeup disabled by ACPI
[ 1.151790] pci 0000:00:1c.7: Enabling MPC IRBNCE
[ 1.157128] pci 0000:00:1c.7: Intel PCH root port ACS workaround enabled
[ 1.164748] pci 0000:00:1c.7: System wakeup disabled by ACPI
[ 1.171447] pci 0000:00:1e.0: System wakeup disabled by ACPI
[ 1.178612] acpiphp: Slot [8] registered
[ 1.183095] pci 0000:00:02.0: PCI bridge to [bus 01]
[ 1.188867] acpiphp: Slot [2] registered
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
arch/x86/kernel/apic/apic.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 36249c715da0..8b58e23bc5e8 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1597,6 +1597,14 @@ void __init enable_IR_x2apic(void)
int ret, x2apic_enabled = 0;
int hardware_init_ret;
+ if (!IS_ENABLED(CONFIG_X86_X2APIC)) {
+ u64 msr;
+
+ rdmsrl(MSR_IA32_APICBASE, msr);
+ if (msr & X2APIC_ENABLE)
+ panic("BIOS has enabled x2apic but kernel doesn't support x2apic, please disable x2apic in BIOS.\n");
+ }
+
hardware_init_ret = irq_remapping_prepare();
if (hardware_init_ret && !x2apic_supported())
return;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 05/16] x86/apic: Kill useless variable x2apic_enabled in function enable_IR_x2apic()
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (2 preceding siblings ...)
2015-01-07 7:31 ` [Patch v2 04/16] x86/apic: Panic if kernel doesn't support x2apic but BIOS has enabled x2apic Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 06/16] x86/apic: Correctly detect X2APIC status in function enable_IR() Jiang Liu
` (5 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov,
x86-DgEjT+Ai2ygdnm+yROfE0A, Jiang Liu, David Rientjes,
HATAYAMA Daisuke, Jan Beulich, Richard Weinberger, Oren Twaig
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Ingo Molnar
Local variable x2apic_enabled has been assigned to but never referred,
so kill it.
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
arch/x86/kernel/apic/apic.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 8b58e23bc5e8..a614e242473b 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -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;
if (!IS_ENABLED(CONFIG_X86_X2APIC)) {
@@ -1652,8 +1652,6 @@ void __init enable_IR_x2apic(void)
goto skip_x2apic;
}
- x2apic_enabled = 1;
-
if (x2apic_supported() && !x2apic_mode) {
x2apic_mode = 1;
enable_x2apic();
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 06/16] x86/apic: Correctly detect X2APIC status in function enable_IR()
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (3 preceding siblings ...)
2015-01-07 7:31 ` [Patch v2 05/16] x86/apic: Kill useless variable x2apic_enabled in function enable_IR_x2apic() Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 07/16] x86/apic: Refine enable_IR_x2apic() and related functions Jiang Liu
` (4 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov,
x86-DgEjT+Ai2ygdnm+yROfE0A, Jiang Liu, David Rientjes,
HATAYAMA Daisuke, Jan Beulich, Richard Weinberger, Oren Twaig
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Ingo Molnar
X2APIC 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.
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
arch/x86/kernel/apic/apic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index a614e242473b..8ce2b8236c1b 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -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;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 07/16] x86/apic: Refine enable_IR_x2apic() and related functions
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (4 preceding siblings ...)
2015-01-07 7:31 ` [Patch v2 06/16] x86/apic: Correctly detect X2APIC status in function enable_IR() Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
[not found] ` <1420615903-28253-8-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-01-07 7:31 ` [Patch v2 08/16] iommu/vt-d: Prepare for killing function irq_remapping_supported() Jiang Liu
` (3 subsequent siblings)
9 siblings, 1 reply; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov,
x86-DgEjT+Ai2ygdnm+yROfE0A, Jiang Liu, David Rientjes,
HATAYAMA Daisuke, Jan Beulich, Richard Weinberger, Oren Twaig
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Ingo Molnar
Refine enable_IR_x2apic() and related functions for better readability.
It also changes the way to handle IR in XAPIC mode when enabling X2APIC.
Previously it just skips X2APIC initialization without checking max CPU
APIC ID in system, which may cause problem if system has CPU with APIC
ID bigger than 255. So treat IR in XAPIC mode as same as IR is disabled
when enabling CPU X2APIC.
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
arch/x86/kernel/apic/apic.c | 85 +++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 44 deletions(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 8ce2b8236c1b..09ac1e4ef86b 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -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,17 +1585,48 @@ int __init enable_IR(void)
"io-apic setup\n");
return -1;
}
+#endif
return irq_remapping_enable();
+}
+
+static __init void try_to_enable_x2apic(int ir_stat)
+{
+#ifdef CONFIG_X86_X2APIC
+ if (!x2apic_supported())
+ return;
+
+ if (ir_stat != IRQ_REMAP_X2APIC_MODE) {
+ /* IR is required if there is APIC ID > 255 even when running
+ * under KVM
+ */
+ if (max_physical_apicid > 255 ||
+ !hypervisor_x2apic_available()) {
+ pr_info("IRQ remapping doesn't support X2APIC mode, disable x2apic.\n");
+ if (x2apic_preenabled)
+ disable_x2apic();
+ return;
+ }
+
+ /*
+ * without IR all CPUs can be addressed by IOAPIC/MSI
+ * only in physical mode
+ */
+ x2apic_force_phys();
+ }
+
+ if (!x2apic_mode) {
+ x2apic_mode = 1;
+ enable_x2apic();
+ pr_info("Enabled x2apic\n");
+ }
#endif
- return -1;
}
void __init enable_IR_x2apic(void)
{
unsigned long flags;
- int ret;
- int hardware_init_ret;
+ int ret, ir_stat;
if (!IS_ENABLED(CONFIG_X86_X2APIC)) {
u64 msr;
@@ -1605,8 +1636,8 @@ void __init enable_IR_x2apic(void)
panic("BIOS has enabled x2apic but kernel doesn't support x2apic, please disable x2apic in BIOS.\n");
}
- hardware_init_ret = irq_remapping_prepare();
- if (hardware_init_ret && !x2apic_supported())
+ ir_stat = irq_remapping_prepare();
+ if (ir_stat < 0 && !x2apic_supported())
return;
ret = save_ioapic_entries();
@@ -1621,45 +1652,11 @@ void __init enable_IR_x2apic(void)
if (x2apic_preenabled && nox2apic)
disable_x2apic();
+ if (ir_stat >= 0)
+ ir_stat = try_to_enable_IR();
+ try_to_enable_x2apic(ir_stat);
- if (hardware_init_ret)
- ret = -1;
- else
- ret = enable_IR();
-
- if (!x2apic_supported())
- goto skip_x2apic;
-
- if (ret < 0) {
- /* IR is required if there is APIC ID > 255 even when running
- * under KVM
- */
- if (max_physical_apicid > 255 ||
- !hypervisor_x2apic_available()) {
- if (x2apic_preenabled)
- disable_x2apic();
- goto skip_x2apic;
- }
- /*
- * without IR all CPUs can be addressed by IOAPIC/MSI
- * only in physical mode
- */
- 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) {
- x2apic_mode = 1;
- enable_x2apic();
- pr_info("Enabled x2apic\n");
- }
-
-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);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 08/16] iommu/vt-d: Prepare for killing function irq_remapping_supported()
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (5 preceding siblings ...)
2015-01-07 7:31 ` [Patch v2 07/16] x86/apic: Refine enable_IR_x2apic() and related functions Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 09/16] iommu/vt-d: Allocate IRQ remapping data structures only for all IOMMUs Jiang Liu
` (2 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov
Cc: Tony Luck, x86-DgEjT+Ai2ygdnm+yROfE0A,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
Jiang Liu
Prepare for killing function irq_remapping_supported() by moving code
from intel_irq_remapping_supported() into intel_prepare_irq_remapping().
Combined with patch from Joerg at https://lkml.org/lkml/2014/12/15/487,
so assume an signed-off from Joerg.
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/intel_irq_remapping.c | 58 +++++++++++++++--------------------
1 file changed, 25 insertions(+), 33 deletions(-)
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 1e7e09327753..8ccc7aa7e43a 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -568,30 +568,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;
}
@@ -616,26 +592,42 @@ static int __init intel_prepare_irq_remapping(void)
struct dmar_drhd_unit *drhd;
struct intel_iommu *iommu;
+ /* First check whether IRQ remapping should be enabled */
+ if (disable_irq_remap)
+ return -ENODEV;
+
+ 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)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 09/16] iommu/vt-d: Allocate IRQ remapping data structures only for all IOMMUs
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (6 preceding siblings ...)
2015-01-07 7:31 ` [Patch v2 08/16] iommu/vt-d: Prepare for killing function irq_remapping_supported() Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 10/16] iommu/vt-d: Allow IR works in XAPIC mode though CPU works in X2APIC mode Jiang Liu
2015-01-07 7:31 ` [Patch v2 11/16] x86/apic: Only disable CPU x2apic mode when necessary Jiang Liu
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov
Cc: Joerg Roedel, x86-DgEjT+Ai2ygdnm+yROfE0A,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
Jiang Liu
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
IRQ remapping is only supported when all IOMMUs in the
system support it. So check if all IOMMUs in the system
support IRQ remapping before doing the allocations.
[Jiang]
1) Rebased onto v3.19.
2) Remove redundant check of ecap_ir_support(iommu->ecap) in function
intel_enable_irq_remapping().
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
drivers/iommu/intel_irq_remapping.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 8ccc7aa7e43a..137663bd5da2 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -619,10 +619,16 @@ static int __init intel_prepare_irq_remapping(void)
goto error;
}
+ /* First make sure all IOMMUs support IRQ remapping */
for_each_iommu(iommu, drhd)
- if (!ecap_ir_support(iommu->ecap) ||
- intel_setup_irq_remapping(iommu))
+ if (!ecap_ir_support(iommu->ecap))
+ goto error;
+
+ /* Do the allocations early */
+ for_each_iommu(iommu, drhd)
+ if (intel_setup_irq_remapping(iommu))
goto error;
+
return 0;
error:
@@ -673,16 +679,12 @@ static int __init intel_enable_irq_remapping(void)
/*
* check for the Interrupt-remapping support
*/
- for_each_iommu(iommu, drhd) {
- if (!ecap_ir_support(iommu->ecap))
- continue;
-
+ for_each_iommu(iommu, drhd)
if (eim && !ecap_eim_support(iommu->ecap)) {
printk(KERN_INFO "DRHD %Lx: EIM not supported by DRHD, "
" ecap %Lx\n", drhd->reg_base_addr, iommu->ecap);
goto error;
}
- }
/*
* Enable queued invalidation for all the DRHD's.
@@ -702,9 +704,6 @@ static int __init intel_enable_irq_remapping(void)
* Setup Interrupt-remapping for all the DRHD's now.
*/
for_each_iommu(iommu, drhd) {
- if (!ecap_ir_support(iommu->ecap))
- continue;
-
iommu_set_irq_remapping(iommu, eim);
setup = 1;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 10/16] iommu/vt-d: Allow IR works in XAPIC mode though CPU works in X2APIC mode
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (7 preceding siblings ...)
2015-01-07 7:31 ` [Patch v2 09/16] iommu/vt-d: Allocate IRQ remapping data structures only for all IOMMUs Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
2015-01-07 7:31 ` [Patch v2 11/16] x86/apic: Only disable CPU x2apic mode when necessary Jiang Liu
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov
Cc: x86-DgEjT+Ai2ygdnm+yROfE0A,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
Jiang Liu, linux-kernel-u79uwXL29TY76Z2rM5mHXA
Currently if CPU supports X2APIC, IR hardware must work in X2APIC mode
or disabled. Change the code to support IR working in XAPIC mode when
CPU supports X2APIC. Then the CPU APIC driver will decide how to handle
such as configuration by:
1) Disabling X2APIC mode
2) Forcing X2APIC physical mode
This change also fixes a live locking when
1) BIOS enables CPU X2APIC
2) DMAR table disables X2APIC mode or IR hardware doesn't support X2APIC
with following messages:
[ 37.863463] dmar: INTR-REMAP: Request device [[f0:1f.7] fault index 2
[ 37.863463] INTR-REMAP:[fault reason 36] Detected reserved fields in the IRTE entry
[ 37.879372] dmar: INTR-REMAP: Request device [[f0:1f.7] fault index 2
[ 37.879372] INTR-REMAP:[fault reason 36] Detected reserved fields in the IRTE entry
[ 37.895282] dmar: INTR-REMAP: Request device [[f0:1f.7] fault index 2
[ 37.895282] INTR-REMAP:[fault reason 36] Detected reserved fields in the IRTE entry
[ 37.911192] dmar: INTR-REMAP: Request device [[f0:1f.7] fault index 2
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
drivers/iommu/intel_irq_remapping.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 137663bd5da2..9d67c12c2ffb 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -32,8 +32,9 @@ struct hpet_scope {
};
#define IR_X2APIC_MODE(mode) (mode ? (1 << 11) : 0)
-#define IRTE_DEST(dest) ((x2apic_mode) ? dest : dest << 8)
+#define IRTE_DEST(dest) ((eim_mode) ? dest : dest << 8)
+static int __read_mostly eim_mode;
static struct ioapic_scope ir_ioapic[MAX_IO_APICS];
static struct hpet_scope ir_hpet[MAX_HPET_TBS];
@@ -644,8 +645,6 @@ static int __init intel_enable_irq_remapping(void)
int eim = 0;
if (x2apic_supported()) {
- pr_info("Queued invalidation will be enabled to support x2apic and Intr-remapping.\n");
-
eim = !dmar_x2apic_optout();
if (!eim)
printk(KERN_WARNING
@@ -683,8 +682,11 @@ static int __init intel_enable_irq_remapping(void)
if (eim && !ecap_eim_support(iommu->ecap)) {
printk(KERN_INFO "DRHD %Lx: EIM not supported by DRHD, "
" ecap %Lx\n", drhd->reg_base_addr, iommu->ecap);
- goto error;
+ eim = 0;
}
+ eim_mode = eim;
+ if (eim)
+ pr_info("Queued invalidation will be enabled to support x2apic and Intr-remapping.\n");
/*
* Enable queued invalidation for all the DRHD's.
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread* [Patch v2 11/16] x86/apic: Only disable CPU x2apic mode when necessary
[not found] ` <1420615903-28253-1-git-send-email-jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (8 preceding siblings ...)
2015-01-07 7:31 ` [Patch v2 10/16] iommu/vt-d: Allow IR works in XAPIC mode though CPU works in X2APIC mode Jiang Liu
@ 2015-01-07 7:31 ` Jiang Liu
9 siblings, 0 replies; 19+ messages in thread
From: Jiang Liu @ 2015-01-07 7:31 UTC (permalink / raw)
To: Thomas Gleixner, Joerg Roedel, Benjamin Herrenschmidt,
Ingo Molnar, H. Peter Anvin, Yinghai Lu, Borislav Petkov,
x86-DgEjT+Ai2ygdnm+yROfE0A, Jiang Liu, David Rientjes,
HATAYAMA Daisuke, Jan Beulich, Richard Weinberger, Oren Twaig
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Tony Luck,
H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Ingo Molnar
When interrupt remapping hardware is not in X2APIC, CPU X2APIC mode
will be disabled if:
1) Maximum CPU APIC ID is bigger than 255
2) hypervisior doesn't support x2apic mode.
But we should only check whether hypervisor supports X2APIC mode when
hypervisor(CONFIG_HYPERVISOR_GUEST) is enabled, otherwise X2APIC will
always be disabled when CONFIG_HYPERVISOR_GUEST is disabled and IR
doesn't work in X2APIC mode.
Signed-off-by: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
arch/x86/kernel/apic/apic.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 09ac1e4ef86b..d714e72ed6d5 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1601,7 +1601,8 @@ static __init void try_to_enable_x2apic(int ir_stat)
* under KVM
*/
if (max_physical_apicid > 255 ||
- !hypervisor_x2apic_available()) {
+ (IS_ENABLED(CONFIG_HYPERVISOR_GUEST) &&
+ !hypervisor_x2apic_available())) {
pr_info("IRQ remapping doesn't support X2APIC mode, disable x2apic.\n");
if (x2apic_preenabled)
disable_x2apic();
--
1.7.10.4
^ permalink raw reply related [flat|nested] 19+ messages in thread