From patchwork Fri Sep 24 09:55:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12514853 X-Patchwork-Delegate: bpf@iogearbox.net 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 0E391C4332F for ; Fri, 24 Sep 2021 09:56:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF35C6124F for ; Fri, 24 Sep 2021 09:56:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245432AbhIXJ5y (ORCPT ); Fri, 24 Sep 2021 05:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245355AbhIXJ5v (ORCPT ); Fri, 24 Sep 2021 05:57:51 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63E03C061756 for ; Fri, 24 Sep 2021 02:56:18 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id g16so25672556wrb.3 for ; Fri, 24 Sep 2021 02:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3h7c0XVFr6N3jiF/U6QxDBsNOiGNhPsYCa4Km18D0Hc=; b=vKOH360OkdUSeBBmWUFXZK8VGjn3L5JmXcL6+bqa2xj579UoV2NU1xzoSlFrm708mm h5Jt8GHJe3mtqjujsS/u/O/LAfckAQvQGenJ/qLfLVMgl12xKd1MKcLBy/7EFiXXmBoL 69vXNFZ3z7kgjYILbRfdlOFB2Q/ewIENfeeLg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3h7c0XVFr6N3jiF/U6QxDBsNOiGNhPsYCa4Km18D0Hc=; b=ek3ZdxrOHd847S464oPNxTObtEwCLewYeAnWS4qVbczdTQY+DAUMjNmRqHjguAmD8l j/SwD+4ZJCiPoDpaPreJZqvfkYztgkdacSRxxsmWdVF9rd+Z1FpDMcSrWuzb3wiqQW9b LCCMYq9uOQT/R1IoKQBUv+VYLgnW66zaasVmxr2SgiJbugbs+ABunKhE3PK9OC96b7ct 1Ezly0FNeCinRqrgs6hC6WAlhu6Erak7bSuocxjeX1vGWjJ3GapR4YJDEvlwTbmILmID AeCw7XLMR7o6/w1LLni4AE7sZpSWTI3AITD1iHxuZUAGBEzETyQFg2VrDZVLRCDmMsHS zaBg== X-Gm-Message-State: AOAM531s2nVkr4nazx5zQrSDq1qwbacBIK3QARpdwDYm9C2aI/Ycdiuq mCoBw9hRm5Uiplg65am222ovFg== X-Google-Smtp-Source: ABdhPJxtHe+PjtTgQIuOLwSiU1zls++8SImNRIUOHlY0ZtTilLz8T0M+r62uqddhxQXzeoDR4eMiBA== X-Received: by 2002:a05:6000:1379:: with SMTP id q25mr10131509wrz.280.1632477376986; Fri, 24 Sep 2021 02:56:16 -0700 (PDT) Received: from antares.. (1.8.8.f.e.b.b.b.5.6.9.e.c.8.5.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:58c:e965:bbbe:f881]) by smtp.gmail.com with ESMTPSA id v20sm7871106wra.73.2021.09.24.02.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:56:16 -0700 (PDT) From: Lorenz Bauer To: Luke Nelson , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: kernel-team@cloudflare.com, Lorenz Bauer , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 1/4] bpf: define bpf_jit_alloc_exec_limit for riscv JIT Date: Fri, 24 Sep 2021 10:55:39 +0100 Message-Id: <20210924095542.33697-2-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095542.33697-1-lmb@cloudflare.com> References: <20210924095542.33697-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Expose the maximum amount of useable memory from the sparcv JIT. Signed-off-by: Lorenz Bauer Acked-by: Luke Nelson --- arch/riscv/net/bpf_jit_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c index fed86f42dfbe..0fee2cbaaf53 100644 --- a/arch/riscv/net/bpf_jit_core.c +++ b/arch/riscv/net/bpf_jit_core.c @@ -166,6 +166,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) return prog; } +u64 bpf_jit_alloc_exec_limit(void) +{ + return BPF_JIT_REGION_SIZE; +} + void *bpf_jit_alloc_exec(unsigned long size) { return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START, From patchwork Fri Sep 24 09:55:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12514857 X-Patchwork-Delegate: bpf@iogearbox.net 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 AC7C3C433F5 for ; Fri, 24 Sep 2021 09:56:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 952D8610CF for ; Fri, 24 Sep 2021 09:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245449AbhIXJ5z (ORCPT ); Fri, 24 Sep 2021 05:57:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245383AbhIXJ5w (ORCPT ); Fri, 24 Sep 2021 05:57:52 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A06CDC061760 for ; Fri, 24 Sep 2021 02:56:19 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id i24so9707596wrc.9 for ; Fri, 24 Sep 2021 02:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RRur22NBusGD90t4t5587ekzz3x5I1RHcVLT1FRWOPw=; b=ZD42DmzkPW2U+A4iJpC8iU2XyYMHKk9YKg9uFkDAbWvXW801p2Hu5cLrfTaUg4kAw2 2eQlDVG0jhv5r8Ceccp0DheyAO7BDxLhXFyhblIdL/rlTOph12MkI0OX9YB8TTHyGQ8A hFCiE7a6ev7YHx/N8MaLkClcCasu5gAUyu0bY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RRur22NBusGD90t4t5587ekzz3x5I1RHcVLT1FRWOPw=; b=6klOSN8IbkUtjz45vxVZYFOxsj378+xrrD4pZrZnl8RDXaE76Ryn8jBNyUS8+dNcY7 aM5RkBwwHi2y1zs562nnTLx+yu65em58yVXwiFPa0fUGXRPGme60W8A2A7bCQ9OB48FU tpV1o8tDocwKFlERFEpgSZVBkeNkfIrzSjPyZTxa1LRp7IBTeogV+hDmCG58zKR8ZE4b XDQhA4SknYvcc+evvbKljFoNQgKG/xFTt1lvbXiOA8iI40EGvjdwTS4MYEHaJJvRJsNH QEWCsMAXdTWi+41P2RhVgLg5SnPlsaHisIw79xa8pL3/NMMcr2wTxkv5h/IxvyLR8zUR Hx0w== X-Gm-Message-State: AOAM532T/A7uDnpz9JL6TU8Z2vpAioKS1l6QOfAgmlqGtdvcZdaqb8z+ qWgWTWVvpVULXr5HD7ESB5Dqig== X-Google-Smtp-Source: ABdhPJx7VqwMpBrGIroLZOsmZihp8ru4ncEtHJRlD9vTSP+bvxaBPO1HLlFCNTEK2gcCOmKarG7JZw== X-Received: by 2002:a1c:a713:: with SMTP id q19mr1109287wme.42.1632477378193; Fri, 24 Sep 2021 02:56:18 -0700 (PDT) Received: from antares.. (1.8.8.f.e.b.b.b.5.6.9.e.c.8.5.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:58c:e965:bbbe:f881]) by smtp.gmail.com with ESMTPSA id v20sm7871106wra.73.2021.09.24.02.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:56:17 -0700 (PDT) From: Lorenz Bauer To: Daniel Borkmann , Alexei Starovoitov , Zi Shen Lim , Catalin Marinas , Will Deacon , Andrii Nakryiko Cc: kernel-team@cloudflare.com, Lorenz Bauer , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/4] bpf: define bpf_jit_alloc_exec_limit for arm64 JIT Date: Fri, 24 Sep 2021 10:55:40 +0100 Message-Id: <20210924095542.33697-3-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095542.33697-1-lmb@cloudflare.com> References: <20210924095542.33697-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Expose the maximum amount of useable memory from the arm64 JIT. Signed-off-by: Lorenz Bauer Acked-by: Will Deacon --- arch/arm64/net/bpf_jit_comp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 41c23f474ea6..803e7773fa86 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -1136,6 +1136,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) return prog; } +u64 bpf_jit_alloc_exec_limit(void) +{ + return BPF_JIT_REGION_SIZE; +} + void *bpf_jit_alloc_exec(unsigned long size) { return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START, From patchwork Fri Sep 24 09:55:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12514855 X-Patchwork-Delegate: bpf@iogearbox.net 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 9E9B0C433FE for ; Fri, 24 Sep 2021 09:56:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89B8C61267 for ; Fri, 24 Sep 2021 09:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245452AbhIXJ54 (ORCPT ); Fri, 24 Sep 2021 05:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245422AbhIXJ5x (ORCPT ); Fri, 24 Sep 2021 05:57:53 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EECADC061574 for ; Fri, 24 Sep 2021 02:56:20 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id t8so25772196wri.1 for ; Fri, 24 Sep 2021 02:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0CNNuOuPK9wKje+YlF31CNcS9Cb8He0qIWrXOq09DgM=; b=ytSNvAbACk+V4wd6bEDLyR+m7sz0p29/e7Zc1NRLHvhWSR0lCtD1NuoFAT0hjjwZ/G vs0IBisrpZ9xA4yDdxrs3YC3MuypsCAAVQacVbYmrkCRKVXiLnHtgNjwHHBOUifu24dC eA4tRxl7f5UTI9hbdcxF6lxLhXekVC1c5MNlo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0CNNuOuPK9wKje+YlF31CNcS9Cb8He0qIWrXOq09DgM=; b=ZMwntsMvQYZC0cLQX4A4vt+lu/OXE1+diklB5U8/XH+rNiNCg/VkKCFkMReeIFZTjY NAErUVknztS1GSQxl8EQX6SwBz8foecgSRPR0jC9sIlO0L/6dl0wMujnL8sLoUMrHFCn SFnWfHltsNOV3HWdMFA4uQz5VGbOa7FBh8TmhJw10iBKM3x9wE9NMjpjcFuTnkSFyQLO bcOyXoz4a5rKIREkXZfbQxdhHPzF12sYuoP8GBw8+CjHiGgJx5zjr8ur/DkZGMAKrUu4 qT+fY1Xqr3PihRbukFSalK6mj8WunOjaqM5kr0SsAaCy+iZfroV76lyw0Ht6cO87TM37 qhBw== X-Gm-Message-State: AOAM531gPGFQImnHvM2SvsSNELwgPCcQHByAJnkJVkYpy7lCFZkcPC+T YIJbSWRx6Bo5ryGK7K6GL1xqtA== X-Google-Smtp-Source: ABdhPJxk2j4nV2vW4VF5ElLtZo7rkIEfDWzE9a+3mZRtcXpy6NKpbbPDIuzglmoO6D/bGygwBPkZ9g== X-Received: by 2002:a5d:56c4:: with SMTP id m4mr10432974wrw.225.1632477379485; Fri, 24 Sep 2021 02:56:19 -0700 (PDT) Received: from antares.. (1.8.8.f.e.b.b.b.5.6.9.e.c.8.5.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:58c:e965:bbbe:f881]) by smtp.gmail.com with ESMTPSA id v20sm7871106wra.73.2021.09.24.02.56.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:56:19 -0700 (PDT) From: Lorenz Bauer To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "David S. Miller" , Jakub Kicinski Cc: kernel-team@cloudflare.com, Lorenz Bauer , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 3/4] bpf: prevent increasing bpf_jit_limit above max Date: Fri, 24 Sep 2021 10:55:41 +0100 Message-Id: <20210924095542.33697-4-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095542.33697-1-lmb@cloudflare.com> References: <20210924095542.33697-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Restrict bpf_jit_limit to the maximum supported by the arch's JIT. Signed-off-by: Lorenz Bauer --- include/linux/filter.h | 1 + kernel/bpf/core.c | 4 +++- net/core/sysctl_net_core.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index 4a93c12543ee..ef03ff34234d 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1051,6 +1051,7 @@ extern int bpf_jit_enable; extern int bpf_jit_harden; extern int bpf_jit_kallsyms; extern long bpf_jit_limit; +extern long bpf_jit_limit_max; typedef void (*bpf_jit_fill_hole_t)(void *area, unsigned int size); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 6fddc13fe67f..e844a2a4c99a 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -524,6 +524,7 @@ int bpf_jit_enable __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON); int bpf_jit_kallsyms __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON); int bpf_jit_harden __read_mostly; long bpf_jit_limit __read_mostly; +long bpf_jit_limit_max __read_mostly; static void bpf_prog_ksym_set_addr(struct bpf_prog *prog) @@ -817,7 +818,8 @@ u64 __weak bpf_jit_alloc_exec_limit(void) static int __init bpf_jit_charge_init(void) { /* Only used as heuristic here to derive limit. */ - bpf_jit_limit = min_t(u64, round_up(bpf_jit_alloc_exec_limit() >> 2, + bpf_jit_limit_max = bpf_jit_alloc_exec_limit(); + bpf_jit_limit = min_t(u64, round_up(bpf_jit_limit_max >> 2, PAGE_SIZE), LONG_MAX); return 0; } diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index c8496c1142c9..5f88526ad61c 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -419,7 +419,7 @@ static struct ctl_table net_core_table[] = { .mode = 0600, .proc_handler = proc_dolongvec_minmax_bpf_restricted, .extra1 = &long_one, - .extra2 = &long_max, + .extra2 = &bpf_jit_limit_max, }, #endif { From patchwork Fri Sep 24 09:55:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12514859 X-Patchwork-Delegate: bpf@iogearbox.net 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 56170C433F5 for ; Fri, 24 Sep 2021 09:56:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D850610CF for ; Fri, 24 Sep 2021 09:56:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245439AbhIXJ6J (ORCPT ); Fri, 24 Sep 2021 05:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245443AbhIXJ5z (ORCPT ); Fri, 24 Sep 2021 05:57:55 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F8C6C061757 for ; Fri, 24 Sep 2021 02:56:22 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id d21so25510602wra.12 for ; Fri, 24 Sep 2021 02:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QzgR0BqQv/FPhfZPF5T0qfZHuwykiaSgdLA+aUJj4v4=; b=NXWVy3Jr0UbQxas9exfy/W4mG5xTI82Js+uuM1UUbejUWm8M1FxV6s1tTFwVbs+IKm UQPSTwVg6pj4ZlPnkONB3VfiCPDELulXSdKQEGpEDXu+KGR7RsEuz7O83y1HMbhcurxd XnP6EKcWoTaYS/8gZMJ7eGfVPtt4rXJxKduqg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QzgR0BqQv/FPhfZPF5T0qfZHuwykiaSgdLA+aUJj4v4=; b=pmPZBbP48lsUP2qCRJ+roCRUtceyUuydwWA5PLowJk+27Uj6qOJ1H46lt4XxXAxO2M sooK50OE6nmKSmHzb8pTmWQ8CVy4sBaYwUYT1b48rnGg2FVaQIJBgcy8vWO9XsYWtwmh qonJsiigZpZUd91EORCGep6cCJKX+uvnX4b96tpW38MjJnSWJkzeNPh6RXo+7zkDpn8b UaveP0tKh5N9NIc98I5Mc7gj+beVIWSuCGvMp4FJuH1p40wtwyiAoge0oZp3nswOqKbo dTCnW1+pkgdTvZHZ6swdVunebCApCuyOKA10ze8vaBfGCxAWz2mDrpwvncoWo4QaFbmB zvhg== X-Gm-Message-State: AOAM531/sl0kPnGCvfXAFDPJlMEhXfpR2shrdimV93Rlg6GDMmoRctcP yK/7a2n21LLLVgTKziRtdh4XuA== X-Google-Smtp-Source: ABdhPJw9dKmwRCKWobc24inKFMURnJ/SXNNtMuE6CNiKmo4sm+L1ffxQuSZ6reyd8y/eaSRhTDq3Eg== X-Received: by 2002:a05:600c:4f54:: with SMTP id m20mr1161495wmq.96.1632477380954; Fri, 24 Sep 2021 02:56:20 -0700 (PDT) Received: from antares.. (1.8.8.f.e.b.b.b.5.6.9.e.c.8.5.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:58c:e965:bbbe:f881]) by smtp.gmail.com with ESMTPSA id v20sm7871106wra.73.2021.09.24.02.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:56:20 -0700 (PDT) From: Lorenz Bauer To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "David S. Miller" , Jakub Kicinski Cc: kernel-team@cloudflare.com, Lorenz Bauer , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 4/4] bpf: export bpf_jit_current Date: Fri, 24 Sep 2021 10:55:42 +0100 Message-Id: <20210924095542.33697-5-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095542.33697-1-lmb@cloudflare.com> References: <20210924095542.33697-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Expose bpf_jit_current as a read only value via sysctl. Signed-off-by: Lorenz Bauer --- include/linux/filter.h | 1 + kernel/bpf/core.c | 3 +-- net/core/sysctl_net_core.c | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index ef03ff34234d..b2143ad5ce00 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1052,6 +1052,7 @@ extern int bpf_jit_harden; extern int bpf_jit_kallsyms; extern long bpf_jit_limit; extern long bpf_jit_limit_max; +extern atomic_long_t bpf_jit_current; typedef void (*bpf_jit_fill_hole_t)(void *area, unsigned int size); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index e844a2a4c99a..93f95e9ee8be 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -525,6 +525,7 @@ int bpf_jit_kallsyms __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON); int bpf_jit_harden __read_mostly; long bpf_jit_limit __read_mostly; long bpf_jit_limit_max __read_mostly; +atomic_long_t bpf_jit_current __read_mostly; static void bpf_prog_ksym_set_addr(struct bpf_prog *prog) @@ -800,8 +801,6 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog, return slot; } -static atomic_long_t bpf_jit_current; - /* Can be overridden by an arch's JIT compiler if it has a custom, * dedicated BPF backend memory area, or if neither of the two * below apply. diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 5f88526ad61c..674aac163b84 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -421,6 +421,13 @@ static struct ctl_table net_core_table[] = { .extra1 = &long_one, .extra2 = &bpf_jit_limit_max, }, + { + .procname = "bpf_jit_current", + .data = &bpf_jit_current, + .maxlen = sizeof(long), + .mode = 0400, + .proc_handler = proc_dolongvec_minmax_bpf_restricted, + }, #endif { .procname = "netdev_tstamp_prequeue",