From: David Hildenbrand <david@redhat.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org,
xingwei lee <xrivendell7@gmail.com>,
yuxin wang <wang1315768607@163.com>,
Marius Fleischer <fleischermarius@gmail.com>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
Dan Carpenter <dan.carpenter@linaro.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Rik van Riel <riel@surriel.com>, "H. Peter Anvin" <hpa@zytor.com>,
Peter Xu <peterx@redhat.com>,
Liam Howlett <liam.howlett@oracle.com>
Subject: Re: [PATCH v3] x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()
Date: Wed, 2 Apr 2025 17:19:31 +0200 [thread overview]
Message-ID: <46f62096-03ed-47fc-a522-64cb2bfeb361@redhat.com> (raw)
In-Reply-To: <54b3a9c3-f39f-4b58-9695-d4303341ec3d@lucifer.local>
On 02.04.25 14:31, Lorenzo Stoakes wrote:
> TL;DR is I agree with you :P I'm not sure where to put R-b tag given you sent a
> fix-patch, as this is obviously smatch/clang-broken as-is so feels wrong to put
> on main bit.
I'll respin! :)
>
> I guess I'll put on fix-patch and Andrew? Are you taking this? If so maybe from
> there you can propagate?
[...]
>
> If that handles it then fine, let's just init to 0.
>
>>
>> So this should be working as expected? No need to add something on top that
>> makes it even more ugly in the caller.
>
> Yes, agreed, if this is already being handled in the one hideous place let's
> make it hideous there only.
>
> But maybe a comment...?
I can add that that function handles the need for actual untracking
internally.
[...]
>>>> +
>>>> + /*
>>>> + * Duplicate the PAT information for the dst VMA based on the src
>>>> + * VMA.
>>>> + */
>>>> + if (get_pat_info(src_vma, &paddr, &pgprot))
>>>> + return -EINVAL;
>>>> + rc = reserve_pfn_range(paddr, vma_size, &pgprot, 1);
>>>> + if (rc)
>>>> + return rc;
>>>
>>> I mean it's a crazy nit, but we use ret elsewhere but rc here, maybe better
>>> to use ret in both places.
>>>
>>> But also feel free to ignore this.
>>
>> "int retval;" ? ;)
>
> Lol, 'rv'?
>
> Maybe let's leave it as is :P
I think "ret" is used in the file, so I'll use that.
>
>>
>>>
>>>>
>>>> + /* Reservation for the destination VMA succeeded. */
>>>> + vm_flags_set(dst_vma, VM_PAT);
>>>> + *pfn = PHYS_PFN(paddr);
>>>> return 0;
>>>> }
>>>>
>>>> +void untrack_pfn_copy(struct vm_area_struct *dst_vma, unsigned long pfn)
>>>> +{
>>>> + untrack_pfn(dst_vma, pfn, dst_vma->vm_end - dst_vma->vm_start, true);
>>>> + /*
>>>> + * Reservation was freed, any copied page tables will get cleaned
>>>> + * up later, but without getting PAT involved again.
>>>> + */
>>>> +}
>>>> +
>>>> /*
>>>> * prot is passed in as a parameter for the new mapping. If the vma has
>>>> * a linear pfn mapping for the entire range, or no vma is provided,
>>>> @@ -1095,15 +1108,6 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
>>>> }
>>>> }
>>>>
>>>> -/*
>>>> - * untrack_pfn_clear is called if the following situation fits:
>>>> - *
>>>> - * 1) while mremapping a pfnmap for a new region, with the old vma after
>>>> - * its pfnmap page table has been removed. The new vma has a new pfnmap
>>>> - * to the same pfn & cache type with VM_PAT set.
>>>> - * 2) while duplicating vm area, the new vma fails to copy the pgtable from
>>>> - * old vma.
>>>> - */
>>>
>>> This just wrong now?
>>
>> Note that I'm keeping the doc to a single place -- the stub in the header.
>> (below)
>>
>> Or can you elaborate what exactly is "wrong"?
>
> Ah ok maybe I just missed this. I was asking whether it was wrong, and this is
> why maybe you are removing (perhaps, not very clearly :)
Ah, sorry. Yes, it's just deduplicated to be adjusted in the other copy :)
[...]
>>> Can I say as an aside that I hate this kind of hook? Like quite a lot?
>>>
>>> I mean I've been looking at mremap() of anon mappings as you know obv. but
>>> the thought of PFN mapping mremap()ing is kind of also a bit ugh.
>>
>> I absolutely hate all of that, but I'll have to leave any cleanups to people
>> with more spare time ;)
>
> Lol well... maybe at some point I will find some for this... when things get
> ugly enough I find that I make the time in the end ;)
We're kind-of attaching metadata to a VMA, that is not directly linked
to the VMA. And the duplication of a VMA cannot handle that, so we defer
copying of that metadata. Hm ...
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-04-02 15:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-25 19:19 [PATCH v3] x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range() David Hildenbrand
2025-04-02 11:36 ` David Hildenbrand
2025-04-02 12:32 ` Lorenzo Stoakes
2025-04-03 14:47 ` David Hildenbrand
2025-04-03 14:50 ` Lorenzo Stoakes
2025-04-02 11:59 ` Lorenzo Stoakes
2025-04-02 12:20 ` David Hildenbrand
2025-04-02 12:31 ` Lorenzo Stoakes
2025-04-02 15:19 ` David Hildenbrand [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-03-27 1:59 kernel test robot
2025-04-02 11:19 ` Lorenzo Stoakes
2025-04-02 11:32 ` David Hildenbrand
2025-04-02 11:40 ` Lorenzo Stoakes
2025-04-02 11:37 Lorenzo Stoakes
2025-04-03 15:14 ` [PATCH v3] x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range() Dan Carpenter
2025-04-03 20:59 ` David Hildenbrand
2025-04-04 11:52 ` Lorenzo Stoakes
2025-04-04 12:20 ` David Hildenbrand
2025-04-04 12:27 ` David Hildenbrand
2025-04-06 17:17 ` Ingo Molnar
2025-04-07 7:11 ` Dan Carpenter
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=46f62096-03ed-47fc-a522-64cb2bfeb361@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dan.carpenter@linaro.org \
--cc=dave.hansen@linux.intel.com \
--cc=fleischermarius@gmail.com \
--cc=hpa@zytor.com \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=torvalds@linux-foundation.org \
--cc=wang1315768607@163.com \
--cc=x86@kernel.org \
--cc=xrivendell7@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.