From patchwork Tue Jan 30 11:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 1892788 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=0zcULMK7; 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=Cf8lajC8; 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 4TPNZg29HKz23gc for ; Tue, 30 Jan 2024 22:42:51 +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=5y28Ihr+AJzyTWf01VNyD6gpI2+tIOJhKvCZ6gW/9DA=; b=0zcULMK70/chGsZvZvCom3DRZp zd1wP3OUHiTpVT50cQLrbDi8uKepfyFQAHUe30F0eln5HGthHKhMBWMre1ZtqEEnP4hKeIEZfth5w wDKISiBQQlTVb8SJdm1v0v4Bqk0kg5yEs1im+LjaP4uaLBSZ56igOf+YXqIlTxfPwjRitKmqypcjw VysXOv3NAnpfITVyiSCEd5+B58O+Pue1iHwd1KvuVd1CHSnwoIoMLDuMtcorjmM1Owa1adejk1+Dr mThqlbl2KsfuO0s4JQ+wUnORdbyH8JYqo8C06npyydzEx4vWDZvA9AMwg27uQzneOd2N49Fyen/n8 yjJLT7zQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rUmVs-0000000GWDy-42vA; Tue, 30 Jan 2024 11:42:48 +0000 Received: from out30-100.freemail.mail.aliyun.com ([115.124.30.100]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rUmVp-0000000GW9O-0onY for linux-um@lists.infradead.org; Tue, 30 Jan 2024 11:42:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1706614963; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=5y28Ihr+AJzyTWf01VNyD6gpI2+tIOJhKvCZ6gW/9DA=; b=Cf8lajC8ACJwvmXGaofg5bvKXb0H9bbJhrknl+ez1C+3ksaCeX1C0Gx+WSAhvKwSrSvKsyUTH7NK5tBDx4sjum0kduljtkBlu/YWTOV4zr8wf3OKimev39JYgNUUaeV7XgPiMZoE//XSBKNBEXUj8ZdBJX2gFKxcEkaIzunQDmo= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R541e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=37;SR=0;TI=SMTPD_---0W.g.laf_1706614959; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W.g.laf_1706614959) by smtp.aliyun-inc.com; Tue, 30 Jan 2024 19:42:40 +0800 From: Xuan Zhuo To: virtualization@lists.linux.dev Cc: Richard Weinberger , Anton Ivanov , Johannes Berg , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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 , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Benjamin Berg , Yang Li , linux-um@lists.infradead.org, netdev@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH vhost 09/17] virtio_ring: reuse the parameter struct of find_vqs() Date: Tue, 30 Jan 2024 19:42:16 +0800 Message-Id: <20240130114224.86536-10-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240130114224.86536-1-xuanzhuo@linux.alibaba.com> References: <20240130114224.86536-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: 239d1d475be4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240130_034245_539327_D857588E X-CRM114-Status: GOOD ( 14.34 ) 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: As the refactor of find_vqs()/vring_new_virtqueue(), the cfg/tp_cfg are passed to vring. This patch refactors the vring by this structure. This can simplify the code. Signed-off-by: Xuan Zhuo --- drivers/virtio/virtio_ring.c | 162 ++++++++++++ 1 file changed, 53 insertions(+), 109 deletions(-) Content analysis details: (-15.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_SPF_WL From: address is in the default SPF welcome-list -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM welcome-list -0.0 SPF_PASS SPF: sender matches SPF record -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.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.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [115.124.30.100 listed in list.dnswl.org] 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 -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 As the refactor of find_vqs()/vring_new_virtqueue(), the cfg/tp_cfg are passed to vring. This patch refactors the vring by this structure. This can simplify the code. Signed-off-by: Xuan Zhuo --- drivers/virtio/virtio_ring.c | 162 ++++++++++++----------------------- 1 file changed, 53 insertions(+), 109 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index d87b80a5b9df..769ec6360d7f 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -237,15 +237,11 @@ struct vring_virtqueue { #endif }; -static struct virtqueue *__vring_new_virtqueue(unsigned int index, +static struct virtqueue *__vring_new_virtqueue(struct virtio_device *vdev, + unsigned int index, struct vring_virtqueue_split *vring_split, - struct virtio_device *vdev, - bool weak_barriers, - bool context, - bool (*notify)(struct virtqueue *), - void (*callback)(struct virtqueue *), - const char *name, - struct device *dma_dev); + struct transport_vq_config *tp_cfg, + struct virtio_vq_config *cfg); static struct vring_desc_extra *vring_alloc_desc_extra(unsigned int num); static void vring_free(struct virtqueue *_vq); @@ -254,6 +250,8 @@ static void vring_free(struct virtqueue *_vq); */ #define to_vvq(_vq) container_of_const(_vq, struct vring_virtqueue, vq) +#define cfg_vq_val(cfg, key) (cfg->key[cfg->cfg_idx]) +#define cfg_vq_get(cfg, key) (cfg->key ? cfg_vq_val(cfg, key) : false) static bool virtqueue_use_indirect(const struct vring_virtqueue *vq, unsigned int total_sg) @@ -1184,32 +1182,29 @@ static int vring_alloc_queue_split(struct vring_virtqueue_split *vring_split, return 0; } -static struct virtqueue *vring_create_virtqueue_split( - unsigned int index, - unsigned int num, - unsigned int vring_align, - struct virtio_device *vdev, - bool weak_barriers, - bool may_reduce_num, - bool context, - bool (*notify)(struct virtqueue *), - void (*callback)(struct virtqueue *), - const char *name, - struct device *dma_dev) +static struct virtqueue *vring_create_virtqueue_split(struct virtio_device *vdev, + unsigned int index, + struct transport_vq_config *tp_cfg, + struct virtio_vq_config *cfg) { struct vring_virtqueue_split vring_split = {}; struct virtqueue *vq; int err; - err = vring_alloc_queue_split(&vring_split, vdev, num, vring_align, - may_reduce_num, dma_dev); + if (!tp_cfg->dma_dev) + tp_cfg->dma_dev = vdev->dev.parent; + + err = vring_alloc_queue_split(&vring_split, vdev, + tp_cfg->num, + tp_cfg->vring_align, + tp_cfg->may_reduce_num, + tp_cfg->dma_dev); if (err) return NULL; - vq = __vring_new_virtqueue(index, &vring_split, vdev, weak_barriers, - context, notify, callback, name, dma_dev); + vq = __vring_new_virtqueue(vdev, index, &vring_split, tp_cfg, cfg); if (!vq) { - vring_free_split(&vring_split, vdev, dma_dev); + vring_free_split(&vring_split, vdev, tp_cfg->dma_dev); return NULL; } @@ -2113,38 +2108,35 @@ static void virtqueue_reinit_packed(struct vring_virtqueue *vq) virtqueue_vring_init_packed(&vq->packed, !!vq->vq.callback); } -static struct virtqueue *vring_create_virtqueue_packed( - unsigned int index, - unsigned int num, - unsigned int vring_align, - struct virtio_device *vdev, - bool weak_barriers, - bool may_reduce_num, - bool context, - bool (*notify)(struct virtqueue *), - void (*callback)(struct virtqueue *), - const char *name, - struct device *dma_dev) +static struct virtqueue *vring_create_virtqueue_packed(struct virtio_device *vdev, + unsigned int index, + struct transport_vq_config *tp_cfg, + struct virtio_vq_config *cfg) { struct vring_virtqueue_packed vring_packed = {}; struct vring_virtqueue *vq; + struct device *dma_dev; int err; - if (vring_alloc_queue_packed(&vring_packed, vdev, num, dma_dev)) + dma_dev = tp_cfg->dma_dev; + if (!dma_dev) + dma_dev = vdev->dev.parent; + + if (vring_alloc_queue_packed(&vring_packed, vdev, tp_cfg->num, dma_dev)) goto err_ring; vq = kmalloc(sizeof(*vq), GFP_KERNEL); if (!vq) goto err_vq; - vq->vq.callback = callback; + vq->vq.callback = cfg_vq_val(cfg, callbacks); vq->vq.vdev = vdev; - vq->vq.name = name; + vq->vq.name = cfg_vq_val(cfg, names); vq->vq.index = index; vq->vq.reset = false; vq->we_own_ring = true; - vq->notify = notify; - vq->weak_barriers = weak_barriers; + vq->notify = tp_cfg->notify; + vq->weak_barriers = tp_cfg->weak_barriers; #ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION vq->broken = true; #else @@ -2156,7 +2148,7 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->premapped = false; vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) && - !context; + !cfg_vq_get(cfg, ctx); vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX); if (virtio_has_feature(vdev, VIRTIO_F_ORDER_PLATFORM)) @@ -2167,9 +2159,9 @@ static struct virtqueue *vring_create_virtqueue_packed( if (err) goto err_state_extra; - virtqueue_vring_init_packed(&vring_packed, !!callback); + virtqueue_vring_init_packed(&vring_packed, !!cfg_vq_val(cfg, callbacks)); - virtqueue_init(vq, num); + virtqueue_init(vq, tp_cfg->num); virtqueue_vring_attach_packed(vq, &vring_packed); spin_lock(&vdev->vqs_list_lock); @@ -2663,15 +2655,11 @@ irqreturn_t vring_interrupt(int irq, void *_vq) EXPORT_SYMBOL_GPL(vring_interrupt); /* Only available for split ring */ -static struct virtqueue *__vring_new_virtqueue(unsigned int index, +static struct virtqueue *__vring_new_virtqueue(struct virtio_device *vdev, + unsigned int index, struct vring_virtqueue_split *vring_split, - struct virtio_device *vdev, - bool weak_barriers, - bool context, - bool (*notify)(struct virtqueue *), - void (*callback)(struct virtqueue *), - const char *name, - struct device *dma_dev) + struct transport_vq_config *tp_cfg, + struct virtio_vq_config *cfg) { struct vring_virtqueue *vq; int err; @@ -2684,25 +2672,25 @@ static struct virtqueue *__vring_new_virtqueue(unsigned int index, return NULL; vq->packed_ring = false; - vq->vq.callback = callback; + vq->vq.callback = cfg_vq_val(cfg, callbacks); vq->vq.vdev = vdev; - vq->vq.name = name; + vq->vq.name = cfg_vq_val(cfg, names); vq->vq.index = index; vq->vq.reset = false; vq->we_own_ring = false; - vq->notify = notify; - vq->weak_barriers = weak_barriers; + vq->notify = tp_cfg->notify; + vq->weak_barriers = tp_cfg->weak_barriers; #ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION vq->broken = true; #else vq->broken = false; #endif - vq->dma_dev = dma_dev; + vq->dma_dev = tp_cfg->dma_dev; vq->use_dma_api = vring_use_dma_api(vdev); vq->premapped = false; vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) && - !context; + !cfg_vq_get(cfg, ctx); vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX); if (virtio_has_feature(vdev, VIRTIO_F_ORDER_PLATFORM)) @@ -2731,38 +2719,10 @@ struct virtqueue *vring_create_virtqueue(struct virtio_device *vdev, struct transport_vq_config *tp_cfg, struct virtio_vq_config *cfg) { - struct device *dma_dev; - unsigned int num; - unsigned int vring_align; - bool weak_barriers; - bool may_reduce_num; - bool context; - bool (*notify)(struct virtqueue *_); - void (*callback)(struct virtqueue *_); - const char *name; - - dma_dev = tp_cfg->dma_dev; - if (!dma_dev) - dma_dev = vdev->dev.parent; - - num = tp_cfg->num; - vring_align = tp_cfg->vring_align; - weak_barriers = tp_cfg->weak_barriers; - may_reduce_num = tp_cfg->may_reduce_num; - notify = tp_cfg->notify; - - name = cfg->names[cfg->cfg_idx]; - callback = cfg->callbacks[cfg->cfg_idx]; - context = cfg->ctx ? cfg->ctx[cfg->cfg_idx] : false; - if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) - return vring_create_virtqueue_packed(index, num, vring_align, - vdev, weak_barriers, may_reduce_num, - context, notify, callback, name, dma_dev); + return vring_create_virtqueue_packed(vdev, index, tp_cfg, cfg); - return vring_create_virtqueue_split(index, num, vring_align, - vdev, weak_barriers, may_reduce_num, - context, notify, callback, name, dma_dev); + return vring_create_virtqueue_split(vdev, index, tp_cfg, cfg); } EXPORT_SYMBOL_GPL(vring_create_virtqueue); @@ -2915,30 +2875,14 @@ struct virtqueue *vring_new_virtqueue(struct virtio_device *vdev, struct virtio_vq_config *cfg) { struct vring_virtqueue_split vring_split = {}; - unsigned int num; - unsigned int vring_align; - bool weak_barriers; - bool context; - bool (*notify)(struct virtqueue *_); - void (*callback)(struct virtqueue *_); - const char *name; - - num = tp_cfg->num; - vring_align = tp_cfg->vring_align; - weak_barriers = tp_cfg->weak_barriers; - notify = tp_cfg->notify; - - name = cfg->names[cfg->cfg_idx]; - callback = cfg->callbacks[cfg->cfg_idx]; - context = cfg->ctx ? cfg->ctx[cfg->cfg_idx] : false; if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) return NULL; - vring_init(&vring_split.vring, num, pages, vring_align); - return __vring_new_virtqueue(index, &vring_split, vdev, weak_barriers, - context, notify, callback, name, - vdev->dev.parent); + tp_cfg->dma_dev = vdev->dev.parent; + + vring_init(&vring_split.vring, tp_cfg->num, pages, tp_cfg->vring_align); + return __vring_new_virtqueue(vdev, index, &vring_split, tp_cfg, cfg); } EXPORT_SYMBOL_GPL(vring_new_virtqueue);