Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp863195imu; Sat, 17 Nov 2018 10:59:00 -0800 (PST) X-Google-Smtp-Source: AJdET5c49kYLqEUz3E6sHJfVFjm0bpBUgdNos7DoXZugLrBgZQRLOjtrwGHqk74JtWhlWKORg3Qv X-Received: by 2002:a63:de4c:: with SMTP id y12mr14382848pgi.198.1542481140562; 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=jNVjlc6ZW6+0L9TPhs8GXTk5fTSN4scMymX0+Kf40MrPN78F9jRbLjFT2z3WenRiIP XWmyymb8MjTqhIiAkB+dpwz5U1F5qnmYPwq4IkVWPgfQPR8JL8MiLY2GtrNS8kHXG+SQ LWZO29CvE4fgk2EAhqpDaFMp7iqmV8oH/QGkiYiMlwmKnVS8MzbEmItiC2CU54TIieZQ ATFe9dkx2PMWlhPtxbMXHDrMcMjBMf2aAI5xMoHVl7w4fJLh85s4YoQR86BMsJaBukw1 7PD9+APUMBKJ4steZNFevScAtpIWP5kMwm2268MU6oOGxVoZm+9XB722oKgbZe0ksTOu CZ5g== 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=26kHMy6e9ZHNMFq26DfYcP5qT10rPVni7XnqYDLJuPI=; b=K6Yok64HSIU5lolmYYFS6z3LddYAaa4J2b7Uqn4RNHnnRBWz0N8uJe/jJtE4q0vzgg /SozOjjGA5njdNP+8+eOhPG/MKdL8q50T4H4yH6j6Qe1QFr8X+sK45mLO0mEdV8diinW f479HZykDt42G7WNKb97epFFwsQGyA3DAgWaVTlStnfPRb/Khw8/HV/+7visYsJqAiU/ eozB46ucrL4uKPcY9ZWmsleWFSbhMjkKZ5jEWKqT1+oPuE/Uv0YbH9tCZ5q8r71hZ96c fIZuPxp51Bytpv1yDWp7v3ZhPEX7sCiVWvgXnAf9MdIRigAlgPEYBoIvm9rjli8F0rVH smmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XYLhyO5m; 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 d14si34280065pgn.390.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=XYLhyO5m; 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 S1726958AbeKRFO7 (ORCPT + 99 others); Sun, 18 Nov 2018 00:14:59 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36520 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726075AbeKRFO6 (ORCPT ); Sun, 18 Nov 2018 00:14:58 -0500 Received: by mail-pf1-f196.google.com with SMTP id b85so6107599pfc.3 for ; Sat, 17 Nov 2018 10:57:23 -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=26kHMy6e9ZHNMFq26DfYcP5qT10rPVni7XnqYDLJuPI=; b=XYLhyO5mN3FVA4ReKitsYfMKGuHNDNlOhuo5CX3m1WdOPZeKdKBplc4oZZ6V6yFg5A hQ83SmcdvQq6M0spjr5rwWJUh9QdiW39oPX0Z2kNZVWF+j0XU6sZnr/m82angEa1AG65 GQ2t7WMlRjYOWyc5If1zGyUDez/kBmIctb+b4= 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=26kHMy6e9ZHNMFq26DfYcP5qT10rPVni7XnqYDLJuPI=; b=tPWg68MXt/9Md4RUxKgqgXn0DH646P3GCjKcjMl+Bd8gEnc5YgOgLZgeb3KMtc54YD 7NmXUkOyOdwGNwjE3LP/qlP20SKrsN3HaIkcSUWzx2nOaJ14KWqhvmR4BLNuxPHSOxq8 gTj6zm9hZntO1izmhx+ZkzKRmOPMIaAS8/WmShPqaOXXSDKU2ZCQeKbXjADRd630wdBr xh5R6HQxw4bFavwbc9j8ZFEkpCl3tBSnOr/aLV2DjTTFSB15e8YsyynjrRZOkTCu5tpD k6h33v9bhpzetuyTUX6n5aEVyLXsZsJnZLmv9/5cDtlzG6zQMVzwrQ1fJIs2KEN9z4Cw nJpg== X-Gm-Message-State: AGRZ1gIMqkinDUCR3MH31Vv7/z5pE1YGSqNJMtjw26573DlHiCBrPnCD Xkm4WaBEwWYqum+53T3eoi2Af6PVPvzjTg== X-Received: by 2002:a63:f241:: with SMTP id d1mr14569834pgk.2.1542481043353; Sat, 17 Nov 2018 10:57:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Nov 2018 10:57:22 -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 3/4] bpf: add __weak hook for allocating executable memory Date: Sat, 17 Nov 2018 10:57:14 -0800 Message-Id: <20181117185715.25198-4-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 By default, BPF uses module_alloc() to allocate executable memory, but this is not necessary on all arches and potentially undesirable on some of them. So break out the module_alloc() call into a __weak function to allow it to be overridden in arch code. Signed-off-by: Ard Biesheuvel --- kernel/bpf/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 29f766dac203..156d6b96ac6c 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -609,6 +609,11 @@ static void bpf_jit_uncharge_modmem(u32 pages) atomic_long_sub(pages, &bpf_jit_current); } +void *__weak bpf_jit_alloc_exec(unsigned long size) +{ + return module_alloc(size); +} + struct bpf_binary_header * bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, unsigned int alignment, @@ -626,7 +631,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, if (bpf_jit_charge_modmem(pages)) return NULL; - hdr = module_alloc(size); + hdr = bpf_jit_alloc_exec(size); if (!hdr) { bpf_jit_uncharge_modmem(pages); return NULL; -- 2.17.1