From patchwork Mon Sep 18 07:29:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13388978 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 0E03EC46CA1 for ; Mon, 18 Sep 2023 07:31:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B0466B0289; Mon, 18 Sep 2023 03:31:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 938E06B028B; Mon, 18 Sep 2023 03:31:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B4786B028C; Mon, 18 Sep 2023 03:31:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 675776B0289 for ; Mon, 18 Sep 2023 03:31:45 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4545980BAA for ; Mon, 18 Sep 2023 07:31:45 +0000 (UTC) X-FDA: 81248898570.18.BDA0EE7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 9D04FA0036 for ; Mon, 18 Sep 2023 07:31:43 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d2NNM60P; spf=pass (imf15.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=1695022303; a=rsa-sha256; cv=none; b=KIwQdG1umaWrfIIeCpAnjHUIB7qDdpoSYWVtMXZh60ynIdVrICfPusrD9ySNVit3ujlInN D4YWy51wk9+7Cgyp6XzwAUowmTZ3AxRF9Oihlcsy+tnIpi2tng4os8JkeOTHeZBYIkpqgC 3MFQBVeZ9e2LhYvNx/wm1d24IwK5ov8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d2NNM60P; spf=pass (imf15.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=1695022303; 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=EJSx7dTPSl55UPeMrpomdQNp6HYHj5K4Qaz1intYvHs=; b=UvDPegsHz7KTtAMYLartKAc6IRGTf1od33FrD0NMCFjj+3eCDfRhbNjjeMajMVloKel9ua /MZugPqlu4ZUyhqTl+nwyjcUnmRAtj1XpgrJuO666dI/3tRLY834pW/TJrdpot5nxj4ifZ ZDqfa/UMocOk9VVPKTEbLM8xYpEaX+g= 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 DE75660F8F; Mon, 18 Sep 2023 07:31:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5155AC433B7; Mon, 18 Sep 2023 07:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695022302; bh=35ZlmvV7rKqwzQaOmbBijH380/EeVtPirZbGWiToTW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2NNM60PB58jmuhS2dGN8NLbq1KB4ygYvRR0t6DZZJS7qBVZpROHao20O2uQV3bli 0QvXp0s5+eLFeJhc/w10Fn3KC9lksq3uhoYzEZC5CWp+6gjai+j/d0a89/bBUhyjJy FfXXBFOSn88hPGWgJbSxUtSr8ULAUympoyAWJKP5uJmt4lykdt9r5kJb2u9np9CG9l pAU2vChu/4/QGlbV5wO6V/EhzFjCpLIlsY1oLhcdgzQ+bitYphtILzsTup5ZLrX357 OmssgGZ5JmBAamSicGtU177ClYYdO2+YHkslBuFOroSFhEYDOcBWDp8NAr0VRv3fiX mkBw/0g11HpDQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= , 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 v3 09/13] powerpc: extend execmem_params for kprobes allocations Date: Mon, 18 Sep 2023 10:29:51 +0300 Message-Id: <20230918072955.2507221-10-rppt@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918072955.2507221-1-rppt@kernel.org> References: <20230918072955.2507221-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 9D04FA0036 X-Stat-Signature: rc6te47437e8yhskfhfj3eq33t6d3bw6 X-Rspam-User: X-HE-Tag: 1695022303-290320 X-HE-Meta: U2FsdGVkX1/PCodlaFOW1iC+EeEjRnC3PTTCvy5d+VBsPCsxQyqyKOaf2TdhFeQ7qoOZJTtKI5HY7DKCxKw4jzizGO9QrEbt1ROt5kcw2O6stdWgoo4TTf71kGeyIFH6QvENf9eQ2aekv5nePzC+hHCjJwLCEloIcCQmOgeuVIxP1gl1JAxm9eTZOI7NhlQSSAK7NtuhjEutLI4T051c7q8y+e82Zic7xq2pf7GuRTsY+imU2kVlUxCGjtZpdMM196rLeiioNyAUIocxgubrblRyFjB1k7M7MV02tuSsTzSdb3AbQjrYBmxnwVHd5W2ulcgzLfoGUc9xRtl9ZYlX5aGH+2n+3h9n1MTPka1hynvxMYc77l0v3IEyV+De2SM/XG4cWruv1E85hlbylUJGjMA0RhDy2FUqaM1FycwDEROC+PwZHZ+lkUcoUEeKWcGttvURBZhI2hjYP93sSo5sNAxVP//j3mG5+N6nourTU89VqL3TufX2mVlNx4tRH9KVZjBH95NRSQ2a/RhE2FEcdxsJbBP/4scLEsxa3uOc1Dy1sQa5+4JTFnfwMEvdJBzJbXjbZ2GIXjiXIdYNlBv+exiZMq1Vuqbo0BDmUtsii59b1sIvMJrxntaLDylTtlLvACfan+jovso0O0vlQTkN5uB9EvbPsy+ULuZ/bVRJFfkdXY65WSgizRgNXVbnMJxC0RwvpQB8g7HxlLVsZ6FfpO/xp6dw+nXDbXVGRrwp+sJ+4nUDZ3fOcVCebmVPLk/un5BfYZDE6cM7fGcK7XfjCupjksa4GZX2T4Jq0I0KPIIFpZ9240SfGWLUn58aoFmTlR5pYvO65uoFSc7w7ut+SHNEkQRt9lKFi6OIgnLv29Tfe4h/h0fnQuFKj+F4TOP3/ikuJam5gvlYn5OkOrLHfiUMardW7RYlWYz90cqjEgfFPLBG0J53yOqlipdsvRTUpNAUZ12wW6hHLPSa7xH CFxhejvX Om9K8LSk/HOGFWhVlqGnfnlv5tbNDu17N8FLoDX8noAZrQYI+IAl566ndzSdYPFfu7ulfmgQguZNLfprc8WAo2WnOqQFr0Ziq+qiSzzmw1Rl2zAWBuJpH4K45QQmtD5mHiZUHWXXlEmVcqH64WZh7wnAWrAOtAM/HdKqt2A12IfcbD9oCSRhae88cuZdvkVk02WFeYNhgpKBcT0bhnnixJcciB2DHgMUF+rm+uwkKO7WybIXpmpDv/mBYcnb1N+IoIlwQ+Zend5xLzmadPkuv1eknMxSl2mbZlXxizA3+rTVOulfDGZaS4zLE4KTf35l7cBAtiIR89BrRo/PwaNHVEMWS0dc9AGo+Q4QpM+UVE6gsZM9HMN2atKhMaOCt/G1BKqYki23Csf5ZwFUP+BGXBJQ+LiuA3TOV/LIouciZjE/nM6vHIkf0ett2Ym/zfrFjcGLgLiulBDAfR/Q= 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)" 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 | 14 -------------- arch/powerpc/kernel/module.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 62228c7072a2..14c5ddec3056 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -126,20 +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_text_alloc(EXECMEM_KPROBES, PAGE_SIZE); - if (!page) - return NULL; - - if (strict_module_rwx_enabled()) - set_memory_rox((unsigned long)page, 1); - - return page; -} - 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 824d9541a310..bf2c62aef628 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -95,6 +95,9 @@ static struct execmem_params execmem_params __ro_after_init = { [EXECMEM_DEFAULT] = { .alignment = 1, }, + [EXECMEM_KPROBES] = { + .alignment = 1, + }, [EXECMEM_MODULE_DATA] = { .alignment = 1, }, @@ -135,5 +138,13 @@ struct execmem_params __init *execmem_arch_params(void) range->pgprot = prot; + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_START; + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_END; + + if (strict_module_rwx_enabled()) + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_ROX; + else + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_EXEC; + return &execmem_params; }