Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp863192imu; Sat, 17 Nov 2018 10:59:00 -0800 (PST) X-Google-Smtp-Source: AJdET5cN0OzoE1WFJ6vsFYCgyMp0ZwK5bQ4VBgfLem2Bc2LCSVRjUyHxlvsdZnv1/DEGbVdxiMzG X-Received: by 2002:a63:f811:: with SMTP id n17mr14803864pgh.23.1542481140559; Sat, 17 Nov 2018 10:59:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542481140; cv=none; d=google.com; s=arc-20160816; b=RF2PlcaYbEPZxn50TrrpZmXPqdSiYPbX8lRHON/V32XJdJyNyqPoKpu/MC96xHINey LPLCfA3+uiuRt3G+6IVsxLn3EsSod525iD1ZIuesQ9Ii+4UItVLWy9AS3mIPS9vu3haR kN/BMlmFq44CYC29BodCtHT/+01/xd6RxUIzcMK6Jti8siKOARzWaioNe4hSwY1MZXIX 6GbOYmaDBNU7qLSeWDwlVETzb/U1TiTBqt27Ui+bMzUvlBRPhyMhDKyJPtPX+gucAhWl VKjVwxc/1QJfeL0D9/f4/nvufuNr+6q/mCD7nu+a8peFOaoD2FWVAjzmyXudRE4Z7VX2 1tJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=JmtMWaiD9FenKM3ns0kNxP2J4QR+RUeNI/5TJ/tQ45I=; b=bKIpP8FcOpu9IUkjLlpvNrHEit7pVJN2ciDqrfstJH9Z3TYUYiYvwzIJarCvbr5+nC cPrg230DOCHP2qyCDLW215RLk6rEplfG2IwbGLl8QQrbBMuV+5bNR1yLO6yGkOi2Btjh pM+2hAOY6JXy9x43LH9KIoo1TmAnhK+iQKUTjUwBjCjmh5DidDhleSuWPIeb9QYmGNCt U/NG1+kYxFDKPJD0W5vxwTl6l83cbTPdyU9sRlHB7O1kmsjL0hRPQk2szMNyaOvvBwS5 Yeah2RKTTRFFGt6880+puQwc2nIJXxMam4/H9sxy869lDUKld52gzvt4FvUbBrBZyQkb F24Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KAW8uS2e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1-v6si33842593pll.325.2018.11.17.10.58.30; Sat, 17 Nov 2018 10:59:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KAW8uS2e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727002AbeKRFPC (ORCPT + 99 others); Sun, 18 Nov 2018 00:15:02 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44821 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726075AbeKRFO7 (ORCPT ); Sun, 18 Nov 2018 00:14:59 -0500 Received: by mail-pg1-f194.google.com with SMTP id t13so3370539pgr.11 for ; Sat, 17 Nov 2018 10:57:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JmtMWaiD9FenKM3ns0kNxP2J4QR+RUeNI/5TJ/tQ45I=; b=KAW8uS2esdTjeBcDfFodpTuBiPuzrfOgpEvhmkdmizzqp7CMEjaFC2ORlF9MeL+yeA stdwlyxwK9cJAK+MAYm3DEfW4lRgMCiJRj3yewaXsrtQx5DmclC4R/K9qjVetVNcal+H pjN2zNK/65b6+lBFp6r24jInRxn3xDvrMAU8w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JmtMWaiD9FenKM3ns0kNxP2J4QR+RUeNI/5TJ/tQ45I=; b=YEIsmFVSBYnhjdSigYWZNQspV57qmBZwZGm0A1P7RMFOTX/EzHn+vnRLnk3hQSf4C9 HW75HkBjmyIRrmHV5JV9smK3DYd7gD31QnbiwodYoatjon+IqAd7xHqeJIIJF4FUd79G Hm7K0FiSdBwF5wLMMTQfbi+lMRvOMJRG5o5XUjGSi1z/WITnprL/WY7JIc64NLSV35Nf owyhysd9vIj/H4kpsJA/fi4qXXKGmIxG7Tw9tSz/SVPGzQSAhyiGT0v0SGopcu0DAPsg CQbQZNk9GOykhmHpDQEQCMaE8LLHcpVX2vrVp70zvJ+CusK/WwIMpf5nFpgVTcqqxZsV VL6w== X-Gm-Message-State: AGRZ1gI27cUyl8d9HDg/ftqaMrjrQCuDqJP9U1N+sOjH1qRNJAf9DDv4 gd6tNlALa/G/jUsCl+v0uvEEBWS2eWHOLQ== X-Received: by 2002:a62:ed09:: with SMTP id u9-v6mr16036733pfh.188.1542481044594; Sat, 17 Nov 2018 10:57:24 -0800 (PST) Received: from mba13.psav.com ([64.114.255.114]) by smtp.gmail.com with ESMTPSA id u76-v6sm49550745pfa.176.2018.11.17.10.57.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Nov 2018 10:57:23 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Daniel Borkmann , Alexei Starovoitov , Rick Edgecombe , Eric Dumazet , Jann Horn , Kees Cook , Jessica Yu , Arnd Bergmann , Catalin Marinas , Will Deacon , Mark Rutland , Ralf Baechle , Paul Burton , James Hogan , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 4/4] arm64/bpf: don't allocate BPF JIT programs in module memory Date: Sat, 17 Nov 2018 10:57:15 -0800 Message-Id: <20181117185715.25198-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181117185715.25198-1-ard.biesheuvel@linaro.org> References: <20181117185715.25198-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The arm64 module region is a 128 MB region that is kept close to the core kernel, in order to ensure that relative branches are always in range. So using the same region for programs that do not have this restriction is wasteful, and preferably avoided. Now that the core BPF JIT code permits the alloc/free routines to be overridden, implement them by simple vmalloc_exec()/vfree() calls, which can be served from anywere. This also solves an issue under KASAN, where shadow memory is needlessly allocated for all BPF programs (which don't require KASAN shadow pages since they are not KASAN instrumented) Signed-off-by: Ard Biesheuvel --- arch/arm64/net/bpf_jit_comp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index a6fdaea07c63..e0c702c2f682 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -940,3 +940,14 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) tmp : orig_prog); return prog; } + +void *bpf_jit_alloc_exec(unsigned long size) +{ + return vmalloc_exec(size); +} + +void bpf_jit_binary_free(struct bpf_binary_header *hdr) +{ + bpf_jit_binary_unlock_ro(hdr); + vfree(hdr); +} -- 2.17.1