Skip to contentSkip to conversation

Switch flat driver to use phys dst for ext ints

PATCH Superseded Matthew Barnes 4 participants 11 messages Oct 2, 2024 – Oct 4, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Switch flat driver to use phys dst for ext ints

This patch series switches the apic_default APIC driver from using logical flat destination mode for external interrupts, to using physical destination mode for external interrupts.

This is followed up by two non-functional cleanup commits.

Matthew Barnes (3):
x86/APIC: Switch flat driver to use phys dst for ext ints x86/APIC: Remove unnecessary logical flat functions x86/APIC: Refactor GENAPIC_FLAT -> GENAPIC_MIXED

 xen/arch/x86/genapic/default.c     |  2 +-
 xen/arch/x86/genapic/delivery.c    | 10 ----------
 xen/arch/x86/include/asm/genapic.h | 14 ++++++--------
 3 files changed, 7 insertions(+), 19 deletions(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/3 x86/APIC: Switch flat driver to use phys dst for ext ints

Resolves: https://gitlab.com/xen-project/xen/-/issues/194

---
 xen/arch/x86/include/asm/genapic.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
xen/arch/x86/include/asm/genapic.h +5 -5
index a694371c6d16..d29bccc39b4b 100644
@@ -45,21 +45,21 @@ void cf_check send_IPI_self_legacy(uint8_t vector);
 
 void cf_check init_apic_ldr_flat(void);
 unsigned int cf_check cpu_mask_to_apicid_flat(const cpumask_t *cpumask);
+const cpumask_t *cf_check vector_allocation_cpumask_phys(int cpu);
 void cf_check send_IPI_mask_flat(const cpumask_t *cpumask, int vector);
 const cpumask_t *cf_check vector_allocation_cpumask_flat(int cpu);
 #define GENAPIC_FLAT \
-	.int_delivery_mode = dest_LowestPrio, \
-	.int_dest_mode = 1 /* logical delivery */, \
+	.int_delivery_mode = dest_Fixed, \
+	.int_dest_mode = 0 /* physical delivery */, \
 	.init_apic_ldr = init_apic_ldr_flat, \
-	.vector_allocation_cpumask = vector_allocation_cpumask_flat, \
-	.cpu_mask_to_apicid = cpu_mask_to_apicid_flat, \
+	.vector_allocation_cpumask = vector_allocation_cpumask_phys, \
+	.cpu_mask_to_apicid = cpu_mask_to_apicid_phys, \
 	.send_IPI_mask = send_IPI_mask_flat, \
 	.send_IPI_self = send_IPI_self_legacy
 
 void cf_check init_apic_ldr_phys(void);
 unsigned int cf_check cpu_mask_to_apicid_phys(const cpumask_t *cpumask);
 void cf_check send_IPI_mask_phys(const cpumask_t *mask, int vector);
-const cpumask_t *cf_check vector_allocation_cpumask_phys(int cpu);
 #define GENAPIC_PHYS \
 	.int_delivery_mode = dest_Fixed, \
 	.int_dest_mode = 0 /* physical delivery */, \
Signature · 1 line
2.46.0
#2 lore raw

Re: [PATCH 1/3] x86/APIC: Switch flat driver to use phys dst for ext ints

On Wed, Oct 02, 2024 at 04:17:24PM +0100, Matthew Barnes wrote:

The commit needs a log, doesn't need to be extremely long, but it's important to note the reasoning behind using physical delivery for external interrupts vs logial mode.

Take a look at the x2APIC one for inspiration, the motivation should be similar.

Thanks, Roger.

#3 lore raw

Re: [PATCH 1/3] x86/APIC: Switch flat driver to use phys dst for ext ints

Quoted 5 lines · Roger Pau Monné

On Wed, Oct 02, 2024 at 04:17:24PM +0100, Matthew Barnes wrote:

The commit needs a log, doesn't need to be extremely long, but it's important to note the reasoning behind using physical delivery for external interrupts vs logial mode.

Furthermore I question that the naming can remain as is - the driver is no longer uniformly "flat" then.

Jan

#4 lore raw

Re: [PATCH 1/3] x86/APIC: Switch flat driver to use phys dst for ext ints

Quoted 9 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monné

On Wed, Oct 02, 2024 at 04:17:24PM +0100, Matthew Barnes wrote:

The commit needs a log, doesn't need to be extremely long, but it's important to note the reasoning behind using physical delivery for external interrupts vs logial mode.

Furthermore I question that the naming can remain as is - the driver is no longer uniformly "flat" then.

Yeah, that's done in a later patch. I wouldn't mind if it was all folded into the same patch TBH.

Thanks, Roger.

#5 lore raw

PATCH 2/3 x86/APIC: Remove unnecessary logical flat functions

In reply to Matthew Barnes

Now that GENAPIC_FLAT uses physical destination for external interrupts, these functions implementing logical flat for external interrupts are no longer used.

No functional change.

---
 xen/arch/x86/genapic/delivery.c    | 10 ----------
 xen/arch/x86/include/asm/genapic.h |  2 --
 2 files changed, 12 deletions(-)
xen/arch/x86/genapic/delivery.c +0 -10
index d1f99bf6834a..3def78f380d3 100644
@@ -19,16 +19,6 @@ void cf_check init_apic_ldr_flat(void)
 	apic_write(APIC_LDR, val);
 }
 
