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 C2F66CCA47B for ; Mon, 13 Jun 2022 11:31:43 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LM8Xt1svmz3cKp for ; Mon, 13 Jun 2022 21:31:42 +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=KfgXbb7S; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=145.40.73.55; helo=sin.source.kernel.org; envelope-from=mhiramat@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=KfgXbb7S; dkim-atps=neutral Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) (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 4LLsFT4S3mz3bks for ; Mon, 13 Jun 2022 10:02:21 +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 sin.source.kernel.org (Postfix) with ESMTPS id 2A92BCE0EC7; Mon, 13 Jun 2022 00:02:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D5FFC34115; Mon, 13 Jun 2022 00:01:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655078536; bh=ZlQBYr8CVFKg9jC19bbC2S1Ejn+8iBBKa/BTt5EXxNE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KfgXbb7SVWFGWbNXSuj16bpGceUsLtbDu1Hewt3CIJPbVPDc+xtiyzOSrQiSfJ3L5 V5Nf70q9aNZ9pP28hqCcRB82eBPGnElrWZOc+Jddd6fTOaRWgSoINxmSJrnG1bzPJ7 5ZuprE6bDAzV6ZNjZBF0A7gpmfjtQmeOIGu2fNilLUuiiu1FSE40vcKKC0MsJaNJwh pBDnu9DBKYoe6n0hxC5YypdAubYP0kE0WkRnj3EbBwdD/PCFyaR+mKjVYvBZ8b1/nO JWT1yveTzJdM1Eej+Ox9IUke9l8mofawIhq3C9185eoPW8CeCvmxzr/ba+FtPTbAt/ jkwNZn9Cqb+hA== Date: Mon, 13 Jun 2022 09:01:54 +0900 From: Masami Hiramatsu (Google) To: Christophe Leroy Subject: Re: [PATCH] kprobes: Enable tracing for mololithic kernel images Message-Id: <20220613090154.13331896ce8692afc0584cce@kernel.org> In-Reply-To: References: <20220608000014.3054333-1-jarkko@profian.com> <20220608232115.ccd4399f4a1d133e9b65c2a9@kernel.org> <20220612211802.30a16623e8b0a55122b02386@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 13 Jun 2022 21:27:22 +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?B?QW5kcsOp?= 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" , Song Liu , linux-s390 , Ilya Leoshkevich , Anup Patel , Helge Deller , Anil S Keshavamurthy , 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 Deacon , 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 , 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 Sun, 12 Jun 2022 15:59:29 +0000 Christophe Leroy wrote: > > > Le 12/06/2022 à 14:18, Masami Hiramatsu (Google) a écrit : > > [You don't often get email from mhiramat@kernel.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] > > > > On Thu, 9 Jun 2022 15:23:16 +0200 > > Ard Biesheuvel wrote: > > > >> 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. > > > > Hmm, what about adding CONFIG_ARCH_HAVE_ALLOC_INSN_PAGE and check it? > > If it is defined, kprobes will not define the __weak function, but > > if not, it will use module_alloc()? > > > > I'm not sure I understand. What's the problem with the __weak function > here ? > > If we don't define the __weak alloc_insn_page() when arch has > CONFIG_ARCH_HAVE_ALLOC_INSN_PAGE, then what's the point in making it weak ? > > powerpc has it's own alloc_insn_page(), but calls module_alloc(). So how > will it work ? Good point! In that case, it will need to separate the module_alloc() from kmodule support even without the __weak. Thank you, > > void *alloc_insn_page(void) > { > void *page; > > page = module_alloc(PAGE_SIZE); > if (!page) > return NULL; > > if (strict_module_rwx_enabled()) { > set_memory_ro((unsigned long)page, 1); > set_memory_x((unsigned long)page, 1); > } > return page; > } > > Christophe -- Masami Hiramatsu (Google)