Skip to content

Commit 9513f25

Browse files
committed
virtio: clean up features qword/dword terms
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: e7d4c1c ("virtio: introduce extended features") Cc: Paolo Abeni <pabeni@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com> Message-ID: <ad53b7b6be87fc524f45abaeca0bb05fb3633397.1764225384.git.mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 2828c60 commit 9513f25

8 files changed

Lines changed: 41 additions & 40 deletions

File tree

drivers/vhost/net.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
6969

7070
#define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >= (__force u32)VHOST_DMA_DONE_LEN)
7171

72-
static const u64 vhost_net_features[VIRTIO_FEATURES_DWORDS] = {
72+
static const u64 vhost_net_features[VIRTIO_FEATURES_U64S] = {
7373
VHOST_FEATURES |
7474
(1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
7575
(1ULL << VIRTIO_NET_F_MRG_RXBUF) |
@@ -1720,7 +1720,7 @@ static long vhost_net_set_owner(struct vhost_net *n)
17201720
static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17211721
unsigned long arg)
17221722
{
1723-
u64 all_features[VIRTIO_FEATURES_DWORDS];
1723+
u64 all_features[VIRTIO_FEATURES_U64S];
17241724
struct vhost_net *n = f->private_data;
17251725
void __user *argp = (void __user *)arg;
17261726
u64 __user *featurep = argp;
@@ -1752,7 +1752,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17521752

17531753
/* Copy the net features, up to the user-provided buffer size */
17541754
argp += sizeof(u64);
1755-
copied = min(count, VIRTIO_FEATURES_DWORDS);
1755+
copied = min(count, (u64)VIRTIO_FEATURES_U64S);
17561756
if (copy_to_user(argp, vhost_net_features,
17571757
copied * sizeof(u64)))
17581758
return -EFAULT;
@@ -1767,13 +1767,13 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17671767

17681768
virtio_features_zero(all_features);
17691769
argp += sizeof(u64);
1770-
copied = min(count, VIRTIO_FEATURES_DWORDS);
1770+
copied = min(count, (u64)VIRTIO_FEATURES_U64S);
17711771
if (copy_from_user(all_features, argp, copied * sizeof(u64)))
17721772
return -EFAULT;
17731773

17741774
/*
17751775
* Any feature specified by user-space above
1776-
* VIRTIO_FEATURES_MAX is not supported by definition.
1776+
* VIRTIO_FEATURES_BITS is not supported by definition.
17771777
*/
17781778
for (i = copied; i < count; ++i) {
17791779
if (copy_from_user(&features, featurep + 1 + i,
@@ -1783,7 +1783,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17831783
return -EOPNOTSUPP;
17841784
}
17851785

1786-
for (i = 0; i < VIRTIO_FEATURES_DWORDS; i++)
1786+
for (i = 0; i < VIRTIO_FEATURES_U64S; i++)
17871787
if (all_features[i] & ~vhost_net_features[i])
17881788
return -EOPNOTSUPP;
17891789

drivers/virtio/virtio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static ssize_t features_show(struct device *_d,
5353

5454
/* We actually represent this as a bitstring, as it could be
5555
* arbitrary length in future. */
56-
for (i = 0; i < VIRTIO_FEATURES_MAX; i++)
56+
for (i = 0; i < VIRTIO_FEATURES_BITS; i++)
5757
len += sysfs_emit_at(buf, len, "%c",
5858
__virtio_test_bit(dev, i) ? '1' : '0');
5959
len += sysfs_emit_at(buf, len, "\n");
@@ -272,8 +272,8 @@ static int virtio_dev_probe(struct device *_d)
272272
int err, i;
273273
struct virtio_device *dev = dev_to_virtio(_d);
274274
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
275-
u64 device_features[VIRTIO_FEATURES_DWORDS];
276-
u64 driver_features[VIRTIO_FEATURES_DWORDS];
275+
u64 device_features[VIRTIO_FEATURES_U64S];
276+
u64 driver_features[VIRTIO_FEATURES_U64S];
277277
u64 driver_features_legacy;
278278

279279
/* We have a driver! */
@@ -286,7 +286,7 @@ static int virtio_dev_probe(struct device *_d)
286286
virtio_features_zero(driver_features);
287287
for (i = 0; i < drv->feature_table_size; i++) {
288288
unsigned int f = drv->feature_table[i];
289-
if (!WARN_ON_ONCE(f >= VIRTIO_FEATURES_MAX))
289+
if (!WARN_ON_ONCE(f >= VIRTIO_FEATURES_BITS))
290290
virtio_features_set_bit(driver_features, f);
291291
}
292292

@@ -303,7 +303,7 @@ static int virtio_dev_probe(struct device *_d)
303303
}
304304

305305
if (virtio_features_test_bit(device_features, VIRTIO_F_VERSION_1)) {
306-
for (i = 0; i < VIRTIO_FEATURES_DWORDS; ++i)
306+
for (i = 0; i < VIRTIO_FEATURES_U64S; ++i)
307307
dev->features_array[i] = driver_features[i] &
308308
device_features[i];
309309
} else {
@@ -325,7 +325,7 @@ static int virtio_dev_probe(struct device *_d)
325325
goto err;
326326

327327
if (drv->validate) {
328-
u64 features[VIRTIO_FEATURES_DWORDS];
328+
u64 features[VIRTIO_FEATURES_U64S];
329329

330330
virtio_features_copy(features, dev->features_array);
331331
err = drv->validate(dev);

drivers/virtio/virtio_debug.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ static struct dentry *virtio_debugfs_dir;
88

99
static int virtio_debug_device_features_show(struct seq_file *s, void *data)
1010
{
11-
u64 device_features[VIRTIO_FEATURES_DWORDS];
11+
u64 device_features[VIRTIO_FEATURES_U64S];
1212
struct virtio_device *dev = s->private;
1313
unsigned int i;
1414

1515
virtio_get_features(dev, device_features);
16-
for (i = 0; i < VIRTIO_FEATURES_MAX; i++) {
16+
for (i = 0; i < VIRTIO_FEATURES_BITS; i++) {
1717
if (virtio_features_test_bit(device_features, i))
1818
seq_printf(s, "%u\n", i);
1919
}
@@ -26,7 +26,7 @@ static int virtio_debug_filter_features_show(struct seq_file *s, void *data)
2626
struct virtio_device *dev = s->private;
2727
unsigned int i;
2828

29-
for (i = 0; i < VIRTIO_FEATURES_MAX; i++) {
29+
for (i = 0; i < VIRTIO_FEATURES_BITS; i++) {
3030
if (virtio_features_test_bit(dev->debugfs_filter_features, i))
3131
seq_printf(s, "%u\n", i);
3232
}
@@ -50,7 +50,7 @@ static int virtio_debug_filter_feature_add(void *data, u64 val)
5050
{
5151
struct virtio_device *dev = data;
5252

53-
if (val >= VIRTIO_FEATURES_MAX)
53+
if (val >= VIRTIO_FEATURES_BITS)
5454
return -EINVAL;
5555

5656
virtio_features_set_bit(dev->debugfs_filter_features, val);
@@ -64,7 +64,7 @@ static int virtio_debug_filter_feature_del(void *data, u64 val)
6464
{
6565
struct virtio_device *dev = data;
6666

67-
if (val >= VIRTIO_FEATURES_MAX)
67+
if (val >= VIRTIO_FEATURES_BITS)
6868
return -EINVAL;
6969

7070
virtio_features_clear_bit(dev->debugfs_filter_features, val);

drivers/virtio/virtio_pci_modern_dev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void vp_modern_get_extended_features(struct virtio_pci_modern_device *mdev,
401401
int i;
402402

403403
virtio_features_zero(features);
404-
for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) {
404+
for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
405405
u64 cur;
406406

407407
vp_iowrite32(i, &cfg->device_feature_select);
@@ -427,7 +427,7 @@ vp_modern_get_driver_extended_features(struct virtio_pci_modern_device *mdev,
427427
int i;
428428

429429
virtio_features_zero(features);
430-
for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) {
430+
for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
431431
u64 cur;
432432

433433
vp_iowrite32(i, &cfg->guest_feature_select);
@@ -448,7 +448,7 @@ void vp_modern_set_extended_features(struct virtio_pci_modern_device *mdev,
448448
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
449449
int i;
450450

451-
for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) {
451+
for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
452452
u32 cur = features[i >> 1] >> (32 * (i & 1));
453453

454454
vp_iowrite32(i, &cfg->guest_feature_select);

include/linux/virtio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ struct virtio_device {
177177
union virtio_map vmap;
178178
#ifdef CONFIG_VIRTIO_DEBUG
179179
struct dentry *debugfs_dir;
180-
u64 debugfs_filter_features[VIRTIO_FEATURES_DWORDS];
180+
u64 debugfs_filter_features[VIRTIO_FEATURES_U64S];
181181
#endif
182182
};
183183

include/linux/virtio_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct virtqueue_info {
8080
* Returns the first 64 feature bits.
8181
* @get_extended_features:
8282
* vdev: the virtio_device
83-
* Returns the first VIRTIO_FEATURES_MAX feature bits (all we currently
83+
* Returns the first VIRTIO_FEATURES_BITS feature bits (all we currently
8484
* need).
8585
* @finalize_features: confirm what device features we'll be using.
8686
* vdev: the virtio_device

include/linux/virtio_features.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
#include <linux/bits.h>
66

7-
#define VIRTIO_FEATURES_DWORDS 2
8-
#define VIRTIO_FEATURES_MAX (VIRTIO_FEATURES_DWORDS * 64)
9-
#define VIRTIO_FEATURES_WORDS (VIRTIO_FEATURES_DWORDS * 2)
7+
#define VIRTIO_FEATURES_U64S 2
8+
#define VIRTIO_FEATURES_BITS (VIRTIO_FEATURES_U64S * 64)
9+
1010
#define VIRTIO_BIT(b) BIT_ULL((b) & 0x3f)
11-
#define VIRTIO_DWORD(b) ((b) >> 6)
11+
#define VIRTIO_U64(b) ((b) >> 6)
12+
1213
#define VIRTIO_DECLARE_FEATURES(name) \
1314
union { \
1415
u64 name; \
15-
u64 name##_array[VIRTIO_FEATURES_DWORDS];\
16+
u64 name##_array[VIRTIO_FEATURES_U64S];\
1617
}
1718

1819
static inline bool virtio_features_chk_bit(unsigned int bit)
@@ -22,9 +23,9 @@ static inline bool virtio_features_chk_bit(unsigned int bit)
2223
* Don't care returning the correct value: the build
2324
* will fail before any bad features access
2425
*/
25-
BUILD_BUG_ON(bit >= VIRTIO_FEATURES_MAX);
26+
BUILD_BUG_ON(bit >= VIRTIO_FEATURES_BITS);
2627
} else {
27-
if (WARN_ON_ONCE(bit >= VIRTIO_FEATURES_MAX))
28+
if (WARN_ON_ONCE(bit >= VIRTIO_FEATURES_BITS))
2829
return false;
2930
}
3031
return true;
@@ -34,26 +35,26 @@ static inline bool virtio_features_test_bit(const u64 *features,
3435
unsigned int bit)
3536
{
3637
return virtio_features_chk_bit(bit) &&
37-
!!(features[VIRTIO_DWORD(bit)] & VIRTIO_BIT(bit));
38+
!!(features[VIRTIO_U64(bit)] & VIRTIO_BIT(bit));
3839
}
3940

4041
static inline void virtio_features_set_bit(u64 *features,
4142
unsigned int bit)
4243
{
4344
if (virtio_features_chk_bit(bit))
44-
features[VIRTIO_DWORD(bit)] |= VIRTIO_BIT(bit);
45+
features[VIRTIO_U64(bit)] |= VIRTIO_BIT(bit);
4546
}
4647

4748
static inline void virtio_features_clear_bit(u64 *features,
4849
unsigned int bit)
4950
{
5051
if (virtio_features_chk_bit(bit))
51-
features[VIRTIO_DWORD(bit)] &= ~VIRTIO_BIT(bit);
52+
features[VIRTIO_U64(bit)] &= ~VIRTIO_BIT(bit);
5253
}
5354

5455
static inline void virtio_features_zero(u64 *features)
5556
{
56-
memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_DWORDS);
57+
memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_U64S);
5758
}
5859

5960
static inline void virtio_features_from_u64(u64 *features, u64 from)
@@ -66,22 +67,22 @@ static inline bool virtio_features_equal(const u64 *f1, const u64 *f2)
6667
{
6768
int i;
6869

69-
for (i = 0; i < VIRTIO_FEATURES_DWORDS; ++i)
70+
for (i = 0; i < VIRTIO_FEATURES_U64S; ++i)
7071
if (f1[i] != f2[i])
7172
return false;
7273
return true;
7374
}
7475

7576
static inline void virtio_features_copy(u64 *to, const u64 *from)
7677
{
77-
memcpy(to, from, sizeof(to[0]) * VIRTIO_FEATURES_DWORDS);
78+
memcpy(to, from, sizeof(to[0]) * VIRTIO_FEATURES_U64S);
7879
}
7980

8081
static inline void virtio_features_andnot(u64 *to, const u64 *f1, const u64 *f2)
8182
{
8283
int i;
8384

84-
for (i = 0; i < VIRTIO_FEATURES_DWORDS; i++)
85+
for (i = 0; i < VIRTIO_FEATURES_U64S; i++)
8586
to[i] = f1[i] & ~f2[i];
8687
}
8788

include/linux/virtio_pci_modern.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void vp_modern_set_extended_features(struct virtio_pci_modern_device *mdev,
107107
static inline u64
108108
vp_modern_get_features(struct virtio_pci_modern_device *mdev)
109109
{
110-
u64 features_array[VIRTIO_FEATURES_DWORDS];
110+
u64 features_array[VIRTIO_FEATURES_U64S];
111111

112112
vp_modern_get_extended_features(mdev, features_array);
113113
return features_array[0];
@@ -116,19 +116,19 @@ vp_modern_get_features(struct virtio_pci_modern_device *mdev)
116116
static inline u64
117117
vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev)
118118
{
119-
u64 features_array[VIRTIO_FEATURES_DWORDS];
119+
u64 features_array[VIRTIO_FEATURES_U64S];
120120
int i;
121121

122122
vp_modern_get_driver_extended_features(mdev, features_array);
123-
for (i = 1; i < VIRTIO_FEATURES_DWORDS; ++i)
123+
for (i = 1; i < VIRTIO_FEATURES_U64S; ++i)
124124
WARN_ON_ONCE(features_array[i]);
125125
return features_array[0];
126126
}
127127

128128
static inline void
129129
vp_modern_set_features(struct virtio_pci_modern_device *mdev, u64 features)
130130
{
131-
u64 features_array[VIRTIO_FEATURES_DWORDS];
131+
u64 features_array[VIRTIO_FEATURES_U64S];
132132

133133
virtio_features_from_u64(features_array, features);
134134
vp_modern_set_extended_features(mdev, features_array);

0 commit comments

Comments
 (0)