Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2674692iof; Wed, 8 Jun 2022 09:39:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIRK1prsmVLD1VhqknZpycJNznH252S+1NxiJ7uz19GUK0YZgfd9JNxgI8Oz64OY5bL5Xb X-Received: by 2002:a62:ab17:0:b0:51b:bf44:a9aa with SMTP id p23-20020a62ab17000000b0051bbf44a9aamr35867411pff.50.1654706392681; Wed, 08 Jun 2022 09:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654706392; cv=none; d=google.com; s=arc-20160816; b=tc0k3zYB+6AkiPe297s3HwPEadj+uWcMkS7ygLQWXEJmecEBraTfp5m16FDQChpBz5 7OuhzYbyBPy6fVLzmvprw2SEe+ZIbNvIi34ABEoazQuPqOY+Xt4nrJ3Ngj8oBx8s/2p3 ZfBFapfiKkt0/n1fIUfyXtRrTgcgRM7Wn1/RREzX7xLePKGuOGOVbq5AFfoaPz7e0qyd 1K+7BWN4nJqyPffSpj0Yx3bz6hCygl2gVpsHWRXuYyQWU4O6TvAVaifjeHc/A1bFdYt+ ZPUecrkeaji0GWWzSnDvnrpdFSV8AcwNPiop3DhJCDV1mzyyeOu3ZbCV67nedUnnqBGr OunA== 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=38HuBAWF7gD1Vrngd4nTaVkJsXzdj9wNQ88iQ8gkhZQ=; b=PnCb9h+VtbsSpDGATQ+hJM6oU5RTyYvlDHznCaR4JdRWJjtfLcDo5i30Ji6J96w4Xe SH0BNRdb4743qz3KFtAAk58FxkUMdwRJdpgCprFF2iEX603QZ7LCZYXvx7wSqlNP+zIa PRGAOcHmtzAbJPtAyPuMA59yX/K7zG0bQG3mKgHHlHh86bsLm6RDxCclMKaiI1vV761n iUOBijLQrfb8I+2lCIzZos7BlK+Bt0Hbqn6fxzP0H2pzJNOgg4MdNqLlC5VMjX6CEJMD P0MPR5ObdDV55+P0eUN5g9qVf046wNolg1oW2piUSHyPbRtXokZTIQr4XWzQEokBlaA2 OU9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lByU8V8g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t34-20020a634462000000b0039db57e26c3si6795574pgk.509.2022.06.08.09.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:39:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lByU8V8g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE5B5BA9B6; Wed, 8 Jun 2022 09:13:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245074AbiFHQM4 (ORCPT + 99 others); Wed, 8 Jun 2022 12:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245050AbiFHQMx (ORCPT ); Wed, 8 Jun 2022 12:12:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8D6242EDF; Wed, 8 Jun 2022 09:12:49 -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 ams.source.kernel.org (Postfix) with ESMTPS id 348DAB82615; Wed, 8 Jun 2022 16:12:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0110C341CF; Wed, 8 Jun 2022 16:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654704766; bh=sPGKDjlNYa4MR2u/HdIgrLdEoGRguN2WqLZlFp878w8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lByU8V8gKdKuGHwNFQ31BBmJTai90bm5fUqFEuBSsaa6btiPhIfz95tJkBi8S9AIO vLz1pK/O2Drl1qSdBQGZEmUkLncmcYqPhY9ojMDcrzj/PoJiylIyB4jQ9TBj1LO7vf E86TLeP7UlVOK/pvkh9gFUxUARll4qyH/h3l61Hb/qa/HAroJ4DVv/04sAyose4z+R l1ezd9XxnR9NMDmViM7wkjScWiuMoHbc3tRttrKQSPMAUuuKANW9byaxXyqnJEWEMK r9QIP0eljUMwKGt9NkqaB84zEOMLtwxSikm7jaOAlUIlC3KnM2nQNlDbedyjaUizAv KmhijBJg1bgVQ== Received: by mail-yb1-f179.google.com with SMTP id g201so9480065ybf.12; Wed, 08 Jun 2022 09:12:46 -0700 (PDT) X-Gm-Message-State: AOAM532dcsgCHnpAC6ITzTX8wYTwyCHGbuLBPuaWxKyH7jd3UJGirvA3 g601s4vKkyIXCMR+16nifS2IuLZzTBgWyFtfD+4= X-Received: by 2002:a25:a242:0:b0:651:a78d:4636 with SMTP id b60-20020a25a242000000b00651a78d4636mr35602450ybi.9.1654704765774; Wed, 08 Jun 2022 09:12:45 -0700 (PDT) MIME-Version: 1.0 References: <20220608000014.3054333-1-jarkko@profian.com> <20220608232115.ccd4399f4a1d133e9b65c2a9@kernel.org> In-Reply-To: <20220608232115.ccd4399f4a1d133e9b65c2a9@kernel.org> From: Song Liu Date: Wed, 8 Jun 2022 09:12:34 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kprobes: Enable tracing for mololithic kernel images To: Masami Hiramatsu Cc: 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 , 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=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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). Thanks, Song > > Acked-by: Masami Hiramatsu (Google) > for kprobe side. > > Thank you, > > -- > Masami Hiramatsu (Google)