From: Juergen Gross <jgross@suse.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Juergen Gross <jgross@suse.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH 4/4] x86/mtrr: Drop cache_disable_lock
Date: Wed, 21 Jan 2026 15:11:06 +0100 [thread overview]
Message-ID: <20260121141106.755458-5-jgross@suse.com> (raw)
In-Reply-To: <20260121141106.755458-1-jgross@suse.com>
Now that no global state is modified under cache_disable_lock, it can
be dropped.
All required serialization is done via mtrr_mutex and cpus_read_lock(),
ensuring that only one set_mtrr() can be active at any time and that
this call can't run concurrently with CPU bringup.
The main advantages are a faster boot of machines with lots of CPUs,
and avoiding hard lockups on those machines in case
mtrr_generic_set_state() takes too long in uncached mode, resulting
in other CPUs waiting for seconds to get the cache_disable_lock.
This has been seen happening in more than 1% of all boots on an Intel
machine with 960 CPUs. With this patch applied boot was always
successful.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
I was considering applying a "Fixes:" tag, but this could only
reference the initial kernel git commit, as MTRR support predates
git, and the problem existed since MTRRs became a thing.
arch/x86/kernel/cpu/mtrr/generic.c | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index bfd5a7ba17cb..280f9491ec2e 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -970,7 +970,6 @@ static void mtrr_enable(struct mtrr_work_state *state)
* The caller must ensure that local interrupts are disabled and
* are reenabled after cache_enable() has been called.
*/
-static DEFINE_RAW_SPINLOCK(cache_disable_lock);
/*
* Cache flushing is the most time-consuming step when programming the
@@ -984,17 +983,9 @@ static void maybe_flush_caches(void)
}
static void cache_disable(struct mtrr_work_state *state)
- __acquires(cache_disable_lock)
{
unsigned long cr0;
- /*
- * This is not ideal since the cache is only flushed/disabled
- * for this CPU while the MTRRs are changed, but changing this
- * requires more invasive changes to the way the kernel boots.
- */
- raw_spin_lock(&cache_disable_lock);
-
/* Enter the no-fill (CD=1, NW=0) cache mode and flush caches. */
cr0 = read_cr0() | X86_CR0_CD;
write_cr0(cr0);
@@ -1018,7 +1009,6 @@ static void cache_disable(struct mtrr_work_state *state)
}
static void cache_enable(struct mtrr_work_state *state)
- __releases(cache_disable_lock)
{
/* Flush TLBs (no need to flush caches - they are disabled) */
count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
@@ -1033,8 +1023,6 @@ static void cache_enable(struct mtrr_work_state *state)
/* Restore value of CR4 */
if (cpu_feature_enabled(X86_FEATURE_PGE))
__write_cr4(state->cr4);
-
- raw_spin_unlock(&cache_disable_lock);
}
void mtrr_generic_set_state(void)
--
2.52.0
prev parent reply other threads:[~2026-01-21 14:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 14:11 [PATCH 0/4] x86/mtrr: Allow MTRR updates on multiple CPUs in parallel Juergen Gross
2026-01-21 14:11 ` [PATCH 1/4] x86/mtrr: Move cache_enable() and cache_disable() to mtrr/generic.c Juergen Gross
2026-01-21 14:11 ` [PATCH 2/4] x86/mtrr: Introduce MTRR work state structure Juergen Gross
2026-01-21 19:58 ` kernel test robot
2026-01-22 13:48 ` Jürgen Groß
2026-01-21 14:11 ` [PATCH 3/4] x86/mtrr: Add a prepare_set hook to mtrr_ops Juergen Gross
2026-01-21 14:11 ` Juergen Gross [this message]
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=20260121141106.755458-5-jgross@suse.com \
--to=jgross@suse.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@kernel.org \
--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®