Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10083071ybi; Wed, 10 Jul 2019 23:11:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzb1S3sKbvEEYQ/xV+adQpxyWpOoO8rEwwexJp98dRZVEVj07k1FGAcdgJHcKNwnD1LUpyr X-Received: by 2002:a17:902:324:: with SMTP id 33mr2621903pld.340.1562825477250; Wed, 10 Jul 2019 23:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562825477; cv=none; d=google.com; s=arc-20160816; b=Q2fgGN+HU1z+JZ1eIKrPw4zSOTfzvxcSv1K5CNUMTsFpm8nxvHqEarpLxh2aKaQ98N SFrXurmHj2Qk+K5puCyshJlrwblhIIKEBa/aXlrsAJOwgF31yzTVQHIGWzhyi5emBKQM mKWn4J53RtWEv2QdFprYj6F36IkaCWoml5Qc9Bj9MTQTJOOcO+RKG6HRE9Sv+s7YqxSB 5s0EqzHu6QPy2b5BNAilU8j3czYsSXHV/GpkG3cGpt7RHe87gy4IvF3fgD9u4bsWvUxI ZUxSvxpmZ5747G+J4XMI+A0KR0b5GE3o2j1Ayt9nKNHf8Gi7JdcNIj/c+x8DBVR7DhVk FQRA== 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:from:references:cc:to :subject; bh=1dmWmqYJ+M+eCUQU/lz7cPHKJBgullOIxMyDjoDZMe4=; b=wqX4g2qdwm53McIrYUFHnw4W7yUes9iZwsrs5a4qHTC7IsSbrhFjGJj99/zGxw/COl RlV3pvd/ykvLUZXpmcfnTFushKWm96bA5P7RbqU/Mgwu+r+pS38NgQTZqUyIayDPgi9P WncYsBvxvvdU/gmiEhNRD1ig6lNdTr1+62xW2LW/P4rHypeju1Y/yKYnk44BZP5u3j/q T/tXE7X+Ve8Q+K63xmX3/Xh05AQU5H+O5ybkzGoLTISE9vnXc5B0BGN06UQCqAB2vhvJ 2VgwRahkpy0J+8kgbWw771KKN/TQm7QGl/QyMqAow5+hzHBrQv6wFwgcO5Ec/gkLaXjh UAng== 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 bc7si4027126plb.55.2019.07.10.23.11.01; Wed, 10 Jul 2019 23:11:17 -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 S1727968AbfGKGJD (ORCPT + 99 others); Thu, 11 Jul 2019 02:09:03 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2201 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726363AbfGKGJD (ORCPT ); Thu, 11 Jul 2019 02:09:03 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 06F992214731C6D96050; Thu, 11 Jul 2019 14:08:59 +0800 (CST) Received: from [127.0.0.1] (10.184.225.177) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Thu, 11 Jul 2019 14:08:50 +0800 Subject: Re: [PATCH v2] module: add usage links when calling ref_module func To: Jessica Yu CC: , , , LKML , , , Mingfangsen References: <4fec6c3b-03b8-dd57-4009-99431105a8a5@huawei.com> <20190709161039.GA3501@linux-8ccs> From: Zhiqiang Liu Message-ID: Date: Thu, 11 Jul 2019 14:03:12 +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: <20190709161039.GA3501@linux-8ccs> Content-Type: text/plain; charset="gb18030" Content-Transfer-Encoding: 8bit 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 On 2019/7/10 0:10, Jessica Yu wrote: > +++ Zhiqiang Liu [03/07/19 10:09 +0800]: >> From: Zhiqiang Liu > >> 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) >> ?0?2*?0?2?0?2?0?2 'b' can walk the list to see who sourced them), and of 'a' >> ?0?2*?0?2?0?2?0?2 targets (so 'a' can see what modules it targets). >> ?0?2*/ >> /* Module a uses b: caller needs module_mutex() */ >> int ref_module(struct module *a, struct module *b) >> { >> +?0?2?0?2?0?2 struct module_use *use; >> ?0?2?0?2?0?2?0?2int err; >> >> ?0?2?0?2?0?2?0?2if (b == NULL || already_uses(a, b)) >> @@ -866,9 +867,18 @@ int ref_module(struct module *a, struct module *b) >> ?0?2?0?2?0?2?0?2if (err) >> ?0?2?0?2?0?2?0?2?0?2?0?2?0?2 return err; >> >> -?0?2?0?2?0?2 err = add_module_usage(a, b); >> +?0?2?0?2?0?2 use = add_module_usage(a, b); >> +?0?2?0?2?0?2 if (!use) { >> +?0?2?0?2?0?2?0?2?0?2?0?2?0?2 module_put(b); >> +?0?2?0?2?0?2?0?2?0?2?0?2?0?2 return -ENOMEM; >> +?0?2?0?2?0?2 } >> + >> +?0?2?0?2?0?2 err = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); > > Sigh. This ultimately doesn't work because in load_module(), we use > ref_module() in resolve_symbol(), and mod->mkobj.kobj doesn't get > initialized until mod_sysfs_init(), which happens much later in > load_module(). So what happens is that the ref_module(mod, owner) call > in resolve_symbol() returns an error because sysfs_create_link() fails here. > We could *maybe* move sysfs initialization earlier in load_module() > but that is an entirely untested idea and I would need to think about > that more. Thank you for the reply. I have tested the patch through livepatch. Maybe I miss somethings. I will rewrite the patch and test it entirely before sending the v3 patch. Thanks again.