Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2065493imu; Wed, 21 Nov 2018 06:16:30 -0800 (PST) X-Google-Smtp-Source: AJdET5dEIrPcGHq2Dhg3XyDVsaGx9CaKksfFTPCqRH8EdcDaVfLpKPbD9+MPD78R2Uu7PD07xEdA X-Received: by 2002:a62:509b:: with SMTP id g27mr7068729pfj.48.1542809790673; Wed, 21 Nov 2018 06:16:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542809790; cv=none; d=google.com; s=arc-20160816; b=wxpJH20zdFdFY/leoSqxFeL/OqZOT0KYqRqfL1WxgR1vEE+1SdchTP2guLkqOxp5ai 8+k4hfxPQll/t8F66WAA8hYbu9o4cUYnrXdxXPcGqPFV/Gfuq5RGd6vsPb4tPiI65e2k 5o4fh96eEfgfs25M50NgwvsYpiolK3ddO5Jo1JEkE+MzWhwU4KejOr2G//QFgau2v/Er WXSVdFFB6RKZAmDucccJ6YqotqoGRQfdAiErtMfjUkIJciyjSi/6FaPxz3PKvXtjvoY0 cG95tgN0FbYtfOcvnoMJMzFdCFxo5koKBCIj3Zzd2QGTlYyToWOJSaS4l3IIdDCl5dgW 3xwA== 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=MYs0Qup+kKVUQb/IfUObkJlJ+Fjala9xEnkQB4UC89I=; b=WVp368lHWyAySyuRnMhi83hZx9sqhmfeiSK4+7ppYb/HFf76uBzhN32VPO8Wv1uzpf 02+i5hB46mURUT9/JUNro4CQH0fiiR34mxA2ZA2NFjVv0EFDSU6CZ3Q88aKWigrEPf3K qxAk4Hja3CyM1WqvyzfGAcII0+6birmTslRnQLwu5DrLv74L8CZ2nNG8PPkwaHxM/VmD 2VuJG7vh389E2+i0dh/ZZSwJkjQDtkVILLRq0bWes6lh3FcdTVKx+MyoKzO4ZjCtG55Q y+lUkRE/AVSOiyJClaDhtAadg1F8Umhagl2z14a61mSfLoedbJNAMwaLynAzuaYwr7U9 kDNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Kr8MbQ/F"; 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 k38si16588879pgi.235.2018.11.21.06.16.14; Wed, 21 Nov 2018 06:16:30 -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="Kr8MbQ/F"; 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 S1730972AbeKUXwJ (ORCPT + 99 others); Wed, 21 Nov 2018 18:52:09 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:42977 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730934AbeKUXwH (ORCPT ); Wed, 21 Nov 2018 18:52:07 -0500 Received: by mail-ed1-f66.google.com with SMTP id j6so4843348edp.9 for ; Wed, 21 Nov 2018 05:17:45 -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=MYs0Qup+kKVUQb/IfUObkJlJ+Fjala9xEnkQB4UC89I=; b=Kr8MbQ/F6Y/x9T5DEV283Q4otL3mpHVSySGp6QGGdlFneYPQCIcZ81V3nFFm5gbfvk /h4YrvBiNU8HxM5HNsH9vWbygI7GLzDiHMGg/3nM/a2a5sGZ1ewObuZ2xAGLvURd0qA0 Rap+LMykouLcOMjSe+5TJ43OAV43KpYfLl9gM= 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=MYs0Qup+kKVUQb/IfUObkJlJ+Fjala9xEnkQB4UC89I=; b=HWoRv2gfLWbDINoIAfNo534ayxup4tBAWsXIdFnxvWl9K+VjMWWVgXrmEDOs0QEr1s jIGT9OVi2AoTQyoohLRgzBuZM8A3+5wW29YTd7q9DGNpg042M5GmD325Fl7O9I9ckP82 X+pmnEezcobILIjvEfhrXX4M2wtJPYzL+/Sem9c+EI4Z0ga1vwFyimDL9YXYZRHVIymv qLVlT6B2niq3q94K1zXFrhRMW6ccrFz8d1ajyBQ3w8TlKq9I6WYtQ5eI8LK2PyLU24MZ 3M1e03DllM7+LzNMaEPYXVcCJXcOMlo9G1EeWuR4cN7SGSg1g2JVtpUvaiCFb9oV/kyd v27w== X-Gm-Message-State: AA+aEWaylZu4QqdgUJArYl/+POASGGsVOHaM8bInqdqJUiKRyhrMKka4 P3xxRQyqQek9s1ozs2O8U7AHmw== X-Received: by 2002:a50:8c21:: with SMTP id p30-v6mr5754586edp.34.1542806265016; Wed, 21 Nov 2018 05:17:45 -0800 (PST) Received: from mba13.wifi.ns.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id f4sm11501597edb.21.2018.11.21.05.17.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 05:17:44 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.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 , "David S. Miller" , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 2/2] arm64/bpf: don't allocate BPF JIT programs in module memory Date: Wed, 21 Nov 2018 14:17:33 +0100 Message-Id: <20181121131733.14910-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181121131733.14910-1-ard.biesheuvel@linaro.org> References: <20181121131733.14910-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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index a6fdaea07c63..f91b7c157841 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -940,3 +940,13 @@ 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_free_exec(const void *addr) +{ + return vfree(size); +} -- 2.17.1