Commit 9513f250 authored by Michael S. Tsirkin's avatar Michael S. Tsirkin
Browse files

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: e7d4c1c5 ("virtio: introduce extended features")
Cc: Paolo Abeni <pabeni@redhat.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Message-ID: <ad53b7b6be87fc524f45abaeca0bb05fb3633397.1764225384.git.mst@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 2828c60b
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"

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

static const u64 vhost_net_features[VIRTIO_FEATURES_DWORDS] = {
static const u64 vhost_net_features[VIRTIO_FEATURES_U64S] = {
	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 = f->private_data;
	void __user *argp = (void __user *)arg;
	u64 __user *featurep = argp;
@@ -1752,7 +1752,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,

		/* Copy the net features, up to the user-provided buffer size */
		argp += sizeof(u64);
		copied = min(count, VIRTIO_FEATURES_DWORDS);
		copied = 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, unsigned int ioctl,

		virtio_features_zero(all_features);
		argp += sizeof(u64);
		copied = min(count, VIRTIO_FEATURES_DWORDS);
		copied = min(count, (u64)VIRTIO_FEATURES_U64S);
		if (copy_from_user(all_features, argp, copied * sizeof(u64)))
			return -EFAULT;

		/*
		 * 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 = 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;
		}

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

+6 −6
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ static ssize_t features_show(struct device *_d,

	/* We actually represent this as a bitstring, as it could be
	 * arbitrary length in future. */
	for (i = 0; i < VIRTIO_FEATURES_MAX; i++)
	for (i = 0; i < VIRTIO_FEATURES_BITS; i++)
		len += sysfs_emit_at(buf, len, "%c",
			       __virtio_test_bit(dev, i) ? '1' : '0');
	len += 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 = dev_to_virtio(_d);
	struct virtio_driver *drv = 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;

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

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

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

	if (drv->validate) {
		u64 features[VIRTIO_FEATURES_DWORDS];
		u64 features[VIRTIO_FEATURES_U64S];

		virtio_features_copy(features, dev->features_array);
		err = drv->validate(dev);
+5 −5
Original line number Diff line number Diff line
@@ -8,12 +8,12 @@ static struct dentry *virtio_debugfs_dir;

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

	virtio_get_features(dev, device_features);
	for (i = 0; i < VIRTIO_FEATURES_MAX; i++) {
	for (i = 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_file *s, void *data)
	struct virtio_device *dev = s->private;
	unsigned int i;

	for (i = 0; i < VIRTIO_FEATURES_MAX; i++) {
	for (i = 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, u64 val)
{
	struct virtio_device *dev = data;

	if (val >= VIRTIO_FEATURES_MAX)
	if (val >= VIRTIO_FEATURES_BITS)
		return -EINVAL;

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

	if (val >= VIRTIO_FEATURES_MAX)
	if (val >= VIRTIO_FEATURES_BITS)
		return -EINVAL;

	virtio_features_clear_bit(dev->debugfs_filter_features, val);
+3 −3
Original line number Diff line number Diff line
@@ -401,7 +401,7 @@ void vp_modern_get_extended_features(struct virtio_pci_modern_device *mdev,
	int i;

	virtio_features_zero(features);
	for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) {
	for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
		u64 cur;

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

	virtio_features_zero(features);
	for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) {
	for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
		u64 cur;

		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 = mdev->common;
	int i;

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

		vp_iowrite32(i, &cfg->guest_feature_select);
+1 −1
Original line number Diff line number Diff line
@@ -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
};

Loading