Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 222dfb8

Browse files
committed
Merge tag 'x86_misc_for_v6.11_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull misc x86 updates from Borislav Petkov: - Make error checking of AMD SMN accesses more robust in the callers as they're the only ones who can interpret the results properly - The usual cleanups and fixes, left and right * tag 'x86_misc_for_v6.11_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/kmsan: Fix hook for unaligned accesses x86/platform/iosf_mbi: Convert PCIBIOS_* return codes to errnos x86/pci/xen: Fix PCIBIOS_* return code handling x86/pci/intel_mid_pci: Fix PCIBIOS_* return code handling x86/of: Return consistent error type from x86_of_pci_irq_enable() hwmon: (k10temp) Rename _data variable hwmon: (k10temp) Remove unused HAVE_TDIE() macro hwmon: (k10temp) Reduce k10temp_get_ccd_support() parameters hwmon: (k10temp) Define a helper function to read CCD temperature x86/amd_nb: Enhance SMN access error checking hwmon: (k10temp) Check return value of amd_smn_read() EDAC/amd64: Check return value of amd_smn_read() EDAC/amd64: Remove unused register accesses tools/x86/kcpuid: Add missing dir via Makefile x86, arm: Add missing license tag to syscall tables files
2 parents 1d86d35 + bf6ab33 commit 222dfb8

File tree

14 files changed

+136
-73
lines changed

14 files changed

+136
-73
lines changed

arch/arm/tools/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
12
#
23
# Linux system call numbers and entry vectors
34
#

arch/x86/entry/syscalls/syscall_32.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
12
#
23
# 32-bit system call numbers and entry vectors
34
#

arch/x86/entry/syscalls/syscall_64.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
12
#
23
# 64-bit system call numbers and entry vectors
34
#

arch/x86/include/asm/amd_nb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ extern int amd_numa_init(void);
2121
extern int amd_get_subcaches(int);
2222
extern int amd_set_subcaches(int, unsigned long);
2323

24-
extern int amd_smn_read(u16 node, u32 address, u32 *value);
25-
extern int amd_smn_write(u16 node, u32 address, u32 value);
24+
int __must_check amd_smn_read(u16 node, u32 address, u32 *value);
25+
int __must_check amd_smn_write(u16 node, u32 address, u32 value);
2626

2727
struct amd_l3_cache {
2828
unsigned indices;

arch/x86/kernel/amd_nb.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,43 @@ static struct pci_dev *next_northbridge(struct pci_dev *dev,
180180
return dev;
181181
}
182182

183+
/*
184+
* SMN accesses may fail in ways that are difficult to detect here in the called
185+
* functions amd_smn_read() and amd_smn_write(). Therefore, callers must do
186+
* their own checking based on what behavior they expect.
187+
*
188+
* For SMN reads, the returned value may be zero if the register is Read-as-Zero.
189+
* Or it may be a "PCI Error Response", e.g. all 0xFFs. The "PCI Error Response"
190+
* can be checked here, and a proper error code can be returned.
191+
*
192+
* But the Read-as-Zero response cannot be verified here. A value of 0 may be
193+
* correct in some cases, so callers must check that this correct is for the
194+
* register/fields they need.
195+
*
196+
* For SMN writes, success can be determined through a "write and read back"
197+
* However, this is not robust when done here.
198+
*
199+
* Possible issues:
200+
*
201+
* 1) Bits that are "Write-1-to-Clear". In this case, the read value should
202+
* *not* match the write value.
203+
*
204+
* 2) Bits that are "Read-as-Zero"/"Writes-Ignored". This information cannot be
205+
* known here.
206+
*
207+
* 3) Bits that are "Reserved / Set to 1". Ditto above.
208+
*
209+
* Callers of amd_smn_write() should do the "write and read back" check
210+
* themselves, if needed.
211+
*
212+
* For #1, they can see if their target bits got cleared.
213+
*
214+
* For #2 and #3, they can check if their target bits got set as intended.
215+
*
216+
* This matches what is done for RDMSR/WRMSR. As long as there's no #GP, then
217+
* the operation is considered a success, and the caller does their own
218+
* checking.
219+
*/
183220
static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write)
184221
{
185222
struct pci_dev *root;
@@ -202,9 +239,6 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write)
202239

