From: Matthew Wilcox <willy@infradead.org>
To: "Dāvis Mosāns" <davispuh@gmail.com>
Cc: FMDF <fmdefrancesco@gmail.com>,
linux-fsdevel@vger.kernel.org,
BTRFS <linux-btrfs@vger.kernel.org>,
kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Re: How to debug stuck read?
Date: Sun, 6 Feb 2022 23:49:22 +0000 [thread overview]
Message-ID: <YgBegj4a/0/PkRlc@casper.infradead.org> (raw)
In-Reply-To: <CAOE4rSzJtDwDpb6PDN-E1i=b5p6jePu7wnKKgwr8dnwextaxUw@mail.gmail.com>
On Mon, Feb 07, 2022 at 01:21:53AM +0200, Dāvis Mosāns wrote:
> svētd., 2022. g. 6. febr., plkst. 13:01 — lietotājs FMDF
> (<fmdefrancesco@gmail.com>) rakstīja:
> [...]
> > There is no special recipe for debugging "this properly" :)
> >
> > You wrote that "by pure luck" you found a memcpy() that wrote beyond the
> > limit of allocated memory. I suppose that you found that faulty memcpy()
> > somewhere in one of the function listed in the stack trace.
> >
> > That's the right approach! You read the calls chain and find out where something
> > looks wrong and then fix it. This is why stack traces are so helpful.
> >
> > It was not "pure luck". I think that you did what developers usually do after
> > decoding a stack trace. If not, how did you find that faulty memcpy() buried
> > somewhere in 40 millions lines of code?
> >
> > it seems that you've found the right way to figure out the problems in code
> > that (probably) you had not ever worked on or read before you hit that bug.
> >
>
> I think there should be a way to see which locks (and by who/where)
> have been taken for a long time.
Well ... we do, but the problem is that the page lock is a single bit.
We just don't have the space in struct page for a pointer to a stack
trace. So the page lock isn't like a spinlock or a mutex where we can
use the LOCKDEP infrastructure to tell us this kind of thing.
Also, in this case, we know exactly where the lock was taken and by whom
-- and it would be no more information than you had from the stack trace.
Something I slightly regret is that you used to get a "task blocked for
more than 120 seconds" message from check_hung_task(). But I made
that not show up in this path because I made the sleep killable and
that's only called for UNINTERRUPTIBLE tasks.
Maybe that should be changed. Perhaps we should emit those messages
for TASK_KILLABLE too.
> Yep, fully sure and tested :P I'm able to reproduce stuck process with
> 100% reliability. After applying my patch it returns EIO as expected
> and doesn't get stuck.
> If you look at copy_compressed_segment (in fs/btrfs/lzo.c) you'll see
> kaddr = kmap(cur_page);
> memcpy(dest + *cur_in - orig_in,
> kaddr + offset_in_page(*cur_in), copy_len);
> kunmap(cur_page);
>
> My guess is that kmap(cur_page) locks that page, then memcpy crashes
> so that page never gets unmapped causing anyone that tries to map it
> to wait forever. Hence this can be reproduced only once per boot. If I
> knew how to find kernel thread that is running this we could check
> it's stack and it should be stuck here on kmap.
kmap() doesn't lock the page; it's already locked at this point.
But if the memcpy() does crash then you're right, the page will never
be unlocked because it was this thread's job to unlock it when the page
was uptodate. The thread will be dead, so there's no way to find it.
Do we not dump the thread's stack on its death?
next prev parent reply other threads:[~2022-02-06 23:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 17:15 How to debug stuck read? Dāvis Mosāns
2022-02-02 19:13 ` Matthew Wilcox
2022-02-02 21:50 ` Dāvis Mosāns
2022-02-06 11:01 ` FMDF
2022-02-06 12:48 ` Matthew Wilcox
2022-02-06 21:22 ` FMDF
2022-02-06 23:21 ` Dāvis Mosāns
2022-02-06 23:49 ` Matthew Wilcox [this message]
2022-02-07 0:07 ` Dāvis Mosāns
2022-02-07 1:06 ` Matthew Wilcox
2022-02-07 1:22 ` Dāvis Mosāns
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=YgBegj4a/0/PkRlc@casper.infradead.org \
--to=willy@infradead.org \
--cc=davispuh@gmail.com \
--cc=fmdefrancesco@gmail.com \
--cc=kernelnewbies@kernelnewbies.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
/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).