diff options
author | Bjorn Andersson <bjorn.andersson@linaro.org> | 2020-01-14 10:57:02 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2020-01-15 05:36:42 +0300 |
commit | f16a4b26f31f95dddb12cf3c2390906a735203ae (patch) | |
tree | 88a2188c8fb7fc91d2a41ac4ab6ed5e98acbf304 /net | |
parent | 0a7e0d0ef05440db03c3199e84d228db943b237f (diff) | |
download | linux-f16a4b26f31f95dddb12cf3c2390906a735203ae.tar.xz |
net: qrtr: Make qrtr_port_lookup() use RCU
The important part of qrtr_port_lookup() wrt synchronization is that the
function returns a reference counted struct qrtr_sock, or fail.
As such we need only to ensure that an decrement of the object's
refcount happens inbetween the finding of the object in the idr and
qrtr_port_lookup()'s own increment of the object.
By using RCU and putting a synchronization point after we remove the
mapping from the idr, but before it can be released we achieve this -
with the benefit of not having to hold the mutex in qrtr_port_lookup().
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/qrtr/qrtr.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index ca802798e19e..0fe08f060b8c 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -646,11 +646,11 @@ static struct qrtr_sock *qrtr_port_lookup(int port) if (port == QRTR_PORT_CTRL) port = 0; - mutex_lock(&qrtr_port_lock); + rcu_read_lock(); ipc = idr_find(&qrtr_ports, port); if (ipc) sock_hold(&ipc->sk); - mutex_unlock(&qrtr_port_lock); + rcu_read_unlock(); return ipc; } @@ -692,6 +692,10 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) mutex_lock(&qrtr_port_lock); idr_remove(&qrtr_ports, port); mutex_unlock(&qrtr_port_lock); + + /* Ensure that if qrtr_port_lookup() did enter the RCU read section we + * wait for it to up increment the refcount */ + synchronize_rcu(); } /* Assign port number to socket. |