From: Ingo Molnar <mingo@kernel.org>
To: David Hildenbrand <david@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org,
Wupeng Ma <mawupeng1@huawei.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v1] x86/mm/pat: fix VM_PAT handling in COW mappings
Date: Mon, 1 Apr 2024 11:45:07 +0200 [thread overview]
Message-ID: <ZgqCI8ClUKM4B5xG@gmail.com> (raw)
In-Reply-To: <2420ca24-b475-45ba-bab9-66c11b8cf484@redhat.com>
* David Hildenbrand <david@redhat.com> wrote:
> > > > try the trivial restriction approach first, and only go with your original
> > > > patch if that fails?
> > >
> > > Which version would you prefer, I had two alternatives (excluding comment
> > > changes, white-space expected to be broken).
> > >
> > >
> > > 1) Disallow when we would have set VM_PAT on is_cow_mapping()
> > >
> > > diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
> > > index 0d72183b5dd0..6979912b1a5d 100644
> > > --- a/arch/x86/mm/pat/memtype.c
> > > +++ b/arch/x86/mm/pat/memtype.c
> > > @@ -994,6 +994,9 @@ int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
> > > && size == (vma->vm_end - vma->vm_start))) {
> > > int ret;
> > > + if (is_cow_mapping(vma->vm_flags))
> > > + return -EINVAL;
> > > +
> > > ret = reserve_pfn_range(paddr, size, prot, 0);
> > > if (ret == 0 && vma)
> > > vm_flags_set(vma, VM_PAT);
> > >
> > >
> > > 2) Fallback to !VM_PAT
> > >
> > > diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
> > > index 0d72183b5dd0..8e97156c9be8 100644
> > > --- a/arch/x86/mm/pat/memtype.c
> > > +++ b/arch/x86/mm/pat/memtype.c
> > > @@ -990,8 +990,8 @@ int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
> > > enum page_cache_mode pcm;
> > > /* reserve the whole chunk starting from paddr */
> > > - if (!vma || (addr == vma->vm_start
> > > - && size == (vma->vm_end - vma->vm_start))) {
> > > + if (!vma || (!is_cow_mapping(vma->vm_flags) && addr == vma->vm_start &&
> > > + size == (vma->vm_end - vma->vm_start))) {
> > > int ret;
> > > ret = reserve_pfn_range(paddr, size, prot, 0);
> > >
> > >
> > >
> > > Personally, I'd go for 2).
> >
> > So what's the advantage of #2? This is clearly something the user didn't
> > really intend or think about much. Isn't explicitly failing that mapping a
> > better option than silently downgrading it to !VM_PAT?
> >
> > (If I'm reading it right ...)
>
> I think a simple mmap(MAP_PRIVATE) of /dev/mem will unconditionally fail
> with 1), while it keeps on working for 2).
>
> Note that I think we currently set VM_PAT on each and every system if
> remap_pfn_range() will cover the whole VMA, even if pat is not actually
> enabled.
>
> It's all a bit of a mess TBH, but I got my hands dirty enough on that.
>
> So 1) can be rather destructive ... 2) at least somehow keeps it working.
>
> For that reason I went with the current patch, because it's hard to tell
> which use case you will end up breaking ... :/
Yeah, so I think you make valid observations, i.e. your first patch is
probably the best one.
But since it changes mm/memory.c, I'd like to pass that over to Andrew
and the MM folks.
The x86 bits:
Acked-by: Ingo Molnar <mingo@kernel.org>
Thanks,
Ingo
next prev parent reply other threads:[~2024-04-01 9:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 18:11 [PATCH v1] x86/mm/pat: fix VM_PAT handling in COW mappings David Hildenbrand
2024-03-12 19:22 ` Matthew Wilcox
2024-03-12 19:38 ` David Hildenbrand
2024-03-14 16:42 ` David Hildenbrand
2024-03-14 17:12 ` David Hildenbrand
2024-03-25 2:57 ` mawupeng
2024-03-26 8:33 ` Ingo Molnar
2024-03-26 8:48 ` David Hildenbrand
2024-03-26 8:53 ` Ingo Molnar
2024-03-26 8:57 ` David Hildenbrand
2024-04-01 9:45 ` Ingo Molnar [this message]
2024-04-02 9:14 ` David Hildenbrand
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=ZgqCI8ClUKM4B5xG@gmail.com \
--to=mingo@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mawupeng1@huawei.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=willy@infradead.org \
--cc=x86@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