From patchwork Wed Feb 28 13:54:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575523 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A695A36132 for ; Wed, 28 Feb 2024 13:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128485; cv=none; b=V3bIc/21su6RS34owEBe9vEwYvOdvMBHx6MJJhLHl4KFLAV34k3wYTsCP2WNzH8RId34QEv0WxMSXRscOWP2r9kP4xz48dxZ4CTx45By2Ty4t6CrNVQxYOyoTuAjTAyLAKbFKZIZehYm58v3Ikdg57h2jl81qGGqC8xtUOrMqw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128485; c=relaxed/simple; bh=LAj1gOQrVPYZ8gqf75q3u1GU6lwBEtEOHkfujLQDOwA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SmvG4VZ+KzsIbBr1IWLArUqKjqUuH8ylVCmWFuqBaEv/MXsjt+9SLBIvnt8MQi1UKLFNy5QOskdJpP1P9CbU1WDp3dkWUwiwaC+I8652X4tbE7mHhDGmzDPzUTCnQ4oLN5017d6szl74uDdOVg/nhPe4z56Sr0/YqOGM4/tGCn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MpH5h61r; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MpH5h61r" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608cf88048eso76824787b3.0 for ; Wed, 28 Feb 2024 05:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128482; x=1709733282; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EtXCLfpS6OZMuKCZ/f5A+kqjwZnwBBWN5rfeZmgSot4=; b=MpH5h61rYtyqMsOmGVOOIPvPCnWVAGqjISEZm2MYF0syaRH88IpS6D+Ttb1CocTnEa ogwXBIgdlyYNiHIfzfPgEKL0aXL2j9N4kk/mRq+sDbqfwr5y5K+6tEAG8b3SYgVYPwnl bTSUTQTWwYtA8RPIXzj464Kl9S18YIpBP7CvBBcHKfbmvobsQrmGO3CrG7gwWSskvt0P S2ErVjINUkBYzdVDvELM6MyMawEYFJOLBhRHTfe82kxp75POCb7A66GhRRQ1d3e0gRSI NY0+0B2VuKuTcf5sj9neosVXSm8AFkMk7xZPpFC9w7BUI3sF6DcDVORcqOwHuAijqUC8 cQYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128482; x=1709733282; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EtXCLfpS6OZMuKCZ/f5A+kqjwZnwBBWN5rfeZmgSot4=; b=Iyrl2D9zda8c7jr2b27RpDeed3rf9zvbXT5zMBu/l8JTEqsCn0RJqIYPdfkp0b3yfR y4eOtRvbvi1uEv1Y2UWUpeISPDIOT4VB/MhxUXhsFGJdcIFUrpZgcW+EAAbIqgEl0S/G VVUpD1Bt21RYm3VaYUlSmtGksWgn5AHu/nB9cYA7zkICUB8ckLi2tVZU244GxTZmKNYm VCviuWiq5ogbeHO3rjfsYc1kDsA+7NTzfD/L5LBbArWeSdQrBmo2irm9D1Qe1Mn/Ol95 5pSQi8YIO7jmNaXmAQx4xNfYU4O9bs4naBuujaCElMp4XshN9gEaDD1cyHAtx7eVvyWK zvpg== X-Gm-Message-State: AOJu0YzLCStuA15AkJPuM5bBIj7NpSSLGGb5Rw1g+tXubm1pgWjKlacQ ceG2rJKEMGdeqANSGgVJLhIGj+OBrmmcOUIqJLgJLIzUBPGfqMpqlSgwDD27spPLktApPr9iMN+ vkTmAYOI/9A== X-Google-Smtp-Source: AGHT+IEWPolryLRbNjuX4vlQButnAeflXpzbBkjByOXThz8G8SMk5AqNplm02wrW3PiVq0hVvtaBOvMg/ZQrZg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:d511:0:b0:609:2031:1e09 with SMTP id x17-20020a0dd511000000b0060920311e09mr1172510ywd.6.1709128482686; Wed, 28 Feb 2024 05:54:42 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:25 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-2-edumazet@google.com> Subject: [PATCH v3 net-next 01/15] ipv6: add ipv6_devconf_read_txrx cacheline_group From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org IPv6 TX and RX fast path use the following fields: - disable_ipv6 - hop_limit - mtu6 - forwarding - disable_policy - proxy_ndp Place them in a group to increase data locality. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- include/linux/ipv6.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h index ef3aa060a289ea4eecf4d6e8c1dc614101f37c3f..383a0ea2ab9131e685822e5df506582802642e84 100644 --- a/include/linux/ipv6.h +++ b/include/linux/ipv6.h @@ -3,6 +3,7 @@ #define _IPV6_H #include +#include #define ipv6_optlen(p) (((p)->hdrlen+1) << 3) #define ipv6_authlen(p) (((p)->hdrlen+2) << 2) @@ -10,9 +11,16 @@ * This structure contains configuration options per IPv6 link. */ struct ipv6_devconf { - __s32 forwarding; + /* RX & TX fastpath fields. */ + __cacheline_group_begin(ipv6_devconf_read_txrx); + __s32 disable_ipv6; __s32 hop_limit; __s32 mtu6; + __s32 forwarding; + __s32 disable_policy; + __s32 proxy_ndp; + __cacheline_group_end(ipv6_devconf_read_txrx); + __s32 accept_ra; __s32 accept_redirects; __s32 autoconf; @@ -45,7 +53,6 @@ struct ipv6_devconf { __s32 accept_ra_rt_info_max_plen; #endif #endif - __s32 proxy_ndp; __s32 accept_source_route; __s32 accept_ra_from_local; #ifdef CONFIG_IPV6_OPTIMISTIC_DAD @@ -55,7 +62,6 @@ struct ipv6_devconf { #ifdef CONFIG_IPV6_MROUTE atomic_t mc_forwarding; #endif - __s32 disable_ipv6; __s32 drop_unicast_in_l2_multicast; __s32 accept_dad; __s32 force_tllao; @@ -76,7 +82,6 @@ struct ipv6_devconf { #endif __u32 enhanced_dad; __u32 addr_gen_mode; - __s32 disable_policy; __s32 ndisc_tclass; __s32 rpl_seg_enabled; __u32 ioam6_id; From patchwork Wed Feb 28 13:54:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575524 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 161EF36132 for ; Wed, 28 Feb 2024 13:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128488; cv=none; b=d4gEDt4pF+aT4pJxXiR8wu6CDe1n39Qv2rs/wG/BSHVfk1qMC6Rnm339ED9SNzYGvmjHK7Jst2vYjZUOnS6xDTWnfVw2bORr9TVpwnVYABGJ7GAboa4haC8M+L8QEAt93gaMxs0zB3rLnkWJpmQislA3W0Q8ZnjXK2oKNVpB9Is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128488; c=relaxed/simple; bh=pyRTrCFIF53ALj594M75v4uX/qajHVqWfX1akzaUjDk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=osi4MdeOMj8hn/s1wjze2M7QzfF0pQj1qEjxj4+vWY8U1kTwTvA4daGQP2BHdT2SbcKJ+8B7gMruVa3a9sbZ9vZLBTJgj9KtcP/LntAiRyRmY4gZUfgjuEJ0oJ1F+2LS/cP6qgMVyFi7Gm4yQiRihoHh/ULekodYaafVeQnFKMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WTAcXtc+; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WTAcXtc+" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc74ac7d015so6997828276.0 for ; Wed, 28 Feb 2024 05:54:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128486; x=1709733286; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ief8H3jG8cWOh1EE+DNugp+OaUBgAgHchahPCNShsic=; b=WTAcXtc+y08nwjwoYGM+145j5J02QzCguORCkzsQF554cwn1jHWSL1c4AZ9j2K0Hpr +zzVs5ILGEqHsSZEfx4Umr6FhrWQ1Ej0hC3my2aeaV+gZfGzfbj93efb2LlBET5+u6W4 xsuXUkd4n/s6rYvqaAjBTbfIdoLByovvEy0LZQl/NuES6OiEvD31DsaOQh9StOsr74yt nxBd0tN52Fkhpc8W90BoLrScoen/HZAl+lyZO/bCEqDbDwlnCtA1ByL4rLo7CF3iacpc GmvOAn1VafdiCcTaG4nEnA/ALbqQJLweq727iMs6sUn64AnjBNG3s0Dt3N+Tr0qjsF7B ce7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128486; x=1709733286; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ief8H3jG8cWOh1EE+DNugp+OaUBgAgHchahPCNShsic=; b=NjCtWgT7ByaULzF5DaRghg4E7S5gbMeqsEBd2VfTFfUdSvZzcrpV7U84kDs8DjVx/J fvt9SVTAJySgd418du2Y/DyTVS63hnH2xmfCBilsKgmsy44cQaSYcHXs6COlkRNWvjgY 4QQ5rGfKKtmG0j+oofR6YyEfoj3AA5jbTn2vDJ+NgpW+mm0/857tpBMI7Np7zrKCjo78 7Ml7fUkrIypIp65/So5z+i9duv1D7uQYNDRQsJ4E/k39iRqgBmqDHlm7SvHVhr62bodu K3IfBHGpATgiSF9n5lxq4gyrphLuYvyrCDWGY4+/EJ7T5i5GGyo8vA1Adkxw8NWY3ro6 2Puw== X-Gm-Message-State: AOJu0YxSmORECSUt22Wb3FfiJ4kzjzcwwre/TBTsimBoVJItBMbKxRIi msZhs4eaVZnLE4yQimtv+iOrhqebKvLp3H7YGS+3+jiqItdyVWX0v/3daZtp+AiMGLnAa63NbUG Z3+BXuSkxng== X-Google-Smtp-Source: AGHT+IGipDaQRvhHY/rNTKkNDYB46GXzP7qMcJe9KPKYkjoKdPbNnsQRYU75TUYubrtJyCSDAZlmeqhYe4wZ1g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:174a:b0:dce:30f5:6bc5 with SMTP id bz10-20020a056902174a00b00dce30f56bc5mr116327ybb.4.1709128484304; Wed, 28 Feb 2024 05:54:44 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:26 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-3-edumazet@google.com> Subject: [PATCH v3 net-next 02/15] ipv6: annotate data-races around cnf.disable_ipv6 From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org disable_ipv6 is read locklessly, add appropriate READ_ONCE() and WRITE_ONCE() annotations. v2: do not preload net before rtnl_trylock() in addrconf_disable_ipv6() (Jiri) Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 9 +++++---- net/ipv6/ip6_input.c | 4 ++-- net/ipv6/ip6_output.c | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index e27069ad938ca68d758ef956b8c36cb85697eeb5..9c1d141a9a343b45225658ce75f23893ff6c7426 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4214,7 +4214,7 @@ static void addrconf_dad_work(struct work_struct *w) if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) && ipv6_addr_equal(&ifp->addr, &addr)) { /* DAD failed for link-local based on MAC */ - idev->cnf.disable_ipv6 = 1; + WRITE_ONCE(idev->cnf.disable_ipv6, 1); pr_info("%s: IPv6 being disabled!\n", ifp->idev->dev->name); @@ -6388,7 +6388,8 @@ static void addrconf_disable_change(struct net *net, __s32 newf) idev = __in6_dev_get(dev); if (idev) { int changed = (!idev->cnf.disable_ipv6) ^ (!newf); - idev->cnf.disable_ipv6 = newf; + + WRITE_ONCE(idev->cnf.disable_ipv6, newf); if (changed) dev_disable_change(idev); } @@ -6405,7 +6406,7 @@ static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int newf) net = (struct net *)table->extra2; old = *p; - *p = newf; + WRITE_ONCE(*p, newf); if (p == &net->ipv6.devconf_dflt->disable_ipv6) { rtnl_unlock(); @@ -6413,7 +6414,7 @@ static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int newf) } if (p == &net->ipv6.devconf_all->disable_ipv6) { - net->ipv6.devconf_dflt->disable_ipv6 = newf; + WRITE_ONCE(net->ipv6.devconf_dflt->disable_ipv6, newf); addrconf_disable_change(net, newf); } else if ((!newf) ^ (!old)) dev_disable_change((struct inet6_dev *)table->extra1); diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index b8378814532cead0275e8b7a656f78450993f619..1ba97933c74fbd12e21f273f0aeda2313bd608b7 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -168,9 +168,9 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, SKB_DR_SET(reason, NOT_SPECIFIED); if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL || - !idev || unlikely(idev->cnf.disable_ipv6)) { + !idev || unlikely(READ_ONCE(idev->cnf.disable_ipv6))) { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); - if (idev && unlikely(idev->cnf.disable_ipv6)) + if (idev && unlikely(READ_ONCE(idev->cnf.disable_ipv6))) SKB_DR_SET(reason, IPV6DISABLED); goto drop; } diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 31b86fe661aa6cd94fb5d8848900406c2db110e3..0559bd0005858631f88c706f98c625ad0bfff278 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -234,7 +234,7 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb) skb->protocol = htons(ETH_P_IPV6); skb->dev = dev; - if (unlikely(idev->cnf.disable_ipv6)) { + if (unlikely(READ_ONCE(idev->cnf.disable_ipv6))) { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); kfree_skb_reason(skb, SKB_DROP_REASON_IPV6DISABLED); return 0; From patchwork Wed Feb 28 13:54:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575525 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ED33151CCE for ; Wed, 28 Feb 2024 13:54:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128489; cv=none; b=AAGtrRy+MoygXTt8N6BrRgoTsvdOPXfBF8rtfpmtWXyeRwW91GOFSF5WdS8Myx5d5g3eUZctViSZEA41/X3FM9q+GKTAujZCja53k3V5jZH3YLPSjpgNKakEtMck/ogjR9149BlfUH+75gx9DfWxLVv4D6OwL4CN9ocZqqDmwIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128489; c=relaxed/simple; bh=91soUPvOOzq4xldWAfV/U6pdkQlpdyHqmLksGJvHONI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kgnB5HoH+M9LSShpvQH/PQ8Yob+y8+KnnnAe+wJKpZyuMIggi2gZSFnswa9gK6g8PV5McZdIxNOgOnkkyQLmAUsi0FyVkDNRyMnBujXm9tH0lAlYpwxN9lGn0OVl1o2+j1sic5pv6QToSCnPfuHrtGoqPT2uFkDNY3Kikndv880= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=u73Oylkx; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="u73Oylkx" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608e88ca078so55622737b3.1 for ; Wed, 28 Feb 2024 05:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128487; x=1709733287; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1W1+/hYZA4R/xgfoHbrrNnSXBXPqK//ZxmcYEZfFWQU=; b=u73OylkxuGhJYuSvALGVUPLhoCry8BZlKpURKgOKSdUtH7R6w4Att+ZRL7fJKL8Vvh VdcVfu/feHS6m0RKuhXqQAA6gqtvSf8BqHQJH2ftsswK6Wax/Ec9zGZdfaN8QWFXCxGQ 7Y8FghumrH6skPNf43un/9yDIBgEY/JiaWidH27nBGHFl4E+6ioDb13RpfmHZlOWYXcA VD6QN+20FGr9C1UXpt6JxlsM1cP55nIHgkXm5J+VaroK+NUunVMTYq2+8Ackh2RlQSET KLNOSrq9zhO+T8jppwsj8yuVYgD1gCxIQYpIafv9jjrI/tYJK6zUWwHr6tnmxgWm0Ui3 L5jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128487; x=1709733287; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1W1+/hYZA4R/xgfoHbrrNnSXBXPqK//ZxmcYEZfFWQU=; b=EDjBHt1PfSLFyQwtk8qVmbsplgvEO/lcWYEGsOKFOipfWaQ9RunmtMi0avdsbxB0Kz 04yYU0QIEGmef0jnBKUz1keNRC31MmQ5mDlqzDk3dTU/SzcYYraFUqtOs4ZYrTTXwkk1 4FIzITNtiTxl8nVzLniHAqRqSPtUJr6Rfnd/WOzhLwG1xQC55gs4/1lD3YPugc2tg2lA 5aX+6ovz/Ow4zAou70AGQ6PYcWhauj6kglymEbdwicxRCSCnY6gDJaEHjF1Q6rhAVKrJ iSkD5XCbLIHVEu1Z9DKa4xLQpm25oM2XCkwOXnGWGKBA40PtLHlhP5AzKLqKff4dLDAe JEkw== X-Gm-Message-State: AOJu0YxyaedYg3Zhw6jBbJTA3WdqRpoDELjt1W55uSJdg6fwKPixHwcA Rt7feWuU/h71NBv2NLPGO1gmODVieLFhnWxmrCz/3cc/5xreZDP8ze2ehtBQq6I8rauj8zQdf7G xLCKorSR8Mg== X-Google-Smtp-Source: AGHT+IFhwptjYoG9LwH/IyVNlB3dmHEAe6ndc+qHvhw/i3eXjRMQKNgcMmxjOQ6tPQWSISG3j66sBA5v0xg8Xg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:100a:b0:dc7:53a0:83ad with SMTP id w10-20020a056902100a00b00dc753a083admr715157ybt.5.1709128487086; Wed, 28 Feb 2024 05:54:47 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:27 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-4-edumazet@google.com> Subject: [PATCH v3 net-next 03/15] ipv6: addrconf_disable_ipv6() optimization From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Writing over /proc/sys/net/ipv6/conf/default/disable_ipv6 does not need to hold RTNL. v3: remove a wrong change (Jakub Kicinski feedback) Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 9c1d141a9a343b45225658ce75f23893ff6c7426..9a5182a12bfd7719fa6d5f0537835e0f0bf37686 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -6398,21 +6398,20 @@ static void addrconf_disable_change(struct net *net, __s32 newf) static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int newf) { - struct net *net; + struct net *net = (struct net *)table->extra2; int old; + if (p == &net->ipv6.devconf_dflt->disable_ipv6) { + WRITE_ONCE(*p, newf); + return 0; + } + if (!rtnl_trylock()) return restart_syscall(); - net = (struct net *)table->extra2; old = *p; WRITE_ONCE(*p, newf); - if (p == &net->ipv6.devconf_dflt->disable_ipv6) { - rtnl_unlock(); - return 0; - } - if (p == &net->ipv6.devconf_all->disable_ipv6) { WRITE_ONCE(net->ipv6.devconf_dflt->disable_ipv6, newf); addrconf_disable_change(net, newf); From patchwork Wed Feb 28 13:54:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575526 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A89B15531E for ; Wed, 28 Feb 2024 13:54:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128490; cv=none; b=W+GYWSEm0n6xfQ3ZqDk3dkYZ3lVON3rQ2sZuKu8DCmIIX4vpmpIXzIqgZOpM8ULz+f37fQPjA3+zMXEcnSP5v+g70TUIDgldm7OGQu+nqXNjAubd2dfMXid4ISv8l3JTUm3D6VmVVNWxwmuAEzGp/Hw7RYk3YICR59fzxYUrG4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128490; c=relaxed/simple; bh=N2hL2xaPrpeRGNwEqKwm4kjCM9F3btIkN1OscYsi5Ek=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WihLuygtPlOmvFjDXyHA5mqrGqXgN25GARWeG39skWrBukVxYFTPwkFTKIo+0iBYqcLm5WCWkEiI0l9WrVUYE042q1h5yQqh/YNEYEjZujsuqbyyLnXMyeyhf6mVzbFMLGgFGOxSyjZnFBRuqBoZGBhoI1Dgx4P4za8gBA9Li2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=r/vLOE2N; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="r/vLOE2N" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc64b659a9cso8663683276.3 for ; Wed, 28 Feb 2024 05:54:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128488; x=1709733288; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OmY3dY632PH80ZQri5XOrSnftpfZoL3ED9y4hOcBys8=; b=r/vLOE2NgF4tSNKkyS1FPG0kuLs0SNVtytIluL3l+LGrPUP11TIZvHlln+cFuNl/y9 FLt/BcYyGQgbV2SDcXAywMVnivmtNmOlum46+JlxSTi+oZtA09Pa0FA/RLByWE4KOVGU Ko0N0EudMRUunpILKDyn7831v9dk6zSaKyOrzi5iezB6YRq8Hc62yWPqHOQoWd+hrlPp n3uJXnN6b00P3JvERmZ2VWvmR1o+Kq6cI8rFnugppR5wK8WcssFwdkgewpSRtcaDrYpP fzkzms4nZJQdfHdAc96QX4z6VnzH+BQsyFOjITFqUbX/24DKE1ZpJo4f3BWNo5+ZDb10 27kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128488; x=1709733288; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OmY3dY632PH80ZQri5XOrSnftpfZoL3ED9y4hOcBys8=; b=rAlIv9pP8EJ2iio/NeQ1XbAL/q+HqwoNeXQVD1YXldSnzU7z4pkZCNfoKBKKGy2lwN ZZrWabL0ja5bGLZ3+G1J73SZlHlFbPulkm4ll7/Ap6qEEWo8TFWndQ0TDjt3lTjcdmny 5rm2MuyOstACy0AI/WJkLZP+BNaP/1Snmi7euBRbHQ7cM27zTMBvNc3XxxXWJLHoR1AB vQrLEiX/ffJ454QdiXKyTTRUw7Zwc/2BZUhY3Gt14F8JONDaKd/KFfZJ9vS7Q2v7xhzj YdSarh2FcJqoMWDMzVpaWoDbn3h1Km1Ut+QSOWsOsQOE9kn9498qVMp6kaJBfg1mvpLn ZiFA== X-Gm-Message-State: AOJu0Yx9wcCdpswLIh33MqnArKlWCFo7CYkAovVIK33YpWPQ8wCZc7RH sz5XXoyL8S5EfVkepizBNZJq68x+lhZ+SF6cf3/PMDhzQxTzPtndRQxc6SLGfHMbAdSAbVdzWrq /j9qrozS5ug== X-Google-Smtp-Source: AGHT+IFMb+DfW/3m5L6YKEnQAj4CdBbRB8XBYmCSPn16BjfQpy4ie8k1yos7yLat6nUsKD43RVmRaJmkpvtK5A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:d08c:0:b0:dc7:4b9:fbc6 with SMTP id h134-20020a25d08c000000b00dc704b9fbc6mr354156ybg.10.1709128488142; Wed, 28 Feb 2024 05:54:48 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:28 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-5-edumazet@google.com> Subject: [PATCH v3 net-next 04/15] ipv6: annotate data-races around cnf.mtu6 From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org idev->cnf.mtu6 might be read locklessly, add appropriate READ_ONCE() and WRITE_ONCE() annotations. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- include/net/ip6_route.h | 2 +- net/ipv6/addrconf.c | 4 ++-- net/ipv6/ndisc.c | 4 ++-- net/ipv6/route.c | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 52a51c69aa9de2fe1e6d351997f5b3d94862521a..a30c6aa9e5cf3e442cd29e2d169ba0b0d46a1f46 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -332,7 +332,7 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst rcu_read_lock(); idev = __in6_dev_get(dst->dev); if (idev) - mtu = idev->cnf.mtu6; + mtu = READ_ONCE(idev->cnf.mtu6); rcu_read_unlock(); out: diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 9a5182a12bfd7719fa6d5f0537835e0f0bf37686..8fd2ff8510021738e6bde499cc9fae83c52b91ee 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -3671,7 +3671,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, if (idev) { rt6_mtu_change(dev, dev->mtu); - idev->cnf.mtu6 = dev->mtu; + WRITE_ONCE(idev->cnf.mtu6, dev->mtu); break; } @@ -3763,7 +3763,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, if (idev->cnf.mtu6 != dev->mtu && dev->mtu >= IPV6_MIN_MTU) { rt6_mtu_change(dev, dev->mtu); - idev->cnf.mtu6 = dev->mtu; + WRITE_ONCE(idev->cnf.mtu6, dev->mtu); } WRITE_ONCE(idev->tstamp, jiffies); inet6_ifinfo_notify(RTM_NEWLINK, idev); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 8523f0595b01899a9f6cf82809c1b4bcfc233202..e96d79cd34d27ca304c5f71b6db41b99d2dd8856 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1578,8 +1578,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) if (mtu < IPV6_MIN_MTU || mtu > skb->dev->mtu) { ND_PRINTK(2, warn, "RA: invalid mtu: %d\n", mtu); - } else if (in6_dev->cnf.mtu6 != mtu) { - in6_dev->cnf.mtu6 = mtu; + } else if (READ_ONCE(in6_dev->cnf.mtu6) != mtu) { + WRITE_ONCE(in6_dev->cnf.mtu6, mtu); fib6_metric_set(rt, RTAX_MTU, mtu); rt6_mtu_change(skb->dev, mtu); } diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 707d65bc9c0e5e9b2900063f0ac86c3c5e299088..66c685b0b6199fee3bc39768eab5a6fb831bd2f5 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1596,7 +1596,7 @@ static unsigned int fib6_mtu(const struct fib6_result *res) rcu_read_lock(); idev = __in6_dev_get(dev); - mtu = idev->cnf.mtu6; + mtu = READ_ONCE(idev->cnf.mtu6); rcu_read_unlock(); } @@ -3249,8 +3249,8 @@ u32 ip6_mtu_from_fib6(const struct fib6_result *res, mtu = IPV6_MIN_MTU; idev = __in6_dev_get(dev); - if (idev && idev->cnf.mtu6 > mtu) - mtu = idev->cnf.mtu6; + if (idev) + mtu = max_t(u32, mtu, READ_ONCE(idev->cnf.mtu6)); } mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); From patchwork Wed Feb 28 13:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575527 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F8E5157E7B for ; Wed, 28 Feb 2024 13:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128492; cv=none; b=NKHvif1tn4+GY1OELenznVRwcV9GpMBCn7/3lSdbrzxQm6lznRf4lcDu1XwnP1FXHcrlwZeDK8s/iEN6DgSE1zEz5vAtoNBH5iQMOE4S6XREmEF2oSXWoCzwhf3daot1TA1NiB5wUiiLHGJdpZmmEGK712p/cAzFDLJEgGDGf9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128492; c=relaxed/simple; bh=ygLg94dIps3zIcDRFubF2s7jK0F5ZmRb8SWXaOSKLXE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RPvsrQ2rJ/wk+lKBmwhisqUB0PZkWcUzek3VmZo3c9Otw4VIZmqkSi4sCxk1TZq2CoRKJWM1jt9ibvjmCCsAU9J5UIRrxaLi3b/TpsJ7UET4j2hgeK8y4l0Xui8tB3Lyznp5nWH7leYm/fwR1EG+SJn3GqXBi6jiaO+Mmj81/xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=v/8e8AEj; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="v/8e8AEj" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so7008038276.0 for ; Wed, 28 Feb 2024 05:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128489; x=1709733289; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=L7NTXK4f/hgsidvPYAJ36SmYjWcf3wQ94jpBSeMR/q0=; b=v/8e8AEjtN5P2UUJUL3vJndeKUrVSuSVGcNgSEetLBsb4MoqqOzwWsw7UEctygJHlO Xpkjgos8CIsKwHY6sR5f+MDFdP+nvwMNFxcGBdd8VHnoqqrw++U1xu+uczNKwVvC6q6S /nWHH4UjwWncUw2v6hzfpnxxbi8gdyIIdnaajeHUfEZV07y8qGfWya798C+8KYtXYJ2e 7ozC/dy/QQB2hZdX0wBt+AowQbta0IqJZMRsSasKD9GS4dxZ6NeEL3TH+IQbRFPdaeFZ EhGncOW84zxwKfq78yJ2Lu6tr+ZZJfbIPgF60uW1KDmBOYb3UQQ0JWKNcnJTYUV5L/Ik l30w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128489; x=1709733289; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L7NTXK4f/hgsidvPYAJ36SmYjWcf3wQ94jpBSeMR/q0=; b=MuIKrFSK00UljPl8Ogu5n7MJmCDpLAvj8/9smnfJOjEqkRDAJTe/THHfIhnsdxl9Bj ijYH1QXe21Bv4KFrE5V2Y8LeDNg91YJ2W+CCHymuP2c+O+3uUE2y2+2rMs5w7S5xPvsA p6cp0MT4VEg6c/kUzepOyFKULD0AEModKcSYlr5XOBdVeEw2a68Xq7k7A3IT+GOyZ1yR T13+bVmAsDrBNRzS4+ygpLCXBW6TdCGpA0SNRP5i7nBw3oLj/XishALYWpUMiGoqSfkp et9h/TZ2H/r8SErZgYJzluWZH6EuiomGB5r/tkirJDzsSGUIv+HEQyQNlqxT9PRdV+Rn x1Ig== X-Gm-Message-State: AOJu0YxsktR680DdAwL/6lBgcihG+HPfjCuYWU3XlwjednympJ1tM2zC tovqxvAH+nZjJi8b3+wdrKZFH1TGxkVxlE3I0e/R6582QrT6m55Ib5+5kfKcNtS/baFUSR5qX4w 6BW3l/+uAIA== X-Google-Smtp-Source: AGHT+IEIXzUAmeELorWcDE5L855aOKhWG/XTCFSxkmmSn2v9yK8O58x9Ry+nVUridtrK8SmY9KP2J90Y8dViuA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1105:b0:dc6:b982:cfa2 with SMTP id o5-20020a056902110500b00dc6b982cfa2mr124760ybu.8.1709128489352; Wed, 28 Feb 2024 05:54:49 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:29 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-6-edumazet@google.com> Subject: [PATCH v3 net-next 05/15] ipv6: annotate data-races around cnf.hop_limit From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet , Florian Westphal X-Patchwork-Delegate: kuba@kernel.org idev->cnf.hop_limit and net->ipv6.devconf_all->hop_limit might be read locklessly, add appropriate READ_ONCE() and WRITE_ONCE() annotations. Signed-off-by: Eric Dumazet Acked-by: Florian Westphal # for netfilter parts Reviewed-by: Jiri Pirko --- drivers/net/ethernet/netronome/nfp/flower/action.c | 2 +- net/ipv6/ipv6_sockglue.c | 2 +- net/ipv6/ndisc.c | 2 +- net/ipv6/netfilter/nf_reject_ipv6.c | 4 ++-- net/ipv6/output_core.c | 4 ++-- net/netfilter/nf_synproxy_core.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/flower/action.c b/drivers/net/ethernet/netronome/nfp/flower/action.c index 2b383d92d7f573b450ed3e315af3f07de56c1921..2c3f629079584024ed9d1640a980f4894b987115 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/action.c +++ b/drivers/net/ethernet/netronome/nfp/flower/action.c @@ -460,7 +460,7 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun, set_tun->ttl = ip6_dst_hoplimit(dst); dst_release(dst); } else { - set_tun->ttl = net->ipv6.devconf_all->hop_limit; + set_tun->ttl = READ_ONCE(net->ipv6.devconf_all->hop_limit); } #endif } else { diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 56c3c467f9deb907ac6e6b84dcd33ec44bde0682..f61d977ac0528e190d901c9b5e71b1cf358096bd 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -1346,7 +1346,7 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname, } if (val < 0) - val = sock_net(sk)->ipv6.devconf_all->hop_limit; + val = READ_ONCE(sock_net(sk)->ipv6.devconf_all->hop_limit); break; } diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index e96d79cd34d27ca304c5f71b6db41b99d2dd8856..9c9c31268432ee58c1a381d0333d85a558a602e1 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1423,7 +1423,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) if (in6_dev->cnf.accept_ra_min_hop_limit < 256 && ra_msg->icmph.icmp6_hop_limit) { if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) { - in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit; + WRITE_ONCE(in6_dev->cnf.hop_limit, ra_msg->icmph.icmp6_hop_limit); fib6_metric_set(rt, RTAX_HOPLIMIT, ra_msg->icmph.icmp6_hop_limit); } else { diff --git a/net/ipv6/netfilter/nf_reject_ipv6.c b/net/ipv6/netfilter/nf_reject_ipv6.c index 196dd4ecb5e215f8a1de321bf249bec6fca6b97c..dedee264b8f6c8e5155074c6788c53fdf228ca3c 100644 --- a/net/ipv6/netfilter/nf_reject_ipv6.c +++ b/net/ipv6/netfilter/nf_reject_ipv6.c @@ -83,7 +83,7 @@ struct sk_buff *nf_reject_skb_v6_tcp_reset(struct net *net, skb_reserve(nskb, LL_MAX_HEADER); nip6h = nf_reject_ip6hdr_put(nskb, oldskb, IPPROTO_TCP, - net->ipv6.devconf_all->hop_limit); + READ_ONCE(net->ipv6.devconf_all->hop_limit)); nf_reject_ip6_tcphdr_put(nskb, oldskb, oth, otcplen); nip6h->payload_len = htons(nskb->len - sizeof(struct ipv6hdr)); @@ -124,7 +124,7 @@ struct sk_buff *nf_reject_skb_v6_unreach(struct net *net, skb_reserve(nskb, LL_MAX_HEADER); nip6h = nf_reject_ip6hdr_put(nskb, oldskb, IPPROTO_ICMPV6, - net->ipv6.devconf_all->hop_limit); + READ_ONCE(net->ipv6.devconf_all->hop_limit)); skb_reset_transport_header(nskb); icmp6h = skb_put_zero(nskb, sizeof(struct icmp6hdr)); diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c index b5205311f372bdaaff140d651e4b42b27a3ed805..806d4b5dd1e60b27726facbb59bbef97d6fee7f5 100644 --- a/net/ipv6/output_core.c +++ b/net/ipv6/output_core.c @@ -111,9 +111,9 @@ int ip6_dst_hoplimit(struct dst_entry *dst) rcu_read_lock(); idev = __in6_dev_get(dev); if (idev) - hoplimit = idev->cnf.hop_limit; + hoplimit = READ_ONCE(idev->cnf.hop_limit); else - hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit; + hoplimit = READ_ONCE(dev_net(dev)->ipv6.devconf_all->hop_limit); rcu_read_unlock(); } return hoplimit; diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c index fbbc4fd373495b69940e29e657fde2cdc67b55db..5b140c12b7dfa40efc9bec6f2588c4350fed6bfb 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -800,7 +800,7 @@ synproxy_build_ip_ipv6(struct net *net, struct sk_buff *skb, skb_reset_network_header(skb); iph = skb_put(skb, sizeof(*iph)); ip6_flow_hdr(iph, 0, 0); - iph->hop_limit = net->ipv6.devconf_all->hop_limit; + iph->hop_limit = READ_ONCE(net->ipv6.devconf_all->hop_limit); iph->nexthdr = IPPROTO_TCP; iph->saddr = *saddr; iph->daddr = *daddr; From patchwork Wed Feb 28 13:54:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575528 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B102157E96 for ; Wed, 28 Feb 2024 13:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128493; cv=none; b=DupF5hIlSAhXbRTGop19t/tjrPDxm0SwOwwemWdcrmYGR9VgrI31rVZ2wWw+GBu/T5AyyKVVBE+MS9ucg9sEF/CnPZsa03AoLT3eIyOXGc7fVuuuPP7eaQwSysaX2fVwr0VtgVc9z7+6MNXinRmueztLwPvUNClBFThd6VfI0HQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128493; c=relaxed/simple; bh=Mt4IQn3UWvTlyV1oEpkOCI3f3CXjXiyKImXQiiAWjX4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tWrcNEJyp6BuWGZ/bfZgbs4AsTqsqEOKhBg3FW9vHVCBiy0u+vBPw0L5VnL0bZ/S7cfq2zadnvhm/fuzSy+fAUroHZWrfnysyTt4g5TKc/kcmFRR9c9LQR5SUhTHhmx6fPvutL7EtFuciHyhH/+5fO8LF1qPYIvJi5F6zyKatcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XldhA6VQ; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XldhA6VQ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b269686aso8651778276.1 for ; Wed, 28 Feb 2024 05:54:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128490; x=1709733290; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SjHU+nStBYgBHY38l5mYoklHn3VcbO0en3He1pBUsDc=; b=XldhA6VQR4ybIXS4fzJn+y7Mez4Q2SE6RZS45YLVIlJoEc/Hsmcwq7V2OjvSncLAbQ L+sRgUbAPslUt9DkMMLkJ2qmerIaa0RkCdey7OUVF15Gu2ebD4y1c1wgh8hicYmkJvcK LXpmVezEfKBeffSZNCd9GDS5XU2LIAfwEANXy6dwO24dmQDnPiJj8mc/fB9inSBhLIJV rU+qZ/sm/7hz4XLdHAgepTelih7GeqEWhaZiQsQjoJWp6JrNOfEP3qvyURz2MLa+JUVF QUrCJBA5GtjhI4nEgu9xmOJu9dmVZUi4XCRw6H+gqKKB/o0Atq7jaX++jTrmdRdlactd ggHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128490; x=1709733290; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SjHU+nStBYgBHY38l5mYoklHn3VcbO0en3He1pBUsDc=; b=Ie9i6XZQdwbner1vDcht4+3oxc9P33iu9Y2v1TWNYkA9ViEiWscRsGsLq888F2BfJS kyNKFQQU1uzausiEp0vBSS+xOuzQmUBFBs+IzX2PMAo6C9mAwT7RxoS26oaw0aIwpZPw 04Khu3sy5lWlXGKJOADnaNSvXF6/EN1GYeyTZ3T4QPFMnzF7EjDXChT/h8qInLVPt/sq 4i7aF0SAtYqd4tFCCwADOsCFXtK4xPrVRL5SzHY4YYVM7kj8xF3QtrjiY6q3gl86POs8 OTdmU94eXuf7sQwEeDGdHtUS5KQT4koImNvorYokzTerjEHxU/NqEtJneFcOPiqM8e2b GDvg== X-Gm-Message-State: AOJu0Yx2GH4WKifNe6CtZDxtO1TKqGVpqpBSoztBePcKzHjazb09wib4 bkZTJOC8ZGpsNB3VbWKENSPlc2OtPM3tziWzjLEyehIB0J1oD2B3cL4IwElxkNHsORK40mjrEyH P4aXcHvBJvw== X-Google-Smtp-Source: AGHT+IGvehOxUynVq9b3g9H41aPDabKxg9xJ7X/cNv76G7yBr5eYbtJ0NBGePLz7BR4tevyBdBlpeXfB3BZqIw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:174a:b0:dce:30f5:6bc5 with SMTP id bz10-20020a056902174a00b00dce30f56bc5mr116330ybb.4.1709128490662; Wed, 28 Feb 2024 05:54:50 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:30 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-7-edumazet@google.com> Subject: [PATCH v3 net-next 06/15] ipv6: annotate data-races around cnf.forwarding From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org idev->cnf.forwarding and net->ipv6.devconf_all->forwarding might be read locklessly, add appropriate READ_ONCE() and WRITE_ONCE() annotations. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- drivers/net/usb/cdc_mbim.c | 2 +- include/net/ipv6.h | 8 +++++--- net/core/filter.c | 2 +- net/ipv6/addrconf.c | 10 ++++++---- net/ipv6/ip6_output.c | 2 +- net/ipv6/ndisc.c | 11 ++++++----- net/ipv6/route.c | 4 ++-- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c index cd4083e0b3b9e6bf8c8fa08ce5b6006d33d9bedd..e13e4920ee9b2e814c4f5ff5df139dc07d739abd 100644 --- a/drivers/net/usb/cdc_mbim.c +++ b/drivers/net/usb/cdc_mbim.c @@ -339,7 +339,7 @@ static void do_neigh_solicit(struct usbnet *dev, u8 *buf, u16 tci) in6_dev = in6_dev_get(netdev); if (!in6_dev) goto out; - is_router = !!in6_dev->cnf.forwarding; + is_router = !!READ_ONCE(in6_dev->cnf.forwarding); in6_dev_put(in6_dev); /* ipv6_stub != NULL if in6_dev_get returned an inet6_dev */ diff --git a/include/net/ipv6.h b/include/net/ipv6.h index cf25ea21d770d4fe1b235bf2d1ec0088b4b0ff45..88a8e554f7a126a1d817c0cc3bb947c7a43c5cdf 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -534,13 +534,15 @@ static inline int ipv6_hopopt_jumbo_remove(struct sk_buff *skb) return 0; } -static inline bool ipv6_accept_ra(struct inet6_dev *idev) +static inline bool ipv6_accept_ra(const struct inet6_dev *idev) { + s32 accept_ra = READ_ONCE(idev->cnf.accept_ra); + /* If forwarding is enabled, RA are not accepted unless the special * hybrid mode (accept_ra=2) is enabled. */ - return idev->cnf.forwarding ? idev->cnf.accept_ra == 2 : - idev->cnf.accept_ra; + return READ_ONCE(idev->cnf.forwarding) ? accept_ra == 2 : + accept_ra; } #define IPV6_FRAG_HIGH_THRESH (4 * 1024*1024) /* 4194304 */ diff --git a/net/core/filter.c b/net/core/filter.c index 358870408a51e61f3cbc552736806e4dfee1ec39..58e8e1a70aa752a2c045117e00d8797478da4738 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5988,7 +5988,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params, return -ENODEV; idev = __in6_dev_get_safely(dev); - if (unlikely(!idev || !idev->cnf.forwarding)) + if (unlikely(!idev || !READ_ONCE(idev->cnf.forwarding))) return BPF_FIB_LKUP_RET_FWD_DISABLED; if (flags & BPF_FIB_LOOKUP_OUTPUT) { diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 8fd2ff8510021738e6bde499cc9fae83c52b91ee..37117df401bc47ab66cf89ebcaee1684be84b4c2 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -551,7 +551,8 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex, goto out; if ((all || type == NETCONFA_FORWARDING) && - nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0) + nla_put_s32(skb, NETCONFA_FORWARDING, + READ_ONCE(devconf->forwarding)) < 0) goto nla_put_failure; #ifdef CONFIG_IPV6_MROUTE if ((all || type == NETCONFA_MC_FORWARDING) && @@ -869,7 +870,8 @@ static void addrconf_forward_change(struct net *net, __s32 newf) idev = __in6_dev_get(dev); if (idev) { int changed = (!idev->cnf.forwarding) ^ (!newf); - idev->cnf.forwarding = newf; + + WRITE_ONCE(idev->cnf.forwarding, newf); if (changed) dev_forward_change(idev); } @@ -886,7 +888,7 @@ static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int newf) net = (struct net *)table->extra2; old = *p; - *p = newf; + WRITE_ONCE(*p, newf); if (p == &net->ipv6.devconf_dflt->forwarding) { if ((!newf) ^ (!old)) @@ -901,7 +903,7 @@ static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int newf) if (p == &net->ipv6.devconf_all->forwarding) { int old_dflt = net->ipv6.devconf_dflt->forwarding; - net->ipv6.devconf_dflt->forwarding = newf; + WRITE_ONCE(net->ipv6.devconf_dflt->forwarding, newf); if ((!newf) ^ (!old_dflt)) inet6_netconf_notify_devconf(net, RTM_NEWNETCONF, NETCONFA_FORWARDING, diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 0559bd0005858631f88c706f98c625ad0bfff278..444be8c84cc579bf32b2950e0261ffe7c1d265a8 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -501,7 +501,7 @@ int ip6_forward(struct sk_buff *skb) u32 mtu; idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); - if (net->ipv6.devconf_all->forwarding == 0) + if (READ_ONCE(net->ipv6.devconf_all->forwarding) == 0) goto error; if (skb->pkt_type != PACKET_HOST) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 9c9c31268432ee58c1a381d0333d85a558a602e1..1fb5e37bc78be54c71b49506e833a53edff3fa0e 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -903,7 +903,7 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb) } if (ipv6_chk_acast_addr(net, dev, &msg->target) || - (idev->cnf.forwarding && + (READ_ONCE(idev->cnf.forwarding) && (net->ipv6.devconf_all->proxy_ndp || idev->cnf.proxy_ndp) && (is_router = pndisc_is_router(&msg->target, dev)) >= 0)) { if (!(NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED) && @@ -929,7 +929,7 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb) } if (is_router < 0) - is_router = idev->cnf.forwarding; + is_router = READ_ONCE(idev->cnf.forwarding); if (dad) { ndisc_send_na(dev, &in6addr_linklocal_allnodes, &msg->target, @@ -1080,7 +1080,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) * Note that we don't do a (daddr == all-routers-mcast) check. */ new_state = msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE; - if (!neigh && lladdr && idev && idev->cnf.forwarding) { + if (!neigh && lladdr && idev && READ_ONCE(idev->cnf.forwarding)) { if (accept_untracked_na(dev, saddr)) { neigh = neigh_create(&nd_tbl, &msg->target, dev); new_state = NUD_STALE; @@ -1100,7 +1100,8 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) * has already sent a NA to us. */ if (lladdr && !memcmp(lladdr, dev->dev_addr, dev->addr_len) && - net->ipv6.devconf_all->forwarding && net->ipv6.devconf_all->proxy_ndp && + READ_ONCE(net->ipv6.devconf_all->forwarding) && + net->ipv6.devconf_all->proxy_ndp && pneigh_lookup(&nd_tbl, net, &msg->target, dev, 0)) { /* XXX: idev->cnf.proxy_ndp */ goto out; @@ -1148,7 +1149,7 @@ static enum skb_drop_reason ndisc_recv_rs(struct sk_buff *skb) } /* Don't accept RS if we're not in router mode */ - if (!idev->cnf.forwarding) + if (!READ_ONCE(idev->cnf.forwarding)) goto out; /* diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 66c685b0b6199fee3bc39768eab5a6fb831bd2f5..6a2b53de48182525a923e62ba3fbd13cba60a48a 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2220,7 +2220,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, strict |= flags & RT6_LOOKUP_F_IFACE; strict |= flags & RT6_LOOKUP_F_IGNORE_LINKSTATE; - if (net->ipv6.devconf_all->forwarding == 0) + if (READ_ONCE(net->ipv6.devconf_all->forwarding) == 0) strict |= RT6_LOOKUP_F_REACHABLE; rcu_read_lock(); @@ -4149,7 +4149,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu in6_dev = __in6_dev_get(skb->dev); if (!in6_dev) return; - if (in6_dev->cnf.forwarding || !in6_dev->cnf.accept_redirects) + if (READ_ONCE(in6_dev->cnf.forwarding) || !in6_dev->cnf.accept_redirects) return; /* RFC2461 8.1: From patchwork Wed Feb 28 13:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575529 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF22F14F9E5 for ; Wed, 28 Feb 2024 13:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128495; cv=none; b=Oj+QtL61eR8n0IyB2RPr/KN/cLT/g2BbcBA/pQphUOaWC2OyNyMoFU2dJRmjnC7YNpcByATeqLIoUG7xSLVPyRpE4XOMtxj+Odr8Tz7YwP0qKOzwMGXngVcYAHxov8ow+Nx/S9Xb6U5Don312dTvcARZcvtlOpFaGhlAUf0S19Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128495; c=relaxed/simple; bh=2H40xd+LczME4dMDxh7XbSLIxqtTZYpnih/4mbpwe7g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eajVyuAloguAs1J4e6y6Os7D38zilckh1ez2n7VA3EJbA3V3KgqYIikiYvom8AabatTIYJn/5Vk4r+xjOju5OqdOeirWw2GK+P4di7mG8LXRm26FP4g78JulRZ0CGgBtleRL2dBZu4rbTn8M7ZjMXpA3LSkFWRYMbntoghV+InM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ILGwSS6s; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ILGwSS6s" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-607838c0800so9605447b3.1 for ; Wed, 28 Feb 2024 05:54:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128492; x=1709733292; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lQuzBEUbCY/TH3aVKeFALmVgaiFsq92+oYWEs6Hx46I=; b=ILGwSS6sKRfTUx5F7nhsClUrhJoft2c9Roq910KFVf1YBUQLCmeY5yRpdkOhE3KjTA m60+sU19hr/jIylBheN5seulbs6OCZHOh6jE1BAbytOdhiFJbbfha5iyuVd4Mj8jlY+f yoxtJO2n7U5gUMKhseYaIEoNTNfNOvr/+A5kg+jlJjr4SMQMwIjGV6J1DGvq0ohjB9ci bV9Di4VlJiHEBa+xvCc69Dex4eV5qOkRuea4BBQ78ICXSFD7LHjN2o59KG7pD89pz5Ul +y2JY+MQDwFzFD9Nglh+ph3WBXUn4Gx65Bzr3aTE48C6tFchxdY+OgEKftvz305mt122 cOTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128492; x=1709733292; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lQuzBEUbCY/TH3aVKeFALmVgaiFsq92+oYWEs6Hx46I=; b=Aptg7XJKxrH1oUh8E5v3wuii/u2Ham8GsRvvZNac93THZ3SvRJ/Zal+qotc/E/Rs/j NtjPeAh7HtQEKod0kzQz5nV5bQY5Do/tGiNsXb8tdbcOSvCAm4Buxa7cKAG3OkMKqToH Edez/4GGGFWaw8EuVN3adbqTwRxsLvA0Wc1DTNQ7IZlSDhIboTwD0OP1HkIw0Sw1RL2j aPO0cr/GOno0A74hQaiBOyq1c16qr1CUQVH/159yF+MsQnEWelz/OxDeLK++i9mMB0po wbDCKiIPHoRimfwPCmFN6ZPz+Q6exHWGYQnEqIJnqjWKSgPJHpeL05rR2UFRuV4g3jht msCQ== X-Gm-Message-State: AOJu0YzWda3w0v8o18lNvPh3EEPFN3Gl/rS3IebxFUw/O0OO7Ay9EwGk I2WroMZsebQXHIfSnbDI3Y7yPcjRizE0bqzwO49WBU2mSm3DFgVG7ywUQ5XjCU2bLvqdtspN+AJ vWaekQi6sHA== X-Google-Smtp-Source: AGHT+IHSRm15nuEVFBKkXS6968ZJoMjOoRacycpnj1GxT38WUA0v3yzhpbWCmhSpmD6+ute//ZoqS2UsZJH7oQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:84d4:0:b0:608:aaf0:d8b4 with SMTP id u203-20020a8184d4000000b00608aaf0d8b4mr510010ywf.3.1709128492732; Wed, 28 Feb 2024 05:54:52 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:31 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-8-edumazet@google.com> Subject: [PATCH v3 net-next 07/15] ipv6: annotate data-races in ndisc_router_discovery() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Annotate reads from in6_dev->cnf.XXX fields, as they could change concurrently. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/ndisc.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 1fb5e37bc78be54c71b49506e833a53edff3fa0e..f6430db249401b12debc0b174027af966fa71ccb 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1319,7 +1319,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) if (old_if_flags != in6_dev->if_flags) send_ifinfo_notify = true; - if (!in6_dev->cnf.accept_ra_defrtr) { + if (!READ_ONCE(in6_dev->cnf.accept_ra_defrtr)) { ND_PRINTK(2, info, "RA: %s, defrtr is false for dev: %s\n", __func__, skb->dev->name); @@ -1327,7 +1327,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) } lifetime = ntohs(ra_msg->icmph.icmp6_rt_lifetime); - if (lifetime != 0 && lifetime < in6_dev->cnf.accept_ra_min_lft) { + if (lifetime != 0 && + lifetime < READ_ONCE(in6_dev->cnf.accept_ra_min_lft)) { ND_PRINTK(2, info, "RA: router lifetime (%ds) is too short: %s\n", lifetime, skb->dev->name); @@ -1338,7 +1339,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) * accept_ra_from_local is set to true. */ net = dev_net(in6_dev->dev); - if (!in6_dev->cnf.accept_ra_from_local && + if (!READ_ONCE(in6_dev->cnf.accept_ra_from_local) && ipv6_chk_addr(net, &ipv6_hdr(skb)->saddr, in6_dev->dev, 0)) { ND_PRINTK(2, info, "RA from local address detected on dev: %s: default router ignored\n", @@ -1350,7 +1351,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) pref = ra_msg->icmph.icmp6_router_pref; /* 10b is handled as if it were 00b (medium) */ if (pref == ICMPV6_ROUTER_PREF_INVALID || - !in6_dev->cnf.accept_ra_rtr_pref) + !READ_ONCE(in6_dev->cnf.accept_ra_rtr_pref)) pref = ICMPV6_ROUTER_PREF_MEDIUM; #endif /* routes added from RAs do not use nexthop objects */ @@ -1421,10 +1422,12 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) spin_unlock_bh(&table->tb6_lock); } - if (in6_dev->cnf.accept_ra_min_hop_limit < 256 && + if (READ_ONCE(in6_dev->cnf.accept_ra_min_hop_limit) < 256 && ra_msg->icmph.icmp6_hop_limit) { - if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) { - WRITE_ONCE(in6_dev->cnf.hop_limit, ra_msg->icmph.icmp6_hop_limit); + if (READ_ONCE(in6_dev->cnf.accept_ra_min_hop_limit) <= + ra_msg->icmph.icmp6_hop_limit) { + WRITE_ONCE(in6_dev->cnf.hop_limit, + ra_msg->icmph.icmp6_hop_limit); fib6_metric_set(rt, RTAX_HOPLIMIT, ra_msg->icmph.icmp6_hop_limit); } else { @@ -1506,7 +1509,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) } #ifdef CONFIG_IPV6_ROUTE_INFO - if (!in6_dev->cnf.accept_ra_from_local && + if (!READ_ONCE(in6_dev->cnf.accept_ra_from_local) && ipv6_chk_addr(dev_net(in6_dev->dev), &ipv6_hdr(skb)->saddr, in6_dev->dev, 0)) { ND_PRINTK(2, info, @@ -1515,7 +1518,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) goto skip_routeinfo; } - if (in6_dev->cnf.accept_ra_rtr_pref && ndopts.nd_opts_ri) { + if (READ_ONCE(in6_dev->cnf.accept_ra_rtr_pref) && ndopts.nd_opts_ri) { struct nd_opt_hdr *p; for (p = ndopts.nd_opts_ri; p; @@ -1527,14 +1530,14 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) continue; #endif if (ri->prefix_len == 0 && - !in6_dev->cnf.accept_ra_defrtr) + !READ_ONCE(in6_dev->cnf.accept_ra_defrtr)) continue; if (ri->lifetime != 0 && - ntohl(ri->lifetime) < in6_dev->cnf.accept_ra_min_lft) + ntohl(ri->lifetime) < READ_ONCE(in6_dev->cnf.accept_ra_min_lft)) continue; - if (ri->prefix_len < in6_dev->cnf.accept_ra_rt_info_min_plen) + if (ri->prefix_len < READ_ONCE(in6_dev->cnf.accept_ra_rt_info_min_plen)) continue; - if (ri->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen) + if (ri->prefix_len > READ_ONCE(in6_dev->cnf.accept_ra_rt_info_max_plen)) continue; rt6_route_rcv(skb->dev, (u8 *)p, (p->nd_opt_len) << 3, &ipv6_hdr(skb)->saddr); @@ -1554,7 +1557,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) } #endif - if (in6_dev->cnf.accept_ra_pinfo && ndopts.nd_opts_pi) { + if (READ_ONCE(in6_dev->cnf.accept_ra_pinfo) && ndopts.nd_opts_pi) { struct nd_opt_hdr *p; for (p = ndopts.nd_opts_pi; p; @@ -1565,7 +1568,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) } } - if (ndopts.nd_opts_mtu && in6_dev->cnf.accept_ra_mtu) { + if (ndopts.nd_opts_mtu && READ_ONCE(in6_dev->cnf.accept_ra_mtu)) { __be32 n; u32 mtu; From patchwork Wed Feb 28 13:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575530 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 586D4151CDB for ; Wed, 28 Feb 2024 13:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128496; cv=none; b=TuAZgp5XwJeCo13CrZhTpRJyCNEZYJwhag679gBA5LKoq0eW60If/0DNaowPeNHUUplh5oIcdsMfHz0xXAek3xdeyZRsZKPVgKJ8yPbND5QyC/1bIsDGx8F1SBzC1q5Ot355Oqn+LjRR3+ka6cqefWKNtcAtRr/qFTr+ZsPwrWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128496; c=relaxed/simple; bh=37i2tXE4tjKcp2Txcdvw0Y29p29o5Hp9vPQSdrQNu60=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gA500z4hG8cahFoRQO34OpIJmkJkiOO1X1b6+ILc4oBlLl+7eB9J3La0Nl/pvUFwdLzCmbTj3X83ILCeh+407zMCkm41JJFY1KcEXHS8mF5SEs19uxk4rm1fhH9/sto4KjBK8SCezZ1Aom+fGqmM+FayftQ8jjV+Vw380sb4EPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FQ6aPgKx; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FQ6aPgKx" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc746178515so7527594276.2 for ; Wed, 28 Feb 2024 05:54:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128494; x=1709733294; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IqDklRU6xerwK/HoCTmWPyGypizoUF4xDNpwuD85Hlk=; b=FQ6aPgKxMC9ypux0ADFTlvFJ4+NE/pEs1ZkFBz3K3amc106X/BnjLPzWIfCetZzONj IsFlA002S0aIaUrdirzOEZLbx63PSlRqmprklO9Ok1oGJAs5MQBNY3y5MBZeroS3k7rm R7kf2AYZVAxBVglJUbhKMpxsz4R8TrXNQLKn6o9l1DehzVAAyfvZlPG0Ilz3d51m2tq7 BTU9gS1Bge6Ju36c3bHz61XsjqzKZNpJVuChPLMrgljg9Y2UKvdu3IXAvQErgkmJCU72 u1nct1RjLjLF/rYgZcKtg3vy2EFiNET5Q2+s3Z7T1Y5OAvUcAYa7YnDrSC5qAvXMW/Yf +q/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128494; x=1709733294; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IqDklRU6xerwK/HoCTmWPyGypizoUF4xDNpwuD85Hlk=; b=kQf5VC/8rFSPt3+N3PRzRermRaTKLxwunycC52JNyOjb7+H5UzzMDYmTzYTEXgKLU+ lADxONaxCdX+ijUTtyTFf7li6eE2owHiasxt6e0mozH4FTYgUBmkex0ULc5QnQMoeVBc WxYWMDgu3eYfgxzek/Edyt++EoHrA7BFKb3oDJ8VeuqKUFAM/qNuv4sohmU8nJ/juLey FBc+e7RGZSqyELZWlK2gOIOE7lpaq5hErFmVBjejy9Fz7uxntb+1zUP+W7ErpAx8cPki bTKQlYbwgcMzMAUTN5VCEG+4faZimbNbin07dRPaLpLtQNiH7dAtJ5tRgmjhmAUb42Cu ykxg== X-Gm-Message-State: AOJu0Yzc/0HziUHh5gm4Qkod2HCdF3x7NQJwxcJXlxVEtbYBB0OX91VF M1e8JMAKjx1QOFg75it1B0y81vFIOEet2v7ebPI1khjtdtXeuboRcy6sO5LyPsvIR3SuF0CnGMH Um/DCiZghnw== X-Google-Smtp-Source: AGHT+IHAAQT8MSHo6rhrozkybAbbRlilrMRks6RTGJwYeW6OoJ38AxKFtBk8BxJ2tjE4MhcKUeCkSM5xEQpzPg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1244:b0:dc6:ff54:249f with SMTP id t4-20020a056902124400b00dc6ff54249fmr367352ybu.8.1709128494406; Wed, 28 Feb 2024 05:54:54 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:32 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-9-edumazet@google.com> Subject: [PATCH v3 net-next 08/15] ipv6: annotate data-races around idev->cnf.ignore_routes_with_linkdown From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org idev->cnf.ignore_routes_with_linkdown can be used without any locks, add appropriate annotations. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- include/net/addrconf.h | 2 +- net/ipv6/addrconf.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/net/addrconf.h b/include/net/addrconf.h index 30d6f1e84e465e06a88bbbffaee70fdbd4ec5dd3..9d06eb945509ecfcf01bec1ffa8481262931c5bd 100644 --- a/include/net/addrconf.h +++ b/include/net/addrconf.h @@ -417,7 +417,7 @@ static inline bool ip6_ignore_linkdown(const struct net_device *dev) if (unlikely(!idev)) return true; - return !!idev->cnf.ignore_routes_with_linkdown; + return !!READ_ONCE(idev->cnf.ignore_routes_with_linkdown); } void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp); diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 37117df401bc47ab66cf89ebcaee1684be84b4c2..31a8225a5abe6f315f110d83568773504aa97e08 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -566,7 +566,7 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex, if ((all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) && nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN, - devconf->ignore_routes_with_linkdown) < 0) + READ_ONCE(devconf->ignore_routes_with_linkdown)) < 0) goto nla_put_failure; out: @@ -935,7 +935,7 @@ static void addrconf_linkdown_change(struct net *net, __s32 newf) if (idev) { int changed = (!idev->cnf.ignore_routes_with_linkdown) ^ (!newf); - idev->cnf.ignore_routes_with_linkdown = newf; + WRITE_ONCE(idev->cnf.ignore_routes_with_linkdown, newf); if (changed) inet6_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF, @@ -956,7 +956,7 @@ static int addrconf_fixup_linkdown(struct ctl_table *table, int *p, int newf) net = (struct net *)table->extra2; old = *p; - *p = newf; + WRITE_ONCE(*p, newf); if (p == &net->ipv6.devconf_dflt->ignore_routes_with_linkdown) { if ((!newf) ^ (!old)) @@ -970,7 +970,7 @@ static int addrconf_fixup_linkdown(struct ctl_table *table, int *p, int newf) } if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) { - net->ipv6.devconf_dflt->ignore_routes_with_linkdown = newf; + WRITE_ONCE(net->ipv6.devconf_dflt->ignore_routes_with_linkdown, newf); addrconf_linkdown_change(net, newf); if ((!newf) ^ (!old)) inet6_netconf_notify_devconf(net, From patchwork Wed Feb 28 13:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575531 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A6F11586E4 for ; Wed, 28 Feb 2024 13:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128499; cv=none; b=dcqqscKx7jvD62/b6JKJapuUbpLb2jewwOljh/qpLpiiWqsEGfOyRPpnVLmIYqkBcFBvHMATG7mFAgj2k8qlCXpCX6yKUnKO2J1s2iCckZEyfK1+B0IMqLNcbb/V1BPa2Yg3A5KY++P1PXgFX8UPH9rCRbkiRW7e6NY6Hnu0Rzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128499; c=relaxed/simple; bh=7zwgaBOw2eLC2MLjKew1aryKHo37TVGSNJYtAe9Zf5g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WpZSS41jIizcYjCgXefJnUHhhImysE/c6de9D9nUYn3/lwp5hqtRLln7F/k9WsqtmBOkWF7xxWT7/zPphrz9i5n8fZhpacOpv2OlLrmS9o7Fv6j9Dn4j96RExuJsSsP9SNItSBkgKM+L6pYAa7SGgA7CAZRPFaHwMvCzJwcDCpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dTG7r0u3; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dTG7r0u3" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60938c2dbbaso15160547b3.0 for ; Wed, 28 Feb 2024 05:54:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128497; x=1709733297; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WTrsKUxf/0GG0WXUlx8/nW/+9j3jmatd2lZxXX3kf2A=; b=dTG7r0u336qJyRRv5TDDUxMikrd9lQ7S00w7HvTIZfyX8tidkKYjkI2N3U7ziMGBxL yUNTsO+OumgA9UxDKZIXc+tDz/u2OWXvH4NDQivHW4Lt0FBL4igBYok3xdlKBmxXan4N jX5M9p/CD3ER4HpAIMLFJv6QEOhtGS2D+Mx/ypWGPlH+eRPaaeLhV3nEeuhwelDol5jm w5uSpbkNf/wc+yzeC/Tz8fD4156EK+C2+uxqWGwOcoN3xSgvavsmjN/qsRJep+RKyd/V j6y62dTEUutAcCL0aGDPf0mOrFkgVXVIoBaLPFvjJ5ZfEoFnMszzGg4S8dhxMPeEKxbR Z57w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128497; x=1709733297; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WTrsKUxf/0GG0WXUlx8/nW/+9j3jmatd2lZxXX3kf2A=; b=KBo1Tq0xkw4tL32X+JYNKsRfnB2vECvNmcc2apjRaYsnU5765KIU7xAWQ2lWJN5QNX 8OEGzmDzibJvvwgyXqSYjzSLG9jo2ijMXBsTh+Q0t9B6t61VIemUKLBrQFZbEkqFUJgi qvp6G6SvLxZzE9zlNMhcyHViX4i7lT/NcPAxDlqvFNEB/wCeU8g9MzA1JCU6hjPVXcVq fwIHyc29bajXl8ZfGSOE5VCjZOHneH+zJcaa30Q7m1WC2jeIU01bpVZL6VK9MjJb9CND 07hbi0O2s3mhf5Grj9xQGZX1Pvr5UQF+cHWFadCcKZorACoAbgo/ZPtuCeOO5dwcCP12 yt1A== X-Gm-Message-State: AOJu0YyrWWYT0muf6jovYjdVlj3jCYobJa/odyYB67CvVBwMyfNiAxyx XBlf4e+5Z+PR09s0DTIVXpfT1ALE/N2xFh1gpp84pmTR8gPcMzQnxXPLnF8Ufd2wZ75bJyegNeM cppVEAbIlwQ== X-Google-Smtp-Source: AGHT+IGlTXPfG8jYFIz5corzlFVJlct+4YECdQTv7lm8y/xJqePS84z09Duq1p0dm+QsXKbeN8X1hAcO5jX2gw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:fc8:b0:607:9e9a:cba6 with SMTP id dg8-20020a05690c0fc800b006079e9acba6mr948375ywb.8.1709128497255; Wed, 28 Feb 2024 05:54:57 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:33 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-10-edumazet@google.com> Subject: [PATCH v3 net-next 09/15] ipv6: annotate data-races in rt6_probe() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Use READ_ONCE() while reading idev->cnf.rtr_probe_interval while its value could be changed. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/route.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 6a2b53de48182525a923e62ba3fbd13cba60a48a..1b897c57c55fe22eff71a22b51ad25269db622f5 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -645,14 +645,15 @@ static void rt6_probe(struct fib6_nh *fib6_nh) write_lock_bh(&neigh->lock); if (!(neigh->nud_state & NUD_VALID) && time_after(jiffies, - neigh->updated + idev->cnf.rtr_probe_interval)) { + neigh->updated + + READ_ONCE(idev->cnf.rtr_probe_interval))) { work = kmalloc(sizeof(*work), GFP_ATOMIC); if (work) __neigh_set_probe_once(neigh); } write_unlock_bh(&neigh->lock); } else if (time_after(jiffies, last_probe + - idev->cnf.rtr_probe_interval)) { + READ_ONCE(idev->cnf.rtr_probe_interval))) { work = kmalloc(sizeof(*work), GFP_ATOMIC); } From patchwork Wed Feb 28 13:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575532 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14181158D66 for ; Wed, 28 Feb 2024 13:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128501; cv=none; b=rT2SR+y/DOsDKJihHbq/UnqbrjkDnbICsSnmlpCXelS9wA8qcfe70zDlMTKnO3+7mqXNGB1bHS+QHE+dPWP02O3n+k+H1kqAs5rR0vDEu3yrhTSS1Gy4ExvDc+jW5wzNg23W2fpCbOJK1hokpwRCiFW9bgxMvL6wu5YAUdGX/w4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128501; c=relaxed/simple; bh=2XX9xA71+RP1Xg97iPh2TN80vTiKjQjIJwbi9JFH4E0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NXKaYJ0boEtYgT0rWsoFbxpGezRSgOVMQnKZV/bRHqFbmxQ+6Moy/B7pQS1H/uXuXATT0PlY8mvx6oplLVMHDE4LXC+oD9RobjlAHIX/kgiqzQfdl21eSF9bqQMjQmktZtWX3HdgDlfXb/cEKpa4aZzuHKsb6Etw8td1loChHso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4S2cS1Tu; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4S2cS1Tu" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b269686aso8652070276.1 for ; Wed, 28 Feb 2024 05:54:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128499; x=1709733299; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MBSkGlpnzKLh2ctZVNRMrN7zMfI7gCScvcV6bolxLsE=; b=4S2cS1TuH8hjTh0n59fPZYLI3ZsI58dSqo9SGTp8lK2XGUthTZ338I9jjILZgKWaPe 5zrG6sxOcxK+db8upPJQXzSVY2bWiT1ThJqd/saDfEiP+eawK0ai/ws7cFDqDWuEuhfi 8RhROObSL9pVl5WJ7Mp/VjlVGOULC1DStmXcHJ9IEZ1qaMPMom9FXDfa7xDJMyLiYRZh IFE+K9PxNbW5Hr0M7sdNfW8WDv7MdVekPn8Fler2Cym+JrDdYb4AinUHBIZYN6TSRi+T yR8B145tcWnIJCE0h67urrqAmTr2HV23LHMgSYkozzEa1LoJsDDgBKEBZdHM/9fO4WkN hppw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128499; x=1709733299; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MBSkGlpnzKLh2ctZVNRMrN7zMfI7gCScvcV6bolxLsE=; b=bOzMdNONKQD214m6paHqiE/cQutb2LLCDDHcjC08+FqB/O3SLagfL0pCWgWsLfrrbH 0O3/g3gutNBh2ksh3V3iu1SaEPj73/ToDzlzTe91LUkOYQLBq/7JsXfcNb83X3QGgRww r3jx9+8lSLN33AQQ8p5mYsHbGQt4jkJoBEQzjqOZOV0LPMw+FTirJNkQybTE8jvxsBNy HQP01mGf4LKtfEUR5NGikdtPN66inKVoC+k5nLn9XS34wyrkxL/4J5kW2fwWI9GICipF SMOB/L9vjajsBrSZdpZHp3o+Ifk6fuX+89522rh47nn5nhU/1dMP0qov5MZKC5LFRiou xzyA== X-Gm-Message-State: AOJu0Yyns5OUTOwS6o1xI1KVwAo1lte7RS+hTXnTLUN2iW90RnuIHGIR f6mM0R/NNsOOmFNLlMixAeFxMSXzt3fH+9Ai/exGADrYrud2cXVDOyEw6OOU9DKm0QEY4ha2Z3L LNY7OpbA/ZA== X-Google-Smtp-Source: AGHT+IGv53usKs3rdAdUyvs1ndEVXHfD6GqkcwiX2Le3x4vPLdp3zXqYnEGZ3sBPThlVMiGTYXJBEKNmH1xRcQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1105:b0:dce:5218:c89b with SMTP id o5-20020a056902110500b00dce5218c89bmr117412ybu.5.1709128499150; Wed, 28 Feb 2024 05:54:59 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:34 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-11-edumazet@google.com> Subject: [PATCH v3 net-next 10/15] ipv6: annotate data-races around devconf->proxy_ndp From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org devconf->proxy_ndp can be read and written locklessly, add appropriate annotations. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 3 ++- net/ipv6/ip6_output.c | 2 +- net/ipv6/ndisc.c | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 31a8225a5abe6f315f110d83568773504aa97e08..18b1e79c1ebf8de17f813ef697be69e3d9c209a2 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -561,7 +561,8 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex, goto nla_put_failure; #endif if ((all || type == NETCONFA_PROXY_NEIGH) && - nla_put_s32(skb, NETCONFA_PROXY_NEIGH, devconf->proxy_ndp) < 0) + nla_put_s32(skb, NETCONFA_PROXY_NEIGH, + READ_ONCE(devconf->proxy_ndp)) < 0) goto nla_put_failure; if ((all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) && diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 444be8c84cc579bf32b2950e0261ffe7c1d265a8..f08af3f4e54f5dcb0b8b5fb8f60463e41bd1f578 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -552,7 +552,7 @@ int ip6_forward(struct sk_buff *skb) } /* XXX: idev->cnf.proxy_ndp? */ - if (net->ipv6.devconf_all->proxy_ndp && + if (READ_ONCE(net->ipv6.devconf_all->proxy_ndp) && pneigh_lookup(&nd_tbl, net, &hdr->daddr, skb->dev, 0)) { int proxied = ip6_forward_proxy_check(skb); if (proxied > 0) { diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index f6430db249401b12debc0b174027af966fa71ccb..4114918f12c88f2b74e53d6d726018994feaf213 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -904,7 +904,8 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb) if (ipv6_chk_acast_addr(net, dev, &msg->target) || (READ_ONCE(idev->cnf.forwarding) && - (net->ipv6.devconf_all->proxy_ndp || idev->cnf.proxy_ndp) && + (READ_ONCE(net->ipv6.devconf_all->proxy_ndp) || + READ_ONCE(idev->cnf.proxy_ndp)) && (is_router = pndisc_is_router(&msg->target, dev)) >= 0)) { if (!(NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED) && skb->pkt_type != PACKET_HOST && @@ -1101,7 +1102,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) */ if (lladdr && !memcmp(lladdr, dev->dev_addr, dev->addr_len) && READ_ONCE(net->ipv6.devconf_all->forwarding) && - net->ipv6.devconf_all->proxy_ndp && + READ_ONCE(net->ipv6.devconf_all->proxy_ndp) && pneigh_lookup(&nd_tbl, net, &msg->target, dev, 0)) { /* XXX: idev->cnf.proxy_ndp */ goto out; From patchwork Wed Feb 28 13:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575533 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 052B1158D66 for ; Wed, 28 Feb 2024 13:55:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128504; cv=none; b=FA2ZvXopJMObm9LDghGcQYpj+vvyT+CVhxGc6V6N+ri3maX81b14d005Ftsu6lqFR85gXW4Bz99geZ1EMbal4SJe/SKSU7N5FS6TodYjTfHc9ku4X7/OPOTR6q6iM2NiCraXeOV0GChGK0ULCanvZJva0IRDvQuz+pU2siT0ZjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128504; c=relaxed/simple; bh=Avi97JMj+FX+r0ctgFZtnz6JEj8JCuE0CB279mVyCyM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nVGXvDnq06aWbJ4lF5FkFHC6z8FagpWRkYzsnsvUtgUA4/DSsX219gP3Z4yo9YirID6nA0kFf/jvupo6Av6+S5N2esrv+xM/19KL16WsZGFzM8gY3fA/xqdO6TLKjl/5EWGd3wUQgQh/6BZLe+8seEXqUguuKWdKLl9MIH7Lf0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yTqeh6Ap; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yTqeh6Ap" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608d6ffc64eso13444887b3.0 for ; Wed, 28 Feb 2024 05:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128502; x=1709733302; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tk2C3ivOITUuGaOou7Ec/yRMlCsy5fQgerbe/Ye8Ii8=; b=yTqeh6ApDLWeCcecNDggGpALSYwrT477PQ3kQIo7WbzeWsbqBOMY42JBajLoHs30U6 /FGDTBqMxOaLpBR/eLsNBpkWWwXlffn1udwcn9ec/DPSRn+ymzrkTSvp+p/YL+xbjpEc PVip0RXquNnJ8/19AohYuOcMQgnBLTDl+BVxUT37rLbFsVeFROUJBt9G7z0d4J6EXvMy QzlKmqtFD/H1w9pCgCLT5L2LuLSXDJZAxRH1feBO+YF3oR5M1RIXwZW5mdP+xj0IbSRT 7u+3olJ7tJUNZ25F1yNN6/sCIaKCs0z3vmdti/4+UF4eNXWe85X4DezSwmcsWTomAvI0 Xamw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128502; x=1709733302; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tk2C3ivOITUuGaOou7Ec/yRMlCsy5fQgerbe/Ye8Ii8=; b=MZQmy/v30JGEFP/+06JT/E1f7Cbrs+GhtBy4RTgMYg1laYGbPTgc53AYuoy/3uVHM7 oZWjsWMHmpbU0GwlIjLciJ0/NIfMqo+q9e1SwFaTSq224k+D+ubP7+ImfEfii+LwDJSY JS+L0z7xFbJKJot0sN/0UKJd/ZoCG/XJhkEpyOwrVDfK2x084IHlpU6U8vTM66iajOI6 lyGvSEysWDUiDKQJhta892o2eyvmJLfcvXPgjVwKVoL11kkjO36r1Q05oRDGiNK2r3/l 9BanPU68Dsu53MspQzCPfWggCtGvrqESWA9uMqHMudvF3BmfJllPBCE6rMpEsO+k3MVW zjUA== X-Gm-Message-State: AOJu0YzjOzPrK/4hm4bqS6kZGuEKOJ/4wMlTUn0D8mYhe5KQviJMzi2j M3D+QdjC/AiVbd/g/U7Mh+Bs0BZ89yd7UjHpYyJBdEut9Lihx/Og8OwYG+gNssoX5Jw3/sMZJ8v xsel4jZkW1A== X-Google-Smtp-Source: AGHT+IGz40cy3krJGgRG4YR5gYwQUW+D+9a623RfqW8WQDglK+SYYRDWl4yctJYjwng7r3vzeMv4VCJ13eVQsw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:db8b:0:b0:607:8f65:5433 with SMTP id d133-20020a0ddb8b000000b006078f655433mr509353ywe.4.1709128502138; Wed, 28 Feb 2024 05:55:02 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:35 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-12-edumazet@google.com> Subject: [PATCH v3 net-next 11/15] ipv6: annotate data-races around devconf->disable_policy From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org idev->cnf.disable_policy and net->ipv6.devconf_all->disable_policy can be read locklessly. Add appropriate annotations on reads and writes. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 2 +- net/ipv6/ip6_output.c | 4 ++-- net/ipv6/route.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 18b1e79c1ebf8de17f813ef697be69e3d9c209a2..865fb55d0a2c7084cb80a704ad4fb2d97938bab4 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -6698,7 +6698,7 @@ int addrconf_disable_policy(struct ctl_table *ctl, int *valp, int val) if (!rtnl_trylock()) return restart_syscall(); - *valp = val; + WRITE_ONCE(*valp, val); net = (struct net *)ctl->extra2; if (valp == &net->ipv6.devconf_dflt->disable_policy) { diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index f08af3f4e54f5dcb0b8b5fb8f60463e41bd1f578..b9dd3a66e4236fbf67af75c5f98c921b38c18bf6 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -513,8 +513,8 @@ int ip6_forward(struct sk_buff *skb) if (skb_warn_if_lro(skb)) goto drop; - if (!net->ipv6.devconf_all->disable_policy && - (!idev || !idev->cnf.disable_policy) && + if (!READ_ONCE(net->ipv6.devconf_all->disable_policy) && + (!idev || !READ_ONCE(idev->cnf.disable_policy)) && !xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); goto drop; diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 1b897c57c55fe22eff71a22b51ad25269db622f5..a92fcac902aea9307e0c83d150e9d1c41435887f 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4584,8 +4584,8 @@ struct fib6_info *addrconf_f6i_alloc(struct net *net, f6i->dst_nocount = true; if (!anycast && - (net->ipv6.devconf_all->disable_policy || - idev->cnf.disable_policy)) + (READ_ONCE(net->ipv6.devconf_all->disable_policy) || + READ_ONCE(idev->cnf.disable_policy))) f6i->dst_nopolicy = true; } From patchwork Wed Feb 28 13:54:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575534 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB1D8158D81 for ; Wed, 28 Feb 2024 13:55:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128506; cv=none; b=aahr17FkLsKChSMRS0AiqDK2q0fdMPab7ozVrldq6flEhPxEhSyU3il+Dpv7n7yIFrdMYmSBVxeUMWE7vkPXNscgSucNYTi/2+OKzFUAPzcN3EM4KiVjfAV94fFtwfaw0WOxxCl5JwVHgTDONktTtoOExFF2vNwTYPJbwgdA7d4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128506; c=relaxed/simple; bh=2YzrzM7iR7CdeEyyZ+xAwDhYy17DBcnlq4xaYTXDaK0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Hy1ZzDBWiGoU4qVSTk2305LH2CzKW1V8+S0mSdjs0Tl5dl/Oi+FFAu+5ILM2uBQ1VLWqZZrPG0OaDRzgrJsyEtW4V5h/Kh3SmVLDyKvgyz2ygHyZEpk/CL0LadcrciNFtdNMlYVQjs1UjGLydUdxmoz7Lnn9d0WhKG2qEHvFWqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d5MaXO/k; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d5MaXO/k" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-607e56f7200so51249227b3.2 for ; Wed, 28 Feb 2024 05:55:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128504; x=1709733304; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ux2I2RIzDi5uA7HnqdhVbRUV2suJ02PPtfk5GugwbHw=; b=d5MaXO/k618VSsws/bw8FgShGiWtSkbOkT10Oi3tz94BVPnX8Y4S+NufKyOV7UsDuj BBOg2SuEuzlF6799reIJHwlQzoFMr32gdLI3JrLw8AitCM+4njbYRGZ3hU7WhHp2i8Jk fShj3wvx2CbD/L2BrtYObl7ixlQx60p1GFHe4yC/wEXzjz6DGSGdn63q7+H2vAObUjkb cOvD4l9gLF5My6IrVaoL1YeMiqkTDohT0kCBYOZxF6l4n4Usky1xnNok4N4Y0tQfqTtF +xnwZeAdnh5VvI6wdPj2n8+xgwEW6U5BAwVaFcT85qjx6psP+5Pw7Hv1hAy/iPFq7xKl bVXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128504; x=1709733304; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ux2I2RIzDi5uA7HnqdhVbRUV2suJ02PPtfk5GugwbHw=; b=GIh4Xg6dSPNJKXYU1eE2xtVWD+/xoC3sEYn2vSbAxIzDo0+nKzdVcpy/be4m3OBCH8 WUrPep3XgcbHvXX53DZT6vNM1QGhRhsX+R7X/9A2YmMqxRufM+Kxu7ewUuWe3KcatIe4 a2iU0ZMJ3rXu1W6FdK+oAA62NSrWh1qqbr4a5lvDguduWL8rCR34aTX5wT5a9MrLxzox uxFKm9UPT2WPvzPMfIlEGknC3w/kCe50UU2hZAikqwDwz8k4nQpNrSLwWVTWOLeQ6rgW BiNLmc004J6ef3YQ5IZvZxuA3bo3+Dwkd/sY7Oj0+rUN9NLM4MrWbd6BNuGPoh3rIeYI OHAQ== X-Gm-Message-State: AOJu0Yy7Uijc9KfgygUPnSg/WfvvkudkhfWBepJqXP7Odk0wYq72bDG/ ghkZZGxy8A0228rJN3Srv2yKRMiztWWTbe3feTJgmGNmVzOoqCMOjnY18Yv56BXrogXVbStoV9W sbRbDz4ABHA== X-Google-Smtp-Source: AGHT+IHFZ9ROAOO7LhhNpH/68QnH0mX8upS+4elYgpXD2SJsiY+NMC7UOfZr7IEIEKipvDYrq32VPOkF/eerjQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1001:b0:dcd:b593:6503 with SMTP id w1-20020a056902100100b00dcdb5936503mr147299ybt.2.1709128503786; Wed, 28 Feb 2024 05:55:03 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:36 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-13-edumazet@google.com> Subject: [PATCH v3 net-next 12/15] ipv6: addrconf_disable_policy() optimization From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Writing over /proc/sys/net/ipv6/conf/default/disable_policy does not need to hold RTNL. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 865fb55d0a2c7084cb80a704ad4fb2d97938bab4..20f327bc13340dfa2613f780b741c30294e50bc9 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -6692,20 +6692,19 @@ void addrconf_disable_policy_idev(struct inet6_dev *idev, int val) static int addrconf_disable_policy(struct ctl_table *ctl, int *valp, int val) { + struct net *net = (struct net *)ctl->extra2; struct inet6_dev *idev; - struct net *net; + + if (valp == &net->ipv6.devconf_dflt->disable_policy) { + WRITE_ONCE(*valp, val); + return 0; + } if (!rtnl_trylock()) return restart_syscall(); WRITE_ONCE(*valp, val); - net = (struct net *)ctl->extra2; - if (valp == &net->ipv6.devconf_dflt->disable_policy) { - rtnl_unlock(); - return 0; - } - if (valp == &net->ipv6.devconf_all->disable_policy) { struct net_device *dev; From patchwork Wed Feb 28 13:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575535 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA35B158D93 for ; Wed, 28 Feb 2024 13:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128508; cv=none; b=owYpFYZ3kJx15Jvwr7dLJdK89SNDpTlpycjA05dM/XM73w8R/xPHCZmmVmM2Rf0zJNUegMgCSus5vqTg/I+s9DBt8OG2Z4FgURMWKxfcEGXFqYojVwKQXEp7o0SUbTiScY5/EFjO0saVpu3fQlhynPWYyr4YkoWJBj2XgDjhkbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128508; c=relaxed/simple; bh=xUrKl6GGvFdOP78PKL1/to9hDJ12lqzjaRTtxfJGCew=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MTkwnUoYCwS7/K/27jBdPNA6nntbCGlscjAYE5f/0qnkzwXgz7QFsHUtZbkJ7VQCT0ckqfsLPuF50LbBD4dC7ASpIpMolLXJ7PRGdspYy7NOzAVGRiM45BV2PyDOEBm5x2eSlR88REjKjii2XvmxP/+W0ddHdwsFVQ7KfR0epSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WqpYmMtm; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WqpYmMtm" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6092c637278so22993297b3.0 for ; Wed, 28 Feb 2024 05:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128506; x=1709733306; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RGqabXLs2FU7t0fSMve41kjIEcWGCFIlHQQ4gILcTEM=; b=WqpYmMtmz+S4G8w3eu2qL9eCqaJMJzDLnHyNEYV5nvzezztWqBOmM2t+yoWWcK9VPG kuYmx7peDoWvon0n9BTpcSoZtlmgAfUI8r+CMyIctVSfJGelHnAH+vAXJGREXZutztOs mjYJMOfr/zY7u6JhpAZqK0XeYXRNgMkAkNGysMYbyggfVaaiRqpZirtbgTdQjsR/lMWz ntga0h75a78A07bJavnn8BAntXzo1T90eAT5UkXdme0ywxaRXrLB3dYeWUKvjYn6YTSq BTZ9liHllnf+6ZiHAoBdi7MNGsNbVZMm4O1CvSQ0MZmSfWR4Z5ruVSIeOVhQU3VYoBq1 CXOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128506; x=1709733306; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RGqabXLs2FU7t0fSMve41kjIEcWGCFIlHQQ4gILcTEM=; b=vjm+QKJJvWDXPUnFYnCszV4EkhxrZk5nTBYlJ+KyIiPUweW5I8VsCXDk1gxIFCSmAo 1EAWuv34kdPwSUCHhneXAiyIssweoLPwhILNqYMVrlL6GiWcqAUI3+nHj4agwobZQsGk KzYNDa+rsQW6BFyrBbUb6G86HOiwajg+IiQ6pypzEh5jT+L3QqevVPx1QIyvCLwzC6AS vNUXPz6awk9jwnxMWp7Kt7RbY+QXtjnChswSBTbD5HiJHetUbIpCBuVCMD0VuYfFiPRH nk3o+FRp0pLgE3AB3rlAj0svPOvW0gEG0c4M4GfaZy+ItRrAv2dVTk+Kcm8hYbZyjO+p jzDA== X-Gm-Message-State: AOJu0YyaBH8pktRJ0FOGdGIcJBb5UG1xBIkGg9JCMI5BjrKuA+nTPKHH O2VOuSBScpbNioV14tO8SSEL3thsgFtpIPQd/wpYmjUjCtntEPhwqacrdZwNhusJmu6nMHUM8Ow Qxx0E7YEpqQ== X-Google-Smtp-Source: AGHT+IEnE6j4sIPi94cQ4i6B3Job3kT7NOTqmJkizywX3qLKUs0zcDAXl9uGsB6/BLEDji1cySdl5go83Y2A5Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:4c8d:0:b0:608:d499:3439 with SMTP id z135-20020a814c8d000000b00608d4993439mr831936ywa.7.1709128505798; Wed, 28 Feb 2024 05:55:05 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:37 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-14-edumazet@google.com> Subject: [PATCH v3 net-next 13/15] ipv6/addrconf: annotate data-races around devconf fields (I) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Annotate lockless reads and writes on following devconf fields: - regen_min_advance - regen_max_retry - dad_transmits - use_tempaddr - max_addresses - max_desync_factor - temp_valid_lft - rtr_solicits - rtr_solicit_max_interval - rtr_solicit_interval - rtr_solicit_delay - enhanced_dad - accept_redirects Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 67 +++++++++++++++++++++++++-------------------- net/ipv6/route.c | 3 +- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 20f327bc13340dfa2613f780b741c30294e50bc9..fee5cf69648bc653502df7bfaac7e5c65a43fbf2 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1359,11 +1359,12 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) in6_ifa_put(ifp); } -static unsigned long ipv6_get_regen_advance(struct inet6_dev *idev) +static unsigned long ipv6_get_regen_advance(const struct inet6_dev *idev) { - return idev->cnf.regen_min_advance + idev->cnf.regen_max_retry * - idev->cnf.dad_transmits * - max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; + return READ_ONCE(idev->cnf.regen_min_advance) + + READ_ONCE(idev->cnf.regen_max_retry) * + READ_ONCE(idev->cnf.dad_transmits) * + max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; } static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) @@ -1384,7 +1385,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) retry: in6_dev_hold(idev); - if (idev->cnf.use_tempaddr <= 0) { + if (READ_ONCE(idev->cnf.use_tempaddr) <= 0) { write_unlock_bh(&idev->lock); pr_info("%s: use_tempaddr is disabled\n", __func__); in6_dev_put(idev); @@ -1392,8 +1393,8 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) goto out; } spin_lock_bh(&ifp->lock); - if (ifp->regen_count++ >= idev->cnf.regen_max_retry) { - idev->cnf.use_tempaddr = -1; /*XXX*/ + if (ifp->regen_count++ >= READ_ONCE(idev->cnf.regen_max_retry)) { + WRITE_ONCE(idev->cnf.use_tempaddr, -1); /*XXX*/ spin_unlock_bh(&ifp->lock); write_unlock_bh(&idev->lock); pr_warn("%s: regeneration time exceeded - disabled temporary address support\n", @@ -1415,7 +1416,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) */ cnf_temp_preferred_lft = READ_ONCE(idev->cnf.temp_prefered_lft); max_desync_factor = min_t(long, - idev->cnf.max_desync_factor, + READ_ONCE(idev->cnf.max_desync_factor), cnf_temp_preferred_lft - regen_advance); if (unlikely(idev->desync_factor > max_desync_factor)) { @@ -1432,7 +1433,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) memset(&cfg, 0, sizeof(cfg)); cfg.valid_lft = min_t(__u32, ifp->valid_lft, - idev->cnf.temp_valid_lft + age); + READ_ONCE(idev->cnf.temp_valid_lft) + age); cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor; cfg.preferred_lft = min_t(__u32, if_public_preferred_lft, cfg.preferred_lft); cfg.preferred_lft = min_t(__u32, cfg.valid_lft, cfg.preferred_lft); @@ -1685,7 +1686,7 @@ static int ipv6_get_saddr_eval(struct net *net, */ int preftmp = dst->prefs & (IPV6_PREFER_SRC_PUBLIC|IPV6_PREFER_SRC_TMP) ? !!(dst->prefs & IPV6_PREFER_SRC_TMP) : - score->ifa->idev->cnf.use_tempaddr >= 2; + READ_ONCE(score->ifa->idev->cnf.use_tempaddr) >= 2; ret = (!(score->ifa->flags & IFA_F_TEMPORARY)) ^ preftmp; break; } @@ -2168,6 +2169,7 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) { struct inet6_dev *idev = ifp->idev; struct net *net = dev_net(idev->dev); + int max_addresses; if (addrconf_dad_end(ifp)) { in6_ifa_put(ifp); @@ -2205,9 +2207,9 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) spin_unlock_bh(&ifp->lock); - if (idev->cnf.max_addresses && - ipv6_count_addresses(idev) >= - idev->cnf.max_addresses) + max_addresses = READ_ONCE(idev->cnf.max_addresses); + if (max_addresses && + ipv6_count_addresses(idev) >= max_addresses) goto lock_errdad; net_info_ratelimited("%s: generating new stable privacy address because of DAD conflict\n", @@ -2604,11 +2606,11 @@ static void manage_tempaddrs(struct inet6_dev *idev, * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR), respectively. */ age = (now - ift->cstamp) / HZ; - max_valid = idev->cnf.temp_valid_lft - age; + max_valid = READ_ONCE(idev->cnf.temp_valid_lft) - age; if (max_valid < 0) max_valid = 0; - max_prefered = idev->cnf.temp_prefered_lft - + max_prefered = READ_ONCE(idev->cnf.temp_prefered_lft) - idev->desync_factor - age; if (max_prefered < 0) max_prefered = 0; @@ -2641,7 +2643,7 @@ static void manage_tempaddrs(struct inet6_dev *idev, if (list_empty(&idev->tempaddr_list) && (valid_lft || prefered_lft)) create = true; - if (create && idev->cnf.use_tempaddr > 0) { + if (create && READ_ONCE(idev->cnf.use_tempaddr) > 0) { /* When a new public address is created as described * in [ADDRCONF], also create a new temporary address. */ @@ -2669,7 +2671,7 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev, int create = 0, update_lft = 0; if (!ifp && valid_lft) { - int max_addresses = in6_dev->cnf.max_addresses; + int max_addresses = READ_ONCE(in6_dev->cnf.max_addresses); struct ifa6_config cfg = { .pfx = addr, .plen = pinfo->prefix_len, @@ -4028,6 +4030,7 @@ static void addrconf_rs_timer(struct timer_list *t) struct inet6_dev *idev = from_timer(idev, t, rs_timer); struct net_device *dev = idev->dev; struct in6_addr lladdr; + int rtr_solicits; write_lock(&idev->lock); if (idev->dead || !(idev->if_flags & IF_READY)) @@ -4040,7 +4043,9 @@ static void addrconf_rs_timer(struct timer_list *t) if (idev->if_flags & IF_RA_RCVD) goto out; - if (idev->rs_probes++ < idev->cnf.rtr_solicits || idev->cnf.rtr_solicits < 0) { + rtr_solicits = READ_ONCE(idev->cnf.rtr_solicits); + + if (idev->rs_probes++ < rtr_solicits || rtr_solicits < 0) { write_unlock(&idev->lock); if (!ipv6_get_lladdr(dev, &lladdr, IFA_F_TENTATIVE)) ndisc_send_rs(dev, &lladdr, @@ -4050,11 +4055,12 @@ static void addrconf_rs_timer(struct timer_list *t) write_lock(&idev->lock); idev->rs_interval = rfc3315_s14_backoff_update( - idev->rs_interval, idev->cnf.rtr_solicit_max_interval); + idev->rs_interval, + READ_ONCE(idev->cnf.rtr_solicit_max_interval)); /* The wait after the last probe can be shorter */ addrconf_mod_rs_timer(idev, (idev->rs_probes == - idev->cnf.rtr_solicits) ? - idev->cnf.rtr_solicit_delay : + READ_ONCE(idev->cnf.rtr_solicits)) ? + READ_ONCE(idev->cnf.rtr_solicit_delay) : idev->rs_interval); } else { /* @@ -4075,24 +4081,25 @@ static void addrconf_rs_timer(struct timer_list *t) */ static void addrconf_dad_kick(struct inet6_ifaddr *ifp) { - unsigned long rand_num; struct inet6_dev *idev = ifp->idev; + unsigned long rand_num; u64 nonce; if (ifp->flags & IFA_F_OPTIMISTIC) rand_num = 0; else - rand_num = get_random_u32_below(idev->cnf.rtr_solicit_delay ? : 1); + rand_num = get_random_u32_below( + READ_ONCE(idev->cnf.rtr_solicit_delay) ? : 1); nonce = 0; - if (idev->cnf.enhanced_dad || - dev_net(idev->dev)->ipv6.devconf_all->enhanced_dad) { + if (READ_ONCE(idev->cnf.enhanced_dad) || + READ_ONCE(dev_net(idev->dev)->ipv6.devconf_all->enhanced_dad)) { do get_random_bytes(&nonce, 6); while (nonce == 0); } ifp->dad_nonce = nonce; - ifp->dad_probes = idev->cnf.dad_transmits; + ifp->dad_probes = READ_ONCE(idev->cnf.dad_transmits); addrconf_mod_dad_work(ifp, rand_num); } @@ -4331,7 +4338,7 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id, send_mld = ifp->scope == IFA_LINK && ipv6_lonely_lladdr(ifp); send_rs = send_mld && ipv6_accept_ra(ifp->idev) && - ifp->idev->cnf.rtr_solicits != 0 && + READ_ONCE(ifp->idev->cnf.rtr_solicits) != 0 && (dev->flags & IFF_LOOPBACK) == 0 && (dev->type != ARPHRD_TUNNEL) && !netif_is_team_port(dev); @@ -4366,7 +4373,7 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id, write_lock_bh(&ifp->idev->lock); spin_lock(&ifp->lock); ifp->idev->rs_interval = rfc3315_s14_backoff_init( - ifp->idev->cnf.rtr_solicit_interval); + READ_ONCE(ifp->idev->cnf.rtr_solicit_interval)); ifp->idev->rs_probes = 1; ifp->idev->if_flags |= IF_RS_SENT; addrconf_mod_rs_timer(ifp->idev, ifp->idev->rs_interval); @@ -5914,7 +5921,7 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token, return -EINVAL; } - if (idev->cnf.rtr_solicits == 0) { + if (READ_ONCE(idev->cnf.rtr_solicits) == 0) { NL_SET_ERR_MSG(extack, "Router solicitation is disabled on device"); return -EINVAL; @@ -5947,7 +5954,7 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token, if (update_rs) { idev->if_flags |= IF_RS_SENT; idev->rs_interval = rfc3315_s14_backoff_init( - idev->cnf.rtr_solicit_interval); + READ_ONCE(idev->cnf.rtr_solicit_interval)); idev->rs_probes = 1; addrconf_mod_rs_timer(idev, idev->rs_interval); } diff --git a/net/ipv6/route.c b/net/ipv6/route.c index a92fcac902aea9307e0c83d150e9d1c41435887f..2cecb1c5a58f679abcb368a62ed914a78f2f4b5f 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4150,7 +4150,8 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu in6_dev = __in6_dev_get(skb->dev); if (!in6_dev) return; - if (READ_ONCE(in6_dev->cnf.forwarding) || !in6_dev->cnf.accept_redirects) + if (READ_ONCE(in6_dev->cnf.forwarding) || + !READ_ONCE(in6_dev->cnf.accept_redirects)) return; /* RFC2461 8.1: From patchwork Wed Feb 28 13:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575536 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D4F015958C for ; Wed, 28 Feb 2024 13:55:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128511; cv=none; b=CJ4+FzF6Iqkn02lebiu2CIoE5uj/J8EHskk1DbHz0zZFTlEBoXp80GqI83LwgbGUUdsEyacYt8p+T/DYUHK9aV4M0I6ejiRklaWT2jj1yf3PRXfqR4Vdk3VUD1YJkhpPliN33CIgPAk6bdd7qjka4FknmqHcVDjykpxneT4V+gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128511; c=relaxed/simple; bh=wex18Eq7NzjB+1akAKoSLfJsBpyZ5jQHKDwzdMxTm4I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AtdQI6oTPpeMSeEXqJDZ2ysujnxJyjqMug4rvYO1Ad+zehOM3GCSmVv3RiAV9d0ACuI8ZL26jS/ts1CP6RMdnfL+oc8fDr+LHtzUCdAmlBFQgooVFSx1iA2gEaoZxaySEaKEvJS/IbNCjLmu/Hg767d06Iq/fUfrDR6nePrRJ/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hyMl5jT8; arc=none smtp.client-ip=209.85.222.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hyMl5jT8" Received: by mail-qk1-f202.google.com with SMTP id af79cd13be357-787b8dd3330so146314985a.1 for ; Wed, 28 Feb 2024 05:55:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128508; x=1709733308; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PXZ05q2LpzNbtZmOcIx147FbutypgpZF+mMinxnSZgY=; b=hyMl5jT88CtjNyL1NAjh3UW4P2HuFP7no/MnqIRA3jfA4bTMT2s6EO4h3ZftlCojO0 eJlcW5ti9SlNFMcrj5EOhoc+X5+N85Hn2ph4wvL6+1ycqDGqAea4UFPMv5hDeBYIG6Pp iZVCWs6y/bsjRpS4P2tEQAcgQ0wFIHJIEZxkh1W0gUaRU58Sl4L9tYANKGQWkDodQyjp brL5ilfaDx9QTT53RMgPMqRWSn7zPvAABRHfErKFwWT4NW3ct5m+FTVMC2WmnHG5/3bg VyQIGdkOm7cpLqqrfgprZ+pWkJsDiHOqh5R3M5uF1kIBM7wSV8kPIqg8lC78VW2u8JUG 3vUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128508; x=1709733308; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PXZ05q2LpzNbtZmOcIx147FbutypgpZF+mMinxnSZgY=; b=Ew5Wvhzte3clUsYj0BOj5jkw7tG85KV4wMo9jjFzZCJZIabuBJqWCV6s28ppFyBG3p PvyAPMs8Krtx5g28l3kdFs1ysdoPu/d41gzsG8ATT6qDOYMFQRR8sISbmyXmpUJbD7JM H2IcCgm8qf1DalX7sXtT38xFZiyfsHnuHREZPLPxZF7lMyAXk+v59mTQZKN15ySUjHal GJOTAO4KgjElHZj/EFRZdo2UrXN+cRI0Yx53JX9z7cpu1zZmHbkj7YFBrCT3m8+vYtW1 +rErZ0CJWye7LpST5LimdvWQlXBBN522iXK65bpKseTjWYbx+bHegn5Nf1zRpanLSPiy qFsQ== X-Gm-Message-State: AOJu0YwUXTE+fOMbzPOk8Jn0KnWTC9pVOzNjIozxD6vxfueIH8gZMNRD 1U0VGkUoYSe9jIP2boZrJOreNsinPtGcmSD130y2ovB5JkX+RDZglWhSNjj0gopTWYeQ+QTekO0 JTXYOdMPqbA== X-Google-Smtp-Source: AGHT+IFWA82Fh6l2ztRrXpP1xUeG7qt7tVpmGqYe/drny4h01+4Kt6Cyn/I0fOX9chFTke/jqfa7/yLcSpQAsg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:ae9:f80f:0:b0:787:f1b3:a77 with SMTP id x15-20020ae9f80f000000b00787f1b30a77mr17165qkh.2.1709128508421; Wed, 28 Feb 2024 05:55:08 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:38 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-15-edumazet@google.com> Subject: [PATCH v3 net-next 14/15] ipv6/addrconf: annotate data-races around devconf fields (II) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Final (?) round of this series. Annotate lockless reads on following devconf fields, because they be changed concurrently from /proc/net/ipv6/conf. - accept_dad - optimistic_dad - use_optimistic - use_oif_addrs_only - ra_honor_pio_life - keep_addr_on_down - ndisc_notify - ndisc_evict_nocarrier - suppress_frag_ndisc - addr_gen_mode - seg6_enabled - ioam6_enabled - ioam6_id - ioam6_id_wide - drop_unicast_in_l2_multicast - mldv[12]_unsolicited_report_interval - force_mld_version - force_tllao - accept_untracked_na - drop_unsolicited_na - accept_source_route Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 49 +++++++++++++++++++++++--------------------- net/ipv6/exthdrs.c | 16 ++++++++------- net/ipv6/ioam6.c | 8 ++++---- net/ipv6/ip6_input.c | 2 +- net/ipv6/mcast.c | 14 ++++++------- net/ipv6/ndisc.c | 18 ++++++++-------- net/ipv6/seg6_hmac.c | 8 +++++--- 7 files changed, 61 insertions(+), 54 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index fee5cf69648bc653502df7bfaac7e5c65a43fbf2..b5c627253eb5e30a981dfd23dfc248ea00e3c557 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1557,15 +1557,17 @@ static inline int ipv6_saddr_preferred(int type) return 0; } -static bool ipv6_use_optimistic_addr(struct net *net, - struct inet6_dev *idev) +static bool ipv6_use_optimistic_addr(const struct net *net, + const struct inet6_dev *idev) { #ifdef CONFIG_IPV6_OPTIMISTIC_DAD if (!idev) return false; - if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad) + if (!READ_ONCE(net->ipv6.devconf_all->optimistic_dad) && + !READ_ONCE(idev->cnf.optimistic_dad)) return false; - if (!net->ipv6.devconf_all->use_optimistic && !idev->cnf.use_optimistic) + if (!READ_ONCE(net->ipv6.devconf_all->use_optimistic) && + !READ_ONCE(idev->cnf.use_optimistic)) return false; return true; @@ -1574,13 +1576,14 @@ static bool ipv6_use_optimistic_addr(struct net *net, #endif } -static bool ipv6_allow_optimistic_dad(struct net *net, - struct inet6_dev *idev) +static bool ipv6_allow_optimistic_dad(const struct net *net, + const struct inet6_dev *idev) { #ifdef CONFIG_IPV6_OPTIMISTIC_DAD if (!idev) return false; - if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad) + if (!READ_ONCE(net->ipv6.devconf_all->optimistic_dad) && + !READ_ONCE(idev->cnf.optimistic_dad)) return false; return true; @@ -1862,7 +1865,7 @@ int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev, idev = __in6_dev_get(dst_dev); if ((dst_type & IPV6_ADDR_MULTICAST) || dst.scope <= IPV6_ADDR_SCOPE_LINKLOCAL || - (idev && idev->cnf.use_oif_addrs_only)) { + (idev && READ_ONCE(idev->cnf.use_oif_addrs_only))) { use_oif_addr = true; } } @@ -2683,8 +2686,8 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev, }; #ifdef CONFIG_IPV6_OPTIMISTIC_DAD - if ((net->ipv6.devconf_all->optimistic_dad || - in6_dev->cnf.optimistic_dad) && + if ((READ_ONCE(net->ipv6.devconf_all->optimistic_dad) || + READ_ONCE(in6_dev->cnf.optimistic_dad)) && !net->ipv6.devconf_all->forwarding && sllao) cfg.ifa_flags |= IFA_F_OPTIMISTIC; #endif @@ -2733,7 +2736,7 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev, */ update_lft = !create && stored_lft; - if (update_lft && !in6_dev->cnf.ra_honor_pio_life) { + if (update_lft && !READ_ONCE(in6_dev->cnf.ra_honor_pio_life)) { const u32 minimum_lft = min_t(u32, stored_lft, MIN_VALID_LIFETIME); valid_lft = max(valid_lft, minimum_lft); @@ -3317,8 +3320,8 @@ void addrconf_add_linklocal(struct inet6_dev *idev, struct inet6_ifaddr *ifp; #ifdef CONFIG_IPV6_OPTIMISTIC_DAD - if ((dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad || - idev->cnf.optimistic_dad) && + if ((READ_ONCE(dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad) || + READ_ONCE(idev->cnf.optimistic_dad)) && !dev_net(idev->dev)->ipv6.devconf_all->forwarding) cfg.ifa_flags |= IFA_F_OPTIMISTIC; #endif @@ -3890,10 +3893,10 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) */ if (!unregister && !idev->cnf.disable_ipv6) { /* aggregate the system setting and interface setting */ - int _keep_addr = net->ipv6.devconf_all->keep_addr_on_down; + int _keep_addr = READ_ONCE(net->ipv6.devconf_all->keep_addr_on_down); if (!_keep_addr) - _keep_addr = idev->cnf.keep_addr_on_down; + _keep_addr = READ_ONCE(idev->cnf.keep_addr_on_down); keep_addr = (_keep_addr > 0); } @@ -4119,8 +4122,8 @@ static void addrconf_dad_begin(struct inet6_ifaddr *ifp) net = dev_net(dev); if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || - (net->ipv6.devconf_all->accept_dad < 1 && - idev->cnf.accept_dad < 1) || + (READ_ONCE(net->ipv6.devconf_all->accept_dad) < 1 && + READ_ONCE(idev->cnf.accept_dad) < 1) || !(ifp->flags&IFA_F_TENTATIVE) || ifp->flags & IFA_F_NODAD) { bool send_na = false; @@ -4212,8 +4215,8 @@ static void addrconf_dad_work(struct work_struct *w) action = DAD_ABORT; ifp->state = INET6_IFADDR_STATE_POSTDAD; - if ((dev_net(idev->dev)->ipv6.devconf_all->accept_dad > 1 || - idev->cnf.accept_dad > 1) && + if ((READ_ONCE(dev_net(idev->dev)->ipv6.devconf_all->accept_dad) > 1 || + READ_ONCE(idev->cnf.accept_dad) > 1) && !idev->cnf.disable_ipv6 && !(ifp->flags & IFA_F_STABLE_PRIVACY)) { struct in6_addr addr; @@ -4352,8 +4355,8 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id, /* send unsolicited NA if enabled */ if (send_na && - (ifp->idev->cnf.ndisc_notify || - dev_net(dev)->ipv6.devconf_all->ndisc_notify)) { + (READ_ONCE(ifp->idev->cnf.ndisc_notify) || + READ_ONCE(dev_net(dev)->ipv6.devconf_all->ndisc_notify))) { ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifp->addr, /*router=*/ !!ifp->idev->cnf.forwarding, /*solicited=*/ false, /*override=*/ true, @@ -6540,7 +6543,7 @@ static int addrconf_sysctl_addr_gen_mode(struct ctl_table *ctl, int write, } else if (&net->ipv6.devconf_all->addr_gen_mode == ctl->data) { struct net_device *dev; - net->ipv6.devconf_dflt->addr_gen_mode = new_val; + WRITE_ONCE(net->ipv6.devconf_dflt->addr_gen_mode, new_val); for_each_netdev(net, dev) { idev = __in6_dev_get(dev); if (idev && @@ -6552,7 +6555,7 @@ static int addrconf_sysctl_addr_gen_mode(struct ctl_table *ctl, int write, } } - *((u32 *)ctl->data) = new_val; + WRITE_ONCE(*((u32 *)ctl->data), new_val); } out: diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 727792907d6cb2132d965da4c7cb8447f07b2a68..26f1e4a5ade05175375add7da8da1fde9b204d96 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -379,9 +379,8 @@ static int ipv6_srh_rcv(struct sk_buff *skb) idev = __in6_dev_get(skb->dev); - accept_seg6 = net->ipv6.devconf_all->seg6_enabled; - if (accept_seg6 > idev->cnf.seg6_enabled) - accept_seg6 = idev->cnf.seg6_enabled; + accept_seg6 = min(READ_ONCE(net->ipv6.devconf_all->seg6_enabled), + READ_ONCE(idev->cnf.seg6_enabled)); if (!accept_seg6) { kfree_skb(skb); @@ -655,10 +654,13 @@ static int ipv6_rthdr_rcv(struct sk_buff *skb) struct ipv6_rt_hdr *hdr; struct rt0_hdr *rthdr; struct net *net = dev_net(skb->dev); - int accept_source_route = net->ipv6.devconf_all->accept_source_route; + int accept_source_route; - if (idev && accept_source_route > idev->cnf.accept_source_route) - accept_source_route = idev->cnf.accept_source_route; + accept_source_route = READ_ONCE(net->ipv6.devconf_all->accept_source_route); + + if (idev) + accept_source_route = min(accept_source_route, + READ_ONCE(idev->cnf.accept_source_route)); if (!pskb_may_pull(skb, skb_transport_offset(skb) + 8) || !pskb_may_pull(skb, (skb_transport_offset(skb) + @@ -919,7 +921,7 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) goto drop; /* Ignore if IOAM is not enabled on ingress */ - if (!__in6_dev_get(skb->dev)->cnf.ioam6_enabled) + if (!READ_ONCE(__in6_dev_get(skb->dev)->cnf.ioam6_enabled)) goto ignore; /* Truncated Option header */ diff --git a/net/ipv6/ioam6.c b/net/ipv6/ioam6.c index 5fa923f0663214df4783344e0f790b368a2bf1bf..08c929513065772dca3666c92326a47f2dae0631 100644 --- a/net/ipv6/ioam6.c +++ b/net/ipv6/ioam6.c @@ -727,7 +727,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb, if (!skb->dev) raw16 = IOAM6_U16_UNAVAILABLE; else - raw16 = (__force u16)__in6_dev_get(skb->dev)->cnf.ioam6_id; + raw16 = (__force u16)READ_ONCE(__in6_dev_get(skb->dev)->cnf.ioam6_id); *(__be16 *)data = cpu_to_be16(raw16); data += sizeof(__be16); @@ -735,7 +735,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb, if (skb_dst(skb)->dev->flags & IFF_LOOPBACK) raw16 = IOAM6_U16_UNAVAILABLE; else - raw16 = (__force u16)__in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id; + raw16 = (__force u16)READ_ONCE(__in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id); *(__be16 *)data = cpu_to_be16(raw16); data += sizeof(__be16); @@ -822,7 +822,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb, if (!skb->dev) raw32 = IOAM6_U32_UNAVAILABLE; else - raw32 = __in6_dev_get(skb->dev)->cnf.ioam6_id_wide; + raw32 = READ_ONCE(__in6_dev_get(skb->dev)->cnf.ioam6_id_wide); *(__be32 *)data = cpu_to_be32(raw32); data += sizeof(__be32); @@ -830,7 +830,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb, if (skb_dst(skb)->dev->flags & IFF_LOOPBACK) raw32 = IOAM6_U32_UNAVAILABLE; else - raw32 = __in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id_wide; + raw32 = READ_ONCE(__in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id_wide); *(__be32 *)data = cpu_to_be32(raw32); data += sizeof(__be32); diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index 1ba97933c74fbd12e21f273f0aeda2313bd608b7..133610a49da6b8a2a210ad8faf74015c6bdf7038 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -236,7 +236,7 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, if (!ipv6_addr_is_multicast(&hdr->daddr) && (skb->pkt_type == PACKET_BROADCAST || skb->pkt_type == PACKET_MULTICAST) && - idev->cnf.drop_unicast_in_l2_multicast) { + READ_ONCE(idev->cnf.drop_unicast_in_l2_multicast)) { SKB_DR_SET(reason, UNICAST_IN_L2_MULTICAST); goto err; } diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index 76ee1615ff2a07e1dd496aada377a7feb4703e8c..7ba01d8cfbae839d87e0c85729f7bed9ba328f05 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c @@ -159,9 +159,9 @@ static int unsolicited_report_interval(struct inet6_dev *idev) int iv; if (mld_in_v1_mode(idev)) - iv = idev->cnf.mldv1_unsolicited_report_interval; + iv = READ_ONCE(idev->cnf.mldv1_unsolicited_report_interval); else - iv = idev->cnf.mldv2_unsolicited_report_interval; + iv = READ_ONCE(idev->cnf.mldv2_unsolicited_report_interval); return iv > 0 ? iv : 1; } @@ -1202,15 +1202,15 @@ static bool mld_marksources(struct ifmcaddr6 *pmc, int nsrcs, static int mld_force_mld_version(const struct inet6_dev *idev) { + const struct net *net = dev_net(idev->dev); + int all_force; + + all_force = READ_ONCE(net->ipv6.devconf_all->force_mld_version); /* Normally, both are 0 here. If enforcement to a particular is * being used, individual device enforcement will have a lower * precedence over 'all' device (.../conf/all/force_mld_version). */ - - if (dev_net(idev->dev)->ipv6.devconf_all->force_mld_version != 0) - return dev_net(idev->dev)->ipv6.devconf_all->force_mld_version; - else - return idev->cnf.force_mld_version; + return all_force ?: READ_ONCE(idev->cnf.force_mld_version); } static bool mld_in_v2_mode_only(const struct inet6_dev *idev) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 4114918f12c88f2b74e53d6d726018994feaf213..ae134634c323cab27c03328015b24ae397f97cfc 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -451,7 +451,7 @@ static void ip6_nd_hdr(struct sk_buff *skb, rcu_read_lock(); idev = __in6_dev_get(skb->dev); - tclass = idev ? idev->cnf.ndisc_tclass : 0; + tclass = idev ? READ_ONCE(idev->cnf.ndisc_tclass) : 0; rcu_read_unlock(); skb_push(skb, sizeof(*hdr)); @@ -535,7 +535,7 @@ void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr, src_addr = solicited_addr; if (ifp->flags & IFA_F_OPTIMISTIC) override = false; - inc_opt |= ifp->idev->cnf.force_tllao; + inc_opt |= READ_ONCE(ifp->idev->cnf.force_tllao); in6_ifa_put(ifp); } else { if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr, @@ -974,7 +974,7 @@ static int accept_untracked_na(struct net_device *dev, struct in6_addr *saddr) { struct inet6_dev *idev = __in6_dev_get(dev); - switch (idev->cnf.accept_untracked_na) { + switch (READ_ONCE(idev->cnf.accept_untracked_na)) { case 0: /* Don't accept untracked na (absent in neighbor cache) */ return 0; case 1: /* Create new entries from na if currently untracked */ @@ -1025,7 +1025,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) * drop_unsolicited_na takes precedence over accept_untracked_na */ if (!msg->icmph.icmp6_solicited && idev && - idev->cnf.drop_unsolicited_na) + READ_ONCE(idev->cnf.drop_unsolicited_na)) return reason; if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts)) @@ -1818,7 +1818,7 @@ static bool ndisc_suppress_frag_ndisc(struct sk_buff *skb) if (!idev) return true; if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED && - idev->cnf.suppress_frag_ndisc) { + READ_ONCE(idev->cnf.suppress_frag_ndisc)) { net_warn_ratelimited("Received fragmented ndisc packet. Carefully consider disabling suppress_frag_ndisc.\n"); return true; } @@ -1895,8 +1895,8 @@ static int ndisc_netdev_event(struct notifier_block *this, unsigned long event, idev = in6_dev_get(dev); if (!idev) break; - if (idev->cnf.ndisc_notify || - net->ipv6.devconf_all->ndisc_notify) + if (READ_ONCE(idev->cnf.ndisc_notify) || + READ_ONCE(net->ipv6.devconf_all->ndisc_notify)) ndisc_send_unsol_na(dev); in6_dev_put(idev); break; @@ -1905,8 +1905,8 @@ static int ndisc_netdev_event(struct notifier_block *this, unsigned long event, if (!idev) evict_nocarrier = true; else { - evict_nocarrier = idev->cnf.ndisc_evict_nocarrier && - net->ipv6.devconf_all->ndisc_evict_nocarrier; + evict_nocarrier = READ_ONCE(idev->cnf.ndisc_evict_nocarrier) && + READ_ONCE(net->ipv6.devconf_all->ndisc_evict_nocarrier); in6_dev_put(idev); } diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c index d43c50a7310d64e3af88657286a431057e9577bd..861e0366f549d523f20dc92c79bef1be8805e0c7 100644 --- a/net/ipv6/seg6_hmac.c +++ b/net/ipv6/seg6_hmac.c @@ -241,6 +241,7 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb) struct sr6_tlv_hmac *tlv; struct ipv6_sr_hdr *srh; struct inet6_dev *idev; + int require_hmac; idev = __in6_dev_get(skb->dev); @@ -248,16 +249,17 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb) tlv = seg6_get_tlv_hmac(srh); + require_hmac = READ_ONCE(idev->cnf.seg6_require_hmac); /* mandatory check but no tlv */ - if (idev->cnf.seg6_require_hmac > 0 && !tlv) + if (require_hmac > 0 && !tlv) return false; /* no check */ - if (idev->cnf.seg6_require_hmac < 0) + if (require_hmac < 0) return true; /* check only if present */ - if (idev->cnf.seg6_require_hmac == 0 && !tlv) + if (require_hmac == 0 && !tlv) return true; /* now, seg6_require_hmac >= 0 && tlv */ From patchwork Wed Feb 28 13:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13575537 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 029B6155A39 for ; Wed, 28 Feb 2024 13:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128512; cv=none; b=bA8l4cgBlBJiY+3IRbBZSzpbe9ZVaUCpExpQ2cMXNB/IqTrpxr8AZ8LXag3x7mMjXB30TYxgyScVwIHYIU8kGs0cFhSYbLcwLMd4G5B8yljVNPQPVrDkkpd2EbWuKJRRqUckACOk1heBP9dV6nEXl5D+pi3aFAQxdykZq1onUqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128512; c=relaxed/simple; bh=/Gk9VZIjSsQKrSNUHcR3haP/H4xsuiieqfVxguNqxnQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fWZnaTGMVgDLM3a6NL6aBPXqnwIjnLab2PDaaRQT6/OEvCIo26Q5pZdSaBM7g66qr/ImZ++7g9KETTYfmCT0P8FvOQgCcdRtzUca3ho2fPOx+HAHaSIyWqDTI7MQp57ngVtSIDVg+IVaueYQygEku/ZzeMNE5dtvFzJuPWGWBIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aqWffDuu; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aqWffDuu" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dce775fa8adso10561349276.1 for ; Wed, 28 Feb 2024 05:55:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709128510; x=1709733310; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Vqh87Fliy9ASVVOzwtH1bbNaiQsOHJXdPBTviCF3k04=; b=aqWffDuujKz0K+xrHy4J7Mir9pPIiqrTap1SbJbnRsEJT9Z2PZgF17CE26TNPdlrmz UsSFYrlmBCrjIz6zNsY/BUtceogBxDut+uQnLROnQxaP/lg8JNXGST5M/ujeVKpstq5w Oy7UTQCXgs9IsLUDo9tRUaCQVyogTvpQz5szl0Ra+9H2mGY/ag8FI5XCvOpy7WmoLSLG eETOdeUT8UipLuh+tUZL91JFm3YtEtMpxS+k08QQ8FSlUa83idss4bRAMWLrk/ooZq/a ZYsYKplXgzNAwUc5PwqqaM9/hyzR7RPFlsGRhLVtpjSYVtoMAxyZN9PTduuOlx6KPcBF GT/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128510; x=1709733310; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Vqh87Fliy9ASVVOzwtH1bbNaiQsOHJXdPBTviCF3k04=; b=dVupQHuQoRpq55sX//vWjLKNk1Na6Ahp/pwF3ep9B0jqYHQF3W+E6pUPI4Z+ADrVfU 0ZO0wsiqAJsIicgGg05NcMOKLz9Bb0ZU8JUBZEmaN+dS8s6nIWedr4rem7AHjQUCGSky 7GswJYxXrXsO1oz2bMY7fP/Hc5Es12H57DtVz47r0vX8Yi++TmE56QwhBXfPmL6rVFtT zB+79f0mgqtZDp6jZkxYAhGZocTgSNx/GLASBSM52mSh1oU7nPtLMHLkqT8NyXnO5zt5 GE69AILqj4EvyRAh0mK0VniHwSJahCKgICxZrk3X9HJ1KwzbOM0n4kSW3vg/hU12akwE wnZQ== X-Gm-Message-State: AOJu0Yy6TJGA0pwVYszn2prdHsfKhSqtjdGhhKkv71izmyi+Vr1af4rf 4aI41dlm8C6KbpyPjSFceWEEWFalzYLToA8TxEJkOCnJvlfnv/PvDIEzmq1GQBSVlDlhwD74zLr TbDcZiRPsAQ== X-Google-Smtp-Source: AGHT+IEXJpwgs/2LknYSl16kVEH4AeYmICJxdShv2dHBWa0ohdCWDvmJgYLW09sYle/8oZQPFfvy7W9UEJOd+Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:814f:0:b0:dc6:cafd:dce5 with SMTP id j15-20020a25814f000000b00dc6cafddce5mr709251ybm.12.1709128510015; Wed, 28 Feb 2024 05:55:10 -0800 (PST) Date: Wed, 28 Feb 2024 13:54:39 +0000 In-Reply-To: <20240228135439.863861-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228135439.863861-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228135439.863861-16-edumazet@google.com> Subject: [PATCH v3 net-next 15/15] ipv6: use xa_array iterator to implement inet6_netconf_dump_devconf() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Jiri Pirko , David Ahern , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org 1) inet6_netconf_dump_devconf() can run under RCU protection instead of RTNL. 2) properly return 0 at the end of a dump, avoiding an an extra recvmsg() system call. 3) Do not use inet6_base_seq() anymore, for_each_netdev_dump() has nice properties. Restarting a GETDEVCONF dump if a device has been added/removed or if net->ipv6.dev_addr_genid has changed is moot. Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko --- net/ipv6/addrconf.c | 102 +++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 58 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index b5c627253eb5e30a981dfd23dfc248ea00e3c557..de7b6b5922fe37a557a89a403425fb427710bad9 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -727,17 +727,18 @@ static u32 inet6_base_seq(const struct net *net) return res; } - static int inet6_netconf_dump_devconf(struct sk_buff *skb, struct netlink_callback *cb) { const struct nlmsghdr *nlh = cb->nlh; struct net *net = sock_net(skb->sk); - int h, s_h; - int idx, s_idx; + struct { + unsigned long ifindex; + unsigned int all_default; + } *ctx = (void *)cb->ctx; struct net_device *dev; struct inet6_dev *idev; - struct hlist_head *head; + int err = 0; if (cb->strict_check) { struct netlink_ext_ack *extack = cb->extack; @@ -754,64 +755,48 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb, } } - s_h = cb->args[0]; - s_idx = idx = cb->args[1]; - - for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { - idx = 0; - head = &net->dev_index_head[h]; - rcu_read_lock(); - cb->seq = inet6_base_seq(net); - hlist_for_each_entry_rcu(dev, head, index_hlist) { - if (idx < s_idx) - goto cont; - idev = __in6_dev_get(dev); - if (!idev) - goto cont; - - if (inet6_netconf_fill_devconf(skb, dev->ifindex, - &idev->cnf, - NETLINK_CB(cb->skb).portid, - nlh->nlmsg_seq, - RTM_NEWNETCONF, - NLM_F_MULTI, - NETCONFA_ALL) < 0) { - rcu_read_unlock(); - goto done; - } - nl_dump_check_consistent(cb, nlmsg_hdr(skb)); -cont: - idx++; - } - rcu_read_unlock(); + rcu_read_lock(); + for_each_netdev_dump(net, dev, ctx->ifindex) { + idev = __in6_dev_get(dev); + if (!idev) + continue; + err = inet6_netconf_fill_devconf(skb, dev->ifindex, + &idev->cnf, + NETLINK_CB(cb->skb).portid, + nlh->nlmsg_seq, + RTM_NEWNETCONF, + NLM_F_MULTI, + NETCONFA_ALL); + if (err < 0) + goto done; } - if (h == NETDEV_HASHENTRIES) { - if (inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_ALL, - net->ipv6.devconf_all, - NETLINK_CB(cb->skb).portid, - nlh->nlmsg_seq, - RTM_NEWNETCONF, NLM_F_MULTI, - NETCONFA_ALL) < 0) + if (ctx->all_default == 0) { + err = inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_ALL, + net->ipv6.devconf_all, + NETLINK_CB(cb->skb).portid, + nlh->nlmsg_seq, + RTM_NEWNETCONF, NLM_F_MULTI, + NETCONFA_ALL); + if (err < 0) goto done; - else - h++; - } - if (h == NETDEV_HASHENTRIES + 1) { - if (inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_DEFAULT, - net->ipv6.devconf_dflt, - NETLINK_CB(cb->skb).portid, - nlh->nlmsg_seq, - RTM_NEWNETCONF, NLM_F_MULTI, - NETCONFA_ALL) < 0) + ctx->all_default++; + } + if (ctx->all_default == 1) { + err = inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_DEFAULT, + net->ipv6.devconf_dflt, + NETLINK_CB(cb->skb).portid, + nlh->nlmsg_seq, + RTM_NEWNETCONF, NLM_F_MULTI, + NETCONFA_ALL); + if (err < 0) goto done; - else - h++; + ctx->all_default++; } done: - cb->args[0] = h; - cb->args[1] = idx; - - return skb->len; + if (err < 0 && likely(skb->len)) + err = skb->len; + rcu_read_unlock(); + return err; } #ifdef CONFIG_SYSCTL @@ -7502,7 +7487,8 @@ int __init addrconf_init(void) err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETNETCONF, inet6_netconf_get_devconf, inet6_netconf_dump_devconf, - RTNL_FLAG_DOIT_UNLOCKED); + RTNL_FLAG_DOIT_UNLOCKED | + RTNL_FLAG_DUMP_UNLOCKED); if (err < 0) goto errout; err = ipv6_addr_label_rtnl_register();