From patchwork Thu Apr 11 02:35:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 1922333 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=On1Axb82; 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=QnUgqwAj; 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 4VFP2C56XCz1yZg for ; Thu, 11 Apr 2024 12:35:45 +1000 (AEST) 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=4mPU8uVU62Gx+L9YfY51VYVWJr6/PqFv0TCtZ2FCoKo=; b=On1Axb829B0jNT448ccsDzF5iW 8y3tJ+xWMSDO0ZvYmMVSjkOxb0gGadOBjxASw95xBZwPkh3uoQa53FtYkRb+nCJfzchN9L82oE3RA bHxfArU3uj4BXG6fevWv8CMQNMH3mQy/VT1xgxnVmByrQ+dNvn7dPUsvv/rtM2ExyM1lj4gj9TonN vz6zyKL96hUNN0sGnKXiOPggIs5zV6v00Y+6RrHG1lGhKBGP9bYjeV7ixJ3GGZX0lh6X9lVoUCfQw 9qf15lCPL7mGWPZj8adfv81UbkMlpG9mZeSgi/nNMjp7cTqIhREe3IY+Eh9tXY8hYaQaDa2UG9wjH sj1DAUwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rukHt-0000000A0A2-1Jgx; Thu, 11 Apr 2024 02:35:41 +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 1rukHo-0000000A07k-2ayq for linux-um@lists.infradead.org; Thu, 11 Apr 2024 02:35:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1712802931; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=4mPU8uVU62Gx+L9YfY51VYVWJr6/PqFv0TCtZ2FCoKo=; b=QnUgqwAjbI45oTvhlx2egEP5yHdbf7U+7pwUImIV3m81f9Qam438liCL2y4JEk4M0pbJ8/wtvEkFntKZcB9kDreMbYtg4h10qhFXSt+rsOeAoub/jVadH3Wy/epgMromZ/jKrNyDPprHT8bMAnOaENCQQ06va3fhr9xy5+rVbQo= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=26;SR=0;TI=SMTPD_---0W4JW4H8_1712802929; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W4JW4H8_1712802929) by smtp.aliyun-inc.com; Thu, 11 Apr 2024 10:35:30 +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 v8 1/6] virtio_balloon: remove the dependence where names[] is null Date: Thu, 11 Apr 2024 10:35:23 +0800 Message-Id: <20240411023528.10914-2-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240411023528.10914-1-xuanzhuo@linux.alibaba.com> References: <20240411023528.10914-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: d277a0b9519b X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_193537_147771_3989C4E9 X-CRM114-Status: GOOD ( 13.61 ) 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: Currently, the init_vqs function within the virtio_balloon driver relies on the condition that certain names array entries are null in order to skip the initialization of some virtual queues (vqs). Th [...] 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] -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 -0.0 SPF_PASS SPF: sender matches SPF record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM welcome-list -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 Currently, the init_vqs function within the virtio_balloon driver relies on the condition that certain names array entries are null in order to skip the initialization of some virtual queues (vqs). This behavior is unique to this part of the codebase. In an upcoming commit, we plan to eliminate this dependency by removing the function entirely. Therefore, with this change, we are ensuring that the virtio_balloon no longer depends on the aforementioned function. As specification 1.0-1.2, vq indexes should not be contiguous if some vq does not exist. But currently the virtqueue index is contiguous for all existing devices. The Linux kernel does not implement functionality to allow vq indexes to be discontinuous. So the current behavior of the virtio-balloon device is different for the spec. But this commit has no functional changes. Signed-off-by: Xuan Zhuo Acked-by: David Hildenbrand Acked-by: Jason Wang --- drivers/virtio/virtio_balloon.c | 48 ++++++++++++++------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 1f5b3dd31fcf..f5ed351e31d4 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -531,49 +531,41 @@ static int init_vqs(struct virtio_balloon *vb) struct virtqueue *vqs[VIRTIO_BALLOON_VQ_MAX]; vq_callback_t *callbacks[VIRTIO_BALLOON_VQ_MAX]; const char *names[VIRTIO_BALLOON_VQ_MAX]; - int err; + int err, idx = 0; - /* - * Inflateq and deflateq are used unconditionally. The names[] - * will be NULL if the related feature is not enabled, which will - * cause no allocation for the corresponding virtqueue in find_vqs. - */ - callbacks[VIRTIO_BALLOON_VQ_INFLATE] = balloon_ack; - names[VIRTIO_BALLOON_VQ_INFLATE] = "inflate"; - callbacks[VIRTIO_BALLOON_VQ_DEFLATE] = balloon_ack; - names[VIRTIO_BALLOON_VQ_DEFLATE] = "deflate"; - callbacks[VIRTIO_BALLOON_VQ_STATS] = NULL; - names[VIRTIO_BALLOON_VQ_STATS] = NULL; - callbacks[VIRTIO_BALLOON_VQ_FREE_PAGE] = NULL; - names[VIRTIO_BALLOON_VQ_FREE_PAGE] = NULL; - names[VIRTIO_BALLOON_VQ_REPORTING] = NULL; + callbacks[idx] = balloon_ack; + names[idx++] = "inflate"; + callbacks[idx] = balloon_ack; + names[idx++] = "deflate"; if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) { - names[VIRTIO_BALLOON_VQ_STATS] = "stats"; - callbacks[VIRTIO_BALLOON_VQ_STATS] = stats_request; + names[idx] = "stats"; + callbacks[idx++] = stats_request; } if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { - names[VIRTIO_BALLOON_VQ_FREE_PAGE] = "free_page_vq"; - callbacks[VIRTIO_BALLOON_VQ_FREE_PAGE] = NULL; + names[idx] = "free_page_vq"; + callbacks[idx++] = NULL; } if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) { - names[VIRTIO_BALLOON_VQ_REPORTING] = "reporting_vq"; - callbacks[VIRTIO_BALLOON_VQ_REPORTING] = balloon_ack; + names[idx] = "reporting_vq"; + callbacks[idx++] = balloon_ack; } - err = virtio_find_vqs(vb->vdev, VIRTIO_BALLOON_VQ_MAX, vqs, - callbacks, names, NULL); + err = virtio_find_vqs(vb->vdev, idx, vqs, callbacks, names, NULL); if (err) return err; - vb->inflate_vq = vqs[VIRTIO_BALLOON_VQ_INFLATE]; - vb->deflate_vq = vqs[VIRTIO_BALLOON_VQ_DEFLATE]; + idx = 0; + + vb->inflate_vq = vqs[idx++]; + vb->deflate_vq = vqs[idx++]; + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) { struct scatterlist sg; unsigned int num_stats; - vb->stats_vq = vqs[VIRTIO_BALLOON_VQ_STATS]; + vb->stats_vq = vqs[idx++]; /* * Prime this virtqueue with one buffer so the hypervisor can @@ -593,10 +585,10 @@ static int init_vqs(struct virtio_balloon *vb) } if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) - vb->free_page_vq = vqs[VIRTIO_BALLOON_VQ_FREE_PAGE]; + vb->free_page_vq = vqs[idx++]; if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) - vb->reporting_vq = vqs[VIRTIO_BALLOON_VQ_REPORTING]; + vb->reporting_vq = vqs[idx++]; return 0; }