linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jan Kara <jack@suse.cz>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	"Darrick J . Wong" <djwong@kernel.org>,
	linux-block@vger.kernel.org, Ming Lei <ming.lei@redhat.com>
Subject: Re: [PATCH 7/8] loop: remove lo_refcount and avoid lo_mutex in ->open / ->release
Date: Tue, 22 Mar 2022 12:09:08 +0100	[thread overview]
Message-ID: <20220322110908.GA28931@lst.de> (raw)
In-Reply-To: <20220316143855.sqm2dk77rbvxtxh7@quack3.lan>

On Wed, Mar 16, 2022 at 03:38:55PM +0100, Jan Kara wrote:
> Well, but another effect of READ_ONCE() / WRITE_ONCE() is that it
> effectively forces the compiler to not store any intermediate value in
> bd_openers. If you have code like bdev->bd_openers++, and bd_openers has
> value say 1, the compiler is fully within its rights if unlocked reader
> sees values, 1, 0, 3, 2. It would have to be a vicious compiler but the C
> standard allows that and some of the optimizations compilers end up doing
> result in code which is not far from this (read more about KCSAN and the
> motivation behind it for details). So data_race() annotation is *not*
> enough for unlocked bd_openers usage.
> 
> > Use of atomic_t for lo->lo_disk->part0->bd_openers does not help, for
> > currently lo->lo_mutex is held in order to avoid races. That is, it is
> > disk->open_mutex which loop_clr_fd() needs to hold when accessing
> > lo->lo_disk->part0->bd_openers.
> 
> It does help because with atomic_t, seeing any intermediate values is not
> possible even for unlocked readers.

The Linux memory model guarantees atomic reads from 32-bit integers.
But if it makes everyone happier I could do a READ_ONCE here.

  reply	other threads:[~2022-03-22 11:09 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16  8:45 yet another approach to fix the loop lock order inversions v3 Christoph Hellwig
2022-03-16  8:45 ` [PATCH 1/8] loop: de-duplicate the idle worker freeing code Christoph Hellwig
2022-03-16  8:45 ` [PATCH 2/8] loop: initialize the worker tracking fields once Christoph Hellwig
2022-03-16  9:26   ` Chaitanya Kulkarni
2022-03-16  8:45 ` [PATCH 3/8] loop: remove the racy bd_inode->i_mapping->nrpages asserts Christoph Hellwig
2022-03-16 10:24   ` Jan Kara
2022-03-16  8:45 ` [PATCH 4/8] loop: don't freeze the queue in lo_release Christoph Hellwig
2022-03-16  8:45 ` [PATCH 5/8] loop: only freeze the queue in __loop_clr_fd when needed Christoph Hellwig
2022-03-16  8:45 ` [PATCH 6/8] loop: implement ->free_disk Christoph Hellwig
2022-03-16 10:30   ` Jan Kara
2022-03-16  8:45 ` [PATCH 7/8] loop: remove lo_refcount and avoid lo_mutex in ->open / ->release Christoph Hellwig
2022-03-16 11:22   ` Jan Kara
2022-03-16 13:14     ` Tetsuo Handa
2022-03-16 14:38       ` Jan Kara
2022-03-22 11:09         ` Christoph Hellwig [this message]
2022-03-23 12:18           ` Jan Kara
2022-03-23 13:09             ` Tetsuo Handa
2022-03-16  8:45 ` [PATCH 8/8] loop: don't destroy lo->workqueue in __loop_clr_fd Christoph Hellwig
2022-03-16 11:25   ` Jan Kara
2022-03-16 13:24     ` Tetsuo Handa
2022-03-22 11:10       ` Christoph Hellwig
2022-03-22 12:42         ` Tetsuo Handa
2022-03-23  0:06           ` Tetsuo Handa
2022-03-16 10:59 ` yet another approach to fix the loop lock order inversions v3 Tetsuo Handa
2022-03-22 11:12   ` Christoph Hellwig

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=20220322110908.GA28931@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=djwong@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    /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;
as well as URLs for NNTP newsgroup(s).