Skip to contentSkip to conversation

x86: enable x2APIC mode regardless of interrupt remapping support

PATCH Superseded Roger Pau Monne 2 participants 16 messages Nov 29, 2019 – Dec 4, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover x86: enable x2APIC mode regardless of interrupt remapping support

Hello,

The following series aims to allow enabling x2APIC mode without interrupt remapping support. The main usage of this would be in virtualized environments, that usually provide x2APIC support but not interrupt remapping.

See the last patch for some performance numbers of using x2APIC over xAPIC when running Xen in pvshim mode.

Thanks, Roger.

Roger Pau Monne (4):
x86/ioapic: only use dest32 with x2apic and interrupt remapping
enabled
x86/apic: force phys mode if interrupt remapping is disabled x86/smp: check APIC ID on AP bringup
x86/apic: allow enabling x2APIC mode regardless of interrupt remapping

 xen/arch/x86/apic.c           | 89 +++++++++++++++++------------------
 xen/arch/x86/genapic/x2apic.c |  8 ++++
 xen/arch/x86/io_apic.c        | 14 +++---
 xen/arch/x86/smpboot.c        |  7 +++
 4 files changed, 64 insertions(+), 54 deletions(-)
Signature · 7 lines
2.24.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/4 x86/ioapic: only use dest32 with x2apic and interrupt remapping enabled

The IO-APIC code assumes that x2apic being enabled also implies interrupt remapping being enabled, and hence will use the 32bit destination field in the IO-APIC entry.

This is safe now, but there's no reason to not enable x2APIC even without interrupt remapping, and hence the IO-APIC code needs to use the 32 bit destination field only when both interrupt remapping and x2APIC are enabled.

---
Changes since v1:
- Fix set_ioapic_affinity_irq.

---
 xen/arch/x86/io_apic.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/io_apic.c +7 -7