203240
err = (write ? pci_write_config_dword(root, 0x64, *value)
204241
: pci_read_config_dword(root, 0x64, value));
205-
if (err)
206-
pr_warn("Error %s SMN address 0x%x.\n",
207-
(write ? "writing to" : "reading from"), address);
208242

209243
out_unlock:
210244
mutex_unlock(&smn_mutex);
@@ -213,7 +247,7 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write)
213247
return err;
214248
}
215249

216-
int amd_smn_read(u16 node, u32 address, u32 *value)
250+
int __must_check amd_smn_read(u16 node, u32 address, u32 *value)
217251
{
218252
int err = __amd_smn_rw(node, address, value, false);
219253

@@ -226,7 +260,7 @@ int amd_smn_read(u16 node, u32 address, u32 *value)
226260
}
227261
EXPORT_SYMBOL_GPL(amd_smn_read);
228262

229-
int amd_smn_write(u16 node, u32 address, u32 value)
263+
int __must_check amd_smn_write(u16 node, u32 address, u32 value)
230264
{
231265
return __amd_smn_rw(node, address, &value, true);
232266
}

arch/x86/kernel/devicetree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int x86_of_pci_irq_enable(struct pci_dev *dev)
8383

8484
ret = pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
8585
if (ret)
86-
return ret;
86+
return pcibios_err_to_errno(ret);
8787
if (!pin)
8888
return 0;
8989

arch/x86/lib/iomem.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ static __always_inline void rep_movs(void *to, const void *from, size_t n)
2525

2626
static void string_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n)
2727
{
28+
const void *orig_to = to;
29+
const size_t orig_n = n;
30+
2831
if (unlikely(!n))
2932
return;
3033

@@ -39,7 +42,7 @@ static void string_memcpy_fromio(void *to, const volatile void __iomem *from, si
3942
}
4043
rep_movs(to, (const void *)from, n);
4144
/* KMSAN must treat values read from devices as initialized. */
42-
kmsan_unpoison_memory(to, n);
45+
kmsan_unpoison_memory(orig_to, orig_n);
4346
}
4447

4548
static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n)

arch/x86/pci/intel_mid_pci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ static int intel_mid_pci_irq_enable(struct pci_dev *dev)
233233
return 0;
234234

235235
ret = pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &gsi);
236-
if (ret < 0) {
236+
if (ret) {
237237
dev_warn(&dev->dev, "Failed to read interrupt line: %d\n", ret);
238-
return ret;
238+
return pcibios_err_to_errno(ret);
239239
}
240240

241241
id = x86_match_cpu(intel_mid_cpu_ids);

arch/x86/pci/xen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ static int xen_pcifront_enable_irq(struct pci_dev *dev)
3838
u8 gsi;
3939

4040
rc = pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &gsi);
41-
if (rc < 0) {
41+
if (rc) {
4242
dev_warn(&dev->dev, "Xen PCI: failed to read interrupt line: %d\n",
4343
rc);
44-
return rc;
44+
return pcibios_err_to_errno(rc);
4545
}
4646
/* In PV DomU the Xen PCI backend puts the PIRQ in the interrupt line.*/
4747
pirq = gsi;

arch/x86/platform/intel/iosf_mbi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int iosf_mbi_pci_read_mdr(u32 mcrx, u32 mcr, u32 *mdr)
6262

6363
fail_read:
6464
dev_err(&mbi_pdev->dev, "PCI config access failed with %d\n", result);
65-
return result;
65+
return pcibios_err_to_errno(result);
6666
}
6767

6868
static int iosf_mbi_pci_write_mdr(u32 mcrx, u32 mcr, u32 mdr)
@@ -91,7 +91,7 @@ static int iosf_mbi_pci_write_mdr(u32 mcrx, u32 mcr, u32 mdr)
9191

9292
fail_write:
9393
dev_err(&mbi_pdev->dev, "PCI config access failed with %d\n", result);
94-
return result;
94+
return pcibios_err_to_errno(result);
9595
}
9696

9797
int iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr)

0 commit comments

Comments
 (0)