From: hev <r@hev.cc>
To: Peter Xu <peterx@redhat.com>
Cc: Anatoly Pugachev <matorola@gmail.com>,
Thorsten Leemhuis <regressions@leemhuis.info>,
Sparc kernel list <sparclinux@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>
Subject: Re: Test case for "mm/thp: carry over dirty bit when thp splits on pmd"
Date: Sat, 19 Nov 2022 22:06:23 +0800 [thread overview]
Message-ID: <CAHirt9i8iLCP3_ppEL5kO2XLVAg0sno0GdzdKyzk7DSMTJF0tA@mail.gmail.com> (raw)
In-Reply-To: <Y3Z9Zf0jARMOkFBq@x1n>
Hi, Peter,
On Fri, Nov 18, 2022 at 2:29 AM Peter Xu <peterx@redhat.com> wrote:
>
> On Thu, Nov 17, 2022 at 10:29:57AM +0800, hev wrote:
> > Hi Peter,
>
> Hi, Hev,
>
> >
> > On Thu, Nov 17, 2022 at 12:25 AM Peter Xu <peterx@redhat.com> wrote:
> > >
> > > On Wed, Nov 16, 2022 at 01:45:15PM +0300, Anatoly Pugachev wrote:
> > > > On Wed, Nov 16, 2022 at 11:49 AM hev <r@hev.cc> wrote:
> > > > >
> > > > > Hello Peter,
> > >
> > > Hi, Hev,
> > >
> > > Thanks for letting me know.
> > >
> > > > >
> > > > > I see a random crash issue on the LoongArch system, that is caused by
> > > > > commit 0ccf7f1 ("mm/thp: carry over dirty bit when thp splits on
> > > > > pmd").
> > > > >
> > > > > Now, the thing is already resolved. The root cause is arch's mkdirty
> > > > > is set hardware writable bit in unconditional. That breaks
> > > > > write-protect and then breaks COW.
> > >
> > > Could you help explain how that happened?
> > >
> > > I'm taking example of loongarch here:
> > >
> > > static inline pte_t pte_mkdirty(pte_t pte)
> > > {
> > > pte_val(pte) |= (_PAGE_DIRTY | _PAGE_MODIFIED);
> > > return pte;
> > > }
> > >
> > > #define _PAGE_MODIFIED (_ULCAST_(1) << _PAGE_MODIFIED_SHIFT)
> > > #define _PAGE_MODIFIED_SHIFT 9
> >
> > _PAGE_MODIFIED is a software dirty bit
> >
> > > #define _PAGE_DIRTY (_ULCAST_(1) << _PAGE_DIRTY_SHIFT)
> > > #define _PAGE_DIRTY_SHIFT 1
> >
> > _PAGE_DIRTY is a hardware writable bit (bad naming), meaning that mmu
> > allows write memory without any exception raised.
>
> (I just missed this email before I reply to the other one, I should have
> read this one first..)
>
> I see. This surprises me a bit, as I can't quickly tell how it'll always
> work with the generic mm code.
>
> Say, is there a quick answer on why _PAGE_DIRTY is set here rather than
> pte_mkwrite()? Because AFAIU that's where the mm wants to grant write
> permission to a page table entry as the API, no?
>
> >
> > >
> > > I don't see when write bit is set, which is bit 8 instead:
> > >
> > > #define _PAGE_WRITE (_ULCAST_(1) << _PAGE_WRITE_SHIFT)
> > > #define _PAGE_WRITE_SHIFT 8
> >
> > _PAGE_WRITE is a software writable bit (not hardware).
> >
> > As David said, In __split_huge_pmd_locked, the VMA does not include VM_WRITE,
> >
> > entry = maybe_mkwrite(entry, vma);
> >
> > so the pte does not include software writable bit (_PAGE_WRITE).
>
> Are you sure? In your test case you mapped with RW, IIUC it means even
> after the fork() VM_WRITE is set on both sides?
Sorry, I was wrong.
In this case, both VMAs are writable, the pte's writable bit is
cleared by pte_wrprotect. So if pte_mkdirty sets hardware writable bit
unconditionally, then there will be no way to catch writes to
implement COW.
I will try to explain how it works about pte write, dirty and
write-protect on LoongArch in the LoongArch mailing-list.
Regards,
Ray
>
> But I agree the write bit is not set, not because !VM_WRITE, but because we
> take care of that explicitly to make sure pte has the same write bit as pmd:
>
> (pmd used to be wr-protected due to fork())
> write = pmd_write(old_pmd);
> ...
>
> (then when split pte shouldn't have write bit too)
> if (!write)
> entry = pte_wrprotect(entry);
>
> >
> > and the dirty is true,
> >
> > if (dirty)
> > entry = pte_mkdirty(entry);
> >
> > so the incorrect arch's pte_mkdirty set hardware writable
> > bit(_PAGE_DIRTY) in unconditional for read-only pages.
>
> True, that does also apply to sparc64 pte_mkdirty() with _PAGE_W_4[UV]. I
> should have noticed earlier that its comment told me that's a write bit
> already..
>
> #define _PAGE_W_4U _AC(0x0000000000000002,UL) /* Writable */
>
> Thanks,
>
> --
> Peter Xu
>
next prev parent reply other threads:[~2022-11-19 14:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAHirt9gr7oL87co3y1hCs3Ux4utzFP5oj6GFOFMZuJR2Vv8+rA@mail.gmail.com>
2022-11-16 10:45 ` Anatoly Pugachev
2022-11-16 11:28 ` David Hildenbrand
2022-11-16 16:25 ` Peter Xu
2022-11-17 2:29 ` hev
2022-11-17 18:28 ` Peter Xu
2022-11-19 14:06 ` hev [this message]
2022-11-21 19:57 ` David Hildenbrand
2022-11-25 11:15 ` hev
2022-11-25 11:17 ` David Hildenbrand
2022-11-25 11:35 ` hev
2022-11-21 18:55 ` Peter Xu
2022-11-25 11:38 ` hev
2022-11-25 18:42 ` Peter Xu
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=CAHirt9i8iLCP3_ppEL5kO2XLVAg0sno0GdzdKyzk7DSMTJF0tA@mail.gmail.com \
--to=r@hev.cc \
--cc=linux-mm@kvack.org \
--cc=matorola@gmail.com \
--cc=peterx@redhat.com \
--cc=regressions@leemhuis.info \
--cc=sparclinux@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