Received: by 2002:ab2:3c46:0:b0:1f5:f2ab:c469 with SMTP id x6csp129122lqf; Fri, 26 Apr 2024 01:35:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtXzCz38y2QF6DjUb9ovh7ikbhWxDMW56TahtMBCMnqput6QpoXuH2rpAsQ0UAyTOkxbOJptD2ldve4HtPw3wfqUwbA3rCNx8kZRT1Xg== X-Google-Smtp-Source: AGHT+IEts2QCBW4UqVf59McLpbxwKsbLbtaV2PRsa2n7aXK7CD5PSc7rGfYcmWQsYXupBTWXl1G9 X-Received: by 2002:a05:6e02:1d89:b0:36a:1104:2d6e with SMTP id h9-20020a056e021d8900b0036a11042d6emr2701096ila.1.1714120506734; Fri, 26 Apr 2024 01:35:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714120506; cv=pass; d=google.com; s=arc-20160816; b=aK2LiUoMT24Zcigu60bU58S2OuXKfYV573AJKUOyLbwrm7Alk92FVC60utUvb/SbAq ZYkliR5c0OLfuPQDi1Qa4Tjb03yR4LP9Y9IaG7IFY3ZhTNrdO2sik8biRqIRVq6foL/5 /CUak6vWZzc2XeCz1ux4M8WSuLaGvSnvgg2QK/og7E7ZIX2Jye6KMX9AqKo1KTTC2rbZ NMfg602Bidzaem8Wdv8j9v+ei4kBKQOLK28TPu4bR1lhkMOXD62LrzUeL2G+mQqcU8r9 avMoGKqzZuqAeL+iZpsw3A5O0HGDhX4//hzYiI56auYvWhG6sXJji6C4XlXXV765Phck oVJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zrqzgDNRKNGQexwDTOARBJiJTaC27zRhVtBugvEVZcA=; fh=CzSJNj8w8iUnmlgWvNYhDvD5pl9OAXL/ljrL7Y6PMxw=; b=a7lWFdGSLU7e1VBLHKYgB+vUcsfK2Ies3mCxeHynZPUDn1H3wmB8ngzRJEMuQSW+mM WejcKY04NBjx8rjbJLGjc9+Byhup0AeXXhIvobmywm0W9SRCw6nNZBeAuS3f2HonzCrg cglZwnYUf81GQVJjU6xQj4jIa2UwZn8qvEKNn6LEuDzDj0oyxUZZCvJYdtudseY2OaB/ XMV7I/Z0NZHYXDbQS4o5As4X2AZwa3T3DosDix+n/y9qeyplXeR1MNdncusEPZM5qMku X3/prPirCWEn479urzaUsm5apRhSG+6cVpFlTg86YMJ23lttovvq2aVVbhwdRvXgjNHc wzMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SmvyMUme; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-159707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s73-20020a63774c000000b005f7fb388554si13405053pgc.145.2024.04.26.01.35.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 01:35:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SmvyMUme; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-159707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4C61A284882 for ; Fri, 26 Apr 2024 08:35:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E57F145B33; Fri, 26 Apr 2024 08:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SmvyMUme" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40F0013E8B2; Fri, 26 Apr 2024 08:31:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714120277; cv=none; b=vDnH5gM912iMpHytOLY38Gnjh9Sqe46Lk7Pu88MHaBuW1dN70yC8nzZAn7j1IYJav5+6Hzr9DsGFvB9tdnqsN3EZ4aWRJVSEtFhPNMbmRdEC34kQGd9+M0zBXQSeQ9Ud8GrxavqvTNt7q4IQtt145+8bKOOfxISsZd3QIpDsOsg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714120277; c=relaxed/simple; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PA5PCJ1dy0PD3HFjdc5Sbst87z8GV1p0bn1idA9bmn+Wbn4jLe/IDkxCOky/K3VYgUHHXwAMZ3N4mX8fleBRdFCgWjDHfQE8e+Smufiqfz3snTc25aZKbwndgqZdJnfiKoDshTPbQF6mwiMl9JR3SSvWWLqD2e/SclFiZgVd/kQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SmvyMUme; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D06EC32782; Fri, 26 Apr 2024 08:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120276; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SmvyMUmeeEFrWhUbUHKYn4DMMnLUUa1g4+adu28RzctMKycdCQJleanPBw3qpvC6e AXnB3fL3Y+frY4KjxDxYGEctRsFjDHtgJpKUgakhljuTLQyByVrPoqm8yiw/ese+Sw 3AINiEao90grvB42lX+M49xK2vOiscW+CXPmMzHjO1X9apGHPz/G5s/ugtCXfPjwN9 214UPXOSJDw2q4YRsmzMcVl4U8SiTEGKs66FQ/JJXbBMCpYr8IcUINJH7HXTRFtQYE XiSs76Z4km7d/H9zgVIB5QWLIoEWTs/cZi94+ScfkrPABGeDB46pF5CGfvdU8JqSEh +esHXQ/w0RQ+A== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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 v6 11/16] powerpc: extend execmem_params for kprobes allocations Date: Fri, 26 Apr 2024 11:28:49 +0300 Message-ID: <20240426082854.7355-12-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, -- 2.43.0