From patchwork Fri Jun 16 08:50:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13282252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72732EB64D8 for ; Fri, 16 Jun 2023 08:52:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DE196B0075; Fri, 16 Jun 2023 04:52:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0675A6B0080; Fri, 16 Jun 2023 04:52:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E234C6B0081; Fri, 16 Jun 2023 04:52:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D358F6B0075 for ; Fri, 16 Jun 2023 04:52:10 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AB235120BEC for ; Fri, 16 Jun 2023 08:52:10 +0000 (UTC) X-FDA: 80907994020.08.0F894F9 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 01BEC40005 for ; Fri, 16 Jun 2023 08:52:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=URGjKWos; spf=pass (imf27.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686905529; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lkRz9xKSBSoA6gSfaBQlRQpd8BnFPgzqkoU2wQa+XH4=; b=VDzMzJRmNWEjJJR1f2gS9PYNFR9IZkl7d+AIb5/4UxvyqmSKo0a/5UJPx4BPkqoOhWIIzN k2iKnEgO/23ExEtcw7TSwOYnoQGYvfFiVY43ib1wcAA7DX8sAAQgg/c8s2MGl+PqNBCHBH mCLCtQl8gsJgHb7LgpQlj5srwb5g2H8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=URGjKWos; spf=pass (imf27.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686905529; a=rsa-sha256; cv=none; b=q0d+g176+YPF/0/5VbxDFReIPIvGSjApJ+bFoluJ/OeN8sgJdhNETxDcPIUTEFojOfLL37 OkIPV+TwdGUVZkN/y8eBFfAivkt0yA/ioq5HfrUxTS5gGHMzcflB/WJtcS7+xmw+D+S9/2 rYYf5RAzZVhwhvO5ZdcCLhXxqFxzqC8= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2ED5C6298F; Fri, 16 Jun 2023 08:52:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 436DDC4339A; Fri, 16 Jun 2023 08:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686905527; bh=3ehPtg/wkIhd28ojF38ghyySOncCvbgritUgNc+jgzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=URGjKWosTv5rUBGWoAB8K22n+ckY0pEN8K+Bt4BqNRZ+SgzdpFKHreY43HU1dyMrc 63qklWW1H6ICT8nAwvHWhUBFVD/O59OAxG9WnKC7G37cBbzQyL5wndhMi12b+NjTmA KzxWoXixUG1F/na3FTPbuDPpQSkcBRHUusl/huYZwNS0rNpCLSziH8G8sg9C2Gr5+V sMjxpInlVLQ2ozavBCagEh9Z3UDjWGN+DByqgzlPXrWZaDTPyD05GivzpznP9XZ9h4 lQRd/685TGI6dpS6i6K691630F1e6FUmQK1hrJ/8UhpaIZwAh+GhrqsCum/sDilGPE b7T6Nk8NGUZ9A== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Mike Rapoport , Nadav Amit , "Naveen N. Rao" , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 07/12] arm64, execmem: extend execmem_params for generated code definitions Date: Fri, 16 Jun 2023 11:50:33 +0300 Message-Id: <20230616085038.4121892-8-rppt@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230616085038.4121892-1-rppt@kernel.org> References: <20230616085038.4121892-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam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ZQfIXevz6b54yf jcApH08u eH8F8vwPdUBM+YH0uWGmVaVHa2Od8j1OKLgqzLRdMZsP02ZkNlHPNd5jsjy33B7EsOz1tRuHK5/tdIeV7O4hqz+ay7O1iXgb5JTKEnR0cqcmr3I8heqnlUlWrz/XxVBHoMGohy857EvCW1Sd+KA/rEKLVGDfau+PCiDvECGs/M/YGNNK8N6UyIw1EHoZNRtCBWn6r4M2+TqDSpf5ioc2sLieRRcZYqEYj6mD/5bBC1l7HrkREkfyE6REwne0v0Of8YkQUSw9QFMZqatONt9me15y1JL77+JAOpU8h5MqOCKP9UQqUZZDSSESYH/eCqGlefYsoPd45LgqqDgwP0cc2LzJ7Sk/SgYw3HpoSiHD/Y3X2a/cezv02p5AxW2987psEXWfzRYMSH+MprpMgLQ/jFKyRmnLHygvlImCqULLAkU6AArGESetzYa4M2pcmSZga4GqFI8ESK7IiuDk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Mike Rapoport (IBM)" The memory allocations for kprobes on arm64 can be placed anywhere in vmalloc address space and currently this is implemented with an override of alloc_insn_page() in arm64. Extend execmem_params with a range for generated code allocations and make kprobes on arm64 use this extension rather than override alloc_insn_page(). Signed-off-by: Mike Rapoport (IBM) Acked-by: Song Liu --- arch/arm64/kernel/module.c | 9 +++++++++ arch/arm64/kernel/probes/kprobes.c | 7 ------- include/linux/execmem.h | 11 +++++++++++ mm/execmem.c | 14 +++++++++++++- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index c3d999f3a3dd..52b09626bc0f 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -30,6 +30,13 @@ static struct execmem_params execmem_params = { .alignment = MODULE_ALIGN, }, }, + .jit = { + .text = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .alignment = 1, + }, + }, }; struct execmem_params __init *execmem_arch_params(void) @@ -40,6 +47,8 @@ struct execmem_params __init *execmem_arch_params(void) execmem_params.modules.text.start = module_alloc_base; execmem_params.modules.text.end = module_alloc_end; + execmem_params.jit.text.pgprot = PAGE_KERNEL_ROX; + /* * KASAN without KASAN_VMALLOC can only deal with module * allocations being served from the reserved module region, diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index 70b91a8c6bb3..6fccedd02b2a 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -129,13 +129,6 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) return 0; } -void *alloc_insn_page(void) -{ - return __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START, VMALLOC_END, - GFP_KERNEL, PAGE_KERNEL_ROX, VM_FLUSH_RESET_PERMS, - NUMA_NO_NODE, __builtin_return_address(0)); -} - /* arm kprobe: install breakpoint in text */ void __kprobes arch_arm_kprobe(struct kprobe *p) { diff --git a/include/linux/execmem.h b/include/linux/execmem.h index 2e1221310d13..dc7c9a446111 100644 --- a/include/linux/execmem.h +++ b/include/linux/execmem.h @@ -52,12 +52,23 @@ struct execmem_modules_range { struct execmem_range data; }; +/** + * struct execmem_jit_range - architecure parameters for address space + * suitable for JIT code allocations + * @text: address range for text allocations + */ +struct execmem_jit_range { + struct execmem_range text; +}; + /** * struct execmem_params - architecure parameters for code allocations * @modules: parameters for modules address space + * @jit: parameters for jit memory address space */ struct execmem_params { struct execmem_modules_range modules; + struct execmem_jit_range jit; }; /** diff --git a/mm/execmem.c b/mm/execmem.c index f7bf496ad4c3..9730ecef9a30 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -89,7 +89,12 @@ void execmem_free(void *ptr) void *jit_text_alloc(size_t size) { - return execmem_text_alloc(size); + unsigned long start = execmem_params.jit.text.start; + unsigned long end = execmem_params.jit.text.end; + pgprot_t pgprot = execmem_params.jit.text.pgprot; + unsigned int align = execmem_params.jit.text.alignment; + + return execmem_alloc(size, start, end, align, pgprot, 0, 0, false); } void jit_free(void *ptr) @@ -135,6 +140,13 @@ static void execmem_init_missing(struct execmem_params *p) execmem_params.modules.data.fallback_start = m->text.fallback_start; execmem_params.modules.data.fallback_end = m->text.fallback_end; } + + if (!execmem_params.jit.text.start) { + execmem_params.jit.text.start = m->text.start; + execmem_params.jit.text.end = m->text.end; + execmem_params.jit.text.alignment = m->text.alignment; + execmem_params.jit.text.pgprot = m->text.pgprot; + } } void __init execmem_init(void)