Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3853232pxb; Tue, 26 Jan 2021 06:31:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcPmGeJwsuqOzo9wWXcC7Prq1O7wFvoYzEpR1vA/MjdVga+9qnjQx5UMxOdZEZV0HgOak2 X-Received: by 2002:a05:6402:55:: with SMTP id f21mr4933992edu.38.1611671472965; Tue, 26 Jan 2021 06:31:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611671472; cv=none; d=google.com; s=arc-20160816; b=bNQGwHU/Dx5v8WhaJv5xyZ7LqQaKtO7jKzhyOh/LpvMgp+DWW/WWRaitM15hRZNDJs rKheXXgKBTY3NG/vNN5q1/ns+e17fgxsS4TCDhoi0z8JvkGiQpZufiQG3LvF500F+4tC bSoh5px86DBs1xoqjACuWWFLDdA/Fzg635XErdNaLz06rnjMbGvwWAGBVPeO3khYa2qb REFEEhGp7CldHxFrpZXvs/Lt+rkXC4jBljRTGr1WpiiDQDCIdVrdcBpOr2QYhngx9HBf 4xnX0IUi0UTOrTLz3f8LlC48q+lsks6z8Sbj5UZklfNik+HF1aMeUkPMohzYnp0OGgZA 2MDg== 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:from:date:dkim-signature; bh=LlgMD91tQ8Q5UpMdw4eNtKETHxLb2ipIyU676pZz94Y=; b=b2p9ukCpl0Heh5WL9HveaQuuluULMk8rxXGZErqMRG4zfAvE2voAxtiE7u9VjH+gGR MbL2Jtq0kofLR6awbImewC6B5UWroc3N/YZpac5LvqvlfX+AGz3l78VDrUiLzVRtDqrv 06GMUf7y1vmAoeI53uhjaoXrc07z5QR36lJR8WvC/UomyV0gkTYCB5T4rfl2u7sjxs0S WwwcSYfmPByGChk6LokSTPIQ7TzYNFZCzNHx5/praUFwBxPRLJnklnvjHyNPKxQYVIv7 KnSshUTf7XXYORxxA6Altq5xn3+TsdR48GjVUSECkStLb0XD5MTcS0LGvdJKXh8Z7qmf qnUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AwWJCyWM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t5si6900473ejb.381.2021.01.26.06.30.46; Tue, 26 Jan 2021 06:31:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AwWJCyWM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391724AbhAZO37 (ORCPT + 99 others); Tue, 26 Jan 2021 09:29:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:54964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405512AbhAZO0I (ORCPT ); Tue, 26 Jan 2021 09:26:08 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6961222D58; Tue, 26 Jan 2021 14:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611671122; bh=zHnnr84X+sq4MJebqrUFKLvmgQBWczP8DyHjmXerqPg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AwWJCyWMMlFIlbu/JtuoYt7B++r72LxtstkUf4QFYfAtgvNAJcO+WUudPI+0YAm7X 6+fXHHEIDTMTt6kZg6TDZE3I494pl2x+zX+0+Z3zEqrei25Exd4peOX9KjXbAQhMZW Xa3bV03H1QYILOE5MzIPVTXLt6G2TfZkhII8H/n8NeE44Jcp4oDH6zKlyiiGpcSKVc WuVOo/vdgulzezm729DrHzj9hm6nPGrcz0PM9LaYzOPQKp4Sd2o9i+pM1Kp8WLmR0+ U2mB0+m3dKee3MVHvNpv99t3i1c1nsU5sjIS0dr1L4bsBmwPtOHhYgrpk2Li8EKP+Y WcqC3Dro3fjsw== Date: Tue, 26 Jan 2021 15:25:16 +0100 From: Jessica Yu To: Christoph Hellwig Cc: Frederic Barrat , Andrew Donnellan , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, dri-devel@lists.freedesktop.org, live-patching@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: Re: [PATCH 04/13] livepatch: move klp_find_object_module to module.c Message-ID: References: <20210121074959.313333-1-hch@lst.de> <20210121074959.313333-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210121074959.313333-5-hch@lst.de> X-OS: Linux gunter 5.10.7-1-default x86_64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Christoph Hellwig [21/01/21 08:49 +0100]: >To uncouple the livepatch code from module loader internals move a >slightly refactored version of klp_find_object_module to module.c >This allows to mark find_module static and removes one of the last >users of module_mutex outside of module.c. > >Signed-off-by: Christoph Hellwig >--- > include/linux/module.h | 3 +-- > kernel/livepatch/core.c | 39 +++++++++++++-------------------------- > kernel/module.c | 17 ++++++++++++++++- > 3 files changed, 30 insertions(+), 29 deletions(-) > >diff --git a/include/linux/module.h b/include/linux/module.h >index b4654f8a408134..8588482bde4116 100644 >--- a/include/linux/module.h >+++ b/include/linux/module.h >@@ -586,8 +586,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod) > return within_module_init(addr, mod) || within_module_core(addr, mod); > } > >-/* Search for module by name: must hold module_mutex. */ >-struct module *find_module(const char *name); >+struct module *find_klp_module(const char *name); > > /* Check if a module is loaded. */ > bool module_loaded(const char *name); >diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c >index a7f625dc24add3..878759baadd81c 100644 >--- a/kernel/livepatch/core.c >+++ b/kernel/livepatch/core.c >@@ -49,30 +49,6 @@ static bool klp_is_module(struct klp_object *obj) > return obj->name; > } > >-/* sets obj->mod if object is not vmlinux and module is found */ >-static void klp_find_object_module(struct klp_object *obj) >-{ >- struct module *mod; >- >- mutex_lock(&module_mutex); >- /* >- * We do not want to block removal of patched modules and therefore >- * we do not take a reference here. The patches are removed by >- * klp_module_going() instead. >- */ >- mod = find_module(obj->name); >- /* >- * Do not mess work of klp_module_coming() and klp_module_going(). >- * Note that the patch might still be needed before klp_module_going() >- * is called. Module functions can be called even in the GOING state >- * until mod->exit() finishes. This is especially important for >- * patches that modify semantic of the functions. >- */ >- if (mod && mod->klp_alive) >- obj->mod = mod; >- mutex_unlock(&module_mutex); >-} Hmm, I am not a huge fan of moving more livepatch code into module.c, I wonder if we can keep them separate. Why not have module_is_loaded() kill two birds with one stone? That is, just have it return a module pointer to signify that the module is loaded, NULL if not. Then we don't need an extra find_klp_module() function just to call find_module() and return a pointer, as module_is_loaded() can just do that for us. As for the mod->klp_alive check, I believe this function (klp_find_object_module()) is called with klp_mutex held, and mod->klp_alive is only modified under klp_mutex. Also, if klp_alive is true, the module is at least COMING and cannot be GOING until it acquires the klp_mutex again in klp_module_going(). So does that hunk really need to be under module_mutex? It has been a long time since I've looked at livepatch code so it would be great if someone could double check. Jessica