From patchwork Thu Oct 14 14:25:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12558647 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10241C43217 for ; Thu, 14 Oct 2021 14:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB8F161130 for ; Thu, 14 Oct 2021 14:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbhJNO2L (ORCPT ); Thu, 14 Oct 2021 10:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231822AbhJNO2L (ORCPT ); Thu, 14 Oct 2021 10:28:11 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B50DC061570 for ; Thu, 14 Oct 2021 07:26:06 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id i12so20073940wrb.7 for ; Thu, 14 Oct 2021 07:26:06 -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=8+uJr5hp/PrwImyhLww643udSk+FgvtkOnzEH/iiMXA=; b=x2fzdmMSRhyCU3dbpcXq3f4TOFHCtRAG3Q2rGhe2H5ELOT1CpqVXnBWY1E3z6p5u6C W2kl7W/6+YTDBSd7Xj3o7MEX3e1NCRMRa4TPCQ3Ns9C12d4kU5pd2phJhneXg8LJ0J4r 8Q8mXJ3vykXbQQ4lxkMZBGAQL7gL65H60WsU0= 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=8+uJr5hp/PrwImyhLww643udSk+FgvtkOnzEH/iiMXA=; b=ZnH19QTIvZsIadP1NcDCH/PwC2YnP77CbgZFM4bFCRZ7dvKrGKmMYWrpM7OSKccOJe tGsiiA4xnZHk8kbNqVTuZ6Ydp2F/auVLOFHH8oCaGcbm0RrGpZ9AjnVRXamig/RRw5jF pxqRnoVazT+DtV4tYwSdOPSdwOTTdsMOpDKpi2aKPmM0jSli1/u8sToShd7xLDa1CPc8 zLgs3gy/AU+ucJpqgpy/JOHEvYh3JHJW96tcO9MpI+jv0xdoQfrE6qhTm1mVPigi0IhI IIt6cJIhJ32/16olMo5AwpFwba7iH+Bsjv8X9sFXWL52jySJANxnYQbgr0nd4tttLOQr MlHQ== X-Gm-Message-State: AOAM530ybwApDG+5RTDn5+5CRZgGF/Z3VFntNGRbPPpvtsR8QT11xMJW Ww/29TJDWciJ06ZxolLBDLibvA== X-Google-Smtp-Source: ABdhPJxSreZiUluGclCO7ih/fTRXwuaw9OMXuN55jnTqByIvdDxPXk6++hqqara4PlR/5NHW91bnrg== X-Received: by 2002:adf:aadc:: with SMTP id i28mr7004852wrc.320.1634221564751; Thu, 14 Oct 2021 07:26:04 -0700 (PDT) Received: from antares.. (4.4.a.7.5.8.b.d.d.b.6.7.4.d.a.6.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:6ad4:76bd:db85:7a44]) by smtp.gmail.com with ESMTPSA id e8sm3731111wrg.48.2021.10.14.07.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 07:26:04 -0700 (PDT) From: Lorenz Bauer To: nicolas.dichtel@6wind.com, luke.r.nels@gmail.com, Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Paul Walmsley , Palmer Dabbelt , Albert Ou 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 v3 1/3] bpf: define bpf_jit_alloc_exec_limit for riscv JIT Date: Thu, 14 Oct 2021 15:25:51 +0100 Message-Id: <20211014142554.53120-2-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211014142554.53120-1-lmb@cloudflare.com> References: <20211014142554.53120-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Expose the maximum amount of useable memory from the riscv JIT. Signed-off-by: Lorenz Bauer Acked-by: Luke Nelson Acked-by: Björn Töpel --- 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 Thu Oct 14 14:25:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12558649 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77AEDC433F5 for ; Thu, 14 Oct 2021 14:26:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6124960EDF for ; Thu, 14 Oct 2021 14:26:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231849AbhJNO2O (ORCPT ); Thu, 14 Oct 2021 10:28:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231822AbhJNO2M (ORCPT ); Thu, 14 Oct 2021 10:28:12 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F073C061570 for ; Thu, 14 Oct 2021 07:26:07 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id r7so20120178wrc.10 for ; Thu, 14 Oct 2021 07:26:07 -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=RmhVf07oF6025wnab8G9e3JeuNPyTuS8nYqhI375yVQIL0U9eUmLhzjtuwOVtNWage l9C1jkYM8uhpYDHf9otaq/XTvm2rgfq0akCikV7qkC4iTfaB4nKogtvA+vhRnruVnbD+ cOkkxtYNiiEdWIWE4OgPf56KWAs6Yw/rBVpRQ= 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=2d2Trox4IdSootnlVivkno7C/hpnheW4lbhK7aKCDPnMqQfpAiZqQ2VLlzTOkb4a4Z gXwlhNLaVA4zZrPh/jPCAwWS5UfSNL7jJfuoBc0DhC0lR5iN9gBXlx4UhqkVC1NUr9xe 3NtNFo/Hssz+X+b3yJNdIplxyQNYOHfF+L/i5WBylh3XmiVC+zyvdp7vovXjoBKAG3OL m4Rsy6q/T/5kepZfOAMyjBcqNm7nL+2pVzGhuVIsHi0z2FLjtx8RWwa7WTUlf9zPd9oC 9LDZzQ/jKP2t7OSkJzQHsvwREIM/hy+aiTONTmG9dognGLzyWEqKqvH/HO2f1zKNcuu5 87VA== X-Gm-Message-State: AOAM5327knjLXGf5QXFbNDBiCPM1fxrZb0dWj6DKIh5vSukSBj9Joy9U gyU0UDwrVVU8C0L6DqSNrQp7Yw== X-Google-Smtp-Source: ABdhPJwA6roeFKn/hKn+FsDIjFD09EJZXyjCtR2peO46ZQ2mwsy86VrESVOK+e2yhDFIHOma2liu8w== X-Received: by 2002:a05:6000:1aca:: with SMTP id i10mr7234743wry.207.1634221565929; Thu, 14 Oct 2021 07:26:05 -0700 (PDT) Received: from antares.. (4.4.a.7.5.8.b.d.d.b.6.7.4.d.a.6.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:6ad4:76bd:db85:7a44]) by smtp.gmail.com with ESMTPSA id e8sm3731111wrg.48.2021.10.14.07.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 07:26:05 -0700 (PDT) From: Lorenz Bauer To: nicolas.dichtel@6wind.com, luke.r.nels@gmail.com, 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 v3 2/3] bpf: define bpf_jit_alloc_exec_limit for arm64 JIT Date: Thu, 14 Oct 2021 15:25:52 +0100 Message-Id: <20211014142554.53120-3-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211014142554.53120-1-lmb@cloudflare.com> References: <20211014142554.53120-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@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 --- 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 Thu Oct 14 14:25:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12558651 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD634C433EF for ; Thu, 14 Oct 2021 14:26:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA11260EDF for ; Thu, 14 Oct 2021 14:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231861AbhJNO2R (ORCPT ); Thu, 14 Oct 2021 10:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbhJNO2N (ORCPT ); Thu, 14 Oct 2021 10:28:13 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8620C061762 for ; Thu, 14 Oct 2021 07:26:08 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id r10so19994711wra.12 for ; Thu, 14 Oct 2021 07:26:08 -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=lgl8mZ/YrF8TfvvRQz3SdK85Z+G04kK8iCOR7zSeTw4=; b=Lkoux+c6UA1oHasGJ/r8HQtqbC5B9HrSLLHEkQAG3UQGRAXXBugFRBQSfv3RJcZ9rf LEJ6dsMUgbYfWleimFXH3kfT8MDUsXnlZAv5pr8HOBsD/bYgM++k1B4dqqj9G7Q13Dd8 BV2f3zEPg0PzEYuK+1yQV0Q0r5oy4LaIQqnnY= 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=lgl8mZ/YrF8TfvvRQz3SdK85Z+G04kK8iCOR7zSeTw4=; b=7SsztrPMYDN4HzKHbOQwZ8gXpPrjzS+DdJ6ObAKl2Kpe7kVk5Qy5FEDSVNch+Z/8U6 qbbMYEs8B1Z9pvGtHz+/xhNSkoqB12WEXTBmO+1MxsYlpwqg3ZvMvNZfym0RcYLau1Qy CYNWkt1/tZ/9ld/ElBMAqhwUNWK1wUucIDMWoxfZy+60PTu1mnYcATNL+3hU+rNIfdSp yoMByDRXDmMgsSQUp2c+EclOnHUSKdr8bGX5UmnUzjTLW2q40zO4DH1dvlnGGx22VPI4 8LcaMow42htBz57kRSO962Yg15teAPFXwsiulG3GfdPsV6j7O5WyY7vnGoxc46RXLyaP 6wwQ== X-Gm-Message-State: AOAM531DWn1oJQzLRD3sckFB6qjpmzBmhXxX166UOnNdiitolY1cTinj aV+YLhF3VW3nxLlDlbSgXlb94w== X-Google-Smtp-Source: ABdhPJzukZ7AV61dROfIxRv1Lfgv+4xIL2tgaMjZiAoRX7cQziN9II70oV45qMpSTCcq+p7wQN86qA== X-Received: by 2002:a5d:6d86:: with SMTP id l6mr7055659wrs.96.1634221567412; Thu, 14 Oct 2021 07:26:07 -0700 (PDT) Received: from antares.. (4.4.a.7.5.8.b.d.d.b.6.7.4.d.a.6.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:6ad4:76bd:db85:7a44]) by smtp.gmail.com with ESMTPSA id e8sm3731111wrg.48.2021.10.14.07.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 07:26:07 -0700 (PDT) From: Lorenz Bauer To: nicolas.dichtel@6wind.com, luke.r.nels@gmail.com, 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 v3 3/3] bpf: prevent increasing bpf_jit_limit above max Date: Thu, 14 Oct 2021 15:25:53 +0100 Message-Id: <20211014142554.53120-4-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211014142554.53120-1-lmb@cloudflare.com> References: <20211014142554.53120-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@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 47f80adbe744..8231a6a257f6 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1050,6 +1050,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 b6c72af64d5d..ab84b3816339 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -525,6 +525,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) @@ -818,7 +819,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 {