From patchwork Sun Dec 15 17:56: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: 13908840 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 53A521B21B2 for ; Sun, 15 Dec 2024 17:56:52 +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=1734285413; cv=none; b=tmzcEQVjI/AVBlGcqxRg6t6ple8c32G21CjBevtZnvVfsgzja2totV/bR8ptbLN04iN1QVORMDs2KMJZX+5SBIXu7Vb4XJBaiS7ZKonv94n+sfIgTtAzQgvZFc+AwnLCrfwIyQ5h9XhsNAWQbiqO/MygcaPVR0dnpymT9FYxqEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734285413; c=relaxed/simple; bh=s3MI24GtlqQdp5wNS4PFx7F9BjHZqq3Vm25eZ/KSfcA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YIjRgxLu6BHbP9BDR3qFSPyzok4t4qtUvn9tnLee7fCEDZZVI2n86wCXqhk2dwf8A3YA+cUNYG6+e4x2ZkNpcl5fh604GZnZ4Z96lDAwSaiwpt8gPkRvd1xqi13GxsTZeQMeSdfM/LHUMNgKMBPNt+XchIxtXuZFP33fliyvNVk= 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=XFUA07IK; 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="XFUA07IK" Received: by mail-qk1-f202.google.com with SMTP id af79cd13be357-7b6eeef7cb8so492884385a.2 for ; Sun, 15 Dec 2024 09:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734285411; x=1734890211; 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=gxiE9o12jvQE0EhYg4DBIO0tfvhpWtc9/ACQybVd+3k=; b=XFUA07IK2+wOLixTZJ8H4Y9ez4bRlwkLBPEVTM7GppB/bAtMPv2jGmTZ0BDd9MYBwD yXZV37boyb5ZAx4ig1xNIA/FjOir5Cb/T24erZtvrGTXXwkEzGOd8CVqxmHEgcFK3xfY 8dKFIbV3bJN/p/MepDRlGdkRZ3mHO22qs6M/OmceIFAxSjQEGoLhHYsZdqqOFRFDWtsh q5Zyt7u0r2YJm9DraD/CcPpMzfR7IjkVJWTTb0Ubg8pyxc77KcuqJenRiKcL7jOJUqgr 78seuaJB1/1z1p03YxKlfm5WaZ4v5KC/uS73d6I9HA7Vsxxk/MX5lhWGR7ViR049dMeF qr8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734285411; x=1734890211; 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=gxiE9o12jvQE0EhYg4DBIO0tfvhpWtc9/ACQybVd+3k=; b=kXv2JupWIVdf06c2wvJgEOfigSd8AsqUpRerVWDsxE+b5YSNJzX21f2pPobl2lxxfG SlSymFDnO8BVLAurUe6JblqtQDXtu/IvrhuoAPP2/lwxgJFkZZZAS1PMVVsLU7RHkSyp QHs2S0C0DcEgQbAWscc1ntQJbQkLxGLQWHkKB51ZPSBI5XU7GY56IbBl9cR4408GLsQw c/MDKrIiE2uG/TK/0BpDuYIh7//c6nn61aLHyv5N+SWfIyqd55aV0i3R1NRQ7kOkLLi+ 6AVAOpGazPd9DSUIxkS6fogiIpp63uA4+3zALLNEqtOOr1fGcqCoo2ZiufLqoXaMbi7o lClw== X-Gm-Message-State: AOJu0YweWti71QazCsVgW7hwGjNbbV5LmqKQ3ZyjElCCvSrVxNmd2Kxw ajilVUTyOzymtbo5c+S1pDcqpNWNy7CmTRLZn9e9mg7HqLvR8VxKJBvb/TrCHsrXMAhKgbsRWXK 93gJhiFdYNg== X-Google-Smtp-Source: AGHT+IH8RcAQn8pr7p0s9VXd24/kph3Gysl7EVJ+ms7UxXw7uZhiCXDJKWVjGpxhefJ0imahysqINKqpnFckZQ== X-Received: from qknvr28.prod.google.com ([2002:a05:620a:55bc:b0:7b6:e98e:956e]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:2b90:b0:7b1:b216:e2fb with SMTP id af79cd13be357-7b6fbed9d38mr1441418385a.20.1734285411315; Sun, 15 Dec 2024 09:56:51 -0800 (PST) Date: Sun, 15 Dec 2024 17:56:26 +0000 In-Reply-To: <20241215175629.1248773-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241215175629.1248773-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241215175629.1248773-2-edumazet@google.com> Subject: [PATCH v2 net-next 1/4] inetpeer: remove create argument of inet_getpeer_v[46]() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Ido Schimmel , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org All callers of inet_getpeer_v4() and inet_getpeer_v6() want to create an inetpeer. Signed-off-by: Eric Dumazet --- include/net/inetpeer.h | 9 ++++----- net/ipv4/icmp.c | 2 +- net/ipv4/ip_fragment.c | 2 +- net/ipv4/route.c | 4 ++-- net/ipv6/icmp.c | 2 +- net/ipv6/ip6_output.c | 2 +- net/ipv6/ndisc.c | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h index 74ff688568a0c6559946a9ae763d5c9822f1d112..6f51f81d6cb19c623e9b347dbdbbd8d849848f6e 100644 --- a/include/net/inetpeer.h +++ b/include/net/inetpeer.h @@ -101,25 +101,24 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base, __be32 v4daddr, - int vif, int create) + int vif) { struct inetpeer_addr daddr; daddr.a4.addr = v4daddr; daddr.a4.vif = vif; daddr.family = AF_INET; - return inet_getpeer(base, &daddr, create); + return inet_getpeer(base, &daddr, 1); } static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, - const struct in6_addr *v6daddr, - int create) + const struct in6_addr *v6daddr) { struct inetpeer_addr daddr; daddr.a6 = *v6daddr; daddr.family = AF_INET6; - return inet_getpeer(base, &daddr, create); + return inet_getpeer(base, &daddr, 1); } static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a, diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 963a89ae9c26e8b462de57e4af981c6c46061052..5eeb9f569a706cf2766d74bcf1a667c8930804f2 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -322,7 +322,7 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt, goto out; vif = l3mdev_master_ifindex(dst->dev); - peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif, 1); + peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif); rc = inet_peer_xrlim_allow(peer, READ_ONCE(net->ipv4.sysctl_icmp_ratelimit)); if (peer) diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 07036a2943c19f13f2d6d1d77cb8123867575b50..46e1171299f22ccf0b201eabbff5d3279a0703d8 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -89,7 +89,7 @@ static void ip4_frag_init(struct inet_frag_queue *q, const void *a) q->key.v4 = *key; qp->ecn = 0; qp->peer = q->fqdir->max_dist ? - inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif, 1) : + inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif) : NULL; } diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 0fbec350961862f76b7eab332539472fed5a5286..297a9939c6e74beffc592dbdd7266281fe842440 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -873,7 +873,7 @@ void ip_rt_send_redirect(struct sk_buff *skb) rcu_read_unlock(); net = dev_net(rt->dst.dev); - peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif, 1); + peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif); if (!peer) { icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, rt_nexthop(rt, ip_hdr(skb)->daddr)); @@ -976,7 +976,7 @@ static int ip_error(struct sk_buff *skb) } peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, - l3mdev_master_ifindex(skb->dev), 1); + l3mdev_master_ifindex(skb->dev)); send = true; if (peer) { diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index 071b0bc1179d81b18c340ce415cef21e02a30cd7..4593e3992c67b84e3a10f30be28762974094d21f 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -222,7 +222,7 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type, if (rt->rt6i_dst.plen < 128) tmo >>= ((128 - rt->rt6i_dst.plen)>>5); - peer = inet_getpeer_v6(net->ipv6.peers, &fl6->daddr, 1); + peer = inet_getpeer_v6(net->ipv6.peers, &fl6->daddr); res = inet_peer_xrlim_allow(peer, tmo); if (peer) inet_putpeer(peer); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 3d672dea9f56284e7a8ebabec037e04e7f3d19f4..2cbcfe70654b5cd90c433a24c47ef5496c604d0d 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -613,7 +613,7 @@ int ip6_forward(struct sk_buff *skb) else target = &hdr->daddr; - peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr, 1); + peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr); /* Limit redirects both by destination (here) and by source (inside ndisc_send_redirect) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index aba94a34867379000e958538d880799c2d0c1476..f113554d13325453cd04ce4e5686d837943e96ff 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1731,7 +1731,7 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) "Redirect: destination is not a neighbour\n"); goto release; } - peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr, 1); + peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr); ret = inet_peer_xrlim_allow(peer, 1*HZ); if (peer) inet_putpeer(peer); From patchwork Sun Dec 15 17:56: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: 13908841 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) (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 E81271B21B2 for ; Sun, 15 Dec 2024 17:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734285424; cv=none; b=E15fxEKROSRr4N4YpRxrz1Ar1VzjSoYh1ivQVbRWrXu6MXSEorXl6vo9ubUPodprnbf4Ernce47blAer4kbpCZ+iXlO/+Ytq7BDuEyUbo+TMhG7NTTnZfyg69oxVEFLUU9Gjs3nXAcAVpYQJje+cF6WlJfSuet4q6nDIqNoP9pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734285424; c=relaxed/simple; bh=pmqBsVm+O9GOOzNqGM5gtbpQ4PVSkgWEKTdLjwIHpKM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fM3J3MbRFnlhwu1PQqcr41ll0bwO0OOW157a8ro1NGvLaD6SB+kffnt6pLHkdAFLrVmM2plwj0M2e4FvMikmZ2G/bJgWTpji23oACUL1pcXZDiKfuajQ0IDTGSSaDKtS4l1uneUx3lSgl6gbr3kqAagD6e2OtAX9MvLNxbG2mwg= 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=M9vXtcNV; arc=none smtp.client-ip=209.85.219.74 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="M9vXtcNV" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6d8f6903d2eso64736356d6.2 for ; Sun, 15 Dec 2024 09:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734285422; x=1734890222; 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=UxJLlGxqCWp+SEOeXAQR+oASm+S2l6LuvafwIt/Iv1o=; b=M9vXtcNVP74cD9phR5jWZFiUKkdq3Z9urCMGJYAJtzNUtIVV5Ckn+NrWJj+5IlQa7d OGYGE4M5TzWvCa8dJkkkA+tzh0LpQ4c5u40SeUQrNfJ8B3spxLEgdwPW/FTM+5zjCWOB 7UYnL3EpWVR7zPMDfE2AuRVyI+XQfxUhmp31IbHlY34/vGE5/yN5cUJuiooP1+FYPiHI eH5S81nP1YKIJn3DLzdpBH3UC8jj/j4ICNF7rBivMiPzg0fq8a/eVxjRH2r/MrHj7kzu R0PxJYLmldF5GgI5PF9Jwr3NA26UrXq443CijFY39htyLlDmlIXRW4DBf+JpAxru0qt0 36cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734285422; x=1734890222; 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=UxJLlGxqCWp+SEOeXAQR+oASm+S2l6LuvafwIt/Iv1o=; b=AD4eS3myd4R9QUHkPnd0IS6Tn0g+IJd+toOZijEkByuSdpIPxzV2w8/wkjs15J3N0M bpn4NBkJJlvyck1JPlIBqa6jvOlNZk6oMiahm67xTQ2J9bA+oDenatObrvN//3RDVOpX WeNm4c0KpLS3N5WfV0Gx/ifPYxZ3CfjLywJ+kaMuaR8/5IncbHiBKOjB5mdWFYpaDgUB dBRnvG1TYDQ+UkNjvBmIMlUVzYPdc+gUJo2n2QGp/3D4UOwlGBChbB0/fnoXrBybKrf9 l1GbepsQ0t+WgUEH+nGS1tG6yWxZ4XQZMPlkH1i4Gra1eZAZLLR06NuykRqQEZaMoisK qZww== X-Gm-Message-State: AOJu0YzI6DYZvANDJWpVskSq+ODwBaF+Ivt3Vb2eCccJGCXn6TdbkGpB w5AsuQrncqiR5WHZr9IvoCdCtHN4QvMIDP9u+Pts+ZevsqYHN7V8Ig9uER5g5nY1lUM7ytzKVlC Si5twMwVMmA== X-Google-Smtp-Source: AGHT+IHHs+SXnVWThAcArGS3fGtqtgB/nfKuMly2cpvUOhCG7IIj3q1nRjl3pYyztcF+I8ZPiddmxuliMoHAgw== X-Received: from qvbdl8.prod.google.com ([2002:ad4:4e08:0:b0:6d8:7cd6:a134]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:5086:b0:6d3:f1ff:f8d6 with SMTP id 6a1803df08f44-6dc96848901mr165230346d6.40.1734285421842; Sun, 15 Dec 2024 09:57:01 -0800 (PST) Date: Sun, 15 Dec 2024 17:56:27 +0000 In-Reply-To: <20241215175629.1248773-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241215175629.1248773-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241215175629.1248773-3-edumazet@google.com> Subject: [PATCH v2 net-next 2/4] inetpeer: remove create argument of inet_getpeer() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Ido Schimmel , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org All callers of inet_getpeer() want to create an inetpeer. Signed-off-by: Eric Dumazet --- include/net/inetpeer.h | 7 +++---- net/ipv4/inetpeer.c | 11 ++--------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h index 6f51f81d6cb19c623e9b347dbdbbd8d849848f6e..f475757daafba998a10c815d0178c98d2bf1ae43 100644 --- a/include/net/inetpeer.h +++ b/include/net/inetpeer.h @@ -96,8 +96,7 @@ static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr) /* can be called with or without local BH being disabled */ struct inet_peer *inet_getpeer(struct inet_peer_base *base, - const struct inetpeer_addr *daddr, - int create); + const struct inetpeer_addr *daddr); static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base, __be32 v4daddr, @@ -108,7 +107,7 @@ static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base, daddr.a4.addr = v4daddr; daddr.a4.vif = vif; daddr.family = AF_INET; - return inet_getpeer(base, &daddr, 1); + return inet_getpeer(base, &daddr); } static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, @@ -118,7 +117,7 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, daddr.a6 = *v6daddr; daddr.family = AF_INET6; - return inet_getpeer(base, &daddr, 1); + return inet_getpeer(base, &daddr); } static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a, diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 5ab56f4cb529769d4edb07261c08d61ff96f0c0f..bc79cc9d13ebb4691660f51babbc748900b8f6db 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -169,13 +169,11 @@ static void inet_peer_gc(struct inet_peer_base *base, } struct inet_peer *inet_getpeer(struct inet_peer_base *base, - const struct inetpeer_addr *daddr, - int create) + const struct inetpeer_addr *daddr) { struct inet_peer *p, *gc_stack[PEER_MAX_GC]; struct rb_node **pp, *parent; unsigned int gc_cnt, seq; - int invalidated; /* Attempt a lockless lookup first. * Because of a concurrent writer, we might not find an existing entry. @@ -183,16 +181,11 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, rcu_read_lock(); seq = read_seqbegin(&base->lock); p = lookup(daddr, base, seq, NULL, &gc_cnt, &parent, &pp); - invalidated = read_seqretry(&base->lock, seq); rcu_read_unlock(); if (p) return p; - /* If no writer did a change during our lookup, we can return early. */ - if (!create && !invalidated) - return NULL; - /* retry an exact lookup, taking the lock before. * At least, nodes should be hot in our cache. */ @@ -201,7 +194,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, gc_cnt = 0; p = lookup(daddr, base, seq, gc_stack, &gc_cnt, &parent, &pp); - if (!p && create) { + if (!p) { p = kmem_cache_alloc(peer_cachep, GFP_ATOMIC); if (p) { p->daddr = *daddr; From patchwork Sun Dec 15 17:56: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: 13908842 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.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 5533C1B395D for ; Sun, 15 Dec 2024 17:57:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734285425; cv=none; b=Jz4T3OrLGhXY/f65jurTSCnntr4GonJbfhQDzr77GqWdQfuXY/7+44TP39N35Joa+wipKc+I/WDzMXtEoe1f5zsZKxuMkTbKjMFKFSGRtl2X7ZbmVZJV1OmwGLGlJHbHqnS20UOrQzDgnRpmjRT0c6bmbN+JktX0TuNz+dMFU1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734285425; c=relaxed/simple; bh=xMhOhgfx9iC1wqcSP9QSIgaVGRXV5Imtz4jU5vk/ndY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sCMehvYK9Hin6jPY50fHuzauKwmLJAGvV61x6vnWqQ03JYk5YmCn7MiIg8CzDXD6/ktECgDDiubwT4dcSfk5WQ0YAFy5CPMNyYz/vBcwEoPQuKPUi7mIs5ANqcfuVFGiRTc7YsL//hUxPcvsyBhEo4Iv6I9ElQ15K9H7hOCH3cg= 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=K5FB3jxO; arc=none smtp.client-ip=209.85.222.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="K5FB3jxO" Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-7b35758d690so623206285a.1 for ; Sun, 15 Dec 2024 09:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734285423; x=1734890223; 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=hhdvF0J0cV225/R+s8FXsA7IsRr6ZvjPGG6itEHAJk0=; b=K5FB3jxO/t7v02vyO9Fh72h9dSh+9Wogmux2v2c0Y44yLmeDN9Yb27tpa7FLptG/aK GH7AS0IxbUSQ4JlEUJogOO8ED1SN8ae0P2zQPBfEfAHcg3srFMn3OgAKMj/0G/bqk+/S 9FZhErtkAvHe1b4RoGGNhlbi6LYdvevY6p9zRC47UYsgsQ94//Li5cN0v5ozDjkkIHje MtnFeXXM6sj5Y40pX+BX1ldxMX0QotNH1K2+52jbKXd0y83MTG0y9BuPgJ7xzWcoD3OE N4GHoW/rAGI6rWJcMjBl63wffAni4hmB9qjD+SGptAm+5Y9zQNXSfaL6QdnBPSLDuJIE oAzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734285423; x=1734890223; 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=hhdvF0J0cV225/R+s8FXsA7IsRr6ZvjPGG6itEHAJk0=; b=HfvweVj7w09TMLkLOJHFzxHARL25gxjo6uEhR5tNLcUDmiDPnTdub0btTZ+xVUZQkl PD5J4hNyrJhpm7m7IkP4HUnKZjlkBxaqrBRJaMzF50h/1zxdoVI3MxmlqkGc8bvWf8yc vIdhJ13S+4M1PQ8GYV4FyBtYkSrl3JlxSFnqQvxvU7kFOQIX8c/rqxQGhMCHuuWThJMZ o49XhJzfHZbTWsB0i2rEZZHKhViA0sd0XBOk0ir3RSY9qzikY4mmBJ7ACziCBLTsYIuQ WKMTH5IgCtq2VNwxWIGyllv4NCAiqpH9S5aTJI2EDPPuhlOjmCmNaH1mt4CSm3QP9neT 1URg== X-Gm-Message-State: AOJu0YygZMeGJjizgP8KXjSE875ZOPpqCEpJVh7CAdb9iOlGYjRohS8Z QZt0GaxH61vTSriKOx8fh73AHgBC8OoDP7ocWVzl5zC2JPpCVg9MQWZXd1BTgPw2xcm5W/+cQtg 5tentWH5h0g== X-Google-Smtp-Source: AGHT+IFCEtJi1acsdkMP6HvSdiF2ahIRKFnhYDPlsGbqzrhCliAZKDVmgz2UPYzD2z28L9UHIpdGIIO3sSIx9A== X-Received: from qtbfz20.prod.google.com ([2002:a05:622a:5a94:b0:463:5373:b17c]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:4408:b0:7b6:dd9c:fac1 with SMTP id af79cd13be357-7b6fbf3d9eemr1384086285a.49.1734285423298; Sun, 15 Dec 2024 09:57:03 -0800 (PST) Date: Sun, 15 Dec 2024 17:56:28 +0000 In-Reply-To: <20241215175629.1248773-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241215175629.1248773-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241215175629.1248773-4-edumazet@google.com> Subject: [PATCH v2 net-next 3/4] inetpeer: update inetpeer timestamp in inet_getpeer() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Ido Schimmel , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org inet_putpeer() will be removed in the following patch, because we will no longer use refcounts. Update inetpeer timestamp (p->dtime) at lookup time. Signed-off-by: Eric Dumazet --- net/ipv4/inetpeer.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index bc79cc9d13ebb4691660f51babbc748900b8f6db..28c3ae5bc4a0b62030bd190dbe5284632ea23efd 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -95,6 +95,7 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, { struct rb_node **pp, *parent, *next; struct inet_peer *p; + u32 now; pp = &base->rb_root.rb_node; parent = NULL; @@ -110,6 +111,9 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, if (cmp == 0) { if (!refcount_inc_not_zero(&p->refcnt)) break; + now = jiffies; + if (READ_ONCE(p->dtime) != now) + WRITE_ONCE(p->dtime, now); return p; } if (gc_stack) { @@ -150,9 +154,6 @@ static void inet_peer_gc(struct inet_peer_base *base, for (i = 0; i < gc_cnt; i++) { p = gc_stack[i]; - /* The READ_ONCE() pairs with the WRITE_ONCE() - * in inet_putpeer() - */ delta = (__u32)jiffies - READ_ONCE(p->dtime); if (delta < ttl || !refcount_dec_if_one(&p->refcnt)) @@ -224,11 +225,6 @@ EXPORT_SYMBOL_GPL(inet_getpeer); void inet_putpeer(struct inet_peer *p) { - /* The WRITE_ONCE() pairs with itself (we run lockless) - * and the READ_ONCE() in inet_peer_gc() - */ - WRITE_ONCE(p->dtime, (__u32)jiffies); - if (refcount_dec_and_test(&p->refcnt)) kfree_rcu(p, rcu); } From patchwork Sun Dec 15 17:56: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: 13908843 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.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 BC9B91B4F09 for ; Sun, 15 Dec 2024 17:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734285427; cv=none; b=dZ/TYI6sWC/561zfLSJIuYVZfVY0lwKgARyjfG6M8fur9VSTX5JKL7H41NvNu42fHPQcom/r0MjWsHznfIsAf63XsoHvtdAqrvU6qqpiQxh2AqVc4rkOFUVSiZSXATI/jTd5MRPGrHyYtYD90mEDmH9OFDlK9MPb30YXfyzJbu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734285427; c=relaxed/simple; bh=7mjwQABpKOUYqcqafn/+erxwARheuqP6yAYNqGU34p8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qyEMp5u+aMfmqcNHBCO4ijVmin67OrQmQdokwp8Rdz8BHLj+ZEx/kT9uAQJzATgYfxtsaUjFFexxY+MtLkgunDVlKjS44EqL3B064Br9lm0TKWktJnJHNTr/fLWy2BFknYfMuHBx7YJwKJ2BOZqJS+rqxdJBUjjI2I/xEmpAj/4= 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=nQsD0w5B; arc=none smtp.client-ip=209.85.160.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="nQsD0w5B" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-467b0b0aed4so36845361cf.2 for ; Sun, 15 Dec 2024 09:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734285424; x=1734890224; 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=yajkkgOSci/yBx4bhAcrhwPI10+aWgtKbVI/AsRWZpA=; b=nQsD0w5BnJRVE8LyxwiC3GWZIq3bAlw7lPJk3bE3lHbh2+sMCiCcsLH14MpRrGYBj+ GK+Co7zxHrutd5chLaMGMa4eFg15WU6/tnV6WMyxurFeqQuKJnr+JKQdJ2c/++C0GjEh +ZEyH4kHCF1ptjOBkr5N3I790dw0P3ahigQtl1DWT2d7bazajidYoKVq3q5n3I0eRR2M deF2xSz71/TfhgLrM4uMSKrgKlFboQ9LIN7TKFXc5QCFqrU4VNL/xG0W3+4Q6vClSvYO 8TXM8wKpZFyzEPs8cEROv79aWplgc+eG8xP5Z8VDWFRC4BnwrSC/mgEKWnE6CEVRkF0E RRXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734285424; x=1734890224; 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=yajkkgOSci/yBx4bhAcrhwPI10+aWgtKbVI/AsRWZpA=; b=PyLyxp2U+PQU1Juy4MJeqJCkIyQbuZhlS5VPW1Z4vzLPc+93OqWtDCwbchEXiKMKKn ypdTBYBwfKjSFoYoMdT/FGVMsArjGVUTzBGa3i2fyMqdW0A+PQvJ5h1MkXdm6Dx0FQwl lHNJ3XOGN+Lmn/aCWS9dCuLHwTu0VVMSuLrOKBl41+yRkChTCXoqfn68cAEVwdkQPyyh bDZ53bDYcRPUpME4j2SLMBiIQshmME5iEdmGgSPktSb5sAsSm8WRPVsb+hKu3tamLBzr C8ngBorFfyNyFNyDvEJpkWlUiR+JexlK6gsbBuxKn536ZO1E+sIB18ynI7JINXuZ0qkB EIIA== X-Gm-Message-State: AOJu0Yzcu/+1G852T9VoundftaAgI5UsKL/d4Y0oVVFwE5AShUYaJS0S JgKXRXfeP5gj1+sGYxOKoVb/wGb+JYHbCd3xhFQn+CLuCy8LNUAaU1RaQbsuSTTs9Nh5LS0Q929 He3NO8wS/iw== X-Google-Smtp-Source: AGHT+IEc+01vUGqJaWTwuAfEodAjXOIps+0cGX+oqPTN4aDTDEDRAFvbmc2Crzaqxsi7tx2B8InjYmJIMG+Xxw== X-Received: from qtcv13.prod.google.com ([2002:a05:622a:188d:b0:467:aff7:d0c2]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:606:b0:467:53c8:7578 with SMTP id d75a77b69052e-467a577f318mr196749071cf.17.1734285424642; Sun, 15 Dec 2024 09:57:04 -0800 (PST) Date: Sun, 15 Dec 2024 17:56:29 +0000 In-Reply-To: <20241215175629.1248773-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241215175629.1248773-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241215175629.1248773-5-edumazet@google.com> Subject: [PATCH v2 net-next 4/4] inetpeer: do not get a refcount in inet_getpeer() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Ido Schimmel , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org All inet_getpeer() callers except ip4_frag_init() don't need to acquire a permanent refcount on the inetpeer. They can switch to full RCU protection. Move the refcount_inc_not_zero() into ip4_frag_init(), so that all the other callers no longer have to perform a pair of expensive atomic operations on a possibly contended cache line. inet_putpeer() no longer needs to be exported. After this patch, my DUT can receive 8,400,000 UDP packets per second targetting closed ports, using 50% less cpu cycles than before. Also change two calls to l3mdev_master_ifindex() by l3mdev_master_ifindex_rcu() (Ido ideas) Fixes: 8c2bd38b95f7 ("icmp: change the order of rate limits") Signed-off-by: Eric Dumazet --- net/ipv4/icmp.c | 9 ++++----- net/ipv4/inetpeer.c | 8 ++------ net/ipv4/ip_fragment.c | 15 ++++++++++----- net/ipv4/route.c | 15 ++++++++------- net/ipv6/icmp.c | 4 ++-- net/ipv6/ip6_output.c | 4 ++-- net/ipv6/ndisc.c | 6 ++++-- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 5eeb9f569a706cf2766d74bcf1a667c8930804f2..094084b61bff8a17c4e85c99019b84e9cba21599 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -312,7 +312,6 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt, struct dst_entry *dst = &rt->dst; struct inet_peer *peer; bool rc = true; - int vif; if (!apply_ratelimit) return true; @@ -321,12 +320,12 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt, if (dst->dev && (dst->dev->flags&IFF_LOOPBACK)) goto out; - vif = l3mdev_master_ifindex(dst->dev); - peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif); + rcu_read_lock(); + peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, + l3mdev_master_ifindex_rcu(dst->dev)); rc = inet_peer_xrlim_allow(peer, READ_ONCE(net->ipv4.sysctl_icmp_ratelimit)); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); out: if (!rc) __ICMP_INC_STATS(net, ICMP_MIB_RATELIMITHOST); diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 28c3ae5bc4a0b62030bd190dbe5284632ea23efd..e02484f4d22b8ea47cbaeed46c5fb0a7411462a1 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -109,8 +109,6 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, p = rb_entry(parent, struct inet_peer, rb_node); cmp = inetpeer_addr_cmp(daddr, &p->daddr); if (cmp == 0) { - if (!refcount_inc_not_zero(&p->refcnt)) - break; now = jiffies; if (READ_ONCE(p->dtime) != now) WRITE_ONCE(p->dtime, now); @@ -169,6 +167,7 @@ static void inet_peer_gc(struct inet_peer_base *base, } } +/* Must be called under RCU : No refcount change is done here. */ struct inet_peer *inet_getpeer(struct inet_peer_base *base, const struct inetpeer_addr *daddr) { @@ -179,10 +178,8 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, /* Attempt a lockless lookup first. * Because of a concurrent writer, we might not find an existing entry. */ - rcu_read_lock(); seq = read_seqbegin(&base->lock); p = lookup(daddr, base, seq, NULL, &gc_cnt, &parent, &pp); - rcu_read_unlock(); if (p) return p; @@ -200,7 +197,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, if (p) { p->daddr = *daddr; p->dtime = (__u32)jiffies; - refcount_set(&p->refcnt, 2); + refcount_set(&p->refcnt, 1); atomic_set(&p->rid, 0); p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW; p->rate_tokens = 0; @@ -228,7 +225,6 @@ void inet_putpeer(struct inet_peer *p) if (refcount_dec_and_test(&p->refcnt)) kfree_rcu(p, rcu); } -EXPORT_SYMBOL_GPL(inet_putpeer); /* * Check transmit rate limitation for given message. diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 46e1171299f22ccf0b201eabbff5d3279a0703d8..7a435746a22dee9f11c0dc732a8b5a7724f4eea3 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -82,15 +82,20 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *skb, static void ip4_frag_init(struct inet_frag_queue *q, const void *a) { struct ipq *qp = container_of(q, struct ipq, q); - struct net *net = q->fqdir->net; - const struct frag_v4_compare_key *key = a; + struct net *net = q->fqdir->net; + struct inet_peer *p = NULL; q->key.v4 = *key; qp->ecn = 0; - qp->peer = q->fqdir->max_dist ? - inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif) : - NULL; + if (q->fqdir->max_dist) { + rcu_read_lock(); + p = inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif); + if (p && !refcount_inc_not_zero(&p->refcnt)) + p = NULL; + rcu_read_unlock(); + } + qp->peer = p; } static void ip4_frag_free(struct inet_frag_queue *q) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 297a9939c6e74beffc592dbdd7266281fe842440..9f9d4e6ea1b9287c0d758e9bdf543a92b14974ef 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -870,11 +870,11 @@ void ip_rt_send_redirect(struct sk_buff *skb) } log_martians = IN_DEV_LOG_MARTIANS(in_dev); vif = l3mdev_master_ifindex_rcu(rt->dst.dev); - rcu_read_unlock(); net = dev_net(rt->dst.dev); peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif); if (!peer) { + rcu_read_unlock(); icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, rt_nexthop(rt, ip_hdr(skb)->daddr)); return; @@ -893,7 +893,7 @@ void ip_rt_send_redirect(struct sk_buff *skb) */ if (peer->n_redirects >= ip_rt_redirect_number) { peer->rate_last = jiffies; - goto out_put_peer; + goto out_unlock; } /* Check for load limit; set rate_last to the latest sent @@ -914,8 +914,8 @@ void ip_rt_send_redirect(struct sk_buff *skb) &ip_hdr(skb)->saddr, inet_iif(skb), &ip_hdr(skb)->daddr, &gw); } -out_put_peer: - inet_putpeer(peer); +out_unlock: + rcu_read_unlock(); } static int ip_error(struct sk_buff *skb) @@ -975,9 +975,9 @@ static int ip_error(struct sk_buff *skb) break; } + rcu_read_lock(); peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, - l3mdev_master_ifindex(skb->dev)); - + l3mdev_master_ifindex_rcu(skb->dev)); send = true; if (peer) { now = jiffies; @@ -989,8 +989,9 @@ static int ip_error(struct sk_buff *skb) peer->rate_tokens -= ip_rt_error_cost; else send = false; - inet_putpeer(peer); } + rcu_read_unlock(); + if (send) icmp_send(skb, ICMP_DEST_UNREACH, code, 0); diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index 4593e3992c67b84e3a10f30be28762974094d21f..a6984a29fdb9dd972a11ca9f8d5e794c443bac6f 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -222,10 +222,10 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type, if (rt->rt6i_dst.plen < 128) tmo >>= ((128 - rt->rt6i_dst.plen)>>5); + rcu_read_lock(); peer = inet_getpeer_v6(net->ipv6.peers, &fl6->daddr); res = inet_peer_xrlim_allow(peer, tmo); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); } if (!res) __ICMP6_INC_STATS(net, ip6_dst_idev(dst), diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 2cbcfe70654b5cd90c433a24c47ef5496c604d0d..06cab008b8277f1b6e56541e91fc92f999221ac5 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -613,6 +613,7 @@ int ip6_forward(struct sk_buff *skb) else target = &hdr->daddr; + rcu_read_lock(); peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr); /* Limit redirects both by destination (here) @@ -620,8 +621,7 @@ int ip6_forward(struct sk_buff *skb) */ if (inet_peer_xrlim_allow(peer, 1*HZ)) ndisc_send_redirect(skb, target); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); } else { int addrtype = ipv6_addr_type(&hdr->saddr); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index f113554d13325453cd04ce4e5686d837943e96ff..d044c67019de6da1eb29dee875cf8cda30210ceb 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1731,10 +1731,12 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) "Redirect: destination is not a neighbour\n"); goto release; } + + rcu_read_lock(); peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr); ret = inet_peer_xrlim_allow(peer, 1*HZ); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); + if (!ret) goto release;