Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2804692iof; Wed, 8 Jun 2022 12:23:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+Sygoquk8HXbG2+9DXXhBQmlcbSRGiwQ2V5fhCpUU/mdEye9AlHvxg6gwIUdpprKkRxW/ X-Received: by 2002:a05:6a00:1146:b0:4c9:ede0:725a with SMTP id b6-20020a056a00114600b004c9ede0725amr36134784pfm.35.1654716215589; Wed, 08 Jun 2022 12:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654716215; cv=none; d=google.com; s=arc-20160816; b=kaXOOCnQr6yJHbC3hgOpbd3EFQ+lERo8uVYcN6LmvY4hjjIrnXqKllPI/5iLHfuqwF cvHNFRdj6osGg1BSoTolV+t9ssLSvSbHzYtrd0+bEoV0ACIExSCiTj6GFUfsb8ipOC8A hFVUsxSETbWyC/g6ZVYnMkASolQbE+u0S/qpAwWcRfmheMM7a8amPS1y2PW7UAWEls2/ LPIc7tXrzOWH5LWdsTHoVGMZDG+WcanW8Q4lHm8LuJx79FA/xG5g/nnf5MxV8lKRAMmZ SYKBEpDcOycIo8lQUXiA4VRpPXVxXKYooeBDu9iPiUrGw7EzLTu3MbBZqlltPp85xoA4 Olbg== 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=o2Iw8swfZuUQy+62vqyuWTnd5FRAdH3q5mToZUKUVO8=; b=auBX6sCZoK2QXOIj15/FacoXVlAQ9uk3KFRO/M0Fw6aXzjChdLxglv58I67nWAUc6a HbhfKxP4Cx/iCisuDi4QmpmVib8nU0iJbKGrPEl8DRrcdazr3wDCBw5q4/ttEFDaPOPv IlozD9sBTw6aQCkEPFdH9HTkMBlC3ZaCZxNT58/x7Ytm4Lkr8XP4IglvRZjn4k//5th5 LCfT59Pmpk242ixunvwZqRVdY4hSyoRPB83a2O/t4nUcHS4/OY/PHxfxlYkqeTZjDG4c QzIGsZYuI5pWhsr2al1tGmQsScMuX3cuu3JLY1y5Gg4JhrfW7ajwxUf92j+Mcl6dsNzI p8nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=StmQEqAd; 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 q17-20020a656851000000b003fcbc8b5e7dsi31044873pgt.811.2022.06.08.12.23.20; Wed, 08 Jun 2022 12:23:35 -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=StmQEqAd; 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 S234191AbiFHSVY (ORCPT + 99 others); Wed, 8 Jun 2022 14:21:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234832AbiFHSTe (ORCPT ); Wed, 8 Jun 2022 14:19:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00A8CA478; Wed, 8 Jun 2022 11:19:32 -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 8169161BE2; Wed, 8 Jun 2022 18:19:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7868C341C7; Wed, 8 Jun 2022 18:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654712371; bh=BrMt+22N41uzooUnzPUoRXnpI1kF+bmp+ST9j+9wk1U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=StmQEqAdS/onK3x3jVjIrEPS7TE62tVZdrRl7yCCLHSUtqUl0sszeA6m8IlQMUNsA NvP9xfO+4f6DpVsUlbf1p7SW00y59l0D1/aohwUdP1Rx+Aw3fUa72rTgnaXH2ZU83H cAkDe0Y5m+t3lNizmtlx2uVxbXKzZBnvDSWMoorJ15pwBINXXH+G8wX2sAst40Zjua Eaf5HK8xbP0FLlhBxPWDLcKebIC3jMHyhOXWNqtOvhPj5z9/w2cb4RaJ1eBhXASHvn wc+WGtmUbt6NeBYy6IhVV/qOnSfCrnCFdt5r6qizloiVh1oWyc8bULajR66pSo9DRj 4zGyMP7SfH29Q== Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-2ef5380669cso217877987b3.9; Wed, 08 Jun 2022 11:19:31 -0700 (PDT) X-Gm-Message-State: AOAM530hdWvnvRxyK7MCL6E7R9l1l2aUROIA99QN9AERsiDXI/GpyXAi 6qGYvifuCqiPLRLCfenOoxe80dIbx90DlbdSGNM= X-Received: by 2002:a81:4a82:0:b0:2ff:94b4:b4d1 with SMTP id x124-20020a814a82000000b002ff94b4b4d1mr38668766ywa.130.1654712370883; Wed, 08 Jun 2022 11:19:30 -0700 (PDT) MIME-Version: 1.0 References: <20220608000014.3054333-1-jarkko@profian.com> In-Reply-To: From: Song Liu Date: Wed, 8 Jun 2022 11:19:19 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kprobes: Enable tracing for mololithic kernel images To: Ard Biesheuvel Cc: Jarkko Sakkinen , Linux Kernel Mailing List , Nathaniel McCallum , Jarkko Sakkinen , 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 , X86 ML , "H. Peter Anvin" , "Naveen N. Rao" , Anil S Keshavamurthy , Masami Hiramatsu , 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 , Guo Ren , 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-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-modules@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 Wed, Jun 8, 2022 at 9:28 AM Ard Biesheuvel wrote: > > Hello Jarkko, > > On Wed, 8 Jun 2022 at 02:02, 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. > > I think I may have mentioned this the previous time as well, but I > don't think this is the right approach. > > Kprobes uses alloc_insn_page() to allocate executable memory, but the > requirements for this memory are radically different compared to > loadable modules, which need to be within an arch-specific distance of > the core kernel, need KASAN backing etc etc. I think the distance of core kernel requirement is the same for kprobe alloc_insn_page and modules, no? Thanks, Song > > This is why arm64, for instance, does not implement alloc_insn_page() > in terms of module_alloc() [and likely does not belong in this patch > for that reason] > > Is there any reason kprobes cannot simply use vmalloc()? >