From: Xu Yihang <xuyihang@huawei.com>
To: <mingo@redhat.com>, <bp@alien8.de>, <x86@kernel.org>,
<hpa@zytor.com>, <dwmw@amazon.co.uk>,
<linux-kernel@vger.kernel.org>
Cc: <xuyihang@huawei.com>
Subject: [PATCH -next] x86/apic: Force logial APIC ID in range from 0 to 8
Date: Fri, 23 Apr 2021 15:53:24 +0800 [thread overview]
Message-ID: <20210423075324.133463-1-xuyihang@huawei.com> (raw)
According to Intel 64 and IA-32 Architectures Software Developer’s Manuals
Vol. 3A 10.6.2.2, Logical APIC ID locates on bit 24 to 31, can only
support up to 8 local APIC under flat mode. Also C99 says left shift exceeding
maximum value representable in the result type is undefined behavior. But
under x86 architecture, it seems doesn't do any actual damage.
There is KASAN warning on a 80 cores machine after booting #64 CPU.
```
[ 1.681097] UBSAN: Undefined behaviour in arch/x86/kernel/apic/apic_flat_64.c:51:11
[ 1.688739] shift exponent 64 is too large for 64-bit type 'long unsigned int'
```
Signed-off-by: Xu Yihang <xuyihang@huawei.com>
---
arch/x86/include/asm/apicdef.h | 1 +
arch/x86/kernel/apic/apic_flat_64.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/apicdef.h b/arch/x86/include/asm/apicdef.h
index 5716f22f81ac..150a5e831368 100644
--- a/arch/x86/include/asm/apicdef.h
+++ b/arch/x86/include/asm/apicdef.h
@@ -42,6 +42,7 @@
#define APIC_RRR 0xC0
#define APIC_LDR 0xD0
#define APIC_LDR_MASK (0xFFu << 24)
+#define APIC_LOGICAL_ID_MAX 8
#define GET_APIC_LOGICAL_ID(x) (((x) >> 24) & 0xFFu)
#define SET_APIC_LOGICAL_ID(x) (((x) << 24))
#define APIC_ALL_CPUS 0xFFu
diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
index 8f72b4351c9f..7bf91cadee21 100644
--- a/arch/x86/kernel/apic/apic_flat_64.c
+++ b/arch/x86/kernel/apic/apic_flat_64.c
@@ -41,7 +41,7 @@ void flat_init_apic_ldr(void)
unsigned long num, id;
num = smp_processor_id();
- id = 1UL << num;
+ id = 1UL << (num % APIC_LOGICAL_ID_MAX);
apic_write(APIC_DFR, APIC_DFR_FLAT);
val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
val |= SET_APIC_LOGICAL_ID(id);
--
2.17.1
next reply other threads:[~2021-04-23 7:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 7:53 Xu Yihang [this message]
2021-04-23 8:37 ` Thomas Gleixner
2021-04-26 2:09 ` xuyihang
2021-04-26 11:09 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210423075324.133463-1-xuyihang@huawei.com \
--to=xuyihang@huawei.com \
--cc=bp@alien8.de \
--cc=dwmw@amazon.co.uk \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®