Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1333991pxj; Sat, 12 Jun 2021 05:37:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPnkgFuZqP5P2ZMmVfovAmm7uMpbMXrs0QU99AHMosRfZx6rjTFE4LKETS3S+gAprQP866 X-Received: by 2002:a17:907:d9e:: with SMTP id go30mr7838768ejc.279.1623501455193; Sat, 12 Jun 2021 05:37:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623501455; cv=none; d=google.com; s=arc-20160816; b=QQRQ4PfGU+iQyqkejQlUCY2D5MxHe4NwjRtapvQ3RBvGKadZa5qzTdv9gADuEWvpcx 9UkleLJlbCodsKbN2nH3yImz9VbAXpmevCx6GVOgB300fD4ECpAaOf7zOdzdKPXfQHHE zvW5X1zL1PF2p4jem4Q/Ia5yFB8FXwECK++Mk9zC1lEqImtuDLg10b2GrcicMhqcLdKh U62i/JwfEmBXFt2v5NLdvmL8eJwKDhyZ7+WmCqV++9rPiwUTCQFK03EQWl7cAQgSw5lg WGbSFEtfrloKJiS33flcJne+FV+ULuBV/2sar+lOh4nd2b7uSMGHU9G4DE9xInyrYy6m 67Fg== 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=pFiQcIG1ZZPTSfoud/r8vGvVbjycJJug3HPxa6DKWNY=; b=jtTDM/8ETkjCs6yExnNU0K91mYZoaIVG0RNUv4GV/W5QCqP8lZ8Yfk/o7bZ4RiiBQO gsAlqegC16RhomLc6Qpe4Mhau8YSEwoJtIGt7ucO6t2vtPyCAk7JB9eesk7fiJhesQV4 m9S5ng3xfUTRFqcNGpoQDWwsvdzPUn32TAzGvIHtjrlSHMhtr/gfS6IVJ65jz7Pw36gc jvTo+JP9LiOCkWXlJklXqopUjMJHMFQ4kkgGIk+osGLoYp+a5OvZAnuOHHuX7yNr3cmi zADPgeNIUeNIvtLkqV33DpW4UkHRdpo00uVI3rPA+JB/NYoQ113ejQLE/UWvRJgQrXux v1BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.jp header.s=amazon201209 header.b=itWDvs74; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.jp Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si2472000eda.198.2021.06.12.05.37.12; Sat, 12 Jun 2021 05:37:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.co.jp header.s=amazon201209 header.b=itWDvs74; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.jp Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231438AbhFLMgn (ORCPT + 99 others); Sat, 12 Jun 2021 08:36:43 -0400 Received: from smtp-fw-9103.amazon.com ([207.171.188.200]:11750 "EHLO smtp-fw-9103.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231218AbhFLMgm (ORCPT ); Sat, 12 Jun 2021 08:36:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.jp; i=@amazon.co.jp; q=dns/txt; s=amazon201209; t=1623501282; x=1655037282; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pFiQcIG1ZZPTSfoud/r8vGvVbjycJJug3HPxa6DKWNY=; b=itWDvs74IrQCMpSd3JETc5txLEPX0F//IGq+B0eHd8emoYO6/tylSZuH pYinIVmC8i9ejAUSgUkHtdGFsXwUnRLXeiysoBZRnhucjKvJImDwXYdLY sYavfGoPXaH0MVRHQMKNRP4Gd1/881wKNGJkOAUW7+MJSBoupEcZ2LMg/ Q=; X-IronPort-AV: E=Sophos;i="5.83,268,1616457600"; d="scan'208";a="937976518" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 12 Jun 2021 12:34:42 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com (Postfix) with ESMTPS id BB357A1D57; Sat, 12 Jun 2021 12:34:41 +0000 (UTC) Received: from EX13D04ANC001.ant.amazon.com (10.43.157.89) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 12 Jun 2021 12:34:41 +0000 Received: from 88665a182662.ant.amazon.com (10.43.160.55) by EX13D04ANC001.ant.amazon.com (10.43.157.89) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 12 Jun 2021 12:34:34 +0000 From: Kuniyuki Iwashima To: "David S . Miller" , Jakub Kicinski , Eric Dumazet , Neal Cardwell , Yuchung Cheng , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau CC: Benjamin Herrenschmidt , Kuniyuki Iwashima , Kuniyuki Iwashima , , , Subject: [PATCH v8 bpf-next 08/11] bpf: Support BPF_FUNC_get_socket_cookie() for BPF_PROG_TYPE_SK_REUSEPORT. Date: Sat, 12 Jun 2021 21:32:21 +0900 Message-ID: <20210612123224.12525-9-kuniyu@amazon.co.jp> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210612123224.12525-1-kuniyu@amazon.co.jp> References: <20210612123224.12525-1-kuniyu@amazon.co.jp> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.43.160.55] X-ClientProxiedBy: EX13D04UWB002.ant.amazon.com (10.43.161.133) To EX13D04ANC001.ant.amazon.com (10.43.157.89) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We will call sock_reuseport.prog for socket migration in the next commit, so the eBPF program has to know which listener is closing to select a new listener. We can currently get a unique ID of each listener in the userspace by calling bpf_map_lookup_elem() for BPF_MAP_TYPE_REUSEPORT_SOCKARRAY map. This patch makes the pointer of sk available in sk_reuseport_md so that we can get the ID by BPF_FUNC_get_socket_cookie() in the eBPF program. Link: https://lore.kernel.org/netdev/20201119001154.kapwihc2plp4f7zc@kafai-mbp.dhcp.thefacebook.com/ Suggested-by: Martin KaFai Lau Signed-off-by: Kuniyuki Iwashima Acked-by: Martin KaFai Lau --- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 10 ++++++++++ tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 12 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 2c1ba70abbf1..f3b72588442b 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5416,6 +5416,7 @@ struct sk_reuseport_md { __u32 ip_protocol; /* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */ __u32 bind_inany; /* Is sock bound to an INANY address? */ __u32 hash; /* A hash of the packet 4 tuples */ + __bpf_md_ptr(struct bpf_sock *, sk); }; #define BPF_TAG_SIZE 8 diff --git a/net/core/filter.c b/net/core/filter.c index caa88955562e..f753ab550525 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -10172,6 +10172,8 @@ sk_reuseport_func_proto(enum bpf_func_id func_id, return &sk_reuseport_load_bytes_proto; case BPF_FUNC_skb_load_bytes_relative: return &sk_reuseport_load_bytes_relative_proto; + case BPF_FUNC_get_socket_cookie: + return &bpf_get_socket_ptr_cookie_proto; default: return bpf_base_func_proto(func_id); } @@ -10201,6 +10203,10 @@ sk_reuseport_is_valid_access(int off, int size, case offsetof(struct sk_reuseport_md, hash): return size == size_default; + case offsetof(struct sk_reuseport_md, sk): + info->reg_type = PTR_TO_SOCKET; + return size == sizeof(__u64); + /* Fields that allow narrowing */ case bpf_ctx_range(struct sk_reuseport_md, eth_protocol): if (size < sizeof_field(struct sk_buff, protocol)) @@ -10273,6 +10279,10 @@ static u32 sk_reuseport_convert_ctx_access(enum bpf_access_type type, case offsetof(struct sk_reuseport_md, bind_inany): SK_REUSEPORT_LOAD_FIELD(bind_inany); break; + + case offsetof(struct sk_reuseport_md, sk): + SK_REUSEPORT_LOAD_FIELD(sk); + break; } return insn - insn_buf; diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 2c1ba70abbf1..f3b72588442b 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5416,6 +5416,7 @@ struct sk_reuseport_md { __u32 ip_protocol; /* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */ __u32 bind_inany; /* Is sock bound to an INANY address? */ __u32 hash; /* A hash of the packet 4 tuples */ + __bpf_md_ptr(struct bpf_sock *, sk); }; #define BPF_TAG_SIZE 8 -- 2.30.2