Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp92052pxk; Tue, 22 Sep 2020 20:00:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUU11y5G+1Bl2SgmbzZJNtKg6Lx/WbUSX81mefCkjGCPiLHaGCY6bSbdTyD+VYwKDuk1+w X-Received: by 2002:a17:906:7695:: with SMTP id o21mr8075044ejm.176.1600830030836; Tue, 22 Sep 2020 20:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600830030; cv=none; d=google.com; s=arc-20160816; b=YXg9zGtvTN2IP17ygNCpo/iB2v+2Hz29eDWsoRJgAxd1Lq5fYFfHxHgx+eXmrgVuCC X22aJfN3irQkU6YnAigfDHdrVmi9ZA0b/qkHElx+K9nPhVg9I/9yzvk66oQvpQzYBnrT qu6cM8TUnXhjA6dgRVx4WbLFYdDfEg+eNe1Kl4/jOh+FoECiEnontNORVN1YXngxpNXw GYYFgFbjrQo6/y5UUX/gHnCLsRxrgDODQM5eX3BfcXrTL5yt/j7RCXrEZ+dPYvZNVZSi ZLifnMIzdGhgC+Pz18mPrzAt7BV/38YQ/pUUiUbnKoR2UVL58IABMWFgPqNoEb8SbXRE KymA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=XGpl1kjus1dop7qF2tbZdW3paE0k1MxNRf+VHSRJnpo=; b=ZC8Lw7bh/ezvP+thggMLMo7mYlaglgKzxqZRDCcb3Thl3aPai9FueUWheHlh9IRY8I h62hojw1J+slrjMmcnBkKGq7YGk+O7w0ddefdP5Hu3G+4AUiHHaiV6LNQU6Ly9dgoj0W R7X3S3NRjMj/2qMp1/5dforrAHU6OyU6OFibSJy15RFS5VHPVtakuxb4IDFBDnEhfa3q mH+6RomIXnqm0xNz8+5Q3EQMEe+ZEMtmjWldeyooNBnAwZDTIivQQcF98Aebn3K1cavn Fs/1mah4fpFJj0Czw1t75waBvzjEOwFixQFUuFrTwYxYcZPY4O94BYxtUYOuv3ChbgKo QoGQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si12015971edm.221.2020.09.22.20.00.07; Tue, 22 Sep 2020 20:00:30 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727220AbgIWCY0 (ORCPT + 99 others); Tue, 22 Sep 2020 22:24:26 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:36328 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727201AbgIWCY0 (ORCPT ); Tue, 22 Sep 2020 22:24:26 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E49F98152EDEF6D69D05; Wed, 23 Sep 2020 10:24:23 +0800 (CST) Received: from [10.174.177.167] (10.174.177.167) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Wed, 23 Sep 2020 10:24:20 +0800 Subject: Re: [PATCH 2/2] locktorture: call percpu_free_rwsem() to do percpu-rwsem cleanup To: CC: Davidlohr Bueso , Josh Triplett , , References: <20200917135910.137389-1-houtao1@huawei.com> <20200917135910.137389-3-houtao1@huawei.com> <20200922232426.GL29330@paulmck-ThinkPad-P72> From: Hou Tao Message-ID: Date: Wed, 23 Sep 2020 10:24:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200922232426.GL29330@paulmck-ThinkPad-P72> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.167] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paul, > On 2020/9/23 7:24, Paul E. McKenney wrote: snip >> Fix it by adding an exit hook in lock_torture_ops and >> use it to call percpu_free_rwsem() for percpu rwsem torture >> before the module is removed, so we can ensure rcu_sync_func() >> completes before module exits. >> >> Also needs to call exit hook if lock_torture_init() fails half-way, >> so use ctx->cur_ops != NULL to signal that init hook has been called. > > Good catch, but please see below for comments and questions. > >> Signed-off-by: Hou Tao >> --- >> kernel/locking/locktorture.c | 28 ++++++++++++++++++++++------ >> 1 file changed, 22 insertions(+), 6 deletions(-) >> >> diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c >> index bebdf98e6cd78..e91033e9b6f95 100644 >> --- a/kernel/locking/locktorture.c >> +++ b/kernel/locking/locktorture.c >> @@ -74,6 +74,7 @@ static void lock_torture_cleanup(void); >> */ >> struct lock_torture_ops { >> void (*init)(void); >> + void (*exit)(void); > > This is fine, but why not also add a flag to the lock_torture_cxt > structure that is set when the ->init() function is called? Perhaps > something like this in lock_torture_init(): > > if (cxt.cur_ops->init) { > cxt.cur_ops->init(); > cxt.initcalled = true; > } > You are right. Add a new field to indicate the init hook has been called is much better than reusing ctx->cur_ops != NULL to do that. >> int (*writelock)(void); >> void (*write_delay)(struct torture_random_state *trsp); >> void (*task_boost)(struct torture_random_state *trsp); >> @@ -571,6 +572,11 @@ void torture_percpu_rwsem_init(void) >> BUG_ON(percpu_init_rwsem(&pcpu_rwsem)); >> } >> >> +static void torture_percpu_rwsem_exit(void) >> +{ >> + percpu_free_rwsem(&pcpu_rwsem); >> +} >> + snip >> @@ -828,6 +836,12 @@ static void lock_torture_cleanup(void) >> cxt.lrsa = NULL; >> >> end: >> + /* If init() has been called, then do exit() accordingly */ >> + if (cxt.cur_ops) { >> + if (cxt.cur_ops->exit) >> + cxt.cur_ops->exit(); >> + cxt.cur_ops = NULL; >> + } > > The above can then be: > > if (cxt.initcalled && cxt.cur_ops->exit) > cxt.cur_ops->exit(); > > Maybe you also need to clear cxt.initcalled at this point, but I don't > immediately see why that would be needed. > Because we are doing cleanup, so I think reset initcalled to false is OK after the cleanup is done. >> torture_cleanup_end(); >> } >> >> @@ -835,6 +849,7 @@ static int __init lock_torture_init(void) >> { >> int i, j; >> int firsterr = 0; >> + struct lock_torture_ops *cur_ops; > > And then you don't need this extra pointer. Not that this pointer is bad > in and of itself, but using (!cxt.cur_ops) to indicate that the ->init() > function has not been called is an accident waiting to happen. > > And the changes below are no longer needed. > > Or am I missing something subtle? > Thanks for your suggestion. Will send v2. Thanks.