Skip to content

Commit 171d82c

Browse files
Taylor Starktyhicks
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]>
1 parent 2c85ebc commit 171d82c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

drivers/nvdimm/virtio_pmem.c

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

4143
if (!vdev->config->get) {
4244
dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -58,10 +60,21 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
5860
goto out_err;
5961
}
6062

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

6679
res.start = vpmem->start;
6780
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)