From nobody Wed Feb 11 04:18:11 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C8B42853EE for ; Sun, 16 Nov 2025 07:45:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763279129; cv=none; b=lmU4Lf2gt6gUiMtwOMl/T5CmRlehNNfFpiqQRjncZc66ICH2kFJj4r0WmZw6wDgSBcGcpyvRw/kP4M0bPLFZhGEgxcXjJsV6bM99IBooZUt1SLDhTtyTq45l66KUvYQII2B2CYxvMvKOemsGHimi7DKZYYAboNnFWYv4VGS2jws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763279129; c=relaxed/simple; bh=GaBinUogl24XMoAq8WDeuyU0VxqLQu+zMucBEEX6Q54=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NdRDdAmIptK9pUIVJs433aolHNhQbi5KZhg6Lesjsp4D0rcL7QMvoqtM1Es/fMYpPelQ3ZcMBgDhf/O8sE7OLWwuCKS+ENPfzrZqee7Hrfk2Tg5FqDWMm+KWzX+Fc2NrJcXgwFlYOTG0lPV4QyVuf3fQd956Ho1LAFmDD+N9fGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=L9rpxFDP; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=bIdgVGUu; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="L9rpxFDP"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="bIdgVGUu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763279126; 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: in-reply-to:in-reply-to:references:references; bh=PVwL92+rv5frGSi1sboKRU9czrSdM9SXscSGog1LIOg=; b=L9rpxFDPQgodlB0wK4Y0bgl+UMQ0DSASXy6zLHORP//Kuh2+NSM3+RbqPlKcXre6sna4bh vrdLvth/uklXzaOHr8kaXzjdmW0vddmTPhGLLbV4JuGw7oeR/MhhEaYfuf2X2lKBl6Mi+e YQO8gToccgIKFGmLoedpFMnKiu+Uums= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-BrKPb5CENEWgVC9nGUnZ4w-1; Sun, 16 Nov 2025 02:45:24 -0500 X-MC-Unique: BrKPb5CENEWgVC9nGUnZ4w-1 X-Mimecast-MFC-AGG-ID: BrKPb5CENEWgVC9nGUnZ4w_1763279124 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-47754e6bddbso23102335e9.3 for ; Sat, 15 Nov 2025 23:45:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763279123; x=1763883923; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=PVwL92+rv5frGSi1sboKRU9czrSdM9SXscSGog1LIOg=; b=bIdgVGUuJd5NfvMWQWKv1trm6jSC3FmntA54BuzOcbj+MaYAa7zrOR+66/t+fD0tcI kRXyyzdG/VaUkXnzm7OJDKeFg7rn8DWwsKR330sXtSxp6bp+gJSueIOiRMpFVNysbmPn w13yCmZ6qpJ0c6ub66UIbYVDlrWjPJvbycqLx/I9mI5AEeq4+TXCcnixCoex6rAHLL56 q5+fofYqU60CS+6olYgZs0GR3r1VqHFr1dDoBEbaV/gKVx8ZJryAkKbMjnYzJ0xIBG5H eVzSgkKENf6X354Q6nH4F5gEbEQ1L6Suuz9AkFZcPTixG135hFGtGbCPzQttv3YXkwH4 ELxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763279123; x=1763883923; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PVwL92+rv5frGSi1sboKRU9czrSdM9SXscSGog1LIOg=; b=PK/ZTv3oJHMbDN3keHeNgYUL24JF1c5wW7Ai4OiIWD46kalpSlYZcLb+jHD7/aMpfn KIKN1iO/SHnC2anAIJZPVbH0Bvt0vEcPY163YFfy43Ht7Bc7anlisADSD/FfhMyZqsz5 vcyItjZ1P3QjEQ5eqcZ3aog9mwCZIKr+8DK5BZ14/gL6S7wFeu/DlEc8MjW/vI2JAKFf l+nWHBQ8Jbqw6Ni87DQfAN/1PFaT5FpZ220Bt0v4XEgw3dVAgKkB00ccRj8Duz7uTX1g 1jYNR9UBFDF0pUZfsW051KUg57m/tfgmK9pEX9OJejIkdQKVjBjJuuS41QvRH91/iYF0 a2XQ== X-Gm-Message-State: AOJu0YxASP/iJqu3gsLj0xQhZvr43jne/T1gjoM+PiJ/cymDE5otrxFG YprQD4UsjZKPIzZNhvMGUGzXFQxInSiKQU5XyvZMei2En6DCUHYG9Np1/LEL7bp1mwRmxGi9BlH h3ARx6AgVld5qVz5LUZuys6Je6T9i3oP7Po14KsqcvU1SfLGP4jg+3acxFVeym7PwyWU78PanUt 5mqsOeESxi9hUw/GlGkqGj0CKJrewGg9lKzpsot6xyNPQ= X-Gm-Gg: ASbGncu0ZAaTcffwYxDz7cnZPFSxo4VXKTTbbRmooRrLc1FAiwbUija2f2CDT/W3ryc ILE8bZ5AAxRqJa9IkBT0Ji8AoQb97y0l50B4BOJaMNOENkpmgCpW+9YCjwoXep1zRLyM7Kgd5Ap xESQID71EpNMeVEEOL9Xrqhcuw90fyDJCGoxZFD+ufJC6wjBYW6vlKUH8pk1wdQlNv53ZVXJSJn c0v/Xe51h8+ln4JPKsWYahgnEmqtkA8QZ78qRHp6S6HlzchhsEMhq4660UNH2hcVs2YfR+pcG2t VA//aBIztdycowpCbZ/yeC1PafINwrrCGooKtC2NpLu275kRwb0MUUwzPDkriy3HnChoxIyeqO3 b1qL5EF+hQEgGagKYn1U= X-Received: by 2002:a05:600c:c4aa:b0:477:79f8:da9d with SMTP id 5b1f17b1804b1-4778fea8cbemr72758345e9.24.1763279123023; Sat, 15 Nov 2025 23:45:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHC8pEYIx+lA7X1G939R16xZ/qeRcjaWyNhzSdboc9RUQDEd8xrOesmfr4DEAXFqOqS57KI2A== X-Received: by 2002:a05:600c:c4aa:b0:477:79f8:da9d with SMTP id 5b1f17b1804b1-4778fea8cbemr72758105e9.24.1763279122501; Sat, 15 Nov 2025 23:45:22 -0800 (PST) Received: from redhat.com (IGLD-80-230-39-63.inter.net.il. [80.230.39.63]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4779b367556sm26675175e9.2.2025.11.15.23.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Nov 2025 23:45:21 -0800 (PST) Date: Sun, 16 Nov 2025 02:45:18 -0500 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Andrew Lunn , Paolo Abeni , Jason Wang , Eugenio =?utf-8?B?UMOpcmV6?= , Xuan Zhuo , Jonathan Corbet , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v4 1/2] virtio: clean up features qword/dword terms Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" virtio pci uses word to mean "16 bits". mmio uses it to mean "32 bits". To avoid confusion, let's avoid the term in core virtio altogether. Just say U64 to mean "64 bit". Fixes: e7d4c1c5a546 ("virtio: introduce extended features") Cc: "Paolo Abeni" Signed-off-by: Michael S. Tsirkin Message-Id: <492ef5aaa196d155d0535b5b6f4ad5b3fba70a1b.1761058528.git.mst@re= dhat.com> Acked-by: Jason Wang --- drivers/vhost/net.c | 12 +++++------ drivers/virtio/virtio.c | 12 +++++------ drivers/virtio/virtio_debug.c | 10 ++++----- drivers/virtio/virtio_pci_modern_dev.c | 6 +++--- include/linux/virtio.h | 2 +- include/linux/virtio_config.h | 2 +- include/linux/virtio_features.h | 29 +++++++++++++------------- include/linux/virtio_pci_modern.h | 8 +++---- 8 files changed, 41 insertions(+), 40 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 35ded4330431..d057ea55f5ad 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -69,7 +69,7 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy = TX;" =20 #define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >=3D (__force u32)VHOST= _DMA_DONE_LEN) =20 -static const u64 vhost_net_features[VIRTIO_FEATURES_DWORDS] =3D { +static const u64 vhost_net_features[VIRTIO_FEATURES_U64S] =3D { VHOST_FEATURES | (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) | (1ULL << VIRTIO_NET_F_MRG_RXBUF) | @@ -1720,7 +1720,7 @@ static long vhost_net_set_owner(struct vhost_net *n) static long vhost_net_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) { - u64 all_features[VIRTIO_FEATURES_DWORDS]; + u64 all_features[VIRTIO_FEATURES_U64S]; struct vhost_net *n =3D f->private_data; void __user *argp =3D (void __user *)arg; u64 __user *featurep =3D argp; @@ -1752,7 +1752,7 @@ static long vhost_net_ioctl(struct file *f, unsigned = int ioctl, =20 /* Copy the net features, up to the user-provided buffer size */ argp +=3D sizeof(u64); - copied =3D min(count, VIRTIO_FEATURES_DWORDS); + copied =3D min(count, (u64)VIRTIO_FEATURES_U64S); if (copy_to_user(argp, vhost_net_features, copied * sizeof(u64))) return -EFAULT; @@ -1767,13 +1767,13 @@ static long vhost_net_ioctl(struct file *f, unsigne= d int ioctl, =20 virtio_features_zero(all_features); argp +=3D sizeof(u64); - copied =3D min(count, VIRTIO_FEATURES_DWORDS); + copied =3D min(count, (u64)VIRTIO_FEATURES_U64S); if (copy_from_user(all_features, argp, copied * sizeof(u64))) return -EFAULT; =20 /* * Any feature specified by user-space above - * VIRTIO_FEATURES_MAX is not supported by definition. + * VIRTIO_FEATURES_BITS is not supported by definition. */ for (i =3D copied; i < count; ++i) { if (copy_from_user(&features, featurep + 1 + i, @@ -1783,7 +1783,7 @@ static long vhost_net_ioctl(struct file *f, unsigned = int ioctl, return -EOPNOTSUPP; } =20 - for (i =3D 0; i < VIRTIO_FEATURES_DWORDS; i++) + for (i =3D 0; i < VIRTIO_FEATURES_U64S; i++) if (all_features[i] & ~vhost_net_features[i]) return -EOPNOTSUPP; =20 diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index a09eb4d62f82..5bdc6b82b30b 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -53,7 +53,7 @@ static ssize_t features_show(struct device *_d, =20 /* We actually represent this as a bitstring, as it could be * arbitrary length in future. */ - for (i =3D 0; i < VIRTIO_FEATURES_MAX; i++) + for (i =3D 0; i < VIRTIO_FEATURES_BITS; i++) len +=3D sysfs_emit_at(buf, len, "%c", __virtio_test_bit(dev, i) ? '1' : '0'); len +=3D sysfs_emit_at(buf, len, "\n"); @@ -272,8 +272,8 @@ static int virtio_dev_probe(struct device *_d) int err, i; struct virtio_device *dev =3D dev_to_virtio(_d); struct virtio_driver *drv =3D drv_to_virtio(dev->dev.driver); - u64 device_features[VIRTIO_FEATURES_DWORDS]; - u64 driver_features[VIRTIO_FEATURES_DWORDS]; + u64 device_features[VIRTIO_FEATURES_U64S]; + u64 driver_features[VIRTIO_FEATURES_U64S]; u64 driver_features_legacy; =20 /* We have a driver! */ @@ -286,7 +286,7 @@ static int virtio_dev_probe(struct device *_d) virtio_features_zero(driver_features); for (i =3D 0; i < drv->feature_table_size; i++) { unsigned int f =3D drv->feature_table[i]; - if (!WARN_ON_ONCE(f >=3D VIRTIO_FEATURES_MAX)) + if (!WARN_ON_ONCE(f >=3D VIRTIO_FEATURES_BITS)) virtio_features_set_bit(driver_features, f); } =20 @@ -303,7 +303,7 @@ static int virtio_dev_probe(struct device *_d) } =20 if (virtio_features_test_bit(device_features, VIRTIO_F_VERSION_1)) { - for (i =3D 0; i < VIRTIO_FEATURES_DWORDS; ++i) + for (i =3D 0; i < VIRTIO_FEATURES_U64S; ++i) dev->features_array[i] =3D driver_features[i] & device_features[i]; } else { @@ -325,7 +325,7 @@ static int virtio_dev_probe(struct device *_d) goto err; =20 if (drv->validate) { - u64 features[VIRTIO_FEATURES_DWORDS]; + u64 features[VIRTIO_FEATURES_U64S]; =20 virtio_features_copy(features, dev->features_array); err =3D drv->validate(dev); diff --git a/drivers/virtio/virtio_debug.c b/drivers/virtio/virtio_debug.c index d58713ddf2e5..ccf1955a1183 100644 --- a/drivers/virtio/virtio_debug.c +++ b/drivers/virtio/virtio_debug.c @@ -8,12 +8,12 @@ static struct dentry *virtio_debugfs_dir; =20 static int virtio_debug_device_features_show(struct seq_file *s, void *dat= a) { - u64 device_features[VIRTIO_FEATURES_DWORDS]; + u64 device_features[VIRTIO_FEATURES_U64S]; struct virtio_device *dev =3D s->private; unsigned int i; =20 virtio_get_features(dev, device_features); - for (i =3D 0; i < VIRTIO_FEATURES_MAX; i++) { + for (i =3D 0; i < VIRTIO_FEATURES_BITS; i++) { if (virtio_features_test_bit(device_features, i)) seq_printf(s, "%u\n", i); } @@ -26,7 +26,7 @@ static int virtio_debug_filter_features_show(struct seq_f= ile *s, void *data) struct virtio_device *dev =3D s->private; unsigned int i; =20 - for (i =3D 0; i < VIRTIO_FEATURES_MAX; i++) { + for (i =3D 0; i < VIRTIO_FEATURES_BITS; i++) { if (virtio_features_test_bit(dev->debugfs_filter_features, i)) seq_printf(s, "%u\n", i); } @@ -50,7 +50,7 @@ static int virtio_debug_filter_feature_add(void *data, u6= 4 val) { struct virtio_device *dev =3D data; =20 - if (val >=3D VIRTIO_FEATURES_MAX) + if (val >=3D VIRTIO_FEATURES_BITS) return -EINVAL; =20 virtio_features_set_bit(dev->debugfs_filter_features, val); @@ -64,7 +64,7 @@ static int virtio_debug_filter_feature_del(void *data, u6= 4 val) { struct virtio_device *dev =3D data; =20 - if (val >=3D VIRTIO_FEATURES_MAX) + if (val >=3D VIRTIO_FEATURES_BITS) return -EINVAL; =20 virtio_features_clear_bit(dev->debugfs_filter_features, val); diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio= _pci_modern_dev.c index 9e503b7a58d8..413a8c353463 100644 --- a/drivers/virtio/virtio_pci_modern_dev.c +++ b/drivers/virtio/virtio_pci_modern_dev.c @@ -401,7 +401,7 @@ void vp_modern_get_extended_features(struct virtio_pci_= modern_device *mdev, int i; =20 virtio_features_zero(features); - for (i =3D 0; i < VIRTIO_FEATURES_WORDS; i++) { + for (i =3D 0; i < VIRTIO_FEATURES_BITS / 32; i++) { u64 cur; =20 vp_iowrite32(i, &cfg->device_feature_select); @@ -427,7 +427,7 @@ vp_modern_get_driver_extended_features(struct virtio_pc= i_modern_device *mdev, int i; =20 virtio_features_zero(features); - for (i =3D 0; i < VIRTIO_FEATURES_WORDS; i++) { + for (i =3D 0; i < VIRTIO_FEATURES_BITS / 32; i++) { u64 cur; =20 vp_iowrite32(i, &cfg->guest_feature_select); @@ -448,7 +448,7 @@ void vp_modern_set_extended_features(struct virtio_pci_= modern_device *mdev, struct virtio_pci_common_cfg __iomem *cfg =3D mdev->common; int i; =20 - for (i =3D 0; i < VIRTIO_FEATURES_WORDS; i++) { + for (i =3D 0; i < VIRTIO_FEATURES_BITS / 32; i++) { u32 cur =3D features[i >> 1] >> (32 * (i & 1)); =20 vp_iowrite32(i, &cfg->guest_feature_select); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 96c66126c074..132a474e5914 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -177,7 +177,7 @@ struct virtio_device { union virtio_map vmap; #ifdef CONFIG_VIRTIO_DEBUG struct dentry *debugfs_dir; - u64 debugfs_filter_features[VIRTIO_FEATURES_DWORDS]; + u64 debugfs_filter_features[VIRTIO_FEATURES_U64S]; #endif }; =20 diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index a1af2676bbe6..69f84ea85d71 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -80,7 +80,7 @@ struct virtqueue_info { * Returns the first 64 feature bits. * @get_extended_features: * vdev: the virtio_device - * Returns the first VIRTIO_FEATURES_MAX feature bits (all we current= ly + * Returns the first VIRTIO_FEATURES_BITS feature bits (all we curren= tly * need). * @finalize_features: confirm what device features we'll be using. * vdev: the virtio_device diff --git a/include/linux/virtio_features.h b/include/linux/virtio_feature= s.h index f748f2f87de8..ea2ad8717882 100644 --- a/include/linux/virtio_features.h +++ b/include/linux/virtio_features.h @@ -4,15 +4,16 @@ =20 #include =20 -#define VIRTIO_FEATURES_DWORDS 2 -#define VIRTIO_FEATURES_MAX (VIRTIO_FEATURES_DWORDS * 64) -#define VIRTIO_FEATURES_WORDS (VIRTIO_FEATURES_DWORDS * 2) +#define VIRTIO_FEATURES_U64S 2 +#define VIRTIO_FEATURES_BITS (VIRTIO_FEATURES_U64S * 64) + #define VIRTIO_BIT(b) BIT_ULL((b) & 0x3f) -#define VIRTIO_DWORD(b) ((b) >> 6) +#define VIRTIO_U64(b) ((b) >> 6) + #define VIRTIO_DECLARE_FEATURES(name) \ union { \ u64 name; \ - u64 name##_array[VIRTIO_FEATURES_DWORDS];\ + u64 name##_array[VIRTIO_FEATURES_U64S];\ } =20 static inline bool virtio_features_chk_bit(unsigned int bit) @@ -22,9 +23,9 @@ static inline bool virtio_features_chk_bit(unsigned int b= it) * Don't care returning the correct value: the build * will fail before any bad features access */ - BUILD_BUG_ON(bit >=3D VIRTIO_FEATURES_MAX); + BUILD_BUG_ON(bit >=3D VIRTIO_FEATURES_BITS); } else { - if (WARN_ON_ONCE(bit >=3D VIRTIO_FEATURES_MAX)) + if (WARN_ON_ONCE(bit >=3D VIRTIO_FEATURES_BITS)) return false; } return true; @@ -34,26 +35,26 @@ static inline bool virtio_features_test_bit(const u64 *= features, unsigned int bit) { return virtio_features_chk_bit(bit) && - !!(features[VIRTIO_DWORD(bit)] & VIRTIO_BIT(bit)); + !!(features[VIRTIO_U64(bit)] & VIRTIO_BIT(bit)); } =20 static inline void virtio_features_set_bit(u64 *features, unsigned int bit) { if (virtio_features_chk_bit(bit)) - features[VIRTIO_DWORD(bit)] |=3D VIRTIO_BIT(bit); + features[VIRTIO_U64(bit)] |=3D VIRTIO_BIT(bit); } =20 static inline void virtio_features_clear_bit(u64 *features, unsigned int bit) { if (virtio_features_chk_bit(bit)) - features[VIRTIO_DWORD(bit)] &=3D ~VIRTIO_BIT(bit); + features[VIRTIO_U64(bit)] &=3D ~VIRTIO_BIT(bit); } =20 static inline void virtio_features_zero(u64 *features) { - memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_DWORDS); + memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_U64S); } =20 static inline void virtio_features_from_u64(u64 *features, u64 from) @@ -66,7 +67,7 @@ static inline bool virtio_features_equal(const u64 *f1, c= onst u64 *f2) { int i; =20 - for (i =3D 0; i < VIRTIO_FEATURES_DWORDS; ++i) + for (i =3D 0; i < VIRTIO_FEATURES_U64S; ++i) if (f1[i] !=3D f2[i]) return false; return true; @@ -74,14 +75,14 @@ static inline bool virtio_features_equal(const u64 *f1,= const u64 *f2) =20 static inline void virtio_features_copy(u64 *to, const u64 *from) { - memcpy(to, from, sizeof(to[0]) * VIRTIO_FEATURES_DWORDS); + memcpy(to, from, sizeof(to[0]) * VIRTIO_FEATURES_U64S); } =20 static inline void virtio_features_andnot(u64 *to, const u64 *f1, const u6= 4 *f2) { int i; =20 - for (i =3D 0; i < VIRTIO_FEATURES_DWORDS; i++) + for (i =3D 0; i < VIRTIO_FEATURES_U64S; i++) to[i] =3D f1[i] & ~f2[i]; } =20 diff --git a/include/linux/virtio_pci_modern.h b/include/linux/virtio_pci_m= odern.h index 48bc12d1045b..9a3f2fc53bd6 100644 --- a/include/linux/virtio_pci_modern.h +++ b/include/linux/virtio_pci_modern.h @@ -107,7 +107,7 @@ void vp_modern_set_extended_features(struct virtio_pci_= modern_device *mdev, static inline u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev) { - u64 features_array[VIRTIO_FEATURES_DWORDS]; + u64 features_array[VIRTIO_FEATURES_U64S]; =20 vp_modern_get_extended_features(mdev, features_array); return features_array[0]; @@ -116,11 +116,11 @@ vp_modern_get_features(struct virtio_pci_modern_devic= e *mdev) static inline u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev) { - u64 features_array[VIRTIO_FEATURES_DWORDS]; + u64 features_array[VIRTIO_FEATURES_U64S]; int i; =20 vp_modern_get_driver_extended_features(mdev, features_array); - for (i =3D 1; i < VIRTIO_FEATURES_DWORDS; ++i) + for (i =3D 1; i < VIRTIO_FEATURES_U64S; ++i) WARN_ON_ONCE(features_array[i]); return features_array[0]; } @@ -128,7 +128,7 @@ vp_modern_get_driver_features(struct virtio_pci_modern_= device *mdev) static inline void vp_modern_set_features(struct virtio_pci_modern_device *mdev, u64 features) { - u64 features_array[VIRTIO_FEATURES_DWORDS]; + u64 features_array[VIRTIO_FEATURES_U64S]; =20 virtio_features_from_u64(features_array, features); vp_modern_set_extended_features(mdev, features_array); --=20 MST From nobody Wed Feb 11 04:18:11 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2F32286412 for ; Sun, 16 Nov 2025 07:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763279131; cv=none; b=mxbktNZ+ioMXQib3wswi+XeA/hRSyxCRAwIqbZ1CxIYyfCgezCRKwiwEgyp1qJMTsus0+a7el/j3IH/+yUBKG+WMa4HyYUzHzeNyqkfVQHJp7ChIYA1svBYsad+v2zglUf5O8bTCpGiZ9kPlwau4wukeo4dvJPvZXxvGivgZOrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763279131; c=relaxed/simple; bh=y8wCZBoR8voYmXOKUgsqLzpqBH63+zG9KD2XjWV0Mfw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zg9w/OxFK5709Pb9bJXW737lC7LT+Ta/VS6ExQbLYpdR0eCo0WxseYp+jUT4+dVHri+tVw3jklLtg1d8MM3fYw/pRxkAZrLyuiFzrnrYvwVtbpqzr2+2iquTG/LUctp9YAJtcyZv9qwV9u580q1O6MEqVC2p8qPOzUa4rUoSWrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bWCErSfU; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=mOxsfcOV; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bWCErSfU"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="mOxsfcOV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763279129; 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: in-reply-to:in-reply-to:references:references; bh=trQJ3e9sH2/7p6hcj43E7jvSF+i5hK8jJlCsMQnk8Kw=; b=bWCErSfU0vtpubxhWwtvIrs6sg1bITNJvVD97hdIcjTGG/FU67KhkjWCNcXlHkEeUVogZq XC0sIYPDyRbhDO8ZDMkOroVgqkG+0blko7RR+UNAAzet4HUGHmk2XT/DvOyCl4qdDh+Ai1 LkCOIMSaw87S/mt/RrwFGSyMh+aMxGE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-355-H1jiqGMEO--_gdQS0_lFuA-1; Sun, 16 Nov 2025 02:45:27 -0500 X-MC-Unique: H1jiqGMEO--_gdQS0_lFuA-1 X-Mimecast-MFC-AGG-ID: H1jiqGMEO--_gdQS0_lFuA_1763279127 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-429cdb0706aso2926055f8f.0 for ; Sat, 15 Nov 2025 23:45:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763279126; x=1763883926; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=trQJ3e9sH2/7p6hcj43E7jvSF+i5hK8jJlCsMQnk8Kw=; b=mOxsfcOVN7c1Nmpzw6izHM6CsPcO9/erni1F62AwNw7Ls/ckzf6XVbD3dc5VFiaPZL Hy/QTk6Ze5z/y8zPXe8CqBLhwy42tj7c1NORelQ+BtpLSfcUIGECxTNuu0oqVZoh5YRy YE60X65iaamZtJUNQ/T112Or5La17ci5I2fqvQwsqSV3eTgtN9qS9hX2rvzFgNaPxZru cf79SPbkKzhlJfBOXgonl0vm+U5+GhAI1KDs6qsy4Q4TAdBLcSGq9zak+VP7t/DUd/mn zoUPNYxLAANUqYHzePFuwubPpbHX5Gfw//O8qzA7sz/SirhqV7GEf1wIvmDGsr7ApsOi aJvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763279126; x=1763883926; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=trQJ3e9sH2/7p6hcj43E7jvSF+i5hK8jJlCsMQnk8Kw=; b=lqASplGxhduAz0v4FWvUAxG0RqGOWhSTbDJhvF1s3j8mnbh9lneDNx6kS/TusbziAp PPE/dAGfN4eJ2esgE59bsq8Y092jPROWtm+rW4IiwaUXz31cogO+OzJnDJfzuktuvQG4 14XzFfYX1F5blXOp96ph9d+ZYkeJqzyquJLg5gikzb6Bgoa6FgXQTpjo1cdzcdC/cYle LjttXbxxVormAk1lBlP9z36DoKUmCcjBaFfdE7tQxIgXy1OuoFMoUPRHdN/wInD2Xe7B kQkVLuaqhsWID6IAcYPZVxdfWuJr6WMv2FBsSnWS474bgty9xOQ9MZtcfY+7EPsZxp/T yo4Q== X-Gm-Message-State: AOJu0Yypovlhga+Akinb3ZD4wpihm3gy6MrdeRah7t11NkFGTvCVDu2R 2CeBRXUYgBw5GIiPG2XEbnZBaQXlg1pOhKZlXriQrg8nFCwnBHf1QAVhWhT2BGr0/sy8g6bC1Ic YeZ3T1HD4YS1AU9gZ0MD6+sik4fisbrt3p2mu/7UuI9rnl7O6bkUbqx3md5J8w93xm74xcSCLU+ VPJxYrGLBtF2dPDGdVmb300LnsUsUlaIM0T0E5Z8NGRtM= X-Gm-Gg: ASbGncvIbjF3VsaCjYiqwXshHAkFRcGzkyso/PuZGU+RhxsLNYEdwtfMiFOHXswGq/U rA7feh56vK1FONXhrxY0Lp9qPwVjzIknx/asCaFCcW+F8vRVv0qwlh+FZ+x9tiKbUtyfhVMxjis SiwOA5hNzo8CEWdmOVPeV57Nq6L36S90F2xxXUCKrBcBKnY2DUyQ/ZGDrgNjunnl92yf0yctx6K kmfEkQJwa4/SFUPFz44E8AVxvMdJIkwVDcZoktCzyrvTYJ+Hcwgsodr85ep9Cspt+oKmroo/xK2 9VcHtXFGPsS1HuLSiX2dOQ6E2WgR2SuwehTJKw5yk8/HprLGQ5bza3DHNe68rJQXExE3VU95VWd ApE53/dtlsj38qLUr6WY= X-Received: by 2002:a05:6000:61e:b0:429:d6dc:ae1a with SMTP id ffacd0b85a97d-42b59377f5cmr7144000f8f.30.1763279126301; Sat, 15 Nov 2025 23:45:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFavbSLEzC3fzGZlFNcbplKoDaGAFf6xm82Dmpuac8kJ0YL87asozxTpPgyhKXE0Otxlq6lXg== X-Received: by 2002:a05:6000:61e:b0:429:d6dc:ae1a with SMTP id ffacd0b85a97d-42b59377f5cmr7143962f8f.30.1763279125674; Sat, 15 Nov 2025 23:45:25 -0800 (PST) Received: from redhat.com (IGLD-80-230-39-63.inter.net.il. [80.230.39.63]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53f2084dsm20221273f8f.42.2025.11.15.23.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Nov 2025 23:45:24 -0800 (PST) Date: Sun, 16 Nov 2025 02:45:22 -0500 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Andrew Lunn , Paolo Abeni , Jason Wang , Eugenio =?utf-8?B?UMOpcmV6?= , Xuan Zhuo , Jonathan Corbet , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Mike Christie , Paolo Bonzini , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v4 2/2] vhost: switch to arrays of feature bits Message-ID: <17c98c7304b6d78d2d59893ba7295c2f64ab1224.1763278904.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current interface where caller has to know in which 64 bit chunk each bit is, is inelegant and fragile. Let's simply use arrays of bits. By using unroll macros text size grows only slightly. Signed-off-by: Michael S. Tsirkin --- drivers/vhost/net.c | 34 +++++++++++++++++++--------------- drivers/vhost/scsi.c | 9 ++++++--- drivers/vhost/test.c | 10 ++++++++-- drivers/vhost/vhost.h | 42 ++++++++++++++++++++++++++++++++++-------- drivers/vhost/vsock.c | 10 ++++++---- 5 files changed, 73 insertions(+), 32 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index d057ea55f5ad..00d00034a97e 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -69,15 +69,15 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Cop= y TX;" =20 #define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >=3D (__force u32)VHOST= _DMA_DONE_LEN) =20 -static const u64 vhost_net_features[VIRTIO_FEATURES_U64S] =3D { - VHOST_FEATURES | - (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) | - (1ULL << VIRTIO_NET_F_MRG_RXBUF) | - (1ULL << VIRTIO_F_ACCESS_PLATFORM) | - (1ULL << VIRTIO_F_RING_RESET) | - (1ULL << VIRTIO_F_IN_ORDER), - VIRTIO_BIT(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) | - VIRTIO_BIT(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO), +static const int vhost_net_features[] =3D { + VHOST_FEATURES, + VHOST_NET_F_VIRTIO_NET_HDR, + VIRTIO_NET_F_MRG_RXBUF, + VIRTIO_F_ACCESS_PLATFORM, + VIRTIO_F_RING_RESET, + VIRTIO_F_IN_ORDER, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO }; =20 enum { @@ -1734,14 +1734,14 @@ static long vhost_net_ioctl(struct file *f, unsigne= d int ioctl, return -EFAULT; return vhost_net_set_backend(n, backend.index, backend.fd); case VHOST_GET_FEATURES: - features =3D vhost_net_features[0]; + features =3D VHOST_FEATURES_U64(vhost_net_features, 0); if (copy_to_user(featurep, &features, sizeof features)) return -EFAULT; return 0; case VHOST_SET_FEATURES: if (copy_from_user(&features, featurep, sizeof features)) return -EFAULT; - if (features & ~vhost_net_features[0]) + if (features & ~VHOST_FEATURES_U64(vhost_net_features, 0)) return -EOPNOTSUPP; =20 virtio_features_from_u64(all_features, features); @@ -1753,9 +1753,13 @@ static long vhost_net_ioctl(struct file *f, unsigned= int ioctl, /* Copy the net features, up to the user-provided buffer size */ argp +=3D sizeof(u64); copied =3D min(count, (u64)VIRTIO_FEATURES_U64S); - if (copy_to_user(argp, vhost_net_features, - copied * sizeof(u64))) - return -EFAULT; + + { + const DEFINE_VHOST_FEATURES_ARRAY(features, vhost_net_features); + + if (copy_to_user(argp, features, copied * sizeof(u64))) + return -EFAULT; + } =20 /* Zero the trailing space provided by user-space, if any */ if (clear_user(argp, size_mul(count - copied, sizeof(u64)))) @@ -1784,7 +1788,7 @@ static long vhost_net_ioctl(struct file *f, unsigned = int ioctl, } =20 for (i =3D 0; i < VIRTIO_FEATURES_U64S; i++) - if (all_features[i] & ~vhost_net_features[i]) + if (all_features[i] & ~VHOST_FEATURES_U64(vhost_net_features, i)) return -EOPNOTSUPP; =20 return vhost_net_set_features(n, all_features); diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 98e4f68f4e3c..04fcbe7efd77 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -197,11 +197,14 @@ enum { }; =20 /* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. = */ -enum { - VHOST_SCSI_FEATURES =3D VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG) | - (1ULL << VIRTIO_SCSI_F_T10_PI) +static const int vhost_scsi_features[] =3D { + VHOST_FEATURES, + VIRTIO_SCSI_F_HOTPLUG, + VIRTIO_SCSI_F_T10_PI }; =20 +#define VHOST_SCSI_FEATURES VHOST_FEATURES_U64(vhost_scsi_features, 0) + #define VHOST_SCSI_MAX_TARGET 256 #define VHOST_SCSI_MAX_IO_VQ 1024 #define VHOST_SCSI_MAX_EVENT 128 diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c index 42c955a5b211..af727fccfe40 100644 --- a/drivers/vhost/test.c +++ b/drivers/vhost/test.c @@ -308,6 +308,12 @@ static long vhost_test_set_backend(struct vhost_test *= n, unsigned index, int fd) return r; } =20 +static const int vhost_test_features[] =3D { + VHOST_FEATURES +}; + +#define VHOST_TEST_FEATURES VHOST_FEATURES_U64(vhost_test_features, 0) + static long vhost_test_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) { @@ -328,14 +334,14 @@ static long vhost_test_ioctl(struct file *f, unsigned= int ioctl, return -EFAULT; return vhost_test_set_backend(n, backend.index, backend.fd); case VHOST_GET_FEATURES: - features =3D VHOST_FEATURES; + features =3D VHOST_TEST_FEATURES; if (copy_to_user(featurep, &features, sizeof features)) return -EFAULT; return 0; case VHOST_SET_FEATURES: if (copy_from_user(&features, featurep, sizeof features)) return -EFAULT; - if (features & ~VHOST_FEATURES) + if (features & ~VHOST_TEST_FEATURES) return -EOPNOTSUPP; return vhost_test_set_features(n, features); case VHOST_RESET_OWNER: diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 621a6d9a8791..d8f1af9a0ff1 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -14,6 +14,7 @@ #include #include #include +#include =20 struct vhost_work; struct vhost_task; @@ -279,14 +280,39 @@ void vhost_iotlb_map_free(struct vhost_iotlb *iotlb, eventfd_signal((vq)->error_ctx);\ } while (0) =20 -enum { - VHOST_FEATURES =3D (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | - (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | - (1ULL << VIRTIO_RING_F_EVENT_IDX) | - (1ULL << VHOST_F_LOG_ALL) | - (1ULL << VIRTIO_F_ANY_LAYOUT) | - (1ULL << VIRTIO_F_VERSION_1) -}; +#define VHOST_FEATURES \ + VIRTIO_F_NOTIFY_ON_EMPTY, \ + VIRTIO_RING_F_INDIRECT_DESC, \ + VIRTIO_RING_F_EVENT_IDX, \ + VHOST_F_LOG_ALL, \ + VIRTIO_F_ANY_LAYOUT, \ + VIRTIO_F_VERSION_1 + +static inline u64 vhost_features_u64(const int *features, int size, int id= x) +{ + unsigned long res =3D 0; + + unrolled_count(VIRTIO_FEATURES_BITS) + for (int i =3D 0; i < size; ++i) { + int bit =3D features[i]; + + if (virtio_features_chk_bit(bit) && VIRTIO_U64(bit) =3D=3D idx) + res |=3D VIRTIO_BIT(bit); + } + return res; +} + +#define VHOST_FEATURES_U64(features, idx) \ + vhost_features_u64(features, ARRAY_SIZE(features), idx) + +#define DEFINE_VHOST_FEATURES_ARRAY_ENTRY(idx, features) \ + [idx] =3D VHOST_FEATURES_U64(features, idx), + +#define DEFINE_VHOST_FEATURES_ARRAY(array, features) \ + u64 array[VIRTIO_FEATURES_U64S] =3D { \ + UNROLL(VIRTIO_FEATURES_U64S, \ + DEFINE_VHOST_FEATURES_ARRAY_ENTRY, features) \ + } =20 /** * vhost_vq_set_backend - Set backend. diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index ae01457ea2cd..16662f2b87c1 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -29,12 +29,14 @@ */ #define VHOST_VSOCK_PKT_WEIGHT 256 =20 -enum { - VHOST_VSOCK_FEATURES =3D VHOST_FEATURES | - (1ULL << VIRTIO_F_ACCESS_PLATFORM) | - (1ULL << VIRTIO_VSOCK_F_SEQPACKET) +static const int vhost_vsock_features[] =3D { + VHOST_FEATURES, + VIRTIO_F_ACCESS_PLATFORM, + VIRTIO_VSOCK_F_SEQPACKET }; =20 +#define VHOST_VSOCK_FEATURES VHOST_FEATURES_U64(vhost_vsock_features, 0) + enum { VHOST_VSOCK_BACKEND_FEATURES =3D (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2) }; --=20 MST