From patchwork Mon Apr 22 08:50:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13637951 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 14C0DC4345F for ; Mon, 22 Apr 2024 08:50:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8993D6B009D; Mon, 22 Apr 2024 04:50:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 848666B00AF; Mon, 22 Apr 2024 04:50:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E89F6B00B0; Mon, 22 Apr 2024 04:50:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 541F36B009D for ; Mon, 22 Apr 2024 04:50:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 130B0A0BA2 for ; Mon, 22 Apr 2024 08:50:52 +0000 (UTC) X-FDA: 82036547544.02.85DE08D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 7EA97C0008 for ; Mon, 22 Apr 2024 08:50:50 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kPg88okh; spf=pass (imf22.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=1713775850; 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:references:dkim-signature; bh=zrqzgDNRKNGQexwDTOARBJiJTaC27zRhVtBugvEVZcA=; b=iX0De/0YuoplKIEgs8jdkvnPPXm/Sd8kM8jbSuxjvitilmwCQ++IaJyn7ZXW/AXkH5lLrp FBhFg0ZaM48BI+EMXXIxH9UuLOCtTxWyYq8K7W9edZ0dxITCj+A3YeDnC7TpgH0O3UnNbO K2rUsOgX1Nqd/M98TLrwQSOXc5EN49s= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kPg88okh; spf=pass (imf22.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=1713775850; a=rsa-sha256; cv=none; b=kmrtiJiSUxZVcLERYWLbX77aQuRzml1/QTkj7OkcTSk0FBbF50gjpAmVgAbHLkwWXefdsP FOYjJKCUfCLgwvWLs/qMI1/wXyMMQXqQ/qZVS8RuGUpeYxqlKGQ2C8SJ73ah2oV3GFMoFP 9zzFu6sBeMRdhZgmdNYyipH4wROJDsk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9598460D3D; Mon, 22 Apr 2024 08:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04E97C113CC; Mon, 22 Apr 2024 08:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713775849; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:From; b=kPg88okhcpP680FfzcbKkgLPJQO9XwxBeUPZL9ss77dhZH7Z8/HIvBwAWyJJ53G+e y02GkWX6ABTqP9C+QXwFZK2Wv6hlPlbwkbnvyR2zM1GZT6x+q/GyOO9FVEG363Rkjp q+s+eR2YgHpQD+XtEMFgMUYFrEVa2GoX7SdH8SmsvWjuoGpxyaJuP9fMLZ0GAEnUvj ZlVPazAINd0nz+LNI+40C+UAUum8w4t1a7R3yo14yIT6THznFpJmshshhibrB2BrNM r0TbYJfaJus567+iUCFCfaH+br/jWyUXOzACTqzLYJmV5MW2Q1RD+gSOO5ynlovuBC +UUCRro7ivoiw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 v5 10/15] powerpc: extend execmem_params for kprobes allocations Date: Mon, 22 Apr 2024 11:50:23 +0300 Message-ID: <20240422085028.3602777-1-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Stat-Signature: 11nmaqih1spjqgkkqxj1tjdm7qqhwhqs X-Rspamd-Queue-Id: 7EA97C0008 X-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kh5d1U0AB+IS7k63uir8z1MJK4te/wnRIZBvxZvRfDBx033EB6hteFLmnukhnvVY4uApZUqlG3sEphUUwYsliy6Y0A/UiRAr16L95dcjowWl0+HSfZWkEOdwJRKmAjtSI7Xq7FzWTworPIucO4ej51ld/0sy2dyA19Lmrnd0yDRVcD611gsGYvvwIhbGNYzG1zkjS2fBhm2veJypGdXKz6PTk0+us8QnbEufUo9XdppgPvLxBCEtJMCj6N+TjcdOkWrweJW3CRRCI94Z2mjYzrGw/Z35C6nvgDxnszv5PrL5stSV4sMA9jRkX0CURBOMZt0pocfK4= 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" powerpc overrides kprobes::alloc_insn_page() to remove writable permissions when STRICT_MODULE_RWX is on. Add definition of EXECMEM_KRPOBES to execmem_params to allow using the generic kprobes::alloc_insn_page() with the desired permissions. As powerpc uses breakpoint instructions to inject kprobes, it does not need to constrain kprobe allocations to the modules area and can use the entire vmalloc address space. Signed-off-by: Mike Rapoport (IBM) --- arch/powerpc/kernel/kprobes.c | 20 -------------------- arch/powerpc/kernel/module.c | 7 +++++++ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 9fcd01bb2ce6..14c5ddec3056 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -126,26 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offse return (kprobe_opcode_t *)(addr + offset); } -void *alloc_insn_page(void) -{ - void *page; - - page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE); - if (!page) - return NULL; - - if (strict_module_rwx_enabled()) { - int err = set_memory_rox((unsigned long)page, 1); - - if (err) - goto error; - } - return page; -error: - execmem_free(page); - return NULL; -} - int arch_prepare_kprobe(struct kprobe *p) { int ret = 0; diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c index ac80559015a3..2a23cf7e141b 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -94,6 +94,7 @@ static struct execmem_info execmem_info __ro_after_init; struct execmem_info __init *execmem_arch_setup(void) { + pgprot_t kprobes_prot = strict_module_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC; unsigned long fallback_start = 0, fallback_end = 0; unsigned long start, end; @@ -132,6 +133,12 @@ struct execmem_info __init *execmem_arch_setup(void) .fallback_start = fallback_start, .fallback_end = fallback_end, }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = kprobes_prot, + .alignment = 1, + }, [EXECMEM_MODULE_DATA] = { .start = VMALLOC_START, .end = VMALLOC_END,