Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30647965rwd; Thu, 6 Jul 2023 08:45:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlHljE/WI/6JNmuETiscwDgtSd6lJ5/3ewhb1wgD9bsClv1+DO0jJT9+sy6epq2Q4ph+vGbi X-Received: by 2002:a17:90a:74c6:b0:262:ff86:ac2d with SMTP id p6-20020a17090a74c600b00262ff86ac2dmr2150597pjl.46.1688658335464; Thu, 06 Jul 2023 08:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688658335; cv=none; d=google.com; s=arc-20160816; b=FYwzi2CZ4snC/p5gTB6Lf4ngiPhJiwWcqhJyIpQqLYCJldzutcS6u5zg+IQmP0KPAd huJv+WZhG7I6MtjMPezj7xONda4t566ZVyUNK+EaurBkN9TYlF5NBCZuxQHw/WJdtuJx N0odd1QmmcsqUIEu2sGVIusIthpnK39UGOSTy6rusPaPdYAp4zSdTgq2SQOIiue5EXnu 741pTRUK3qSWeFOMkkGBka4hX7GNVTp5s0hwaZjnl5DK6NwlQpV+N+Ui0Sdpvst33RE9 dr7HBIbynZ0CbOq+nVca0GywXGoF6hn3gJwlJusSIhokyOwM0Qc7vKeegIfSs5OUoHjq I/zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=trA35bhtZS7sC65wm9GfBeAVYdZXIA5psrybUjewGIQ=; fh=uX93oDSK2USwrk3UKWJI9B5Go5W2toUUNoPCfgm/ACY=; b=OMAk5hZOKdQ3D69nexO4QFYA8wH+wZR0s5ws6wHuAZelhQK7z4dpGXFfMIa9mIhBCI ZNtqMbumgJjWMcy3KWYy5J1SdJrshooNsmtIfJz3+8YCgKPsVkIzF2S8Rq7Li3x2j/LU 4E0mg0vOBm8EIuHvbe0M0utb/3xPM8ZXCgLIju17iwgSzY8rG0AWAJuuB7aMxd1OPxTw Mq0gr6aARiiNnYCXNVEpQvuOtVdGNbB79VoW1p7viJpiHDm1cvpX93rs6IGPIhu/gbCw wafrq9AEtIqmjdtHpWx0ycNqlT+qeLHDKUPA7Rj/gBWPqvJlU9WzCDC+gNvY23yspsOx D1og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=A0UumUCQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a63de03000000b0055795190dd2si1582582pgg.666.2023.07.06.08.45.21; Thu, 06 Jul 2023 08:45:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=A0UumUCQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233203AbjGFPd4 (ORCPT + 99 others); Thu, 6 Jul 2023 11:33:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232960AbjGFPdz (ORCPT ); Thu, 6 Jul 2023 11:33:55 -0400 Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F346BFF; Thu, 6 Jul 2023 08:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1688657635; x=1720193635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=trA35bhtZS7sC65wm9GfBeAVYdZXIA5psrybUjewGIQ=; b=A0UumUCQtccE+sL4EQW3IA6Wg1hcfLSmRSmI/JZD/sedyT5VYzAKy+fS qjJCBdlLKda+gxGC1/nglq1eFqaJmASSIL1vTr72VH8gF+r8AifyGvAa4 QqOoXm+zYDyY8Tu1M2r39/T7cT4zFNhrTsSoccqGOyygiR2iLn3AaIYYA 8=; X-IronPort-AV: E=Sophos;i="6.01,185,1684800000"; d="scan'208";a="658357472" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-21d8d9f4.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2023 15:33:49 +0000 Received: from EX19MTAUWC001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2a-m6i4x-21d8d9f4.us-west-2.amazon.com (Postfix) with ESMTPS id 7CCA88103C; Thu, 6 Jul 2023 15:33:42 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Thu, 6 Jul 2023 15:33:40 +0000 Received: from 88665a182662.ant.amazon.com (10.187.171.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Thu, 6 Jul 2023 15:33:35 +0000 From: Kuniyuki Iwashima To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH bpf-next v4 6/7] bpf, net: Support SO_REUSEPORT sockets with bpf_sk_assign Date: Thu, 6 Jul 2023 08:33:27 -0700 Message-ID: <20230706153327.99298-1-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.187.171.32] X-ClientProxiedBy: EX19D043UWA004.ant.amazon.com (10.13.139.41) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_PERMERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lorenz Bauer Date: Thu, 6 Jul 2023 09:11:15 +0100 > On Thu, Jul 6, 2023 at 1:41 AM Kuniyuki Iwashima wrote: > > > > Sorry for late reply. > > > > What we know about sk before inet6?_lookup_reuseport() are > > > > (1) sk was full socket in bpf_sk_assign() > > (2) sk had SOCK_RCU_FREE in bpf_sk_assign() > > (3) sk was TCP_LISTEN here if TCP > > Are we looking at the same bpf_sk_assign? Confusingly there are two > very similarly named functions. The one we care about is: > > BPF_CALL_3(bpf_sk_assign, struct sk_buff *, skb, struct sock *, sk, u64, flags) > { > if (!sk || flags != 0) > return -EINVAL; > if (!skb_at_tc_ingress(skb)) > return -EOPNOTSUPP; > if (unlikely(dev_net(skb->dev) != sock_net(sk))) > return -ENETUNREACH; > if (sk_is_refcounted(sk) && > unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) > return -ENOENT; > > skb_orphan(skb); > skb->sk = sk; > skb->destructor = sock_pfree; > > return 0; > } > > From this we can't tell what state the socket is in or whether it is > RCU freed or not. But we can in inet6?_steal_sock() by calling sk_is_refcounted() again via skb_steal_sock(). In inet6?_steal_sock(), we call inet6?_lookup_reuseport() only for sk that was a TCP listener or UDP non-connected socket until just before the sk_state checks. Then, we know *refcounted should be false for such sockets even before inet6?_lookup_reuseport(). After the checks, sk might be poped out of the reuseport group before inet6?_lookup_reuseport() and reuse_sk might be NULL, but it's not related because *refcounted is a value for sk, not for reuse_sk.