Skip to contentSkip to conversation

xen/x86: Simplify init_ioapic()

PATCH In review Julien Grall 2 participants 6 messages Apr 4, 2020 – Apr 10, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover xen/x86: Simplify init_ioapic()

From: Julien Grall <[email protected]>

Hi all,

The main goal of this small series is to simplify init_ioapic().

Cheers,

Julien Grall (3):
xen/x86: ioapic: Use true/false in bad_ioapic_register() xen/x86: ioapic: Rename init_ioapic_mappings() to ioapic_init() xen/x86: ioapic: Simplify ioapic_init()

 xen/arch/x86/apic.c           |  2 +-
 xen/arch/x86/io_apic.c        | 65 ++++++++++++++++-------------------
 xen/include/asm-x86/io_apic.h |  2 +-
 3 files changed, 32 insertions(+), 37 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 xen/x86: ioapic: Use true/false in bad_ioapic_register()

From: Julien Grall <[email protected]>

bad_ioapic_register() is returning a bool, so we should switch to true/false.

---
Changes in v2:
- Add Wei's reviewed-by
- Fix typo
- Add Jan's acked-by

---
 xen/arch/x86/io_apic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/io_apic.c +2 -2
index e98e08e9c8..9868933287 100644
@@ -2531,10 +2531,10 @@ static __init bool bad_ioapic_register(unsigned int idx)
     {
         printk(KERN_WARNING "I/O APIC %#x registers return all ones, skipping!\n",
                mp_ioapics[idx].mpc_apicaddr);
-        return 1;
+        return true;
     }
 
-    return 0;
+    return false;
 }
 
 void __init init_ioapic_mappings(void)
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/3 xen/x86: ioapic: Rename init_ioapic_mappings() to ioapic_init()

In reply to Julien Grall

From: Julien Grall <[email protected]>

The function init_ioapic_mappings() is doing more than initialization mappings. It is also initialization the number of IRQs/GSIs supported.

So rename the function to ioapic_init().

---
Changes in v2:
- Rename to ioapic_init() rather than init_ioapic().
- Add Roger's reviewed-by
- Add Jan's acked-by

---
 xen/arch/x86/apic.c           | 2 +-
 xen/arch/x86/io_apic.c        | 2 +-
 xen/include/asm-x86/io_apic.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/apic.c +1 -1
index cde67cd87e..71f4efb2fe 100644
@@ -978,7 +978,7 @@ __next:
         boot_cpu_physical_apicid = get_apic_id();
     x86_cpu_to_apicid[0] = get_apic_id();
 
