Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp101213lqj; Thu, 11 Apr 2024 10:59:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXM6IkJR8l+8T+ow3190imeATzZQqZZ1Xq8Hf7UUu3Zu/WIZG1f5JavgxQVcpwhNHEnTbd4Na/2JeCdmgfbVmsu8iJZx93eRrPXf2vFvw== X-Google-Smtp-Source: AGHT+IGc1HhhzDgkfqkStyfbhnqzUvu7RQG+37H++wyaofVbdvBYkcF0lwisPjbf5WLu5gVLCzFi X-Received: by 2002:a17:903:2450:b0:1e0:b6d5:bed with SMTP id l16-20020a170903245000b001e0b6d50bedmr220446pls.5.1712858374308; Thu, 11 Apr 2024 10:59:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712858374; cv=pass; d=google.com; s=arc-20160816; b=Xz/FPDSxuc2vnMR3nbWTkJiTqxk/rIJSEbhSa3VRzO8EidGMVlra2og4ZzcCPa5LwF ivlOV3dWoCwp7BhtJQ9FD7wFdDVBDr9/jWLBMIKE0wLvOe4dEvkI1U2/K5+myGNgQTdc UR/Mcg9iu+rQSSV/YRBBj9Xbnmo9SRdOdjQIq18mBWQwHaCR9vaWxB/7Ya4XYquPpdqk DUNZ4iGQAuOSkro+6+V7sl0snRlF5umbx5ZJNCDeLb4nC67Fc4LSHokmrYamJ7OyRMvY GxF9zmyPDNvhniC907swBFDyEniPf3uHAZC0jVqBWF/Wqx+FIabgM69IYmE5u4tLdRCA 9q8g== 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=pwwydKtK80imDCH7bqWn/JiP55fokAfjgg74fNlJBKE=; fh=SgAimfoqqdos20VWKa/NZoWkGX6dsss6oX4o+VgWJ6E=; b=BgOT2VPAL7CiZFMyHAtwzmEvK3em3RIgMrFpSaKdQ1IItMafhRh4dYMa8k1tiHnsaI RCDtmSwFweTXUmc6GfNawBGFH0dZLb2Zo43Viw2GfiNjGZXrq5JfOrC6ZDjp6sNXNAHK KsvDNoERa54mwz83an1Xr/nQm6Zo4mwlCkX4/KtAt97h9DGUhy+avZHRkOUhGBeup7NJ 6fKj74Ea5XA+YT3l+mF0t/rBdmNA5NDa5PUCg4IK1KIGrLwmw84efRZZNoFRR4W6neQ6 XrkVkfF0Z7zHUwq7VwBH+xvw7V+D5H2nATfoQ9oZBBky+r6blUyczW2gWlVOYghDTqW7 DDpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="j/I3kYyA"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141264-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141264-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id g5-20020a170902f74500b001e2a3ff7b93si1646636plw.111.2024.04.11.10.59.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:59:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141264-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="j/I3kYyA"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141264-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141264-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 628AEB266C6 for ; Thu, 11 Apr 2024 17:33:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB6411369B2; Thu, 11 Apr 2024 16:03:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j/I3kYyA" 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 EFBD413541B; Thu, 11 Apr 2024 16:03:29 +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=1712851410; cv=none; b=NRThKKPPpfKy2wS96lkpFU8qYC9QnKdqTu7n3RA7ZRIlF9oN81NvM+OUYBbkf+8y3uwZtSt3QNBG8w+kHk00E4C/s4SRqXnixGDXT0tDltnOb2WJ95bXLSj58mdzQVkSAzBAdzYmdMAYSFORdoMqsKR5uBAY2OpeL5N3DFGZ/l4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851410; c=relaxed/simple; bh=cENIBA3iYOmaUBlvaH6AHVDS8Oi8YHeSCX1M4uQK1+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=REm4diTzP68CRnR6BFsJ3YtJ7/n8em2nvlLN9D7Cdt9CpVGyhpmWHxOP0QznhiHohUGy1al5SjD5deEAgR9sLaC00XX89aH7N1GzP3hocIVmQ6cmN9jIhd9pieQNL3p+3CuMyWseLGHzPscxtC4X13v4XZPEisobo8yFozE6BVU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j/I3kYyA; arc=none smtp.client-ip=10.30.226.201 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?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 , 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> 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 | 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; } -- 2.43.0