Replace cf_mutex with rw_semaphore to reflect the fact that some calls could be called concurrently but can suffice with read lock.
Unified · Split
| @@ -23,9 +23,9 @@ static DEFINE_IDA(vdpa_index_ida); · 22 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | void vdpa_set_status(struct vdpa_device *vdev, u8 status) |
| 25 | 25 | { |
| 26 | − mutex_lock(&vdev->cf_mutex); | |
| 26 | + down_write(&vdev->cf_lock); | |
| 27 | 27 | vdev->config->set_status(vdev, status); |
| 28 | − mutex_unlock(&vdev->cf_mutex); | |
| 28 | + up_write(&vdev->cf_lock); | |
| 29 | 29 | } |
| 30 | 30 | EXPORT_SYMBOL(vdpa_set_status); |
| 31 | 31 | |
| @@ -148,7 +148,6 @@ static void vdpa_release_dev(struct device *d) · 116 unmodified lines | ||
| 148 | 148 | ops->free(vdev); |
| 149 | 149 | |
| 150 | 150 | ida_simple_remove(&vdpa_index_ida, vdev->index); |
| 151 | − mutex_destroy(&vdev->cf_mutex); | |
| 152 | 151 | kfree(vdev->driver_override); |
| 153 | 152 | kfree(vdev); |
| 154 | 153 | } |
| @@ -211,7 +210,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, · 56 unmodified lines | ||
| 211 | 210 | if (err) |
| 212 | 211 | goto err_name; |
| 213 | 212 | |
| 214 | − mutex_init(&vdev->cf_mutex); | |
| 213 | + init_rwsem(&vdev->cf_lock); | |
| 215 | 214 | device_initialize(&vdev->dev); |
| 216 | 215 | |
| 217 | 216 | return vdev; |
| @@ -407,9 +406,9 @@ static void vdpa_get_config_unlocked(struct vdpa_device *vdev, · 189 unmodified lines | ||
| 407 | 406 | void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, |
| 408 | 407 | void *buf, unsigned int len) |
| 409 | 408 | { |
| 410 | − mutex_lock(&vdev->cf_mutex); | |
| 409 | + down_read(&vdev->cf_lock); | |
| 411 | 410 | vdpa_get_config_unlocked(vdev, offset, buf, len); |
| 412 | − mutex_unlock(&vdev->cf_mutex); | |
| 411 | + up_read(&vdev->cf_lock); | |
| 413 | 412 | } |
| 414 | 413 | EXPORT_SYMBOL_GPL(vdpa_get_config); |
| 415 | 414 | |
| @@ -423,9 +422,9 @@ EXPORT_SYMBOL_GPL(vdpa_get_config); · 7 unmodified lines | ||
| 423 | 422 | void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, |
| 424 | 423 | const void *buf, unsigned int length) |
| 425 | 424 | { |
| 426 | − mutex_lock(&vdev->cf_mutex); | |
| 425 | + down_write(&vdev->cf_lock); | |
| 427 | 426 | vdev->config->set_config(vdev, offset, buf, length); |
| 428 | − mutex_unlock(&vdev->cf_mutex); | |
| 427 | + up_write(&vdev->cf_lock); | |
| 429 | 428 | } |
| 430 | 429 | EXPORT_SYMBOL_GPL(vdpa_set_config); |
| 431 | 430 | |
| @@ -866,7 +865,7 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · 434 unmodified lines | ||
| 866 | 865 | u8 status; |
| 867 | 866 | int err; |
| 868 | 867 | |
| 869 | − mutex_lock(&vdev->cf_mutex); | |
| 868 | + down_read(&vdev->cf_lock); | |
| 870 | 869 | status = vdev->config->get_status(vdev); |
| 871 | 870 | if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) { |
| 872 | 871 | NL_SET_ERR_MSG_MOD(extack, "Features negotiation not completed"); |
| @@ -903,14 +902,14 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · 30 unmodified lines | ||
| 903 | 902 | if (err) |
| 904 | 903 | goto msg_err; |
| 905 | 904 | |
| 906 | − mutex_unlock(&vdev->cf_mutex); | |
| 905 | + up_read(&vdev->cf_lock); | |
| 907 | 906 | genlmsg_end(msg, hdr); |
| 908 | 907 | return 0; |
| 909 | 908 | |
| 910 | 909 | msg_err: |
| 911 | 910 | genlmsg_cancel(msg, hdr); |
| 912 | 911 | out: |
| 913 | − mutex_unlock(&vdev->cf_mutex); | |
| 912 | + up_read(&vdev->cf_lock); | |
| 914 | 913 | return err; |
| 915 | 914 | } |
| 916 | 915 | |
| @@ -954,7 +953,7 @@ static int vendor_stats_fill(struct vdpa_device *vdev, struct sk_buff *msg, · 37 unmodified lines | ||
| 954 | 953 | { |
| 955 | 954 | int err; |
| 956 | 955 | |
| 957 | − mutex_lock(&vdev->cf_mutex); | |
| 956 | + down_read(&vdev->cf_lock); | |
| 958 | 957 | if (!vdev->config->get_vendor_vq_stats) { |
| 959 | 958 | err = -EOPNOTSUPP; |
| 960 | 959 | goto out; |
| @@ -962,7 +961,7 @@ static int vendor_stats_fill(struct vdpa_device *vdev, struct sk_buff *msg, · 1 unmodified line | ||
| 962 | 961 | |
| 963 | 962 | err = vdpa_fill_stats_rec(vdev, msg, info, index); |
| 964 | 963 | out: |
| 965 | − mutex_unlock(&vdev->cf_mutex); | |
| 964 | + up_read(&vdev->cf_lock); | |
| 966 | 965 | return err; |
| 967 | 966 | } |
| 968 | 967 | |
| @@ -66,7 +66,7 @@ struct vdpa_mgmt_dev; · 65 unmodified lines | ||
| 66 | 66 | * @dma_dev: the actual device that is performing DMA |
| 67 | 67 | * @driver_override: driver name to force a match |
| 68 | 68 | * @config: the configuration ops for this device. |
| 69 | − * @cf_mutex: Protects get and set access to configuration layout. | |
| 69 | + * @cf_lock: Protects get and set access to configuration layout. | |
| 70 | 70 | * @index: device index |
| 71 | 71 | * @features_valid: were features initialized? for legacy guests |
| 72 | 72 | * @use_va: indicate whether virtual address must be used by this device |
| @@ -79,7 +79,7 @@ struct vdpa_device { · 6 unmodified lines | ||
| 79 | 79 | struct device *dma_dev; |
| 80 | 80 | const char *driver_override; |
| 81 | 81 | const struct vdpa_config_ops *config; |
| 82 | − struct mutex cf_mutex; /* Protects get/set config */ | |
| 82 | + struct rw_semaphore cf_lock; /* Protects get/set config */ | |
| 83 | 83 | unsigned int index; |
| 84 | 84 | bool features_valid; |
| 85 | 85 | bool use_va; |
| @@ -398,10 +398,10 @@ static inline int vdpa_reset(struct vdpa_device *vdev) · 312 unmodified lines | ||
| 398 | 398 | const struct vdpa_config_ops *ops = vdev->config; |
| 399 | 399 | int ret; |
| 400 | 400 | |
| 401 | − mutex_lock(&vdev->cf_mutex); | |
| 401 | + down_write(&vdev->cf_lock); | |
| 402 | 402 | vdev->features_valid = false; |
| 403 | 403 | ret = ops->reset(vdev); |
| 404 | − mutex_unlock(&vdev->cf_mutex); | |
| 404 | + up_write(&vdev->cf_lock); | |
| 405 | 405 | return ret; |
| 406 | 406 | } |
| 407 | 407 | |
| @@ -420,9 +420,9 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) · 12 unmodified lines | ||
| 420 | 420 | { |
| 421 | 421 | int ret; |
| 422 | 422 | |
| 423 | − mutex_lock(&vdev->cf_mutex); | |
| 423 | + down_write(&vdev->cf_lock); | |
| 424 | 424 | ret = vdpa_set_features_unlocked(vdev, features); |
| 425 | − mutex_unlock(&vdev->cf_mutex); | |
| 425 | + up_write(&vdev->cf_lock); | |
| 426 | 426 | |
| 427 | 427 | return ret; |
| 428 | 428 | } |