mld: convert ifmcaddr6 to RCU
Subsystems (6)
PATCH v2 7/7 mld: convert ifmcaddr6 to RCU
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.
Because of this conversion, the locking scenario can be changed. So, the locking scenario is changed to the following.
1. ifmcaddr6->mca_lock only protects following resources.
a) ifmcaddr6->mca_flags
b) ifmcaddr6->mca_work.
c) ifmcaddr6->mca_sources->sf_gsresp
2. inet6_dev->lock only protects following resources.
a) inet6_dev->mc_gq_running
b) inet6_dev->mc_gq_work
c) inet6_dev->mc_ifc_count
d) inet6_dev->mc_ifc_work
e) inet6_dev->mc_delerec_work
3. Other resources are protected by RTNL and RCU.
There are only two atomic context locks, they are ifmcaddr6->mca_lock and inet6_dev->lock. These locks are protecting resources, they are written on the datapath.
RTNL can't be used on the datapath, these locks are used.
---
v1 -> v2:
- Separated from previous big one patch.
- Do not rename 'ifmcaddr6->mca_lock'.
- Do not use atomic_t for 'ifmcaddr6->mca_sfcount'
- Do not use atomic_t for 'ipv6_mc_socklist'->sf_count'.
- Do not add mld_check_leave_group() function.
- Do not add ip6_mc_del_src_bulk() function.
- Do not add ip6_mc_add_src_bulk() function.
- Do not use rcu_read_lock() in the qeth_l3_add_mcast_rtnl().
drivers/s390/net/qeth_l3_main.c | 6 +- include/net/if_inet6.h | 5 +- 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 | 340 ++++++++++++++------------------ 7 files changed, 169 insertions(+), 201 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 +3 -2
@@ -113,7 +113,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 *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,7 +167,7 @@ struct inet6_dev {struct list_head addr_list; -struct ifmcaddr6 *mc_list; +struct ifmcaddr6 __rcu *mc_list;struct ifmcaddr6 *mc_tomb;unsigned char mc_qrv;/* Query Robustness Variable */
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 +153 -187
993 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/20210214-015930 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 3c5a2fd042d0bfac71a2dfb99515723d318df47b config: x86_64-randconfig-s022-20210214 (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/05d3b96bdcaec52bc3f2ef1f96e571dc17bf9f5a 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/20210214-015930 git checkout 05d3b96bdcaec52bc3f2ef1f96e571dc17bf9f5a # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
"sparse warnings: (new ones prefixed by >>)"
>> net/ipv6/mcast.c:764:44: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ifmcaddr6 *[assigned] pmc @@ got struct ifmcaddr6 [noderef] __rcu *next @@ net/ipv6/mcast.c:764:44: sparse: expected struct ifmcaddr6 *[assigned] pmc net/ipv6/mcast.c:764:44: sparse: got struct ifmcaddr6 [noderef] __rcu *next >> net/ipv6/mcast.c:773:39: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ifmcaddr6 *mc_tomb @@ got struct ifmcaddr6 [noderef] __rcu *next @@ net/ipv6/mcast.c:773:39: sparse: expected struct ifmcaddr6 *mc_tomb net/ipv6/mcast.c:773:39: sparse: got struct ifmcaddr6 [noderef] __rcu *next net/ipv6/mcast.c:781:35: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct ip6_sf_list [noderef] __rcu *__tmp @@ got struct ip6_sf_list * @@ net/ipv6/mcast.c:781:35: sparse: expected struct ip6_sf_list [noderef] __rcu *__tmp net/ipv6/mcast.c:781:35: sparse: got struct ip6_sf_list * net/ipv6/mcast.c:781:33: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list *sources @@ got struct ip6_sf_list [noderef] __rcu *__tmp @@ net/ipv6/mcast.c:781:33: sparse: expected struct ip6_sf_list *sources net/ipv6/mcast.c:781:33: sparse: got struct ip6_sf_list [noderef] __rcu *__tmp >> net/ipv6/mcast.c:804:25: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ifmcaddr6 *nextpmc @@ got struct ifmcaddr6 [noderef] __rcu *next @@ net/ipv6/mcast.c:804:25: sparse: expected struct ifmcaddr6 *nextpmc net/ipv6/mcast.c:804:25: sparse: got struct ifmcaddr6 [noderef] __rcu *next net/ipv6/mcast.c:2301:43: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list *[assigned] dpsf @@ got struct ip6_sf_list [noderef] __rcu *sf_next @@ net/ipv6/mcast.c:2301:43: sparse: expected struct ip6_sf_list *[assigned] dpsf net/ipv6/mcast.c:2301:43: sparse: got struct ip6_sf_list [noderef] __rcu *sf_next net/ipv6/mcast.c:2311:63: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list *mca_tomb @@ got struct ip6_sf_list [noderef] __rcu *sf_next @@ net/ipv6/mcast.c:2311:63: sparse: expected struct ip6_sf_list *mca_tomb net/ipv6/mcast.c:2311:63: sparse: got struct ip6_sf_list [noderef] __rcu *sf_next net/ipv6/mcast.c:2323:63: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list *[assigned] dpsf @@ got struct ip6_sf_list [noderef] __rcu *sf_next @@ net/ipv6/mcast.c:2323:63: sparse: expected struct ip6_sf_list *[assigned] dpsf net/ipv6/mcast.c:2323:63: sparse: got struct ip6_sf_list [noderef] __rcu *sf_next net/ipv6/mcast.c:2332:47: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list [noderef] __rcu *sf_next @@ got struct ip6_sf_list *mca_tomb @@ net/ipv6/mcast.c:2332:47: sparse: expected struct ip6_sf_list [noderef] __rcu *sf_next net/ipv6/mcast.c:2332:47: sparse: got struct ip6_sf_list *mca_tomb net/ipv6/mcast.c:2410:25: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list *nextpsf @@ got struct ip6_sf_list [noderef] __rcu *sf_next @@ net/ipv6/mcast.c:2410:25: sparse: expected struct ip6_sf_list *nextpsf net/ipv6/mcast.c:2410:25: sparse: got struct ip6_sf_list [noderef] __rcu *sf_next net/ipv6/mcast.c:449:17: sparse: sparse: incompatible types in comparison expression (different address spaces): net/ipv6/mcast.c:449:17: sparse: struct ip6_sf_socklist [noderef] __rcu * net/ipv6/mcast.c:449:17: sparse: struct ip6_sf_socklist * >> net/ipv6/mcast.c:935:38: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ifmcaddr6 [noderef] __rcu * @@ got struct ifmcaddr6 * @@ net/ipv6/mcast.c: note: in included file: include/net/mld.h:32:43: sparse: sparse: array of flexible structures net/ipv6/mcast.c:1777:27: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list [noderef] __rcu * @@ got struct ip6_sf_list * @@ net/ipv6/mcast.c:1833:51: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ip6_sf_list [noderef] __rcu * @@ got struct ip6_sf_list * @@ net/ipv6/mcast.c:1901:20: sparse: sparse: incompatible types in comparison expression (different address spaces): net/ipv6/mcast.c:1901:20: sparse: struct ip6_sf_list [noderef] __rcu * net/ipv6/mcast.c:1901:20: sparse: struct ip6_sf_list * >> net/ipv6/mcast.c:1925:26: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ifmcaddr6 *pmc_next @@ got struct ifmcaddr6 [noderef] __rcu *next @@ net/ipv6/mcast.c:1925:26: sparse: expected struct ifmcaddr6 *pmc_next net/ipv6/mcast.c:1925:26: sparse: got struct ifmcaddr6 [noderef] __rcu *next net/ipv6/mcast.c:1940:50: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct ip6_sf_list **ppsf @@ got struct ip6_sf_list [noderef] __rcu ** @@ net/ipv6/mcast.c:1940:50: sparse: expected struct ip6_sf_list **ppsf net/ipv6/mcast.c:1940:50: sparse: got struct ip6_sf_list [noderef] __rcu ** >> net/ipv6/mcast.c:1946:48: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct ifmcaddr6 [noderef] __rcu *next @@ got struct ifmcaddr6 *pmc_next @@
net/ipv6/mcast.c:1946:48: sparse: expected struct ifmcaddr6 [noderef] __rcu *next
net/ipv6/mcast.c:1946:48: sparse: got struct ifmcaddr6 *pmc_next
net/ipv6/mcast.c: note: in included file (through include/linux/rbtree.h, include/linux/mm_types.h, include/linux/mmzone.h, ...):
include/linux/rcupdate.h:700:9: sparse: sparse: context imbalance in 'ip6_mc_msfget' - unexpected unlock
vim +764 net/ipv6/mcast.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 756
1666d49e1d416f Hangbin Liu 2017-01-12 757 static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
^1da177e4c3f41 Linus Torvalds 2005-04-16 758 {
1666d49e1d416f Hangbin Liu 2017-01-12 759 struct in6_addr *pmca = &im->mca_addr;
50d689e601cc17 Taehee Yoo 2021-02-13 760 struct ip6_sf_list *psf, *sources;
50d689e601cc17 Taehee Yoo 2021-02-13 761 struct ifmcaddr6 *pmc, *pmc_prev;
^1da177e4c3f41 Linus Torvalds 2005-04-16 762
^1da177e4c3f41 Linus Torvalds 2005-04-16 763 pmc_prev = NULL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 @764 for (pmc = idev->mc_tomb; pmc; pmc = pmc->next) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 765 if (ipv6_addr_equal(&pmc->mca_addr, pmca))
^1da177e4c3f41 Linus Torvalds 2005-04-16 766 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 767 pmc_prev = pmc;
^1da177e4c3f41 Linus Torvalds 2005-04-16 768 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 769 if (pmc) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 770 if (pmc_prev)
^1da177e4c3f41 Linus Torvalds 2005-04-16 771 pmc_prev->next = pmc->next;
^1da177e4c3f41 Linus Torvalds 2005-04-16 772 else
^1da177e4c3f41 Linus Torvalds 2005-04-16 @773 idev->mc_tomb = pmc->next;
^1da177e4c3f41 Linus Torvalds 2005-04-16 774 }
6457d26bd40077 Stephen Hemminger 2010-02-17 775
^1da177e4c3f41 Linus Torvalds 2005-04-16 776 if (pmc) {
1666d49e1d416f Hangbin Liu 2017-01-12 777 im->idev = pmc->idev;
08d3ffcc0cfaba Hangbin Liu 2018-07-20 778 if (im->mca_sfmode == MCAST_INCLUDE) {
a84d016479896b Eric Dumazet 2019-08-27 779 swap(im->mca_tomb, pmc->mca_tomb);
50d689e601cc17 Taehee Yoo 2021-02-13 780
50d689e601cc17 Taehee Yoo 2021-02-13 781 sources = rcu_replace_pointer(im->mca_sources,
50d689e601cc17 Taehee Yoo 2021-02-13 782 pmc->mca_sources,
50d689e601cc17 Taehee Yoo 2021-02-13 783 lockdep_rtnl_is_held());
50d689e601cc17 Taehee Yoo 2021-02-13 784 rcu_assign_pointer(pmc->mca_sources, sources);
50d689e601cc17 Taehee Yoo 2021-02-13 785 for_each_psf_rtnl(im, psf)
c7ea20c9da5b94 Hangbin Liu 2018-07-10 786 psf->sf_crcount = idev->mc_qrv;
c7ea20c9da5b94 Hangbin Liu 2018-07-10 787 } else {
c7ea20c9da5b94 Hangbin Liu 2018-07-10 788 im->mca_crcount = idev->mc_qrv;
^1da177e4c3f41 Linus Torvalds 2005-04-16 789 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 790 in6_dev_put(pmc->idev);
a84d016479896b Eric Dumazet 2019-08-27 791 ip6_mc_clear_src(pmc);
9c8bb163ae784b Hangbin Liu 2017-02-08 792 kfree(pmc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 793 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 794 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 795
^1da177e4c3f41 Linus Torvalds 2005-04-16 796 static void mld_clear_delrec(struct inet6_dev *idev)
^1da177e4c3f41 Linus Torvalds 2005-04-16 797 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 798 struct ifmcaddr6 *pmc, *nextpmc;
^1da177e4c3f41 Linus Torvalds 2005-04-16 799
^1da177e4c3f41 Linus Torvalds 2005-04-16 800 pmc = idev->mc_tomb;
^1da177e4c3f41 Linus Torvalds 2005-04-16 801 idev->mc_tomb = NULL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 802
^1da177e4c3f41 Linus Torvalds 2005-04-16 803 for (; pmc; pmc = nextpmc) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 @804 nextpmc = pmc->next;
^1da177e4c3f41 Linus Torvalds 2005-04-16 805 ip6_mc_clear_src(pmc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 806 in6_dev_put(pmc->idev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 807 kfree(pmc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 808 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 809
^1da177e4c3f41 Linus Torvalds 2005-04-16 810 /* clear dead sources, too */
05d3b96bdcaec5 Taehee Yoo 2021-02-13 811 for_each_mc_rtnl(idev, pmc) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 812 struct ip6_sf_list *psf, *psf_next;
^1da177e4c3f41 Linus Torvalds 2005-04-16 813
^1da177e4c3f41 Linus Torvalds 2005-04-16 814 psf = pmc->mca_tomb;
^1da177e4c3f41 Linus Torvalds 2005-04-16 815 pmc->mca_tomb = NULL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 816 for (; psf; psf = psf_next) {
50d689e601cc17 Taehee Yoo 2021-02-13 817 psf_next = rtnl_dereference(psf->sf_next);
50d689e601cc17 Taehee Yoo 2021-02-13 818 kfree_rcu(psf, rcu);
^1da177e4c3f41 Linus Torvalds 2005-04-16 819 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 820 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 821 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 822
1691c63ea42d6f WANG Cong 2014-09-11 823 static void mca_get(struct ifmcaddr6 *mc)
1691c63ea42d6f WANG Cong 2014-09-11 824 {
d3981bc615f652 Reshetova, Elena 2017-07-04 825 refcount_inc(&mc->mca_refcnt);
1691c63ea42d6f WANG Cong 2014-09-11 826 }
1691c63ea42d6f WANG Cong 2014-09-11 827
1691c63ea42d6f WANG Cong 2014-09-11 828 static void ma_put(struct ifmcaddr6 *mc)
1691c63ea42d6f WANG Cong 2014-09-11 829 {
d3981bc615f652 Reshetova, Elena 2017-07-04 830 if (refcount_dec_and_test(&mc->mca_refcnt)) {
1691c63ea42d6f WANG Cong 2014-09-11 831 in6_dev_put(mc->idev);
05d3b96bdcaec5 Taehee Yoo 2021-02-13 832 kfree_rcu(mc, rcu);
1691c63ea42d6f WANG Cong 2014-09-11 833 }
1691c63ea42d6f WANG Cong 2014-09-11 834 }
1691c63ea42d6f WANG Cong 2014-09-11 835
1691c63ea42d6f WANG Cong 2014-09-11 836 static struct ifmcaddr6 *mca_alloc(struct inet6_dev *idev,
c7ea20c9da5b94 Hangbin Liu 2018-07-10 837 const struct in6_addr *addr,
c7ea20c9da5b94 Hangbin Liu 2018-07-10 838 unsigned int mode)
1691c63ea42d6f WANG Cong 2014-09-11 839 {
1691c63ea42d6f WANG Cong 2014-09-11 840 struct ifmcaddr6 *mc;
1691c63ea42d6f WANG Cong 2014-09-11 841
05d3b96bdcaec5 Taehee Yoo 2021-02-13 842 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
63159f29be1df7 Ian Morris 2015-03-29 843 if (!mc)
1691c63ea42d6f WANG Cong 2014-09-11 844 return NULL;
1691c63ea42d6f WANG Cong 2014-09-11 845
da82b573563d55 Taehee Yoo 2021-02-13 846 INIT_DELAYED_WORK(&mc->mca_work, mld_mca_work);
1691c63ea42d6f WANG Cong 2014-09-11 847
1691c63ea42d6f WANG Cong 2014-09-11 848 mc->mca_addr = *addr;
1691c63ea42d6f WANG Cong 2014-09-11 849 mc->idev = idev; /* reference taken by caller */
1691c63ea42d6f WANG Cong 2014-09-11 850 mc->mca_users = 1;
1691c63ea42d6f WANG Cong 2014-09-11 851 /* mca_stamp should be updated upon changes */
1691c63ea42d6f WANG Cong 2014-09-11 852 mc->mca_cstamp = mc->mca_tstamp = jiffies;
d3981bc615f652 Reshetova, Elena 2017-07-04 853 refcount_set(&mc->mca_refcnt, 1);
1691c63ea42d6f WANG Cong 2014-09-11 854 spin_lock_init(&mc->mca_lock);
1691c63ea42d6f WANG Cong 2014-09-11 855
c7ea20c9da5b94 Hangbin Liu 2018-07-10 856 mc->mca_sfmode = mode;
c7ea20c9da5b94 Hangbin Liu 2018-07-10 857 mc->mca_sfcount[mode] = 1;
1691c63ea42d6f WANG Cong 2014-09-11 858
1691c63ea42d6f WANG Cong 2014-09-11 859 if (ipv6_addr_is_ll_all_nodes(&mc->mca_addr) ||
1691c63ea42d6f WANG Cong 2014-09-11 860 IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL)
a3403c9c2ef72a Taehee Yoo 2021-02-13 861 mc->mca_noreport = true;
1691c63ea42d6f WANG Cong 2014-09-11 862
1691c63ea42d6f WANG Cong 2014-09-11 863 return mc;
1691c63ea42d6f WANG Cong 2014-09-11 864 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 865
^1da177e4c3f41 Linus Torvalds 2005-04-16 866 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 867 * device multicast group inc (add if not found)
^1da177e4c3f41 Linus Torvalds 2005-04-16 868 */
c7ea20c9da5b94 Hangbin Liu 2018-07-10 869 static int __ipv6_dev_mc_inc(struct net_device *dev,
c7ea20c9da5b94 Hangbin Liu 2018-07-10 870 const struct in6_addr *addr, unsigned int mode)
^1da177e4c3f41 Linus Torvalds 2005-04-16 871 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 872 struct ifmcaddr6 *mc;
^1da177e4c3f41 Linus Torvalds 2005-04-16 873 struct inet6_dev *idev;
^1da177e4c3f41 Linus Torvalds 2005-04-16 874
a9ed4a2986e130 Sabrina Dubroca 2014-09-02 875 ASSERT_RTNL();
a9ed4a2986e130 Sabrina Dubroca 2014-09-02 876
96b52e61be1ad4 Eric Dumazet 2010-06-07 877 /* we need to take a reference on idev */
^1da177e4c3f41 Linus Torvalds 2005-04-16 878 idev = in6_dev_get(dev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 879
63159f29be1df7 Ian Morris 2015-03-29 880 if (!idev)
^1da177e4c3f41 Linus Torvalds 2005-04-16 881 return -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 882
^1da177e4c3f41 Linus Torvalds 2005-04-16 883 if (idev->dead) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 884 in6_dev_put(idev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 885 return -ENODEV;
^1da177e4c3f41 Linus Torvalds 2005-04-16 886 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 887
05d3b96bdcaec5 Taehee Yoo 2021-02-13 888 for_each_mc_rtnl(idev, mc) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 889 if (ipv6_addr_equal(&mc->mca_addr, addr)) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 890 mc->mca_users++;
c7ea20c9da5b94 Hangbin Liu 2018-07-10 891 ip6_mc_add_src(idev, &mc->mca_addr, mode, 0, NULL, 0);
^1da177e4c3f41 Linus Torvalds 2005-04-16 892 in6_dev_put(idev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 893 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 894 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 895 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 896
c7ea20c9da5b94 Hangbin Liu 2018-07-10 897 mc = mca_alloc(idev, addr, mode);
1691c63ea42d6f WANG Cong 2014-09-11 898 if (!mc) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 899 in6_dev_put(idev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 900 return -ENOMEM;
^1da177e4c3f41 Linus Torvalds 2005-04-16 901 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 902
05d3b96bdcaec5 Taehee Yoo 2021-02-13 903 rcu_assign_pointer(mc->next, idev->mc_list);
05d3b96bdcaec5 Taehee Yoo 2021-02-13 904 rcu_assign_pointer(idev->mc_list, mc);
1691c63ea42d6f WANG Cong 2014-09-11 905
1691c63ea42d6f WANG Cong 2014-09-11 906 mca_get(mc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 907
1666d49e1d416f Hangbin Liu 2017-01-12 908 mld_del_delrec(idev, mc);
0ae0d60a379c11 Hangbin Liu 2018-07-20 909 igmp6_group_added(mc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 910 ma_put(mc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 911 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 912 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 913
c7ea20c9da5b94 Hangbin Liu 2018-07-10 914 int ipv6_dev_mc_inc(struct net_device *dev, const struct in6_addr *addr)
c7ea20c9da5b94 Hangbin Liu 2018-07-10 915 {
c7ea20c9da5b94 Hangbin Liu 2018-07-10 916 return __ipv6_dev_mc_inc(dev, addr, MCAST_EXCLUDE);
c7ea20c9da5b94 Hangbin Liu 2018-07-10 917 }
4effd28c124530 Linus Lüssing 2019-01-21 918 EXPORT_SYMBOL(ipv6_dev_mc_inc);
c7ea20c9da5b94 Hangbin Liu 2018-07-10 919
^1da177e4c3f41 Linus Torvalds 2005-04-16 920 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 921 * device multicast group del
^1da177e4c3f41 Linus Torvalds 2005-04-16 922 */
9acd9f3ae92d0d YOSHIFUJI Hideaki 2008-04-10 923 int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr)
^1da177e4c3f41 Linus Torvalds 2005-04-16 924 {
05d3b96bdcaec5 Taehee Yoo 2021-02-13 925 struct ifmcaddr6 __rcu **map;
05d3b96bdcaec5 Taehee Yoo 2021-02-13 926 struct ifmcaddr6 *ma;
^1da177e4c3f41 Linus Torvalds 2005-04-16 927
a9ed4a2986e130 Sabrina Dubroca 2014-09-02 928 ASSERT_RTNL();
a9ed4a2986e130 Sabrina Dubroca 2014-09-02 929
05d3b96bdcaec5 Taehee Yoo 2021-02-13 930 for (map = &idev->mc_list;
05d3b96bdcaec5 Taehee Yoo 2021-02-13 931 (ma = rtnl_dereference(*map)) != NULL;
05d3b96bdcaec5 Taehee Yoo 2021-02-13 932 map = &ma->next) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 933 if (ipv6_addr_equal(&ma->mca_addr, addr)) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 934 if (--ma->mca_users == 0) {
05d3b96bdcaec5 Taehee Yoo 2021-02-13 @935 *map = rtnl_dereference(ma->next);
^1da177e4c3f41 Linus Torvalds 2005-04-16 936
^1da177e4c3f41 Linus Torvalds 2005-04-16 937 igmp6_group_dropped(ma);
1666d49e1d416f Hangbin Liu 2017-01-12 938 ip6_mc_clear_src(ma);
^1da177e4c3f41 Linus Torvalds 2005-04-16 939
^1da177e4c3f41 Linus Torvalds 2005-04-16 940 ma_put(ma);
^1da177e4c3f41 Linus Torvalds 2005-04-16 941 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 942 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 943 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 944 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 945 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 946
^1da177e4c3f41 Linus Torvalds 2005-04-16 947 return -ENOENT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 948 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 949 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org