mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Borislav Petkov (AMD)" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/urgent] x86/microcode/AMD: Pay attention to the stepping dynamically
Date: Tue, 22 Oct 2024 16:08:26 -0000	[thread overview]
Message-ID: <172961330684.1442.17411760938161239553.tip-bot2@tip-bot2> (raw)
In-Reply-To: <91194406-3fdf-4e38-9838-d334af538f74@kernel.dk>

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     d1744a4c975b1acbe8b498356d28afbc46c88428
Gitweb:        https://git.kernel.org/tip/d1744a4c975b1acbe8b498356d28afbc46c88428
Author:        Borislav Petkov (AMD) <bp@alien8.de>
AuthorDate:    Mon, 21 Oct 2024 10:27:52 +02:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Tue, 22 Oct 2024 16:37:13 +02:00

x86/microcode/AMD: Pay attention to the stepping dynamically

Commit in Fixes changed how a microcode patch is loaded on Zen and newer but
the patch matching needs to happen with different rigidity, depending on what
is being done:

1) When the patch is added to the patches cache, the stepping must be ignored
   because the driver still supports different steppings per system

2) When the patch is matched for loading, then the stepping must be taken into
   account because each CPU needs the patch matching its exact stepping

Take care of that by making the matching smarter.

Fixes: 94838d230a6c ("x86/microcode/AMD: Use the family,model,stepping encoded in the patch ID")
Reported-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Tested-by: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/r/91194406-3fdf-4e38-9838-d334af538f74@kernel.dk
---
 arch/x86/kernel/cpu/microcode/amd.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index f63b051..1ae36ab 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -613,16 +613,19 @@ static int __init save_microcode_in_initrd(void)
 }
 early_initcall(save_microcode_in_initrd);
 
-static inline bool patch_cpus_equivalent(struct ucode_patch *p, struct ucode_patch *n)
+static inline bool patch_cpus_equivalent(struct ucode_patch *p,
+					 struct ucode_patch *n,
+					 bool ignore_stepping)
 {
 	/* Zen and newer hardcode the f/m/s in the patch ID */
         if (x86_family(bsp_cpuid_1_eax) >= 0x17) {
 		union cpuid_1_eax p_cid = ucode_rev_to_cpuid(p->patch_id);
 		union cpuid_1_eax n_cid = ucode_rev_to_cpuid(n->patch_id);
 
-		/* Zap stepping */
-		p_cid.stepping = 0;
-		n_cid.stepping = 0;
+		if (ignore_stepping) {
+			p_cid.stepping = 0;
+			n_cid.stepping = 0;
+		}
 
 		return p_cid.full == n_cid.full;
 	} else {
@@ -644,13 +647,13 @@ static struct ucode_patch *cache_find_patch(struct ucode_cpu_info *uci, u16 equi
 	WARN_ON_ONCE(!n.patch_id);
 
 	list_for_each_entry(p, &microcode_cache, plist)
-		if (patch_cpus_equivalent(p, &n))
+		if (patch_cpus_equivalent(p, &n, false))
 			return p;
 
 	return NULL;
 }
 
-static inline bool patch_newer(struct ucode_patch *p, struct ucode_patch *n)
+static inline int patch_newer(struct ucode_patch *p, struct ucode_patch *n)
 {
 	/* Zen and newer hardcode the f/m/s in the patch ID */
         if (x86_family(bsp_cpuid_1_eax) >= 0x17) {
@@ -659,6 +662,9 @@ static inline bool patch_newer(struct ucode_patch *p, struct ucode_patch *n)
 		zp.ucode_rev = p->patch_id;
 		zn.ucode_rev = n->patch_id;
 
+		if (zn.stepping != zp.stepping)
+			return -1;
+
 		return zn.rev > zp.rev;
 	} else {
 		return n->patch_id > p->patch_id;
@@ -668,10 +674,14 @@ static inline bool patch_newer(struct ucode_patch *p, struct ucode_patch *n)
 static void update_cache(struct ucode_patch *new_patch)
 {
 	struct ucode_patch *p;
+	int ret;
 
 	list_for_each_entry(p, &microcode_cache, plist) {
-		if (patch_cpus_equivalent(p, new_patch)) {
-			if (!patch_newer(p, new_patch)) {
+		if (patch_cpus_equivalent(p, new_patch, true)) {
+			ret = patch_newer(p, new_patch);
+			if (ret < 0)
+				continue;
+			else if (!ret) {
 				/* we already have the latest patch */
 				kfree(new_patch->data);
 				kfree(new_patch);

  parent reply	other threads:[~2024-10-22 16:08 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-27 15:17 AMD zen microcode updates breaks boot Jens Axboe
2024-09-28  6:10 ` Borislav Petkov
2024-09-28 11:31   ` Jens Axboe
2024-09-30  4:43     ` Borislav Petkov
2024-09-30 12:27       ` Jens Axboe
2024-09-30 16:16         ` Borislav Petkov
2024-09-30 16:25           ` Jens Axboe
2024-10-09  9:12             ` Borislav Petkov
2024-10-09 11:04               ` Jens Axboe
2024-10-10 13:46                 ` Borislav Petkov
2024-10-10 13:50                   ` Jens Axboe
2024-10-17  2:34                     ` Jens Axboe
2024-10-17 10:02                       ` Borislav Petkov
2024-10-17 14:05                         ` Jens Axboe
2024-10-17 14:13                           ` Borislav Petkov
2024-10-17 14:23                             ` Jens Axboe
2024-10-17 14:27                               ` Borislav Petkov
2024-10-17 14:40                                 ` Jens Axboe
2024-10-18 11:58                                   ` Borislav Petkov
2024-10-18 12:49                                     ` Borislav Petkov
2024-10-18 13:30                                       ` Jens Axboe
2024-10-18 15:51                                         ` Borislav Petkov
2024-10-18 16:45                                           ` Dr. David Alan Gilbert
2024-10-18 16:47                                             ` Jens Axboe
2024-10-18 17:59                                               ` Dr. David Alan Gilbert
2024-10-18 16:48                                           ` Jens Axboe
2024-10-18 17:56                                             ` Borislav Petkov
2024-10-18 18:03                                               ` Jens Axboe
2024-10-18 23:01                                                 ` Jens Axboe
2024-10-19  9:37                                                   ` Borislav Petkov
2024-10-19 13:54                                                     ` Jens Axboe
2024-10-19 23:21                                                       ` Borislav Petkov
2024-10-20  3:24                                                         ` Jens Axboe
2024-10-20 12:18                                                           ` Borislav Petkov
2024-10-21  0:47                                                             ` Jens Axboe
2024-10-21  7:31                                                               ` Borislav Petkov
2024-10-21 17:00                                                                 ` Jens Axboe
2024-10-22 12:05                                                                   ` Borislav Petkov
2024-10-22 12:07                                                                     ` [PATCH 1/2] x86/microcode/AMD: Pay attention to the stepping dynamically Borislav Petkov
2024-10-22 12:08                                                                     ` [PATCH 2/2] x86/microcode/AMD: Split load_microcode_amd() Borislav Petkov
2024-10-22 13:15                                                                       ` Jens Axboe
2024-10-22 14:33                                                                         ` Borislav Petkov
2024-10-22 16:08 ` tip-bot2 for Borislav Petkov (AMD) [this message]
2024-10-22 16:08 ` [tip: x86/urgent] " tip-bot2 for Borislav Petkov (AMD)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=172961330684.1442.17411760938161239553.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®