* [PATCH 0/2] blktrace: fix one kind of lockdep warning
@ 2024-11-28 12:50 Ming Lei
2024-11-28 12:50 ` [PATCH 1/2] blktrace: don't centralize grabbing q->debugfs_mutex in blk_trace_ioctl Ming Lei
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Ming Lei @ 2024-11-28 12:50 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Ming Lei
Hello,
This patchset kills one big kind of lockdep warning by cutting
dependency between q->debugfs_lock and mm->mmap_lock around copy_to_user()
and copy_from_user(().
Ming Lei (2):
blktrace: don't centralize grabbing q->debugfs_mutex in
blk_trace_ioctl
blktrace: move copy_[to|from]_user() out of ->debugfs_lock
kernel/trace/blktrace.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)
--
2.47.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] blktrace: don't centralize grabbing q->debugfs_mutex in blk_trace_ioctl
2024-11-28 12:50 [PATCH 0/2] blktrace: fix one kind of lockdep warning Ming Lei
@ 2024-11-28 12:50 ` Ming Lei
2024-11-28 12:50 ` [PATCH 2/2] blktrace: move copy_[to|from]_user() out of ->debugfs_lock Ming Lei
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Ming Lei @ 2024-11-28 12:50 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Ming Lei
Call each handler directly and the handler do grab q->debugfs_mutex,
prepare for killing dependency between ->debug_mutex and ->mmap_lock.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
kernel/trace/blktrace.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8fd292d34d89..f01aae3a2f7b 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -732,34 +732,32 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg)
int ret, start = 0;
char b[BDEVNAME_SIZE];
- mutex_lock(&q->debugfs_mutex);
-
switch (cmd) {
case BLKTRACESETUP:
snprintf(b, sizeof(b), "%pg", bdev);
- ret = __blk_trace_setup(q, b, bdev->bd_dev, bdev, arg);
+ ret = blk_trace_setup(q, b, bdev->bd_dev, bdev, arg);
break;
#if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
case BLKTRACESETUP32:
snprintf(b, sizeof(b), "%pg", bdev);
+ mutex_lock(&q->debugfs_mutex);
ret = compat_blk_trace_setup(q, b, bdev->bd_dev, bdev, arg);
+ mutex_unlock(&q->debugfs_mutex);
break;
#endif
case BLKTRACESTART:
start = 1;
fallthrough;
case BLKTRACESTOP:
- ret = __blk_trace_startstop(q, start);
+ ret = blk_trace_startstop(q, start);
break;
case BLKTRACETEARDOWN:
- ret = __blk_trace_remove(q);
+ ret = blk_trace_remove(q);
break;
default:
ret = -ENOTTY;
break;
}
-
- mutex_unlock(&q->debugfs_mutex);
return ret;
}
--
2.47.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] blktrace: move copy_[to|from]_user() out of ->debugfs_lock
2024-11-28 12:50 [PATCH 0/2] blktrace: fix one kind of lockdep warning Ming Lei
2024-11-28 12:50 ` [PATCH 1/2] blktrace: don't centralize grabbing q->debugfs_mutex in blk_trace_ioctl Ming Lei
@ 2024-11-28 12:50 ` Ming Lei
2024-12-04 20:40 ` Kees Bakker
2024-11-29 16:05 ` [PATCH 0/2] blktrace: fix one kind of lockdep warning Jens Axboe
2024-11-29 16:05 ` Jens Axboe
3 siblings, 1 reply; 6+ messages in thread
From: Ming Lei @ 2024-11-28 12:50 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Ming Lei, syzbot+91585b36b538053343e4
Move copy_[to|from]_user() out of ->debugfs_lock and cut the dependency
between mm->mmap_lock and q->debugfs_lock, then we avoids lots of
lockdep false positive warning. Obviously ->debug_lock isn't needed
for copy_[to|from]_user().
The only behavior change is to call blk_trace_remove() in case of setup
failure handling by re-grabbing ->debugfs_lock, and this way is just
fine since we do cover concurrent setup() & remove().
Reported-by: syzbot+91585b36b538053343e4@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/linux-block/67450fd4.050a0220.1286eb.0007.GAE@google.com/
Closes: https://lore.kernel.org/linux-block/6742e584.050a0220.1cc393.0038.GAE@google.com/
Closes: https://lore.kernel.org/linux-block/6742a600.050a0220.1cc393.002e.GAE@google.com/
Closes: https://lore.kernel.org/linux-block/67420102.050a0220.1cc393.0019.GAE@google.com/
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
kernel/trace/blktrace.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index f01aae3a2f7b..18c81e6aa496 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -617,8 +617,9 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
return ret;
}
-static int __blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
- struct block_device *bdev, char __user *arg)
+int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
+ struct block_device *bdev,
+ char __user *arg)
{
struct blk_user_trace_setup buts;
int ret;
@@ -627,26 +628,17 @@ static int __blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (ret)
return -EFAULT;
+ mutex_lock(&q->debugfs_mutex);
ret = do_blk_trace_setup(q, name, dev, bdev, &buts);
+ mutex_unlock(&q->debugfs_mutex);
if (ret)
return ret;
if (copy_to_user(arg, &buts, sizeof(buts))) {
- __blk_trace_remove(q);
+ blk_trace_remove(q);
return -EFAULT;
}
return 0;
-}
-
-int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
- struct block_device *bdev,
- char __user *arg)
-{
- int ret;
-
- mutex_lock(&q->debugfs_mutex);
- ret = __blk_trace_setup(q, name, dev, bdev, arg);
- mutex_unlock(&q->debugfs_mutex);
return ret;
}
@@ -673,12 +665,14 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
.pid = cbuts.pid,
};
+ mutex_lock(&q->debugfs_mutex);
ret = do_blk_trace_setup(q, name, dev, bdev, &buts);
+ mutex_unlock(&q->debugfs_mutex);
if (ret)
return ret;
if (copy_to_user(arg, &buts.name, ARRAY_SIZE(buts.name))) {
- __blk_trace_remove(q);
+ blk_trace_remove(q);
return -EFAULT;
}
@@ -740,9 +734,7 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg)
#if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
case BLKTRACESETUP32:
snprintf(b, sizeof(b), "%pg", bdev);
- mutex_lock(&q->debugfs_mutex);
ret = compat_blk_trace_setup(q, b, bdev->bd_dev, bdev, arg);
- mutex_unlock(&q->debugfs_mutex);
break;
#endif
case BLKTRACESTART:
--
2.47.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] blktrace: fix one kind of lockdep warning
2024-11-28 12:50 [PATCH 0/2] blktrace: fix one kind of lockdep warning Ming Lei
2024-11-28 12:50 ` [PATCH 1/2] blktrace: don't centralize grabbing q->debugfs_mutex in blk_trace_ioctl Ming Lei
2024-11-28 12:50 ` [PATCH 2/2] blktrace: move copy_[to|from]_user() out of ->debugfs_lock Ming Lei
@ 2024-11-29 16:05 ` Jens Axboe
2024-11-29 16:05 ` Jens Axboe
3 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2024-11-29 16:05 UTC (permalink / raw)
To: Ming Lei, linux-block
On 11/28/24 5:50 AM, Ming Lei wrote:
> Hello,
>
> This patchset kills one big kind of lockdep warning by cutting
> dependency between q->debugfs_lock and mm->mmap_lock around copy_to_user()
> and copy_from_user(().
This is almost identical to one I did a month or two ago, but didn't
get to finish. Thanks for getting this done!
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] blktrace: fix one kind of lockdep warning
2024-11-28 12:50 [PATCH 0/2] blktrace: fix one kind of lockdep warning Ming Lei
` (2 preceding siblings ...)
2024-11-29 16:05 ` [PATCH 0/2] blktrace: fix one kind of lockdep warning Jens Axboe
@ 2024-11-29 16:05 ` Jens Axboe
3 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2024-11-29 16:05 UTC (permalink / raw)
To: linux-block, Ming Lei
On Thu, 28 Nov 2024 20:50:25 +0800, Ming Lei wrote:
> This patchset kills one big kind of lockdep warning by cutting
> dependency between q->debugfs_lock and mm->mmap_lock around copy_to_user()
> and copy_from_user(().
>
>
> Ming Lei (2):
> blktrace: don't centralize grabbing q->debugfs_mutex in
> blk_trace_ioctl
> blktrace: move copy_[to|from]_user() out of ->debugfs_lock
>
> [...]
Applied, thanks!
[1/2] blktrace: don't centralize grabbing q->debugfs_mutex in blk_trace_ioctl
commit: 36a76c9c0f6dc999834ad34d64ff85be0b2923f9
[2/2] blktrace: move copy_[to|from]_user() out of ->debugfs_lock
commit: 98c00f3a7804ebdaacd80a269910f80179aa4a51
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] blktrace: move copy_[to|from]_user() out of ->debugfs_lock
2024-11-28 12:50 ` [PATCH 2/2] blktrace: move copy_[to|from]_user() out of ->debugfs_lock Ming Lei
@ 2024-12-04 20:40 ` Kees Bakker
0 siblings, 0 replies; 6+ messages in thread
From: Kees Bakker @ 2024-12-04 20:40 UTC (permalink / raw)
To: Ming Lei, Jens Axboe, linux-block; +Cc: syzbot+91585b36b538053343e4
Op 28-11-2024 om 13:50 schreef Ming Lei:
> Move copy_[to|from]_user() out of ->debugfs_lock and cut the dependency
> between mm->mmap_lock and q->debugfs_lock, then we avoids lots of
> lockdep false positive warning. Obviously ->debug_lock isn't needed
> for copy_[to|from]_user().
>
> The only behavior change is to call blk_trace_remove() in case of setup
> failure handling by re-grabbing ->debugfs_lock, and this way is just
> fine since we do cover concurrent setup() & remove().
>
> Reported-by: syzbot+91585b36b538053343e4@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/linux-block/67450fd4.050a0220.1286eb.0007.GAE@google.com/
> Closes: https://lore.kernel.org/linux-block/6742e584.050a0220.1cc393.0038.GAE@google.com/
> Closes: https://lore.kernel.org/linux-block/6742a600.050a0220.1cc393.002e.GAE@google.com/
> Closes: https://lore.kernel.org/linux-block/67420102.050a0220.1cc393.0019.GAE@google.com/
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> kernel/trace/blktrace.c | 26 +++++++++-----------------
> 1 file changed, 9 insertions(+), 17 deletions(-)
>
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index f01aae3a2f7b..18c81e6aa496 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -617,8 +617,9 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
> return ret;
> }
>
> -static int __blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
> - struct block_device *bdev, char __user *arg)
> +int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
> + struct block_device *bdev,
> + char __user *arg)
> {
> struct blk_user_trace_setup buts;
> int ret;
> @@ -627,26 +628,17 @@ static int __blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
> if (ret)
> return -EFAULT;
>
> + mutex_lock(&q->debugfs_mutex);
> ret = do_blk_trace_setup(q, name, dev, bdev, &buts);
> + mutex_unlock(&q->debugfs_mutex);
> if (ret)
> return ret;
>
> if (copy_to_user(arg, &buts, sizeof(buts))) {
> - __blk_trace_remove(q);
> + blk_trace_remove(q);
> return -EFAULT;
> }
> return 0;
> -}
> -
> -int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
> - struct block_device *bdev,
> - char __user *arg)
> -{
> - int ret;
> -
> - mutex_lock(&q->debugfs_mutex);
> - ret = __blk_trace_setup(q, name, dev, bdev, arg);
> - mutex_unlock(&q->debugfs_mutex);
>
> return ret;
You forgot to delete "return ret;" from function blk_trace_setup()
> }
> [...]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-12-04 20:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-28 12:50 [PATCH 0/2] blktrace: fix one kind of lockdep warning Ming Lei
2024-11-28 12:50 ` [PATCH 1/2] blktrace: don't centralize grabbing q->debugfs_mutex in blk_trace_ioctl Ming Lei
2024-11-28 12:50 ` [PATCH 2/2] blktrace: move copy_[to|from]_user() out of ->debugfs_lock Ming Lei
2024-12-04 20:40 ` Kees Bakker
2024-11-29 16:05 ` [PATCH 0/2] blktrace: fix one kind of lockdep warning Jens Axboe
2024-11-29 16:05 ` Jens Axboe
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).