-const cpumask_t *cf_check vector_allocation_cpumask_flat(int cpu)
-{
-	return &cpu_online_map;
-} 
-
-unsigned int cf_check cpu_mask_to_apicid_flat(const cpumask_t *cpumask)
-{
-	return cpumask_bits(cpumask)[0]&0xFF;
-}
-
 /*
  * PHYSICAL DELIVERY MODE (unicast to physical APIC IDs).
  */
xen/arch/x86/include/asm/genapic.h +0 -2
index d29bccc39b4b..91fdeaca47b3 100644
@@ -44,10 +44,8 @@ extern const struct genapic apic_bigsmp;
 void cf_check send_IPI_self_legacy(uint8_t vector);
 
 void cf_check init_apic_ldr_flat(void);
-unsigned int cf_check cpu_mask_to_apicid_flat(const cpumask_t *cpumask);
 const cpumask_t *cf_check vector_allocation_cpumask_phys(int cpu);
 void cf_check send_IPI_mask_flat(const cpumask_t *cpumask, int vector);
-const cpumask_t *cf_check vector_allocation_cpumask_flat(int cpu);
 #define GENAPIC_FLAT \
 	.int_delivery_mode = dest_Fixed, \
 	.int_dest_mode = 0 /* physical delivery */, \
Signature · 1 line
2.46.0
#6 lore raw

Re: [PATCH 2/3] x86/APIC: Remove unnecessary logical flat functions

Quoted 3 lines · Matthew Barnes

Now that GENAPIC_FLAT uses physical destination for external interrupts, these functions implementing logical flat for external interrupts are no longer used.

I think it's fine to merge this with the previous commit, so that the functions are removed at the point there are no longer used.

Thanks, Roger.

#7 lore raw

Re: [PATCH 2/3] x86/APIC: Remove unnecessary logical flat functions

Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Matthew Barnes

Now that GENAPIC_FLAT uses physical destination for external interrupts, these functions implementing logical flat for external interrupts are no longer used.

I think it's fine to merge this with the previous commit, so that the functions are removed at the point there are no longer used.

Indeed - no reason to even transiently introduce new Misra violations.

Jan

#8 lore raw

PATCH 3/3 x86/APIC: Refactor GENAPIC_FLAT -> GENAPIC_MIXED

In reply to Matthew Barnes

The macro name is changed to somewhat mirror x2apic driver code, as logical flat is no longer used for external interrupts for this mode.

No functional change.

---
 xen/arch/x86/genapic/default.c     | 2 +-
 xen/arch/x86/include/asm/genapic.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/genapic/default.c +1 -1
index a968836a1878..3f0d57ea5e25 100644
@@ -16,5 +16,5 @@
 /* should be called last. */
 const struct genapic __initconst_cf_clobber apic_default = {
 	APIC_INIT("default", NULL),
-	GENAPIC_FLAT
+	GENAPIC_MIXED
 };
xen/arch/x86/include/asm/genapic.h +1 -1
index 91fdeaca47b3..fcb3eb04db7b 100644
@@ -46,7 +46,7 @@ void cf_check send_IPI_self_legacy(uint8_t vector);
 void cf_check init_apic_ldr_flat(void);
 const cpumask_t *cf_check vector_allocation_cpumask_phys(int cpu);
 void cf_check send_IPI_mask_flat(const cpumask_t *cpumask, int vector);
-#define GENAPIC_FLAT \
+#define GENAPIC_MIXED \
 	.int_delivery_mode = dest_Fixed, \
 	.int_dest_mode = 0 /* physical delivery */, \
 	.init_apic_ldr = init_apic_ldr_flat, \
Signature · 1 line
2.46.0
#9 lore raw
In reply to Matthew Barnes
Quoted 10 lines · Matthew Barnes

This patch series switches the apic_default APIC driver from using logical flat destination mode for external interrupts, to using physical destination mode for external interrupts.

This is followed up by two non-functional cleanup commits.

Matthew Barnes (3):
x86/APIC: Switch flat driver to use phys dst for ext ints x86/APIC: Remove unnecessary logical flat functions x86/APIC: Refactor GENAPIC_FLAT -> GENAPIC_MIXED

Patches 1 and 2 look fine.

For patch 3, can't we just delete the macro and expand it in it's single location?

It's a bigger patch, but a better improvement in genapic.h

~Andrew

#10 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 10 lines · Matthew Barnes

This patch series switches the apic_default APIC driver from using logical flat destination mode for external interrupts, to using physical destination mode for external interrupts.

This is followed up by two non-functional cleanup commits.

Matthew Barnes (3):
x86/APIC: Switch flat driver to use phys dst for ext ints x86/APIC: Remove unnecessary logical flat functions x86/APIC: Refactor GENAPIC_FLAT -> GENAPIC_MIXED

Quoted 6 lines

Patches 1 and 2 look fine.

For patch 3, can't we just delete the macro and expand it in it's single location?

It's a bigger patch, but a better improvement in genapic.h

I agree, but if we go that route we might as well do the conversion of GENAPIC_PHYS in the same patch, and deal with both at the same time (GENAPIC_PHYS is also used in a single place).

Thanks, Roger.