Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1465080pxb; Fri, 18 Feb 2022 08:17:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJy588J92u4Cu4a8kfyCONNOXqQ8H9XwfUKmf9njT+Cw+av2FL7xbbstBjSthMUaWgHhjsFV X-Received: by 2002:a50:daca:0:b0:410:2f34:b6ee with SMTP id s10-20020a50daca000000b004102f34b6eemr9186426edj.158.1645201077924; Fri, 18 Feb 2022 08:17:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645201077; cv=none; d=google.com; s=arc-20160816; b=t79gcp0rquHn7Gs6wq7SlO/XvjsiF3BywD2LKpubLy1Iw6Lx9auoGrb5EgqKvwGBSl vei1ZlvgqjGmkc68DbNi6a0R9/ED0+I/LpamuX/IyNMjGDPdb7Ykcm9zj8moK+IucflR PM+MhC2eztIm0bxCYNXovb+4cNrkOeZJlPoRzDJmPuUIGmlnpX9qW9gs7BlFHniAMn/j bdTjzw7YyK/iOlWmyyDTw83OQ0GyUFwJjo/d4Qz4YYhssOUWdU59fq163M0P76g1+LYi Cjkrjlw0DHHsvyI/RbxO27MI+Kd3g4dQmgGpjmVvTx1BITAuk2hr25nxIXxSD8uQlMSH xJ6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4dgrVhY1zhSIpJ67A/qW0ekCgb8tkD1wGOZsXKygGvI=; b=eS827uUl5cT+KTMli3zYvg51fA6o5I8QySyTAfwCRDxb032dsmN8uF4h4BEYbKqvkW sgXLLnQOnOQCQ3ZI97ATfnoyUzzkae3DU+ZgxvfK+8O5r81zPkawNQKJAXPKHRV4WjL4 awZGnBboASux7YfFY7IjQmYkU63EizAWSyen2k8rdG/J6RaSnVvMfuTofJG5zJUD2bfy xf2NpS5un+Cem6kZkpPX34t5Cr1MJW52Uc8bgf9hY9SxQitN/gomvThLNkJ1cagxMhlm TY4t0tUciOGCzAc7WrgZz3mgwEn8dlrfy1lqWr+X/P2aTV4/yApF+93L4f4rJJZUk7Mz wc2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=BtcpeqG9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb32si5377111ejc.781.2022.02.18.08.17.33; Fri, 18 Feb 2022 08:17:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=BtcpeqG9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236790AbiBRPHb (ORCPT + 99 others); Fri, 18 Feb 2022 10:07:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236785AbiBRPHa (ORCPT ); Fri, 18 Feb 2022 10:07:30 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A7811FA5E for ; Fri, 18 Feb 2022 07:07:11 -0800 (PST) Received: from zn.tnic (dslb-088-067-221-104.088.067.pools.vodafone-ip.de [88.67.221.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 29CCA1EC0453; Fri, 18 Feb 2022 16:07:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1645196826; h=from:from: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:in-reply-to:in-reply-to: references:references; bh=4dgrVhY1zhSIpJ67A/qW0ekCgb8tkD1wGOZsXKygGvI=; b=BtcpeqG9GRvEK/cadYcIC9HJIHGD3pgA8AuAa7ojK/+CEMs0QtVTqam4AeeqHVNCZX4w7n JjJjZoKg6leeI8XSdmdG6SdzLCEk3Qn/imzg4N+NDeWvQMTEUC3akhJiFxd2ie/q+YDQ7H Yuooou/A67KcZu+7spNLKDZsDl4N1ls= Date: Fri, 18 Feb 2022 16:07:09 +0100 From: Borislav Petkov To: Jue Wang , Tony Luck Cc: x86@kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v2] x86/mce: work around an erratum on fast string copy instructions. Message-ID: References: <20220218013209.2436006-1-juew@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220218013209.2436006-1-juew@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 17, 2022 at 05:32:09PM -0800, Jue Wang wrote: > +static noinstr bool quirk_skylake_repmov(void) > +{ > + u64 mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS); > + u64 misc_enable = __rdmsr(MSR_IA32_MISC_ENABLE); > + > + /* > + * Apply the quirk only to local machine checks, i.e., no broadcast > + * sync is needed. > + */ > + if ((mcgstatus & MCG_STATUS_LMCES) && > + unlikely(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) { > + u64 mc1_status = mce_rdmsrl(MSR_IA32_MCx_STATUS(1)); > + > + /* Check for a software-recoverable data fetch error. */ > + if ((mc1_status & > + (MCI_STATUS_VAL | MCI_STATUS_OVER | MCI_STATUS_UC | MCI_STATUS_EN | > + MCI_STATUS_ADDRV | MCI_STATUS_MISCV | MCI_STATUS_PCC | > + MCI_STATUS_AR | MCI_STATUS_S)) == > + (MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN | > + MCI_STATUS_ADDRV | MCI_STATUS_MISCV | > + MCI_STATUS_AR | MCI_STATUS_S)) { > + misc_enable &= ~MSR_IA32_MISC_ENABLE_FAST_STRING; > + __wrmsr(MSR_IA32_MISC_ENABLE, > + (u32)misc_enable, (u32)(misc_enable >> 32)); "You're going to have to use the mce_{rd,wr}msrl() routines." I actually really meant that. And I went and simplified this a bit more so that it is more readable, diff ontop. Also, Tony, I think the clearing of MCG_STATUS should happen last. --- diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index c1a41da99975..1741be9b9464 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -831,34 +831,35 @@ quirk_sandybridge_ifu(int bank, struct mce *m, struct pt_regs *regs) */ static noinstr bool quirk_skylake_repmov(void) { - u64 mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS); - u64 misc_enable = __rdmsr(MSR_IA32_MISC_ENABLE); + u64 mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS); + u64 misc_enable = mce_rdmsrl(MSR_IA32_MISC_ENABLE); + u64 mc1_status; /* * Apply the quirk only to local machine checks, i.e., no broadcast * sync is needed. */ - if ((mcgstatus & MCG_STATUS_LMCES) && - (misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) { - u64 mc1_status = mce_rdmsrl(MSR_IA32_MCx_STATUS(1)); - - /* Check for a software-recoverable data fetch error. */ - if ((mc1_status & - (MCI_STATUS_VAL | MCI_STATUS_OVER | MCI_STATUS_UC | MCI_STATUS_EN | - MCI_STATUS_ADDRV | MCI_STATUS_MISCV | MCI_STATUS_PCC | - MCI_STATUS_AR | MCI_STATUS_S)) == - (MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN | - MCI_STATUS_ADDRV | MCI_STATUS_MISCV | - MCI_STATUS_AR | MCI_STATUS_S)) { - misc_enable &= ~MSR_IA32_MISC_ENABLE_FAST_STRING; - __wrmsr(MSR_IA32_MISC_ENABLE, - (u32)misc_enable, (u32)(misc_enable >> 32)); - mce_wrmsrl(MSR_IA32_MCG_STATUS, 0); - mce_wrmsrl(MSR_IA32_MCx_STATUS(1), 0); - pr_err_once("Errata detected, disable fast string copy instructions.\n"); - return true; - } + if (!(mcgstatus & MCG_STATUS_LMCES) || + !(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) + return false; + + mc1_status = mce_rdmsrl(MSR_IA32_MCx_STATUS(1)); + + /* Check for a software-recoverable data fetch error. */ + if ((mc1_status & + (MCI_STATUS_VAL | MCI_STATUS_OVER | MCI_STATUS_UC | MCI_STATUS_EN | + MCI_STATUS_ADDRV | MCI_STATUS_MISCV | MCI_STATUS_PCC | + MCI_STATUS_AR | MCI_STATUS_S)) == + (MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN | + MCI_STATUS_ADDRV | MCI_STATUS_MISCV | + MCI_STATUS_AR | MCI_STATUS_S)) { + misc_enable &= ~MSR_IA32_MISC_ENABLE_FAST_STRING; + mce_wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable); + mce_wrmsrl(MSR_IA32_MCx_STATUS(1), 0); + pr_err_once("Erratum detected, disable fast string copy instructions.\n"); + return true; } + return false; } @@ -1432,7 +1433,7 @@ noinstr void do_machine_check(struct pt_regs *regs) return unexpected_machine_check(regs); if (mce_flags.skx_repmov_quirk && quirk_skylake_repmov()) - return; + goto clear; /* * Establish sequential order between the CPUs entering the machine @@ -1576,6 +1577,7 @@ noinstr void do_machine_check(struct pt_regs *regs) out: instrumentation_end(); +clear: mce_wrmsrl(MSR_IA32_MCG_STATUS, 0); } EXPORT_SYMBOL_GPL(do_machine_check); -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette