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
2323
2424 void vdpa_set_status(struct vdpa_device *vdev, u8 status)
2525 {
26− mutex_lock(&vdev->cf_mutex);
26+ down_write(&vdev->cf_lock);
2727 vdev->config->set_status(vdev, status);
28− mutex_unlock(&vdev->cf_mutex);
28+ up_write(&vdev->cf_lock);
2929 }
3030 EXPORT_SYMBOL(vdpa_set_status);
3131
@@ -148,7 +148,6 @@ static void vdpa_release_dev(struct device *d) · 116 unmodified lines
148148 ops->free(vdev);
149149
150150 ida_simple_remove(&vdpa_index_ida, vdev->index);
151− mutex_destroy(&vdev->cf_mutex);
152151 kfree(vdev->driver_override);
153152 kfree(vdev);
154153 }
@@ -211,7 +210,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, · 56 unmodified lines
211210 if (err)
212211 goto err_name;
213212
214− mutex_init(&vdev->cf_mutex);
213+ init_rwsem(&vdev->cf_lock);
215214 device_initialize(&vdev->dev);
216215
217216 return vdev;
@@ -407,9 +406,9 @@ static void vdpa_get_config_unlocked(struct vdpa_device *vdev, · 189 unmodified lines
407406 void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
408407 void *buf, unsigned int len)
409408 {
410− mutex_lock(&vdev->cf_mutex);
409+ down_read(&vdev->cf_lock);
411410 vdpa_get_config_unlocked(vdev, offset, buf, len);
412− mutex_unlock(&vdev->cf_mutex);
411+ up_read(&vdev->cf_lock);
413412 }
414413 EXPORT_SYMBOL_GPL(vdpa_get_config);
415414
@@ -423,9 +422,9 @@ EXPORT_SYMBOL_GPL(vdpa_get_config); · 7 unmodified lines
423422 void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset,
424423 const void *buf, unsigned int length)
425424 {
426− mutex_lock(&vdev->cf_mutex);
425+ down_write(&vdev->cf_lock);
427426 vdev->config->set_config(vdev, offset, buf, length);
428− mutex_unlock(&vdev->cf_mutex);
427+ up_write(&vdev->cf_lock);
429428 }
430429 EXPORT_SYMBOL_GPL(vdpa_set_config);
431430
@@ -866,7 +865,7 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · 434 unmodified lines
866865 u8 status;
867866 int err;
868867
869− mutex_lock(&vdev->cf_mutex);
868+ down_read(&vdev->cf_lock);
870869 status = vdev->config->get_status(vdev);
871870 if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
872871 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
903902 if (err)
904903 goto msg_err;
905904
906− mutex_unlock(&vdev->cf_mutex);
905+ up_read(&vdev->cf_lock);
907906 genlmsg_end(msg, hdr);
908907 return 0;
909908
910909 msg_err:
911910 genlmsg_cancel(msg, hdr);
912911 out:
913− mutex_unlock(&vdev->cf_mutex);
912+ up_read(&vdev->cf_lock);
914913 return err;
915914 }
916915
@@ -954,7 +953,7 @@ static int vendor_stats_fill(struct vdpa_device *vdev, struct sk_buff *msg, · 37 unmodified lines
954953 {
955954 int err;
956955
957− mutex_lock(&vdev->cf_mutex);
956+ down_read(&vdev->cf_lock);
958957 if (!vdev->config->get_vendor_vq_stats) {
959958 err = -EOPNOTSUPP;
960959 goto out;
@@ -962,7 +961,7 @@ static int vendor_stats_fill(struct vdpa_device *vdev, struct sk_buff *msg, · 1 unmodified line
962961
963962 err = vdpa_fill_stats_rec(vdev, msg, info, index);
964963 out:
965− mutex_unlock(&vdev->cf_mutex);
964+ up_read(&vdev->cf_lock);
966965 return err;
967966 }
968967
include/linux/vdpa.h+6−6
@@ -66,7 +66,7 @@ struct vdpa_mgmt_dev; · 65 unmodified lines
6666 * @dma_dev: the actual device that is performing DMA
6767 * @driver_override: driver name to force a match
6868 * @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.
7070 * @index: device index
7171 * @features_valid: were features initialized? for legacy guests
7272 * @use_va: indicate whether virtual address must be used by this device
@@ -79,7 +79,7 @@ struct vdpa_device { · 6 unmodified lines
7979 struct device *dma_dev;
8080 const char *driver_override;
8181 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 */
8383 unsigned int index;
8484 bool features_valid;
8585 bool use_va;
@@ -398,10 +398,10 @@ static inline int vdpa_reset(struct vdpa_device *vdev) · 312 unmodified lines
398398 const struct vdpa_config_ops *ops = vdev->config;
399399 int ret;
400400
401− mutex_lock(&vdev->cf_mutex);
401+ down_write(&vdev->cf_lock);
402402 vdev->features_valid = false;
403403 ret = ops->reset(vdev);
404− mutex_unlock(&vdev->cf_mutex);
404+ up_write(&vdev->cf_lock);
405405 return ret;
406406 }
407407
@@ -420,9 +420,9 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) · 12 unmodified lines
420420 {
421421 int ret;
422422
423− mutex_lock(&vdev->cf_mutex);
423+ down_write(&vdev->cf_lock);
424424 ret = vdpa_set_features_unlocked(vdev, features);
425− mutex_unlock(&vdev->cf_mutex);
425+ up_write(&vdev->cf_lock);
426426
427427 return ret;
428428 }

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