Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp441543iol; Thu, 9 Jun 2022 06:58:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/r5SiAIXRv3IpEqEe34jw/qXqliZefHYS0mS5TRpsneD0JkHvWtR8kZWQxHhUuWFofJri X-Received: by 2002:a17:906:6d05:b0:709:2c7d:5846 with SMTP id m5-20020a1709066d0500b007092c7d5846mr37317387ejr.158.1654783116616; Thu, 09 Jun 2022 06:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654783116; cv=none; d=google.com; s=arc-20160816; b=rVzjK3/K5FFB54VYlCCu/oW23XLWJbfqJftobuWM96LPSLgmHkRSsf7sspIoh2CowT JCgPzrRRqnUfPS6a0f8oWEq1s4rFhbYz9wdPJ7Ky1qkEgOlXV3wSrVCtX3UWwrK/wK/2 iw0ORPHx7SNXwOrRUxXBWJFyg5CNmQWNbZo6rGpIzBbcFwpgr6pVyCk2BZnZ0iof/xg4 q5masMz7kPuqqlM0fIw0UgdV4pMfywVBb+G4SZbA532Sd8Le3XQ+UzUL1l/DqEoplD8/ Csioot4d1v/tB188y8TBf/sYLOCXoMyWyjwlLZwsCo3f0X98RQOZEafxyLJsUDv6OOUT RnBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0i5y+i0fXXgcL3cCGeqihPzmF+g78wwTszFvUhWrePM=; b=Qxf/buc+DO7J5EhBqoqrFjHlPj/WPbdkdYnPv0dj9MM6xVG4jcLifZQ2TBw+256vck Ecq5nCtBVXs0IiayXilSjRTL1+hfLNEoQ5ZNwlnsBjm5iIA7WOFaeNK6EUu4CRXpFeiJ ps30XSj5Crkb6IE9UpmWv44nndNtNHP0IWKzubhnRqWgCZX6UgtORWK0nooufg5FFb7+ 0I9gz3YzQzXjbRAUpcK/7N0aDfCuiYOAcaIg673ZcU4dow49X3oNDfoOjoU0q+gV/1sO OQiIzwqwxKyB84me/Zad81+eBS1uzCLcYApVcmvdkYHibD/17KAwsVAatSx6raa2l1GK aSmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jQI8KSeT; 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 ss2-20020a170907c00200b00710af3cf548si13491640ejc.850.2022.06.09.06.58.09; Thu, 09 Jun 2022 06:58:36 -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=jQI8KSeT; 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 S1343738AbiFINXf (ORCPT + 99 others); Thu, 9 Jun 2022 09:23:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235210AbiFINXd (ORCPT ); Thu, 9 Jun 2022 09:23:33 -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 E78C22600; Thu, 9 Jun 2022 06:23:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 867D061D17; Thu, 9 Jun 2022 13:23:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA142C3411F; Thu, 9 Jun 2022 13:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654781010; bh=IcMP1Nqp9GJ7GlASLImme5YF3P4SQbrK4SBhBNQ9UV0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jQI8KSeT4hxL6/XRNWsYygZWPq6c2rTnYyQvpYYkJPXgEXv7HKrcTvhEmEXb1M5OE YUL9w6tQFJLUK2/WUFDSypzkpzdCLwJ2PazaP+wEYYauRmJqicn3D79nREb+ysfjrg x1mwP9BXotlSStVEgEtVsRx4zHHmQqdBzqXpfFmRnaaNH+7hKs7r2ABNQGzOJ4P0kf sT1LX9OuXM4G/GeSHuVyF6fKGGhXuoQL0NDdIeclh0lzQxzdpK9LYU91FXM1NO9wdK YDH1zAXnAWA5HicNM35ekYln4tgWB/u9SCrULYSznxrQAiKtg+JmsncEygLd46VaOl sTlmmDnaL9E/w== Received: by mail-oi1-f170.google.com with SMTP id l81so16385028oif.9; Thu, 09 Jun 2022 06:23:30 -0700 (PDT) X-Gm-Message-State: AOAM5311zLAhnHqWyTbM5wAfYXd+yQdZ6gN7XfSBCy4E6z28GSL0ak5D lMxT8TOhl911G3/dqZyYejodJBywV3Ksm+DsExs= X-Received: by 2002:a05:6808:300e:b0:32c:425e:df34 with SMTP id ay14-20020a056808300e00b0032c425edf34mr1704337oib.126.1654781009990; Thu, 09 Jun 2022 06:23:29 -0700 (PDT) MIME-Version: 1.0 References: <20220608000014.3054333-1-jarkko@profian.com> <20220608232115.ccd4399f4a1d133e9b65c2a9@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Thu, 9 Jun 2022 15:23:16 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kprobes: Enable tracing for mololithic kernel images To: Jarkko Sakkinen Cc: Song Liu , Masami Hiramatsu , Guo Ren , Jarkko Sakkinen , Linux Kernel Mailing List , Nathaniel McCallum , Russell King , Catalin Marinas , Will Deacon , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "the arch/x86 maintainers" , "H. Peter Anvin" , "Naveen N. Rao" , Anil S Keshavamurthy , Luis Chamberlain , Steven Rostedt , Kees Cook , "Peter Zijlstra (Intel)" , Nathan Chancellor , Josh Poimboeuf , Mark Rutland , "Eric W. Biederman" , Marco Elver , Dan Li , Sami Tolvanen , "Russell King (Oracle)" , Nick Desaulniers , Linus Walleij , Chen Zhongjin , Nicolas Pitre , Mark Brown , Luis Machado , Geert Uytterhoeven , Joey Gouly , Masahiro Yamada , Andrew Morton , Andrey Konovalov , Kefeng Wang , Atsushi Nemoto , Guenter Roeck , Dave Anglin , Christophe Leroy , Alexei Starovoitov , Nicholas Piggin , Daniel Axtens , "Aneesh Kumar K.V" , Jordan Niethe , Anup Patel , Atish Patra , Changbin Du , Heiko Stuebner , Liao Chang , Philipp Tomsich , Wu Caize , Emil Renner Berthing , Alexander Egorenkov , Thomas Richter , Tobias Huschle , Ilya Leoshkevich , Tom Lendacky , Daniel Bristot de Oliveira , Michael Roth , "Kirill A. Shutemov" , Javier Martinez Canillas , Miroslav Benes , =?UTF-8?Q?Andr=C3=A9_Almeida?= , Tiezhu Yang , Dmitry Torokhov , Aaron Tomlin , Linux ARM , "open list:BROADCOM NVRAM DRIVER" , Parisc List , linuxppc-dev , linux-riscv , linux-s390 , sparclinux , linux-modules@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Thu, 9 Jun 2022 at 15:14, Jarkko Sakkinen wrote: > > On Wed, Jun 08, 2022 at 09:12:34AM -0700, Song Liu wrote: > > On Wed, Jun 8, 2022 at 7:21 AM Masami Hiramatsu wrote: > > > > > > Hi Jarkko, > > > > > > On Wed, 8 Jun 2022 08:25:38 +0300 > > > Jarkko Sakkinen wrote: > > > > > > > On Wed, Jun 08, 2022 at 10:35:42AM +0800, Guo Ren wrote: > > > > > . > > > > > > > > > > On Wed, Jun 8, 2022 at 8:02 AM Jarkko Sakkinen wrote: > > > > > > > > > > > > Tracing with kprobes while running a monolithic kernel is currently > > > > > > impossible because CONFIG_KPROBES is dependent of CONFIG_MODULES. This > > > > > > dependency is a result of kprobes code using the module allocator for the > > > > > > trampoline code. > > > > > > > > > > > > Detaching kprobes from modules helps to squeeze down the user space, > > > > > > e.g. when developing new core kernel features, while still having all > > > > > > the nice tracing capabilities. > > > > > > > > > > > > For kernel/ and arch/*, move module_alloc() and module_memfree() to > > > > > > module_alloc.c, and compile as part of vmlinux when either CONFIG_MODULES > > > > > > or CONFIG_KPROBES is enabled. In addition, flag kernel module specific > > > > > > code with CONFIG_MODULES. > > > > > > > > > > > > As the result, kprobes can be used with a monolithic kernel. > > > > > It's strange when MODULES is n, but vmlinux still obtains module_alloc. > > > > > > > > > > Maybe we need a kprobe_alloc, right? > > > > > > > > Perhaps not the best name but at least it documents the fact that > > > > they use the same allocator. > > > > > > > > Few years ago I carved up something "half-way there" for kprobes, > > > > and I used the name text_alloc() [*]. > > > > > > > > [*] https://lore.kernel.org/all/20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com/ > > > > > > Yeah, I remember that. Thank you for updating your patch! > > > I think the idea (split module_alloc() from CONFIG_MODULE) is good to me. > > > If module support maintainers think this name is not good, you may be > > > able to rename it as text_alloc() and make the module_alloc() as a > > > wrapper of it. > > > > IIUC, most users of module_alloc() use it to allocate memory for text, except > > that module code uses it for both text and data. Therefore, I guess calling it > > text_alloc() is not 100% accurate until we change the module code (to use > > a different API to allocate memory for data). > > After reading the feedback, I'd stay on using module_alloc() because > it has arch-specific quirks baked in. Easier to deal with them in one > place. > In that case, please ensure that you enable this only on architectures where it is needed. arm64 implements alloc_insn_page() without relying on module_alloc() so I would not expect to see any changes there.