From nobody Tue Dec 16 21:05:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B060EEB64DC for ; Fri, 21 Jul 2023 17:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229937AbjGURLN (ORCPT ); Fri, 21 Jul 2023 13:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjGURLL (ORCPT ); Fri, 21 Jul 2023 13:11:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2376A1710; Fri, 21 Jul 2023 10:11:07 -0700 (PDT) Date: Fri, 21 Jul 2023 17:11:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689959465; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vi6cCicNwWyAB5LUQqwwsECz3OgXnLAG3wsxIu9BQfc=; b=ae6Kr3A701kX8L/iXG/2GCRc7slZW36BFBPMpV/Qxf5mDI/Y3wSXMos0OXYYWLtx7Lpr+o yBR6zjsmgSf0cbrxoEMxIKWcDxTS6StYPWAP0S9pDkMqX+XPN8g6jSB8aBj1sr7cnsRztY l1ITNaJKvvwcVI6RPROxSH+dnzHZQ4DEDB6+Z1nMqlsFEoPzBVS06rcdQLPFOukZvL6ZYo oWlUPYLs+UXpr6UT7kZp5lnWrFqjFujP8RfzQ2GW70plA2FAA4/vFdR71HYzqmMuz50cdD fSWON0v6Sp0pZy5TNWnuikOXALYFrQqFtHU+zOjCUk7z/DYKXUQK/h/GIMSl4A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689959465; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vi6cCicNwWyAB5LUQqwwsECz3OgXnLAG3wsxIu9BQfc=; b=oX5LeEzkMKLOYxW+2u/emjsoXV+jOLDkM3sVAwkXSAv9vsPyS3MKzqcDlAQn28IJ8rj29S ybSxJBDH0HC7OEDw== From: "tip-bot2 for Borislav Petkov (AMD)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: ras/core] x86/mce: Prevent duplicate error records Cc: "Borislav Petkov (AMD)" , Tony Luck , Aristeu Rozanski , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230515143225.GC4090740@cathedrallabs.org> References: <20230515143225.GC4090740@cathedrallabs.org> MIME-Version: 1.0 Message-ID: <168995946413.28540.2865986697159776163.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the ras/core branch of tip: Commit-ID: c3629dd7e67d6ec5705d33b0de0d142c972fe573 Gitweb: https://git.kernel.org/tip/c3629dd7e67d6ec5705d33b0de0d142c9= 72fe573 Author: Borislav Petkov (AMD) AuthorDate: Wed, 19 Jul 2023 14:19:50 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 21 Jul 2023 18:55:46 +02:00 x86/mce: Prevent duplicate error records A legitimate use case of the MCA infrastructure is to have the firmware log all uncorrectable errors and also, have the OS see all correctable errors. The uncorrectable, UCNA errors are usually configured to be reported through an SMI. CMCI, which is the correctable error reporting interrupt, uses SMI too and having both enabled, leads to unnecessary overhead. So what ends up happening is, people disable CMCI in the wild and leave on only the UCNA SMI. When CMCI is disabled, the MCA infrastructure resorts to polling the MCA banks. If a MCA MSR is shared between the logical threads, one error ends up getting logged multiple times as the polling runs on every logical thread. Therefore, introduce locking on the Intel side of the polling routine to prevent such duplicate error records from appearing. Based on a patch by Aristeu Rozanski . Signed-off-by: Borislav Petkov (AMD) Tested-by: Tony Luck Acked-by: Aristeu Rozanski Link: https://lore.kernel.org/r/20230515143225.GC4090740@cathedrallabs.org --- arch/x86/kernel/cpu/mce/core.c | 9 ++++++++- arch/x86/kernel/cpu/mce/intel.c | 19 ++++++++++++++++++- arch/x86/kernel/cpu/mce/internal.h | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 89e2aab..b8ad5a5 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1608,6 +1608,13 @@ static void __start_timer(struct timer_list *t, unsi= gned long interval) local_irq_restore(flags); } =20 +static void mc_poll_banks_default(void) +{ + machine_check_poll(0, this_cpu_ptr(&mce_poll_banks)); +} + +void (*mc_poll_banks)(void) =3D mc_poll_banks_default; + static void mce_timer_fn(struct timer_list *t) { struct timer_list *cpu_t =3D this_cpu_ptr(&mce_timer); @@ -1618,7 +1625,7 @@ static void mce_timer_fn(struct timer_list *t) iv =3D __this_cpu_read(mce_next_interval); =20 if (mce_available(this_cpu_ptr(&cpu_info))) { - machine_check_poll(0, this_cpu_ptr(&mce_poll_banks)); + mc_poll_banks(); =20 if (mce_intel_cmci_poll()) { iv =3D mce_adjust_timer(iv); diff --git a/arch/x86/kernel/cpu/mce/intel.c b/arch/x86/kernel/cpu/mce/inte= l.c index 95275a5..f532355 100644 --- a/arch/x86/kernel/cpu/mce/intel.c +++ b/arch/x86/kernel/cpu/mce/intel.c @@ -56,6 +56,13 @@ static DEFINE_PER_CPU(int, cmci_backoff_cnt); */ static DEFINE_RAW_SPINLOCK(cmci_discover_lock); =20 +/* + * On systems that do support CMCI but it's disabled, polling for MCEs can + * cause the same event to be reported multiple times because IA32_MCi_STA= TUS + * is shared by the same package. + */ +static DEFINE_SPINLOCK(cmci_poll_lock); + #define CMCI_THRESHOLD 1 #define CMCI_POLL_INTERVAL (30 * HZ) #define CMCI_STORM_INTERVAL (HZ) @@ -426,12 +433,22 @@ void cmci_disable_bank(int bank) raw_spin_unlock_irqrestore(&cmci_discover_lock, flags); } =20 +/* Bank polling function when CMCI is disabled. */ +static void cmci_mc_poll_banks(void) +{ + spin_lock(&cmci_poll_lock); + machine_check_poll(0, this_cpu_ptr(&mce_poll_banks)); + spin_unlock(&cmci_poll_lock); +} + void intel_init_cmci(void) { int banks; =20 - if (!cmci_supported(&banks)) + if (!cmci_supported(&banks)) { + mc_poll_banks =3D cmci_mc_poll_banks; return; + } =20 mce_threshold_vector =3D intel_threshold_interrupt; cmci_discover(banks); diff --git a/arch/x86/kernel/cpu/mce/internal.h b/arch/x86/kernel/cpu/mce/i= nternal.h index d2412ce..ed4a71c 100644 --- a/arch/x86/kernel/cpu/mce/internal.h +++ b/arch/x86/kernel/cpu/mce/internal.h @@ -274,4 +274,5 @@ static __always_inline u32 mca_msr_reg(int bank, enum m= ca_msr reg) return 0; } =20 +extern void (*mc_poll_banks)(void); #endif /* __X86_MCE_INTERNAL_H__ */