Skip to content

Commit ed18213

Browse files
allenpaiseffective-light
authored andcommitted
virtio-pmem: Support PCI BAR-relative addresses
Update virtio-pmem to allow for the pmem region to be specified in either guest absolute terms or as a PCI BAR-relative address. This is required to support virtio-pmem in Hyper-V, since Hyper-V only allows PCI devices to operate on PCI memory ranges defined via BARs. Virtio-pmem will check for a shared memory window and use that if found, else it will fallback to using the guest absolute addresses in virtio_pmem_config. This was chosen over defining a new feature bit, since it's similar to how virtio-fs is configured. Signed-off-by: Taylor Stark <[email protected]> Link: https://lore.kernel.org/r/20210715223505.GA29329@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net Signed-off-by: Tyler Hicks <[email protected]> [apais: Forward port to 6.6] Signed-off-by: Allen Pais <[email protected]>
1 parent 3fa1ea3 commit ed18213

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

drivers/nvdimm/virtio_pmem.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
3636
struct virtio_pmem *vpmem;
3737
struct resource res;
3838
int err = 0;
39+
bool have_shm_region;
40+
struct virtio_shm_region pmem_region;
3941

4042
if (!vdev->config->get) {
4143
dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -57,10 +59,20 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
5759
goto out_err;
5860
}
5961

60-
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
61-
start, &vpmem->start);
62-
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
63-
size, &vpmem->size);
62+
/* Retrieve the pmem device's address and size. It may have been supplied
63+
* as a PCI BAR-relative shared memory region, or as a guest absolute address.
64+
*/
65+
have_shm_region = virtio_get_shm_region(vpmem->vdev, &pmem_region,
66+
VIRTIO_PMEM_SHMCAP_ID_PMEM_REGION);
67+
if (have_shm_region) {
68+
vpmem->start = pmem_region.addr;
69+
vpmem->size = pmem_region.len;
70+
} else {
71+
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
72+
start, &vpmem->start);
73+
virtio_cread_le(vpmem->vdev, struct virtio_pmem_config,
74+
size, &vpmem->size);
75+
}
6476

6577
res.start = vpmem->start;
6678
res.end = vpmem->start + vpmem->size - 1;

drivers/nvdimm/virtio_pmem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ struct virtio_pmem {
5050
__u64 size;
5151
};
5252

53+
/* For the id field in virtio_pci_shm_cap */
54+
#define VIRTIO_PMEM_SHMCAP_ID_PMEM_REGION 0
55+
5356
void virtio_pmem_host_ack(struct virtqueue *vq);
5457
int async_pmem_flush(struct nd_region *nd_region, struct bio *bio);
5558
#endif

0 commit comments

Comments
 (0)