From patchwork Sat Nov 17 18:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10687613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5622B13BF for ; Sat, 17 Nov 2018 18:57:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 468ED29E21 for ; Sat, 17 Nov 2018 18:57:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A42629E42; Sat, 17 Nov 2018 18:57:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CDE9429E21 for ; Sat, 17 Nov 2018 18:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=5v1E9xn3xuEAopLvEllGfr+gAhAFbcTxYSFIzQ5p7bQ=; b=dcV pUm73o2TojVLwdd3bk4ztJCiti+pcrFGqaNMG7j5UDaqMAeNFfP7pBAHLSdfVheHNi7hpEh0T+kXi JeKqZroMxvvGXd3a/O4X8/sCLyrTOfLbY/U7j0oisxA9r4PHG8T1prQSzgEDtAJ+yPUdAEyaxxqne 9BhFTkhDZtgsrWKxrfee8YJnJNL2LysEJSN+VXoe+/Nfe3I4wkdyzFflgErKvSZ8JBSC4PPn/euLe J0mN3yo3yJZrYZQT3PcWcirchU5eDk4CbnXPXtNrxeQ1ywyryHXrSKnxrZMd4Rt/FES/CiHkuu4aB vdq3WxBeQnDfYjBT2Un0vcdPz691xRQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gO5mo-0004QQ-Uj; Sat, 17 Nov 2018 18:57:42 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gO5mc-0004Du-Nw for linux-arm-kernel@lists.infradead.org; Sat, 17 Nov 2018 18:57:32 +0000 Received: by mail-pg1-x544.google.com with SMTP id g189so317564pgc.5 for ; Sat, 17 Nov 2018 10:57:20 -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; bh=KK24Xtf0yZxdzxm9LC+famSI28x00YC11YF96N0BM3E=; b=UORXOUKYewxZBY9q60veahrHkEtPpR9GSai6HV7K7LIRYSUmveL4hgphwWKykjezr5 5aJslRjRd5lwcVzGm/diuVIZt/WHst6O5IT8qVuNmMEHGGC3uCNjKCW4U/6UPunf//Ri Yog90RJJIsfBEnEswOgbukRNoDii/RYXBxk8s= 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; bh=KK24Xtf0yZxdzxm9LC+famSI28x00YC11YF96N0BM3E=; b=FzmGKxumWx/JQs3khjigIL+Y5uL+9hR6UrUIGr9yJo9CtOTG9ST17QlOxda0abzDP6 qwskTyDZs59/dKGYrZkeeLKkPVv6uI2dvvpwqfaovOyDvEmIC9z/BwK8YYZseCXtS9M8 WfKL89loAwg4yjAOe/LQAsgAe7jks0mfdMrKwsIl0DglH804YBEnA5EP+kSza4obJKjf VdqmVEx6dXJ4NATaNz1rNW+r1jhZxWJiApux49OH47Tf8ov7B1cem/XAYHGDxTCeIkB7 40ftPDl1qrQbb1Rzt2a/NvUpvHtA+KZx6yfoSSqD/CdT/icyql9sP5XtQpzUHuuxTaN2 FQXA== X-Gm-Message-State: AGRZ1gLnCg9nfb8AL97OK0BcLUF4tDmq6XzdOX8k1rA+U9ezfw82i9mJ fBRDhNVeVlgfc4vn/de4Dk7poA== X-Google-Smtp-Source: AJdET5dcu85Awa0hWemuaG/qBca5+pUPD7vYP+djiZMTtvFzptSWkQPdpArsamMNJVlWr5986121ww== X-Received: by 2002:a63:3c44:: with SMTP id i4mr14292473pgn.286.1542481039552; Sat, 17 Nov 2018 10:57:19 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Nov 2018 10:57:18 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Subject: [PATCH 0/4] bpf: permit JIT allocations to be served outside the module region Date: Sat, 17 Nov 2018 10:57:11 -0800 Message-Id: <20181117185715.25198-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181117_105730_779847_93EF577D X-CRM114-Status: GOOD ( 12.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-mips@linux-mips.org, Benjamin Herrenschmidt , Will Deacon , Alexei Starovoitov , Paul Mackerras , sparclinux@vger.kernel.org, Daniel Borkmann , Michael Ellerman , Catalin Marinas , James Hogan , Kees Cook , Arnd Bergmann , Jann Horn , linux-arm-kernel@lists.infradead.org, Eric Dumazet , Ard Biesheuvel , netdev@vger.kernel.org, Ralf Baechle , Paul Burton , Jessica Yu , Rick Edgecombe , linuxppc-dev@lists.ozlabs.org, "David S. Miller" MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On arm64, modules are allocated from a 128 MB window which is close to the core kernel, so that relative direct branches are guaranteed to be in range (except in some KASLR configurations). Also, module_alloc() is in charge of allocating KASAN shadow memory when running with KASAN enabled. This means that the way BPF reuses module_alloc()/module_memfree() is undesirable on arm64 (and potentially other architectures as well), and so this series refactors BPF's use of those functions to permit architectures to change this behavior. Patch #1 fixes a bug introduced during the merge window, where the new alloc/free tracking does not account for memory that is freed by some arch code. Patch #2 refactors the freeing path so that architectures can switch to something other than module_memfree(). Patch #3 does the same for module_alloc(). Patch #4 implements the new alloc/free overrides for arm64 Cc: Daniel Borkmann Cc: Alexei Starovoitov Cc: Rick Edgecombe Cc: Eric Dumazet Cc: Jann Horn Cc: Kees Cook Cc: Jessica Yu Cc: Arnd Bergmann Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Ralf Baechle Cc: Paul Burton Cc: James Hogan Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: "David S. Miller" Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org Cc: linuxppc-dev@lists.ozlabs.org Cc: sparclinux@vger.kernel.org Cc: netdev@vger.kernel.org Ard Biesheuvel (4): bpf: account for freed JIT allocations in arch code net/bpf: refactor freeing of executable allocations bpf: add __weak hook for allocating executable memory arm64/bpf: don't allocate BPF JIT programs in module memory arch/arm64/net/bpf_jit_comp.c | 11 ++++++++++ arch/mips/net/bpf_jit.c | 7 ++----- arch/powerpc/net/bpf_jit_comp.c | 7 ++----- arch/powerpc/net/bpf_jit_comp64.c | 12 +++-------- arch/sparc/net/bpf_jit_comp_32.c | 7 ++----- kernel/bpf/core.c | 22 ++++++++++---------- 6 files changed, 31 insertions(+), 35 deletions(-) Acked-by: Yonghong Song