Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1211233iol; Sun, 12 Jun 2022 09:07:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLVEeTx4lpfaBRZN16ro+7htEAOtH2jbm8I2nQy1DXgXPojjtfvCUzIbCmAYDZWiEEjHdN X-Received: by 2002:a05:6402:5211:b0:42e:2e1c:5bce with SMTP id s17-20020a056402521100b0042e2e1c5bcemr54404207edd.198.1655050068918; Sun, 12 Jun 2022 09:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655050068; cv=none; d=google.com; s=arc-20160816; b=lS7pmqmbyBE3DRsw0GvtR3Z5XVEATGUTAX4fRWoQPv4KbQ0icCt3IqebaoqTXWzCls Vgt5EPnZhUkd1R24xsw3XpPwwUKEQ2XVkxhIXqDqZy8RW0YGgNTmNnC8wXv08MENYu9m o0MICi4qPobX1Azkm/arydwiFcmnfNHYBwvZU1MtMtqp9KLtliRSNtw3wjXaRl9XlW3g rg+LHL1a35C5QN93nB6J23BuDSMMtRBhewufniJ2QJ7D776UBmyPhdyzWpDnqk0GK1Of 7HL0vR5OhNrYfd1XW349IBOovtLc8kJ8GZP85KfFCKzImtcNyQv9BEwrUHw410wJWmOG efUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=KSqLGFTdXknieseSeuTfrpApRy4mabmfKPCLjdMbG3I=; b=vozzhNJ+JfW7inufqd2oXt+m+zAxVCLLVDxLXLBw351s//ieIJS6VY1sQDXNp1sN3U bnXK1JBq9mDGbWH7WSMyBUVi5zD1P+IjGR6srwHTgyHNM8iNFlbrPJFee/PODjS+rtWD CoBVJxFUbb5pQgh5m6sQaVMqrfG00wSdyMFbgdolKLEJ6hHB5GzLPN8UCH9c3Hvbq7k2 ft49JjsNZ+tN5YZNqs8u4EY1i7UYYmAbn5logADz28i9+tP5mOHdhtmCBmCzi3SHO+6b N48pXmj19s14xbecHhZVzDjep3PCF1pAGoY/cysfFzq4m/qPTHdVpYIUnsKg6vQfTWg3 NYYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hJVwSxcZ; 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 dn21-20020a17090794d500b00711f7d60f41si5793103ejc.856.2022.06.12.09.07.24; Sun, 12 Jun 2022 09:07:48 -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=hJVwSxcZ; 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 S236536AbiFLMSc (ORCPT + 99 others); Sun, 12 Jun 2022 08:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234382AbiFLMSa (ORCPT ); Sun, 12 Jun 2022 08:18:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A15FAE7E; Sun, 12 Jun 2022 05:18:26 -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 CFEF960EB6; Sun, 12 Jun 2022 12:18:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83C2CC34115; Sun, 12 Jun 2022 12:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655036305; bh=WgqWCXOvSOyYM9CA6unsEF9x7497RtdMdOYMhEwuXNA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hJVwSxcZhwtzLwx3w1QhqIA1+qrWZ1YGyKj5qHKKPQ++Yqa816Xz6ppZ1R/IDxtM8 0mGodfwO2v8xthNHRtUQ7dsU9T6KZrnnSnwkX2Km4qoMD4VxgmypasgeO574/wxfWh iPI0tb5tr49puQN4NIA3CqGVLyVln/zbm8lBPZ8hG8qBmrK2oCj41WK75ev21hQO/v iwYspOZKGjKe7g7QShHcxe1rR10SCFSjyNkmdYBtuEMKE90L7FAENwgzstDNcN3N7s 6bz8ns5CJW9GDL1c/9Wzb9AS47ccvnKE6Mk6uAYpYzfOmoKzOnrDABFX7VAQu5vWRi lMYiDZBwwPCeQ== Date: Sun, 12 Jun 2022 21:18:02 +0900 From: Masami Hiramatsu (Google) To: Ard Biesheuvel Cc: Jarkko Sakkinen , 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?B?QW5kcsOp?= 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 Subject: Re: [PATCH] kprobes: Enable tracing for mololithic kernel images Message-Id: <20220612211802.30a16623e8b0a55122b02386@kernel.org> In-Reply-To: References: <20220608000014.3054333-1-jarkko@profian.com> <20220608232115.ccd4399f4a1d133e9b65c2a9@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=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, 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 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()? Thank you, -- Masami Hiramatsu (Google)