mld: change context of mld module
Subsystems (6)
PATCH 8/8 mld: change context of mld module
MLD module's context is atomic although most logic is called from control-path, not data path. Only a few functions are called from datapath, most of the functions are called from the control-path. Furthermore, MLD's response is not processed immediately because MLD protocol is using delayed response.
It means that If a query is received, the node should have a delay in response At this point, it could change the context. It means most of the functions can be implemented as the sleepable context so that mld functions can use sleepable functions.
Most resources are protected by spinlock and rwlock so the context of mld functions is atomic. So, in order to change context, locking scenario should be changed.
It switches from spinlock/rwlock to mutex and rcu.
Some locks are deleted and added.
1. ipv6->mc_socklist->sflock is deleted
This is rwlock and it is unnecessary.
Because it protects ipv6_mc_socklist-sflist but it is now protected by rtnl_lock().
2. ifmcaddr6->mca_work_lock is added.
This lock protects ifmcaddr6->mca_work.
This workqueue can be used by both control-path and data-path. It means mutex can't be used.
So mca_work_lock(spinlock) is added.
3. inet6_dev->mc_tomb_lock is deleted
This lock protects inet6_dev->mc_bom_list.
But it is protected by rtnl_lock().
4. inet6_dev->lock is used for protecting workqueues. inet6_dev has its own workqueues(mc_gq_work, mc_ifc_work, mc_delrec_work) and it can be started and stop by both control-path and data-path. So, mutex can't be used.
--- drivers/s390/net/qeth_l3_main.c | 6 +- include/net/if_inet6.h | 29 +- net/batman-adv/multicast.c | 4 +- net/ipv6/addrconf.c | 4 +- net/ipv6/mcast.c | 785 ++++++++++++++++---------------- 5 files changed, 411 insertions(+), 417 deletions(-)
drivers/s390/net/qeth_l3_main.c +3 -3
@@ -1098,8 +1098,8 @@ 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); -list_for_each_entry (im6, in6_dev->mc_list, list) { +rcu_read_lock (); +list_for_each_entry_rcu (im6, in6_dev->mc_list, list) { tmp.u.a6.addr = im6->mca_addr; ipm =qeth_l3_find_addr_by_ip (card, &tmp);
@@ -1117,7 +1117,7 @@ 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); +rcu_read_unlock (); out:return 0 ;
include/net/if_inet6.h +17 -12
@@ -88,7 +88,6 @@ struct ipv6_mc_socklist {bool sfmode;/* MCAST_{INCLUDE,EXCLUDE} */ struct list_head list;struct list_head sflist; -rwlock_t sflock;atomic_t sl_count;struct rcu_head rcu; };
@@ -96,17 +95,19 @@ struct ipv6_mc_socklist {struct ip6_sf_list {struct list_head list;struct in6_addr sf_addr; -unsigned long sf_count[2 ];/* include/exclude counts */ +atomic_t incl_count;/* include count */ +atomic_t excl_count;/* exclude count */ unsigned char sf_gsresp;/* include in g & s response? */ bool sf_oldin;/* change state */ unsigned char sf_crcount;/* retrans. left to send */ +struct rcu_head rcu; }; -#define MAF_TIMER_RUNNING 0x01 -#define MAF_LAST_REPORTER 0x02 -#define MAF_LOADED 0x04 -#define MAF_NOREPORT 0x08 -#define MAF_GSQUERY 0x10 +enum mca_enum { +MCA_TIMER_RUNNING , +MCA_LAST_REPORTER , +MCA_GSQUERY , +};struct ifmcaddr6 {struct in6_addr mca_addr;
@@ -116,14 +117,18 @@ struct ifmcaddr6 {struct list_head mca_tomb_list;unsigned int mca_sfmode;unsigned char mca_crcount; -unsigned long mca_sfcount[2 ]; -struct delayed_work mca_work; -unsigned int mca_flags; +atomic_t mca_incl_count; +atomic_t mca_excl_count; +struct delayed_work mca_work;/* Protected by mca_work_lock */ +spinlock_t mca_work_lock; +unsigned long mca_flags; +bool mca_noreport; +bool mca_loaded;int mca_users;refcount_t mca_refcnt; -spinlock_t mca_lock;unsigned long mca_cstamp;unsigned long mca_tstamp; +struct rcu_head rcu; };/* Anycast stuff */
@@ -163,7 +168,6 @@ struct inet6_dev {struct list_head addr_list;struct list_head mc_list;struct list_head mc_tomb_list; -spinlock_t mc_tomb_lock;unsigned char mc_qrv;/* Query Robustness Variable */ unsigned char mc_gq_running;
@@ -178,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;struct ifacaddr6 *ac_list;rwlock_t lock;
net/batman-adv/multicast.c +1 -3
@@ -454,8 +454,7 @@ batadv_mcast_mla_softif_get_ipv6(struct net_device *dev,return 0 ; } -read_lock_bh (&in6_dev->lock); -list_for_each_entry (pmc6, &in6_dev->mc_list, list) { +list_for_each_entry_rcu (pmc6, &in6_dev->mc_list, list) {if (IPV6_ADDR_MC_SCOPE (&pmc6->mca_addr) <IPV6_ADDR_SCOPE_LINKLOCAL )continue ;
@@ -484,7 +483,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 +1 -3
@@ -5110,7 +5110,7 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb, fillargs->event =RTM_GETMULTICAST ;/* multicast address */ -list_for_each_entry (ifmca, &idev->mc_list, list) { +list_for_each_entry_rcu (ifmca, &idev->mc_list, list) {if (ip_idx < s_ip_idx) goto next2; err =inet6_fill_ifmcaddr (skb, ifmca, fillargs);
@@ -6094,10 +6094,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/mcast.c +389 -396
1,848 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Taehee,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Taehee-Yoo/mld-change-context-from-atomic-to-sleepable/20210209-072339 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6626a0266566c5aea16178c5e6cd7fc4db3f2f56 config: mips-allyesconfig (attached as .config) compiler: mips-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9ac7d23c98251efc265073a0d63930c91739cc02
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Taehee-Yoo/mld-change-context-from-atomic-to-sleepable/20210209-072339 git checkout 9ac7d23c98251efc265073a0d63930c91739cc02
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> net/ipv6/mcast.c:333:6: warning: no previous prototype for 'mld_check_leave_group' [-Wmissing-prototypes]
333 | bool mld_check_leave_group(struct ipv6_mc_socklist *mc_lst, int omode)
| ^~~~~~~~~~~~~~~~~~~~~
net/ipv6/mcast.c: In function 'ip6_mc_del_src':
net/ipv6/mcast.c:2153:6: warning: variable 'i' set but not used [-Wunused-but-set-variable]
2153 | int i, err, rv;
| ^vim +/mld_check_leave_group +333 net/ipv6/mcast.c
331
332 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
> 333 bool mld_check_leave_group(struct ipv6_mc_socklist *mc_lst, int omode)
334 {
335 if (atomic_read(&mc_lst->sl_count) == 1 && omode == MCAST_INCLUDE)
336 return true;
337 else
338 return false;
339 }
340
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Taehee,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Taehee-Yoo/mld-change-context-from-atomic-to-sleepable/20210209-072339 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6626a0266566c5aea16178c5e6cd7fc4db3f2f56 config: powerpc64-randconfig-r015-20210209 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# https://github.com/0day-ci/linux/commit/9ac7d23c98251efc265073a0d63930c91739cc02
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Taehee-Yoo/mld-change-context-from-atomic-to-sleepable/20210209-072339 git checkout 9ac7d23c98251efc265073a0d63930c91739cc02
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> net/ipv6/mcast.c:333:6: warning: no previous prototype for function 'mld_check_leave_group' [-Wmissing-prototypes]
bool mld_check_leave_group(struct ipv6_mc_socklist *mc_lst, int omode)
^ net/ipv6/mcast.c:333:1: note: declare 'static' if the function is not intended to be used outside of this translation unit bool mld_check_leave_group(struct ipv6_mc_socklist *mc_lst, int omode)
^
static
1 warning generated.
vim +/mld_check_leave_group +333 net/ipv6/mcast.c
331
332 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
> 333 bool mld_check_leave_group(struct ipv6_mc_socklist *mc_lst, int omode)
334 {
335 if (atomic_read(&mc_lst->sl_count) == 1 && omode == MCAST_INCLUDE)
336 return true;
337 else
338 return false;
339 }
340
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Taehee,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Taehee-Yoo/mld-change-context-from-atomic-to-sleepable/20210209-072339 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6626a0266566c5aea16178c5e6cd7fc4db3f2f56 config: i386-randconfig-s002-20210209 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-215-g0fb77bb6-dirty # https://github.com/0day-ci/linux/commit/9ac7d23c98251efc265073a0d63930c91739cc02 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Taehee-Yoo/mld-change-context-from-atomic-to-sleepable/20210209-072339 git checkout 9ac7d23c98251efc265073a0d63930c91739cc02 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
"sparse warnings: (new ones prefixed by >>)"
>> net/ipv6/mcast.c:333:6: sparse: sparse: symbol 'mld_check_leave_group' was not declared. Should it be static?
net/ipv6/mcast.c: note: in included file:
include/net/mld.h:32:43: sparse: sparse: array of flexible structures
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build bot[RFC PATCH] mld: mld_check_leave_group() can be static
In reply to Taehee YooReported-by: kernel test robot <[email protected]>
--- mcast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/mcast.c +1 -1
@@ -330,7 +330,7 @@ void ipv6_sock_mc_close(struct sock *sk) }/* special case - (INCLUDE, empty) == LEAVE_GROUP */ -bool mld_check_leave_group (struct ipv6_mc_socklist *mc_lst,int omode) +static bool mld_check_leave_group (struct ipv6_mc_socklist *mc_lst,int omode) {if (atomic_read (&mc_lst->sl_count) ==1 && omode ==MCAST_INCLUDE )return true;
Quoted 51 lines · Taehee Yoo
MLD module's context is atomic although most logic is called from control-path, not data path. Only a few functions are called from datapath, most of the functions are called from the control-path. Furthermore, MLD's response is not processed immediately because MLD protocol is using delayed response.
It means that If a query is received, the node should have a delay in response At this point, it could change the context. It means most of the functions can be implemented as the sleepable context so that mld functions can use sleepable functions.Most resources are protected by spinlock and rwlock so the context of mld functions is atomic. So, in order to change context, locking scenario should be changed.
It switches from spinlock/rwlock to mutex and rcu.Some locks are deleted and added.
1.ipv6->mc_socklist->sflockis deleted
This is rwlock and it is unnecessary.
Because it protects ipv6_mc_socklist-sflist but it is now protected byrtnl_lock().2.
ifmcaddr6->mca_work_lockis added.
This lock protectsifmcaddr6->mca_work.
This workqueue can be used by both control-path and data-path. It means mutex can't be used.
Somca_work_lock(spinlock)is added.3.
inet6_dev->mc_tomb_lockis deleted
This lock protectsinet6_dev->mc_bom_list.
But it is protected byrtnl_lock().4.
inet6_dev->lockis used for protecting workqueues.inet6_devhas its ownworkqueues(mc_gq_work, mc_ifc_work, mc_delrec_work)and it can be started and stop by both control-path and data-path. So, mutex can't be used.Suggested-by Cong Wang <[email protected]>Signed-off-by Taehee Yoo <[email protected]>--- drivers/s390/net/qeth_l3_main.c | 6 +- include/net/if_inet6.h | 29 +- net/batman-adv/multicast.c | 4 +- net/ipv6/addrconf.c | 4 +- net/ipv6/mcast.c | 785 ++++++++++++++++---------------- 5 files changed, 411 insertions(+), 417 deletions(-)drivers/s390/net/qeth_l3_main.c +0
-0
drivers/s390/net/qeth_l3_main.c static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg) · line 1102
Quoted 7 lines
drivers/s390/net/qeth_l3_main.c +2
-2@@ -1098,8 +1098,8 @@ 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); -list_for_each_entry (im6, in6_dev->mc_list, list) { +rcu_read_lock (); +list_for_each_entry_rcu (im6, in6_dev->mc_list, list) {
No need for the rcu_read_lock(), we're called under rtnl. So if there's a v2, please just make this
list_for_each_entry_rcu(im6, in6_dev->mc_list, list, lockdep_rtnl_is_held())
Quoted 12 lines
drivers/s390/net/qeth_l3_main.c +1
-1tmp.u.a6.addr = im6->mca_addr; ipm =qeth_l3_find_addr_by_ip (card, &tmp);@@ -1117,7 +1117,7 @@ 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); +rcu_read_unlock (); out:return 0 ;
Quoted 1 line · Julian Wiedmann
Hi Julian,
Thank you for the review!
Quoted 55 lines · Taehee Yoo
Quoted 54 lines
MLD module's context is atomic although most logic is called from control-path, not data path. Only a few functions are called from datapath, most of the functions are called from the control-path. Furthermore, MLD's response is not processed immediately because MLD protocol is using delayed response.
It means that If a query is received, the node should have a delay in response At this point, it could change the context. It means most of the functions can be implemented as the sleepable context so that mld functions can use sleepable functions.Most resources are protected by spinlock and rwlock so the context of mld functions is atomic. So, in order to change context, locking scenario should be changed.
It switches from spinlock/rwlock to mutex and rcu.Some locks are deleted and added.
1.ipv6->mc_socklist->sflockis deleted
This is rwlock and it is unnecessary.
Because it protects ipv6_mc_socklist-sflist but it is now protected byrtnl_lock().2.
ifmcaddr6->mca_work_lockis added.
This lock protectsifmcaddr6->mca_work.
This workqueue can be used by both control-path and data-path. It means mutex can't be used.
Somca_work_lock(spinlock)is added.3.
inet6_dev->mc_tomb_lockis deleted
This lock protectsinet6_dev->mc_bom_list.
But it is protected byrtnl_lock().4.
inet6_dev->lockis used for protecting workqueues.inet6_devhas its ownworkqueues(mc_gq_work, mc_ifc_work, mc_delrec_work)and it can be started and stop by both control-path and data-path. So, mutex can't be used.Suggested-by Cong Wang <[email protected]>Signed-off-by Taehee Yoo <[email protected]>--- drivers/s390/net/qeth_l3_main.c | 6 +- include/net/if_inet6.h | 29 +- net/batman-adv/multicast.c | 4 +- net/ipv6/addrconf.c | 4 +- net/ipv6/mcast.c | 785 ++++++++++++++++---------------- 5 files changed, 411 insertions(+), 417 deletions(-)drivers/s390/net/qeth_l3_main.c +0
-0@@ -1098,8 +1098,8 @@ 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 ;
Quoted 8 lines
drivers/s390/net/qeth_l3_main.c static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg) · line 1102
Quoted 4 lines
drivers/s390/net/qeth_l3_main.c +2
-2-read_lock_bh (&in6_dev->lock); -list_for_each_entry (im6, in6_dev->mc_list, list) { +rcu_read_lock (); +list_for_each_entry_rcu (im6, in6_dev->mc_list, list) {No need for the
rcu_read_lock(), we're called under rtnl. So if there's a v2, please just make this
Thanks! I missed checking for the RTNL :)
In the next patch, mc_list will not be changed to use list macro. So I will just remove read_{lock | unlock}_bh() in here.
Quoted 9 lines
list_for_each_entry_rcu(im6, in6_dev->mc_list, list, lockdep_rtnl_is_held())Quoted 6 lines
drivers/s390/net/qeth_l3_main.c +0
-0tmp.u.a6.addr = im6->mca_addr; ipm =qeth_l3_find_addr_by_ip (card, &tmp);@@ -1117,7 +1117,7 @@ static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg) qeth_l3_ipaddr_hash(ipm));
Quoted 7 lines
drivers/s390/net/qeth_l3_main.c static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg) · line 1123
Quoted 6 lines
drivers/s390/net/qeth_l3_main.c +1
-1} -read_unlock_bh (&in6_dev->lock); +rcu_read_unlock (); out:return 0 ;
Thanks a lot!
Taehee Yoo