From nobody Mon Feb 9 08:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603964113; cv=none; d=zohomail.com; s=zohoarc; b=l5pKQD07g6tNLMr+XWBKtWCIolGbmPA88FxrwORjT4dbfIepA14ehGP6E5FKqaSFvZwp13rMp3m2jBbWs/uDU9txUVTJy21esSaJrCiTSqxyJTJIGRnBn1vDTikemK1GSAYRF8xcWe3uPKTXrRgHvl8kIP506Q29EBj/xmG1uFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603964113; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=8ebpGRl8V/SQHWtFmQyZ24PuNhlns0+asaugWNkot24=; b=mSovl1B/3TUDX8qc6snKK0FxJRFNuXt85B3HaXKjUAOtdsjbu3qW0Iu9LW/3iu66XKPVGPD8OpvlmFof70LJAElmdC1HmY2yD42oOot+2EYvgbgMuSK64AKYIJXb/PcFxbFiAN5rZ3Xr+f6ahLCOFUsIcbzVUdYqZ3LvBvkYbl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603964113250606.3024915816235; Thu, 29 Oct 2020 02:35:13 -0700 (PDT) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-HXKRTteoM3OMqP-vhgkRfQ-1; Thu, 29 Oct 2020 05:35:08 -0400 Received: by mail-ej1-f70.google.com with SMTP id c10so937143ejm.15 for ; Thu, 29 Oct 2020 02:35:08 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (234.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.234]) by smtp.gmail.com with ESMTPSA id ds7sm1162895ejc.83.2020.10.29.02.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 02:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603964112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ebpGRl8V/SQHWtFmQyZ24PuNhlns0+asaugWNkot24=; b=Kgkf2rfK3sFV/OjpH2KyNz1+Ukr4V/3xx6aHUsRAB9O1fItjcuWC0Z274Gg/IyqIsdXmOf Z95ehdqmDKVq8kk5smu/PONmX2rnIn2zYgciKv0bsE/0xr9G/d4kIsfKaMrWeeoySPAE0P lbJ0QY2RmbXJ6BcadBzz7KTMh0/SxdA= X-MC-Unique: HXKRTteoM3OMqP-vhgkRfQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ebpGRl8V/SQHWtFmQyZ24PuNhlns0+asaugWNkot24=; b=SIeKpYH8uzUIqAeeA9WFPvkrlT/ML7eaw3uS7yLctSI4oXa5yjMB9n5iQ4U8ozzlHN JrHL7JrrZDEU0nCb8NmgTWfRlhFh6of7b3B8gsAgUNajQfKzHWIaqzJ4F/qu8cclWVb9 D55Vdssu9yPA+iGX9YKBAtoWdMCJ/glPCCar9aTCb68PPAFeFSYwuAUYk01k1+ybCtti 7dAAweS/uOFBeY5pAYp6/KAtZYMDYRXHLkRfGkW/z0XU2s3uXQ+P/rRjllegrBap0fsu GH/DjAKlBSZ6m1lQPsqWGcL/KV7QT9tN3J3Pm2AFWHz6ucncE1pSi5zSBkQ8QWttgM0x mc4A== X-Gm-Message-State: AOAM533hyQN2iyLF4NIiVayWH7VX7frmrcvuD6dLvCv0hNvUafCeV/KJ Gf+x0y2ZzOe8YRYHiffOWKv27zLGBPtimgKBxK5HI3w6hz3odidOcO4aeuDHMfa3KR4Nx+YV80y fBuaY0ShrMH2Fpg== X-Received: by 2002:a05:6402:1004:: with SMTP id c4mr3001091edu.149.1603964107186; Thu, 29 Oct 2020 02:35:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydv1/hzCveV0yJGEQIelPM8p1TF/vx6Lv0Ya7VjwzOzBrXzGv+iGdES7KEf2jLrzvvLRSAlA== X-Received: by 2002:a05:6402:1004:: with SMTP id c4mr3001077edu.149.1603964107030; Thu, 29 Oct 2020 02:35:07 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Klaus Jensen , Eric Auger , Max Reitz , Fam Zheng , Keith Busch , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Message-Id: <20201029093306.1063879-23-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029093306.1063879-1-philmd@redhat.com> References: <20201029093306.1063879-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) From: Eric Auger Make sure iov's va and size are properly aligned on the host page size. Signed-off-by: Eric Auger Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi Tested-by: Eric Auger Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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(BlockDriv= erState *bs, NvmeCmd *cmd, for (i =3D 0; i < qiov->niov; ++i) { bool retry =3D true; uint64_t iova; + size_t len =3D QEMU_ALIGN_UP(qiov->iov[i].iov_len, + qemu_real_host_page_size); try_map: r =3D qemu_vfio_dma_map(s->vfio, qiov->iov[i].iov_base, - qiov->iov[i].iov_len, - true, &iova); + len, true, &iova); if (r =3D=3D -ENOMEM && retry) { retry =3D false; trace_nvme_dma_flush_queue_wait(s); @@ -1163,8 +1164,9 @@ static inline bool nvme_qiov_aligned(BlockDriverState= *bs, BDRVNVMeState *s =3D bs->opaque; =20 for (i =3D 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_siz= e)) { 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 =3D NULL; QEMUIOVector local_qiov; - + size_t len =3D 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 <=3D 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 =3D qemu_try_memalign(s->page_size, bytes); + buf =3D qemu_try_memalign(qemu_real_host_page_size, len); =20 if (!buf) { return -ENOMEM; --=20 2.26.2