1 |
From 3149efcdf2c6314420c418dfc94de53bfd076b1f Mon Sep 17 00:00:00 2001 |
2 |
From: Long Li <longli@microsoft.com> |
3 |
Date: Wed, 26 Jan 2022 17:43:34 -0800 |
4 |
Subject: PCI: hv: Fix NUMA node assignment when kernel boots with custom NUMA topology |
5 |
|
6 |
From: Long Li <longli@microsoft.com> |
7 |
|
8 |
commit 3149efcdf2c6314420c418dfc94de53bfd076b1f upstream. |
9 |
|
10 |
When kernel boots with a NUMA topology with some NUMA nodes offline, the PCI |
11 |
driver should only set an online NUMA node on the device. This can happen |
12 |
during KDUMP where some NUMA nodes are not made online by the KDUMP kernel. |
13 |
|
14 |
This patch also fixes the case where kernel is booting with "numa=off". |
15 |
|
16 |
Fixes: 999dd956d838 ("PCI: hv: Add support for protocol 1.3 and support PCI_BUS_RELATIONS2") |
17 |
Signed-off-by: Long Li <longli@microsoft.com> |
18 |
Reviewed-by: Michael Kelley <mikelley@microsoft.com> |
19 |
Tested-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@microsoft.com> |
20 |
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> |
21 |
Link: https://lore.kernel.org/r/1643247814-15184-1-git-send-email-longli@linuxonhyperv.com |
22 |
Signed-off-by: Wei Liu <wei.liu@kernel.org> |
23 |
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
24 |
--- |
25 |
drivers/pci/controller/pci-hyperv.c | 13 +++++++++++-- |
26 |
1 file changed, 11 insertions(+), 2 deletions(-) |
27 |
|
28 |
--- a/drivers/pci/controller/pci-hyperv.c |
29 |
+++ b/drivers/pci/controller/pci-hyperv.c |
30 |
@@ -1899,8 +1899,17 @@ static void hv_pci_assign_numa_node(stru |
31 |
if (!hv_dev) |
32 |
continue; |
33 |
|
34 |
- if (hv_dev->desc.flags & HV_PCI_DEVICE_FLAG_NUMA_AFFINITY) |
35 |
- set_dev_node(&dev->dev, hv_dev->desc.virtual_numa_node); |
36 |
+ if (hv_dev->desc.flags & HV_PCI_DEVICE_FLAG_NUMA_AFFINITY && |
37 |
+ hv_dev->desc.virtual_numa_node < num_possible_nodes()) |
38 |
+ /* |
39 |
+ * The kernel may boot with some NUMA nodes offline |
40 |
+ * (e.g. in a KDUMP kernel) or with NUMA disabled via |
41 |
+ * "numa=off". In those cases, adjust the host provided |
42 |
+ * NUMA node to a valid NUMA node used by the kernel. |
43 |
+ */ |
44 |
+ set_dev_node(&dev->dev, |
45 |
+ numa_map_to_online_node( |
46 |
+ hv_dev->desc.virtual_numa_node)); |
47 |
|
48 |
put_pcichild(hv_dev); |
49 |
} |