From patchwork Sun May 5 16:06: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: 13654473 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 65316C04FFE for ; Sun, 5 May 2024 16:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0526C6B00A1; Sun, 5 May 2024 12:09:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 003616B00A2; Sun, 5 May 2024 12:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE6FD6B00A3; Sun, 5 May 2024 12:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BF2E26B00A1 for ; Sun, 5 May 2024 12:09:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7FFC64050A for ; Sun, 5 May 2024 16:09:04 +0000 (UTC) X-FDA: 82084826208.22.32F3D0F Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf16.hostedemail.com (Postfix) with ESMTP id 473F6180011 for ; Sun, 5 May 2024 16:09:01 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V9ugyDvV; 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=1714925343; 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=bJfv/r25YA3xCz10DuiezBlOz16mED+YumBAQBQryMZfXmuoeS8/cNSMc2m2f5kFV2Ckvg sh/OoG9ZKuu/dWKMr6M1Bj4bMBvbP4o58/r9GufATIar3jdVXCglznEuE51qFEMTLrIuze 48euC0T0QCYY6JEVrlEI2mKpaFuxp2I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714925343; a=rsa-sha256; cv=none; b=HkIhmT7alNhx0gPpSm0begVvWRsEDVX+AlahcE1DWddMuhwGNmadSCCfrK07loP2APlH8u 9gDWwo9NDE2IhyLZHdl3l7+tr0MM1C/LuvZ6k/WeL3WeuJqemoBZVbhIbHV1mSFA9mgERk z3+LSrXY3K/PaHgWGD2jdOUr/HTpQPg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V9ugyDvV; 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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2CECBCE0ABA; Sun, 5 May 2024 16:08:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BD9DC4AF67; Sun, 5 May 2024 16:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925338; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V9ugyDvVuvSs/IjM/QctAFO62DH9XQommkAxsxi4rdAIIff0oz6X9Qud+GkrDWACM RYQi+mih740PBAh9yI8vFEoeet38MCrU8nEZEy07fSxynn/GgVcd072Ihsx2EaHbY4 Z27gTNeymS2cYPNHB2tcTnBIsC4q2mJ6iW7K1ExKD7uVI3lUYcdOAwJFh/DfD+OqrW 7/wkJExymiv498tChhAzeu53jc+ORXNU0laY/Aj4OLEg+tUJsKk0iVBj9EfjrO1Ij0 XBfIVdsalrZBo/iYhsLX7slbIb8fHOpQyFnOlaCclEnik8YVloSy1kYXig+pYSJtTX 9TAT/kTQtt5fw== 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 RESEND v8 11/16] powerpc: extend execmem_params for kprobes allocations Date: Sun, 5 May 2024 19:06:23 +0300 Message-ID: <20240505160628.2323363-12-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 473F6180011 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: cdu7qapqkthefjyt4c1t4b1ci6k4bwxy X-HE-Tag: 1714925341-917650 X-HE-Meta: U2FsdGVkX1/cFJJFaXCSi6IhM9GgC5o6/8uwH+0w0l0maA9tOrWpgTw+42tZy69joAe8o1/wLmnJSc1bmFBlqphxkL0vMdoks69fdbEYaNh3+My8mHhpEeFx993/MLtR3KXmBQ3G8+ZsBUgEdYSHpTX/AQQDHTCroIYOmwlOVeHHWyTix8fyiRibAwDAdIhKZpAnW6mfUDNMps+mhYLIkunpkxZEiOQvPrIDHWxKbkV2TH8dGqZUjAJXkB6EEI2ywIGtiLV3dG0WWKHSSrvm4kKg3bYJR3tXztOHbt9oE+QljNayaz2sqWPKdrHrOfnft1Jizk6J+DLtZnXEyJA2jNyLq/90APvJaBYLEKYS4SfhXJ6GYhbcvY9l1E7xkp+UWsBUmBhIhSrDI958U/t/QGFv6WiLJmrgPNKq86nVNjU7pf1tNTylrXJgFpBp0LjgSIXEc++vb52rj1mPcpsdTWbRFpBHc2eRJPDCFpDhYKawqFKsWYiV3XI91pTpWvq3vshH59Adw1XHXMSIh6ip8UBECfswBbh6U2dfunqLKjfiIwKT+cE3TsWYGfc6UjwdLc8RLzdmgi8yyCwrwofTLlUnM0pzpKl1MhDgrJ9E8/ivJcEAT8UogkHz8AZOltqYO4Ph4g896dSZFFAANTK5OehYVXGtkWlCR7+dZ7yVuKRpGve8PP7UP9+0bVhDHV1pUM1nsWP6NlIoMFaaSxJ2gGBdY7Zj36J/Z7gZ5uLUVklLxet57dUSH0cgBnZtybTXWuXYEDv7hUU6ulsP5I4Z6M0zwDs8RExcvHnUMoVIgYNEfk72yEonFg2k0nlE9cNEBz9Sv+YzsfxCEqjKw8suiAfi8gBusTNch2kAwuagdItDnLA9QR+sTUxMdMlr2EmplElmHNLquP7JpMV2TehNvGrO2hnlN+Xc0mz4/0nbKjPoQaclWd4ju74BQ/TY1X2RtXZ71JjFbHidI4rNH+6 gxmPJn9E KPul2fb7L9NHxnc5AZ/bZjyWgL2dPccTWRmMvlHqKMSzqgBkgKngIE1yklVqhLSrjiSCiN7iSHbsrit/6xJJ6y8wRBLn1Tyw5k825yaYFK+24olaj36AHbo+Yys2rVAg+77nE/8Cp6qLUGadVXuQMR8tm+DXLmBu6AfFGjgrDb3ZAIGGdlemT9GIFEMKgwIgeisROX61dhyf9oZn9TqaL690B3fuTXGFCO0jyXCUi13TuEiHdNTh5lzx6hDnpYop7lihwLzSP5XmyVBJ6NHF0MNcAIuFZxqNCQKFcjGT/8Aev61o3oUdclKzcxHljqh/3F6mHtyhmAN0iATfCnHbY4lQpLSgrAcv5nnWLpwoNOqN0ByENymVcbcanJy/drVh2mQmiIOfCUQN8Jwp5lPnRqE0O58lVk93kmjhqweK6rj6vI3sTk7RBNX530w== 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,