netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 3/7] mld: add a new delayed_work, mc_delrec_work
@ 2021-02-13 17:51 Taehee Yoo
  2021-02-13 19:18 ` Cong Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Taehee Yoo @ 2021-02-13 17:51 UTC (permalink / raw)
  To: davem, kuba, xiyou.wangcong, netdev, jwi, kgraul, hca, gor,
	borntraeger, mareklindner, sw, a, sven, yoshfuji, dsahern
  Cc: Taehee Yoo

The goal of mc_delrec_work delayed work is to call mld_clear_delrec().
The mld_clear_delrec() is called under both data path and control path.
So, the context of mld_clear_delrec() can be atomic.
But this function accesses struct ifmcaddr6 and struct ip6_sf_list.
These structures are going to be protected by RTNL.
So, this function should be called in a sleepable context.

Suggested-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
v1 -> v2:
 - Separated from previous big one patch.

 include/net/if_inet6.h |  1 +
 net/ipv6/mcast.c       | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index bec372283ac0..5946b5d76f7b 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -182,6 +182,7 @@ struct inet6_dev {
 	struct delayed_work	mc_gq_work;	/* general query work */
 	struct delayed_work	mc_ifc_work;	/* interface change work */
 	struct delayed_work	mc_dad_work;	/* dad complete mc work */
+	struct delayed_work     mc_delrec_work; /* delete records work */
 
 	struct ifacaddr6	*ac_list;
 	rwlock_t		lock;
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 1f7fd3fbb4b6..ca8ca6faca4e 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -1067,6 +1067,22 @@ static void mld_dad_stop_work(struct inet6_dev *idev)
 		__in6_dev_put(idev);
 }
 
+static void mld_clear_delrec_start_work(struct inet6_dev *idev)
+{
+	write_lock_bh(&idev->lock);
+	if (!mod_delayed_work(mld_wq, &idev->mc_delrec_work, 0))
+		in6_dev_hold(idev);
+	write_unlock_bh(&idev->lock);
+}
+
+static void mld_clear_delrec_stop_work(struct inet6_dev *idev)
+{
+	write_lock_bh(&idev->lock);
+	if (cancel_delayed_work(&idev->mc_delrec_work))
+		__in6_dev_put(idev);
+	write_unlock_bh(&idev->lock);
+}
+
 /*
  *	IGMP handling (alias multicast ICMPv6 messages)
  */
@@ -1304,7 +1320,7 @@ static int mld_process_v1(struct inet6_dev *idev, struct mld_msg *mld,
 	/* cancel the interface change work */
 	mld_ifc_stop_work(idev);
 	/* clear deleted report items */
-	mld_clear_delrec(idev);
+	mld_clear_delrec_start_work(idev);
 
 	return 0;
 }
@@ -2120,6 +2136,18 @@ static void mld_dad_work(struct work_struct *work)
 	in6_dev_put(idev);
 }
 
+static void mld_clear_delrec_work(struct work_struct *work)
+{
+	struct inet6_dev *idev = container_of(to_delayed_work(work),
+			struct inet6_dev,
+			mc_delrec_work);
+
+	rtnl_lock();
+	mld_clear_delrec(idev);
+	rtnl_unlock();
+	in6_dev_put(idev);
+}
+
 static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode,
 	const struct in6_addr *psfsrc)
 {
@@ -2553,6 +2581,7 @@ void ipv6_mc_down(struct inet6_dev *idev)
 	mld_gq_stop_work(idev);
 	mld_dad_stop_work(idev);
 	read_unlock_bh(&idev->lock);
+	mld_clear_delrec_stop_work(idev);
 }
 
 static void ipv6_mc_reset(struct inet6_dev *idev)
@@ -2593,6 +2622,7 @@ void ipv6_mc_init_dev(struct inet6_dev *idev)
 	idev->mc_ifc_count = 0;
 	INIT_DELAYED_WORK(&idev->mc_ifc_work, mld_ifc_work);
 	INIT_DELAYED_WORK(&idev->mc_dad_work, mld_dad_work);
+	INIT_DELAYED_WORK(&idev->mc_delrec_work, mld_clear_delrec_work);
 	ipv6_mc_reset(idev);
 	write_unlock_bh(&idev->lock);
 }
-- 
2.17.1


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

* Re: [PATCH net-next v2 3/7] mld: add a new delayed_work, mc_delrec_work
  2021-02-13 17:51 [PATCH net-next v2 3/7] mld: add a new delayed_work, mc_delrec_work Taehee Yoo
@ 2021-02-13 19:18 ` Cong Wang
  2021-02-14 11:30   ` Taehee Yoo
  2021-02-14 14:53   ` Taehee Yoo
  0 siblings, 2 replies; 4+ messages in thread
