x86/IO-APIC: remove dead / unreachable code
cover x86/IO-APIC: remove dead / unreachable code
It's not quite clear whether the two functions involved violate only rule 2.1 (dead code, not accepted so far) or even rule 2.2 (unreachable code). I'm leaning towards the latter, hence the changes would be an active fix.
This is effectively follow-on to "x86/apic: Drop vestigial pieces (Intel VFM cleanup)".
1: drop setup_ioapic_ids_from_mpc()
2: drop io_apic_get_unique_id()
Jan
PATCH 1/2 x86/IO-APIC: drop setup_ioapic_ids_from_mpc()
Along the lines of what b89f8f054f96 ("x86/apic: Drop sync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).
Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."
Otoh it's "only" __init code.
xen/arch/x86/io_apic.c +0 -119
@@ -1459,119 +1459,6 @@ void disable_IO_APIC(void) }/* -* function to set the IO-APIC physical IDs based on the -* values stored in the MPC table. -* -* by Matt Domsch <[email protected]> Tue Dec 21 12:25:05 CST 1999 -*/ - -static void __init setup_ioapic_ids_from_mpc (void ) -{ -union IO_APIC_reg_00 reg_00; -static physid_mask_t __initdata phys_id_present_map; -int apic; -int i; -unsigned char old_id; -unsigned long flags; -const uint32_t broadcast_id =0xf ; - -/* -* Don't check I/O APIC IDs for xAPIC systems. They have -* no meaning without the serial APIC bus. -*/ -if (!(boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) - ||APIC_XAPIC (apic_version[boot_cpu_physical_apicid])) -return ; - -/* -* This is broken; anything with a real cpu count has to -* circumvent this idiocy regardless. -*/ - phys_id_present_map = phys_cpu_present_map; - -/* -* Set the IOAPIC ID to the value stored in the MPC table. -*/ -for (apic =0 ; apic < nr_ioapics; apic++) { -if (!nr_ioapic_entries[apic]) -continue ; - -/* Read the register 0 value */ -spin_lock_irqsave (&ioapic_lock, flags); - reg_00.raw =io_apic_read (apic,0 ); -spin_unlock_irqrestore (&ioapic_lock, flags); - - old_id = mp_ioapics[apic].mpc_apicid; - -if (mp_ioapics[apic].mpc_apicid >= broadcast_id) { -printk (KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n" , - apic, mp_ioapics[apic].mpc_apicid); -printk (KERN_ERR "... fixing up to %d. (tell your hw vendor)\n" , - reg_00.bits.ID); - mp_ioapics[apic].mpc_apicid = reg_00.bits.ID; - } - -/* -* Sanity check, is the ID really free? Every APIC in a -* system must have a unique ID or we get lots of nice -* 'stuck on smp_invalidate_needed IPI wait' messages. -*/ -if (physid_isset (mp_ioapics[apic].mpc_apicid, phys_id_present_map) ) - { -printk (KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n" , - apic, mp_ioapics[apic].mpc_apicid); -for (i =0 ; i < broadcast_id; i++) -if (!physid_isset (i, phys_id_present_map)) -break ; -if (i >= broadcast_id) -panic ("Max APIC ID exceeded\n" ); -printk (KERN_ERR "... fixing up to %d. (tell your hw vendor)\n" , - i); - mp_ioapics[apic].mpc_apicid = i; - }else { -apic_printk (APIC_VERBOSE ,"Setting %d in the " -"phys_id_present_map\n" , - mp_ioapics[apic].mpc_apicid); - } -physid_set (mp_ioapics[apic].mpc_apicid, phys_id_present_map); - -/* -* We need to adjust the IRQ routing table -* if the ID changed. -*/ -if (old_id != mp_ioapics[apic].mpc_apicid) -for (i =0 ; i < mp_irq_entries; i++) -if (mp_irqs[i].mpc_dstapic == old_id) - mp_irqs[i].mpc_dstapic - = mp_ioapics[apic].mpc_apicid; - -/* -* Read the right value from the MPC table and -* write it into the ID register. -*/ -apic_printk (APIC_VERBOSE ,KERN_INFO -"...changing IO-APIC physical APIC ID to %d ..." , - mp_ioapics[apic].mpc_apicid); - - reg_00.bits.ID = mp_ioapics[apic].mpc_apicid; -spin_lock_irqsave (&ioapic_lock, flags); -io_apic_write (apic,0 , reg_00.raw); -spin_unlock_irqrestore (&ioapic_lock, flags); - -/* -* Sanity check -*/ -spin_lock_irqsave (&ioapic_lock, flags); - reg_00.raw =io_apic_read (apic,0 ); -spin_unlock_irqrestore (&ioapic_lock, flags); -if (reg_00.bits.ID != mp_ioapics[apic].mpc_apicid) -printk ("could not set ID!\n" ); -else -apic_printk (APIC_VERBOSE ," ok.\n" ); - } -} - -/* * There is a nasty bug in some older SMP boards, their mptable lies * about the timer IRQ. We do the following to work around the situation: *
@@ -2158,12 +2045,6 @@ void __init setup_IO_APIC(void) ioapic_level_type.end = end_level_ioapic_irq_new; } -/* -* Set up IO-APIC IRQ routing. -*/ -if (!acpi_ioapic) -setup_ioapic_ids_from_mpc (); -setup_IO_APIC_irqs ();init_IO_APIC_traps ();check_timer ();
Re: [PATCH 1/2] x86/IO-APIC: drop setup_ioapic_ids_from_mpc()
Quoted 9 lines · Jan Beulich
Along the lines of what
b89f8f054f96("x86/apic: Dropsync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
Quoted 6 lines
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."Otoh it's "only"
__initcode.Signed-off-by Jan Beulich <[email protected]>
Re: [PATCH 1/2] x86/IO-APIC: drop setup_ioapic_ids_from_mpc()
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
Along the lines of what
b89f8f054f96("x86/apic: Dropsync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
Quoted 6 lines
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."Otoh it's "only"
__initcode.Signed-off-by Jan Beulich <[email protected]>
The code change is fine, but the commit message should be first paragraph only.
The first paragraph is plenty of justification to make the change, irrespective of anything else.
The other 3 paragraphs are musings on an area of MISRA where which is unclear, or even disputed. The code here is statically reachable, dynamically unreachable, and trying to argue this in terms of dead or unreachability detracts from an otherwise clear patch.
With a very strong preference to have the commit message be only the first paragraph, Reviewed-by: Andrew Cooper <[email protected]>
Re: [PATCH 1/2] x86/IO-APIC: drop setup_ioapic_ids_from_mpc()
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Along the lines of what
b89f8f054f96("x86/apic: Dropsync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."Otoh it's "only"
__initcode.
Quoted 7 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>The code change is fine, but the commit message should be first paragraph only.
The first paragraph is plenty of justification to make the change, irrespective of anything else.
Well. I wouldn't have added the other parts if we weren't where we are in the release cycle. Strictly speaking, with them dropped I can't put these two patches in right now. Oleksii, may I ask for your view please (on both of the patches, as they're both similar in this regard)?
Quoted 7 lines
The other 3 paragraphs are musings on an area of MISRA where which is unclear, or even disputed. The code here is statically reachable, dynamically unreachable, and trying to argue this in terms of dead or unreachability detracts from an otherwise clear patch.
With a very strong preference to have the commit message be only the first paragraph, Reviewed-by: Andrew Cooper <[email protected]>
Thanks (also for the one for patch 2).
Jan
Re: [PATCH 1/2] x86/IO-APIC: drop setup_ioapic_ids_from_mpc()
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Along the lines of what
b89f8f054f96("x86/apic: Dropsync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
Quoted 6 lines
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."Otoh it's "only"
__initcode.Signed-off-by Jan Beulich<[email protected]>The code change is fine, but the commit message should be first paragraph only.
Quoted 6 lines
Quoted 2 lines
The first paragraph is plenty of justification to make the change, irrespective of anything else.
Well. I wouldn't have added the other parts if we weren't where we are in the release cycle. Strictly speaking, with them dropped I can't put these two patches in right now. Oleksii, may I ask for your view please (on both of the patches, as they're both similar in this regard)?
For both patches, I think it would still be useful to retain the explanation about the MISRA Rule 2.2 violation in the commit message. While I agree that the first paragraph provides sufficient justification on its own, the additional context helps clarify why we're committing this change now, rather than waiting until after the release. It also highlights the additional benefit of improving MISRA compliance by removing this dead code.
Anyway, I am okay with having these patches merged now:
~ Oleksii
Quoted 11 lines
Quoted 8 lines
The other 3 paragraphs are musings on an area of MISRA where which is unclear, or even disputed. The code here is statically reachable, dynamically unreachable, and trying to argue this in terms of dead or unreachability detracts from an otherwise clear patch.
With a very strong preference to have the commit message be only the first paragraph, Reviewed-by: Andrew Cooper<[email protected]>
Thanks (also for the one for patch 2).
Jan
PATCH 2/2 x86/IO-APIC: drop io_apic_get_unique_id()
In reply to Jan BeulichAlong the lines of what b89f8f054f96 ("x86/apic: Drop sync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).
Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."
Otoh it's "only" __init code.
As this removes the last user of APIC_XAPIC(), remove the macro as well.
xen/arch/x86/include/asm/apicdef.h +0 -1
@@ -19,7 +19,6 @@#define APIC_LVR_DIRECTED_EOI (1 << 24)#define GET_APIC_VERSION (x) ((x)&0xFF)#define GET_APIC_MAXLVT (x) (((x)>>16)&0xFF) -#define APIC_XAPIC (x) ((x) >= 0x14)#define APIC_TASKPRI 0x80#define APIC_TPRI_MASK 0xFF#define APIC_ARBPRI 0x90
xen/arch/x86/include/asm/io_apic.h +0 -1
@@ -184,7 +184,6 @@ extern bool skip_ioapic_setup;extern bool ioapic_ack_new;extern bool ioapic_ack_forced; -extern int io_apic_get_unique_id (int ioapic,int apic_id);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);
xen/arch/x86/io_apic.c +0 -80
86 lines not on this page · raw message
xen/arch/x86/mpparse.c +1 -11
@@ -871,7 +871,6 @@ void __init mp_register_ioapic ( u32 gsi_base) {int idx =0 ; -int tmpid;if (nr_ioapics >=MAX_IO_APICS ) { printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
@@ -891,16 +890,7 @@ void __init mp_register_ioapic ( mp_ioapics[idx].mpc_apicaddr = address;set_fixmap_nocache (FIX_IO_APIC_BASE_0 + idx, address); -if ((boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) - && !APIC_XAPIC (apic_version[boot_cpu_physical_apicid])) - tmpid =io_apic_get_unique_id (idx, id); -else - tmpid = id; -if (tmpid ==-1 ) { - nr_ioapics--; -return ; - } - mp_ioapics[idx].mpc_apicid = tmpid; + mp_ioapics[idx].mpc_apicid = id; mp_ioapics[idx].mpc_apicver =io_apic_get_version (idx);/*
Re: [PATCH 2/2] x86/IO-APIC: drop io_apic_get_unique_id()
Quoted 9 lines · Jan Beulich
Along the lines of what
b89f8f054f96("x86/apic: Dropsync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
Quoted 8 lines
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."Otoh it's "only"
__initcode.As this removes the last user of
APIC_XAPIC(), remove the macro as well.Signed-off-by Jan Beulich <[email protected]>
Re: [PATCH 2/2] x86/IO-APIC: drop io_apic_get_unique_id()
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
Along the lines of what
b89f8f054f96("x86/apic: Dropsync_Arb_IDs()") said, the function is dead logic as well: All 64-bit capable Intel systems have (at least) xAPIC (if not x2APIC).Even if Eclair can't know it, such code is violating Misra rule 2.2 (dead code; we didn't accept that yet, but - where possible - we probably would better follow it). Depending on one's reading, this code may actually be a violation of rule 2.1 (unreachable), which we did accept:
Quoted 8 lines
"Code is unreachable if, ..., there is no combination of program inputs
that can cause it to be executed."Otoh it's "only"
__initcode.As this removes the last user of
APIC_XAPIC(), remove the macro as well.Signed-off-by Jan Beulich <[email protected]>
Same feedback as with the previous patch, albeit about the middle 3 paragraphs. Again with a strong preference for those to be removed,
I'd not even spotted that APIC_XAPIC() existed. This being explicit conformation of where XAPIC starts would have been helpful when doing archaeology.
Quoted 9 lines · Jan Beulich
It's not quite clear whether the two functions involved violate only rule 2.1 (dead code, not accepted so far) or even rule 2.2 (unreachable code). I'm leaning towards the latter, hence the changes would be an active fix.
This is effectively follow-on to "x86/apic: Drop vestigial pieces (Intel VFM cleanup)".
1: drop
setup_ioapic_ids_from_mpc()
2: dropio_apic_get_unique_id()
Just to mention: This drops about 7% (in terms of LoC) from io_apic.c
Jan