From patchwork Mon Apr 29 12:16:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13646786 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 6C1BBC4345F for ; Mon, 29 Apr 2024 12:20:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 070466B00A2; Mon, 29 Apr 2024 08:20:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01F366B00A3; Mon, 29 Apr 2024 08:20:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E29476B00A4; Mon, 29 Apr 2024 08:20:51 -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 C70826B00A2 for ; Mon, 29 Apr 2024 08:20:51 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 716ECA10B9 for ; Mon, 29 Apr 2024 12:20:51 +0000 (UTC) X-FDA: 82062478302.29.6A9FC0C Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf16.hostedemail.com (Postfix) with ESMTP id 9DB58180022 for ; Mon, 29 Apr 2024 12:18:47 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pj81Sk0a; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714393128; 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=zrqzgDNRKNGQexwDTOARBJiJTaC27zRhVtBugvEVZcA=; b=gjfIt4w/YMJEBe5dYBDpWOTxWt7M9wd0ctA/sipqPC6q7XqpYmD7WJ3Hoql/f4ZkbOtxTY 5Ywa0pqNJz1pXUPqkAME5aANV0avPq12ByicYcIi9uet+1LOmpFnFiO4vpk4Ud0oIthDJI +2BZHV4oqvzGHB9gM/deVMzj1qqeOec= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pj81Sk0a; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714393128; a=rsa-sha256; cv=none; b=I6AQZl1QD2o60OHC46bk2KktaJEypWup/afJaTmaejuWeOKKbnEMk0Y7iuEyYB02oWAr2Z umsU5uY6fZBaz3WUBFxjvJmdXhaFOT4BSj98VbJEP5LhVupYibVziIcAQ6slck7k3HBt7e MZZ/B5PLjjkOLxMiBoZlXWRvILtjkvg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C44C4CE0B5D; Mon, 29 Apr 2024 12:18:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C527C4AF1A; Mon, 29 Apr 2024 12:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714393123; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pj81Sk0ak1YHUDc9lTjxzNdfpVkgXO4Oi7cV0sSoCO0iei4+w8g2JKr6Tzbl/FI3g QCJVK4n6ogTuudsUiBRqpTClIyM/zm7aOvYmwjxu32rDBW7hLNfSvaswQy7kBsA4o2 +EAMgky5wuHYLcMh1Y4eafH4Z5RHuTLFhkxoHAqzJDMhqQAaWrXzYVKublPr9zBuFX raYOPAinzNdDC915/FzUfGBgvU2K0eXnDTfpyAzL2NzulgLsBsU/3AYrgKbLeQ+ZJk OHjSF/lbn5/sLmuYWVw6329yc229RgXiDL/QXSwIbhPeqAuI6xqkN+cLsY5CAwO2cJ y7FG0WB5c0nSQ== 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 , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , 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 v7 11/16] powerpc: extend execmem_params for kprobes allocations Date: Mon, 29 Apr 2024 15:16:15 +0300 Message-ID: <20240429121620.1186447-12-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240429121620.1186447-1-rppt@kernel.org> References: <20240429121620.1186447-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9DB58180022 X-Stat-Signature: w17rhb3wy54kchjc3pgts316di6rmq74 X-HE-Tag: 1714393127-130160 X-HE-Meta: U2FsdGVkX19M4dK6wUX6ATgjXCmoIJ1G+8azDz0S2wnRE3fS2y4FlvxpW43kQIK1Lr7p0uWHIbz8MA+RSt0GcqyOubq/JVK5jd9UUao+X21tLg9l+jFpPhWRU0a7Wdf9otV0h4AGvzZexdf2DpZFgiQYVuTSRXEuC+hzOM00RcuHjQTVwCrca1FNs1XCiOJPpISAlE57XHNzs6h48YgEA8ZJ3jS5y/cENIdQ9oxqVRVkGGfbXI2Cxp5KQI8+SCXnwrv6/8rh+IpgGgEd6L509FhgfzuFbcc1uAlb9XkxbbUdke/SzJetU+3gmpReluNIYCF7lB0/EBZz1Y1dwj5uL0U6SmryI+QKYm4EbWjEoTeRxdqrEb1I9PjZHbFa5IdPO9Yx0onzXbnJhi/AjMffNWUIBRLMJ2IE1H8niszP1XuwyRJs/tOAORfm5RVEagOOmtdUJmsUJf0HruIksiCh0gP3eBvw3yZLBEek6QbV2jA1E0LkFJn7syBGx+OWAzFxa/RGMm2p09fxVb9X+4VQ8I5dvfq2hqIZ8k2gDeFRZyhQJBSv1I3iQ5NYaTzHRYSpzjmu4GIK8cERiKKVPQMgEaHP/ZQMKHwV45jJ/Q2mglPQL5iw3YtIN4kZht7Txsec2cKIQABVTicMMTPlExXCnhdXJyfxljyFINVEXbTtRnO0OdL4rqixRFtxr5FBD7FCSIT8x2xEawZvaHC2kgX/75GUXhZTYBP2IdIFIcre2L66IlUageLGXE8+Yw+CuozaxDw+9HXrW6XPq/c38cGpzI+IZOQpHbb31pk+U7HWULe2UtvLWEFkLTRxfJxny9cuyJZBdi17gNDi6IZ7ZTYDHU6ch/rp4LoJPhoHaIRUW3Ix1EfU5zbFy1W0Bx6xkhkhikgs0LsEEBbdb7UBxrdSuS7tPnBIXDiY23yG4/v30NwP+5EEpzVWIJ4+GXE6JzyRcc03r8N1RmSBJmPk1wc Uqgw29ZO fwBtRVl2MFVl/OMivvaV33goZMTG6CFlliopTChkGJINNwJVKxCFT7DHm00cV7608H2enbst0fSHAUa6SWXYWFTf355YnLNdBWlnsSTFKlVp0BV8fv4B5UYdNXO5bcJj/wk7Mx7EwWs1QvJoFf3lQbrgrxQ== 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,