Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp401880lqp; Thu, 21 Mar 2024 05:06:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRcc1gaSgdixMLvWm3S0TViY9NAt20aJnk/VIVZf5lg2aFi4AoIyn9C/SGkj65NA0TSgZI1gcYKjw6UxOJgK1cAclT0dYPzFQesKSlzw== X-Google-Smtp-Source: AGHT+IHDRo77CQZe5KsqGhzb4ecrqfmnqIvLM2RJIQ3uoVPHoIdQ39dVUQEn1oTEWfXXlwVEW1ZM X-Received: by 2002:a17:90a:b28a:b0:29c:791d:b5d5 with SMTP id c10-20020a17090ab28a00b0029c791db5d5mr9602703pjr.34.1711022802507; Thu, 21 Mar 2024 05:06:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711022802; cv=pass; d=google.com; s=arc-20160816; b=Jtz8P9C1GQhs2aWIys3Kjn2ZaTZzCFxGXpdjWrcwmgFnyQci9Vt02Io8k+iEvcTwmx rB/8ZzJBmAmLLN9GnQfXOdPEvTuwYHEFjXRlo6C3jaWIOOZHdegYUf0qLZZHSD0un4Nu +dTcQbpSyE/mOS+NmNCWctGTVxo2xkqFJVsUXb/pX3WEOTqTtUoDbwxSykH/wBZwwTOs gJFBL9nh9bSPbF4xYZnaeUbibi/jxjlTq3Vt4nPy1ZeNhpCeIcuHgB1Oa9yISrYgm92j jZJfJ11zTtSKTfJqGmmjBtk9ZOgOW5g4HJviShnn6gJIvQEkyWY3ojZo4jmNNVGx7VG2 BDYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UWpi7LyUNy0AQEy2CiHgJzLBINZOuA2fWgsxTgHOoiI=; fh=QzA5NeGFu/NO+G38+1yaLpwAKk6qo9JKFzJm54YDkPU=; b=YJGAC9014dLHTFd3y1q9aIGFQaDyTl8vOvAqWgSCJpBw/Gc+1LAIRplqwPv+Wjv7fv /woRZfN4P+7uz6T+ocBBI0dx31DAZ/7WuDzNsvC56tpkcYYiJXHkC+koY7l+2LwacH8F 9nopvdt9fSjVBu+Hlk4mlTBZxqc15X3rymcotKS2EGCshjYx6LiPe6bHvdtV5O9L9cyt b0jomiNqT0yMEuI4rmCe/Jn0Msv29u6m8ocwRqNy0wzhyJTKDr3MjiV87inyja2SVmsy 6fnxV1Bxs3VIJ6l6WT+eTyG/1kjYkP/wsKYru8TlVf0EOFv7QVAyeQZ+9dxjZYNuefwG eGXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=neutral (body hash did not verify) header.i=@alien8.de header.s=alien8 header.b=XSp17bLB; arc=pass (i=1 spf=pass spfdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-110004-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110004-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lw16-20020a17090b181000b002a02f8e675bsi113540pjb.183.2024.03.21.05.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 05:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110004-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@alien8.de header.s=alien8 header.b=XSp17bLB; arc=pass (i=1 spf=pass spfdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-110004-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110004-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3354A28325A for ; Thu, 21 Mar 2024 12:06:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65152762E8; Thu, 21 Mar 2024 12:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="XSp17bLB" Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97BC8757FB for ; Thu, 21 Mar 2024 12:06:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711022782; cv=none; b=fNYjluG4gAiwX+rJLew4EUN0dcKos1AnSE7SDwcnK1T1Xh7IfQFJaoX7lh8P9kYVPM99zNGsfq/5VoARAQGc43GPx9rfZ+x9AMP/7UseC6nFOHl9mXshJDPG9RJ1ZcQbWvAfdlsMS0M8aNeDbhblwsp5GMTn4NOvi1kzmyKUs4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711022782; c=relaxed/simple; bh=UvforLwfgnlG+jp6wPQG0d7IyTlRP6uEi4yy81qpH+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HfEDKamlwlRMhOG619xSFL11D0ZGljOXrO5hBm3mDe5MhtdXJBXFPyxX3DMEMr3IMEbHsK3CdaZxO8kMmeRyOyx0DPgOzK32mdbVRpYHJ7miV7COwuBgaiXNXOsNnydjT72KfjNsz/3h3y/wJ9CkEddd0mlV7lXebptOIE7Zqds= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; dkim=fail (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b=XSp17bLB reason="signature verification failed"; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 53C5B40E0174; Thu, 21 Mar 2024 12:06:12 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=fail (4096-bit key) reason="fail (body has been altered)" header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OyVSDZbBXt_s; Thu, 21 Mar 2024 12:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1711022768; bh=ySNfKOBvmaBjblVhDHOEORlC5hG2HM8FoWiv/5wO+kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XSp17bLBcorqiurTE1T/YaEeVhg9jfcch8XQBB3BlXIaVrMPGW+FB2MFsSFXWTBG7 RfvQQG8o4RmzN0PUF1B6ZMWcp0Acxhef/xIky4oXrjlj63FstUj1iKNl/8PA+E6c/e 7bDT9d4KnPNjrLBgdAFiQ4CpXulA947qu/d02HXGfS1XwcbmkhP7yGYfweECSyja/d AmHWHK3EGtOc5DPLQw4hEKmLJDvDhHELZD2TyYn8tePfLm79yJ5QWsBBz8cYfcE+q2 irabCiG4qd1+h5mSvN5XYyLdlFuZgSQM0XMrlFpI+QTS0kbdluQKluziU+B/T7h3rC +SDx4HSNfmfUJ9WNeBCnPNt9+eE1B8ky1uznePXlEknDtIe6j3AQPGKwuufArOrKiP wZc5TjRh1CFe/1yHATVowgrb790CjVdjzAGCNK3XvKEYHwnt0J1BT1MWV6lj1gCG8h a1AaE0DjZ691zbBrD68SDTgojRfK+dyxMX/J/NASWSCQA5irUFPMIaVcmFxdYxX4po nRUp8kxTxPg2xzV0Zk7d9c8hyvqw7exa4Jx6TkACseoDyIq3zS5g5fzNdVhHgeJS/U +fNequf0McdUq/t9EtGK9MDEwKxBkCgDfC/yHnNmuEMT7o4hsvKzJ5Y5YPpE8Bd8W5 V1//s3w8r1sa/5TS+ZkrGfy8= Received: from zn.tnic (pd953021b.dip0.t-ipconnect.de [217.83.2.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 1483540E016C; Thu, 21 Mar 2024 12:06:04 +0000 (UTC) From: Borislav Petkov To: X86 ML Cc: LKML , Boris Ostrovsky , "Maciej S. Szmigiero" Subject: [PATCH 2/2] x86/CPU/AMD: Improve the erratum 1386 workaround Date: Thu, 21 Mar 2024 13:05:48 +0100 Message-ID: <20240321120548.22687-2-bp@alien8.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321120548.22687-1-bp@alien8.de> References: <20240321120548.22687-1-bp@alien8.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: "Borislav Petkov (AMD)" Disable XSAVES only on machines which haven't loaded the microcode revision containing the erratum fix. This will come in handy when running archaic OSes as guests. OSes whose brilliant programmers thought that CPUID is overrated and one should not query it but use features directly, ala shoot first, ask questions later... but only if you're alive after the shooting. Signed-off-by: Borislav Petkov (AMD) Cc: Boris Ostrovsky Cc: "Maciej S. Szmigiero" --- arch/x86/kernel/cpu/amd.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 6d8677e80ddb..c02b07feff6e 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -804,6 +805,16 @@ static void init_amd_bd(struct cpuinfo_x86 *c) =20 static void fix_erratum_1386(struct cpuinfo_x86 *c) { + u8 fam, model, stpng, rev; + union zen_patch_rev p; + + p.ucode_rev =3D c->microcode; + + fam =3D p.ext_fam + 0xf; + model =3D p.ext_model << 4 | p.model; + stpng =3D p.stepping; + rev =3D p.rev; + /* * Work around Erratum 1386. The XSAVES instruction malfunctions in * certain circumstances on Zen1/2 uarch, and not all parts have had @@ -811,7 +822,24 @@ static void fix_erratum_1386(struct cpuinfo_x86 *c) * * Affected parts all have no supervisor XSAVE states, meaning that * the XSAVEC instruction (which works fine) is equivalent. + * + * Clear the feature flag only on microcode revisions which + * don't have the fix. */ + if (fam =3D=3D c->x86 && + model =3D=3D c->x86_model && + stpng =3D=3D c->x86_stepping) { + if (fam =3D=3D 0x17) { + if (model =3D=3D 0x1 && stpng =3D=3D 0x2) { + if (rev >=3D 0x6e) + return; + } else if (model =3D=3D 0x31 && stpng =3D=3D 0x0) { + if (rev >=3D 0x52) + return; + } + } + } + clear_cpu_cap(c, X86_FEATURE_XSAVES); } =20 --=20 2.43.0