From patchwork Fri Nov 23 09:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151850 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1852700ljp; Fri, 23 Nov 2018 01:42:12 -0800 (PST) X-Google-Smtp-Source: AJdET5eDFHUbu+QR3EfuLSGYv44iqM6O/8UgmB4nvojUfBLAPCNS0O/ozY/MLZVmkJrblP8VWwze X-Received: by 2002:a62:647:: with SMTP id 68-v6mr15764217pfg.42.1542966132636; Fri, 23 Nov 2018 01:42:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542966132; cv=none; d=google.com; s=arc-20160816; b=JNwOy+JJIAo0S6e0XwFDboFpQpWjPSXRYK09eeTe60g44HPy3VfHFDzJyeOaeuLmAB jhCRMQGnrZFUWuJLqhVAw+K1Yhe0RdxN+75dXoIx7jMHlMOYLwjMUUZ66XjgTuKqBcZK bP/eLUsfuTAEhROrWJKARL2Wod8d1H8COO9X2nKhuaVjQhYMqf8BbeXu3z0WzNq2guCn 9EB2jrd1uKlYH/mWiKVr/dEoRPJKZ1C2X7oeH7rT7VdKqaqX2/ve1XUbxiM1qO3KYewT WYRJWyQa/esJJCIKV2e4gaWzZp+CK7AhuR0UJ1KOqmQTYA46/lLVdNsj71GeMVi8NRIX vEZQ== 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=v8u1be1RwPj+OIivYZiNyoEvuwKWhLSeAuAn+o4TaVM=; b=dZNUMUwEl9vsgeox1qOlLfxj35g0ldXtIEh0lpc2jhqKqkofAvx0FGo2qODJdHhqGH rq12gsg1iK9wrwWnms/r2E2oLgd5pBxifjhCFsxMbeb2BLPkiSowQZbl8x/ecFBgRoQw XApfQgMlFqQ1cvWKOfqqvHURkQ2sS73k4lqIYkLkfkDWdKLxpGiI2mHKrMYlIGZaCaCp rbF3n0yV0M3FBPH7e8KDeCt50epALt70RDkn+bL3LNTHsjqzmVw+nYiE/XXQ/B8F2rrA lVEiE4OtF+PJaZEThaHEqf/RC8Apt3U5YpUjSEfZrdYbbmBgAyK/lcSrivtWByKSqVCX aanw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Thb6DIKW; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 w12si23559025pgl.122.2018.11.23.01.42.12; Fri, 23 Nov 2018 01:42:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of netdev-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=Thb6DIKW; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 S2502907AbeKWUZl (ORCPT + 11 others); Fri, 23 Nov 2018 15:25:41 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33637 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405424AbeKWUZk (ORCPT ); Fri, 23 Nov 2018 15:25:40 -0500 Received: by mail-wm1-f67.google.com with SMTP id 79so11221878wmo.0 for ; Fri, 23 Nov 2018 01:42:09 -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=v8u1be1RwPj+OIivYZiNyoEvuwKWhLSeAuAn+o4TaVM=; b=Thb6DIKWloK3VAeOMhRGVz7JUMNthBIe3jpvdlMgfpDF2WM7Yv2reFjk5VNxYFDevF NRAouSWeMHTKNfl8RW9mdnY2lDYEC64JhMi24oVca5KQTsrDG0pS82iG2Py6+5QvTSrh l8iLl3PyXCClu0kqpLSRn2/DU+KBkPmqZEpaQ= 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=v8u1be1RwPj+OIivYZiNyoEvuwKWhLSeAuAn+o4TaVM=; b=Ran0gGHUl/I5elEss3AMHzehXJzZ1gEW5fSjQvIxlCPSWgv6dXVCfwAQMIJteqiK9X VtSoJVHGWVBypY7MAQ3jP4cIyIGI2qbhK9w7e14KbZZWwVwv8b7/2AwVrzz+zFW+9t9c VDqyMds+zG1X569LNvJMo/sJGjCepKI7pXRMAjok45blqapIwHb2v4vgN5dG2dV81ypf JwhmAS/sYdKtJmasD3aIuYj5x6MTzM+kbyZ6m0SGj5fF+E4wZdAF2A26euIwx9hpXJh3 3o7sLldeTMVs0gnS7cxtGFqPpX0jnzzE3jFIE/5V6yBbzokaAVHP4JRCwYRU3blLQy+H eu/Q== X-Gm-Message-State: AGRZ1gKdLTEXiSNmjiQha9bfj4/0ebzb8nxfscTltf269keYUzt4B7u3 5JC7jvD341l30mdDhNU33e/g8Q== X-Received: by 2002:a1c:5f83:: with SMTP id t125-v6mr13176800wmb.53.1542966129100; Fri, 23 Nov 2018 01:42:09 -0800 (PST) Received: from mba13.wifi.ns.nl (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id k7sm35489897wrl.51.2018.11.23.01.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 01:42:08 -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 , "David S. Miller" , linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Subject: [PATCH v3 1/2] bpf: add __weak hook for allocating executable memory Date: Fri, 23 Nov 2018 10:41:51 +0100 Message-Id: <20181123094152.21368-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181123094152.21368-1-ard.biesheuvel@linaro.org> References: <20181123094152.21368-1-ard.biesheuvel@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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() and module_memfree() calls into __weak functions to allow them to be overridden in arch code. Signed-off-by: Ard Biesheuvel --- kernel/bpf/core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 1a796e0799ec..572dd74c26e3 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -609,6 +609,16 @@ 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); +} + +void __weak bpf_jit_free_exec(const void *addr) +{ + module_memfree(addr); +} + struct bpf_binary_header * bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, unsigned int alignment, @@ -626,7 +636,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; @@ -650,7 +660,7 @@ void bpf_jit_binary_free(struct bpf_binary_header *hdr) { u32 pages = hdr->pages; - module_memfree(hdr); + bpf_jit_free_exec(hdr); bpf_jit_uncharge_modmem(pages); }