From patchwork Wed Mar 27 09:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 1916650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hdlYpStG; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=CaddRTJ+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V4MYK6J98z1yXq for ; Wed, 27 Mar 2024 20:57:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=q0Dvjh2yewc3tZhXFBCBkxpmAup7Qf1wZ+MGKVYZBQ4=; b=hdlYpStGCvrOpK2LMHG2Sq3F5d UQZlKONSdfie1Bd7vfwyWsh8xbH/54yCQjov0tXkW6BZl/2C2xxySMzZDFsn6KYOLCZhWhiFRiSAR qlIqQ/42SSktXrr5epSJzm1df7eVXgiW8QlT0QknT37Iwcy2i3Who4odkvrXRWJRVB5cRUSvbCSsw bCGMLyh+ku3+WD4YMq7G+/lCYinq9VC5z4RRPiuaGwRuRKcZoHjhg3YKt/EZB16e8AN6CGd7pmNhm Uk3fH+id7Na9lCyyLapOrGzNg1uNFmHXL7AKGRbnOkChKpzm0HVbgk8EOLDhMMCMVryWZMbZgOmpk kOWc1r/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpQ2d-00000008IyN-0zQC; Wed, 27 Mar 2024 09:57:55 +0000 Received: from out30-98.freemail.mail.aliyun.com ([115.124.30.98]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpQ2Y-00000008Iuw-2r8a for linux-um@lists.infradead.org; Wed, 27 Mar 2024 09:57:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1711533466; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=q0Dvjh2yewc3tZhXFBCBkxpmAup7Qf1wZ+MGKVYZBQ4=; b=CaddRTJ+AxMBMZymdIEEJ/8yqGKM0tZ+c3RdTCZciBkLpNixpSEndmKk6LbSiPxMxIvewTqOu6pONdsYRivjZVxe6Xd7f4ckbZBjK7C0Em3xO3wOpKfVDEH5Fntihh8lclvIBY1KmxkLk+3yL3tubGDH6OF8PSZLqca/luFcRno= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R571e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=26;SR=0;TI=SMTPD_---0W3OGSvO_1711533463; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W3OGSvO_1711533463) by smtp.aliyun-inc.com; Wed, 27 Mar 2024 17:57:44 +0800 From: Xuan Zhuo To: virtualization@lists.linux.dev Cc: Richard Weinberger , Anton Ivanov , Johannes Berg , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Vadim Pasternak , Bjorn Andersson , Mathieu Poirier , Cornelia Huck , Halil Pasic , Eric Farman , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Xuan Zhuo , linux-um@lists.infradead.org, platform-driver-x86@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH vhost v6 2/6] virtio: remove support for names array entries being null. Date: Wed, 27 Mar 2024 17:57:37 +0800 Message-Id: <20240327095741.88135-3-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240327095741.88135-1-xuanzhuo@linux.alibaba.com> References: <20240327095741.88135-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: f3c3b67ebbb4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_025751_136704_6EC530D8 X-CRM114-Status: GOOD ( 16.19 ) X-Spam-Score: -15.7 (---------------) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: commit 6457f126c888 ("virtio: support reserved vqs") introduced this support. Multiqueue virtio-net use 2N as ctrl vq finally, so the logic doesn't apply. And not one uses this. On the other side, that makes some trouble for us to refactor the find_vqs() params. Content analysis details: (-15.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [115.124.30.98 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -7.5 USER_IN_DEF_SPF_WL From: address is in the default SPF welcome-list 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM welcome-list -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines -0.5 ENV_AND_HDR_SPF_MATCH Env and Hdr From used in default SPF WL Match X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org commit 6457f126c888 ("virtio: support reserved vqs") introduced this support. Multiqueue virtio-net use 2N as ctrl vq finally, so the logic doesn't apply. And not one uses this. On the other side, that makes some trouble for us to refactor the find_vqs() params. So I remove this support. Signed-off-by: Xuan Zhuo Acked-by: Jason Wang --- arch/um/drivers/virtio_uml.c | 8 ++++---- drivers/remoteproc/remoteproc_virtio.c | 11 ++++------- drivers/s390/virtio/virtio_ccw.c | 8 ++++---- drivers/virtio/virtio_mmio.c | 8 ++++---- drivers/virtio/virtio_pci_common.c | 18 +++++++++--------- drivers/virtio/virtio_vdpa.c | 11 ++++------- include/linux/virtio_config.h | 2 +- 7 files changed, 30 insertions(+), 36 deletions(-) diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c index 8adca2000e51..773f9fc4d582 100644 --- a/arch/um/drivers/virtio_uml.c +++ b/arch/um/drivers/virtio_uml.c @@ -1019,8 +1019,8 @@ static int vu_find_vqs(struct virtio_device *vdev, unsigned nvqs, struct irq_affinity *desc) { struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); - int i, queue_idx = 0, rc; struct virtqueue *vq; + int i, rc; /* not supported for now */ if (WARN_ON(nvqs > 64)) @@ -1032,11 +1032,11 @@ static int vu_find_vqs(struct virtio_device *vdev, unsigned nvqs, for (i = 0; i < nvqs; ++i) { if (!names[i]) { - vqs[i] = NULL; - continue; + rc = -EINVAL; + goto error_setup; } - vqs[i] = vu_setup_vq(vdev, queue_idx++, callbacks[i], names[i], + vqs[i] = vu_setup_vq(vdev, i, callbacks[i], names[i], ctx ? ctx[i] : false); if (IS_ERR(vqs[i])) { rc = PTR_ERR(vqs[i]); diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index 83d76915a6ad..8fb5118b6953 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -119,9 +119,6 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, if (id >= ARRAY_SIZE(rvdev->vring)) return ERR_PTR(-EINVAL); - if (!name) - return NULL; - /* Search allocated memory region by name */ mem = rproc_find_carveout_by_name(rproc, "vdev%dvring%d", rvdev->index, id); @@ -187,15 +184,15 @@ static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs, const bool * ctx, struct irq_affinity *desc) { - int i, ret, queue_idx = 0; + int i, ret; for (i = 0; i < nvqs; ++i) { if (!names[i]) { - vqs[i] = NULL; - continue; + ret = -EINVAL; + goto error; } - vqs[i] = rp_find_vq(vdev, queue_idx++, callbacks[i], names[i], + vqs[i] = rp_find_vq(vdev, i, callbacks[i], names[i], ctx ? ctx[i] : false); if (IS_ERR(vqs[i])) { ret = PTR_ERR(vqs[i]); diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c index ac67576301bf..508154705554 100644 --- a/drivers/s390/virtio/virtio_ccw.c +++ b/drivers/s390/virtio/virtio_ccw.c @@ -659,7 +659,7 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs, { struct virtio_ccw_device *vcdev = to_vc_device(vdev); unsigned long *indicatorp = NULL; - int ret, i, queue_idx = 0; + int ret, i; struct ccw1 *ccw; ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); @@ -668,11 +668,11 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs, for (i = 0; i < nvqs; ++i) { if (!names[i]) { - vqs[i] = NULL; - continue; + ret = -EINVAL; + goto out; } - vqs[i] = virtio_ccw_setup_vq(vdev, queue_idx++, callbacks[i], + vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i], ctx ? ctx[i] : false, ccw); if (IS_ERR(vqs[i])) { diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 59892a31cf76..82ee4a288728 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -496,7 +496,7 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned int nvqs, { struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); int irq = platform_get_irq(vm_dev->pdev, 0); - int i, err, queue_idx = 0; + int i, err; if (irq < 0) return irq; @@ -511,11 +511,11 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned int nvqs, for (i = 0; i < nvqs; ++i) { if (!names[i]) { - vqs[i] = NULL; - continue; + vm_del_vqs(vdev); + return -EINVAL; } - vqs[i] = vm_setup_vq(vdev, queue_idx++, callbacks[i], names[i], + vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i], ctx ? ctx[i] : false); if (IS_ERR(vqs[i])) { vm_del_vqs(vdev); diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index b655fccaf773..eda71c6e87ee 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -292,7 +292,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, { struct virtio_pci_device *vp_dev = to_vp_device(vdev); u16 msix_vec; - int i, err, nvectors, allocated_vectors, queue_idx = 0; + int i, err, nvectors, allocated_vectors; vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL); if (!vp_dev->vqs) @@ -302,7 +302,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, /* Best option: one for change interrupt, one per vq. */ nvectors = 1; for (i = 0; i < nvqs; ++i) - if (names[i] && callbacks[i]) + if (callbacks[i]) ++nvectors; } else { /* Second best: one for change, shared for all vqs. */ @@ -318,8 +318,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, allocated_vectors = vp_dev->msix_used_vectors; for (i = 0; i < nvqs; ++i) { if (!names[i]) { - vqs[i] = NULL; - continue; + err = -EINVAL; + goto error_find; } if (!callbacks[i]) @@ -328,7 +328,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, msix_vec = allocated_vectors++; else msix_vec = VP_MSIX_VQ_VECTOR; - vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i], + vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i], ctx ? ctx[i] : false, msix_vec); if (IS_ERR(vqs[i])) { @@ -363,7 +363,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, const char * const names[], const bool *ctx) { struct virtio_pci_device *vp_dev = to_vp_device(vdev); - int i, err, queue_idx = 0; + int i, err; vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL); if (!vp_dev->vqs) @@ -378,10 +378,10 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, vp_dev->per_vq_vectors = false; for (i = 0; i < nvqs; ++i) { if (!names[i]) { - vqs[i] = NULL; - continue; + err = -EINVAL; + goto out_del_vqs; } - vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i], + vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i], ctx ? ctx[i] : false, VIRTIO_MSI_NO_VECTOR); if (IS_ERR(vqs[i])) { diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index e803db0da307..e82cca24d6e6 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -161,9 +161,6 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, bool may_reduce_num = true; int err; - if (!name) - return NULL; - if (index >= vdpa->nvqs) return ERR_PTR(-ENOENT); @@ -370,7 +367,7 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, struct cpumask *masks; struct vdpa_callback cb; bool has_affinity = desc && ops->set_vq_affinity; - int i, err, queue_idx = 0; + int i, err; if (has_affinity) { masks = create_affinity_masks(nvqs, desc ? desc : &default_affd); @@ -380,11 +377,11 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, for (i = 0; i < nvqs; ++i) { if (!names[i]) { - vqs[i] = NULL; - continue; + err = -EINVAL; + goto err_setup_vq; } - vqs[i] = virtio_vdpa_setup_vq(vdev, queue_idx++, + vqs[i] = virtio_vdpa_setup_vq(vdev, i, callbacks[i], names[i], ctx ? ctx[i] : false); if (IS_ERR(vqs[i])) { diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index da9b271b54db..1c79cec258f4 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -56,7 +56,7 @@ typedef void vq_callback_t(struct virtqueue *); * callbacks: array of callbacks, for each virtqueue * include a NULL entry for vqs that do not need a callback * names: array of virtqueue names (mainly for debugging) - * include a NULL entry for vqs unused by driver + * MUST NOT be NULL * Returns 0 on success or error status * @del_vqs: free virtqueues found by find_vqs(). * @synchronize_cbs: synchronize with the virtqueue callbacks (optional)