Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4170457ybi; Fri, 5 Jul 2019 23:21:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgXKtvheGoQunn5Gp+iBIRNAvOCjyfNbEt1qhkrZP5geHPBe0A6oU+cRctXtnUrHS90xQJ X-Received: by 2002:a17:90a:cb18:: with SMTP id z24mr9708992pjt.108.1562394103937; Fri, 05 Jul 2019 23:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562394103; cv=none; d=google.com; s=arc-20160816; b=JlCYZNUoudKIFBjN8tO3YOsDOKuz1iMEAe+S2cVk4mQpnYyBER2zMpMDBL/1wQ+/gE fsJyMlaMCfWso2NjJ3KVRrwCNVgu2Hw60+tC9V3dYm9cqbXg9QJTvrCkO5kDIxWTbMKK b5/iFb7SjzUGjPhpzi9JO/USs7p9tyBXO+ChiNcZX56Ib3vhz17rK7bsFO42jArUBElB PiSjYjAaV80vhVWCxv0dZNKgO06wbiCSS7Xo5ey+OIxZ6SdP0eZCUbxfrajvT5UZUhWK ZitKMhXTiw2Bob7FO5cgCQhhWJht3Vw7Xy9SkOW9+sAYAau82627FDKkib5Cjcjbn5ec MOyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=lQ3X6dLSLUwjU3pm/BC0mhB6bgUq8FohwweygLLGWjY=; b=WBtrhAt/aWmf4+KZHVEgt9MezCbbFriZwqefPTffk6rHI8JfM2bKZ0V+pkhIx8fA+W vlnaIXkav/dyIuZJNnAPZCfHburhZo8Hgq5RtBXeNlB2ook15UmpX5qbfpKay2UfIhr3 WFUJHsHXCjqU+LgT+rjmKythUc1g82EzocMRUfz3dLI/7A6qhE+gJTaPo7e5AfYkdvcH u5vEWNl9Y9R7RTSOTjCBIn3QFoAdOvN+Q1buZLZX9hM+caLgOl9b8vWGeOljucMFc3kv HoQmIPmShwfrIs9CjlGOJqO4xHRqLZtOtouSsnIa1Tyc7SItq9QsClTSmaYyCN13dAeR Il5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 205si11908857pge.295.2019.07.05.23.21.29; Fri, 05 Jul 2019 23:21:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725983AbfGFGSX (ORCPT + 99 others); Sat, 6 Jul 2019 02:18:23 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:35006 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725900AbfGFGSX (ORCPT ); Sat, 6 Jul 2019 02:18:23 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 55ECC99253F3C03CB4B3; Sat, 6 Jul 2019 14:18:17 +0800 (CST) Received: from [127.0.0.1] (10.184.225.177) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Sat, 6 Jul 2019 14:18:10 +0800 Subject: Re: [PATCH v2] module: add usage links when calling ref_module func From: Zhiqiang Liu To: Jessica Yu , , , CC: LKML , , , Mingfangsen References: <4fec6c3b-03b8-dd57-4009-99431105a8a5@huawei.com> Message-ID: <7c865af8-a178-a10f-bdcb-7750ab27c2ce@huawei.com> Date: Sat, 6 Jul 2019 14:17:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <4fec6c3b-03b8-dd57-4009-99431105a8a5@huawei.com> Content-Type: text/plain; charset="gb18030" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.184.225.177] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Friendly ping ... On 2019/7/3 10:09, Zhiqiang Liu wrote: > From: Zhiqiang Liu > > Users can call ref_module func in their modules to construct > relationships with other modules. However, the holders > '/sys/module//holders' of the target module donot include > the users` module. So lsmod command misses detailed info of 'Used by'. > > When load module, the process is given as follows, > load_module() > -> mod_sysfs_setup() > -> add_usage_links > -> do_init_module > -> mod->init() > > add_usage_links func creates holders of target modules linking to > this module. If ref_module is called in mod->init() func, the usage > links cannot be added. > > Here, we will add usage link of a to b's holder_dir. > > V1->V2: > - remove incorrect Fixes tag > - fix error handling of sysfs_create_link as suggested by Jessica Yu > > Signed-off-by: Zhiqiang Liu > Suggested-by: Jessica Yu > Reviewed-by: Kang Zhou > --- > kernel/module.c | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/kernel/module.c b/kernel/module.c > index 80c7c09584cf..672abce2222c 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -837,25 +837,26 @@ static int already_uses(struct module *a, struct module *b) > * 'b' can walk the list to see who sourced them), and of 'a' > * targets (so 'a' can see what modules it targets). > */ > -static int add_module_usage(struct module *a, struct module *b) > +static struct module_use *add_module_usage(struct module *a, struct module *b) > { > struct module_use *use; > > pr_debug("Allocating new usage for %s.\n", a->name); > use = kmalloc(sizeof(*use), GFP_ATOMIC); > if (!use) > - return -ENOMEM; > + return NULL; > > use->source = a; > use->target = b; > list_add(&use->source_list, &b->source_list); > list_add(&use->target_list, &a->target_list); > - return 0; > + return use; > } > > /* Module a uses b: caller needs module_mutex() */ > int ref_module(struct module *a, struct module *b) > { > + struct module_use *use; > int err; > > if (b == NULL || already_uses(a, b)) > @@ -866,9 +867,18 @@ int ref_module(struct module *a, struct module *b) > if (err) > return err; > > - err = add_module_usage(a, b); > + use = add_module_usage(a, b); > + if (!use) { > + module_put(b); > + return -ENOMEM; > + } > + > + err = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); > if (err) { > module_put(b); > + list_del(&use->source_list); > + list_del(&use->target_list); > + kfree(use); > return err; > } > return 0; >