From nobody Mon Nov 17 12:05:12 2025 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=1603807083; cv=none; d=zohomail.com; s=zohoarc; b=ho66X4/FLf3dIGBhSvgQZE/qF6m0Pdpe5JZgXtU88AcmtbdmgFYrnEV1xckuTiN/tBF9XqeSRASVXHCZqmt0GS3GlVovd+gMFgTOCJ1sUznh+vW4Gy4IEP3SWgX5Tx/jq162hCwg4t/OXxcVmGCMgQZDsds1rq0nsbRI4+x/HSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603807083; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=xm7DOhBe3iyYOLIHKljm0VOmYGJ+D2G+GQFpjtxbZOQ=; b=mogOjEI0P9z6Ugsz6u329tg7nr25nNk8DB0mIJILEk46EWLYETXPBgK8/3+LC/gozMkrgoA7q+vI62JNJ3Dyrjd8dt5uIh35uhXjiGvtrccwpErcptWgsVmDusZBa2TNmMnfmDUs2jjeTN/fSSBzT0aJfijXUnoCv2B2+1JmqbE= 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 1603807083165965.8527938154635; Tue, 27 Oct 2020 06:58:03 -0700 (PDT) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-501-PbXwevrqOfCNM_qpEgOxyg-1; Tue, 27 Oct 2020 09:58:00 -0400 Received: by mail-ed1-f69.google.com with SMTP id dc23so710399edb.13 for ; Tue, 27 Oct 2020 06:58:00 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id e2sm1095439ejd.81.2020.10.27.06.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 06:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603807082; 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=xm7DOhBe3iyYOLIHKljm0VOmYGJ+D2G+GQFpjtxbZOQ=; b=bJn7MbySmtxe+wuaAGW5TiCqfTDIzmKNYjEaFW3yUsjjb0QGeZ96ARE97qPqQv5XHEtLu4 eELoZkyvG2fU93UsseU6vOfs0y6xePDoscbtR9ic2+JyaQhUxmeHfg/uKPTJHdxU8ZNJHn vbsg+LW8unllx+9666u+wlV6UDOBd5A= X-MC-Unique: PbXwevrqOfCNM_qpEgOxyg-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=xm7DOhBe3iyYOLIHKljm0VOmYGJ+D2G+GQFpjtxbZOQ=; b=PBCtaXZoFLxQqJYtBh8gIH/sXoFfZy8HW5P8nhU9n5j7LQ8rmK7a5IwtK7gqLhSp44 49x+HABkZJ5VqUoD+A1z/Kqp2QiMZQLoXAVSOagroZnnbdYWLiUSUwKU4jhTjw3K7BZN 8go1BKxHqRJlNVjIXf+7+Iun38eBte/p6ViBppIGT2RomTUs3S4mmNgFiPbb+d5PjXb4 jllqIzkiMTGSF+m2a3Vc7nymJefBSDOWdVrGluLSHEjKALCBAQjTAMb0EkpyAB2/FShY UdSR5p4pw/VFmmXlleaZ3wB8t2XATxXCIS3+9lLTThlaZD7SM+thklqRGbu7W6EtH038 DZvQ== X-Gm-Message-State: AOAM530d3E3JxneLeUZMS/x4xt7Av/PEYL4BPBU24VgeVDyG93o5PzXf iuUWFss7yIEr2EmiU9Bgr3voryI/igu9I2hijFjDv9sNSD5B/Z8VZWEYFZGcWfwaZFUhNIsLvdk aSeQ1Z9J/GGuNBw== X-Received: by 2002:a17:906:2dc7:: with SMTP id h7mr2638981eji.546.1603807079519; Tue, 27 Oct 2020 06:57:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWKxF53GuI7DB3LBnIlx/SCjKP14ed38wRlih8sAJZ/8YOthHVUwVuFSqQQTeiaC3xnaIDFw== X-Received: by 2002:a17:906:2dc7:: with SMTP id h7mr2638968eji.546.1603807079354; Tue, 27 Oct 2020 06:57:59 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Klaus Jensen , qemu-block@nongnu.org, Fam Zheng , Keith Busch , Eric Auger , Stefan Hajnoczi , Kevin Wolf , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 24/25] block/nvme: Align iov's va and size on host page size Date: Tue, 27 Oct 2020 14:55:46 +0100 Message-Id: <20201027135547.374946-25-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201027135547.374946-1-philmd@redhat.com> References: <20201027135547.374946-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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e3626045565..c1c52bae44f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1018,11 +1018,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); @@ -1166,8 +1167,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; @@ -1183,7 +1185,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); @@ -1193,7 +1195,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