Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3166075rwd; Fri, 16 Jun 2023 13:16:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6M6tSIiilMZLL0uXa5XOSFtGmTKMs7a2Y8uxftmADXvFloTkh1p3w8x/M6wJWByop4ds1T X-Received: by 2002:a05:6a00:2e93:b0:666:d78c:33ab with SMTP id fd19-20020a056a002e9300b00666d78c33abmr2790086pfb.21.1686946585567; Fri, 16 Jun 2023 13:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686946585; cv=none; d=google.com; s=arc-20160816; b=UOvHy1ZcGT+jXNUDEIBidNewLnAiYM0bxgrFMofCfvL3BaYmCHv4BYn0J5YN1qOSxB ZIjbp+BxJmoR8QVSag82fMQCP/fz0SfS9tFD3WeN13Ld+Anq4+9ZAxcueAnd+xr5hIss mv2LyViKI8n+8X89GzzMfDoVNOmfQnpmMNp6QVWYp+Z6OmsKm0y8LNCymehQcPfXvBr1 qW/PVQXLVJIIQU0qksCDY1P2GtLed/zdxUYSLaNDy5kZ3XDKUDISofBqmJ0PV64A/NzE SMoZ1n2zfkwJtYGU8E9gQVWVwjIvBwknvJ2NfthJ3IdZ4IzQAv6+PoDxpw1+cc/FV6kS ztEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=e+qMejtAppujqwxHMVXJzCo+OWBzndr9A4qSF+ATCZM=; b=yG3+c/QeqfS8WAVZ8SuK+95E8GVQ3XcllwidiLwwWVxgDWhxj/yo2Ob+rir61ZouUx sQO18H5UR+e16+hGKGZngWK7AxDQNr6M/KP7w8L/gq6ZWAKAPqvsivGumlT0jG3Sxvgz XTMckNTgRgg69Pt9Dy7XvkQHj8otRHMgHG3mHo6gOLu1tQ+gfmHa0eWABpNFLBletGXs 0whPbUhytZp4GU01A+V1sfZ7h5arrFfqfJWtiBzU/OEFiPl0VIv8tcH9Q0HvxvexfSAL Eapc3O2KIMxkki48OWMRXRUFqvpz6J19fR+/JO6pppWDllL/5On3GCsLPKyETnTSA12G kMQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TK7lwF2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020aa78424000000b0064d545c8466si12831524pfn.287.2023.06.16.13.16.13; Fri, 16 Jun 2023 13:16:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TK7lwF2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345452AbjFPUKC (ORCPT + 99 others); Fri, 16 Jun 2023 16:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231781AbjFPUKB (ORCPT ); Fri, 16 Jun 2023 16:10:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B76430DD; Fri, 16 Jun 2023 13:10:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D54CE61A33; Fri, 16 Jun 2023 20:09:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48066C433D9; Fri, 16 Jun 2023 20:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686946199; bh=WUwJ/CcnS7KQMIGc+n1lO6t7DBapdJHs3PtzN2L5DOs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=TK7lwF2dgyhLjZz3axawLmkbuign1yOCHmc3Tx1v0nJMLzHE4AMIBuiBwMBtxulD8 Z3Vut6IBWtk2ssQ8ijhfs8vBi+Qy0HXySzPTA15IW8YrnEaB7IlHu2VlzDPnGeCZmI K6M5pS/g15siuIekZ5t1I3/fk6k5aKAJaEj6SrOz/PCsDCt5E2f7BsT9bm6PGwrWgg 43Q6XfEEqBYd9YLn7kuhpOmt+nKESiRp8navYHM6l1x9CJMp/jkfUZ7Re+m79aLMHD kbDq8gJyNG5Gays0CHzsM1Js8nifxRWQM5ErJCnC9FUIgd0MSE3JJ4Wb0UcNmLCkft Ujy1yQtMOaDZQ== Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-4f762b3227dso1482607e87.1; Fri, 16 Jun 2023 13:09:59 -0700 (PDT) X-Gm-Message-State: AC+VfDxnGmwARsmvlN+BebDLZcp92GaeS8oe6MzbebP6N92K1Svg8lL5 QIX8BTHOVcMGoqeGC6KLFpf3otMVMH3+9o+2Vew= X-Received: by 2002:a05:6512:3052:b0:4f7:47bb:2ce0 with SMTP id b18-20020a056512305200b004f747bb2ce0mr3066562lfb.4.1686946197316; Fri, 16 Jun 2023 13:09:57 -0700 (PDT) MIME-Version: 1.0 References: <20230616085038.4121892-1-rppt@kernel.org> <20230616085038.4121892-10-rppt@kernel.org> In-Reply-To: <20230616085038.4121892-10-rppt@kernel.org> From: Song Liu Date: Fri, 16 Jun 2023 13:09:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 09/12] powerpc: extend execmem_params for kprobes allocations To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, Andrew Morton , Catalin Marinas , Christophe Leroy , "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 , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 16, 2023 at 1:52=E2=80=AFAM Mike Rapoport wro= te: > > From: "Mike Rapoport (IBM)" > > powerpc overrides kprobes::alloc_insn_page() to remove writable > permissions when STRICT_MODULE_RWX is on. > > Add definition of jit area 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) Acked-by: Song Liu > --- > arch/powerpc/kernel/kprobes.c | 14 -------------- > arch/powerpc/kernel/module.c | 13 +++++++++++++ > 2 files changed, 13 insertions(+), 14 deletions(-) > > diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.= c > index 5db8df5e3657..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 lo= ng addr, unsigned long offse > return (kprobe_opcode_t *)(addr + offset); > } > > -void *alloc_insn_page(void) > -{ > - void *page; > - > - page =3D jit_text_alloc(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 =3D 0; > diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c > index 4c6c15bf3947..8e5b379d6da1 100644 > --- a/arch/powerpc/kernel/module.c > +++ b/arch/powerpc/kernel/module.c > @@ -96,6 +96,11 @@ static struct execmem_params execmem_params =3D { > .alignment =3D 1, > }, > }, > + .jit =3D { > + .text =3D { > + .alignment =3D 1, > + }, > + }, > }; > > > @@ -131,5 +136,13 @@ struct execmem_params __init *execmem_arch_params(vo= id) > > execmem_params.modules.text.pgprot =3D prot; > > + execmem_params.jit.text.start =3D VMALLOC_START; > + execmem_params.jit.text.end =3D VMALLOC_END; > + > + if (strict_module_rwx_enabled()) > + execmem_params.jit.text.pgprot =3D PAGE_KERNEL_ROX; > + else > + execmem_params.jit.text.pgprot =3D PAGE_KERNEL_EXEC; > + > return &execmem_params; > } > -- > 2.35.1 >