|
| 1 | +From 348008f0043cd5ba915cfde44027c59bdb8a6791 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Yazen Ghannam <yazen.ghannam@amd.com> |
| 3 | +Date: Mon, 3 Apr 2023 16:42:44 +0000 |
| 4 | +Subject: x86/amd_nb: Check for invalid SMN reads |
| 5 | + |
| 6 | +commit c625dabbf1c4a8e77e4734014f2fde7aa9071a1f upstream. |
| 7 | + |
| 8 | +AMD Zen-based systems use a System Management Network (SMN) that |
| 9 | +provides access to implementation-specific registers. |
| 10 | + |
| 11 | +SMN accesses are done indirectly through an index/data pair in PCI |
| 12 | +config space. The PCI config access may fail and return an error code. |
| 13 | +This would prevent the "read" value from being updated. |
| 14 | + |
| 15 | +However, the PCI config access may succeed, but the return value may be |
| 16 | +invalid. This is in similar fashion to PCI bad reads, i.e. return all |
| 17 | +bits set. |
| 18 | + |
| 19 | +Most systems will return 0 for SMN addresses that are not accessible. |
| 20 | +This is in line with AMD convention that unavailable registers are |
| 21 | +Read-as-Zero/Writes-Ignored. |
| 22 | + |
| 23 | +However, some systems will return a "PCI Error Response" instead. This |
| 24 | +value, along with an error code of 0 from the PCI config access, will |
| 25 | +confuse callers of the amd_smn_read() function. |
| 26 | + |
| 27 | +Check for this condition, clear the return value, and set a proper error |
| 28 | +code. |
| 29 | + |
| 30 | +Fixes: ddfe43cdc0da ("x86/amd_nb: Add SMN and Indirect Data Fabric access for AMD Fam17h") |
| 31 | +Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> |
| 32 | +Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> |
| 33 | +Cc: stable@vger.kernel.org |
| 34 | +Link: https://lore.kernel.org/r/20230403164244.471141-1-yazen.ghannam@amd.com |
| 35 | +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| 36 | +--- |
| 37 | + arch/x86/kernel/amd_nb.c | 9 ++++++++- |
| 38 | + 1 file changed, 8 insertions(+), 1 deletion(-) |
| 39 | + |
| 40 | +diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c |
| 41 | +index cab4d8b1535d61..6f1cc7f1b202a6 100644 |
| 42 | +--- a/arch/x86/kernel/amd_nb.c |
| 43 | ++++ b/arch/x86/kernel/amd_nb.c |
| 44 | +@@ -209,7 +209,14 @@ out: |
| 45 | + |
| 46 | + int amd_smn_read(u16 node, u32 address, u32 *value) |
| 47 | + { |
| 48 | +- return __amd_smn_rw(node, address, value, false); |
| 49 | ++ int err = __amd_smn_rw(node, address, value, false); |
| 50 | ++ |
| 51 | ++ if (PCI_POSSIBLE_ERROR(*value)) { |
| 52 | ++ err = -ENODEV; |
| 53 | ++ *value = 0; |
| 54 | ++ } |
| 55 | ++ |
| 56 | ++ return err; |
| 57 | + } |
| 58 | + EXPORT_SYMBOL_GPL(amd_smn_read); |
| 59 | + |
| 60 | +-- |
| 61 | +cgit 1.2.3-korg |
| 62 | + |
0 commit comments