From patchwork Thu Apr 11 16:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13626220 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 96314C001CC for ; Thu, 11 Apr 2024 16:03:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F0056B0083; Thu, 11 Apr 2024 12:03:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 19F9B6B0085; Thu, 11 Apr 2024 12:03:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03F1E6B00AC; Thu, 11 Apr 2024 12:03:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D8C336B0083 for ; Thu, 11 Apr 2024 12:03:35 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 733BC120A82 for ; Thu, 11 Apr 2024 16:03:35 +0000 (UTC) X-FDA: 81997721190.01.6A2A0CB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf12.hostedemail.com (Postfix) with ESMTP id 27C8B40013 for ; Thu, 11 Apr 2024 16:03:32 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="j/I3kYyA"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1712851413; 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=pwwydKtK80imDCH7bqWn/JiP55fokAfjgg74fNlJBKE=; b=FegacPX/1Kzvf7TrrmsrEHgZCeG/IVOkhWHjroRxgWezd785TVM0pn3EjhwPCmt07rJdkj xRmpYS0k+UGUf+RuqMKQPsQfeM5BgVfQODkRkTRobOvUVpOjzarGvxZFjemMbPlU/sV8V9 bD7LeCiRAhyL9pTU8nWUqLj+UyCpyJw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="j/I3kYyA"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1712851413; a=rsa-sha256; cv=none; b=MlEgTwZw50wdfBwO1AbaPn26l3kPxYHqx6PTfhLCVnkuCIrhbNpGHohjz4mDc8qHSGdlZg edF2fn/7gWRmXKas2p6SGeGqAJ4PDXJhSwmKm2LwshpZvYAX106kwtMpoN9uA2hlWSRgMf hxwDNYLPXIyzQSPOdhn7Tq2p/G+3y6g= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 89315CE17A6; Thu, 11 Apr 2024 16:03:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1005C113CD; Thu, 11 Apr 2024 16:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712851409; bh=cENIBA3iYOmaUBlvaH6AHVDS8Oi8YHeSCX1M4uQK1+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/I3kYyASz3jRj3IBv0xPGti1R9fc4sE0HhRO8zaPGh5Vk+vkDBHxC+pzR2FUwfuR KnpDikB8wMbbeAqJAtMLwAeVL1eJvfDjozH0NtgeS49EL95J770yIrp9g0nlg6iomh AlqQRMWFh3zN4BL/VZI5Jp9oHmPxYrGaPu9PUdFJCOqFHRs+W+gpJZRz140wbgg5EZ xbIPlN1AXz1UpUSuTKdbXAesib8tJHXu3g3JSzCdFAUT/mQV9vKni9IhxeHqfEG958 Ff9bC4fhYXGks5Ttq2rANZs8q+xgorE8R7v/aOeje6wOIf4JJRY4ood7R8dYzsbCUV suRcoWyHa9FMg== 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 , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , 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 v4 10/15] powerpc: extend execmem_params for kprobes allocations Date: Thu, 11 Apr 2024 19:00:46 +0300 Message-ID: <20240411160051.2093261-11-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411160051.2093261-1-rppt@kernel.org> References: <20240411160051.2093261-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 27C8B40013 X-Stat-Signature: kyctdwpze75gbdfby5i3tqfyqw3tmnfw X-Rspam-User: X-HE-Tag: 1712851412-163738 X-HE-Meta: U2FsdGVkX19H01IbR5FckPJKQnDkSuPF81FlJH6XWgqQFXrl+m0OSNsoD0Il6onEmKU5GElj3Jg6TDYxMcgKxo8B65MnBO260j4A6WgqPeQ5SNZtMnhzuukoKBH+gMn4IDRg+2urjV2Dnn6q1RoynLWZbeCM+svfPSmyn+0jKtCZvxb4vheEl+EczIaMx1t14HntTCNErIQlyAsHuG6SIheF8d0ObhdEA7mnMyrVKeTk2TLNyb4911iVP58KprlVx95bk1BwPTKxrW6XSPkjVBLo0W6zz2Tgc6AgcLwK2Kif/tI0r4hKk8XV0V5LMERsMU70819JKWeD0bQw588BH/WKgCHaQg804JnlIKvsvdF3691cKehNWvg5Feny7dW/KRtdEG+n1nG3JLc4vnGh3YdxG32c10R6TzKfAOLdg41SvBDr2ciodfZF4O7g6xtELLK1i2NsAKqwyU5M7ZMGitR/15ZpMtktJNZlgK7UxJCu1EaDSs+gTE9maiwzc/9IwHz1DOrO09ws4rlzck2VWB17Iuka5JYErS6g+Jutwu1pZuLyC3OIXLM3utr/mtXPyeS0ZGrwBwyDJuM/elqgwazIiVYhV/yLt5c/qWt4nndYGaBsdefZZAeWWbCP19oJG0WXap0AzysQDxP0vGQ98Fg0OQHaTIV6uR8bk53lhYA3UDqDQmVqRaaHH3X6ru+anFUkF+9d5w9PanRZJEnk17TmSySVNvLA54mj2DJ+bDFjuGfsv/PmcDg6NWy6/wFmqq9nDOi3EVPX2oDENrbC5O1dS2io2dnQA1aqWUmyn8pNoWs5UkUyeHHnRCNxyz2hwRIWz8V2V6AS+zd5wLAT/Gxz+hLWqecGi5xacsNVq75/v5jf1B+uv+gggpTNVMQ2IDDSiNlH8e/6xTXG4IBtD72UC2ExgnQIsPz2frnbu0shI3UektiXHOLoRvrzTiajQcPn60R8MMaNM6ezCs7 j/ypiV7n uE/5L5E/waqIJNxHfJfk5Dhp6hUL0r4ewtOx0H8wnMt+b0poqlwKYY3NqL5T8jJ5Jnt7A/32bEv0KDJAvw6kvK+s0Bn9t8A6U689A/JBsWPxIqPjIJ5GszOqcNHdb2XRuKtVItgS2E65MwBqDHqDLYYArKEiNY2ad8ANDrA0IU92JxREwHNVMUq1+EYgV+FvSljfoEhdfTfofQS9hiruvJrqv9FYOSTbjOYxom1+9SX5sD1OozEQQCdnjUblqr2V1RPNuXAoabXmcCl0PhjSiFfVv1N3AOow4lJWG/PmnOOfAhVg72mo3Wsd29kQwFOw5Vc4S/Gkbory1E8+Wbu+VqKOjSSjLvwT55XyUFrNAxEnPoR8= 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 | 11 +++++++++++ 2 files changed, 11 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 5a1d0490c831..a1eaa74f2d41 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -95,6 +95,9 @@ static struct execmem_info execmem_info __ro_after_init = { [EXECMEM_DEFAULT] = { .alignment = 1, }, + [EXECMEM_KPROBES] = { + .alignment = 1, + }, [EXECMEM_MODULE_DATA] = { .alignment = 1, }, @@ -137,5 +140,13 @@ struct execmem_info __init *execmem_arch_setup(void) text->pgprot = prot; + execmem_info.ranges[EXECMEM_KPROBES].start = VMALLOC_START; + execmem_info.ranges[EXECMEM_KPROBES].start = VMALLOC_END; + + if (strict_module_rwx_enabled()) + execmem_info.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_ROX; + else + execmem_info.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_EXEC; + return &execmem_info; }