mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zizhi Wo <wozizhi@huaweicloud.com>
To: Nilay Shroff <nilay@linux.ibm.com>,
	Zizhi Wo <wozizhi@huaweicloud.com>,
	axboe@kernel.dk, dlemoal@kernel.org, kch@nvidia.com,
	johannes.thumshirn@wdc.com, kbusch@kernel.org,
	bvanassche@acm.org, linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, yangerkun@huawei.com,
	chengzhihao1@huawei.com
Subject: Re: [PATCH V3 6/6] null_blk: mark racy configfs attribute accesses with READ_ONCE/WRITE_ONCE
Date: Thu, 9 Jul 2026 10:17:01 +0800	[thread overview]
Message-ID: <264a41dd-b072-490b-aada-c50c46c7a6c6@huaweicloud.com> (raw)
In-Reply-To: <eef66514-5f53-420c-9b42-5af9c261852c@linux.ibm.com>



在 2026/7/9 1:49, Nilay Shroff 写道:
> On 7/8/26 1:09 PM, Zizhi Wo wrote:
>> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/ 
>> main.c
>> index 9e0002e4aeec..fd3c993a67b2 100644
>> --- a/drivers/block/null_blk/main.c
>> +++ b/drivers/block/null_blk/main.c
>> @@ -346,7 +346,7 @@ static ssize_t                                \
>>   nullb_device_##NAME##_show(struct config_item *item, char *page)    \
>>   {                                    \
>>       return nullb_device_##TYPE##_attr_show(                \
>> -                to_nullb_device(item)->NAME, page);    \
>> +            READ_ONCE(to_nullb_device(item)->NAME), page);    \
>>   }                                    \
>>   static ssize_t                                \
>>   nullb_device_##NAME##_store(struct config_item *item, const char 
>> *page,    \
>> @@ -366,7 +366,7 @@ nullb_device_##NAME##_store(struct config_item 
>> *item, const char *page,    \
>>       else if (test_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags))     \
>>           ret = -EBUSY;                        \
>>       if (!ret)                            \
>> -        dev->NAME = new_value;                    \
>> +        WRITE_ONCE(dev->NAME, new_value);            \
>>       mutex_unlock(&lock);                        \
>>       if (ret < 0)                            \
>>           return ret;                        \
> 
> So in this series I see that all attribute _store() methods are now 
> protected
> by the file-scoped mutex, which wasn't the case before. If this is 
> intentional,
> have you considered protecting _show() with the same mutex as well? If 
> yes, then
> that would avoid the lockless read/write races without requiring the 
> additional
> READ_ONCE()/WRITE_ONCE() annotations throughout the code.
> 
> Since these configfs attribute accesses are not on the I/O hot path, 
> taking the
> mutex in _show() also seems acceptable from a performance perspective. 
> Earlier
> in the previous series, I suggested using READ_ONCE/WRITE_ONCE because only
> _store() methods using apply_fn attributes were using the lock but that's
> not the case now.
> 
> Thanks,
> --Nilay

Thanks for the suggestion.

Indeed, _store() now takes the lock unconditionally. Otherwise the
else-branch of _store() could run concurrently with
nullb_device_power_store() -> null_add_dev() during power-on and cause
other problems. So taking the lock in _show() directly avoids the races,
without scattering ~a dozen WRITE_ONCE() across two files.

Since this is not a hot path, and I/O hot paths such as
null_complete_cmd() are rejected from writing during power-on anyway,
this is fine.

I'll drop this patch and instead take "lock" in _show() (and in
power_show()) in the next revision.

Thanks,
Zizhi Wo







      reply	other threads:[~2026-07-09  2:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  7:39 [PATCH V3 0/6] null_blk: fix init/exit races and memleaks Zizhi Wo
2026-07-08  7:39 ` [PATCH V3 1/6] null_blk: use DEFINE_MUTEX for the file-scope mutex Zizhi Wo
2026-07-08  7:39 ` [PATCH V3 2/6] null_blk: register configfs subsystem after creating default devices Zizhi Wo
2026-07-08 15:51   ` Bart Van Assche
2026-07-08  7:39 ` [PATCH V3 3/6] null_blk: move unregister_blkdev() after destroying dev in null_exit() Zizhi Wo
2026-07-08 15:51   ` Bart Van Assche
2026-07-08  7:39 ` [PATCH V3 4/6] null_blk: free global tag_set on init error path Zizhi Wo
2026-07-08 15:56   ` Bart Van Assche
2026-07-08  7:39 ` [PATCH V3 5/6] null_blk: serialize configfs attribute stores with device setup Zizhi Wo
2026-07-08  9:11   ` Zizhi Wo
2026-07-08  7:39 ` [PATCH V3 6/6] null_blk: mark racy configfs attribute accesses with READ_ONCE/WRITE_ONCE Zizhi Wo
2026-07-08 17:49   ` Nilay Shroff
2026-07-09  2:17     ` Zizhi Wo [this message]

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=264a41dd-b072-490b-aada-c50c46c7a6c6@huaweicloud.com \
    --to=wozizhi@huaweicloud.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=chengzhihao1@huawei.com \
    --cc=dlemoal@kernel.org \
    --cc=johannes.thumshirn@wdc.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nilay@linux.ibm.com \
    --cc=yangerkun@huawei.com \
    /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®