Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5342931rwb; Mon, 14 Nov 2022 03:15:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4X0eTFtTgoY42lAUEqdDpOGuWmk2TVzP7cPurgCrOYxlhR/3avZYSYXIQiQFrcDZOharAR X-Received: by 2002:a17:907:9144:b0:7a8:3597:34a8 with SMTP id l4-20020a170907914400b007a8359734a8mr9804460ejs.628.1668424542728; Mon, 14 Nov 2022 03:15:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668424542; cv=none; d=google.com; s=arc-20160816; b=WmFCaQ1WT/A21Q3PSAJ1dG4gOmYn+s6HzxAVh1XbgN4SLh49n2OZkO5WQSId9RGIpQ lbDUOLzjw93cLoIbZt26T9iH3cpu9Qw0XNev/gy8EEikySXvBIOWdjU/AsXr8poBOqEt 685MfSuBx94bR6ebYKbvr4ykeiH3voz8X5f5IHDlelPPi3vi0CbvUmHthmiY13T0ZYYp auJVXAJWrivls2np7ZmexiN15jN+JMUlLSUjgVKyXkw24aEFBb4yMQ4fdejxVwLW/vFr n3cjgYYGOByyBuDMWR3oq0j62Z7Wv/IUkRPcLxPi9mZmgmHBXx30ExOJqpfzKUhmMVDz S/vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=TtcLNi7tC7VoXUW8XmXn99oLkoAAo0InkjTMRf4bmeE=; b=u78REYa4ZLOFr31ex23fWoeZAt9eYBGbQrJM5tXDvoJKvR0mn3h1Aukb2fAF0NAEpR qiXYq8teh7r9TCTTUnl/cc6bD8jIRc/9aKqVwVwvlDecymleR6PTA4G4w1nwE73QRYgZ nF7kiY/MUKq/kNf194EwAMSniquODc+vraQ1EvphF5sl0oXXIsCgY0dAF2X0KKC2Ke2x PmXZvzxIixptJMZ1rsZqgZon4/MgTuLW7083FH7pRuiZgO091PRmjvyV7a3wvJoLglYr EMOEXM01UQDkYoCgiDL84GVaV/jo6sDHLOQG7048YVEAVyMNep+zI8n/aMj6nIgFg2Sh KADA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cnkmuHD7; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw13-20020a170906478d00b0078d148daf4bsi8525725ejc.409.2022.11.14.03.15.21; Mon, 14 Nov 2022 03:15:42 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=cnkmuHD7; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236406AbiKNKbq (ORCPT + 88 others); Mon, 14 Nov 2022 05:31:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236269AbiKNKbL (ORCPT ); Mon, 14 Nov 2022 05:31:11 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B325E13CEB; Mon, 14 Nov 2022 02:31:10 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id o30so7146044wms.2; Mon, 14 Nov 2022 02:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=TtcLNi7tC7VoXUW8XmXn99oLkoAAo0InkjTMRf4bmeE=; b=cnkmuHD7oFyxoE3BFuMTChrbYeCfQtstPgtM5B1oWK1SXWUj8xVQ9s86ljm4VGdq0e 2gmJPnqZBi9Q0XqWd6MzA0pGOO/JGtzqTsaexGkMH2ghLTkSzI3X0dmnmP0fc2ip2XIC c5GH1dKY40VqlM2m+JNsGawSOzZ9HItXFJgfe1/apiIOtXBUk+P3dtaWF7AmthDs+qkJ tQeOQ+JvAMRV037sL61QwRWHXp+bHm8sOiBIHy6sv4pDsK4zsP10GWBro6fLWenbVfKq sMBGt96H/dyPqJ0x1pyaXiwJpq91eD/Fljp+4djd6fEq3qv1ZZrqfHCaBVgGdWNvmLDP YdQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TtcLNi7tC7VoXUW8XmXn99oLkoAAo0InkjTMRf4bmeE=; b=6pQD0HxBzgSsDnS/SSSP/3ACSITghwCJQBh8U8iZIadwunKag4mZhwjL6lrpFK1h1d QxUHC4ixY+IZXRYsnG7nDt2OUQw5KRqCbOjKWEFLX3t6Kje8la9YCtdGl8/l9Z6Ow0o8 N3WiHGbMGbvuD7wM7qB8CDH0JGOPxvIihYlxPHlhANqypbAo1XqcpSayRlcom3mk22AB YgkGEdIyJX6phQ9Kr3AgNMexe2y2pufclqalDkvtORZejC4zS9OoHdt+og9x8O66Lm/n q7v6RZI5JtWtD2YKkP5jZHkL2rqLUdGNNooxe1qLBP3C5L3iOF/SIt33398l0Apagf3Q AvZg== X-Gm-Message-State: ANoB5pmHMeUVaYHVAeKKLg6HSWc/TRNBQ0N0mKYgf/rujUOH2JM8DMLo YDH/+smE2B4eo8GWw2mf8zM= X-Received: by 2002:a05:600c:1c1a:b0:3cf:aae0:802a with SMTP id j26-20020a05600c1c1a00b003cfaae0802amr7467422wms.112.1668421869130; Mon, 14 Nov 2022 02:31:09 -0800 (PST) Received: from krava (2001-1ae9-1c2-4c00-726e-c10f-8833-ff22.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:726e:c10f:8833:ff22]) by smtp.gmail.com with ESMTPSA id g4-20020a5d4884000000b002383e977920sm9105111wrq.110.2022.11.14.02.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 02:31:08 -0800 (PST) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Mon, 14 Nov 2022 11:31:06 +0100 To: "Leizhen (ThunderTown)" Cc: Jiri Olsa , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Masahiro Yamada , Alexei Starovoitov , Kees Cook , Andrew Morton , Luis Chamberlain , linux-modules@vger.kernel.org, Steven Rostedt , Ingo Molnar , David Laight , Stephen Rothwell Subject: Re: [PATCH v8 7/9] livepatch: Improve the search performance of module_kallsyms_on_each_symbol() Message-ID: References: <20221102084921.1615-1-thunder.leizhen@huawei.com> <20221102084921.1615-8-thunder.leizhen@huawei.com> <050b7513-4a20-75c7-0574-185004770329@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Mon, Nov 14, 2022 at 06:00:38PM +0800, Leizhen (ThunderTown) wrote: > > > On 2022/11/14 17:27, Jiri Olsa wrote: > > On Mon, Nov 14, 2022 at 04:50:25PM +0800, Leizhen (ThunderTown) wrote: > >> > >> On 2022/11/14 15:47, Jiri Olsa wrote: > >>> On Wed, Nov 02, 2022 at 04:49:19PM +0800, Zhen Lei wrote: > >>>> Currently we traverse all symbols of all modules to find the specified > >>>> function for the specified module. But in reality, we just need to find > >>>> the given module and then traverse all the symbols in it. > >>> hi, > >>> sorry for delayed answer, I did not notice this until Stephen's email > >>> about merge issue with recent bpf change [1] > >>> > >>>> Let's add a new parameter 'const char *modname' to function > >>>> module_kallsyms_on_each_symbol(), then we can compare the module names > >>> we have use case for iterating all modules and their symbols when we > >>> want to resolve passed addresses for tracing > >>> > >>> we don't have 'modname' that we could pass, we need to iterate all modules > >>> > >>> so perhaps this could be made optional like with passing NULL for modname? > >> The deletion of modname was suggested by Petr Mladek. The reason is that > >> everyone passes modname as NULL, there was no actual demand at the time. > >> https://lkml.org/lkml/2022/9/20/682 > >> > >>>> directly in this function and call hook 'fn' after matching. And the > >>>> parameter 'struct module *' in the hook 'fn' can also be deleted. > >>> we need 'struct module *' argument in the callback as well because we are > >>> taking the module reference if we trace function in it, so it wont get > >>> unloaded > >>> > >>> please let me know if I should do the change or can help in any way > >> It seems that we should take the module reference before invoking callback > >> and put it after it is called, without passing modname. > > we take the module ref only if we (callback) find the traced address in > > the module, we don't have the module object before > > > > jirka > > > > Do it in function module_kallsyms_on_each_symbol()? > > But I just saw that mutex_lock(&module_mutex) protection is already > provided in this function. So reference counting protection may not > be required. we take the module ref so it won't unload even outside of the module_kallsyms_on_each_symbol function jirka