mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: Borislav Petkov <bp@alien8.de>, Thomas Gleixner <tglx@kernel.org>,
	x86@kernel.org,  linux-kernel@vger.kernel.org, yosry@kernel.org
Cc: Jim Mattson <jmattson@google.com>
Subject: [PATCH 1/1] x86/CPU/AMD: Avoid racy updates to MSR_K7_HWCR in set_cpuid_faulting()
Date: Tue,  9 Jun 2026 14:15:47 -0700	[thread overview]
Message-ID: <20260609211611.466231-2-jmattson@google.com> (raw)
In-Reply-To: <20260609211611.466231-1-jmattson@google.com>

Since msr_set_bit() and msr_clear_bit() perform a non-atomic update to an
MSR, they can race with a write to the same MSR from interrupt context.  On
AMD CPUs, set_cpuid_faulting() uses these functions to modify MSR_K7_HWCR
from process context, and boost_set_msr() modifies MSR_K7_HWCR from
interrupt context.

To prevent the race, disable interrupts on the AMD path through
set_cpuid_faulting(). Note that when set_cpuid_faulting() is called from
__switch_to_xtra(), interrupts are already disabled.

Reported-by: Sashiko (gemini/gemini-3.1-pro-preview)
Fixes: 65f55a301766 ("x86/CPU/AMD: Add CPUID faulting support")
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kernel/process.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 4c718f8adc59..92492a63108f 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -354,10 +354,14 @@ static void set_cpuid_faulting(bool on)
 		this_cpu_write(msr_misc_features_shadow, msrval);
 		wrmsrq(MSR_MISC_FEATURES_ENABLES, msrval);
 	} else if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
+		unsigned long flags;
+
+		local_irq_save(flags);
 		if (on)
 			msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_CPUID_USER_DIS_BIT);
 		else
 			msr_clear_bit(MSR_K7_HWCR, MSR_K7_HWCR_CPUID_USER_DIS_BIT);
+		local_irq_restore(flags);
 	}
 }
 
-- 
2.54.0.1099.g489fc7bff1-goog


  reply	other threads:[~2026-06-09 21:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 21:15 [PATCH 0/1] Fix an HWCR RMW race Jim Mattson
2026-06-09 21:15 ` Jim Mattson [this message]
2026-06-09 21:41   ` [PATCH 1/1] x86/CPU/AMD: Avoid racy updates to MSR_K7_HWCR in set_cpuid_faulting() Borislav Petkov
2026-06-09 22:08     ` Jim Mattson
2026-06-09 23:27       ` 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=20260609211611.466231-2-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --cc=yosry@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®