Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp8220844rwd; Tue, 20 Jun 2023 11:54:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6URjjFmG90vDrmC/C22gq3+vVwoH5LZLAzK3W4SM3OlQILQMEh9nnhC1AninkkNKVIkEju X-Received: by 2002:a17:903:2343:b0:1b5:640a:887a with SMTP id c3-20020a170903234300b001b5640a887amr8645544plh.60.1687287256283; Tue, 20 Jun 2023 11:54:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687287256; cv=none; d=google.com; s=arc-20160816; b=sN6fc0EJBXiXt0Tcx0sMYrv7sPXq5srLnME/VGZvHMOsjxL+hYWah809H5nOZ2qj3O OYMiUMH29uPiP7wpe2HdAr6fecn3U1gk65b1/v+8Iu5wMvQojXhgtsxKj6oivepzU3tk /Z8f7+aRouB1j2Utme2OUDCLvCYX6NZLhNAhh8LN8QBBr43dAFFvkXPmNwxLGFq0zVDs 5sZVUIZePd9322hEiQ1vFjy4THv8eA1Dj9aRYjlDqyEUm+SoPuozQetGJj96LYUicP2a yrs4HtcTljATCqLDhpMrn/IRREZqXklo7xt2nuLIBL3TH+YSMSv/xGHJtp2+VTbvqur8 lFug== 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=kP7uUg6bTWjebzwk/DY0XKPv7AdGZoJ1Fbg26s6nHds=; b=pJdFHVu6W3o7hlDiwLMZh7dg4363Nu7pSIM3f5wr162PAKVD/lfENL62pkrE/9lXww d4B0yBxtEUPJxyfdrDszRaodWxL0Rq3mL3F2PIa5Lulwv3qPLlHNGtRYY5M4UareWJzU Ipvh8g9G0xphNl8k2/zpPRDBSWMoMv/pD3rF0soxzArldzSyXGUGO+yMoqBz1NyYJsN/ BLgDZ/zAnaieOkZXuPFvOBcgtHlz5lZvoDES5uaZzduY20ulURCCsn/xzZ795f6eAfz7 tUK+8TBdZxGhCE8D3I1t9Rl2j8WBE6Df48H58NcBeCe2n4Xv3swKZkYy36WOx3NtFvIX JNPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=LOGDrxLL; 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 le8-20020a170902fb0800b001b02d0941dfsi2251685plb.354.2023.06.20.11.54.02; Tue, 20 Jun 2023 11:54:16 -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=LOGDrxLL; 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 S229964AbjFTScG (ORCPT + 99 others); Tue, 20 Jun 2023 14:32:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbjFTScC (ORCPT ); Tue, 20 Jun 2023 14:32:02 -0400 Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2857C10C2; Tue, 20 Jun 2023 11:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1687285910; x=1718821910; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kP7uUg6bTWjebzwk/DY0XKPv7AdGZoJ1Fbg26s6nHds=; b=LOGDrxLLJUW8VtKNdaNrtYOFvUnws2nfn2luYVhxhsP465psYu09U1w3 Qw8bwGNBkKVGMsIEHMQ47npNXpRWfvmqMf3Xq1NfMdjZR1UtfnVY1nWcN AhDWjVVp7mzEZcGjd07FLavq8wYcpwiLS73BMKbpJ8obYNGn5nscjbkbu E=; X-IronPort-AV: E=Sophos;i="6.00,257,1681171200"; d="scan'208";a="11370153" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 18:31:46 +0000 Received: from EX19MTAUWC002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com (Postfix) with ESMTPS id 630E546DFB; Tue, 20 Jun 2023 18:31:39 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 20 Jun 2023 18:31:38 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.101.48) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.26; Tue, 20 Jun 2023 18:31:32 +0000 From: Kuniyuki Iwashima To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH bpf-next v2 3/6] net: remove duplicate reuseport_lookup functions Date: Tue, 20 Jun 2023 11:31:23 -0700 Message-ID: <20230620183123.74585-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.106.101.48] X-ClientProxiedBy: EX19D036UWB003.ant.amazon.com (10.13.139.172) 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_H4,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: Tue, 20 Jun 2023 15:26:05 +0100 > On Tue, Jun 13, 2023 at 7:57 PM Kuniyuki Iwashima wrote: > > > > The assignment to result below is buggy. Let's say SO_REUSEPROT group > > have TCP_CLOSE and TCP_ESTABLISHED sockets. > > > > 1. Find TCP_CLOSE sk and do SO_REUSEPORT lookup > > 2. result is not NULL, but the group has TCP_ESTABLISHED sk > > 3. result = result > > 4. Find TCP_ESTABLISHED sk, which has a higher score > > 5. result = result (TCP_CLOSE) <-- should be sk. > > > > Same for v6 function. > > Thanks for your explanation, I think I get it now. I misunderstood > that you were worried about returning TCP_ESTABLISHED instead of > TCP_CLOSE, but it's exactly the other way around. > > I have a follow up question regarding the existing code: > > result = lookup_reuseport(net, sk, skb, > saddr, sport, daddr, hnum); > /* Fall back to scoring if group has connections */ > if (result && !reuseport_has_conns(sk)) > return result; > > result = result ? : sk; > badness = score; > > Assuming that result != NULL but reuseport_has_conns() == true, we use > the reuseport socket as the result, but assign the score of sk to > badness. Shouldn't we use the score of the reuseport socket? Good point. This is based on an assumption that all SO_REUSEPORT sockets have the same score, which is wrong for two corner cases if reuseport_has_conns() == true : 1) SO_INCOMING_CPU is set -> selected sk might have +1 score 2) BPF prog returns ESTABLISHED and/or SO_INCOMING_CPU sk -> selected sk will have more than 8 Using the old score could trigger more lookups depending on the order that sockets are created. sk -> sk (SO_INCOMING_CPU) -> sk (ESTABLISHED) | | `-> select the next SO_INCOMING_CPU sk | `-> select itself (We should save this lookup) So, yes, we should update badness like if (unlikely(result)) { badness = compute_score(result, ...); } else { result = sk; badness = score; }