mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hou Tao <houtao1@huawei.com>
To: <paulmck@kernel.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
	Josh Triplett <josh@joshtriplett.org>,
	<linux-kernel@vger.kernel.org>, <rcu@vger.kernel.org>
Subject: Re: [PATCH 2/2] locktorture: call percpu_free_rwsem() to do percpu-rwsem cleanup
Date: Wed, 23 Sep 2020 10:24:20 +0800	[thread overview]
Message-ID: <fe8c274e-efa4-04ec-0d95-d7c49ec4dd83@huawei.com> (raw)
In-Reply-To: <20200922232426.GL29330@paulmck-ThinkPad-P72>

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 <houtao1@huawei.com>
>> ---
>>  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.



  reply	other threads:[~2020-09-23  2:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 13:59 [PATCH 0/2] two tiny fixes for locktorture Hou Tao
2020-09-17 13:59 ` [PATCH 1/2] locktorture: doesn't check nreaders_stress when no readlock support Hou Tao
2020-09-17 16:58   ` Paul E. McKenney
2020-09-18  1:13     ` Hou Tao
2020-09-18  3:37       ` Paul E. McKenney
2020-09-18 11:44         ` [PATCH v2 " Hou Tao
2020-09-18 17:59           ` Paul E. McKenney
2020-09-19  3:25             ` Hou Tao
2020-09-17 13:59 ` [PATCH 2/2] locktorture: call percpu_free_rwsem() to do percpu-rwsem cleanup Hou Tao
2020-09-22 23:24   ` Paul E. McKenney
2020-09-23  2:24     ` Hou Tao [this message]
2020-09-23  3:51       ` Paul E. McKenney
2020-09-24 14:18         ` [PATCH v2 " Hou Tao
2020-09-25 17:13           ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe8c274e-efa4-04ec-0d95-d7c49ec4dd83@huawei.com \
    --to=houtao1@huawei.com \
    --cc=dave@stgolabs.net \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®