From patchwork Fri Sep 6 17:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1981992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0k375ct2z1y1H for ; Sat, 7 Sep 2024 03:38:11 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smcuJ-0004qU-JG; Fri, 06 Sep 2024 17:38:03 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smcuG-0004pI-PV for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 17:38:00 +0000 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 84D0E3F129 for ; Fri, 6 Sep 2024 17:38:00 +0000 (UTC) Received: by mail-io1-f71.google.com with SMTP id ca18e2360f4ac-82a678fbd0dso83444639f.2 for ; Fri, 06 Sep 2024 10:38:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725644279; x=1726249079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JMfInY9z8wUsTfUw9EGQZi7m31pvq09NQXirD62HY7c=; b=a84DADRcJzT3YypZ69d7Azc0/K/c7j26OwpgOmw8GHup5fbUcHa5WmNPGIYHbBS4qM 7ufvP5CzrEbMexAGRdd/vE6wEa5PBelFnYZlGy98GaXQjvf3/GxEg3g9ZF7lxVLjFIkU qQxUezwaA/DKCmCkHL84v8C1PbDRcYX5iv/gIJv08un98XwO/GvcbqLn3MCn9q68PP74 lAAPseFoV26g2QQVp7Wns8J4WlUmJiPaXquDb3HxXBo+VarPweCBzSZ3t644knDOqOpf NE/TmLBz0l6VztNMmgBueC/iRQn/6MkKm5fqpNn3V8DCveNBY9Qc7CtwiAbvIVb61Uyy FnOA== X-Gm-Message-State: AOJu0YziG2mZlKFMLuAkVjZS6ZQAReCM9B6IidmbCqSg5q+ZMWSGLixo OZQn9e80FRpEGA22LFEE5WBqYimcHXW9NARGX0xlR/qUDCv007n8mFCegu42ZDhyuugjQvZpSrP qASguy6IgQuKXrzz8VWF9IFcXXPsAbAvkrTpTrOOHOHF0LUpIiMvh0dUEpKfnRO3faDkWuKb7u2 srFgxCBbD02rTb X-Received: by 2002:a05:6602:1b1a:b0:82a:a35a:d163 with SMTP id ca18e2360f4ac-82aa35ad2c1mr11927239f.0.1725644279278; Fri, 06 Sep 2024 10:37:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGelenAfJMpPo+CPpbj/Ni75lhNd3sSaB2fnmWiCGJ4lFU9Oes7Uj1A0UcJyCoxdGnUMKOIMA== X-Received: by 2002:a05:6602:1b1a:b0:82a:a35a:d163 with SMTP id ca18e2360f4ac-82aa35ad2c1mr11925739f.0.1725644278834; Fri, 06 Sep 2024 10:37:58 -0700 (PDT) Received: from smtp.gmail.com (209-50-27-115.lnk02.ne.dynamic.allophone.net. [209.50.27.115]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ced2de7857sm4205704173.60.2024.09.06.10.37.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 10:37:58 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH v3 1/1] x86/CPU/AMD: Improve the erratum 1386 workaround Date: Fri, 6 Sep 2024 12:37:09 -0500 Message-Id: <20240906173709.17861-3-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906173709.17861-1-bethany.jamison@canonical.com> References: <20240906173709.17861-1-bethany.jamison@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Borislav Petkov (AMD)" BugLink: https://bugs.launchpad.net/bugs/2077321 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) Tested-by: "Maciej S. Szmigiero" Cc: Boris Ostrovsky Link: https://lore.kernel.org/r/20240324200525.GBZgCHhYFsBj12PrKv@fat_crate.local (backported from commit 29ba89f1895285f06c333546882e0c5ae9a6df23) [bjamison: context conflict from neighboring line, Jammy is missing 'fix_erratum_1386' definition] Signed-off-by: Bethany Jamison --- arch/x86/include/asm/cpu_device_id.h | 8 ++++++++ arch/x86/kernel/cpu/amd.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/x86/include/asm/cpu_device_id.h b/arch/x86/include/asm/cpu_device_id.h index e8e3dbe7f1730..b6325ee308718 100644 --- a/arch/x86/include/asm/cpu_device_id.h +++ b/arch/x86/include/asm/cpu_device_id.h @@ -288,6 +288,14 @@ struct x86_cpu_desc { .x86_microcode_rev = (revision), \ } +#define AMD_CPU_DESC(fam, model, stepping, revision) { \ + .x86_family = (fam), \ + .x86_vendor = X86_VENDOR_AMD, \ + .x86_model = (model), \ + .x86_stepping = (stepping), \ + .x86_microcode_rev = (revision), \ +} + extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match); extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table); diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index c99a16417cf03..cb8bd6145d1bc 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -931,6 +932,11 @@ static void init_amd_bd(struct cpuinfo_x86 *c) clear_rdrand_cpuid_bit(c); } +static const struct x86_cpu_desc erratum_1386_microcode[] = { + AMD_CPU_DESC(0x17, 0x1, 0x2, 0x0800126e), + AMD_CPU_DESC(0x17, 0x31, 0x0, 0x08301052), +}; + void init_spectral_chicken(struct cpuinfo_x86 *c) { #ifdef CONFIG_CPU_UNRET_ENTRY @@ -958,7 +964,13 @@ void init_spectral_chicken(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 (x86_cpu_has_min_microcode_rev(erratum_1386_microcode)) + return; + clear_cpu_cap(c, X86_FEATURE_XSAVES); }