linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] block: fix lock order and remove redundant locking
@ 2025-02-05 14:44 Nilay Shroff
  2025-02-05 14:44 ` [PATCH 1/2] block: fix lock ordering between the queue ->sysfs_lock and freeze-lock Nilay Shroff
  2025-02-05 14:44 ` [PATCH 2/2] block: avoid acquiring q->sysfs_lock while accessing sysfs attributes Nilay Shroff
  0 siblings, 2 replies; 18+ messages in thread
From: Nilay Shroff @ 2025-02-05 14:44 UTC (permalink / raw)
  To: linux-block; +Cc: hch, ming.lei, dlemoal, axboe, gjoyce

Hi,

This patchset contains two patches in the series. The fist patch fixes
the incorrect lock ordering between queue ->sysfs_lock and freeze-lock.
And the second patch avoids using q->sysfs_lock while accessing sysfs
attribute files.

After we modeled the freeze & enter queue as lock for supporting lockdep
under commit f1be1788a32e ("block: model freeze & enter queue as lock
for supporting lockdep"), we received numerous lockdep splats. And one
of those splats[1] reported the potential deadlock due to incorrect lock
ordering issue between q->sysfs-lock and q->q_usage_counter. So the
first patch in the series addresses this lockdep splat.

The second patch in the series removes unnecessary holding of q->sysfs_lock
while we access the sysfs block layer attribute files. Ideally, we don't
need to hold any lock while accessing sysfs attribute files as attribute 
file is already protected with internal sysfs/kernfs locking. For instance,
accessing a sysfs attribute file for reading, follows the following
code path:
    vfs_read
      kernfs_fop_read_iter
        seq_read_iter
          kernfs_seq_start  ==> acquires kernfs internal mutex
            kernfs_seq_show
              sysfs_kf_seq_show
                queue_attr_show

Similarly, accessing a sysfs attribute file for writing, follows the
the following code path:
    vfs_write
      kernfs_fop_write_iter  ==> acquires kernfs internal mutex
        sysfs_kf_write
          queue_attr_store

As shown in the above code path, kernfs internal mutex already protects
sysfs store/show operations, and so we could safely get rid off holding
q->sysfs_lock while accessing sysfs attribute files.

Please note that above changes were unit tested against blktests and
quick xfstests with lockdep enabled.

Nilay Shroff (2):
  block: fix lock ordering between the queue ->sysfs_lock and
    freeze-lock
  block: avoid acquiring q->sysfs_lock while accessing sysfs attributes

 block/blk-mq-sysfs.c |  6 +-----
 block/blk-mq.c       | 49 +++++++++++++++++++++++++++++---------------
 block/blk-sysfs.c    | 10 +++------
 block/elevator.c     |  9 ++++++++
 4 files changed, 46 insertions(+), 28 deletions(-)

-- 
2.47.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2025-02-09 13:41 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-05 14:44 [PATCH 0/2] block: fix lock order and remove redundant locking Nilay Shroff
2025-02-05 14:44 ` [PATCH 1/2] block: fix lock ordering between the queue ->sysfs_lock and freeze-lock Nilay Shroff
2025-02-05 15:59   ` Christoph Hellwig
2025-02-06 13:22     ` Nilay Shroff
2025-02-06 14:15       ` Christoph Hellwig
2025-02-07 11:59       ` Ming Lei
2025-02-07 18:02         ` Nilay Shroff
2025-02-08  8:30           ` Ming Lei
2025-02-08 13:18             ` Nilay Shroff
2025-02-05 14:44 ` [PATCH 2/2] block: avoid acquiring q->sysfs_lock while accessing sysfs attributes Nilay Shroff
2025-02-05 15:53   ` Christoph Hellwig
2025-02-06 13:54     ` Nilay Shroff
2025-02-06 14:07       ` Christoph Hellwig
2025-02-07 11:03         ` Nilay Shroff
2025-02-08 10:41       ` Ming Lei
2025-02-08 12:56         ` Nilay Shroff
2025-02-09 11:41           ` Ming Lei
2025-02-09 13:41             ` Nilay Shroff

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).