Skip to content

Commit c624896

Browse files
committed
virtio: Rename set_features to finalize_features
Rather than explicitly handing the features to the lower-level, we just hand the virtio_device and have it set the features. This make it clear that it has the chance to manipulate the features of the device at this point (and that all feature negotiation is already done). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent dd7c7bc commit c624896

5 files changed

Lines changed: 24 additions & 20 deletions

File tree

‎drivers/lguest/lguest_device.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,17 @@ static u32 lg_get_features(struct virtio_device *vdev)
9898
return features;
9999
}
100100

101-
static void lg_set_features(struct virtio_device *vdev, u32 features)
101+
static void lg_finalize_features(struct virtio_device *vdev)
102102
{
103-
unsigned int i;
103+
unsigned int i, bits;
104104
struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
105105
/* Second half of bitmap is features we accept. */
106106
u8 *out_features = lg_features(desc) + desc->feature_len;
107107

108108
memset(out_features, 0, desc->feature_len);
109-
for (i = 0; i < min(desc->feature_len * 8, 32); i++) {
110-
if (features & (1 << i))
109+
bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
110+
for (i = 0; i < bits; i++) {
111+
if (test_bit(i, vdev->features))
111112
out_features[i / 8] |= (1 << (i % 8));
112113
}
113114
}
@@ -297,7 +298,7 @@ static void lg_del_vq(struct virtqueue *vq)
297298
/* The ops structure which hooks everything together. */
298299
static struct virtio_config_ops lguest_config_ops = {
299300
.get_features = lg_get_features,
300-
.set_features = lg_set_features,
301+
.finalize_features = lg_finalize_features,
301302
.get = lg_get,
302303
.set = lg_set,
303304
.get_status = lg_get_status,

‎drivers/s390/kvm/kvm_virtio.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ static u32 kvm_get_features(struct virtio_device *vdev)
8888
return features;
8989
}
9090

91-
static void kvm_set_features(struct virtio_device *vdev, u32 features)
91+
static void kvm_finalize_features(struct virtio_device *vdev)
9292
{
93-
unsigned int i;
93+
unsigned int i, bits;
9494
struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
9595
/* Second half of bitmap is features we accept. */
9696
u8 *out_features = kvm_vq_features(desc) + desc->feature_len;
9797

9898
memset(out_features, 0, desc->feature_len);
99-
for (i = 0; i < min(desc->feature_len * 8, 32); i++) {
100-
if (features & (1 << i))
99+
bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
100+
for (i = 0; i < bits; i++) {
101+
if (test_bit(i, vdev->features))
101102
out_features[i / 8] |= (1 << (i % 8));
102103
}
103104
}
@@ -223,7 +224,7 @@ static void kvm_del_vq(struct virtqueue *vq)
223224
*/
224225
static struct virtio_config_ops kvm_vq_configspace_ops = {
225226
.get_features = kvm_get_features,
226-
.set_features = kvm_set_features,
227+
.finalize_features = kvm_finalize_features,
227228
.get = kvm_get,
228229
.set = kvm_set,
229230
.get_status = kvm_get_status,

‎drivers/virtio/virtio.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int virtio_dev_probe(struct device *_d)
113113
set_bit(f, dev->features);
114114
}
115115

116-
/* Transport features are always preserved to pass to set_features. */
116+
/* Transport features always preserved to pass to finalize_features. */
117117
for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
118118
if (device_features & (1 << i))
119119
set_bit(i, dev->features);
@@ -122,8 +122,7 @@ static int virtio_dev_probe(struct device *_d)
122122
if (err)
123123
add_status(dev, VIRTIO_CONFIG_S_FAILED);
124124
else {
125-
/* They should never have set feature bits beyond 32 */
126-
dev->config->set_features(dev, dev->features[0]);
125+
dev->config->finalize_features(dev);
127126
add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
128127
}
129128
return err;

‎drivers/virtio/virtio_pci.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ static u32 vp_get_features(struct virtio_device *vdev)
9494
return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
9595
}
9696

97-
/* virtio config->set_features() implementation */
98-
static void vp_set_features(struct virtio_device *vdev, u32 features)
97+
/* virtio config->finalize_features() implementation */
98+
static void vp_finalize_features(struct virtio_device *vdev)
9999
{
100100
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
101101

102-
iowrite32(features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
102+
/* We only support 32 feature bits. */
103+
BUILD_BUG_ON(ARRAY_SIZE(vdev->features) != 1);
104+
iowrite32(vdev->features[0], vp_dev->ioaddr+VIRTIO_PCI_GUEST_FEATURES);
103105
}
104106

105107
/* virtio config->get() implementation */
@@ -297,7 +299,7 @@ static struct virtio_config_ops virtio_pci_config_ops = {
297299
.find_vq = vp_find_vq,
298300
.del_vq = vp_del_vq,
299301
.get_features = vp_get_features,
300-
.set_features = vp_set_features,
302+
.finalize_features = vp_finalize_features,
301303
};
302304

303305
/* the PCI probing function */

‎include/linux/virtio_config.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@
6161
* @get_features: get the array of feature bits for this device.
6262
* vdev: the virtio_device
6363
* Returns the first 32 feature bits (all we currently need).
64-
* @set_features: confirm what device features we'll be using.
64+
* @finalize_features: confirm what device features we'll be using.
6565
* vdev: the virtio_device
66-
* feature: the first 32 feature bits
66+
* This gives the final feature bits for the device: it can change
67+
* the dev->feature bits if it wants.
6768
*/
6869
struct virtio_config_ops
6970
{
@@ -79,7 +80,7 @@ struct virtio_config_ops
7980
void (*callback)(struct virtqueue *));
8081
void (*del_vq)(struct virtqueue *vq);
8182
u32 (*get_features)(struct virtio_device *vdev);
82-
void (*set_features)(struct virtio_device *vdev, u32 features);
83+
void (*finalize_features)(struct virtio_device *vdev);
8384
};
8485

8586
/* If driver didn't advertise the feature, it will never appear. */

0 commit comments

Comments
 (0)