linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	syzbot <syzbot+7ca4b2719dc742b8d0a4@syzkaller.appspotmail.com>,
	Muhammad Usama Anjum <usama.anjum@collabora.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, syzkaller-bugs@googlegroups.com,
	wangkefeng.wang@huawei.com
Subject: Re: [syzbot] [mm?] WARNING in unmap_page_range (2)
Date: Thu, 16 Nov 2023 19:13:44 +0100	[thread overview]
Message-ID: <6308590a-d958-4ecc-a478-ba088cf7984d@redhat.com> (raw)
In-Reply-To: <ZVZYvleasZddv-TD@x1n>

> It should be fine, as:
> 
> static void make_uffd_wp_pte(struct vm_area_struct *vma,
> 			     unsigned long addr, pte_t *pte)
> {
> 	pte_t ptent = ptep_get(pte);
> 
> #ifndef CONFIG_USERFAULTFD_
> 
> 	if (pte_present(ptent)) {
> 		pte_t old_pte;
> 
> 		old_pte = ptep_modify_prot_start(vma, addr, pte);
> 		ptent = pte_mkuffd_wp(ptent);
> 		ptep_modify_prot_commit(vma, addr, pte, old_pte, ptent);
> 	} else if (is_swap_pte(ptent)) {
> 		ptent = pte_swp_mkuffd_wp(ptent);
> 		set_pte_at(vma->vm_mm, addr, pte, ptent);
> 	} else {                                      <----------------- this must be pte_none() already
> 		set_pte_at(vma->vm_mm, addr, pte,
> 			   make_pte_marker(PTE_MARKER_UFFD_WP));
> 	}
> }

Indeed! Is pte_swp_mkuffd_wp() reasonable for pte markers? I rememebr 
that we don't support multiple markers yet, so it might be good enough.

> 
>>
>> 2) We get the error on arm64, which does *not* support uffd-wp. Do we
>>     maybe end up calling make_uffd_wp_pte() and place a pte marker, even
>>     though we don't have CONFIG_PTE_MARKER_UFFD_WP?
>>
>>
>> static inline bool pte_marker_entry_uffd_wp(swp_entry_t entry)
>> {
>> #ifdef CONFIG_PTE_MARKER_UFFD_WP
>> 	return is_pte_marker_entry(entry) &&
>> 	    (pte_marker_get(entry) & PTE_MARKER_UFFD_WP);
>> #else
>> 	return false;
>> #endif
>> }
>>
>> Will always return false without CONFIG_PTE_MARKER_UFFD_WP.
>>
>> But make_uffd_wp_pte() might just happily place an entry. Hm.
>>
>>
>> The following might fix the problem:
>>

[...]

> 
> I'd like to double check with Muhammad (as I didn't actually follow his
> work in the latest versions.. quite a lot changed), but I _think_
> fundamentally we missed something important in the fast path, and I think
> it applies even to archs that support uffd..
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index e91085d79926..3b81baabd22a 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -2171,7 +2171,8 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start,
>                  return 0;
>          }
> 
> -       if (!p->vec_out) {
> +       if (!p->vec_out &&
> +           (p->arg.flags & PM_SCAN_WP_MATCHING))

Ouch, yes. So that's the global fence I was wondering where to find it.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2023-11-16 18:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <000000000000b0e576060a30ee3b@google.com>
2023-11-15 22:00 ` Andrew Morton
2023-11-16  9:19   ` David Hildenbrand
2023-11-16 18:00     ` Peter Xu
2023-11-16 18:13       ` David Hildenbrand [this message]
2023-11-16 20:04         ` 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=6308590a-d958-4ecc-a478-ba088cf7984d@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=syzbot+7ca4b2719dc742b8d0a4@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=usama.anjum@collabora.com \
    --cc=wangkefeng.wang@huawei.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