From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9EC1C43334 for ; Fri, 10 Jun 2022 11:25:03 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LKJXZ4sVnz3g31 for ; Fri, 10 Jun 2022 21:25:02 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ck3AUkzb; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=139.178.84.217; helo=dfw.source.kernel.org; envelope-from=song@kernel.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ck3AUkzb; dkim-atps=neutral Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4LJzBn3ZcSz30Dp for ; Fri, 10 Jun 2022 08:23:29 +1000 (AEST) 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 B852161F9C for ; Thu, 9 Jun 2022 22:23:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76BA4C36B00 for ; Thu, 9 Jun 2022 22:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654813405; bh=z3Jhlwc3PQEgsjMohe71D/i53Eq6SNGSccBMpFOwt4k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ck3AUkzbsBZezflJocw9zOjL/O7W+Kv8m0QA0BWWxYDhG4pRCd/G2CjKMTq/fC9c1 YDNJYznqiEIRugQsJ37KCtmFgdeOGurtnYp3KcOlLoT/AuXQJ1xFQ01PLNaPuPrniX o9DIY8DcqggM7iRQQv6RSEuWXTgHJ/U6NHDMrFYk/AsalPOGLOXKYsBHvI333WH8dN ebZHsPO17DYhEkGqqmvhIjoY9hWt2nOdAWOzvaXbFIWq3dR/5HSlguDxAQP+21u1/1 VkLbgWA+pA+yM8yGgWFQASY92sYL1GnFC2OWBJ/5Yje+BH1mik8t3w0FK7H+HRgXch 6rK8u6pNFWjZQ== Received: by mail-yb1-f172.google.com with SMTP id y188so14632661ybe.11 for ; Thu, 09 Jun 2022 15:23:25 -0700 (PDT) X-Gm-Message-State: AOAM532YTFYlF5KbiZyQxtKEwKq3eFB2sm3f3zxSDX99ICbLLc4Ij+Q/ fA1KuVqqrTL09PDC+t56LyVQvV17R8DVslthDto= X-Google-Smtp-Source: ABdhPJzANLs6nyK/WG2Y1yCpx8YIaUD2OiJdlTAbvSByFB1d3SGWElQ7owoxfdbySFyAvjdjDfiWZ3ugKMwaWDz7IWk= X-Received: by 2002:a0d:eb4d:0:b0:30c:9849:27a1 with SMTP id u74-20020a0deb4d000000b0030c984927a1mr44312236ywe.472.1654813393600; Thu, 09 Jun 2022 15:23:13 -0700 (PDT) MIME-Version: 1.0 References: <20220608000014.3054333-1-jarkko@profian.com> <20220608232115.ccd4399f4a1d133e9b65c2a9@kernel.org> In-Reply-To: From: Song Liu Date: Thu, 9 Jun 2022 15:23:02 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kprobes: Enable tracing for mololithic kernel images To: Christophe Leroy Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Fri, 10 Jun 2022 21:09:20 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dan Li , Heiko Stuebner , Linus Walleij , Guo Ren , Alexander Gordeev , Javier Martinez Canillas , Geert Uytterhoeven , Catalin Marinas , Christian Borntraeger , Guenter Roeck , =?UTF-8?Q?Andr=C3=A9_Almeida?= , Michael Roth , Nicholas Piggin , Thomas Gleixner , Andrey Konovalov , Nick Desaulniers , Linux Kernel Mailing List , Luis Chamberlain , Sven Schnelle , Wu Caize , Paul Mackerras , Andrew Morton , Mark Rutland , Luis Machado , Atsushi Nemoto , Dave Hansen , Joey Gouly , "James E.J. Bottomley" , linux-s390 , Ilya Leoshkevich , Anup Patel , Helge Deller , Anil S Keshavamurthy , Masami Hiramatsu , Tom Lendacky , Vasily Gorbik , Philipp Tomsich , Dave Anglin , Linux ARM , Daniel Axtens , Nicolas Pitre , Jarkko Sakkinen , "Eric W. Biederman" , "Aneesh Kumar K.V" , Daniel Bristot de Oliveira , Kefeng Wang , Emil Renner Berthing , Jordan Niethe , Atish Patra , Alexei Starovoitov , Will Dea con , Masahiro Yamada , Jarkko Sakkinen , Sami Tolvanen , "Naveen N. Rao" , Marco Elver , Kees Cook , Steven Rostedt , Nathan Chancellor , "Russell King \(Oracle\)" , Mark Brown , Borislav Petkov , Alexander Egorenkov , Thomas Bogendoerfer , Parisc List , Nathaniel McCallum , Dmitry Torokhov , "David S. Miller" , "Kirill A. Shutemov" , Tobias Huschle , "Peter Zijlstra \(Intel\)" , "H. Peter Anvin" , sparclinux , Tiezhu Yang , Miroslav Benes < mbenes@suse.cz>, Chen Zhongjin , Ard Biesheuvel , the arch/x86 maintainers , Russell King , linux-riscv , Ingo Molnar , Aaron Tomlin , Albert Ou , Heiko Carstens , Liao Chang , Paul Walmsley , Josh Poimboeuf , Thomas Richter , "open list:BROADCOM NVRAM DRIVER" , Changbin Du , Palmer Dabbelt , linuxppc-dev , "linux-modules@vger.kernel.org" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, Jun 9, 2022 at 1:34 AM Christophe Leroy wrote: > > > > Le 08/06/2022 =C3=A0 18:12, Song Liu a =C3=A9crit : > > On Wed, Jun 8, 2022 at 7:21 AM Masami Hiramatsu w= rote: > >> > >> 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 f= or 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 a= ll > >>>>> 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_M= ODULES > >>>>> or CONFIG_KPROBES is enabled. In addition, flag kernel module spec= ific > >>>>> 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_all= oc. > >>>> > >>>> 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.sakki= nen@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 cal= ling it > > text_alloc() is not 100% accurate until we change the module code (to u= se > > a different API to allocate memory for data). > > When CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC, module code uses > module_alloc() for text and vmalloc() for data, see function > move_module() in kernel/module/main.c Thanks for the pointer! I will play with it. Song