* [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads
@ 2024-11-12 16:00 Mark Harmstone
2024-11-13 8:21 ` Johannes Thumshirn
2024-11-14 15:06 ` David Sterba
0 siblings, 2 replies; 6+ messages in thread
From: Mark Harmstone @ 2024-11-12 16:00 UTC (permalink / raw)
To: linux-btrfs; +Cc: Mark Harmstone, Johannes Thumshirn
Lockdep doesn't like the fact that btrfs_uring_read_extent() returns to
userspace still holding the inode lock, even though we release it once
the I/O finishes. Add calls to rwsem_release() and rwsem_acquire_read() to
work round this.
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/ioctl.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 1fdeb216bf6c..6ea01e4f940e 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4752,6 +4752,11 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int iss
size_t page_offset;
ssize_t ret;
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ /* The inode lock has already been acquired in btrfs_uring_read_extent. */
+ rwsem_acquire_read(&inode->vfs_inode.i_rwsem.dep_map, 0, 0, _THIS_IP_);
+#endif
+
if (priv->err) {
ret = priv->err;
goto out;
@@ -4860,6 +4865,15 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
* and inode and freeing the allocations.
*/
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ /*
+ * We're returning to userspace with the inode lock held, and that's
+ * okay - it'll get unlocked in a kthread. Call rwsem_release to
+ * avoid confusing lockdep.
+ */
+ rwsem_release(&inode->vfs_inode.i_rwsem.dep_map, _THIS_IP_);
+#endif
+
return -EIOCBQUEUED;
out_fail:
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads
2024-11-12 16:00 [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads Mark Harmstone
@ 2024-11-13 8:21 ` Johannes Thumshirn
2024-11-13 10:24 ` Mark Harmstone
2024-11-14 15:06 ` David Sterba
1 sibling, 1 reply; 6+ messages in thread
From: Johannes Thumshirn @ 2024-11-13 8:21 UTC (permalink / raw)
To: Mark Harmstone, linux-btrfs@vger.kernel.org
On 12.11.24 17:01, Mark Harmstone wrote:
> Lockdep doesn't like the fact that btrfs_uring_read_extent() returns to
> userspace still holding the inode lock, even though we release it once
> the I/O finishes. Add calls to rwsem_release() and rwsem_acquire_read() to
> work round this.
>
> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
> Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> fs/btrfs/ioctl.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 1fdeb216bf6c..6ea01e4f940e 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4752,6 +4752,11 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int iss
> size_t page_offset;
> ssize_t ret;
>
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> + /* The inode lock has already been acquired in btrfs_uring_read_extent. */
> + rwsem_acquire_read(&inode->vfs_inode.i_rwsem.dep_map, 0, 0, _THIS_IP_);
> +#endif
> +
> if (priv->err) {
> ret = priv->err;
> goto out;
> @@ -4860,6 +4865,15 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
> * and inode and freeing the allocations.
> */
>
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> + /*
> + * We're returning to userspace with the inode lock held, and that's
> + * okay - it'll get unlocked in a kthread. Call rwsem_release to
> + * avoid confusing lockdep.
> + */
> + rwsem_release(&inode->vfs_inode.i_rwsem.dep_map, _THIS_IP_);
> +#endif
> +
> return -EIOCBQUEUED;
>
> out_fail:
Can't say anything about the correctness (as I have no clue), but we
have wrappers around rwsem_release (btrfs_lockdep_release()) and
rwsem_acquire_read (btrfs_lockdep_acquire()) that I think serve the
documentation purpose.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads
2024-11-13 8:21 ` Johannes Thumshirn
@ 2024-11-13 10:24 ` Mark Harmstone
2024-11-13 10:26 ` Johannes Thumshirn
0 siblings, 1 reply; 6+ messages in thread
From: Mark Harmstone @ 2024-11-13 10:24 UTC (permalink / raw)
To: Johannes Thumshirn, Mark Harmstone, linux-btrfs@vger.kernel.org
On 13/11/24 08:21, Johannes Thumshirn wrote:
> >
> On 12.11.24 17:01, Mark Harmstone wrote:
>> Lockdep doesn't like the fact that btrfs_uring_read_extent() returns to
>> userspace still holding the inode lock, even though we release it once
>> the I/O finishes. Add calls to rwsem_release() and rwsem_acquire_read() to
>> work round this.
>>
>> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
>> Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>> ---
>> fs/btrfs/ioctl.c | 14 ++++++++++++++
>> 1 file changed, 14 insertions(+)
>>
>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>> index 1fdeb216bf6c..6ea01e4f940e 100644
>> --- a/fs/btrfs/ioctl.c
>> +++ b/fs/btrfs/ioctl.c
>> @@ -4752,6 +4752,11 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int iss
>> size_t page_offset;
>> ssize_t ret;
>>
>> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
>> + /* The inode lock has already been acquired in btrfs_uring_read_extent. */
>> + rwsem_acquire_read(&inode->vfs_inode.i_rwsem.dep_map, 0, 0, _THIS_IP_);
>> +#endif
>> +
>> if (priv->err) {
>> ret = priv->err;
>> goto out;
>> @@ -4860,6 +4865,15 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
>> * and inode and freeing the allocations.
>> */
>>
>> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
>> + /*
>> + * We're returning to userspace with the inode lock held, and that's
>> + * okay - it'll get unlocked in a kthread. Call rwsem_release to
>> + * avoid confusing lockdep.
>> + */
>> + rwsem_release(&inode->vfs_inode.i_rwsem.dep_map, _THIS_IP_);
>> +#endif
>> +
>> return -EIOCBQUEUED;
>>
>> out_fail:
>
> Can't say anything about the correctness (as I have no clue), but we
> have wrappers around rwsem_release (btrfs_lockdep_release()) and
> rwsem_acquire_read (btrfs_lockdep_acquire()) that I think serve the
> documentation purpose.
btrfs_lockdep_acquire(a,b) calls rwsem_acquire_read on &a->b_map, so
can't be used for something located at &inode->vfs_inode.i_rwsem.dep_map.
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads
2024-11-13 10:24 ` Mark Harmstone
@ 2024-11-13 10:26 ` Johannes Thumshirn
0 siblings, 0 replies; 6+ messages in thread
From: Johannes Thumshirn @ 2024-11-13 10:26 UTC (permalink / raw)
To: Mark Harmstone, linux-btrfs@vger.kernel.org
On 13.11.24 11:24, Mark Harmstone wrote:
> On 13/11/24 08:21, Johannes Thumshirn wrote:
>>>
>> On 12.11.24 17:01, Mark Harmstone wrote:
>>> Lockdep doesn't like the fact that btrfs_uring_read_extent() returns to
>>> userspace still holding the inode lock, even though we release it once
>>> the I/O finishes. Add calls to rwsem_release() and rwsem_acquire_read() to
>>> work round this.
>>>
>>> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
>>> Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>>> ---
>>> fs/btrfs/ioctl.c | 14 ++++++++++++++
>>> 1 file changed, 14 insertions(+)
>>>
>>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>>> index 1fdeb216bf6c..6ea01e4f940e 100644
>>> --- a/fs/btrfs/ioctl.c
>>> +++ b/fs/btrfs/ioctl.c
>>> @@ -4752,6 +4752,11 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int iss
>>> size_t page_offset;
>>> ssize_t ret;
>>>
>>> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
>>> + /* The inode lock has already been acquired in btrfs_uring_read_extent. */
>>> + rwsem_acquire_read(&inode->vfs_inode.i_rwsem.dep_map, 0, 0, _THIS_IP_);
>>> +#endif
>>> +
>>> if (priv->err) {
>>> ret = priv->err;
>>> goto out;
>>> @@ -4860,6 +4865,15 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
>>> * and inode and freeing the allocations.
>>> */
>>>
>>> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
>>> + /*
>>> + * We're returning to userspace with the inode lock held, and that's
>>> + * okay - it'll get unlocked in a kthread. Call rwsem_release to
>>> + * avoid confusing lockdep.
>>> + */
>>> + rwsem_release(&inode->vfs_inode.i_rwsem.dep_map, _THIS_IP_);
>>> +#endif
>>> +
>>> return -EIOCBQUEUED;
>>>
>>> out_fail:
>>
>> Can't say anything about the correctness (as I have no clue), but we
>> have wrappers around rwsem_release (btrfs_lockdep_release()) and
>> rwsem_acquire_read (btrfs_lockdep_acquire()) that I think serve the
>> documentation purpose.
>
> btrfs_lockdep_acquire(a,b) calls rwsem_acquire_read on &a->b_map, so
> can't be used for something located at &inode->vfs_inode.i_rwsem.dep_map.
Ah my bad, sorry.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads
2024-11-12 16:00 [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads Mark Harmstone
2024-11-13 8:21 ` Johannes Thumshirn
@ 2024-11-14 15:06 ` David Sterba
2024-11-15 15:43 ` Mark Harmstone
1 sibling, 1 reply; 6+ messages in thread
From: David Sterba @ 2024-11-14 15:06 UTC (permalink / raw)
To: Mark Harmstone; +Cc: linux-btrfs, Johannes Thumshirn
On Tue, Nov 12, 2024 at 04:00:49PM +0000, Mark Harmstone wrote:
> Lockdep doesn't like the fact that btrfs_uring_read_extent() returns to
> userspace still holding the inode lock, even though we release it once
> the I/O finishes. Add calls to rwsem_release() and rwsem_acquire_read() to
> work round this.
>
> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
> Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> fs/btrfs/ioctl.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 1fdeb216bf6c..6ea01e4f940e 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4752,6 +4752,11 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int iss
> size_t page_offset;
> ssize_t ret;
>
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> + /* The inode lock has already been acquired in btrfs_uring_read_extent. */
> + rwsem_acquire_read(&inode->vfs_inode.i_rwsem.dep_map, 0, 0, _THIS_IP_);
> +#endif
Please put that to a wrapper, we want to avoid #ifdefs in the middle of
functions (there are exceptions), especially when the macro is for lock
debugging.
The wrapper name can follow naming and syntax of the other
btrfs_lockde_* wrappers, so like btrfs_lockdep_inode_acquire(owner,
lock). There is only one rwsem in inode, but for clarity and consistency
I think it makes sense.
btrfs_lockdep_inode_acquire(inode, i_rwsem);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads
2024-11-14 15:06 ` David Sterba
@ 2024-11-15 15:43 ` Mark Harmstone
0 siblings, 0 replies; 6+ messages in thread
From: Mark Harmstone @ 2024-11-15 15:43 UTC (permalink / raw)
To: dsterba@suse.cz; +Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn
On 14/11/24 15:06, David Sterba wrote:
> >
> On Tue, Nov 12, 2024 at 04:00:49PM +0000, Mark Harmstone wrote:
>> Lockdep doesn't like the fact that btrfs_uring_read_extent() returns to
>> userspace still holding the inode lock, even though we release it once
>> the I/O finishes. Add calls to rwsem_release() and rwsem_acquire_read() to
>> work round this.
>>
>> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
>> Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>> ---
>> fs/btrfs/ioctl.c | 14 ++++++++++++++
>> 1 file changed, 14 insertions(+)
>>
>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>> index 1fdeb216bf6c..6ea01e4f940e 100644
>> --- a/fs/btrfs/ioctl.c
>> +++ b/fs/btrfs/ioctl.c
>> @@ -4752,6 +4752,11 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int iss
>> size_t page_offset;
>> ssize_t ret;
>>
>> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
>> + /* The inode lock has already been acquired in btrfs_uring_read_extent. */
>> + rwsem_acquire_read(&inode->vfs_inode.i_rwsem.dep_map, 0, 0, _THIS_IP_);
>> +#endif
>
> Please put that to a wrapper, we want to avoid #ifdefs in the middle of
> functions (there are exceptions), especially when the macro is for lock
> debugging.
>
> The wrapper name can follow naming and syntax of the other
> btrfs_lockde_* wrappers, so like btrfs_lockdep_inode_acquire(owner,
> lock). There is only one rwsem in inode, but for clarity and consistency
> I think it makes sense.
>
> btrfs_lockdep_inode_acquire(inode, i_rwsem);
Thanks David. The CONFIG_DEBUG_LOCK_ALLOC #ifdefs turned out not to be
necessary, lockdep handles this, but I'll create the wrappers to match
everything else.
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-11-15 15:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-12 16:00 [PATCH] btrfs: fix lockdep warnings on io_uring encoded reads Mark Harmstone
2024-11-13 8:21 ` Johannes Thumshirn
2024-11-13 10:24 ` Mark Harmstone
2024-11-13 10:26 ` Johannes Thumshirn
2024-11-14 15:06 ` David Sterba
2024-11-15 15:43 ` Mark Harmstone
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.