linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: gw: syncronize rcu operations before removing gw job entry
@ 2021-06-18 17:36 Oliver Hartkopp
  2021-06-19 20:41 ` Marc Kleine-Budde
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Hartkopp @ 2021-06-18 17:36 UTC (permalink / raw)
  To: linux-can; +Cc: Oliver Hartkopp

can_can_gw_rcv() is called under RCU protection, so after calling
can_rx_unregister, we may call synchronize_rcu in order to wait for any
RCU read-side critical sections to finish before removing the kmem_cache
entry with the referenced gw job entry.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 net/can/gw.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/can/gw.c b/net/can/gw.c
index ba4124805602..d8861e862f15 100644
--- a/net/can/gw.c
+++ b/net/can/gw.c
@@ -594,10 +594,11 @@ static int cgw_notifier(struct notifier_block *nb,
 
 		hlist_for_each_entry_safe(gwj, nx, &net->can.cgw_list, list) {
 			if (gwj->src.dev == dev || gwj->dst.dev == dev) {
 				hlist_del(&gwj->list);
 				cgw_unregister_filter(net, gwj);
+				synchronize_rcu();
 				kmem_cache_free(cgw_cache, gwj);
 			}
 		}
 	}
 
@@ -1152,10 +1153,11 @@ static void cgw_remove_all_jobs(struct net *net)
 	ASSERT_RTNL();
 
 	hlist_for_each_entry_safe(gwj, nx, &net->can.cgw_list, list) {
 		hlist_del(&gwj->list);
 		cgw_unregister_filter(net, gwj);
+		synchronize_rcu();
 		kmem_cache_free(cgw_cache, gwj);
 	}
 }
 
 static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -1220,10 +1222,11 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh,
 		if (memcmp(&gwj->ccgw, &ccgw, sizeof(ccgw)))
 			continue;
 
 		hlist_del(&gwj->list);
 		cgw_unregister_filter(net, gwj);
+		synchronize_rcu();
 		kmem_cache_free(cgw_cache, gwj);
 		err = 0;
 		break;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] can: gw: syncronize rcu operations before removing gw job entry
  2021-06-18 17:36 [PATCH] can: gw: syncronize rcu operations before removing gw job entry Oliver Hartkopp
@ 2021-06-19 20:41 ` Marc Kleine-Budde
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2021-06-19 20:41 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: linux-can

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

On 18.06.2021 19:36:45, Oliver Hartkopp wrote:
> can_can_gw_rcv() is called under RCU protection, so after calling
> can_rx_unregister, we may call synchronize_rcu in order to wait for any
> RCU read-side critical sections to finish before removing the kmem_cache
> entry with the referenced gw job entry.
> 
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>

Applied to linux-can/testing.

Thanks,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-19 20:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 17:36 [PATCH] can: gw: syncronize rcu operations before removing gw job entry Oliver Hartkopp
2021-06-19 20:41 ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).