[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH-for-5.2 v2 22/25] block/nvme: Align iov's va and size on host pag
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH-for-5.2 v2 22/25] block/nvme: Align iov's va and size on host page size |
Date: |
Thu, 29 Oct 2020 10:33:03 +0100 |
From: Eric Auger <eric.auger@redhat.com>
Make sure iov's va and size are properly aligned on the
host page size.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@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 | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index e807dd56dfe..f1e2fd34cdf 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -1015,11 +1015,12 @@ static coroutine_fn int
nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd,
for (i = 0; i < qiov->niov; ++i) {
bool retry = true;
uint64_t iova;
+ size_t len = QEMU_ALIGN_UP(qiov->iov[i].iov_len,
+ qemu_real_host_page_size);
try_map:
r = qemu_vfio_dma_map(s->vfio,
qiov->iov[i].iov_base,
- qiov->iov[i].iov_len,
- true, &iova);
+ len, true, &iova);
if (r == -ENOMEM && retry) {
retry = false;
trace_nvme_dma_flush_queue_wait(s);
@@ -1163,8 +1164,9 @@ static inline bool nvme_qiov_aligned(BlockDriverState *bs,
BDRVNVMeState *s = bs->opaque;
for (i = 0; i < qiov->niov; ++i) {
- if (!QEMU_PTR_IS_ALIGNED(qiov->iov[i].iov_base, s->page_size) ||
- !QEMU_IS_ALIGNED(qiov->iov[i].iov_len, s->page_size)) {
+ if (!QEMU_PTR_IS_ALIGNED(qiov->iov[i].iov_base,
+ qemu_real_host_page_size) ||
+ !QEMU_IS_ALIGNED(qiov->iov[i].iov_len, qemu_real_host_page_size)) {
trace_nvme_qiov_unaligned(qiov, i, qiov->iov[i].iov_base,
qiov->iov[i].iov_len, s->page_size);
return false;
@@ -1180,7 +1182,7 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t
offset, uint64_t bytes,
int r;
uint8_t *buf = NULL;
QEMUIOVector local_qiov;
-
+ size_t len = QEMU_ALIGN_UP(bytes, qemu_real_host_page_size);
assert(QEMU_IS_ALIGNED(offset, s->page_size));
assert(QEMU_IS_ALIGNED(bytes, s->page_size));
assert(bytes <= s->max_transfer);
@@ -1190,7 +1192,7 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t
offset, uint64_t bytes,
}
s->stats.unaligned_accesses++;
trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write);
- buf = qemu_try_memalign(s->page_size, bytes);
+ buf = qemu_try_memalign(qemu_real_host_page_size, len);
if (!buf) {
return -ENOMEM;
--
2.26.2
- [PATCH-for-5.2 v2 13/25] block/nvme: Use definitions instead of magic values in add_io_queue(), (continued)
- [PATCH-for-5.2 v2 13/25] block/nvme: Use definitions instead of magic values in add_io_queue(), Philippe Mathieu-Daudé, 2020/10/29
- [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é <=
- [PATCH-for-5.2 v2 23/25] block/nvme: Fix use of write-only doorbells page on Aarch64 arch, Philippe Mathieu-Daudé, 2020/10/29
- [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