From patchwork Sun May 5 14:25:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654322 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 D36FFC4345F for ; Sun, 5 May 2024 14:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FDA56B00A6; Sun, 5 May 2024 10:28:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 57C6F6B00A5; Sun, 5 May 2024 10:28:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F5626B00A6; Sun, 5 May 2024 10:28:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1EB626B00A4 for ; Sun, 5 May 2024 10:28:37 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CABF916075A for ; Sun, 5 May 2024 14:28:36 +0000 (UTC) X-FDA: 82084573032.19.ED73104 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 34F644000A for ; Sun, 5 May 2024 14:28:35 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HouVCimm; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 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=1714919315; 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=a0bwsiUHkJHAmE2CcEcHZfy7vtt56rL5/QXRgpY8DvZ7LtznH+y/JhayFNieplCU9mWUMR STP8R7g5AqipKSGJvVzGHtY4xWMYiWlO932XilYrwWj6Doy90GL07SR66pBh2xje73tL+N zR4VlTKqpwBaAKESSzW+jgskPFgd80I= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HouVCimm; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714919315; a=rsa-sha256; cv=none; b=dgelda9NxihRCaZz11eM2rqVtWZaNs39lvcEKK2Pn0geRWb2TmLOj9pP08zGEUHbqAx6JA iYCjUV9J/MSwWpqjL5gq9zHnofaIUBUSw5dHDwoGUoOOtkQ9afb+Ki2O8Ffayjsu/6+szX GgjpMerr1ZIjwHOd7JnqatxSNqMz2W0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 775C560C85; Sun, 5 May 2024 14:28:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7E8EC4AF68; Sun, 5 May 2024 14:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714919314; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HouVCimm5zjabPrPHbBxrJVWmW8jUHhus9RmA0vBjK24AhE+RiRRAmw6fnLtV9+mB E8Zf6Qm/XH2RCzAzq6T2PoUko9u8kIBmzdN7a+qj2rZ9hJ7Ba09sdtGK8jnrLMrhfk sfGbpF4bpAMeeLGuBF2UAemlSDdzUQifI5IDFYqMeZU86qvygTwnzqmd4UsljDVczA 8ULLCYI6frEKwv4cYmKbYL4WV0lkCL1DWorVc1kzahSkFadNEQDClCW8rIrO8p0cGu yZuimlp3U1GOmPiigwpQc55F5FF/VKyrWPTNPAxZE25KpJ39SDIk3tsah1lyz5HRN+ SuLfdNBz4BL4g== 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 , Liviu Dudau , 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 v8 11/17] powerpc: extend execmem_params for kprobes allocations Date: Sun, 5 May 2024 17:25:54 +0300 Message-ID: <20240505142600.2322517-12-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505142600.2322517-1-rppt@kernel.org> References: <20240505142600.2322517-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bDT2QpwwxsM/IIQ+xiWaGyygFDMwCsr+l1fRPJxJpnlmX3/u1IX/N Cv9DWSCD auYOKy2Xfa/0YeltMtFPbn/LLrA9oDML4gDGmwxFiIXtDivBpYgO6Rfbpuc9qO0K4SdB3bASKVfyb41ViDCtZbeKvlezns5W9wJklLZ2v7d//Sg/VSLQXu7iyDmcR07wkVMzfNH0ahzhgsCQBMVMFpd4MOLAl9yiNEvcOQp/CpP/7KjuYNUmlkmbOfCUyk+Km/1dr36Xw1lGb4pThePiBHw5a/A2E1hKt6Hi5o5Kozv6EZVxwSKaMO1x56esLzSyWVhUQT46Fs3J3zZlYNXclVleRugf+XF10G6kZ0DLX5NkTn1yF9SfYzRgNkOX8YYEE1/msdABux1GJekVk8PNRhkInMhiH+W9gH9gVfHiqUWvXgtlIDu5LovQZd8OTJtYe+7rMeERGSBBm9040pe3U4MtMDgfqIPnbmMnPo1dVXAYiPHKEy6+ASaTd+A== 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,