From nobody Mon Dec 1 22:04:09 2025 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 4F816313295 for ; Thu, 27 Nov 2025 06:40:37 +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=1764225640; cv=none; b=arHjXPsrpR9WXUeMuvpdoVSlgUTcH/876Io6xKR7MfQekbMZUE5Ni7UCCmL7WcGS/kChYke6PmlG4OiIvX/oUUhynZd1QvjN3WM6IElXUqT9CWzNaiVNOCXHj6XZemdtLx+YPbB3YBC8bdxu5496d25OPc4zW1yqS/qByGFIxoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764225640; c=relaxed/simple; bh=ivUXO36DJq1dbC9CAEPa5O93ZoCOFhDovxe/PoQeME4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QBBOqYTAs096g/J2/kopiWIHzUFts1QIZ6h/0sv0IzmdOSLsw26oHVZ+6JhbqvrHKuxtycw5yIhRxYRNAdA3c75BELUsLJJQ3oHKeGK0eFupg8goSt3PegGk0X+0wQzElvzUtiT1Ef8fH2jqMPMQgEXwij+pL+FBhf/I3PBGA+I= 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=SDj4zmDA; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=mgU8XnlM; 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="SDj4zmDA"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="mgU8XnlM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764225637; 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=ixkqHa7UY4id+SD0ZRwvgJtg9ZQCnNOZWuNc83xEvBE=; b=SDj4zmDAdlgEd0svhPcjzK2Us5s3T7IHY6AJU/L3vie7RM1M3GqxW/njxHbHdPd2atAhtU oNfyaCcT8kK3Wa4zdepqbnRYekDpAL0eCKaj6QjWKHJ8dyjLJaZxK5tCTbdXN+MMNLBDSo 7R7HcVQV3ibTMBKcueLJQe1Nf4vThbw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-LDbMcIMfNG6bwqGE_3mvGg-1; Thu, 27 Nov 2025 01:40:35 -0500 X-MC-Unique: LDbMcIMfNG6bwqGE_3mvGg-1 X-Mimecast-MFC-AGG-ID: LDbMcIMfNG6bwqGE_3mvGg_1764225634 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-42b2fb13b79so251697f8f.3 for ; Wed, 26 Nov 2025 22:40:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764225634; x=1764830434; 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=ixkqHa7UY4id+SD0ZRwvgJtg9ZQCnNOZWuNc83xEvBE=; b=mgU8XnlMvxs9IW0DJbLT+4mkcXXxK1N0fdOz3bVJvR88JtC8rtbEmEsVBhkwVd1ogl l3zU12IupPGhs3celvPSmz7o70URFDGM2x27f0ybkkXKEvPak2qH+hgSkzgFVYCFwf87 YQHrwDu3xU6gkIPHC5MpZUXgMEYBwp75G6Viv2vYp7t+n2ziUeKGi/CU8W1mg/TODrJJ a3Iw9pQlnJZtXHrt6rOYWW1bCV3tQhqqeW4hatdrRQtF1c6QAFVVuE7YZhyGHuYyhejs jEbGcTEuX5UDKBJfdkv2yHRY3EL5Pmc+MXqxVuwQusiLOETh+cbfkoHrQ7cdSaH/Yruo DLZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764225634; x=1764830434; 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=ixkqHa7UY4id+SD0ZRwvgJtg9ZQCnNOZWuNc83xEvBE=; b=wb2dCP87O63gIIvX9dRZ8zZZq7tK5i2qMIfIKitIaI5AFz5MGSTV2+t2yLHLXeM3si ReydSL2zKrsiXfV4n0TsR07HUhSZvqe0KJJjPHSfy2BFzONFDaUTWon2RNTJeE1YBKUs sV/PYEC675w2/G75cjb+gNtxAc63cxkIMax3hU6RDV4hTFfJJFzQnj8fZhUvqiVEEFWr LxWV7e6LI1VmkMc16IRUGSP1F2kyDVTQw5wzUeCWVAZZ6mUK5dxOX+dqsxg1cW1oaaxi S2dKH7jYtjkH+SBqXxE5xpyMqr2BbhTJhDCbSAw6sj4gOhWeQmZQ2vC31SqrNqhPdlko fTTg== X-Gm-Message-State: AOJu0Yw0roiEWmdGyspu69idxZJWlilPssLxw+8NF6vE+x2n1+r1fQjc ufEbdGnX9VwrJz6FFC7ebfEO4CeuIDSJNJWel2YaTpvaqLSzaUDdMvZMn4bBOvP92ZK/iSWjpF1 zf+JoeapmzMaxTqnwyzfTdJEwcFBET4YErIDgwPIDucOls7whEGN2qB82SXnZMs3l9iicj+vWTH qMGM47WkqPU/dZLBIQR0fZzvxOo03G1CHXTP2+cggKwr0= X-Gm-Gg: ASbGncuXGpJNdTjs6c/dw8KOHzzJZ2922sHeb302xY9q/kwXUQtR4TFGLK4f9NDPGoA Ve7dC6QaeTYTaZYtHj4tLpEEidX68MITeIPDSy/tPJDbXn5nQNwfu58p5+5xTuX26IbYd/Svxk0 j3d9a1fP0rtEAV1syACDdIQ3OUpMApvHteZnNyTQifzwgBIP3c3cm5GfZRAr/Db3UFRHgVeve+g TgDGhW0aZi/37gySFrozVwtrcJ8hpkyhXBMqu1wuvUPlR6QET0gI7mbci7cxLFMGqWoYNokzV8q OGS3ZmL6HT7AQ1+E6+eNKUYQVO6RhuqRne2DUo9CmnsYmEWCAOJ2F7GR+JKqj58r4snWijLkb7j jttCUxXBHji/Qn5UF8pN2EbaAQIizsA== X-Received: by 2002:a05:6000:2584:b0:42b:2a09:2e59 with SMTP id ffacd0b85a97d-42cc19f0942mr23867969f8f.0.1764225633635; Wed, 26 Nov 2025 22:40:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHeII0KjZfqE/x5p5aVz7nAKQexoeFKp+f876+mbJSMjnNag/kZbcGgIiTKL8OMS1SQs7DKWw== X-Received: by 2002:a05:6000:2584:b0:42b:2a09:2e59 with SMTP id ffacd0b85a97d-42cc19f0942mr23867919f8f.0.1764225632944; Wed, 26 Nov 2025 22:40:32 -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-42e1c5d613esm1742574f8f.11.2025.11.26.22.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 22:40:32 -0800 (PST) Date: Thu, 27 Nov 2025 01:40:30 -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 v6 1/3] 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 Acked-by: Jason Wang Signed-off-by: Michael S. Tsirkin --- 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 Mon Dec 1 22:04:09 2025 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 08DB1314A6B for ; Thu, 27 Nov 2025 06:40:40 +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=1764225642; cv=none; b=hUIli88qsi1P6XkvQQNz3ahov+d85RDl3N4cP1Hs0bb9egTDAFVCCyupZLx1RgIFb/r1CMnRwUDyGG0lEUOHN++IVdGlSZtpeGzvlqzZVMqJ8wyPZi3fZDBG1qaQ9N227ORLvsg3KSisAOfmUI0AisHnmMJgEDgDPE8X2IesHgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764225642; c=relaxed/simple; bh=p4zBspV0umYpwlxraVSt9LbhsuCRfZnCfl2fUmVODfw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ib2+clSd7SOdqDCir6C/gtKL0aB0yhJVmd04pWrzwRHcSIiIywzr2j/pl+3lTxou+h4/jLwTYbTifVEZNQvVKPXhwUeEal2L2yfvXSG58lRspKot3xLW5U+CEcGhQQpBcVgJOiEfS4JVEZtDs4bV7vW08wJam62DZwMT9m5ymPU= 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=KqMckK5O; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hw6jYxpx; 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="KqMckK5O"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hw6jYxpx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764225639; 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=kFZFceCxodv+sVrwXshrWOSA01PvSJh54J0xHtV2LxM=; b=KqMckK5OlIm5OfN8CI+1xGSUykS/5rvlMMwlRrNABDokK3BrNXgZPkoqGQqh1RnbXiepVb fejs+f7Ek17gzRsvoiy/lXZwp0SZ897HnLP8lgYjHMrksmm8y68TwVjIu6c/xyg6f0qv8k XVz9jJC7sujuR9Hu6T/flc70aji5LJ4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-9Zy5EcNBNESCvsPEeWCQsg-1; Thu, 27 Nov 2025 01:40:37 -0500 X-MC-Unique: 9Zy5EcNBNESCvsPEeWCQsg-1 X-Mimecast-MFC-AGG-ID: 9Zy5EcNBNESCvsPEeWCQsg_1764225636 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-47106a388cfso2499865e9.0 for ; Wed, 26 Nov 2025 22:40:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764225636; x=1764830436; 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=kFZFceCxodv+sVrwXshrWOSA01PvSJh54J0xHtV2LxM=; b=hw6jYxpxwPKIFKJGvab+MkvyWyCbd827Ljgf6Dmmt8Hn0CT7rL62onmKBUd1VdHnAo YI3iylFQxACvau8rTBkosao51et2ddJBigJo1nTvpDc//3olZ3rQ801CGtD0TKVs/tb9 eX05AFNGoP3FLX/gpXgPkH2LHie0hflArld1mja6rZGRMmKGZo0fs+9ikG6g+14KXqd+ k5B29FvaR3vNimVFKMlOkk5bl8VMCJTDk42l6HNaWhQczgcHAly+X+FeRGpPhf+zxFiZ fkHQfI+81lEFGXyWG2WJmpgIdmCO3kSAIu8tB/E049IYipx3Yp3iKsFc/cXhCx5iXHLl Me6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764225636; x=1764830436; 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=kFZFceCxodv+sVrwXshrWOSA01PvSJh54J0xHtV2LxM=; b=G8gPsxrVL5IPx+4+TVNhND6wRffxKmtzYWpLlHzPWOyhsnaqtt7rmKw6r587M6aiis /yR1fKcSMZf6/N4dJ0bt/7U3QsZxRuTWQLfBJtAmSWZ0WHDEIvnG3Sn1UZ15gsko1Tsp XpML65SBb5ub/LfHl9xqYMkeT+KKUJGn3jnybHKH8onaRrFCnY3o51OOmtfiIwrEs7fA RYPOTFcW4cOlh4L91zocReIqnyrjg5cU8qMCtuH5zkfi3P973Khouiih7LWnhdImrHYz m65JAxJgwSD7rxAlo8x98MSquitseUgx+dzD65JaljOAFzYNs2FFl8JUbKhvyupvq1/Y ECCQ== X-Gm-Message-State: AOJu0YxPR+fy0yTBZ5Ww4cQwkoLMhdh3IwOkKXr9ta/AMKwCVIrlp47P CaCoVVuspwzeKWYxBAIfwJI4yYPGT8sE75NfZO6NOhb62MRQAg9Q/o7Eh0ceTtJ1hFHSpvH+1Fu eFG2C47uSbyZCXWknV1b44bfHnI+AiTC1YjobYVfiSQGfYtFzRERqQPtMrq/Powo3qA+NCF89nB F9dh4VPIrrU+ahgKHUo9qi/cGw1Qjyvjpn4ybc1n8DiP0= X-Gm-Gg: ASbGncuB/hqcga7r13wmiD9wLposUxjNCdwrjRxwhzuHYeYZ7e/R4NhWAUfN5BKKKdq 9wNIa1rnIm6e58+YY0ZBk9eM4Dc+BIeMd9oDmYADp9s66LcUmPSiXsnezyAlT9bfeUnfLfDhiKj 1L4k18jA3xctkBUwrDee4TvXD3kOGDlNDusaUgiiEDAMmqZxNiCpkRVbr0wWBxg0xODC3kn7d69 j28/39L0tiXQWKKE1HRCncwStgL545NU9nBFCkAwYHNsP+MEG+DHrA8dzmSVXynapyKAuKg/TzD +Pa5sVzdDPXqr0e+4QNpLCdc/wwGYq3T6n0MbKqASQ+AlmBezXvNDCzzC60Ojpcyj71GqXGN5fi B255s4jsgrNn3uN1AE97aXqylJ1iVzQ== X-Received: by 2002:a05:600c:3543:b0:477:1ae1:fa5d with SMTP id 5b1f17b1804b1-477c1142268mr180867465e9.20.1764225635959; Wed, 26 Nov 2025 22:40:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmaKJl3GPl1IrG9e+lyxemKaHO0wPm9ET8yhjMSTC9B7Xozmw3CvG5GdadD3czzW5PwSFbkA== X-Received: by 2002:a05:600c:3543:b0:477:1ae1:fa5d with SMTP id 5b1f17b1804b1-477c1142268mr180867165e9.20.1764225635290; Wed, 26 Nov 2025 22:40:35 -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-4790b0c44dcsm78642495e9.11.2025.11.26.22.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 22:40:34 -0800 (PST) Date: Thu, 27 Nov 2025 01:40:33 -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 v6 2/3] vhost/test: add test specific macro for features Message-ID: <23ca04512a800ee8b3594482492e536020931340.1764225384.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" test just uses vhost features with no change, but people tend to copy/paste code, so let's add our own define. Signed-off-by: Michael S. Tsirkin --- drivers/vhost/test.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c index 42c955a5b211..94cd09f36f59 100644 --- a/drivers/vhost/test.c +++ b/drivers/vhost/test.c @@ -28,6 +28,8 @@ */ #define VHOST_TEST_PKT_WEIGHT 256 =20 +#define VHOST_TEST_FEATURES VHOST_FEATURES + enum { VHOST_TEST_VQ =3D 0, VHOST_TEST_VQ_MAX =3D 1, @@ -328,14 +330,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: --=20 MST From nobody Mon Dec 1 22:04:09 2025 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 8E9F431690D for ; Thu, 27 Nov 2025 06:40:44 +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=1764225646; cv=none; b=SZRijjJy9iavP25EJ+AtyiWO9Ke1riuqW2aJsJkU0++vdgMEdnBXnbGHCrvikTzJkKIHbDCdIko7UUDCAxa8MzmMpK4KzbUSsrJnC2k+9pjEDaS3IY18mTZea6bF+CCXlS1h3FmDxOWiFvOzloV4TFaK6aAuvs0ZMxIQq3I2Vz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764225646; c=relaxed/simple; bh=6sJDh7TR0maQBdks2dSRada8nx8D+7jUwjltz8Ik4ms=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uU2J3knCFCV8o+FOmv1YJZ7pLDEcInNnoLnZTGwrEzz1NVv1EeyCGRyFd7ygJrRJX0zderjwAnafurlPVeFozjcWuxbB0Y3WRNe08P0GCQ6p1Tss0INHbHy9yXzoIhO7La4Df6BSEhV/JLDNhFHjPCzVmPy8pjsXFKoPu54FN34= 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=YsGhDTqP; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=a4bgkbIr; 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="YsGhDTqP"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="a4bgkbIr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764225643; 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=M+AVszRknLoY/jDDQOQpI/1Oya1cYB7+TjwgCKh4fLI=; b=YsGhDTqPAIjIOenEvtxU8k0YMqZbDJ+ntInVFfCJyUateTH5GWZGYn7zBdCApgr6xy18WN 0WFIdZvS+Kvys6KSrop2NfndPfBnwk7jXK5dvCGZ1/xX+oPqR5B0S6O1eyWJ4CV7o0ScIz C0re6/ZLI1JoSSMekxDWrYxYInVJE/0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-a6i8pJXyPo27WmI3l4nblw-1; Thu, 27 Nov 2025 01:40:40 -0500 X-MC-Unique: a6i8pJXyPo27WmI3l4nblw-1 X-Mimecast-MFC-AGG-ID: a6i8pJXyPo27WmI3l4nblw_1764225640 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-477cf2230c8so3885235e9.0 for ; Wed, 26 Nov 2025 22:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764225639; x=1764830439; 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=M+AVszRknLoY/jDDQOQpI/1Oya1cYB7+TjwgCKh4fLI=; b=a4bgkbIroaiQLUuX2xEWFOpDIRPbGgpdEJ8ODCSn2M9cWbTHE+D0W8iZyzEZ925Y7D WCDFWEUAt7yfRuF74o/X2qZmVD+6yi6DX6NRQ0/Yt3d3nOvY2745ZQMEGGZ9iY1vYeMf wxDNJxKujzB5wcwRPPkNsusdAITZ50nDrrhgZPPLs2whEHzlHR9I7+V8LBh6O8NG47HK aEbuh3y7u/mQHZlC8nWmDtuJmeeh23QDYFKSE9AcwdktY90D6U4wnOa4T+WsQvFhFSDw YoUhhpYY3VMawGdVxVJXWdxGjF0pglQG1kxMO9WMVCjKfTdHr7IQ4X9LM6+RELlQtHev vkZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764225639; x=1764830439; 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=M+AVszRknLoY/jDDQOQpI/1Oya1cYB7+TjwgCKh4fLI=; b=huHeq93rH4RIaXyy/wGY9HN1Ck+uh0nQlo/4PeeAN2B8RZssH8odFEZc8tuGrLxyTy SMMtZHZZ+BZvSkQp7IWKFekPI9woESajhesQvmKN5/5B7N4Xo4XVH8d/ne56nUKflKoo KDzJ3g3SyLpykrv2GFb4Rr0ibw3FFJFizeOMa42s6cv4oVaajEldUpH/+vUh9dU6018J OsV6BdWuCmhbN519OUV10MZalUqRk46aru3TA5TN93dbaQqVzviJbruwNOkNhUMcTGRc FK/11Ozb7OkpsXrXo3MP6e1bRJ66YVAOTWZIyUHfiWvlHAyxC6jnjGTEOtSZV+K8Sus/ 3YIg== X-Gm-Message-State: AOJu0YxwvNY+sNs69etVOVh/4OMqvREFFE6vPUicPEm1j0zpVIAQNR11 wmEvEgtu4dm/is+d8w+f5EHIGrNsOTiZXcxyj15M3x6eXLcRENsLR5LUvcz6ayCRh4nmt4UoM28 dVlrkdpcpsa0J8DqxKjKvAc8ee5pJJWuSrLNfBPvBPfkET8amkvGbHebk/vyh9zVODhpeL959Gz qdWHVIIlPKO8So6F1ZGwzDTP1mnkuAkGZOnN/6aeu1aBE= X-Gm-Gg: ASbGncuEucF09VBdZKOddudbn3DdnZME9nncKrAxk9Xh/a1ZeKC4XTaCwHw9077rjbD IDgWrIN3J68//aq+FtZJ6pXJiOQaMMBh8pYq5uqDGEMjc2z7oc+6lNfmPNDLqPH9ymDVvV7uRpv o+J9WP3CngOaRcfjLk9gCH+DIildj2Q7ji8EjwhoYaSqxBfs1fLEivAd/1uhHw7GAKZCdi9phwl xUTddyjTX5620gxpnJJhcpt2XSy9lZxjmJ25vaDX0BbTyaTVu7UsveQs+hA18G0NQgW+fXUut8v kFmShJBfsazuTxSebY0jPppfMo+GakmSOICyLBkUDhdiEOfxtDaixLnPitd9jTcpcyxmjdCWPD8 HxAIxVC0SQASjRy2aRObdCuVOjG2H1w== X-Received: by 2002:a05:600c:4f48:b0:471:115e:87bd with SMTP id 5b1f17b1804b1-47904b2494cmr86357085e9.26.1764225639483; Wed, 26 Nov 2025 22:40:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIc2HWl1bEZAW98bVde7+vw9sLlCeonr8va9/QQZdNQY3M7yfM4XWOaGQlBJyuh5tTNCFGXw== X-Received: by 2002:a05:600c:4f48:b0:471:115e:87bd with SMTP id 5b1f17b1804b1-47904b2494cmr86356645e9.26.1764225638741; Wed, 26 Nov 2025 22:40:38 -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-4790b0c44dcsm78644225e9.11.2025.11.26.22.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 22:40:38 -0800 (PST) Date: Thu, 27 Nov 2025 01:40:35 -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 v6 3/3] vhost: switch to arrays of feature bits Message-ID: <637e182e139980e5930d50b928ba5ac072d628a9.1764225384.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 | 19 ++++++++++--------- drivers/vhost/scsi.c | 9 ++++++--- drivers/vhost/test.c | 6 +++++- drivers/vhost/vhost.h | 42 ++++++++++++++++++++++++++++++++++-------- drivers/vhost/vsock.c | 10 ++++++---- 5 files changed, 61 insertions(+), 25 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index d057ea55f5ad..f8ed39337f56 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_bits[] =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 { @@ -1720,6 +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) { + const DEFINE_VHOST_FEATURES_ARRAY(vhost_net_features, vhost_net_bits); u64 all_features[VIRTIO_FEATURES_U64S]; struct vhost_net *n =3D f->private_data; void __user *argp =3D (void __user *)arg; diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 98e4f68f4e3c..f43c1fe9fad9 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_bits[] =3D { + VHOST_FEATURES, + VIRTIO_SCSI_F_HOTPLUG, + VIRTIO_SCSI_F_T10_PI }; =20 +#define VHOST_SCSI_FEATURES VHOST_FEATURES_U64(vhost_scsi_bits, 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 94cd09f36f59..f592b2f548e8 100644 --- a/drivers/vhost/test.c +++ b/drivers/vhost/test.c @@ -28,7 +28,11 @@ */ #define VHOST_TEST_PKT_WEIGHT 256 =20 -#define VHOST_TEST_FEATURES VHOST_FEATURES +static const int vhost_test_bits[] =3D { + VHOST_FEATURES +}; + +#define VHOST_TEST_FEATURES VHOST_FEATURES_U64(vhost_test_features, 0) =20 enum { VHOST_TEST_VQ =3D 0, diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 621a6d9a8791..c7b92730668e 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) +{ + u64 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..0298ddc34824 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_bits[] =3D { + VHOST_FEATURES, + VIRTIO_F_ACCESS_PLATFORM, + VIRTIO_VSOCK_F_SEQPACKET }; =20 +#define VHOST_VSOCK_FEATURES VHOST_FEATURES_U64(vhost_vsock_bits, 0) + enum { VHOST_VSOCK_BACKEND_FEATURES =3D (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2) }; --=20 MST