From: Peter Xu <peterx@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Andrea Arcangeli <aarcange@redhat.com>,
Nadav Amit <nadav.amit@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v2] mm/mprotect: Fix soft-dirty check in can_change_pte_writable()
Date: Thu, 21 Jul 2022 12:57:15 -0400 [thread overview]
Message-ID: <YtmFa+BdYkY3SSVP@xz-m1.local> (raw)
In-Reply-To: <f0d193c2-9b23-6f3a-9208-2a615febe0c2@redhat.com>
On Thu, Jul 21, 2022 at 09:28:47AM +0200, David Hildenbrand wrote:
> Modifying your test to map page from a file MAP_SHARED gives me under
> 5.18.11-100.fc35.x86_64:
>
>
> 53,54d52
> < FILE *file = fopen("tmpfile", "w+");
> < int file_fd;
> 56d53
> < assert(file);
> 59,61d55
> <
> < file_fd = fileno(file);
> < ftruncate(file_fd, psize);
> 63c57
> < MAP_SHARED, file_fd, 0);
> ---
> > MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
>
>
> t480s: ~ $ sudo ./tmp
> ERROR: Wrote page again, soft-dirty=0 (expect: 1
>
>
>
> IMHO, while the check in vma_wants_writenotify() is correct and makes
> sure that the pages are kept R/O by the generic machinery. We get
> vma_wants_writenotify(), so we activate MM_CP_TRY_CHANGE_WRITABLE. The
> wrong logic in can_change_pte_writable(), however, maps the page
> writable again without caring about softdirty.
>
> At least that would be my explanation for the failure. But maybe I
> messes up something else :)
Correct, I missed that part. I verified that the same test also fails for
me easily on a xfs file test of an old kernel.
Let me touch up the commit message for that. Though I think I'll still
keep the Fixes since the patch won't apply to before the commit, but I'll
mention that's only for tracking purpose.
[...]
> Can we turn that into a vm selftest in
> tools/testing/selftests/vm/soft-dirty.c, and also extend it by
> MAP_SHARED froma file as above?
Sure. I'll post a v3 with that.
[...]
> > @@ -48,8 +48,11 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma,
> > if (pte_protnone(pte) || !pte_dirty(pte))
> > return false;
> >
> > - /* Do we need write faults for softdirty tracking? */
> > - if ((vma->vm_flags & VM_SOFTDIRTY) && !pte_soft_dirty(pte))
> > + /*
> > + * Do we need write faults for softdirty tracking? Note,
> > + * soft-dirty is enabled when !VM_SOFTDIRTY.
> > + */
> > + if (!(vma->vm_flags & VM_SOFTDIRTY) && !pte_soft_dirty(pte))
> > return false;
>
> I wonder if we now want, just as in vma_wants_writenotify(), an early
> check for IS_ENABLED(CONFIG_MEM_SOFT_DIRTY), to optimize this out
> completely.
Hmm, it may not even be an optimization issue, since when
!CONFIG_MEM_SOFT_DIRTY we have VM_SOFTDIRTY defined as 0x0.
It means !(vma->vm_flags & VM_SOFTDIRTY) will be constantly true even if
soft dirty not compiled in.
I'll add that check too. Thanks,
--
Peter Xu
prev parent reply other threads:[~2022-07-21 16:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 22:03 Peter Xu
2022-07-21 7:28 ` David Hildenbrand
2022-07-21 16:57 ` Peter Xu [this message]
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=YtmFa+BdYkY3SSVP@xz-m1.local \
--to=peterx@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nadav.amit@gmail.com \
/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