From patchwork Fri Sep 6 17:16:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1981987 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 4X0jbq3kgKz1y1K for ; Sat, 7 Sep 2024 03:17:58 +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 1smcag-00026w-92; Fri, 06 Sep 2024 17:17:46 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smcae-00026Z-TA for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 17:17:44 +0000 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) (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-1.canonical.com (Postfix) with ESMTPS id 9FDFF3F17E for ; Fri, 6 Sep 2024 17:17:44 +0000 (UTC) Received: by mail-io1-f70.google.com with SMTP id ca18e2360f4ac-82aa3526f4eso1484739f.2 for ; Fri, 06 Sep 2024 10:17:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725643063; x=1726247863; 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=Ea4nSaLbw2ImPYN9WSO4KvnY+mDz/H8bR1kxu6P588s=; b=V3NuoX8rfDI4Bykt/8v60PUPrDrHhRR7tlCAlAtD8QAEzZ1eekhJTd2mbYha0EseDz hkYIImqWRFTX0NtL/EbCyTfKfkZj6RC4f9LnjcxIUAQdvEdzyLNAfs3tqREac7+W4XkZ wjPA6Zw0yLn3CUXRHimdB+FTD668upPMb46DXumTf1PuBIMo/zq9Ro5gVh0mjr43cYXz IONWkxed+V9TjK4kZvjqsMnBLiswRUlWlcKu2I3WUQJZE3X4DyM2tQ5FBaigxrUjdtTc o40rxLMh5ertNA8AWkQPja8+rrJ53PqHsM05ucnDIC4SeUnlev+N17FYy/IyT8rJPTFh UCJg== X-Gm-Message-State: AOJu0YzFNR/K2rb57SxlZkoU9a7slGucXZV52leO4coPCY47Ek29w8e7 wA9wU9OuFpIGZ279nPQFf6H8/GejpmPjESItQPGc7CPyhpwBvqVhSKjkdUxoWmw5oZOR+Ntq9Rx GBK5O+sJ4+0On+767P2q1NLuTLk/lyRSjbB1oNu/lLJFwWpXUGCKjuhuU/NYjffklyZwPy5k+L9 26XNSKGguYy0jA X-Received: by 2002:a6b:e20e:0:b0:82a:2a45:68 with SMTP id ca18e2360f4ac-82a960d83bfmr205770939f.0.1725643063298; Fri, 06 Sep 2024 10:17:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHwyu7rvJI1/Phqmo64807EzAuP6qokSiy+BTIe0ZA3tkCWa4oNuDQ3dYi4U0eVqovPgr+lg== X-Received: by 2002:a6b:e20e:0:b0:82a:2a45:68 with SMTP id ca18e2360f4ac-82a960d83bfmr205768939f.0.1725643062807; Fri, 06 Sep 2024 10:17:42 -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 ca18e2360f4ac-82a1a42a0a9sm476908239f.24.2024.09.06.10.17.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 10:17:42 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][N][PATCH v2 1/1] x86/CPU/AMD: Improve the erratum 1386 workaround Date: Fri, 6 Sep 2024 12:16:52 -0500 Message-Id: <20240906171653.17265-2-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906171653.17265-1-bethany.jamison@canonical.com> References: <20240906171653.17265-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 (cherry picked from commit 29ba89f1895285f06c333546882e0c5ae9a6df23) 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 0838ea579eb0f..ca6096dcc5c6b 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 @@ -925,6 +926,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), +}; + static void fix_erratum_1386(struct cpuinfo_x86 *c) { /* @@ -934,7 +940,13 @@ 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 (x86_cpu_has_min_microcode_rev(erratum_1386_microcode)) + return; + clear_cpu_cap(c, X86_FEATURE_XSAVES); }