Skip to contentSkip to conversation

xen/x86: Simplify ioapic_init()

PATCH Superseded Julien Grall 4 participants 16 messages Mar 27, 2020 – Mar 31, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover xen/x86: Simplify ioapic_init()

From: Julien Grall <[email protected]>

Hi all,

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

Cheers,

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

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

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

From: Julien Grall <[email protected]>

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

---
 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
#4 lore raw

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

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 init_ioapic(). This will allow us to re-use the name in a follow-up patch.

---
 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..c7a54cafc3 100644
@@ -978,7 +978,7 @@ __next:
         boot_cpu_physical_apicid = get_apic_id();
     x86_cpu_to_apicid[0] = get_apic_id();
 
-    init_ioapic_mappings();
+    init_ioapic();
 }
 
 /*****************************************************************************
xen/arch/x86/io_apic.c +1 -1
index 9868933287..9a11ee8342 100644
@@ -2537,7 +2537,7 @@ static __init bool bad_ioapic_register(unsigned int idx)
     return false;
 }
 
-void __init init_ioapic_mappings(void)
+void __init init_ioapic(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..8c0af4bdd3 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 init_ioapic(void);
 
 extern void ioapic_suspend(void);
 extern void ioapic_resume(void);
Signature · 1 line
2.17.1
Reviewed-by on v1 2/3
#5 lore raw

Re: [Xen-devel] [PATCH 2/3] xen/x86: ioapic: Rename init_ioapic_mappings() to init_ioapic()

Quoted 9 lines · 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 init_ioapic(). This will allow us to re-use the name in a follow-up patch.

I've got one comment/request however.

Quoted 11 lines
---
 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 +0 -0
index cde67cd87e..c7a54cafc3 100644

xen/arch/x86/apic.c __next: · line 981

Quoted 5 lines
xen/arch/x86/apic.c +1 -1
@@ -978,7 +978,7 @@ __next:
         boot_cpu_physical_apicid = get_apic_id();
     x86_cpu_to_apicid[0] = get_apic_id();
 
-    init_ioapic_mappings();
+    init_ioapic();

I would rename this to ioapic_init instead since you are already changing it. I usually prefer the subsystem name to be prefixed to the action the function performs instead of the other way around.

Thanks, Roger.

#6 lore raw

Re: [Xen-devel] [PATCH 2/3] xen/x86: ioapic: Rename init_ioapic_mappings() to init_ioapic()

Quoted 29 lines · Roger Pau Monné
Quoted 9 lines · 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 init_ioapic(). This will allow us to re-use the name in a follow-up patch.

I've got one comment/request however.

Quoted 14 lines
---
  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 +0 -0
index cde67cd87e..c7a54cafc3 100644
@@ -978,7 +978,7 @@ __next:
          boot_cpu_physical_apicid = get_apic_id();
      x86_cpu_to_apicid[0] = get_apic_id();
 
Quoted 6 lines

xen/arch/x86/apic.c __next: · line 981

Quoted 2 lines
xen/arch/x86/apic.c +1 -1
-    init_ioapic_mappings();
+    init_ioapic();

I would rename this to ioapic_init instead since you are already changing it. I usually prefer the subsystem name to be prefixed to the action the function performs instead of the other way around.

I will do it.

Cheers,

Signature · 1 line
Julien Grall
Acked-by
#7 lore raw

Re: [PATCH 2/3] xen/x86: ioapic: Rename init_ioapic_mappings() to init_ioapic()

In reply to Roger Pau Monné
Quoted 29 lines · Roger Pau Monné
Quoted 9 lines · 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 init_ioapic(). This will allow us to re-use the name in a follow-up patch.

I've got one comment/request however.

Quoted 14 lines
---
 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 +0 -0
index cde67cd87e..c7a54cafc3 100644
@@ -978,7 +978,7 @@ __next:
         boot_cpu_physical_apicid = get_apic_id();
     x86_cpu_to_apicid[0] = get_apic_id();
 
Quoted 6 lines

xen/arch/x86/apic.c __next: · line 981

Quoted 2 lines
xen/arch/x86/apic.c +1 -1
-    init_ioapic_mappings();
+    init_ioapic();

I would rename this to ioapic_init instead since you are already changing it. I usually prefer the subsystem name to be prefixed to the action the function performs instead of the other way around.

With this adjustment

Jan

#8 lore raw

PATCH 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.

---
 xen/arch/x86/io_apic.c | 63 ++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 33 deletions(-)
xen/arch/x86/io_apic.c +30 -33
index 9a11ee8342..3d52e4daf1 100644
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
     return false;
 }
 
-void __init init_ioapic(void)
+static void __init init_ioapic_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;
     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;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+
+        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,18 +2567,24 @@ void __init init_ioapic(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 init_ioapic(void)
+{
+    if ( smp_found_config )
+    {
+        nr_irqs_gsi = 0;
+        init_ioapic_mappings();
     }
 
     nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi() + 1);
Signature · 1 line
2.17.1
#9 lore raw

Re: [Xen-devel] [PATCH 3/3] xen/x86: ioapic: Simplify ioapic_init()

Quoted 47 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.

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

---
 xen/arch/x86/io_apic.c | 63 ++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 33 deletions(-)
xen/arch/x86/io_apic.c +1 -12
index 9a11ee8342..3d52e4daf1 100644
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
     return false;
 }
 
-void __init init_ioapic(void)
+static void __init init_ioapic_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;
     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");

xen/arch/x86/io_apic.c static __init bool bad_ioapic_register(unsigned int idx) · line 2549

Quoted 10 lines
xen/arch/x86/io_apic.c +4 -6
-                smp_found_config = false;
-                skip_ioapic_setup = true;
-                goto fake_ioapic_page;
-            }
-        }
-        else
+        union IO_APIC_reg_01 reg_01;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+
+        ioapic_phys = mp_ioapics[i].mpc_apicaddr;

ioapic_phys is set a second time here. See the line before.

Wei.

#10 lore raw

Re: [Xen-devel] [PATCH 3/3] xen/x86: ioapic: Simplify ioapic_init()

Hi Wei,

Quoted 52 lines · Wei Liu
Quoted 51 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.

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

---
  xen/arch/x86/io_apic.c | 63 ++++++++++++++++++++----------------------
  1 file changed, 30 insertions(+), 33 deletions(-)
xen/arch/x86/io_apic.c +1 -16
index 9a11ee8342..3d52e4daf1 100644
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
      return false;
  }
 
-void __init init_ioapic(void)
+static void __init init_ioapic_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;
      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;
-            }
Quoted 8 lines

xen/arch/x86/io_apic.c static __init bool bad_ioapic_register(unsigned int idx) · line 2549

Quoted 6 lines
xen/arch/x86/io_apic.c +4 -2
-        }
-        else
+        union IO_APIC_reg_01 reg_01;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+
+        ioapic_phys = mp_ioapics[i].mpc_apicaddr;

ioapic_phys is set a second time here. See the line before.

Good spot! I will drop the line.

Cheers,

Signature · 1 line
Julien Grall
#11 lore raw

Re: [Xen-devel] [PATCH 3/3] xen/x86: ioapic: Simplify ioapic_init()

In reply to Julien Grall
Quoted 26 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.

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

---
 xen/arch/x86/io_apic.c | 63 ++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 33 deletions(-)
xen/arch/x86/io_apic.c +0 -0
index 9a11ee8342..3d52e4daf1 100644

xen/arch/x86/io_apic.c static __init bool bad_ioapic_register(unsigned int idx) · line 2540

Quoted 5 lines
xen/arch/x86/io_apic.c +1 -1
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
     return false;
 }
 
-void __init init_ioapic(void)
+static void __init init_ioapic_mappings(void)

Likewise my comment in 2/3 I would name this ioapic_init_mappings.

Quoted 14 lines
xen/arch/x86/io_apic.c +0 -9
 {
-    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;
     for ( i = 0; i < nr_ioapics; i++ )
     {
-        if ( smp_found_config )
-        {
-            ioapic_phys = mp_ioapics[i].mpc_apicaddr;
-            if ( !ioapic_phys )
-            {

xen/arch/x86/io_apic.c static __init bool bad_ioapic_register(unsigned int idx) · line 2547

Quoted 10 lines
xen/arch/x86/io_apic.c +2 -8
-                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;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;

Nit: paddr_t might be better here.

Thanks, Roger.

#12 lore raw

Re: [Xen-devel] [PATCH 3/3] xen/x86: ioapic: Simplify ioapic_init()

Hi Roger,

Quoted 30 lines · Roger Pau Monné
Quoted 29 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.

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

---
  xen/arch/x86/io_apic.c | 63 ++++++++++++++++++++----------------------
  1 file changed, 30 insertions(+), 33 deletions(-)
xen/arch/x86/io_apic.c +0 -0
index 9a11ee8342..3d52e4daf1 100644
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
      return false;
  }
 
Quoted 4 lines

xen/arch/x86/io_apic.c static __init bool bad_ioapic_register(unsigned int idx) · line 2540

Quoted 2 lines
xen/arch/x86/io_apic.c +1 -1
-void __init init_ioapic(void)
+static void __init init_ioapic_mappings(void)

Likewise my comment in 2/3 I would name this ioapic_init_mappings.

Will do.

Quoted 26 lines
Quoted 15 lines
xen/arch/x86/io_apic.c +0 -9
  {
-    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;
      for ( i = 0; i < nr_ioapics; i++ )
      {
-        if ( smp_found_config )
-        {
-            ioapic_phys = mp_ioapics[i].mpc_apicaddr;
-            if ( !ioapic_phys )
-            {

xen/arch/x86/io_apic.c static __init bool bad_ioapic_register(unsigned int idx) · line 2547

Quoted 10 lines
xen/arch/x86/io_apic.c +2 -8
-                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;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;
Quoted 1 line

Nit: paddr_t might be better here.

Sure.

Cheers,

Signature · 1 line
Julien Grall
#13 lore raw

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

In reply to Julien Grall
Quoted 72 lines · Julien Grall
xen/arch/x86/io_apic.c +19 -33
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
     return false;
 }
 
-void __init init_ioapic(void)
+static void __init init_ioapic_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;
     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;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+
+        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,18 +2567,24 @@ void __init init_ioapic(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) )

xen/arch/x86/io_apic.c void __init init_ioapic(void) · line 2586

Quoted 10 lines
xen/arch/x86/io_apic.c +10 -0
+            printk(KERN_ERR "Failed to mark IO-APIC page %lx read-only\n",
+                   ioapic_phys);
+    }
+}
+
+void __init init_ioapic(void)
+{
+    if ( smp_found_config )
+    {
+        nr_irqs_gsi = 0;

This would seem to also belong into the function, e.g. as part of the loop header:

    for ( nr_irqs_gsi = i = 0; i < nr_ioapics; i++ )

Jan

#14 lore raw

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

Hi Jan,

Quoted 87 lines · Jan Beulich
Quoted 72 lines · Julien Grall
xen/arch/x86/io_apic.c +19 -33
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
      return false;
  }
 
-void __init init_ioapic(void)
+static void __init init_ioapic_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;
      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;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+
+        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,18 +2567,24 @@ void __init init_ioapic(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) )

xen/arch/x86/io_apic.c void __init init_ioapic(void) · line 2586

Quoted 10 lines
xen/arch/x86/io_apic.c +10 -0
+            printk(KERN_ERR "Failed to mark IO-APIC page %lx read-only\n",
+                   ioapic_phys);
+    }
+}
+
+void __init init_ioapic(void)
+{
+    if ( smp_found_config )
+    {
+        nr_irqs_gsi = 0;

This would seem to also belong into the function, e.g. as part of the loop header:

Quoted 1 line
     for ( nr_irqs_gsi = i = 0; i < nr_ioapics; i++ )

While the initial value of the 'i' and 'nr_irqs_gsi' is the same, the variables have very different meaning and may confuse the reader.

So I would rather not follow your suggestion here. Although, I can move the zeroing right before the for loop.

Cheers,

Signature · 1 line
Julien Grall
#15 lore raw

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

Quoted 87 lines · Julien Grall

Hi Jan,

Quoted 84 lines · Jan Beulich
Quoted 69 lines · Julien Grall
xen/arch/x86/io_apic.c +19 -30
@@ -2537,34 +2537,25 @@ static __init bool bad_ioapic_register(unsigned int idx)
       return false;
   }
   -void __init init_ioapic(void)
+static void __init init_ioapic_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;
       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;
+        unsigned long ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+
+        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,18 +2567,24 @@ void __init init_ioapic(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) )

xen/arch/x86/io_apic.c void __init init_ioapic(void) · line 2586

Quoted 10 lines
xen/arch/x86/io_apic.c +10 -0
+            printk(KERN_ERR "Failed to mark IO-APIC page %lx read-only\n",
+                   ioapic_phys);
+    }
+}
+
+void __init init_ioapic(void)
+{
+    if ( smp_found_config )
+    {
+        nr_irqs_gsi = 0;

This would seem to also belong into the function, e.g. as part of the loop header:

Quoted 4 lines
Quoted 1 line

     for ( nr_irqs_gsi = i = 0; i < nr_ioapics; i++ )

While the initial value of the 'i' and 'nr_irqs_gsi' is the same, the variables have very different meaning and may confuse the reader.

I expected reservations like this, hence the "e.g."; i.e. ...

Quoted 2 lines

So I would rather not follow your suggestion here. Although, I can move the zeroing right before the for loop.

... I'm fine with this as well.

Jan