From: Cong Wang @ 2021-02-13 19:18 UTC (permalink / raw)
  To: Taehee Yoo
  Cc: David Miller, Jakub Kicinski, Linux Kernel Network Developers,
	jwi, kgraul, hca, gor, borntraeger, Marek Lindner, sw, a, sven,
	Hideaki YOSHIFUJI, dsahern

On Sat, Feb 13, 2021 at 9:52 AM Taehee Yoo <ap420073@gmail.com> wrote:
>
> The goal of mc_delrec_work delayed work is to call mld_clear_delrec().
> The mld_clear_delrec() is called under both data path and control path.
> So, the context of mld_clear_delrec() can be atomic.
> But this function accesses struct ifmcaddr6 and struct ip6_sf_list.
> These structures are going to be protected by RTNL.
> So, this function should be called in a sleepable context.

Hmm, but with this patch mld_clear_delrec() is called asynchronously
without waiting, is this a problem? If not, please explain why in your
changelog.

By the way, if you do not use a delay, you can just use regular work.

Thanks.

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

* Re: [PATCH net-next v2 3/7] mld: add a new delayed_work, mc_delrec_work
  2021-02-13 19:18 ` Cong Wang
@ 2021-02-14 11:30   ` Taehee Yoo
  2021-02-14 14:53   ` Taehee Yoo
  1 sibling, 0 replies; 4+ messages in thread
From: Taehee Yoo @ 2021-02-14 11:30 UTC (permalink / raw)
  To: Cong Wang
  Cc: David Miller, Jakub Kicinski, Linux Kernel Network Developers,
	jwi, kgraul, hca, gor, borntraeger, Marek Lindner, sw, a, sven,
	Hideaki YOSHIFUJI, dsahern, ap420073

On 21. 2. 14. 오전 4:18, Cong Wang wrote:
 > On Sat, Feb 13, 2021 at 9:52 AM Taehee Yoo <ap420073@gmail.com> wrote:
 >>
 >> The goal of mc_delrec_work delayed work is to call mld_clear_delrec().
 >> The mld_clear_delrec() is called under both data path and control path.
 >> So, the context of mld_clear_delrec() can be atomic.
 >> But this function accesses struct ifmcaddr6 and struct ip6_sf_list.
 >> These structures are going to be protected by RTNL.
 >> So, this function should be called in a sleepable context.
 >
 > Hmm, but with this patch mld_clear_delrec() is called asynchronously
 > without waiting, is this a problem? If not, please explain why in your
 > changelog.
 >

The mld_clear_delrec() is called when an mld v1 query is received or an 
interface is down/destroyed.
The purpose of this function is to clear deleted records, which are not 
used when an mld v1 query is received.
So, In the datapath, it has no problem.
Also it increases the refcount of idev so it has no problem when an 
interface is down or destroyed.

I will include this description in the v3 patch.
Thanks!

 > By the way, if you do not use a delay, you can just use regular work.
 >
 > Thanks.
 >

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

* Re: [PATCH net-next v2 3/7] mld: add a new delayed_work, mc_delrec_work
  2021-02-13 19:18 ` Cong Wang
  2021-02-14 11:30   ` Taehee Yoo
@ 2021-02-14 14:53   ` Taehee Yoo
  1 sibling, 0 replies; 4+ messages in thread
From: Taehee Yoo @ 2021-02-14 14:53 UTC (permalink / raw)
  To: Cong Wang
  Cc: David Miller, Jakub Kicinski, Linux Kernel Network Developers,
	jwi, kgraul, hca, gor, borntraeger, Marek Lindner, sw, a, sven,
	Hideaki YOSHIFUJI, dsahern, ap420073

 >
 > By the way, if you do not use a delay, you can just use regular work.
 >

The regular workqueue API couldn't be used in an atomic context, So I 
used delayed_work.
If 0 delay is passed to delayed_work, it internally calls regular workqueue.
So, I think there is no actual difference.

Thanks!

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

end of thread, other threads:[~2021-02-14 14:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-13 17:51 [PATCH net-next v2 3/7] mld: add a new delayed_work, mc_delrec_work Taehee Yoo
2021-02-13 19:18 ` Cong Wang
2021-02-14 11:30   ` Taehee Yoo
2021-02-14 14:53   ` Taehee Yoo

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).