Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+24 -20
+6 -5
drivers/lguest/lguest_device.c
··· 98 98 return features; 99 99 } 100 100 101 - static void lg_set_features(struct virtio_device *vdev, u32 features) 101 + static void lg_finalize_features(struct virtio_device *vdev) 102 102 { 103 - unsigned int i; 103 + unsigned int i, bits; 104 104 struct lguest_device_desc *desc = to_lgdev(vdev)->desc; 105 105 /* Second half of bitmap is features we accept. */ 106 106 u8 *out_features = lg_features(desc) + desc->feature_len; 107 107 108 108 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)) 111 112 out_features[i / 8] |= (1 << (i % 8)); 112 113 } 113 114 } ··· 298 297 /* The ops structure which hooks everything together. */ 299 298 static struct virtio_config_ops lguest_config_ops = { 300 299 .get_features = lg_get_features, 301 - .set_features = lg_set_features, 300 + .finalize_features = lg_finalize_features, 302 301 .get = lg_get, 303 302 .set = lg_set, 304 303 .get_status = lg_get_status,
+6 -5
drivers/s390/kvm/kvm_virtio.c
··· 88 88 return features; 89 89 } 90 90 91 - static void kvm_set_features(struct virtio_device *vdev, u32 features) 91 + static void kvm_finalize_features(struct virtio_device *vdev) 92 92 { 93 - unsigned int i; 93 + unsigned int i, bits; 94 94 struct kvm_device_desc *desc = to_kvmdev(vdev)->desc; 95 95 /* Second half of bitmap is features we accept. */ 96 96 u8 *out_features = kvm_vq_features(desc) + desc->feature_len; 97 97 98 98 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)) 101 102 out_features[i / 8] |= (1 << (i % 8)); 102 103 } 103 104 } ··· 224 223 */ 225 224 static struct virtio_config_ops kvm_vq_configspace_ops = { 226 225 .get_features = kvm_get_features, 227 - .set_features = kvm_set_features, 226 + .finalize_features = kvm_finalize_features, 228 227 .get = kvm_get, 229 228 .set = kvm_set, 230 229 .get_status = kvm_get_status,
+2 -3
drivers/virtio/virtio.c
··· 113 113 set_bit(f, dev->features); 114 114 } 115 115 116 - /* Transport features are always preserved to pass to set_features. */ 116 + /* Transport features always preserved to pass to finalize_features. */ 117 117 for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) 118 118 if (device_features & (1 << i)) 119 119 set_bit(i, dev->features); ··· 122 122 if (err) 123 123 add_status(dev, VIRTIO_CONFIG_S_FAILED); 124 124 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); 127 126 add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); 128 127 } 129 128 return err;
+6 -4
drivers/virtio/virtio_pci.c
··· 94 94 return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES); 95 95 } 96 96 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) 99 99 { 100 100 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 101 101 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); 103 105 } 104 106 105 107 /* virtio config->get() implementation */ ··· 299 297 .find_vq = vp_find_vq, 300 298 .del_vq = vp_del_vq, 301 299 .get_features = vp_get_features, 302 - .set_features = vp_set_features, 300 + .finalize_features = vp_finalize_features, 303 301 }; 304 302 305 303 /* the PCI probing function */
+4 -3
include/linux/virtio_config.h
··· 61 61 * @get_features: get the array of feature bits for this device. 62 62 * vdev: the virtio_device 63 63 * 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. 65 65 * 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. 67 68 */ 68 69 struct virtio_config_ops 69 70 { ··· 80 79 void (*callback)(struct virtqueue *)); 81 80 void (*del_vq)(struct virtqueue *vq); 82 81 u32 (*get_features)(struct virtio_device *vdev); 83 - void (*set_features)(struct virtio_device *vdev, u32 features); 82 + void (*finalize_features)(struct virtio_device *vdev); 84 83 }; 85 84 86 85 /* If driver didn't advertise the feature, it will never appear. */