[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/6] util/vfio-helpers: Pass page protections to qemu_vfio_pci
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 1/6] util/vfio-helpers: Pass page protections to qemu_vfio_pci_map_bar() |
Date: |
Tue, 22 Sep 2020 10:38:16 +0200 |
Pages are currently mapped READ/WRITE. To be able to use different
protections, add a new argument to qemu_vfio_pci_map_bar().
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/qemu/vfio-helpers.h | 2 +-
block/nvme.c | 3 ++-
util/vfio-helpers.c | 4 ++--
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h
index 1f057c2b9e4..4491c8e1a6e 100644
--- a/include/qemu/vfio-helpers.h
+++ b/include/qemu/vfio-helpers.h
@@ -22,7 +22,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t
size,
int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s);
void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host);
void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index,
- uint64_t offset, uint64_t size,
+ uint64_t offset, uint64_t size, int prot,
Error **errp);
void qemu_vfio_pci_unmap_bar(QEMUVFIOState *s, int index, void *bar,
uint64_t offset, uint64_t size);
diff --git a/block/nvme.c b/block/nvme.c
index f4f27b6da7d..5a4dc6a722a 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -712,7 +712,8 @@ static int nvme_init(BlockDriverState *bs, const char
*device, int namespace,
goto out;
}
- s->regs = qemu_vfio_pci_map_bar(s->vfio, 0, 0, NVME_BAR_SIZE, errp);
+ s->regs = qemu_vfio_pci_map_bar(s->vfio, 0, 0, NVME_BAR_SIZE,
+ PROT_READ | PROT_WRITE, errp);
if (!s->regs) {
ret = -EINVAL;
goto out;
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 583bdfb36fc..9ac307e3d42 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -146,13 +146,13 @@ static int qemu_vfio_pci_init_bar(QEMUVFIOState *s, int
index, Error **errp)
* Map a PCI bar area.
*/
void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index,
- uint64_t offset, uint64_t size,
+ uint64_t offset, uint64_t size, int prot,
Error **errp)
{
void *p;
assert_bar_index_valid(s, index);
p = mmap(NULL, MIN(size, s->bar_region_info[index].size - offset),
- PROT_READ | PROT_WRITE, MAP_SHARED,
+ prot, MAP_SHARED,
s->device, s->bar_region_info[index].offset + offset);
if (p == MAP_FAILED) {
error_setg_errno(errp, errno, "Failed to map BAR region");
--
2.26.2
- [PATCH v2 0/6] block/nvme: Map doorbells pages write-only, remove magic from nvme_init, Philippe Mathieu-Daudé, 2020/09/22
- [PATCH v2 1/6] util/vfio-helpers: Pass page protections to qemu_vfio_pci_map_bar(),
Philippe Mathieu-Daudé <=
- [PATCH v2 2/6] block/nvme: Map doorbells pages write-only, Philippe Mathieu-Daudé, 2020/09/22
- [PATCH v2 3/6] block/nvme: Reduce I/O registers scope, Philippe Mathieu-Daudé, 2020/09/22
- [PATCH v2 4/6] block/nvme: Drop NVMeRegs structure, directly use NvmeBar, Philippe Mathieu-Daudé, 2020/09/22
- [PATCH v2 5/6] block/nvme: Use register definitions from 'block/nvme.h', Philippe Mathieu-Daudé, 2020/09/22
- [PATCH v2 6/6] block/nvme: Replace magic value by SCALE_MS definition, Philippe Mathieu-Daudé, 2020/09/22
- Re: [PATCH v2 0/6] block/nvme: Map doorbells pages write-only, remove magic from nvme_init, no-reply, 2020/09/22
- Re: [PATCH v2 0/6] block/nvme: Map doorbells pages write-only, remove magic from nvme_init, Fam Zheng, 2020/09/22
- Re: [PATCH v2 0/6] block/nvme: Map doorbells pages write-only, remove magic from nvme_init, Stefan Hajnoczi, 2020/09/25