All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/CPU/AMD: Ignore invalid reset reason value
@ 2025-07-23 20:07 Yazen Ghannam
  2025-07-24  4:25 ` Borislav Petkov
  2025-08-13 19:32 ` Yazen Ghannam
  0 siblings, 2 replies; 3+ messages in thread
From: Yazen Ghannam @ 2025-07-23 20:07 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, Yazen Ghannam, Libing He, Mario Limonciello,
	David Arcari

The reset reason value may be "all bits set", e.g. 0xFFFFFFFF. This is a
commonly used error response from hardware. This may occur due to a real
hardware issue or when running in a VM.

The user will see all reset reasons reported in this case.

Return early if running in a VM as this register is not emulated.

Check for an error response value and return early to avoid decoding
invalid data.

Also, adjust the data variable type to match the hardware register size.

Fixes: ab8131028710 ("x86/CPU/AMD: Print the reason for the last reset")
Reported-by: Libing He <libhe@redhat.com>
Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Cc: David Arcari <darcari@redhat.com>
Cc: stable@vger.kernel.org
---
Link:
https://lore.kernel.org/r/20250721181155.3536023-1-yazen.ghannam@amd.com

v1->v2:
* Include Reviewed-by tag from Mario.
* Include hypervisor check suggested by Boris.

 arch/x86/kernel/cpu/amd.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 50f88fe51816..7a10fe426104 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -1274,10 +1274,13 @@ static const char * const s5_reset_reason_txt[] = {
 
 static __init int print_s5_reset_status_mmio(void)
 {
-	unsigned long value;
 	void __iomem *addr;
+	u32 value;
 	int i;
 
+	if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
+		return 0;
+
 	if (!cpu_feature_enabled(X86_FEATURE_ZEN))
 		return 0;
 
@@ -1288,12 +1291,16 @@ static __init int print_s5_reset_status_mmio(void)
 	value = ioread32(addr);
 	iounmap(addr);
 
+	/* Value with "all bits set" is an error response and should be ignored. */
+	if (value == U32_MAX)
+		return 0;
+
 	for (i = 0; i < ARRAY_SIZE(s5_reset_reason_txt); i++) {
 		if (!(value & BIT(i)))
 			continue;
 
 		if (s5_reset_reason_txt[i]) {
-			pr_info("x86/amd: Previous system reset reason [0x%08lx]: %s\n",
+			pr_info("x86/amd: Previous system reset reason [0x%08x]: %s\n",
 				value, s5_reset_reason_txt[i]);
 		}
 	}

base-commit: 65f55a30176662ee37fe18b47430ee30b57bfc98
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86/CPU/AMD: Ignore invalid reset reason value
  2025-07-23 20:07 [PATCH v2] x86/CPU/AMD: Ignore invalid reset reason value Yazen Ghannam
@ 2025-07-24  4:25 ` Borislav Petkov
  2025-08-13 19:32 ` Yazen Ghannam
  1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2025-07-24  4:25 UTC (permalink / raw)
  To: Yazen Ghannam, x86
  Cc: linux-kernel, Libing He, Mario Limonciello, David Arcari

On July 23, 2025 11:07:52 PM GMT+03:00, Yazen Ghannam <yazen.ghannam@amd.com> wrote:
>The reset reason value may be "all bits set", e.g. 0xFFFFFFFF. This is a
>commonly used error response from hardware. This may occur due to a real
>hardware issue or when running in a VM.
>
>The user will see all reset reasons reported in this case.
>
>Return early if running in a VM as this register is not emulated.
>
>Check for an error response value and return early to avoid decoding
>invalid data.
>
>Also, adjust the data variable type to match the hardware register size.
>
>Fixes: ab8131028710 ("x86/CPU/AMD: Print the reason for the last reset")
>Reported-by: Libing He <libhe@redhat.com>
>Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
>Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
>Cc: David Arcari <darcari@redhat.com>
>Cc: stable@vger.kernel.org
>---
>Link:
>https://lore.kernel.org/r/20250721181155.3536023-1-yazen.ghannam@amd.com
>
>v1->v2:
>* Include Reviewed-by tag from Mario.
>* Include hypervisor check suggested by Boris.
>
> arch/x86/kernel/cpu/amd.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
>diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
>index 50f88fe51816..7a10fe426104 100644
>--- a/arch/x86/kernel/cpu/amd.c
>+++ b/arch/x86/kernel/cpu/amd.c
>@@ -1274,10 +1274,13 @@ static const char * const s5_reset_reason_txt[] = {
> 
> static __init int print_s5_reset_status_mmio(void)
> {
>-	unsigned long value;
> 	void __iomem *addr;
>+	u32 value;
> 	int i;
> 
>+	if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
>+		return 0;
>+
> 	if (!cpu_feature_enabled(X86_FEATURE_ZEN))
> 		return 0;
> 
>@@ -1288,12 +1291,16 @@ static __init int print_s5_reset_status_mmio(void)
> 	value = ioread32(addr);
> 	iounmap(addr);
> 
>+	/* Value with "all bits set" is an error response and should be ignored. */
>+	if (value == U32_MAX)
>+		return 0;
>+
> 	for (i = 0; i < ARRAY_SIZE(s5_reset_reason_txt); i++) {
> 		if (!(value & BIT(i)))
> 			continue;
> 
> 		if (s5_reset_reason_txt[i]) {
>-			pr_info("x86/amd: Previous system reset reason [0x%08lx]: %s\n",
>+			pr_info("x86/amd: Previous system reset reason [0x%08x]: %s\n",
> 				value, s5_reset_reason_txt[i]);
> 		}
> 	}
>
>base-commit: 65f55a30176662ee37fe18b47430ee30b57bfc98

Ack.
-- 
Sent from a small device: formatting sucks and brevity is inevitable.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86/CPU/AMD: Ignore invalid reset reason value
  2025-07-23 20:07 [PATCH v2] x86/CPU/AMD: Ignore invalid reset reason value Yazen Ghannam
  2025-07-24  4:25 ` Borislav Petkov
@ 2025-08-13 19:32 ` Yazen Ghannam
  1 sibling, 0 replies; 3+ messages in thread
From: Yazen Ghannam @ 2025-08-13 19:32 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, Libing He, Mario Limonciello, David Arcari

On Wed, Jul 23, 2025 at 08:07:52PM +0000, Yazen Ghannam wrote:
> The reset reason value may be "all bits set", e.g. 0xFFFFFFFF. This is a
> commonly used error response from hardware. This may occur due to a real
> hardware issue or when running in a VM.
> 
> The user will see all reset reasons reported in this case.
> 
> Return early if running in a VM as this register is not emulated.
> 
> Check for an error response value and return early to avoid decoding
> invalid data.
> 
> Also, adjust the data variable type to match the hardware register size.
> 
> Fixes: ab8131028710 ("x86/CPU/AMD: Print the reason for the last reset")
> Reported-by: Libing He <libhe@redhat.com>
> Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> Cc: David Arcari <darcari@redhat.com>
> Cc: stable@vger.kernel.org
> ---

Hi all,

Any more feedback on this?

Thanks,
Yazen

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-13 19:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 20:07 [PATCH v2] x86/CPU/AMD: Ignore invalid reset reason value Yazen Ghannam
2025-07-24  4:25 ` Borislav Petkov
2025-08-13 19:32 ` Yazen Ghannam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.