From nobody Wed Sep 17 01:33:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1671882589; cv=none; d=zohomail.com; s=zohoarc; b=IaE3KQ3xfcq++LFJmGPSCekM5KNWv0dhSEy7laiyAu6Ftntfz8q+UOufOyRy0qpmg43jlLpCizkqpxhZC5g8cUgpxhN0QAN7Vmqho07bVp1ytXclMkmapAeAxJsOM5Xd5mUoXEsCG6f8HO0DrezvTVGBYmJWChygAGAR0YmssKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671882589; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=am5gBJpuS1Y/HmziIkm9HIPRT0OJmZb/12q5aPavsuY=; b=mb1BIfQzHKc+sfA5b//4SoNUZdCWzJyF00U7T++aDSmeJfhDgjU0HQPQC9pBUD8SevphM+m12x0kciqyeYO1AYK9rLfR3i9KhCIo+5iAfCB5NKYgiuhfJFToUfutn06XUSb/m9F3Vu0yCE+99ih+0bst6nFLX7edWWCzzj6IsH4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671882589855889.7034705615002; Sat, 24 Dec 2022 03:49:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p931h-0003D9-Sx; Sat, 24 Dec 2022 06:49:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p931d-0003Ce-MD for qemu-devel@nongnu.org; Sat, 24 Dec 2022 06:49:13 -0500 Received: from szxga08-in.huawei.com ([45.249.212.255]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p931b-0008J7-2B for qemu-devel@nongnu.org; Sat, 24 Dec 2022 06:49:13 -0500 Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NfMjr1FSWz16LdP; Sat, 24 Dec 2022 19:47:44 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi100025.china.huawei.com (7.221.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sat, 24 Dec 2022 19:48:54 +0800 To: , , , CC: , , , , , , , Longpeng Subject: [PATCH 1/2] vdpa-dev: get iova range explicitly Date: Sat, 24 Dec 2022 19:48:47 +0800 Message-ID: <20221224114848.3062-2-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20221224114848.3062-1-longpeng2@huawei.com> References: <20221224114848.3062-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi100025.china.huawei.com (7.221.188.158) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.255; envelope-from=longpeng2@huawei.com; helo=szxga08-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Longpeng(Mike)" From: "Longpeng(Mike)" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671882593135100001 Content-Type: text/plain; charset="utf-8" From: Longpeng In commit a585fad26b ("vdpa: request iova_range only once") we remove GET_IOVA_RANGE form vhost_vdpa_init, the generic vdpa device will start without iova_range populated, so the device won't work. Let's call GET_IOVA_RANGE ioctl explicitly. Fixes: a585fad26b2e6ccc ("vdpa: request iova_range only once") Signed-off-by: Longpeng Acked-by: Jason Wang --- hw/virtio/vdpa-dev.c | 9 +++++++++ hw/virtio/vhost-vdpa.c | 7 +++++++ include/hw/virtio/vhost-vdpa.h | 2 ++ net/vhost-vdpa.c | 8 -------- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index db6ba61152..01b41eb0f1 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -53,6 +53,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, E= rror **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VhostVdpaDevice *v =3D VHOST_VDPA_DEVICE(vdev); + struct vhost_vdpa_iova_range iova_range; uint16_t max_queue_size; struct vhost_virtqueue *vqs; int i, ret; @@ -108,6 +109,14 @@ static void vhost_vdpa_device_realize(DeviceState *dev= , Error **errp) v->dev.backend_features =3D 0; v->started =3D false; =20 + ret =3D vhost_vdpa_get_iova_range(v->vhostfd, &iova_range); + if (ret < 0) { + error_setg(errp, "vhost-vdpa-device: get iova range failed: %s", + strerror(-ret)); + goto free_vqs; + } + v->vdpa.iova_range =3D iova_range; + ret =3D vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, = NULL); if (ret < 0) { error_setg(errp, "vhost-vdpa-device: vhost initialization failed: = %s", diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 870265188a..109a2ee3bf 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -378,6 +378,13 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev= , uint8_t status) return 0; } =20 +int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_r= ange) +{ + int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); + + return ret < 0 ? -errno : 0; +} + /* * The use of this function is for requests that only need to be * applied once. Typically such request occurs at the beginning diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 45b969a311..7997f09a8d 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -51,6 +51,8 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; =20 +int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_r= ange); + int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, hwaddr size, void *vaddr, bool readonly); int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index d36664f33a..ffdc435d19 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -702,14 +702,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, return nc; } =20 -static int vhost_vdpa_get_iova_range(int fd, - struct vhost_vdpa_iova_range *iova_ra= nge) -{ - int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); - - return ret < 0 ? -errno : 0; -} - static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) { int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); --=20 2.23.0 From nobody Wed Sep 17 01:33:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1671882602; cv=none; d=zohomail.com; s=zohoarc; b=YzZCz4cWLqA7N/EBi2xVrXzFBTbR0ZBrn5ddhFPXUo+0CrQsTlXQ2Sv4eMjaweCtxTcrAidu549TTRWezug1IVcCUB+t6iDdHFV8rKEnEtSMrsG9yKxsb0k5JCujsabxiyr3NIrJExhtF00xnqiYGZYNGxMzTvXhvNFj0MhkQ78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671882602; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=toqKeZd/vVAS2/v7+7Bgv1EFcu77Mw5x9mJCX93xdBc=; b=dPXVBfWlTYlJ8uWCG+bcrCtm9jPWF7Fl+dtqJtGW9F7D8xEI7PxAX6FCzGEwy6taOWrd4xEB2zqLMTtaoYOiDmqxncUaC4Q613fUXrDjTEPjSBPxgcre8vnvtmFnXV/KiBBfIdCMQYiZ974ueRJqz9BvjBrN3w2AXDw0NTVRnQQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16718826028406.362083931430334; Sat, 24 Dec 2022 03:50:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p931i-0003F8-7a; Sat, 24 Dec 2022 06:49:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p931f-0003Cu-IY for qemu-devel@nongnu.org; Sat, 24 Dec 2022 06:49:15 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p931d-0008JN-J6 for qemu-devel@nongnu.org; Sat, 24 Dec 2022 06:49:15 -0500 Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NfMk152RnzJqd1; Sat, 24 Dec 2022 19:47:53 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi100025.china.huawei.com (7.221.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sat, 24 Dec 2022 19:48:55 +0800 To: , , , CC: , , , , , , , Longpeng Subject: [PATCH 2/2] vdpa: harden the error path if get_iova_range failed Date: Sat, 24 Dec 2022 19:48:48 +0800 Message-ID: <20221224114848.3062-3-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20221224114848.3062-1-longpeng2@huawei.com> References: <20221224114848.3062-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi100025.china.huawei.com (7.221.188.158) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.188; envelope-from=longpeng2@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Longpeng(Mike)" From: "Longpeng(Mike)" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671882604645100003 Content-Type: text/plain; charset="utf-8" From: Longpeng We should stop if the GET_IOVA_RANGE ioctl failed. Signed-off-by: Longpeng Acked-by: Jason Wang --- net/vhost-vdpa.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index ffdc435d19..e65023d013 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -797,7 +797,13 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, return queue_pairs; } =20 - vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + r =3D vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + if (unlikely(r < 0)) { + error_setg(errp, "vhost-vdpa: get iova range failed: %s", + strerror(-r)); + goto err; + } + if (opts->x_svq) { if (!vhost_vdpa_net_valid_svq_features(features, errp)) { goto err_svq; --=20 2.23.0