From patchwork Thu May 21 14:34:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Fastabend X-Patchwork-Id: 218822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E80DC433DF for ; Thu, 21 May 2020 14:35:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C07C206F6 for ; Thu, 21 May 2020 14:35:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sir33K5V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729698AbgEUOfJ (ORCPT ); Thu, 21 May 2020 10:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729558AbgEUOfJ (ORCPT ); Thu, 21 May 2020 10:35:09 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27DECC061A0E; Thu, 21 May 2020 07:35:08 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id q9so3147266pjm.2; Thu, 21 May 2020 07:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=WpksQQuSOYFEg+wnTmw3DB7QF9n6IUD+5AgSrpySUcw=; b=Sir33K5VyX4mIVVc8fDv/ETvdM5x7DhRtmZiz9HxaNlNdqfFRk9klDIrxMrCDz6jV+ j7+2o+65QHSP9UeF2kSxpqnp+UF0oGdudfGsEbt05SrB1NKR1V1Hg2R9nKeqM5zpio7j XXDJ4GVs8IPjDSAGQRYzR9zuQ7vLBvNO/2CenwBdDo3KtFOrEMdQ2ZECa5nEZUmvfgDI RvcdR7SwIPJsSo/VfQ/B+JLioZ3fx9XzUOKeJclqfQZ2/TDazQT7r9MvoOdiACiQ+ZGP cgYhryn6CzaTSWkxoXn4UwH7YACEe7SVgPriPFOCSlweCtSH/67rOhRpbXtrKQNNVeFX hPtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=WpksQQuSOYFEg+wnTmw3DB7QF9n6IUD+5AgSrpySUcw=; b=aJL1nLew4Mlks7BpQAw35KhumH/FFQo/3oJslICLyJyv2scG14fTBg8axYFL97Q+lq KlQapDhp9FNGFn6Oqk0XIFfdTApSBfD2vXOSZMOde/eBP3sRKhm4ZDGl00sHPY9ZrdPo opmxPOlRBi3kk7DOHB5FLooVUX6KUt9RFIjczJZx+L0XRVNe7pak56fjv/0gkClVp5YS okKdJiznFArgrQ8xpY7O/1IYvBjmnSxAALX/7z6uZsokxAQ/5Vxza7ZXxnh2dv9BnWgd atXtQ5sINRw0BnNMc7hfsq0bTLl7sdTf8DVK5OUdYRKbasnRyZkk8Rty/sGDnDz+m8Ae Druw== X-Gm-Message-State: AOAM533OH1tCM0ac19x+ZQPpGr7sxRiKQyN7gD9Qf5jROit43H7ri4Nc fvjgCI3xepHTl49U9+rV2qA= X-Google-Smtp-Source: ABdhPJxQBl4jGtUjPZzqWxuxRlUkaX4vxMT3AHYC0klsfz94l29yqKjsF1MfcoIrjBkfXXtX9SRRFA== X-Received: by 2002:a17:90a:9f92:: with SMTP id o18mr11823960pjp.180.1590071707750; Thu, 21 May 2020 07:35:07 -0700 (PDT) Received: from [127.0.1.1] ([184.63.162.180]) by smtp.gmail.com with ESMTPSA id j16sm4543046pfa.179.2020.05.21.07.34.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 May 2020 07:35:07 -0700 (PDT) Subject: [bpf-next PATCH v3 1/5] bpf: sk_msg add some generic helpers that may be useful from sk_msg From: John Fastabend To: yhs@fb.com, ast@kernel.org, daniel@iogearbox.net Cc: lmb@cloudflare.com, bpf@vger.kernel.org, john.fastabend@gmail.com, jakub@cloudflare.com, netdev@vger.kernel.org Date: Thu, 21 May 2020 07:34:52 -0700 Message-ID: <159007169244.10695.7758980724441079287.stgit@john-Precision-5820-Tower> In-Reply-To: <159007153289.10695.12380087259405383510.stgit@john-Precision-5820-Tower> References: <159007153289.10695.12380087259405383510.stgit@john-Precision-5820-Tower> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add these generic helpers that may be useful to use from sk_msg programs. The helpers do not depend on ctx so we can simply add them here, BPF_FUNC_perf_event_output BPF_FUNC_get_current_uid_gid BPF_FUNC_get_current_pid_tgid BPF_FUNC_get_current_comm BPF_FUNC_get_current_cgroup_id BPF_FUNC_get_current_ancestor_cgroup_id BPF_FUNC_get_cgroup_classid Acked-by: Yonghong Song Signed-off-by: John Fastabend --- net/core/filter.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index 822d662..a56046a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6443,6 +6443,22 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_msg_push_data_proto; case BPF_FUNC_msg_pop_data: return &bpf_msg_pop_data_proto; + case BPF_FUNC_perf_event_output: + return &bpf_event_output_data_proto; + case BPF_FUNC_get_current_uid_gid: + return &bpf_get_current_uid_gid_proto; + case BPF_FUNC_get_current_pid_tgid: + return &bpf_get_current_pid_tgid_proto; +#ifdef CONFIG_CGROUPS + case BPF_FUNC_get_current_cgroup_id: + return &bpf_get_current_cgroup_id_proto; + case BPF_FUNC_get_current_ancestor_cgroup_id: + return &bpf_get_current_ancestor_cgroup_id_proto; +#endif +#ifdef CONFIG_CGROUP_NET_CLASSID + case BPF_FUNC_get_cgroup_classid: + return &bpf_get_cgroup_classid_curr_proto; +#endif default: return bpf_base_func_proto(func_id); } From patchwork Thu May 21 14:35:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Fastabend X-Patchwork-Id: 218821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3FB9C433E0 for ; Thu, 21 May 2020 14:35:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0EBC20671 for ; Thu, 21 May 2020 14:35:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dhzTNDTR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729794AbgEUOfx (ORCPT ); Thu, 21 May 2020 10:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728103AbgEUOfv (ORCPT ); Thu, 21 May 2020 10:35:51 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABB2AC061A0E; Thu, 21 May 2020 07:35:51 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id n11so3248837pgl.9; Thu, 21 May 2020 07:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=djZbck+yBbWihA0B4R6+ByjUmJULJBdA1YBImrlU7zA=; b=dhzTNDTReu8aSKrCsAu11pj9PjXQlMbK1478ADFibV/P/8uKf1lyyC+urY13GsPspG o1TIaCaXVKNdPQL57IJEpGq4VbGJX0Lt76cDO84vWvznU7qabxmG9e3OrhQTZQL9iIuw bcYRiXgYJLWwDlzJBEe+9wQ83O51VqBM2IPKn/VK7wkLdH8Yr8y+CUGfqe8g/mQcWTA2 2ZGUv4YmHBsQYRdD5izTe/v7y+RFAhbRQzkkYusbkyq3xffYL/eW8yqxD4kfAONaSuew 4FS4calAUcUju8ClMC61Zz9E42WadHO5p0dO2m6fKVOXwk43AoAXogDblmWnVCJEM2fY VNiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=djZbck+yBbWihA0B4R6+ByjUmJULJBdA1YBImrlU7zA=; b=IETzVTY/MmoA2E7NX+9lwjE4uy5F79rxsAMELq+utjQBstWc6MZygzDZod8J+1uyrt 9dk5PIIx3pnOYwtlh/us9ja+RyL9Vhf01B4xMqor91B/UqcYY6UIe9YV0GIyZCHxt0Ej DIumiONcc+9d9VWkahbAesMqVZ6jHICIju6vNdByvhy5XzmUOa2g7Aw/ZLJBkMWZCcoo q+Df33mPTxeDF00qN43hWsZ8Uo+U1Tx1pkjdW+zoLXZwNi7KlGK1+ewW0X4qIMzdKKYt z0sfzjljlbiIt2XFIddV/naxVJ+brBECvltT5+E3GwXB3jVRrbC6E+0iCHlknnstHweb Nv9w== X-Gm-Message-State: AOAM5300XZIGqfldyJFTBu7LtvVf7c1fNBfI0PSBpvQf4iaBrgRXcgbZ vCbtNLB5jeHd7rinVda6nkY= X-Google-Smtp-Source: ABdhPJyLzlpVlUi/2GBMAgBg/vyGhhM84Af3V164XmjFhOalQ8aMM/2HUiOww28544kayx7NAhtQ0w== X-Received: by 2002:a62:79c2:: with SMTP id u185mr9882284pfc.159.1590071751303; Thu, 21 May 2020 07:35:51 -0700 (PDT) Received: from [127.0.1.1] ([184.63.162.180]) by smtp.gmail.com with ESMTPSA id p4sm4552683pff.159.2020.05.21.07.35.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 May 2020 07:35:50 -0700 (PDT) Subject: [bpf-next PATCH v3 3/5] bpf: sk_msg add get socket storage helpers From: John Fastabend To: yhs@fb.com, ast@kernel.org, daniel@iogearbox.net Cc: lmb@cloudflare.com, bpf@vger.kernel.org, john.fastabend@gmail.com, jakub@cloudflare.com, netdev@vger.kernel.org Date: Thu, 21 May 2020 07:35:36 -0700 Message-ID: <159007173608.10695.10412818793074834651.stgit@john-Precision-5820-Tower> In-Reply-To: <159007153289.10695.12380087259405383510.stgit@john-Precision-5820-Tower> References: <159007153289.10695.12380087259405383510.stgit@john-Precision-5820-Tower> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add helpers to use local socket storage. Signed-off-by: John Fastabend Acked-by: Yonghong Song --- include/uapi/linux/bpf.h | 2 ++ net/core/filter.c | 15 +++++++++++++++ tools/include/uapi/linux/bpf.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index b9b8a0f..d394b09 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -3641,6 +3641,8 @@ struct sk_msg_md { __u32 remote_port; /* Stored in network byte order */ __u32 local_port; /* stored in host byte order */ __u32 size; /* Total size of sk_msg */ + + __bpf_md_ptr(struct bpf_sock *, sk); /* current socket */ }; struct sk_reuseport_md { diff --git a/net/core/filter.c b/net/core/filter.c index a56046a..48b499f 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6449,6 +6449,10 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_get_current_uid_gid_proto; case BPF_FUNC_get_current_pid_tgid: return &bpf_get_current_pid_tgid_proto; + case BPF_FUNC_sk_storage_get: + return &bpf_sk_storage_get_proto; + case BPF_FUNC_sk_storage_delete: + return &bpf_sk_storage_delete_proto; #ifdef CONFIG_CGROUPS case BPF_FUNC_get_current_cgroup_id: return &bpf_get_current_cgroup_id_proto; @@ -7269,6 +7273,11 @@ static bool sk_msg_is_valid_access(int off, int size, if (size != sizeof(__u64)) return false; break; + case offsetof(struct sk_msg_md, sk): + if (size != sizeof(__u64)) + return false; + info->reg_type = PTR_TO_SOCKET; + break; case bpf_ctx_range(struct sk_msg_md, family): case bpf_ctx_range(struct sk_msg_md, remote_ip4): case bpf_ctx_range(struct sk_msg_md, local_ip4): @@ -8605,6 +8614,12 @@ static u32 sk_msg_convert_ctx_access(enum bpf_access_type type, si->dst_reg, si->src_reg, offsetof(struct sk_msg_sg, size)); break; + + case offsetof(struct sk_msg_md, sk): + *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_msg, sk), + si->dst_reg, si->src_reg, + offsetof(struct sk_msg, sk)); + break; } return insn - insn_buf; diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 146c742..b95bb16 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -3641,6 +3641,8 @@ struct sk_msg_md { __u32 remote_port; /* Stored in network byte order */ __u32 local_port; /* stored in host byte order */ __u32 size; /* Total size of sk_msg */ + + __bpf_md_ptr(struct bpf_sock *, sk); /* current socket */ }; struct sk_reuseport_md {