Commit ffa423fb authored by WANG Cong's avatar WANG Cong Committed by David S. Miller

tap: convert a mutex to a spinlock

We are not allowed to block on the RCU reader side, so can't
just hold the mutex as before. As a quick fix, convert it to
a spinlock.

Fixes: d9f1f61c ("tap: Extending tap device create/destroy APIs")
Reported-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
Tested-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
Cc: Sainath Grandhi <sainath.grandhi@intel.com>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6a146f3a
...@@ -106,7 +106,7 @@ struct major_info { ...@@ -106,7 +106,7 @@ struct major_info {
struct rcu_head rcu; struct rcu_head rcu;
dev_t major; dev_t major;
struct idr minor_idr; struct idr minor_idr;
struct mutex minor_lock; spinlock_t minor_lock;
const char *device_name; const char *device_name;
struct list_head next; struct list_head next;
}; };
...@@ -416,15 +416,15 @@ int tap_get_minor(dev_t major, struct tap_dev *tap) ...@@ -416,15 +416,15 @@ int tap_get_minor(dev_t major, struct tap_dev *tap)
goto unlock; goto unlock;
} }
mutex_lock(&tap_major->minor_lock); spin_lock(&tap_major->minor_lock);
retval = idr_alloc(&tap_major->minor_idr, tap, 1, TAP_NUM_DEVS, GFP_KERNEL); retval = idr_alloc(&tap_major->minor_idr, tap, 1, TAP_NUM_DEVS, GFP_ATOMIC);
if (retval >= 0) { if (retval >= 0) {
tap->minor = retval; tap->minor = retval;
} else if (retval == -ENOSPC) { } else if (retval == -ENOSPC) {
netdev_err(tap->dev, "Too many tap devices\n"); netdev_err(tap->dev, "Too many tap devices\n");
retval = -EINVAL; retval = -EINVAL;
} }
mutex_unlock(&tap_major->minor_lock); spin_unlock(&tap_major->minor_lock);
unlock: unlock:
rcu_read_unlock(); rcu_read_unlock();
...@@ -442,12 +442,12 @@ void tap_free_minor(dev_t major, struct tap_dev *tap) ...@@ -442,12 +442,12 @@ void tap_free_minor(dev_t major, struct tap_dev *tap)
goto unlock; goto unlock;
} }
mutex_lock(&tap_major->minor_lock); spin_lock(&tap_major->minor_lock);
if (tap->minor) { if (tap->minor) {
idr_remove(&tap_major->minor_idr, tap->minor); idr_remove(&tap_major->minor_idr, tap->minor);
tap->minor = 0; tap->minor = 0;
} }
mutex_unlock(&tap_major->minor_lock); spin_unlock(&tap_major->minor_lock);
unlock: unlock:
rcu_read_unlock(); rcu_read_unlock();
...@@ -467,13 +467,13 @@ static struct tap_dev *dev_get_by_tap_file(int major, int minor) ...@@ -467,13 +467,13 @@ static struct tap_dev *dev_get_by_tap_file(int major, int minor)
goto unlock; goto unlock;
} }
mutex_lock(&tap_major->minor_lock); spin_lock(&tap_major->minor_lock);
tap = idr_find(&tap_major->minor_idr, minor); tap = idr_find(&tap_major->minor_idr, minor);
if (tap) { if (tap) {
dev = tap->dev; dev = tap->dev;
dev_hold(dev); dev_hold(dev);
} }
mutex_unlock(&tap_major->minor_lock); spin_unlock(&tap_major->minor_lock);
unlock: unlock:
rcu_read_unlock(); rcu_read_unlock();
...@@ -1244,7 +1244,7 @@ static int tap_list_add(dev_t major, const char *device_name) ...@@ -1244,7 +1244,7 @@ static int tap_list_add(dev_t major, const char *device_name)
tap_major->major = MAJOR(major); tap_major->major = MAJOR(major);
idr_init(&tap_major->minor_idr); idr_init(&tap_major->minor_idr);
mutex_init(&tap_major->minor_lock); spin_lock_init(&tap_major->minor_lock);
tap_major->device_name = device_name; tap_major->device_name = device_name;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment