From patchwork Sat Nov 17 18:57:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151417 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp808718ljp; Sat, 17 Nov 2018 10:57:32 -0800 (PST) X-Google-Smtp-Source: AJdET5ejD0Ja1JszN4/O9WRaKOPZJOtup2Me7wvvC8JyQI6FyZ63w3tEzH2WsSHMYYgVZ8BsPfK7 X-Received: by 2002:a62:220d:: with SMTP id i13mr5136451pfi.162.1542481052303; Sat, 17 Nov 2018 10:57:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542481052; cv=none; d=google.com; s=arc-20160816; b=FSu4WxHrmgtJKRyGRbTGNFXegKXoREZZzJWSwaG90+K45CfOLlAc1rDsXhIV1GYHQA sqis3LB9io3Pccf5KepFpliHOIlE6GBZaxjkN9dD3odXWBG8fSVzj0qs7x/vWSNDLa6n 3KA8gh+peeoG0Kn+jjkM/qC3jsgaB6/SD9uOgNV76WiSdfTU2Rs6UdUrVPB4VmIHzMsg c7gAuV/1CiDcYg8/uLmF3Sx4mtmi3xYI8e1V9JEix0g+iPtnF4Tl0/i7aOqpgzd28lZY 8gJDLrcffAgE2ZsoCPI60O/rsG4t4XDhvYZQnXtqI+8vhVMbfaicUHejhQdwFYT0lzGx ttjg== 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 o68si346275pfo.140.2018.11.17.10.57.32; Sat, 17 Nov 2018 10:57:32 -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 S1726964AbeKRFO7 (ORCPT + 32 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(-) -- 2.17.1 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;