Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp268015rdh; Sat, 23 Sep 2023 09:28:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9KOBbb1XAJv3MV/4VjxvECjeI/sH3XpwDBli7F8q3fgrNB5Gy0ihyDWwc3O3Jq+o4fEBb X-Received: by 2002:a17:902:ef96:b0:1bf:22b7:86d with SMTP id iz22-20020a170902ef9600b001bf22b7086dmr1574904plb.3.1695486536971; Sat, 23 Sep 2023 09:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695486536; cv=none; d=google.com; s=arc-20160816; b=UwOTW4zK80NTxwd41w0IaEgyv0BiFuq25Y6RoJygWbeCItEOEkeYHNXRQHSEKouy8b fypIrioQS1gVE9oOmEv0GGoGWh9VJSbjubur5GDced1hm8NAhUKd+Dht0sBJgmQ6vkE2 G3jIVIy024OARM6J/U0wgekGBmtVoxKBe9YMgG6S+V3Ox3K+gL6QBICTL+erm0dJE3Ra J5U8pvmVsvZWRajz65jqLZaFMrD+JDsW8/R7gyzuEm9kSfTIDm+8Sax13p2XlmpikEUf MmosztcC9/IlvnI4TmZtukxX3w6i4G7SiXATMjshDdGy1n48QSei3zhXr3obUOXVFTGC ZGhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LVhzKv59o4GVMxVkdtW171K/F7Liht7V34XZBgcW2M4=; fh=2os1a4FYY3Z5vnmLu5OFWfpQg8CchBgG3MrVkK6MJAg=; b=kdgzLlLjv5kWHTgCBqK0VWxvadkNFGQDUhRDRg/9GnjybeQ5gMlncZnC4C65NYifEp oceS9g/NBgOlr2EKiBVo6poamAhpiujnyIewUayJV0UVYD8B8U/EJjPBCN+GVuE99zE/ Ccr7n2l3P1tCvQ/VUHNyXjaSGAN7yeaC9y/Nb5g21NLLOGN7TdLOANYUnq7dK3QUQLaM 0KksvP/2CNC8J0mgnAtv9N5bp1hl/Lwv2ZE3812Tz6TB6sq5um3hsgP/CDREmQmZMkpP OapY3qHv0cAYBjMQRc0tpsEdrrTDP4wI1d2mhnezZCvQWqzBkqpFwpDrsNNGHy69WggJ ruhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kdX7uAUn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id x9-20020a170902ec8900b001bf0b29d935si698788plg.34.2023.09.23.09.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 09:28:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kdX7uAUn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id CB4B0807DEFB; Sat, 23 Sep 2023 09:28:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231993AbjIWQ2q (ORCPT + 99 others); Sat, 23 Sep 2023 12:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231853AbjIWQ2p (ORCPT ); Sat, 23 Sep 2023 12:28:45 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5048192; Sat, 23 Sep 2023 09:28:39 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98403C433C7; Sat, 23 Sep 2023 16:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695486519; bh=RqAizeoAgpyrjTuWTc3EPt+00fz0GKOYt3wgiu3ilxI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kdX7uAUn5A/nOh6b98KyxWdk9fFgHiJgriB/fwuK77YQxwt85ckYKTY9t3fBf62wY OdfH5+weEeIpqZEmVKOTk/M6qPAq6DbFmu80HRazp/dQJOGu5Fdotg7Z2IUrfIcHFK CzwEzww+QWurkfb1eX0LPowGymg+QANEOY5nujQK9DRlmOgfq/CMbzYwknq+dY7tnp PeA7IOMb8Twk1q2cqZZhCdVsAByDQXH6HWv6/P0+r3F48yu28WNKT0AH75egCCxIj0 rSO4bYh3+oBADB8dkFnn9uQPpZxQXif883hCwsCk2af3dw5oO2O8+odTCE6fZmVuyX JCGFYC8Rtz+ZQ== Date: Sat, 23 Sep 2023 19:27:42 +0300 From: Mike Rapoport To: Christophe Leroy Cc: "linux-kernel@vger.kernel.org" , Andrew Morton , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Catalin Marinas , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , 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: Re: [PATCH v3 09/13] powerpc: extend execmem_params for kprobes allocations Message-ID: <20230923162742.GO3303@kernel.org> References: <20230918072955.2507221-1-rppt@kernel.org> <20230918072955.2507221-10-rppt@kernel.org> <1cb41761-29d0-5d33-b7c1-0ca3acaa810d@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1cb41761-29d0-5d33-b7c1-0ca3acaa810d@csgroup.eu> X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sat, 23 Sep 2023 09:28:54 -0700 (PDT) X-Spam-Level: ** Hi Christophe, On Fri, Sep 22, 2023 at 10:32:46AM +0000, Christophe Leroy wrote: > Hi Mike, > > Le 18/09/2023 ? 09:29, Mike Rapoport a ?crit?: > > 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. > > I don't understand what you mean here. Does it mean kprobe allocation > doesn't need to be executable ? I don't think so based on the pgprot you > set. > > On powerpc book3s/32, vmalloc space is not executable. Only modules > space is executable. X/NX cannot be set on a per page basis, it can only > be set on a 256 Mbytes segment basis. > > See commit c49643319715 ("powerpc/32s: Only leave NX unset on segments > used for modules") and 6ca055322da8 ("powerpc/32s: Use dedicated segment > for modules with STRICT_KERNEL_RWX") and 7bee31ad8e2f ("powerpc/32s: Fix > is_module_segment() when MODULES_VADDR is defined"). > > So if your intention is still to have an executable kprobes, then you > can't use vmalloc address space. Right, and I've fixed the KPROBES range to uses the same range as MODULES. The commit message is stale and I need to update it. > Christophe > > > > > 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; > > } -- Sincerely yours, Mike.