All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/srat: Conditional apic_id vs MAX_LOCAL_APIC comparison
@ 2025-02-28  5:18 WangYuli
  2025-02-28  9:32 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: WangYuli @ 2025-02-28  5:18 UTC (permalink / raw)
  To: dave.hansen, luto, peterz, tglx, mingo, bp, x86, hpa
  Cc: linux-kernel, zhanjun, niecheng1, chenlinxuan, WangYuli,
	Huacai Chen, Wentao Guan

The apic_id employed within the acpi_numa_processor_affinity_init()
function is derived from the acpi_srat_cpu_affinity structure defined
in acpi/actbl3.h.

When CONFIG_X86_X2APIC is not enabled, its maximum value is limited
to 255. It is only capable of exceeding 256 and 32768 —  which
corresponds to the definition of MAX_LOCAL_APIC — when CONFIG_X86_X2APIC
is activated.

Consequently, with CONFIG_X86_X2APIC disabled, this code segment will
elicit the compiler's "-Wtautological-constant-out-of-range-compare"
warning, as a variable capped at 255 can never satisfy a condition
requiring it to be greater than or equal to 256 or 32768.

Compiling the kernel with the W=1e flag will, in this scenario, lead
to compilation failure.

Suggested-by: Huacai Chen <chenhuacai@loongson.cn>
Co-developed-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
---
 arch/x86/mm/srat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/mm/srat.c b/arch/x86/mm/srat.c
index 6f8e0f21c710..93e5bcc58ead 100644
--- a/arch/x86/mm/srat.c
+++ b/arch/x86/mm/srat.c
@@ -90,10 +90,12 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 	else
 		apic_id = pa->apic_id;
 
+#ifdef CONFIG_X86_X2APIC
 	if (apic_id >= MAX_LOCAL_APIC) {
 		printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
 		return;
 	}
+#endif /* CONFIG_X86_X2APIC */
 
 	set_apicid_to_node(apic_id, node);
 	node_set(node, numa_nodes_parsed);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/srat: Conditional apic_id vs MAX_LOCAL_APIC comparison
  2025-02-28  5:18 [PATCH] x86/srat: Conditional apic_id vs MAX_LOCAL_APIC comparison WangYuli
@ 2025-02-28  9:32 ` Ingo Molnar
  2025-03-03  3:42   ` WangYuli
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2025-02-28  9:32 UTC (permalink / raw)
  To: WangYuli
  Cc: dave.hansen, luto, peterz, tglx, mingo, bp, x86, hpa,
	linux-kernel, zhanjun, niecheng1, chenlinxuan, Huacai Chen,
	Wentao Guan


* WangYuli <wangyuli@uniontech.com> wrote:

> The apic_id employed within the acpi_numa_processor_affinity_init()
> function is derived from the acpi_srat_cpu_affinity structure defined
> in acpi/actbl3.h.
> 
> When CONFIG_X86_X2APIC is not enabled, its maximum value is limited
> to 255.

How does the compiler know the value is limited to 0-255?

<acpi/actbl3.h> has an u32 apic_id field:

 struct acpi_srat_x2apic_cpu_affinity {
        struct acpi_subtable_header header;
        u16 reserved;           /* Reserved, must be zero */
        u32 proximity_domain;
        u32 apic_id;
        ^^^^^^^^^^^^
        u32 flags;
        u32 clock_domain;
        u32 reserved2;
 };

and the apic_id local variable in acpi_numa_processor_affinity_init() 
is an 'int':

        int apic_id;

Neither is limited to 0-255.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [PATCH] x86/srat: Conditional apic_id vs MAX_LOCAL_APIC comparison
  2025-02-28  9:32 ` Ingo Molnar
@ 2025-03-03  3:42   ` WangYuli
  0 siblings, 0 replies; 3+ messages in thread
From: WangYuli @ 2025-03-03  3:42 UTC (permalink / raw)
  To: mingo
  Cc: bp, chenhuacai, chenlinxuan, dave.hansen, guanwentao, hpa,
	linux-kernel, luto, mingo, niecheng1, peterz, tglx, wangyuli, x86,
	zhanjun

Hi Ingo,

The commit message already clearly explains that, uniquely,
acpi_numa_processor_affinity_init() utilizes the apic_id from the
acpi_srat_cpu_affinity struct, which is typed as u8 rather than u32.

The apic_id becomes (pa->apic_id << 8) | pa->local_sapic_eid if and
only if CONFIG_X86_X2APIC is enabled; otherwise, it remains pa->apic_id.

Consequently, even with apic_id being of type int, its maximum value is
still constrained to 255.

Thanks,
--
WangYuli

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-03  3:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28  5:18 [PATCH] x86/srat: Conditional apic_id vs MAX_LOCAL_APIC comparison WangYuli
2025-02-28  9:32 ` Ingo Molnar
2025-03-03  3:42   ` WangYuli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.