-    init_ioapic_mappings();
+    ioapic_init();
 }
 
 /*****************************************************************************
xen/arch/x86/io_apic.c +1 -1
index 9868933287..8233eb44e1 100644
@@ -2537,7 +2537,7 @@ static __init bool bad_ioapic_register(unsigned int idx)
     return false;
 }
 
-void __init init_ioapic_mappings(void)
+void __init ioapic_init(void)
 {
     unsigned long ioapic_phys;
     unsigned int i, idx = FIX_IO_APIC_BASE_0;
xen/include/asm-x86/io_apic.h +1 -1
index 998905186b..e006b2b8dd 100644
@@ -180,7 +180,7 @@ extern int io_apic_get_version (int ioapic);
 extern int io_apic_get_redir_entries (int ioapic);
 extern int io_apic_set_pci_routing (int ioapic, int pin, int irq, int edge_level, int active_high_low);
 
-extern void init_ioapic_mappings(void);
+extern void ioapic_init(void);
 
 extern void ioapic_suspend(void);
 extern void ioapic_resume(void);
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/3 xen/x86: ioapic: Simplify ioapic_init()

In reply to Julien Grall

From: Julien Grall <[email protected]>

Since commit 9facd54a45 "x86/ioapic: Add register level checks to detect bogus io-apic entries", Xen is able to cope with IO APICs not mapped in the fixmap.

Therefore the whole logic to allocate a fake page for some IO APICs is unnecessary.

With the logic removed, the code can be simplified a lot as we don't need to go through all the IO APIC if SMP has not been detected or a bogus zero IO-APIC address has been detected.

To avoid another level of tabulation, the simplification is now moved in its own function.

---
Changes in v2:
- Don't set ioapic_phys twice in a row
- Rename init_ioapic_mappings() to ioapic_init_mappings()
- Use paddr_t rather than unsigned long
- Move nr_irq_gsis = 0 in ioapic_init_mappings()

---
 xen/arch/x86/io_apic.c | 61 +++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 33 deletions(-)
xen/arch/x86/io_apic.c +28 -33
index 8233eb44e1..878ee5192d 100644
@@ -2537,34 +2537,26 @@ static __init bool bad_ioapic_register(unsigned int idx)
     return false;
 }
 
-void __init ioapic_init(void)
+static void __init ioapic_init_mappings(void)
 {
-    unsigned long ioapic_phys;
     unsigned int i, idx = FIX_IO_APIC_BASE_0;
-    union IO_APIC_reg_01 reg_01;
 
-    if ( smp_found_config )
-        nr_irqs_gsi = 0;
+    nr_irqs_gsi = 0;
+
     for ( i = 0; i < nr_ioapics; i++ )
     {
-        if ( smp_found_config )
-        {
-            ioapic_phys = mp_ioapics[i].mpc_apicaddr;
-            if ( !ioapic_phys )
-            {
-                printk(KERN_ERR "WARNING: bogus zero IO-APIC address "
-                       "found in MPTABLE, disabling IO/APIC support!\n");
-                smp_found_config = false;
-                skip_ioapic_setup = true;
-                goto fake_ioapic_page;
-            }
-        }
-        else
+        union IO_APIC_reg_01 reg_01;
+        paddr_t ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+
+        if ( !ioapic_phys )
         {
- fake_ioapic_page:
-            ioapic_phys = __pa(alloc_xenheap_page());
-            clear_page(__va(ioapic_phys));
+            printk(KERN_ERR
+                   "WARNING: bogus zero IO-APIC address found in MPTABLE, disabling IO/APIC support!\n");
+            smp_found_config = false;
+            skip_ioapic_setup = true;
+            break;
         }
+
         set_fixmap_nocache(idx, ioapic_phys);
         apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
                     __fix_to_virt(idx), ioapic_phys);
@@ -2576,19 +2568,22 @@ void __init ioapic_init(void)
             continue;
         }
 
-        if ( smp_found_config )
-        {
-            /* The number of IO-APIC IRQ registers (== #pins): */
-            reg_01.raw = io_apic_read(i, 1);
-            nr_ioapic_entries[i] = reg_01.bits.entries + 1;
-            nr_irqs_gsi += nr_ioapic_entries[i];
-
-            if ( rangeset_add_singleton(mmio_ro_ranges,
-                                        ioapic_phys >> PAGE_SHIFT) )
-                printk(KERN_ERR "Failed to mark IO-APIC page %lx read-only\n",
-                       ioapic_phys);
-        }
+        /* The number of IO-APIC IRQ registers (== #pins): */
+        reg_01.raw = io_apic_read(i, 1);
+        nr_ioapic_entries[i] = reg_01.bits.entries + 1;
+        nr_irqs_gsi += nr_ioapic_entries[i];
+
+        if ( rangeset_add_singleton(mmio_ro_ranges,
+                                    ioapic_phys >> PAGE_SHIFT) )
+            printk(KERN_ERR "Failed to mark IO-APIC page %lx read-only\n",
+                   ioapic_phys);
     }
+}
+
+void __init ioapic_init(void)
+{
+    if ( smp_found_config )
+        ioapic_init_mappings();
 
     nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi() + 1);
 
Signature · 1 line
2.17.1
Reviewed-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] xen/x86: ioapic: Simplify ioapic_init()

Quoted 9 lines · Julien Grall

From: Julien Grall <[email protected]>

Since commit 9facd54a45 "x86/ioapic: Add register level checks to detect bogus io-apic entries", Xen is able to cope with IO APICs not mapped in the fixmap.

Therefore the whole logic to allocate a fake page for some IO APICs is unnecessary.

Quoted 8 lines

With the logic removed, the code can be simplified a lot as we don't need to go through all the IO APIC if SMP has not been detected or a bogus zero IO-APIC address has been detected.

To avoid another level of tabulation, the simplification is now moved in its own function.

#5 lore raw

Re: [PATCH v2 3/3] xen/x86: ioapic: Simplify ioapic_init()

Hi Jan,

Quoted 14 lines · Jan Beulich
Quoted 13 lines · Julien Grall

From: Julien Grall <[email protected]>

Since commit 9facd54a45 "x86/ioapic: Add register level checks to detect bogus io-apic entries", Xen is able to cope with IO APICs not mapped in the fixmap.

Therefore the whole logic to allocate a fake page for some IO APICs is unnecessary.

With the logic removed, the code can be simplified a lot as we don't need to go through all the IO APIC if SMP has not been detected or a bogus zero IO-APIC address has been detected.

Quoted 6 lines
Quoted 4 lines

To avoid another level of tabulation, the simplification is now moved in its own function.

Thank you! I took the liberty to push them.

Cheers,

Signature · 1 line
Julien Grall