[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH-for-5.2 v2 23/25] block/nvme: Fix use of write-only doorbells pag
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH-for-5.2 v2 23/25] block/nvme: Fix use of write-only doorbells page on Aarch64 arch |
Date: |
Thu, 29 Oct 2020 10:33:04 +0100 |
qemu_vfio_pci_map_bar() calls mmap(), and mmap(2) states:
'offset' must be a multiple of the page size as returned
by sysconf(_SC_PAGE_SIZE).
In commit f68453237b9 we started to use an offset of 4K which
broke this contract on Aarch64 arch.
Fix by mapping at offset 0, and and accessing doorbells at offset=4K.
Fixes: f68453237b9 ("block/nvme: Map doorbells pages write-only")
Reported-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index f1e2fd34cdf..c8ef69cbb28 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -94,6 +94,7 @@ typedef struct {
struct BDRVNVMeState {
AioContext *aio_context;
QEMUVFIOState *vfio;
+ void *bar0_wo_map;
/* Memory mapped registers */
volatile struct {
uint32_t sq_tail;
@@ -777,8 +778,10 @@ static int nvme_init(BlockDriverState *bs, const char
*device, int namespace,
}
}
- s->doorbells = qemu_vfio_pci_map_bar(s->vfio, 0, sizeof(NvmeBar),
- NVME_DOORBELL_SIZE, PROT_WRITE, errp);
+ s->bar0_wo_map = qemu_vfio_pci_map_bar(s->vfio, 0, 0,
+ sizeof(NvmeBar) +
NVME_DOORBELL_SIZE,
+ PROT_WRITE, errp);
+ s->doorbells = (void *)((uintptr_t)s->bar0_wo_map + sizeof(NvmeBar));
if (!s->doorbells) {
ret = -EINVAL;
goto out;
@@ -910,8 +913,8 @@ static void nvme_close(BlockDriverState *bs)
&s->irq_notifier[MSIX_SHARED_IRQ_IDX],
false, NULL, NULL);
event_notifier_cleanup(&s->irq_notifier[MSIX_SHARED_IRQ_IDX]);
- qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->doorbells,
- sizeof(NvmeBar), NVME_DOORBELL_SIZE);
+ qemu_vfio_pci_unmap_bar(s->vfio, 0, s->bar0_wo_map,
+ 0, sizeof(NvmeBar) + NVME_DOORBELL_SIZE);
qemu_vfio_close(s->vfio);
g_free(s->device);
--
2.26.2
- [PATCH-for-5.2 v2 14/25] block/nvme: Correctly initialize Admin Queue Attributes, (continued)
- [PATCH-for-5.2 v2 14/25] block/nvme: Correctly initialize Admin Queue Attributes, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 15/25] block/nvme: Simplify ADMIN queue access, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 17/25] block/nvme: Set request_alignment at initialization, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 16/25] block/nvme: Simplify nvme_cmd_sync(), Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 18/25] block/nvme: Correct minimum device page size, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 19/25] block/nvme: Change size and alignment of IDENTIFY response buffer, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 20/25] block/nvme: Change size and alignment of queue, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 21/25] block/nvme: Change size and alignment of prp_list_pages, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 22/25] block/nvme: Align iov's va and size on host page size, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-5.2 v2 23/25] block/nvme: Fix use of write-only doorbells page on Aarch64 arch,
Philippe Mathieu-Daudé <=
- [PATCH-for-5.2 v2 24/25] block/nvme: Fix nvme_submit_command() on big-endian host, Philippe Mathieu-Daudé, 2020/10/29
- [PATCH-for-6.0 v2 25/25] block/nvme: Simplify Completion Queue Command Identifier field use, Philippe Mathieu-Daudé, 2020/10/29