index 97cb2d154a..be0b085513 100644
@@ -562,7 +562,7 @@ set_ioapic_affinity_irq(struct irq_desc *desc, const cpumask_t *mask)
 
     dest = set_desc_affinity(desc, mask);
     if (dest != BAD_APICID) {
-        if ( !x2apic_enabled )
+        if ( !iommu_intremap )
             dest = SET_APIC_LOGICAL_ID(dest);
         entry = irq_2_pin + irq;
         for (;;) {
@@ -964,7 +964,7 @@ static hw_irq_controller ioapic_edge_type;
 #define IOAPIC_LEVEL	1
 
 #define SET_DEST(ent, mode, val) do { \
-    if (x2apic_enabled) \
+    if (x2apic_enabled && iommu_intremap) \
         (ent).dest.dest32 = (val); \
     else \
         (ent).dest.mode.mode##_dest = (val); \
@@ -1194,14 +1194,14 @@ static void /*__init*/ __print_IO_APIC(bool boot)
 	printk(KERN_DEBUG ".... IRQ redirection table:\n");
 
 	printk(KERN_DEBUG " NR %s Msk Trg IRR Pol Stat DstM DelM Vec\n",
-               x2apic_enabled ? " DestID" : "Dst");
+               (x2apic_enabled && iommu_intremap) ? " DestID" : "Dst");
 
 	for (i = 0; i <= reg_01.bits.entries; i++) {
             struct IO_APIC_route_entry entry;
 
             entry = ioapic_read_entry(apic, i, 0);
 
-            if ( x2apic_enabled )
+            if ( x2apic_enabled && iommu_intremap )
                 printk(KERN_DEBUG " %02x %08x", i, entry.dest.dest32);
             else
                 printk(KERN_DEBUG " %02x  %02x ", i,
@@ -2504,9 +2504,9 @@ void dump_ioapic_irq_info(void)
                    rte.dest_mode ? 'L' : 'P',
                    rte.delivery_status, rte.polarity, rte.irr,
                    rte.trigger ? 'L' : 'E', rte.mask,
-                   x2apic_enabled ? 8 : 2,
-                   x2apic_enabled ? rte.dest.dest32
-                                  : rte.dest.logical.logical_dest);
+                   (x2apic_enabled && iommu_intremap) ? 8 : 2,
+                   (x2apic_enabled && iommu_intremap) ?
+                       rte.dest.dest32 : rte.dest.logical.logical_dest);
 
             if ( entry->next == 0 )
                 break;
Signature · 7 lines
2.24.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [Xen-devel] [PATCH v2 1/4] x86/ioapic: only use dest32 with x2apic and interrupt remapping enabled

xen/arch/x86/io_apic.c set_ioapic_affinity_irq(struct irq_desc *desc, const cpumask_t *mask) · line 565

Quoted 8 lines · Roger Pau Monne
xen/arch/x86/io_apic.c +1 -1
@@ -562,7 +562,7 @@ set_ioapic_affinity_irq(struct irq_desc *desc, const cpumask_t *mask)
 
     dest = set_desc_affinity(desc, mask);
     if (dest != BAD_APICID) {
-        if ( !x2apic_enabled )
+        if ( !iommu_intremap )

To match description as well as the other changes done, doesn't this need to be "!x2apic_enabled || !iommu_intremap"?

jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [Xen-devel] [PATCH v2 1/4] x86/ioapic: only use dest32 with x2apic and interrupt remapping enabled

Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monne
xen/arch/x86/io_apic.c +0 -0
@@ -562,7 +562,7 @@ set_ioapic_affinity_irq(struct irq_desc *desc, const cpumask_t *mask)
 
Quoted 7 lines

xen/arch/x86/io_apic.c set_ioapic_affinity_irq(struct irq_desc *desc, const cpumask_t *mask) · line 565

Quoted 4 lines
xen/arch/x86/io_apic.c +1 -1
     dest = set_desc_affinity(desc, mask);
     if (dest != BAD_APICID) {
-        if ( !x2apic_enabled )
+        if ( !iommu_intremap )

To match description as well as the other changes done, doesn't this need to be "!x2apic_enabled || !iommu_intremap"?

Yes, in fact I already had this change on my local branch, not sure why it didn't end up in the patch I sent.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

PATCH v2 2/4 x86/apic: force phys mode if interrupt remapping is disabled

In reply to Roger Pau Monne

Cluster mode can only be used with interrupt remapping support, since the top 16bits of the APIC ID are filled with the cluster ID, and hence on systems where the physical ID is still smaller than 255 the cluster ID is not. Force x2APIC to use physical mode if there's no interrupt remapping support.

Note that this requires a further patch in order to enable x2APIC without interrupt remapping support.

---
Changes since v1:
- New in this version.

---
 xen/arch/x86/genapic/x2apic.c | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/arch/x86/genapic/x2apic.c +8 -0
index d5a17f10d5..7e32ee22ff 100644
@@ -228,6 +228,14 @@ const struct genapic *__init apic_x2apic_probe(void)
     if ( x2apic_phys < 0 )
         x2apic_phys = !!(acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL);
 
+    if ( !x2apic_phys && !iommu_intremap )
+        /*
+         * Force physical mode if there's no interrupt remapping support: the
+         * ID in clustered mode requires a 32 bit destination field due to the
+         * usage of the high 16 bits to store the cluster ID.
+         */
+        x2apic_phys = true;
+
     if ( x2apic_phys )
         return &apic_x2apic_phys;
 
Signature · 7 lines
2.24.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

Re: [Xen-devel] [PATCH v2 2/4] x86/apic: force phys mode if interrupt remapping is disabled

Quoted 10 lines · Roger Pau Monne

Cluster mode can only be used with interrupt remapping support, since the top 16bits of the APIC ID are filled with the cluster ID, and hence on systems where the physical ID is still smaller than 255 the cluster ID is not. Force x2APIC to use physical mode if there's no interrupt remapping support.

Note that this requires a further patch in order to enable x2APIC without interrupt remapping support.

This is missing a command line doc update and the logic below ignores a user-set x2apic_phys value. Will wait for comments on other patches before resending, sorry.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

Re: [Xen-devel] [PATCH v2 2/4] x86/apic: force phys mode if interrupt remapping is disabled

Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Roger Pau Monne

Cluster mode can only be used with interrupt remapping support, since the top 16bits of the APIC ID are filled with the cluster ID, and hence on systems where the physical ID is still smaller than 255 the cluster ID is not. Force x2APIC to use physical mode if there's no interrupt remapping support.

Quoted 7 lines
Quoted 4 lines

Note that this requires a further patch in order to enable x2APIC without interrupt remapping support.

This is missing a command line doc update and the logic below ignores a user-set x2apic_phys value.

So what would the behavior be in your opinion when the user has requested cluster mode? I can't see you do much other than panic()-ing, perhaps it's better to override the request (as you already do)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Re: [Xen-devel] [PATCH v2 2/4] x86/apic: force phys mode if interrupt remapping is disabled

Quoted 13 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Roger Pau Monne

Cluster mode can only be used with interrupt remapping support, since the top 16bits of the APIC ID are filled with the cluster ID, and hence on systems where the physical ID is still smaller than 255 the cluster ID is not. Force x2APIC to use physical mode if there's no interrupt remapping support.

Note that this requires a further patch in order to enable x2APIC without interrupt remapping support.

Quoted 7 lines
Quoted 2 lines

This is missing a command line doc update and the logic below ignores a user-set x2apic_phys value.

So what would the behavior be in your opinion when the user has requested cluster mode? I can't see you do much other than panic()-ing, perhaps it's better to override the request (as you already do)?

I think panic'ing is fine, a user shouldn't be setting x2apic_phys unless they know what are doing, and then Xen changing it on the back of the user also doesn't seem fine.

A panic explaining that x2apic_phys=false is not supported and that the box can only be booted with x2apic phys mode should be fine IMO.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw

Re: [Xen-devel] [PATCH v2 2/4] x86/apic: force phys mode if interrupt remapping is disabled

Quoted 22 lines · Roger Pau Monné
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Roger Pau Monne

Cluster mode can only be used with interrupt remapping support, since the top 16bits of the APIC ID are filled with the cluster ID, and hence on systems where the physical ID is still smaller than 255 the cluster ID is not. Force x2APIC to use physical mode if there's no interrupt remapping support.

Note that this requires a further patch in order to enable x2APIC without interrupt remapping support.

Quoted 7 lines
Quoted 2 lines

This is missing a command line doc update and the logic below ignores a user-set x2apic_phys value.

So what would the behavior be in your opinion when the user has requested cluster mode? I can't see you do much other than panic()-ing, perhaps it's better to override the request (as you already do)?

Quoted 6 lines

I think panic'ing is fine, a user shouldn't be setting x2apic_phys unless they know what are doing, and then Xen changing it on the back of the user also doesn't seem fine.

A panic explaining that x2apic_phys=false is not supported and that the box can only be booted with x2apic phys mode should be fine IMO.

I can see this as a valid position to take. Personally, however, I do think we should avoid failing to boot if we easily can. (Yes, we should log the fact that we ignore a command line option in such a case.)

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw

Re: [Xen-devel] [PATCH v2 2/4] x86/apic: force phys mode if interrupt remapping is disabled

Quoted 27 lines · Jan Beulich
Quoted 26 lines · Roger Pau Monné
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Roger Pau Monne

Cluster mode can only be used with interrupt remapping support, since the top 16bits of the APIC ID are filled with the cluster ID, and hence on systems where the physical ID is still smaller than 255 the cluster ID is not. Force x2APIC to use physical mode if there's no interrupt remapping support.

Note that this requires a further patch in order to enable x2APIC without interrupt remapping support.

Quoted 7 lines
Quoted 2 lines

This is missing a command line doc update and the logic below ignores a user-set x2apic_phys value.

So what would the behavior be in your opinion when the user has requested cluster mode? I can't see you do much other than panic()-ing, perhaps it's better to override the request (as you already do)?

I think panic'ing is fine, a user shouldn't be setting x2apic_phys unless they know what are doing, and then Xen changing it on the back of the user also doesn't seem fine.

Quoted 7 lines
Quoted 2 lines

A panic explaining that x2apic_phys=false is not supported and that the box can only be booted with x2apic phys mode should be fine IMO.

I can see this as a valid position to take. Personally, however, I do think we should avoid failing to boot if we easily can. (Yes, we should log the fact that we ignore a command line option in such a case.)

Ack, I don't have a strong opinion, so I would go this route.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

PATCH v2 3/4 x86/smp: check APIC ID on AP bringup

In reply to Roger Pau Monne

Check that the processor to be woken up APIC ID is addressable in the current APIC mode.

Note that in practice systems with APIC IDs > 255 should already have x2APIC enabled by the firmware, and hence this is mostly a safety belt.

---
 xen/arch/x86/smpboot.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/smpboot.c +7 -0
index fa691b6ba0..484d344c44 100644
@@ -1317,6 +1317,13 @@ int __cpu_up(unsigned int cpu)
     if ( (apicid = x86_cpu_to_apicid[cpu]) == BAD_APICID )
         return -ENODEV;
 
+    if ( (!x2apic_enabled || !iommu_intremap) && (apicid >> 8) )
+    {
+        printk("Processor with APIC ID %u cannot be onlined in xAPIC mode "
+               "or without interrupt remapping\n", apicid);
+        return -EINVAL;
+    }
+
     if ( (ret = do_boot_cpu(apicid, cpu)) != 0 )
         return ret;
 
Signature · 7 lines
2.24.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

Re: [Xen-devel] [PATCH v2 3/4] x86/smp: check APIC ID on AP bringup

xen/arch/x86/smpboot.c int __cpu_up(unsigned int cpu) · line 1323

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/smpboot.c +4 -0
@@ -1317,6 +1317,13 @@ int __cpu_up(unsigned int cpu)
     if ( (apicid = x86_cpu_to_apicid[cpu]) == BAD_APICID )
         return -ENODEV;
 
+    if ( (!x2apic_enabled || !iommu_intremap) && (apicid >> 8) )
+    {
+        printk("Processor with APIC ID %u cannot be onlined in xAPIC mode "
+               "or without interrupt remapping\n", apicid);

Please log the APIC ID in hex, to match how it gets logged e.g. by the ACPI table parsing code. I'd also prefer if the message could be shortened a little: I don't think the "or" is needed, "Processor" could become "CPU", and slight re-wording could save even a little more: "Cannot online CPU with APIC ID %#x in xAPIC mode w/o interrupt remapping".

Then again this isn't fully correct: We could bring such a CPU online in x2APIC mode but without interrupt remapping. There would be a restriction on which CPUs physical interrupts could be delivered to. So perhaps "Unsupported: APIC ID %#x in xAPIC mode w/o interrupt remapping" or some such?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#12 lore raw

PATCH v2 4/4 x86/apic: allow enabling x2APIC mode regardless of interrupt remapping

In reply to Roger Pau Monne

x2APIC mode doesn't mandate interrupt remapping, and hence can be enabled independently. This patch enables x2APIC when available, regardless of whether there's interrupt remapping support.

This is beneficial specially when running on virtualized environments, since it reduces the amount of vmexits. For example when sending an IPI in xAPIC mode Xen performs at least 3 different accesses to the APIC MMIO region, while when using x2APIC mode a single wrmsr is used.

The following numbers are from a lock profiling of a Xen PV shim running a Linux PV kernel with 32 vCPUs and xAPIC mode:

(XEN) Global lock flush_lock: addr=ffff82d0804af1c0, lockval=03190319, not locked
(XEN) lock:656153(892606463454), block:602183(9495067321843)

Average lock time: 1360363ns
Average block time: 15767743ns

While the following are from the same configuration but with the shim using x2APIC mode:

(XEN) Global lock flush_lock: addr=ffff82d0804b01c0, lockval=1adb1adb, not locked
(XEN) lock:1841883(1375128998543), block:1658716(10193054890781)

Average lock time: 746588ns
Average block time: 6145147ns

Enabling x2APIC has halved the average lock time, thus reducing contention.

---
Changes since v1:
- Fix error paths of iommu_enable_x2apic call in x2apic_bsp_setup.
---
NB: should enabling x2APIC without interrupt remapping be limited to running on virtualized environments?

The bigger performance benefit is indeed achieved when using x2APIC on virt environments, but I also don't see why we wouldn't want to try using it everywhere where it's supported.

---
 xen/arch/x86/apic.c | 89 +++++++++++++++++++++------------------------
 1 file changed, 42 insertions(+), 47 deletions(-)
xen/arch/x86/apic.c +42 -47
index a8ee18636f..eaf8924585 100644
@@ -492,7 +492,8 @@ static void __enable_x2apic(void)
 
 static void resume_x2apic(void)
 {
-    iommu_enable_x2apic();
+    if ( iommu_supports_x2apic() )
+        iommu_enable_x2apic();
     __enable_x2apic();
 }
 
@@ -695,7 +696,8 @@ int lapic_suspend(void)
 
     local_irq_save(flags);
     disable_local_APIC();
-    iommu_disable_x2apic();
+    if ( iommu_supports_x2apic() )
+        iommu_disable_x2apic();
     local_irq_restore(flags);
     return 0;
 }
@@ -875,56 +877,46 @@ void __init x2apic_bsp_setup(void)
         printk("x2APIC: Already enabled by BIOS: Ignoring cmdline disable.\n");
     }
 
-    if ( !iommu_supports_x2apic() )
+    if ( iommu_supports_x2apic() )
     {
-        if ( !x2apic_enabled )
+        if ( (ioapic_entries = alloc_ioapic_entries()) == NULL )
         {
-            printk("Not enabling x2APIC: depends on IOMMU support\n");
-            return;
+            printk("Allocate ioapic_entries failed\n");
+            goto out;
         }
-        panic("x2APIC: already enabled by BIOS, but no IOMMU support\n");
-    }
 
-    if ( (ioapic_entries = alloc_ioapic_entries()) == NULL )
-    {
-        printk("Allocate ioapic_entries failed\n");
-        goto out;
-    }
-
-    if ( save_IO_APIC_setup(ioapic_entries) )
-    {
-        printk("Saving IO-APIC state failed\n");
-        goto out;
-    }
+        if ( save_IO_APIC_setup(ioapic_entries) )
+        {
+            printk("Saving IO-APIC state failed\n");
+            goto out;
+        }
 
-    mask_8259A();
-    mask_IO_APIC_setup(ioapic_entries);
+        mask_8259A();
+        mask_IO_APIC_setup(ioapic_entries);
 
-    switch ( iommu_enable_x2apic() )
-    {
-    case 0:
-        intremap_enabled = true;
-        break;
-    case -ENXIO: /* ACPI_DMAR_X2APIC_OPT_OUT set */
-        if ( !x2apic_enabled )
+        switch ( iommu_enable_x2apic() )
         {
+        case 0:
+            intremap_enabled = true;
+            break;
+
+        case -ENXIO: /* ACPI_DMAR_X2APIC_OPT_OUT set */
+            if ( x2apic_enabled )
+                panic("IOMMU requests xAPIC mode, but x2APIC already enabled by firmware\n");
+
             printk("Not enabling x2APIC (upon firmware request)\n");
             intremap_enabled = false;
             goto restore_out;
+
+        default:
+            printk(XENLOG_ERR "Failed to enable Interrupt Remapping\n");
+            intremap_enabled = false;
+            break;
         }
-        /* fall through */
-    default:
-        if ( x2apic_enabled )
-            panic("Interrupt remapping could not be enabled while "
-                  "x2APIC is already enabled by BIOS\n");
-
-        printk(XENLOG_ERR
-               "Failed to enable Interrupt Remapping: Will not enable x2APIC.\n");
-        intremap_enabled = false;
-        goto restore_out;
-    }
 
-    force_iommu = 1;
+        if ( intremap_enabled )
+            force_iommu = 1;
+    }
 
     if ( !x2apic_enabled )
     {
@@ -938,13 +930,16 @@ void __init x2apic_bsp_setup(void)
         printk("Switched to APIC driver %s\n", genapic.name);
 
 restore_out:
-    /*
-     * NB: do not use raw mode when restoring entries if the iommu has been
-     * enabled during the process, because the entries need to be translated
-     * and added to the remapping table in that case.
-     */
-    restore_IO_APIC_setup(ioapic_entries, !intremap_enabled);
-    unmask_8259A();
+    if ( iommu_supports_x2apic() )
+    {
+        /*
+         * NB: do not use raw mode when restoring entries if the iommu has been
+         * enabled during the process, because the entries need to be translated
+         * and added to the remapping table in that case.
+         */
+        restore_IO_APIC_setup(ioapic_entries, !intremap_enabled);
+        unmask_8259A();
+    }
 
 out:
     if ( ioapic_entries )
Signature · 7 lines
2.24.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

Re: [Xen-devel] [PATCH v2 4/4] x86/apic: allow enabling x2APIC mode regardless of interrupt remapping

xen/arch/x86/apic.c static void __enable_x2apic(void) · line 496

Quoted 9 lines · Roger Pau Monne
xen/arch/x86/apic.c +2 -1
@@ -492,7 +492,8 @@ static void __enable_x2apic(void)
 
 static void resume_x2apic(void)
 {
-    iommu_enable_x2apic();
+    if ( iommu_supports_x2apic() )
+        iommu_enable_x2apic();

The hooks called by this function are __init, and at least the AMD one also isn't (I think) prepared to be called more than once.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [Xen-devel] [PATCH v2 4/4] x86/apic: allow enabling x2APIC mode regardless of interrupt remapping

Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monne
xen/arch/x86/apic.c +0 -0
@@ -492,7 +492,8 @@ static void __enable_x2apic(void)
 
Quoted 8 lines

xen/arch/x86/apic.c static void __enable_x2apic(void) · line 496

Quoted 5 lines
xen/arch/x86/apic.c +2 -1
 static void resume_x2apic(void)
 {
-    iommu_enable_x2apic();
+    if ( iommu_supports_x2apic() )
+        iommu_enable_x2apic();

The hooks called by this function are __init, and at least the AMD one also isn't (I think) prepared to be called more than once.

It's already called twice, there's one call to iommu_supports_x2apic in x2apic_bsp_setup and another one in iommu_enable_x2apic, so I think calling iommu_supports_x2apic multiple times is fine (or we would already have issues).

I will cache the value of iommu_enable_x2apic to be used in the suspend/resume paths of the local apic, so there's no need to call iommu_supports_x2apic after init.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw

Re: [Xen-devel] [PATCH v2 4/4] x86/apic: allow enabling x2APIC mode regardless of interrupt remapping

Quoted 15 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monne
xen/arch/x86/apic.c +0 -0
@@ -492,7 +492,8 @@ static void __enable_x2apic(void)
 
Quoted 8 lines

xen/arch/x86/apic.c static void __enable_x2apic(void) · line 496

Quoted 5 lines
xen/arch/x86/apic.c +2 -1
 static void resume_x2apic(void)
 {
-    iommu_enable_x2apic();
+    if ( iommu_supports_x2apic() )
+        iommu_enable_x2apic();

The hooks called by this function are __init, and at least the AMD one also isn't (I think) prepared to be called more than once.

Quoted 4 lines

It's already called twice, there's one call to iommu_supports_x2apic in x2apic_bsp_setup and another one in iommu_enable_x2apic, so I think calling iommu_supports_x2apic multiple times is fine (or we would already have issues).

Ah, right - amd_iommu_prepare() bails (relatively) early when noticing it had been called before.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel