Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virtio_pmem: populate numa information

Compute the numa information for a virtio_pmem device from the memory
range of the device. Previously, the target_node was always 0 since
the ndr_desc.target_node field was never explicitly set. The code for
computing the numa node is taken from cxl_pmem_region_probe in
drivers/cxl/pmem.c.

Signed-off-by: Michael Sammler <sammler@google.com>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
Tested-by: Mina Almasry <almasrymina@google.com>
Message-Id: <20221115214036.1571015-1-sammler@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Michael Sammler and committed by
Michael S. Tsirkin
d5ff73bb 0e84f918

+9 -2
+9 -2
drivers/nvdimm/virtio_pmem.c
··· 32 32 static int virtio_pmem_probe(struct virtio_device *vdev) 33 33 { 34 34 struct nd_region_desc ndr_desc = {}; 35 - int nid = dev_to_node(&vdev->dev); 36 35 struct nd_region *nd_region; 37 36 struct virtio_pmem *vpmem; 38 37 struct resource res; ··· 78 79 dev_set_drvdata(&vdev->dev, vpmem->nvdimm_bus); 79 80 80 81 ndr_desc.res = &res; 81 - ndr_desc.numa_node = nid; 82 + 83 + ndr_desc.numa_node = memory_add_physaddr_to_nid(res.start); 84 + ndr_desc.target_node = phys_to_target_node(res.start); 85 + if (ndr_desc.target_node == NUMA_NO_NODE) { 86 + ndr_desc.target_node = ndr_desc.numa_node; 87 + dev_dbg(&vdev->dev, "changing target node from %d to %d", 88 + NUMA_NO_NODE, ndr_desc.target_node); 89 + } 90 + 82 91 ndr_desc.flush = async_pmem_flush; 83 92 ndr_desc.provider_data = vdev; 84 93 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);