From: Greg Kroah-Hartman Date: Tue, 23 Aug 2022 07:23:26 +0000 (+0200) Subject: 5.10-stable patches X-Git-Tag: v4.9.326~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8f5bbd9bb73e73dfb59c3dd9d7191e149138b40a;p=thirdparty%2Fkernel%2Fstable-queue.git 5.10-stable patches added patches: qrtr-convert-qrtr_ports-from-idr-to-xarray.patch --- diff --git a/queue-5.10/qrtr-convert-qrtr_ports-from-idr-to-xarray.patch b/queue-5.10/qrtr-convert-qrtr_ports-from-idr-to-xarray.patch new file mode 100644 index 00000000000..5242a32daff --- /dev/null +++ b/queue-5.10/qrtr-convert-qrtr_ports-from-idr-to-xarray.patch @@ -0,0 +1,122 @@ +From 3cbf7530a163d048a6376cd22fecb9cdcb23b192 Mon Sep 17 00:00:00 2001 +From: "Matthew Wilcox (Oracle)" +Date: Wed, 31 Mar 2021 05:36:42 +0100 +Subject: qrtr: Convert qrtr_ports from IDR to XArray + +From: Matthew Wilcox (Oracle) + +commit 3cbf7530a163d048a6376cd22fecb9cdcb23b192 upstream. + +The XArray interface is easier for this driver to use. Also fixes a +bug reported by the improper use of GFP_ATOMIC. + +Signed-off-by: Matthew Wilcox (Oracle) +Reviewed-by: Manivannan Sadhasivam +Signed-off-by: David S. Miller +Signed-off-by: Stanislav Goriainov +Signed-off-by: Greg Kroah-Hartman +--- + net/qrtr/qrtr.c | 42 ++++++++++++++---------------------------- + 1 file changed, 14 insertions(+), 28 deletions(-) + +--- a/net/qrtr/qrtr.c ++++ b/net/qrtr/qrtr.c +@@ -20,6 +20,8 @@ + /* auto-bind range */ + #define QRTR_MIN_EPH_SOCKET 0x4000 + #define QRTR_MAX_EPH_SOCKET 0x7fff ++#define QRTR_EPH_PORT_RANGE \ ++ XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET) + + /** + * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1 +@@ -106,8 +108,7 @@ static LIST_HEAD(qrtr_all_nodes); + static DEFINE_MUTEX(qrtr_node_lock); + + /* local port allocation management */ +-static DEFINE_IDR(qrtr_ports); +-static DEFINE_MUTEX(qrtr_port_lock); ++static DEFINE_XARRAY_ALLOC(qrtr_ports); + + /** + * struct qrtr_node - endpoint node +@@ -635,7 +636,7 @@ static struct qrtr_sock *qrtr_port_looku + port = 0; + + rcu_read_lock(); +- ipc = idr_find(&qrtr_ports, port); ++ ipc = xa_load(&qrtr_ports, port); + if (ipc) + sock_hold(&ipc->sk); + rcu_read_unlock(); +@@ -677,9 +678,7 @@ static void qrtr_port_remove(struct qrtr + + __sock_put(&ipc->sk); + +- mutex_lock(&qrtr_port_lock); +- idr_remove(&qrtr_ports, port); +- mutex_unlock(&qrtr_port_lock); ++ xa_erase(&qrtr_ports, port); + + /* Ensure that if qrtr_port_lookup() did enter the RCU read section we + * wait for it to up increment the refcount */ +@@ -698,29 +697,20 @@ static void qrtr_port_remove(struct qrtr + */ + static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) + { +- u32 min_port; + int rc; + +- mutex_lock(&qrtr_port_lock); + if (!*port) { +- min_port = QRTR_MIN_EPH_SOCKET; +- rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, QRTR_MAX_EPH_SOCKET, GFP_ATOMIC); +- if (!rc) +- *port = min_port; ++ rc = xa_alloc(&qrtr_ports, port, ipc, QRTR_EPH_PORT_RANGE, ++ GFP_KERNEL); + } else if (*port < QRTR_MIN_EPH_SOCKET && !capable(CAP_NET_ADMIN)) { + rc = -EACCES; + } else if (*port == QRTR_PORT_CTRL) { +- min_port = 0; +- rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, 0, GFP_ATOMIC); ++ rc = xa_insert(&qrtr_ports, 0, ipc, GFP_KERNEL); + } else { +- min_port = *port; +- rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, *port, GFP_ATOMIC); +- if (!rc) +- *port = min_port; ++ rc = xa_insert(&qrtr_ports, *port, ipc, GFP_KERNEL); + } +- mutex_unlock(&qrtr_port_lock); + +- if (rc == -ENOSPC) ++ if (rc == -EBUSY) + return -EADDRINUSE; + else if (rc < 0) + return rc; +@@ -734,20 +724,16 @@ static int qrtr_port_assign(struct qrtr_ + static void qrtr_reset_ports(void) + { + struct qrtr_sock *ipc; +- int id; +- +- mutex_lock(&qrtr_port_lock); +- idr_for_each_entry(&qrtr_ports, ipc, id) { +- /* Don't reset control port */ +- if (id == 0) +- continue; ++ unsigned long index; + ++ rcu_read_lock(); ++ xa_for_each_start(&qrtr_ports, index, ipc, 1) { + sock_hold(&ipc->sk); + ipc->sk.sk_err = ENETRESET; + ipc->sk.sk_error_report(&ipc->sk); + sock_put(&ipc->sk); + } +- mutex_unlock(&qrtr_port_lock); ++ rcu_read_unlock(); + } + + /* Bind socket to address. diff --git a/queue-5.10/series b/queue-5.10/series index 48548907e03..5cf80f7d0a1 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -154,3 +154,4 @@ tracing-probes-have-kprobes-and-uprobes-use-comm-too.patch can-j1939-j1939_sk_queue_activate_next_locked-replace-warn_on_once-with-netdev_warn_once.patch can-j1939-j1939_session_destroy-fix-memory-leak-of-skbs.patch pci-err-retain-status-from-error-notification.patch +qrtr-convert-qrtr_ports-from-idr-to-xarray.patch