From: Yuntao Wang <yuntao.wang@linux.dev>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Thorsten Blum <thorsten.blum@toblux.com>,
Tony Luck <tony.luck@intel.com>,
Daniel Sneddon <daniel.sneddon@linux.intel.com>,
Yuntao Wang <yuntao.wang@linux.dev>
Subject: [PATCH] x86/apic: Fix the issues in x2apic_disable()
Date: Mon, 12 Aug 2024 18:08:19 +0800 [thread overview]
Message-ID: <20240812100819.870513-1-yuntao.wang@linux.dev> (raw)
There are two issues in x2apic_disable().
The first issue is that the 'pr_warn' in 'if (x2apic_hw_locked())' will
never be executed, because when x2apic_hw_locked() evaluates to true,
x2apic_state should be X2APIC_ON_LOCKED. However, the current logic in
x2apic_disable() is that if x2apic_state is not X2APIC_ON, it returns
early, so the subsequent logic will not be executed.
Therefore, 'if (state != X2APIC_ON)' should be changed to
'if (state < X2APIC_ON)', so that when x2apic_state is X2APIC_ON_LOCKED,
the corresponding warning log can be printed.
The second issue is that the current logic of x2apic_disable() first sets
x2apic_mode and x2apic_state to 0 and X2APIC_DISABLED, respectively, and
then tries to disable x2APIC. However, when the APIC is locked in x2APIC
mode, that is, x2apic_state is X2APIC_ON_LOCKED, x2APIC cannot be disabled,
which causes the final values of the x2apic_mode/x2apic_state variables to
be inconsistent with the actual state of x2APIC.
Let's fix these issues.
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
arch/x86/kernel/apic/apic.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 66fd4b2a37a3..fce8d0214069 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1775,13 +1775,10 @@ static __init void apic_set_fixmap(bool read_apic);
static __init void x2apic_disable(void)
{
- u32 x2apic_id, state = x2apic_state;
+ u32 x2apic_id;
- x2apic_mode = 0;
- x2apic_state = X2APIC_DISABLED;
-
- if (state != X2APIC_ON)
- return;
+ if (x2apic_state < X2APIC_ON)
+ goto out;
x2apic_id = read_apic_id();
if (x2apic_id >= 255)
@@ -1799,6 +1796,10 @@ static __init void x2apic_disable(void)
* which fails to do the read after x2APIC was disabled.
*/
apic_set_fixmap(false);
+
+out:
+ x2apic_mode = 0;
+ x2apic_state = X2APIC_DISABLED;
}
static __init void x2apic_enable(void)
--
2.46.0
next reply other threads:[~2024-08-12 10:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 10:08 Yuntao Wang [this message]
2024-08-12 14:48 ` [PATCH] x86/apic: Fix the issues in x2apic_disable() Thomas Gleixner
2024-08-12 15:53 ` Yuntao Wang
2024-08-12 18:00 ` Thomas Gleixner
2024-08-13 1:48 ` [PATCH v2] " Yuntao Wang
2024-08-13 13:21 ` [tip: x86/urgent] x86/apic: Make x2apic_disable() work correctly tip-bot2 for Yuntao Wang
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=20240812100819.870513-1-yuntao.wang@linux.dev \
--to=yuntao.wang@linux.dev \
--cc=bp@alien8.de \
--cc=daniel.sneddon@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=thorsten.blum@toblux.com \
--cc=tony.luck@intel.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 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.