Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp868231iol; Thu, 9 Jun 2022 16:15:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVhTFbboMUUGQaFq8aUIJFPhFiBbf+n4cazpWJsttYW+w8ajB0NKEH1jw4nWQHYX/qCBso X-Received: by 2002:a05:6a00:885:b0:510:950f:f787 with SMTP id q5-20020a056a00088500b00510950ff787mr108289478pfj.83.1654816514616; Thu, 09 Jun 2022 16:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654816514; cv=none; d=google.com; s=arc-20160816; b=Ef0/ZKlePfuk21L0u8qtHmhxshfbXlFfJBl/rFqkGmifBlF2VGdyN5OmLokPGLS9wg pzFzmWktsQbKTl092CVPKtavGegJZqDPhgL53QkbM0XXGN6QdlOVXURCdXmzkuPlXVyy QdYugoJPixwK6OmhcJgJsz4I7yGfx8B/X9BIqHlia/a/gQO0bWMOvVtTFqw4jZOSPOXN oH/k1wObbc1dY0C2zegrv1DL8vKydX1UPca5zQmjW5X6uPxFStBdJOxAB3wk1AsZnUMr GXldHweMlnu94cbMuz7rzmQndWiceAWbVaTjCzpNdOCqxr5tw2hCC61XoFxUUvmqw8p9 RcLw== 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=daKwUjxF14ts320k79Z8sapsgbX1OFsHzCLW3q8WBaA=; b=bB+KMIbh+PyRBsTAkSodUhcLan6iTBc3OCqn+HKRtGlf5N24tA7o3pIxXss7+YhSWm XwUzEW0Ng0ZLe48YTO7oTyGWDB2BMGt5w+b1KaCFzAILP6I2LcO55r+0GpWNC7/5ifJ2 5UtVmoM/HXBfP3cooUqOe1o+Vni4eNXvR16qL3Jg4xoeK3siNqgyiDXHd9o4hFxkntzL HsSOVjRokKpplH+oyBVJ/DOX2gfCPFVBg888eOFgRT6fbOrtMn/VDMwMwOm6euignMn9 EyUaOi8p8+gSpzlJbW5iLo0y1trFg7xP/k4xRHdrOZyFpfPrKCTljKH/OUpoMZAW87Ss /8iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mlhMnjdI; 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 j185-20020a638bc2000000b003fcb1bb48f2si31880692pge.638.2022.06.09.16.15.00; Thu, 09 Jun 2022 16:15:14 -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=mlhMnjdI; 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 S1344829AbiFIWXS (ORCPT + 99 others); Thu, 9 Jun 2022 18:23:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240263AbiFIWXQ (ORCPT ); Thu, 9 Jun 2022 18:23:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0295108F8F; Thu, 9 Jun 2022 15:23:15 -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 3C38C61F8D; Thu, 9 Jun 2022 22:23:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A19E6C341C6; Thu, 9 Jun 2022 22:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654813394; bh=z3Jhlwc3PQEgsjMohe71D/i53Eq6SNGSccBMpFOwt4k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mlhMnjdIVr6bGr6zRRzNNuuMtIoJqknDoNXAwEpZFVmKdg48Ux8BomZhVN1c6HTUt 37rDnfHERbyHrCbEj7wLLPnG5uM2meP8f/gXM96A9FY4TrUpbosSqiiXypesYZrYnX Ij/ra4ztJebl/75Kc6TUi92kcmBgBB7b00cdaTxZq3dAUdk2PYYuByhybCpDHb/oLk qVMN7LKXUSSb/cte+PbL/dLrxwEyTZDCZlO8p3ARu56dfI+HU2cceVDtXL9JoK5zVh OYaEbb8Ggaeeb2AOdQ4u55WHeCmR0uENDcxq6uIXndRxfj7mRxHtzSHibYPPisIItJ KOz24XIB+SYww== Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-3137c877092so55590267b3.13; Thu, 09 Jun 2022 15:23:14 -0700 (PDT) X-Gm-Message-State: AOAM5320POycCwR6kcCmztV7pgTch3m2ZremaQPZDxpNk4kXxEQ8tPc7 zm+VD/cI8Kg2oQfLTEmEOLxj5M6QegiIe9xu5Ms= 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 Cc: Masami Hiramatsu , Jarkko Sakkinen , 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 , Ard Biesheuvel , "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 , 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" Content-Transfer-Encoding: quoted-printable 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, 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