arch/x86/mm/srat.c | 2 ++ 1 file changed, 2 insertions(+)
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
* 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
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
© 2016 - 2025 Red Hat, Inc.