From: Matthew Wilcox <willy@infradead.org>
To: Dave Hansen <dave.hansen@intel.com>
Cc: Yin Fengwei <fengwei.yin@intel.com>,
syzbot <syzbot+55cc72f8cc3a549119df@syzkaller.appspotmail.com>,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [mm?] BUG: Bad page map (7)
Date: Mon, 11 Sep 2023 17:44:02 +0100 [thread overview]
Message-ID: <ZP9D0q5MSVFobNbZ@casper.infradead.org> (raw)
In-Reply-To: <f3379aeb-f394-8c99-5143-f93e82400320@intel.com>
On Mon, Sep 11, 2023 at 08:34:57AM -0700, Dave Hansen wrote:
> On 9/11/23 06:26, Matthew Wilcox wrote:
> > @@ -231,7 +235,10 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
> > if (--nr == 0)
> > break;
> > ptep++;
> > - pte = __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT));
> > + if (__pte_needs_invert(pte_val(pte)))
> > + pte = __pte(pte_val(pte) - (1UL << PFN_PTE_SHIFT));
> > + else
> > + pte = __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT));
> > }
> > arch_leave_lazy_mmu_mode();
> > }
>
> This is much better than a whole x86 fork of set_ptes(). But it's still
> a bit wonky because it exposes the PTE inversion logic to generic code.
I saw that as an advantage ... let people know that it exists as a
concept.
> static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
> pte_t *ptep, pte_t pte, unsigned int nr)
> {
> pgprot_t prot = pte_pgprot(x);
> unsigned long pfn = pte_pfn(pte);
>
> page_table_check_ptes_set(mm, ptep, pte, nr);
>
> arch_enter_lazy_mmu_mode();
> for (;;) {
> set_pte(ptep, pte);
> if (--nr == 0)
> break;
> ptep++;
> pfn++;
> pte = pfn_pte(pfn, pgprot);
> }
> arch_leave_lazy_mmu_mode();
> }
>
> Obviously completely untested. :)
After fixing your two typos, this assembles to 176 bytes more code than
my version. Not sure that's great.
How about this? Keeps the inverted knowledge entirely in arch/x86.
Compiles to exactly the same code as the version I sent earlier.
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index d6ad98ca1288..c9781b8b14af 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -955,6 +955,14 @@ static inline int pte_same(pte_t a, pte_t b)
return a.pte == b.pte;
}
+static inline pte_t pte_next(pte_t pte)
+{
+ if (__pte_needs_invert(pte_val(pte)))
+ return __pte(pte_val(pte) - (1UL << PFN_PTE_SHIFT));
+ return __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT));
+}
+#define pte_next pte_next
+
static inline int pte_present(pte_t a)
{
return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE);
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 1fba072b3dac..7a932ed59c27 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -205,6 +205,10 @@ static inline int pmd_young(pmd_t pmd)
#define arch_flush_lazy_mmu_mode() do {} while (0)
#endif
+#ifndef pte_next
+#define pte_next(pte) ((pte) + (1UL << PFN_PTE_SHIFT))
+#endif
+
#ifndef set_ptes
/**
* set_ptes - Map consecutive pages to a contiguous range of addresses.
@@ -231,7 +235,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
if (--nr == 0)
break;
ptep++;
- pte = __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT));
+ pte = pte_next(pte);
}
arch_leave_lazy_mmu_mode();
}
next prev parent reply other threads:[~2023-09-11 16:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-09 17:12 syzbot
2023-09-10 3:02 ` Matthew Wilcox
2023-09-10 3:29 ` syzbot
2023-09-10 3:40 ` Yin, Fengwei
2023-09-11 7:24 ` Yin Fengwei
2023-09-11 7:32 ` Yin Fengwei
2023-09-11 7:12 ` Yin Fengwei
2023-09-11 7:48 ` syzbot
2023-09-11 13:26 ` Matthew Wilcox
2023-09-11 14:00 ` syzbot
2023-09-11 15:34 ` Dave Hansen
2023-09-11 16:44 ` Matthew Wilcox [this message]
2023-09-11 16:55 ` Dave Hansen
2023-09-11 19:12 ` Matthew Wilcox
2023-09-11 20:22 ` Dave Hansen
2023-09-12 4:59 ` Matthew Wilcox
2023-09-12 16:07 ` Dave Hansen
2023-09-12 18:01 ` Dave Hansen
2023-09-14 7:33 ` Yin Fengwei
2023-09-14 8:37 ` Yin Fengwei
2023-09-19 1:11 ` Yin Fengwei
2023-09-19 16:11 ` Dave Hansen
2023-09-20 1:29 ` Yin Fengwei
2023-09-20 1:47 ` Matthew Wilcox
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=ZP9D0q5MSVFobNbZ@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=fengwei.yin@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=syzbot+55cc72f8cc3a549119df@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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