History

net/vdpa: Use readers/writers semaphore instead of cf_mutex

Replace cf_mutex with rw_semaphore to reflect the fact that some calls could be called concurrently but can suffice with read lock.

Eli Cohen committed 4 years ago

Commit a6a51ad1 parent 0078ad92 files · +18 −19Browse files

Unified · Split

2 files
  1. drivers/vdpa/vdpa.c +12 −13
  2. include/linux/vdpa.h +6 −6
drivers/vdpa/vdpa.c+12−13
@@ -23,9 +23,9 @@ static DEFINE_IDA(vdpa_index_ida); · 22 unmodified lines
23 23
24void vdpa_set_status(struct vdpa_device *vdev, u8 status)24void vdpa_set_status(struct vdpa_device *vdev, u8 status)
25{25{
26 mutex_lock(&vdev->cf_mutex);26 down_write(&vdev->cf_lock);
27 vdev->config->set_status(vdev, status);27 vdev->config->set_status(vdev, status);
28 mutex_unlock(&vdev->cf_mutex);28 up_write(&vdev->cf_lock);
29}29}
30EXPORT_SYMBOL(vdpa_set_status);30EXPORT_SYMBOL(vdpa_set_status);
31 31
@@ -148,7 +148,6 @@ static void vdpa_release_dev(struct device *d) · 116 unmodified lines
148 ops->free(vdev);148 ops->free(vdev);
149 149
150 ida_simple_remove(&vdpa_index_ida, vdev->index);150 ida_simple_remove(&vdpa_index_ida, vdev->index);
151 mutex_destroy(&vdev->cf_mutex);
152 kfree(vdev->driver_override);151 kfree(vdev->driver_override);
153 kfree(vdev);152 kfree(vdev);
154}153}
@@ -211,7 +210,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, · 56 unmodified lines
211 if (err)210 if (err)
212 goto err_name;211 goto err_name;
213 212
214 mutex_init(&vdev->cf_mutex);213 init_rwsem(&vdev->cf_lock);
215 device_initialize(&vdev->dev);214 device_initialize(&vdev->dev);
216 215
217 return vdev;216 return vdev;
@@ -407,9 +406,9 @@ static void vdpa_get_config_unlocked(struct vdpa_device *vdev, · 189 unmodified lines
407void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,406void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
408 void *buf, unsigned int len)407 void *buf, unsigned int len)
409{408{
410 mutex_lock(&vdev->cf_mutex);409 down_read(&vdev->cf_lock);
411 vdpa_get_config_unlocked(vdev, offset, buf, len);410 vdpa_get_config_unlocked(vdev, offset, buf, len);
412 mutex_unlock(&vdev->cf_mutex);411 up_read(&vdev->cf_lock);
413}412}
414EXPORT_SYMBOL_GPL(vdpa_get_config);413EXPORT_SYMBOL_GPL(vdpa_get_config);
415 414
@@ -423,9 +422,9 @@ EXPORT_SYMBOL_GPL(vdpa_get_config); · 7 unmodified lines
423void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset,422void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset,
424 const void *buf, unsigned int length)423 const void *buf, unsigned int length)
425{424{
426 mutex_lock(&vdev->cf_mutex);425 down_write(&vdev->cf_lock);
427 vdev->config->set_config(vdev, offset, buf, length);426 vdev->config->set_config(vdev, offset, buf, length);
428 mutex_unlock(&vdev->cf_mutex);427 up_write(&vdev->cf_lock);
429}428}
430EXPORT_SYMBOL_GPL(vdpa_set_config);429EXPORT_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 u8 status;865 u8 status;
867 int err;866 int err;
868 867
869 mutex_lock(&vdev->cf_mutex);868 down_read(&vdev->cf_lock);
870 status = vdev->config->get_status(vdev);869 status = vdev->config->get_status(vdev);
871 if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {870 if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
872 NL_SET_ERR_MSG_MOD(extack, "Features negotiation not completed");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 if (err)902 if (err)
904 goto msg_err;903 goto msg_err;
905 904
906 mutex_unlock(&vdev->cf_mutex);905 up_read(&vdev->cf_lock);
907 genlmsg_end(msg, hdr);906 genlmsg_end(msg, hdr);
908 return 0;907 return 0;
909 908
910msg_err:909msg_err:
911 genlmsg_cancel(msg, hdr);910 genlmsg_cancel(msg, hdr);
912out:911out:
913 mutex_unlock(&vdev->cf_mutex);912 up_read(&vdev->cf_lock);
914 return err;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 int err;954 int err;
956 955
957 mutex_lock(&vdev->cf_mutex);956 down_read(&vdev->cf_lock);
958 if (!vdev->config->get_vendor_vq_stats) {957 if (!vdev->config->get_vendor_vq_stats) {
959 err = -EOPNOTSUPP;958 err = -EOPNOTSUPP;
960 goto out;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 err = vdpa_fill_stats_rec(vdev, msg, info, index);962 err = vdpa_fill_stats_rec(vdev, msg, info, index);
964out:963out:
965 mutex_unlock(&vdev->cf_mutex);964 up_read(&vdev->cf_lock);
966 return err;965 return err;
967}966}
968 967
include/linux/vdpa.h+6−6
@@ -66,7 +66,7 @@ struct vdpa_mgmt_dev; · 65 unmodified lines
66 * @dma_dev: the actual device that is performing DMA66 * @dma_dev: the actual device that is performing DMA
67 * @driver_override: driver name to force a match67 * @driver_override: driver name to force a match
68 * @config: the configuration ops for this device.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 * @index: device index70 * @index: device index
71 * @features_valid: were features initialized? for legacy guests71 * @features_valid: were features initialized? for legacy guests
72 * @use_va: indicate whether virtual address must be used by this device72 * @use_va: indicate whether virtual address must be used by this device
@@ -79,7 +79,7 @@ struct vdpa_device { · 6 unmodified lines
79 struct device *dma_dev;79 struct device *dma_dev;
80 const char *driver_override;80 const char *driver_override;
81 const struct vdpa_config_ops *config;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 unsigned int index;83 unsigned int index;
84 bool features_valid;84 bool features_valid;
85 bool use_va;85 bool use_va;
@@ -398,10 +398,10 @@ static inline int vdpa_reset(struct vdpa_device *vdev) · 312 unmodified lines
398 const struct vdpa_config_ops *ops = vdev->config;398 const struct vdpa_config_ops *ops = vdev->config;
399 int ret;399 int ret;
400 400
401 mutex_lock(&vdev->cf_mutex);401 down_write(&vdev->cf_lock);
402 vdev->features_valid = false;402 vdev->features_valid = false;
403 ret = ops->reset(vdev);403 ret = ops->reset(vdev);
404 mutex_unlock(&vdev->cf_mutex);404 up_write(&vdev->cf_lock);
405 return ret;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 int ret;421 int ret;
422 422
423 mutex_lock(&vdev->cf_mutex);423 down_write(&vdev->cf_lock);
424 ret = vdpa_set_features_unlocked(vdev, features);424 ret = vdpa_set_features_unlocked(vdev, features);
425 mutex_unlock(&vdev->cf_mutex);425 up_write(&vdev->cf_lock);
426 426
427 return ret;427 return ret;
428}428}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t