mld: change context from atomic to sleepable
Subsystems (6)
v3 cover mld: change context from atomic to sleepable
This patchset changes the context of MLD module.
Before this patchset, MLD functions are atomic context so it couldn't use sleepable functions and flags.
There are several reasons why MLD functions are under atomic context.
1. It uses timer API.
Timer expiration functions are executed in the atomic context.
2. atomic locks
MLD functions use rwlock and spinlock to protect their own resources.
So, in order to switch context, this patchset converts resources to use RCU and removes atomic locks and timer API.
1. The first patch convert from the timer API to delayed work. Timer API is used for delaying some works.
MLD protocol has a delay mechanism, which is used for replying to a query. If a listener receives a query from a router, it should send a response after some delay. But because of timer expire function is executed in the atomic context, this patch convert from timer API to the delayed work.
2. The fourth patch deletes inet6_dev->mc_lock.
The mc_lock has protected inet6_dev->mc_tomb pointer.
But this pointer is already protected by RTNL and it isn't be used by datapath. So, it isn't be needed and because of this, many atomic context critical sections are deleted.
3. The fifth patch convert ip6_sf_socklist to RCU. ip6_sf_socklist has been protected by ipv6_mc_socklist->sflock(rwlock). But this is already protected by RTNL So if it is converted to use RCU in order to be used in the datapath, the sflock is no more needed. So, its control path context can be switched to sleepable.
4. The sixth patch convert ip6_sf_list to RCU.
The reason for this patch is the same as the previous patch.
5. The seventh patch convert ifmcaddr6 to RCU.
The reason for this patch is the same as the previous patch.
6. Add new workqueues for processing query/report event. By this patch, query and report events are processed by workqueue So context is sleepable, not atomic.
While this logic, it acquires RTNL.
7. Add new mc_lock.
The purpose of this lock is to protect per-interface mld data. Per-interface mld data is usually used by query/report event handler. So, query/report event workers need only this lock instead of RTNL. Therefore, it could reduce bottleneck.
Changelog:
v2 -> v3:
1. Do not use msecs_to_jiffies().
(by Cong Wang)
2. Do not add unnecessary rtnl_lock() and rtnl_unlock().
(by Cong Wang)
3. Fix sparse warnings because of rcu annotation.
(by kernel test robot)
- Remove some rcu_assign_pointer(), which was used for non-rcu pointer.
- Add union for rcu pointer.
- Use rcu API in mld_clear_zeros().
- Remove remained rcu_read_unlock().
- Use rcu API for tomb resources.
4. withdraw prevopus 2nd and 3rd patch.
- "separate two flags from ifmcaddr6->mca_flags"
- "add a new delayed_work, mc_delrec_work"
5. Add 6th and 7th patch.
v1 -> v2:
1. Withdraw unnecessary refactoring patches.
(by Cong Wang, Eric Dumazet, David Ahern)
a) convert from array to list.
b) function rename.
2. Separate big one patch into small several patches.
3. Do not rename 'ifmcaddr6->mca_lock'.
In the v1 patch, this variable was changed to 'ifmcaddr6->mca_work_lock'. But this is actually not needed.
4. Do not use atomic_t for 'ifmcaddr6->mca_sfcount' and 'ipv6_mc_socklist'->sf_count'.
5. Do not add mld_check_leave_group() function.
6. Do not add ip6_mc_del_src_bulk() function.
7. Do not add ip6_mc_add_src_bulk() function.
8. Do not use rcu_read_lock() in the qeth_l3_add_mcast_rtnl(). (by Julian Wiedmann)
Taehee Yoo (7):
mld: convert from timer to delayed work
mld: get rid of inet6_dev->mc_lock
mld: convert ipv6_mc_socklist->sflist to RCU
mld: convert ip6_sf_list to RCU
mld: convert ifmcaddr6 to RCU
mld: add new workqueues for process mld events
mld: add mc_lock for protecting per-interface mld data
drivers/s390/net/qeth_l3_main.c | 6 +- include/net/if_inet6.h | 37 +- include/net/mld.h | 3 + net/batman-adv/multicast.c | 6 +- net/ipv6/addrconf.c | 9 +- net/ipv6/addrconf_core.c | 2 +- net/ipv6/af_inet6.c | 2 +- net/ipv6/icmp.c | 4 +- net/ipv6/mcast.c | 1080 ++++++++++++++++++------------- 9 files changed, 678 insertions(+), 471 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/7 mld: convert from timer to delayed work
mcast.c has several timers for delaying works.
Timer's expire handler is working under atomic context so it can't use sleepable things such as GFP_KERNEL, mutex, etc.
In order to use sleepable APIs, it converts from timers to delayed work. But there are some critical sections, which is used by both process and BH context. So that it still uses spin_lock_bh() and rwlock.
---
v2 -> v3:
- Do not use msecs_to_jiffies()
- Do not add unnecessary rtnl_lock and rtnl_unlock
v1 -> v2:
- Separated from previous big one patch.
include/net/if_inet6.h | 8 +-- net/ipv6/mcast.c | 140 +++++++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 65 deletions(-)
include/net/if_inet6.h +4 -4
@@ -120,7 +120,7 @@ struct ifmcaddr6 {unsigned int mca_sfmode;unsigned char mca_crcount;unsigned long mca_sfcount[2 ]; -struct timer_list mca_timer; +struct delayed_work mca_work;unsigned int mca_flags;int mca_users;refcount_t mca_refcnt;
@@ -179,9 +179,9 @@ struct inet6_dev {unsigned long mc_qri;/* Query Response Interval */ unsigned long mc_maxdelay; -struct timer_list mc_gq_timer;/* general query timer */ -struct timer_list mc_ifc_timer;/* interface change timer */ -struct timer_list mc_dad_timer;/* dad complete mc timer */ +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 ifacaddr6 *ac_list;rwlock_t lock;
net/ipv6/mcast.c +79 -61
350 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 2/7 mld: get rid of inet6_dev->mc_lock
In reply to Taehee YooThe purpose of mc_lock is to protect inet6_dev->mc_tomb. But mc_tomb is already protected by RTNL and all functions, which manipulate mc_tomb are called under RTNL.
So, mc_lock is not needed.
Furthermore, it is spinlock so the critical section is atomic. In order to reduce atomic context, it should be removed.
---
v2 -> v3:
- No change
v1 -> v2:
- Separated from previous big one patch.
include/net/if_inet6.h | 1 - net/ipv6/mcast.c | 9 --------- 2 files changed, 10 deletions(-)
include/net/if_inet6.h +0 -1
@@ -167,7 +167,6 @@ struct inet6_dev {struct ifmcaddr6 *mc_list;struct ifmcaddr6 *mc_tomb; -spinlock_t mc_lock;unsigned char mc_qrv;/* Query Robustness Variable */ unsigned char mc_gq_running;
net/ipv6/mcast.c +0 -9
@@ -752,10 +752,8 @@ static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im) }spin_unlock_bh (&im->mca_lock); -spin_lock_bh (&idev->mc_lock); pmc->next = idev->mc_tomb; idev->mc_tomb = pmc; -spin_unlock_bh (&idev->mc_lock); }static void mld_del_delrec (struct inet6_dev *idev,struct ifmcaddr6 *im)
@@ -764,7 +762,6 @@ static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)struct ip6_sf_list *psf;struct in6_addr *pmca = &im->mca_addr; -spin_lock_bh (&idev->mc_lock); pmc_prev =NULL ;for (pmc = idev->mc_tomb; pmc; pmc = pmc->next) {if (ipv6_addr_equal (&pmc->mca_addr, pmca))
@@ -777,7 +774,6 @@ static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)else idev->mc_tomb = pmc->next; } -spin_unlock_bh (&idev->mc_lock);spin_lock_bh (&im->mca_lock);if (pmc) {
@@ -801,10 +797,8 @@ static void mld_clear_delrec(struct inet6_dev *idev) {struct ifmcaddr6 *pmc, *nextpmc; -spin_lock_bh (&idev->mc_lock); pmc = idev->mc_tomb; idev->mc_tomb =NULL ; -spin_unlock_bh (&idev->mc_lock);for (; pmc; pmc = nextpmc) { nextpmc = pmc->next;
@@ -1907,7 +1901,6 @@ static void mld_send_cr(struct inet6_dev *idev)int type, dtype;read_lock_bh (&idev->lock); -spin_lock (&idev->mc_lock);/* deleted MCA's */ pmc_prev =NULL ;
@@ -1941,7 +1934,6 @@ static void mld_send_cr(struct inet6_dev *idev) }else pmc_prev = pmc; } -spin_unlock (&idev->mc_lock);/* change recs */ for (pmc = idev->mc_list; pmc; pmc = pmc->next) {
@@ -2582,7 +2574,6 @@ void ipv6_mc_up(struct inet6_dev *idev)void ipv6_mc_init_dev (struct inet6_dev *idev) {write_lock_bh (&idev->lock); -spin_lock_init (&idev->mc_lock); idev->mc_gq_running =0 ;INIT_DELAYED_WORK (&idev->mc_gq_work, mld_gq_work); idev->mc_tomb =NULL ;
Signature · 1 line
2.17.1
PATCH v3 3/7 mld: convert ipv6_mc_socklist->sflist to RCU
In reply to Taehee YooThe sflist has been protected by rwlock so that the critical section is atomic context.
In order to switch this context, changing locking is needed. The sflist actually already protected by RTNL So if it's converted to use RCU, its control path context can be switched to sleepable.
---
v2 -> v3:
- Fix sparse warnings because of rcu annotation
v1 -> v2:
- Separated from previous big one patch.
include/net/if_inet6.h | 4 ++-- net/ipv6/mcast.c | 52 ++++++++++++++++++------------------------ 2 files changed, 24 insertions(+), 32 deletions(-)
include/net/if_inet6.h +2 -2
@@ -78,6 +78,7 @@ struct inet6_ifaddr {struct ip6_sf_socklist {unsigned int sl_max;unsigned int sl_count; +struct rcu_head rcu;struct in6_addr sl_addr[]; };
@@ -91,8 +92,7 @@ struct ipv6_mc_socklist {int ifindex;unsigned int sfmode;/* MCAST_{INCLUDE,EXCLUDE} */ struct ipv6_mc_socklist __rcu *next; -rwlock_t sflock; -struct ip6_sf_socklist *sflist; +struct ip6_sf_socklist __rcu *sflist;struct rcu_head rcu; };
net/ipv6/mcast.c +22 -30
138 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 4/7 mld: convert ip6_sf_list to RCU
In reply to Taehee YooThe ip6_sf_list has been protected by mca_lock(spin_lock) so that the critical section is atomic context. In order to switch this context, changing locking is needed. The ip6_sf_list actually already protected by RTNL So if it's converted to use RCU, its control path context can be switched to sleepable.
But It doesn't remove mca_lock yet because ifmcaddr6 isn't converted to RCU yet. So, It's not fully converted to the sleepable context.
---
v2 -> v3:
- Fix sparse warnings because of rcu annotation
v1 -> v2:
- Separated from previous big one patch.
include/net/if_inet6.h | 7 +- net/ipv6/mcast.c | 200 ++++++++++++++++++++++++++--------------- 2 files changed, 130 insertions(+), 77 deletions(-)
include/net/if_inet6.h +4 -3
@@ -97,12 +97,13 @@ struct ipv6_mc_socklist { };struct ip6_sf_list { -struct ip6_sf_list *sf_next; +struct ip6_sf_list __rcu *sf_next;struct in6_addr sf_addr;unsigned long sf_count[2 ];/* include/exclude counts */ unsigned char sf_gsresp;/* include in g & s response? */ unsigned char sf_oldin;/* change state */ unsigned char sf_crcount;/* retrans. left to send */ +struct rcu_head rcu; };#define MAF_TIMER_RUNNING 0x01
@@ -115,8 +116,8 @@ struct ifmcaddr6 {struct in6_addr mca_addr;struct inet6_dev *idev;struct ifmcaddr6 *next; -struct ip6_sf_list *mca_sources; -struct ip6_sf_list *mca_tomb; +struct ip6_sf_list __rcu *mca_sources; +struct ip6_sf_list __rcu *mca_tomb;unsigned int mca_sfmode;unsigned char mca_crcount;unsigned long mca_sfcount[2 ];
net/ipv6/mcast.c +126 -74
419 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 5/7 mld: convert ifmcaddr6 to RCU
In reply to Taehee YooThe ifmcaddr6 has been protected by inet6_dev->lock(rwlock) so that the critical section is atomic context. In order to switch this context, changing locking is needed. The ifmcaddr6 actually already protected by RTNL So if it's converted to use RCU, its control path context can be switched to sleepable.
---
v2 -> v3:
- Fix sparse warnings because of rcu annotation
- Do not use mca_lock
v1 -> v2:
- Separated from previous big one patch.
drivers/s390/net/qeth_l3_main.c | 6 +- include/net/if_inet6.h | 7 +- net/batman-adv/multicast.c | 6 +- net/ipv6/addrconf.c | 9 +- net/ipv6/addrconf_core.c | 2 +- net/ipv6/af_inet6.c | 2 +- net/ipv6/mcast.c | 296 +++++++++++++------------------- 7 files changed, 140 insertions(+), 188 deletions(-)
drivers/s390/net/qeth_l3_main.c +3 -3
@@ -1098,8 +1098,9 @@ static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg) tmp.disp_flag =QETH_DISP_ADDR_ADD ; tmp.is_multicast =1 ; -read_lock_bh (&in6_dev->lock); -for (im6 = in6_dev->mc_list; im6 !=NULL ; im6 = im6->next) { +for (im6 =rtnl_dereference (in6_dev->mc_list); + im6; + im6 =rtnl_dereference (im6->next)) { tmp.u.a6.addr = im6->mca_addr; ipm =qeth_l3_find_addr_by_ip (card, &tmp);
@@ -1117,7 +1118,6 @@ static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg) qeth_l3_ipaddr_hash(ipm)); } -read_unlock_bh (&in6_dev->lock); out:return 0 ;
include/net/if_inet6.h +4 -3
@@ -115,7 +115,7 @@ struct ip6_sf_list {struct ifmcaddr6 {struct in6_addr mca_addr;struct inet6_dev *idev; -struct ifmcaddr6 *next; +struct ifmcaddr6 __rcu *next;struct ip6_sf_list __rcu *mca_sources;struct ip6_sf_list __rcu *mca_tomb;unsigned int mca_sfmode;
@@ -128,6 +128,7 @@ struct ifmcaddr6 {spinlock_t mca_lock;unsigned long mca_cstamp;unsigned long mca_tstamp; +struct rcu_head rcu; };/* Anycast stuff */
@@ -166,8 +167,8 @@ struct inet6_dev {struct list_head addr_list; -struct ifmcaddr6 *mc_list; -struct ifmcaddr6 *mc_tomb; +struct ifmcaddr6 __rcu *mc_list; +struct ifmcaddr6 __rcu *mc_tomb;unsigned char mc_qrv;/* Query Robustness Variable */ unsigned char mc_gq_running;
net/batman-adv/multicast.c +3 -3
@@ -454,8 +454,9 @@ batadv_mcast_mla_softif_get_ipv6(struct net_device *dev,return 0 ; } -read_lock_bh (&in6_dev->lock); -for (pmc6 = in6_dev->mc_list; pmc6; pmc6 = pmc6->next) { +for (pmc6 =rcu_dereference (in6_dev->mc_list); + pmc6; + pmc6 =rcu_dereference (pmc6->next)) {if (IPV6_ADDR_MC_SCOPE (&pmc6->mca_addr) <IPV6_ADDR_SCOPE_LINKLOCAL )continue ;
@@ -484,7 +485,6 @@ batadv_mcast_mla_softif_get_ipv6(struct net_device *dev,hlist_add_head (&new->list, mcast_list); ret++; } -read_unlock_bh (&in6_dev->lock);rcu_read_unlock ();return ret;
net/ipv6/addrconf.c +5 -4
@@ -5107,17 +5107,20 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,break ; }case MULTICAST_ADDR : +read_unlock_bh (&idev->lock); fillargs->event =RTM_GETMULTICAST ;/* multicast address */ -for (ifmca = idev->mc_list; ifmca; - ifmca = ifmca->next, ip_idx++) { +for (ifmca =rcu_dereference (idev->mc_list); + ifmca; + ifmca =rcu_dereference (ifmca->next), ip_idx++) {if (ip_idx < s_ip_idx)continue ; err =inet6_fill_ifmcaddr (skb, ifmca, fillargs);if (err <0 )break ; } +read_lock_bh (&idev->lock);break ;case ANYCAST_ADDR : fillargs->event =RTM_GETANYCAST ;
@@ -6093,10 +6096,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)static void ipv6_ifa_notify (int event,struct inet6_ifaddr *ifp) { -rcu_read_lock_bh ();if (likely (ifp->idev->dead ==0 ))__ipv6_ifa_notify (event, ifp); -rcu_read_unlock_bh (); }#ifdef CONFIG_SYSCTL
net/ipv6/addrconf_core.c +1 -1
@@ -250,7 +250,7 @@ void in6_dev_finish_destroy(struct inet6_dev *idev)struct net_device *dev = idev->dev;WARN_ON (!list_empty (&idev->addr_list)); -WARN_ON (idev->mc_list); +WARN_ON (rcu_access_pointer (idev->mc_list));WARN_ON (timer_pending (&idev->rs_timer));#ifdef NET_REFCNT_DEBUG
net/ipv6/af_inet6.c +1 -1
@@ -222,7 +222,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol, inet->mc_loop =1 ; inet->mc_ttl =1 ; inet->mc_index =0 ; - inet->mc_list =NULL ; +RCU_INIT_POINTER (inet->mc_list,NULL ); inet->rcv_tos =0 ;if (net->ipv4.sysctl_ip_no_pmtu_disc)
net/ipv6/mcast.c +123 -173
815 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 6/7 mld: add new workqueues for process mld events
In reply to Taehee YooWhen query/report packets are received, mld module processes them. But they are processed under BH context so it couldn't use sleepable functions. So, in order to switch context, the two workqueues are added which processes query and report event.
In the struct inet6_dev, mc_{query | report}_queue are added so it is per-interface queue.
And mc_{query | report}_work are workqueue structure.
When the query or report event is received, skb is queued to proper queue and worker function is scheduled immediately. Workqueues and queues are protected by spinlock, which is mc_{query | report}_lock, and worker functions are protected by RTNL.
---
v3:
- Initial patch
include/net/if_inet6.h | 9 +- include/net/mld.h | 3 + net/ipv6/icmp.c | 4 +- net/ipv6/mcast.c | 280 +++++++++++++++++++++++++++++------------ 4 files changed, 210 insertions(+), 86 deletions(-)
include/net/if_inet6.h +8 -1
@@ -125,7 +125,6 @@ struct ifmcaddr6 {unsigned int mca_flags;int mca_users;refcount_t mca_refcnt; -spinlock_t mca_lock;unsigned long mca_cstamp;unsigned long mca_tstamp;struct rcu_head rcu;
@@ -183,6 +182,14 @@ 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_query_work;/* mld query work */ +struct delayed_work mc_report_work;/* mld report work */ + +struct sk_buff_head mc_query_queue;/* mld query queue */ +struct sk_buff_head mc_report_queue;/* mld report queue */ + +spinlock_t mc_query_lock;/* mld query queue lock */ +spinlock_t mc_report_lock;/* mld query report lock */ struct ifacaddr6 *ac_list;rwlock_t lock;
include/net/mld.h +3 -0
@@ -92,6 +92,9 @@ struct mld2_query {#define MLD_EXP_MIN_LIMIT 32768UL#define MLDV1_MRD_MAX_COMPAT (MLD_EXP_MIN_LIMIT - 1) +#define MLD_MAX_QUEUE 8 +#define MLD_MAX_SKBS 32 +static inline unsigned long mldv2_mrc (const struct mld2_query *mlh2) {/* RFC3810, 5.1.3. Maximum Response Code */
net/ipv6/icmp.c +2 -2
@@ -944,11 +944,11 @@ static int icmpv6_rcv(struct sk_buff *skb)case ICMPV6_MGM_QUERY :igmp6_event_query (skb); -break ; +return 0 ;case ICMPV6_MGM_REPORT :igmp6_event_report (skb); -break ; +return 0 ;case ICMPV6_MGM_REDUCTION :case ICMPV6_NI_QUERY :
net/ipv6/mcast.c +197 -83
712 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 7/7 mld: add mc_lock for protecting per-interface mld data
In reply to Taehee YooThe purpose of this lock is to avoid a bottleneck in the query/report event handler logic.
By previous patches, almost all mld data is protected by RTNL. So, the query and report event handler, which is data path logic acquires RTNL too. Therefore if a lot of query and report events are received, it uses RTNL for a long time.
So it makes the control-plane bottleneck because of using RTNL. In order to avoid this bottleneck, mc_lock is added.
mc_lock protect only per-interface mld data and per-interface mld data is used in the query/report event handler logic.
So, no longer rtnl_lock is needed in the query/report event handler logic. Therefore bottleneck will be disappeared by mc_lock.
---
v3:
- Initial patch
include/net/if_inet6.h | 1 + net/ipv6/mcast.c | 309 +++++++++++++++++++++++++---------------- 2 files changed, 194 insertions(+), 116 deletions(-)
include/net/if_inet6.h +1 -0
@@ -190,6 +190,7 @@ struct inet6_dev {spinlock_t mc_query_lock;/* mld query queue lock */ spinlock_t mc_report_lock;/* mld query report lock */ +struct mutex mc_lock;/* mld global lock */ struct ifacaddr6 *ac_list;rwlock_t lock;
net/ipv6/mcast.c +193 -116
1,024 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 104 lines · Taehee Yoo
This patchset changes the context of MLD module.
Before this patchset, MLD functions are atomic context so it couldn't use sleepable functions and flags.There are several reasons why MLD functions are under atomic context.
1. It uses timer API.
Timer expiration functions are executed in the atomic context.
2. atomic locks
MLD functions use rwlock and spinlock to protect their own resources.So, in order to switch context, this patchset converts resources to use RCU and removes atomic locks and timer API.
1. The first patch convert from the timer API to delayed work. Timer API is used for delaying some works.
MLD protocol has a delay mechanism, which is used for replying to a query. If a listener receives a query from a router, it should send a response after some delay. But because of timer expire function is executed in the atomic context, this patch convert from timer API to the delayed work.2. The fourth patch deletes
inet6_dev->mc_lock.
Themc_lockhas protectedinet6_dev->mc_tombpointer.
But this pointer is already protected by RTNL and it isn't be used by datapath. So, it isn't be needed and because of this, many atomic context critical sections are deleted.3. The fifth patch convert
ip6_sf_socklistto RCU.ip6_sf_socklisthas been protected byipv6_mc_socklist->sflock(rwlock). But this is already protected by RTNL So if it is converted to use RCU in order to be used in the datapath, the sflock is no more needed. So, its control path context can be switched to sleepable.4. The sixth patch convert
ip6_sf_listto RCU.
The reason for this patch is the same as the previous patch.5. The seventh patch convert ifmcaddr6 to RCU.
The reason for this patch is the same as the previous patch.6. Add new workqueues for processing query/report event. By this patch, query and report events are processed by workqueue So context is sleepable, not atomic.
While this logic, it acquires RTNL.7. Add new
mc_lock.
The purpose of this lock is to protect per-interface mld data. Per-interface mld data is usually used by query/report event handler. So, query/report event workers need only this lock instead of RTNL. Therefore, it could reduce bottleneck.Changelog:
v2 -> v3:
1. Do not usemsecs_to_jiffies().
(by Cong Wang)
2. Do not add unnecessaryrtnl_lock()andrtnl_unlock().
(by Cong Wang)
3. Fix sparse warnings because of rcu annotation.
(by kernel test robot)
- Remove somercu_assign_pointer(), which was used for non-rcu pointer.
- Add union for rcu pointer.
- Use rcu API inmld_clear_zeros().
- Remove remainedrcu_read_unlock().
- Use rcu API for tomb resources.
4. withdraw prevopus 2nd and 3rd patch.
- "separate two flags fromifmcaddr6->mca_flags"
- "add a newdelayed_work,mc_delrec_work"
5. Add 6th and 7th patch.v1 -> v2:
1. Withdraw unnecessary refactoring patches.
(by Cong Wang, Eric Dumazet, David Ahern)
a) convert from array to list.
b) function rename.
2. Separate big one patch into small several patches.
3. Do not rename 'ifmcaddr6->mca_lock'.
In the v1 patch, this variable was changed to 'ifmcaddr6->mca_work_lock'. But this is actually not needed.
4. Do not useatomic_tfor 'ifmcaddr6->mca_sfcount' and 'ipv6_mc_socklist'->sf_count'.
5. Do not addmld_check_leave_group()function.
6. Do not addip6_mc_del_src_bulk()function.
7. Do not addip6_mc_add_src_bulk()function.
8. Do not usercu_read_lock()in theqeth_l3_add_mcast_rtnl(). (by Julian Wiedmann)Taehee Yoo (7):
mld: convert from timer to delayed work
mld: get rid ofinet6_dev->mc_lock
mld: convertipv6_mc_socklist->sflistto RCU
mld: convertip6_sf_listto RCU
mld: convert ifmcaddr6 to RCU
mld: add new workqueues for process mld events
mld: addmc_lockfor protecting per-interface mld datadrivers/s390/net/qeth_l3_main.c | 6 +- include/net/if_inet6.h | 37 +- include/net/mld.h | 3 + net/batman-adv/multicast.c | 6 +- net/ipv6/addrconf.c | 9 +- net/ipv6/addrconf_core.c | 2 +- net/ipv6/af_inet6.c | 2 +- net/ipv6/icmp.c | 4 +- net/ipv6/mcast.c | 1080 ++++++++++++++++++------------- 9 files changed, 678 insertions(+), 471 deletions(-)
Re: [PATCH net-next v3 5/7] mld: convert ifmcaddr6 to RCU
In reply to Taehee YooQuoted 6 lines · Taehee Yoo
The ifmcaddr6 has been protected by
inet6_dev->lock(rwlock)so that the critical section is atomic context. In order to switch this context, changing locking is needed. The ifmcaddr6 actually already protected by RTNL So if it's converted to use RCU, its control path context can be switched to sleepable.
I do not really understand the changelog.
You wanted to convert from RCU to RTNL, right ?
Also :
Quoted 4 lines
net/ipv6/mcast.c +0
-0@@ -571,13 +573,9 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,if (!ipv6_addr_is_multicast (group))return -EINVAL ;
net/ipv6/mcast.c int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, · line 579
Quoted 10 lines
net/ipv6/mcast.c +2
-6-rcu_read_lock (); - idev =ip6_mc_find_dev_rcu (net, group, gsf->gf_interface); - -if (!idev) { -rcu_read_unlock (); + idev =ip6_mc_find_dev_rtnl (net, group, gsf->gf_interface); +if (!idev)return -ENODEV ; - }
I do not see RTNL being acquired before entering ip6_mc_msfget()
Re: [PATCH net-next v3 5/7] mld: convert ifmcaddr6 to RCU
Quoted 2 lines · Eric Dumazet
Hi Eric,
Thank you for the review!
Quoted 11 lines · Taehee Yoo
Quoted 6 lines
The ifmcaddr6 has been protected by
inet6_dev->lock(rwlock)so that the critical section is atomic context. In order to switch this context, changing locking is needed. The ifmcaddr6 actually already protected by RTNL So if it's converted to use RCU, its control path context can be switched to sleepable.I do not really understand the changelog.
You wanted to convert from RCU to RTNL, right ?
The purpose of this is to use both RCU and RTNL. In the control path, ifmcaddr6 is protected by RTNL (setsockopt_needs_rtnl() in the do_ipv6_setsockopt()) And in the data path, ifmcaddr6 will be protected by RCU.
But ifmcaddr6 is already protected by RTNL in the control path. So, this patch is to convert ifmcaddr6 to RCU only for datapath. Therefore, by this patch, ifmcaddr6 will be protected by both RTNL and RCU.
I'm so sorry for this strange changelog.
Quoted 7 lines
Also :
Quoted 4 lines
net/ipv6/mcast.c +0
-0@@ -571,13 +573,9 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,if (!ipv6_addr_is_multicast (group))return -EINVAL ;
Quoted 13 lines
net/ipv6/mcast.c int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf, · line 500
Quoted 10 lines
net/ipv6/mcast.c +2
-6-rcu_read_lock (); - idev =ip6_mc_find_dev_rcu (net, group, gsf->gf_interface); - -if (!idev) { -rcu_read_unlock (); + idev =ip6_mc_find_dev_rtnl (net, group, gsf->gf_interface); +if (!idev)return -ENODEV ; - }I do not see RTNL being acquired before entering
ip6_mc_msfget()
Thank you so much for catching this.
I will send a patch to fix this problem!
Thanks a lot!
Taehee Yoo
Re: [PATCH net-next v3 7/7] mld: add mc_lock for protecting per-interface mld data
In reply to Taehee YooQuoted 10 lines · Taehee Yoo
The purpose of this lock is to avoid a bottleneck in the query/report event handler logic.
By previous patches, almost all mld data is protected by RTNL. So, the query and report event handler, which is data path logic acquires RTNL too. Therefore if a lot of query and report events are received, it uses RTNL for a long time.
So it makes the control-plane bottleneck because of using RTNL. In order to avoid this bottleneck,mc_lockis added.
Quoted 5 lines
mc_lockprotect only per-interface mld data and per-interface mld data is used in the query/report event handler logic.
So, no longerrtnl_lockis needed in the query/report event handler logic. Therefore bottleneck will be disappeared bymc_lock.
What testsuite have you run exactly to validate this monster patch ?
Have you used CONFIG_LOCKDEP=y / CONFIG_DEBUG_ATOMIC_SLEEP=y ?
Quoted 2 lines
Suggested-by Cong Wang <[email protected]>Signed-off-by Taehee Yoo <[email protected]>
[...]
Quoted 7 lines
/*
- * device multicast group del
+ * device multicast group del
*/
int__ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr){
net/ipv6/mcast.c int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) · line 975
Quoted 10 lines
net/ipv6/mcast.c +2
-1@@ -943,8 +967,9 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr)ASSERT_RTNL (); +mutex_lock (&idev->mc_lock);for (map = &idev->mc_list; - (ma =rtnl_dereference (*map)); + (ma =mc_dereference (*map, idev)); map = &ma->next) {if (ipv6_addr_equal (&ma->mca_addr, addr)) {if (--ma->mca_users ==0 ) {
This can be called with rcu_bh held, thus :
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:928
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 4624, name: kworker/1:2
4 locks held by kworker/1:2/4624:
#0: ffff88802135d138 ((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at: arch_atomic64_set arch/x86/include/asm/atomic64_64.h:34 [inline] #0: ffff88802135d138 ((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at: atomic64_set include/asm-generic/atomic-instrumented.h:856 [inline] #0: ffff88802135d138 ((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at: atomic_long_set include/asm-generic/atomic-long.h:41 [inline] #0: ffff88802135d138 ((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at: set_work_data kernel/workqueue.c:616 [inline] #0: ffff88802135d138 ((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at: set_work_pool_and_clear_pending kernel/workqueue.c:643 [inline] #0: ffff88802135d138 ((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at: process_one_work+0x871/0x1600 kernel/workqueue.c:2246 #1: ffffc90009adfda8 ((addr_chk_work).work){+.+.}-{0:0}, at: process_one_work+0x8a5/0x1600 kernel/workqueue.c:2250 #2: ffffffff8d66d328 (rtnl_mutex){+.+.}-{3:3}, at: addrconf_verify_work+0xa/0x20 net/ipv6/addrconf.c:4572
#3: ffffffff8bf74300 (rcu_read_lock_bh){....}-{1:2}, at: addrconf_verify_rtnl+0x2b/0x1150 net/ipv6/addrconf.c:4459
Preemption disabled at:
[<ffffffff87b39f41>] local_bh_disable include/linux/bottom_half.h:19 [inline] [<ffffffff87b39f41>] rcu_read_lock_bh include/linux/rcupdate.h:727 [inline] [<ffffffff87b39f41>] addrconf_verify_rtnl+0x41/0x1150 net/ipv6/addrconf.c:4461 CPU: 1 PID: 4624 Comm: kworker/1:2 Not tainted 5.12.0-rc4-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: ipv6_addrconf addrconf_verify_work Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x141/0x1d7 lib/dump_stack.c:120 ___might_sleep.cold+0x1f1/0x237 kernel/sched/core.c:8328 __mutex_lock_common kernel/locking/mutex.c:928 [inline] __mutex_lock+0xa9/0x1120 kernel/locking/mutex.c:1096 __ipv6_dev_mc_dec+0x5f/0x340 net/ipv6/mcast.c:970 addrconf_leave_solict net/ipv6/addrconf.c:2182 [inline] addrconf_leave_solict net/ipv6/addrconf.c:2174 [inline] __ipv6_ifa_notify+0x5b6/0xa90 net/ipv6/addrconf.c:6077 ipv6_ifa_notify net/ipv6/addrconf.c:6100 [inline] ipv6_del_addr+0x463/0xae0 net/ipv6/addrconf.c:1294 addrconf_verify_rtnl+0xd59/0x1150 net/ipv6/addrconf.c:4488 addrconf_verify_work+0xf/0x20 net/ipv6/addrconf.c:4573 process_one_work+0x98d/0x1600 kernel/workqueue.c:2275 worker_thread+0x64c/0x1120 kernel/workqueue.c:2421 kthread+0x3b1/0x4a0 kernel/kthread.c:292 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
Re: [PATCH net-next v3 7/7] mld: add mc_lock for protecting per-interface mld data
Quoted 77 lines · Eric Dumazet
Quoted 10 lines · Taehee Yoo
The purpose of this lock is to avoid a bottleneck in the query/report event handler logic.
By previous patches, almost all mld data is protected by RTNL. So, the query and report event handler, which is data path logic acquires RTNL too. Therefore if a lot of query and report events are received, it uses RTNL for a long time.
So it makes the control-plane bottleneck because of using RTNL. In order to avoid this bottleneck,mc_lockis added.Quoted 5 lines
mc_lockprotect only per-interface mld data and per-interface mld data is used in the query/report event handler logic.
So, no longerrtnl_lockis needed in the query/report event handler logic. Therefore bottleneck will be disappeared bymc_lock.What testsuite have you run exactly to validate this monster patch ?
Have you used
CONFIG_LOCKDEP=y/CONFIG_DEBUG_ATOMIC_SLEEP=y?Quoted 2 lines
Suggested-by Cong Wang <[email protected]>Signed-off-by Taehee Yoo <[email protected]>[...]
Quoted 7 lines
/*
- * device multicast group del
+ * device multicast group del
*/
int__ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr){Review int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) · line 975
Quoted 10 lines
(quoted diff) +2
-1@@ -943,8 +967,9 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) ASSERT_RTNL(); + mutex_lock(&idev->mc_lock); for (map = &idev->mc_list; - (ma = rtnl_dereference(*map)); + (ma = mc_dereference(*map, idev)); map = &ma->next) { if (ipv6_addr_equal(&ma->mca_addr, addr)) { if (--ma->mca_users == 0) {This can be called with
rcu_bhheld, thus :BUG: sleeping function called from invalid context at kernel/locking/mutex.c:928
in_atomic(): 1,irqs_disabled(): 0,non_block: 0, pid: 4624, name: kworker/1:2
4 locks held by kworker/1:2/4624:
#0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:arch_atomic64_setarch/x86/include/asm/atomic64_64.h:34[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:atomic64_setinclude/asm-generic/atomic-instrumented.h:856[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:atomic_long_setinclude/asm-generic/atomic-long.h:41[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:set_work_datakernel/workqueue.c:616[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:set_work_pool_and_clear_pendingkernel/workqueue.c:643[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:process_one_work+0x871/0x1600kernel/workqueue.c:2246#1:ffffc90009adfda8((addr_chk_work).work){+.+.}-{0:0}, at:process_one_work+0x8a5/0x1600kernel/workqueue.c:2250#2:ffffffff8d66d328(rtnl_mutex){+.+.}-{3:3}, at:addrconf_verify_work+0xa/0x20net/ipv6/addrconf.c:4572
#3:ffffffff8bf74300(rcu_read_lock_bh){....}-{1:2}, at:addrconf_verify_rtnl+0x2b/0x1150net/ipv6/addrconf.c:4459
Preemption disabled at:[<ffffffff87b39f41>] local_bh_disable include/linux/bottom_half.h:19 [inline] [<ffffffff87b39f41>] rcu_read_lock_bh include/linux/rcupdate.h:727 [inline] [<ffffffff87b39f41>] addrconf_verify_rtnl+0x41/0x1150 net/ipv6/addrconf.c:4461 CPU: 1 PID: 4624 Comm: kworker/1:2 Not tainted 5.12.0-rc4-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: ipv6_addrconf addrconf_verify_work Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x141/0x1d7 lib/dump_stack.c:120 ___might_sleep.cold+0x1f1/0x237 kernel/sched/core.c:8328 __mutex_lock_common kernel/locking/mutex.c:928 [inline] __mutex_lock+0xa9/0x1120 kernel/locking/mutex.c:1096 __ipv6_dev_mc_dec+0x5f/0x340 net/ipv6/mcast.c:970 addrconf_leave_solict net/ipv6/addrconf.c:2182 [inline] addrconf_leave_solict net/ipv6/addrconf.c:2174 [inline] __ipv6_ifa_notify+0x5b6/0xa90 net/ipv6/addrconf.c:6077
Quoted 9 lines
ipv6_ifa_notify net/ipv6/addrconf.c:6100 [inline] ipv6_del_addr+0x463/0xae0 net/ipv6/addrconf.c:1294 addrconf_verify_rtnl+0xd59/0x1150 net/ipv6/addrconf.c:4488 addrconf_verify_work+0xf/0x20 net/ipv6/addrconf.c:4573 process_one_work+0x98d/0x1600 kernel/workqueue.c:2275 worker_thread+0x64c/0x1120 kernel/workqueue.c:2421 kthread+0x3b1/0x4a0 kernel/kthread.c:292 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
I will test this fix:
net/ipv6/addrconf.c +2 -0
@@ -4485,7 +4485,9 @@ static void addrconf_verify_rtnl(void) age >= ifp->valid_lft) {spin_unlock (&ifp->lock);in6_ifa_hold (ifp); +rcu_read_unlock_bh ();ipv6_del_addr (ifp); +rcu_read_lock_bh (); goto restart; } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) {spin_unlock (&ifp->lock);
Re: [PATCH net-next v3 7/7] mld: add mc_lock for protecting per-interface mld data
Quoted 16 lines · Eric Dumazet
Quoted 13 lines · Eric Dumazet
Quoted 10 lines · Taehee Yoo
The purpose of this lock is to avoid a bottleneck in the query/report event handler logic.
By previous patches, almost all mld data is protected by RTNL. So, the query and report event handler, which is data path logic acquires RTNL too. Therefore if a lot of query and report events are received, it uses RTNL for a long time.
So it makes the control-plane bottleneck because of using RTNL. In order to avoid this bottleneck,mc_lockis added.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
mc_lockprotect only per-interface mld data and per-interface mld data is used in the query/report event handler logic.
So, no longerrtnl_lockis needed in the query/report event handler logic. Therefore bottleneck will be disappeared bymc_lock.What testsuite have you run exactly to validate this monster patch ?
I've been using an application, which calls setsockopt() with the below options. IPV6_ADD_MEMBERSHIPIPV6_DROP_MEMBERSHIPMCAST_JOIN_SOURCE_GROUPMCAST_LEAVE_SOURCE_GROUPMCAST_BLOCK_SOURCEMCAST_UNBLOCK_SOURCEMCAST_MSFILTER
And checks out /proc/net/mcfilter6 and /proc/net/igmp6.
Quoted 2 lines
Quoted 2 lines
Have you used
CONFIG_LOCKDEP=y/CONFIG_DEBUG_ATOMIC_SLEEP=y?
Yes, I'm using both configs.
Quoted 64 lines
Quoted 54 lines
Quoted 2 lines
Suggested-by Cong Wang <[email protected]>Signed-off-by Taehee Yoo <[email protected]>[...]
Quoted 7 lines
/*
- * device multicast group del
+ * device multicast group del
*/
int__ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr){Review int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) · line 975
Quoted 10 lines
(quoted diff) +2
-1@@ -943,8 +967,9 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) ASSERT_RTNL(); + mutex_lock(&idev->mc_lock); for (map = &idev->mc_list; - (ma = rtnl_dereference(*map)); + (ma = mc_dereference(*map, idev)); map = &ma->next) { if (ipv6_addr_equal(&ma->mca_addr, addr)) { if (--ma->mca_users == 0) {This can be called with
rcu_bhheld, thus :BUG: sleeping function called from invalid context at kernel/locking/mutex.c:928
in_atomic(): 1,irqs_disabled(): 0,non_block: 0, pid: 4624, name: kworker/1:2
4 locks held by kworker/1:2/4624:
#0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:arch_atomic64_setarch/x86/include/asm/atomic64_64.h:34[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:atomic64_setinclude/asm-generic/atomic-instrumented.h:856[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:atomic_long_setinclude/asm-generic/atomic-long.h:41[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:set_work_datakernel/workqueue.c:616[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:set_work_pool_and_clear_pendingkernel/workqueue.c:643[inline] #0:ffff88802135d138((wq_completion)ipv6_addrconf){+.+.}-{0:0}, at:process_one_work+0x871/0x1600kernel/workqueue.c:2246#1:ffffc90009adfda8((addr_chk_work).work){+.+.}-{0:0}, at:process_one_work+0x8a5/0x1600kernel/workqueue.c:2250#2:ffffffff8d66d328(rtnl_mutex){+.+.}-{3:3}, at:addrconf_verify_work+0xa/0x20net/ipv6/addrconf.c:4572
#3:ffffffff8bf74300(rcu_read_lock_bh){....}-{1:2}, at:addrconf_verify_rtnl+0x2b/0x1150net/ipv6/addrconf.c:4459
Preemption disabled at:[<ffffffff87b39f41>] local_bh_disable include/linux/bottom_half.h:19 [inline] [<ffffffff87b39f41>] rcu_read_lock_bh include/linux/rcupdate.h:727 [inline] [<ffffffff87b39f41>] addrconf_verify_rtnl+0x41/0x1150 net/ipv6/addrconf.c:4461 CPU: 1 PID: 4624 Comm: kworker/1:2 Not tainted 5.12.0-rc4-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: ipv6_addrconf addrconf_verify_work Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x141/0x1d7 lib/dump_stack.c:120 ___might_sleep.cold+0x1f1/0x237 kernel/sched/core.c:8328 __mutex_lock_common kernel/locking/mutex.c:928 [inline] __mutex_lock+0xa9/0x1120 kernel/locking/mutex.c:1096 __ipv6_dev_mc_dec+0x5f/0x340 net/ipv6/mcast.c:970 addrconf_leave_solict net/ipv6/addrconf.c:2182 [inline] addrconf_leave_solict net/ipv6/addrconf.c:2174 [inline] __ipv6_ifa_notify+0x5b6/0xa90 net/ipv6/addrconf.c:6077Quoted 9 lines
ipv6_ifa_notify net/ipv6/addrconf.c:6100 [inline] ipv6_del_addr+0x463/0xae0 net/ipv6/addrconf.c:1294 addrconf_verify_rtnl+0xd59/0x1150 net/ipv6/addrconf.c:4488 addrconf_verify_work+0xf/0x20 net/ipv6/addrconf.c:4573 process_one_work+0x98d/0x1600 kernel/workqueue.c:2275 worker_thread+0x64c/0x1120 kernel/workqueue.c:2421 kthread+0x3b1/0x4a0 kernel/kthread.c:292 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
Quoted 1 line
I will test this fix:
Thanks a lot!
Quoted 16 lines
net/ipv6/addrconf.c +2
-0@@ -4485,7 +4485,9 @@ static void addrconf_verify_rtnl(void) age >= ifp->valid_lft) {spin_unlock (&ifp->lock);in6_ifa_hold (ifp); +rcu_read_unlock_bh ();ipv6_del_addr (ifp); +rcu_read_lock_bh (); goto restart; } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) {spin_unlock (&ifp->lock);