From patchwork Mon Apr 22 09:44:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13638187 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 C01E3C4345F for ; Mon, 22 Apr 2024 09:47:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53D956B00CA; Mon, 22 Apr 2024 05:47:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C6246B00CB; Mon, 22 Apr 2024 05:47:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33FE86B00CC; Mon, 22 Apr 2024 05:47:01 -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 0F4966B00CA for ; Mon, 22 Apr 2024 05:47:01 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BC63240A32 for ; Mon, 22 Apr 2024 09:47:00 +0000 (UTC) X-FDA: 82036689000.05.6AEB916 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf04.hostedemail.com (Postfix) with ESMTP id 83C3F40010 for ; Mon, 22 Apr 2024 09:46:58 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qf2hni4y; spf=pass (imf04.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1713779219; 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=K/WB6ZD0YXpRZdA3756yJMX0etyImqre5BqKYA6DSy4jnzn6qYCUQKJqGpu8J8JaDrMglf Mhg9BR3CNhWssFBPzQyao8IflOqFAd5dF3Oawr9ZEttyXTS2utKpZJGuZnEtOlHRRtI9Pw 8fNHyXFDsw873oMGY6hxfhsDelEsVvY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713779219; a=rsa-sha256; cv=none; b=L+8cUZfBsZPRR1xKMbtjmb4V9dMnJcifJ8qd+augWPNKo08Vb/hl5sE6JPAmI5uqwAVTTl Ac41mG5HiUQCf6as2tTV1EAWYb+mFRsPLmzjalGVsn2vLEmeIzyvTpaUwefTXSM/dh4DFM j06PjgkVxiZ4dE+Tnh8N1Xqhy9MoMVA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qf2hni4y; spf=pass (imf04.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id D0C28CE01F6; Mon, 22 Apr 2024 09:46:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B40EAC113CC; Mon, 22 Apr 2024 09:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713779215; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qf2hni4yU29ZmfimX5Cthr6CT3r7qdoQ7j5VBIxbVBQyvb9mCZ4CBagbjVGA5QCXy drdysa/61Vf21EY8h6kOpDDExnGMALPyCkYtnoLux9i3IFh/BF4WoAv3oQFZJv1+ps 2OGjzZqUQiBD2VeZc8eDhrfIta3TxXUsfB1i7t6nj3JTuZNc+1pTkCGyZsBH21rz5D 2va/X1F3NvU4RuGx3srP5xXEnrggRK2ya2WdyPUJlsD8ttZ1wcPpIEwJl7KLfSPRt7 7PJxaKVzGH/rZKJ5ki0jECLWbefv/dYFhAE99e1HFD/ERBzi5uCuc7+O1NnLtafK2i hp7aF4xoRcz6g== 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 , 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 v5 10/15] powerpc: extend execmem_params for kprobes allocations Date: Mon, 22 Apr 2024 12:44:31 +0300 Message-ID: <20240422094436.3625171-11-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422094436.3625171-1-rppt@kernel.org> References: <20240422094436.3625171-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: ywsb51fswk4espupriy8uqxbimgmwibz X-Rspamd-Queue-Id: 83C3F40010 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1713779218-641035 X-HE-Meta: U2FsdGVkX1+xDd1mfJUF+dijkILVgMJRflLVJ4ukexmleq3EkXXods6eISDkG0O3nERDwBWDdizqROuooz7xQcbC58FqcsYEPRQ/Zbky9mrsR/jBKPhiqiNUjvfV5QS2nS3pSHHmjo/V3WG7qWqv8Ps7NnfPIQVjpfaPtn8vgxdFkUAka817ynkHg8i/zB4LJLC5ORclo074UkthAnroWgzupLCCQPt++1MKGNmLoBvy30MUVImF4krSiKWWUB1wkeqO/aa8DfeX+3k4q2JTSbKnufl5sqpnMOeiQ73LZT+FHXkgHSupwvF0nqTnT3hvrDqCAtxWd213Mnpv8qFXdf4GWKqY6feuqnt+X8Ks5UrWicSDN+amSQj5ugBwcN/AI0kbtiMchyHIYXyffQy/e739sDvFkQS/sULAiKbhzIl79q6PbAUqDFhXa9RrJb4NAYyFYr4GZitAVo1RN1ZH6KNgi7isnfdS0QShbWT8pcXba5tXEGqm6Z2s5f+K/aTrRlzcdt8ZbFWhPuEDOH3BAHcmBK2ivGpIN/40jYcwMWavGEA8SRH5YRaF6t4O0xl/L8xiu7bglai6u/wt97CIHmA9z6ZfOTudi8L1Lo836OLiWfTj816KoJjMcndJhW+dN8Pt9/rg+81Alvk3LEV4cF/pF5NVvvCzcAt1eCE2g3Z03HBRBGKMLN6ydEYB0JgrOwQexyDaGy1Hr0atOZfrNB0P1bnF/zdAYoDOufkPu2PCTzD76xPQpBE6tK3n+VRCYIH9EjbHeAl5nGsDHKX1rN9iBQ2IZZlkwWH4BmA4msfGr0Q4kSMiAx8R9RIsipcO4ykfix2pbIgYeTx80VnOdImHvQ4LWJ6tGrbROSCYXD777/ixucnYSm64IkqVybjooEYKqY+A5xoZmnUw1QQTsQ1ejYC61WrF0ECaeoEPNxeAvCxPGmd3SCTyMXAghYjjzI+Yk3ptWBsOKbD6CGT cdybdYVk 8HnH0ZRGJHW7VoiB7wB0OUw+ykZkILAG8NTaqR8cnS/Ia7k78goy4py85MO4iMOX5lTOTmXvuLluFbd0P5h4QiKZX8ARE1BOBRffsJbhwt5dXOcGiIGxDiys+VX+NTC9vItIGOjOrOmro+WqdZXWtifYdT2lTUywhJLq1/MrypiqvxjJ0V4p7/EPyxoWdjJ/3m5FqXZhujbTgjW6vSoaPOHHtF8f7XyGeMl/t+m9YTO1qSe74azvxJSqTook5wBTE2j8uPwRu3aIMTF7ncR4UshR6FLIhCYiIFixrevB1Id8WVmKe16A+uwvnYQDkKPS/2xfQtk1g3m1F1HsNhJk+laN4t8VGLe2H4BZsAM6HHgmAwLM= 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,