Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4165774pxy; Mon, 26 Apr 2021 20:50:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzytm+V+nlcXyfRiEUvO2yTLb3TUVnZtdd2lo6xQCvMnIWR+1/IG1Z3+I9640dmxcP97zP9 X-Received: by 2002:a63:1e62:: with SMTP id p34mr19667983pgm.355.1619495450919; Mon, 26 Apr 2021 20:50:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619495450; cv=none; d=google.com; s=arc-20160816; b=f8fPsD6YTCVYb0imCtCXOoH0TH73m0izZo7jbW/YYkmBYPK00jg6SPt+sIHR/cCi6d ynnNsW3OTXeWE51PfHvmKwxNlfInFzY9Tb8qGJsqABq3AXuHu0yhq1BuTpuywVUB2T8k W14OM9JO1z+J5+r62nRB0XuVJIPtF2HEdNPP+6ZmNMW8mETNAQy85WTSiXelBR4SbXek BnGMtXD3ia9f8+nRqE0ZpsXH+AYko8YEejQUgqemdmx+0atKiuDRkcEZxH1Pa2HJwMOt m4cLCR8/7Bl5dq83Ny9fzAhYvEnkKasmzRIElVIrQ4MkHgjyUth/b15QaMXt9/+5p/MA YhEg== 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=GhbXRsTc1eaTiJbgT8QkZFIVPPspAJ0LsgWqW2KcmiU=; b=M0Yx150DdrnSPT1NRjr+DQX3JTlGFtLrBvAOy6kjp0wxmw3UDe8tEszFALJLjnWh4Y Ix0jR3EYx1zsPs9pSnal9JbqeFYhOAdv0697GipgyCWUt/C+3xCYGWqzxGaPchKXE24p zp8k1NpA5htFwgAIxSCfXiIdPW2XezcSwXaBFDPODLQfCmqgUaNrpp2/LcWqo0J2PhxY /wWwV8Cg7tbNSySgVFz9MCzOT7uXZt8ZP0J1o3uCP2MvHGtvO/LUXHTlYGcYhekn0olr Qa8jgJdjX+J/8Dk+xmmGWFbVqZpHhNrzUr5L4Lk86y2OSdhHrfd1szohxUu+RiYxRECc rl5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.jp header.s=amazon201209 header.b=Fn9kWsEb; 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 t1si20364718pgu.333.2021.04.26.20.50.38; Mon, 26 Apr 2021 20:50:50 -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=Fn9kWsEb; 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 S234744AbhD0Dtt (ORCPT + 99 others); Mon, 26 Apr 2021 23:49:49 -0400 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:36812 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234272AbhD0Dts (ORCPT ); Mon, 26 Apr 2021 23:49:48 -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=1619495347; x=1651031347; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GhbXRsTc1eaTiJbgT8QkZFIVPPspAJ0LsgWqW2KcmiU=; b=Fn9kWsEbZxc3SiekhI0aUQr6c0SekJ6soF240cVdPheT//2CrcFdhLo5 7tGDZGvsjHe3qhd9d7XUm4AY2T4IgCWtwRax1LW0YxUoouV5RaNZrQRZN WuYDCNK7II+MIkaibBQzplqDS1C13HdqXGXOqKQCJNyNF6YDEuBqlpjCA w=; X-IronPort-AV: E=Sophos;i="5.82,254,1613433600"; d="scan'208";a="108549093" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-a70de69e.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP; 27 Apr 2021 03:49:06 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-a70de69e.us-east-1.amazon.com (Postfix) with ESMTPS id BE356A1DB1; Tue, 27 Apr 2021 03:49:03 +0000 (UTC) Received: from EX13D04ANC001.ant.amazon.com (10.43.157.89) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 27 Apr 2021 03:49:02 +0000 Received: from 88665a182662.ant.amazon.com (10.43.162.93) by EX13D04ANC001.ant.amazon.com (10.43.157.89) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 27 Apr 2021 03:48:57 +0000 From: Kuniyuki Iwashima To: "David S . Miller" , Jakub Kicinski , Eric Dumazet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau CC: Benjamin Herrenschmidt , Kuniyuki Iwashima , Kuniyuki Iwashima , , , Subject: [PATCH v4 bpf-next 08/11] bpf: Support BPF_FUNC_get_socket_cookie() for BPF_PROG_TYPE_SK_REUSEPORT. Date: Tue, 27 Apr 2021 12:46:20 +0900 Message-ID: <20210427034623.46528-9-kuniyu@amazon.co.jp> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210427034623.46528-1-kuniyu@amazon.co.jp> References: <20210427034623.46528-1-kuniyu@amazon.co.jp> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.43.162.93] X-ClientProxiedBy: EX13D18UWC002.ant.amazon.com (10.43.162.88) 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 --- 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 ec6d85a81744..d2e6bf2d464b 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5364,6 +5364,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 cae56d08a670..3d0f989f5d38 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -10135,6 +10135,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); } @@ -10164,6 +10166,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 = ARG_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)) @@ -10236,6 +10242,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 ec6d85a81744..d2e6bf2d464b 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5364,6 +5364,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