mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Rick Edgecombe <rick.p.edgecombe@intel.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>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Tianyu Lan <Tianyu.Lan@microsoft.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/mm/cpa: set PAGE_KERNEL in __set_pages_p()
Date: Tue, 10 May 2022 08:35:27 -0500	[thread overview]
Message-ID: <5fe161cb-6c55-6c4d-c208-16c77e115d3f@amd.com> (raw)
In-Reply-To: <YnpTHMvOO/pLJQ+l@hyeyoo>

On 5/10/22 06:57, Hyeonggon Yoo wrote:
> On Mon, May 09, 2022 at 11:06:22AM -0500, Tom Lendacky wrote:
>> On 5/6/22 00:19, Hyeonggon Yoo wrote:
>>> __set_pages_np() not only clears _PAGE_PRESENT and _PAGE_RW, but also
>>> clears _PAGE_GLOBAL to avoid confusing _PAGE_GLOBAL as _PAGE_PROTNONE
>>> when the PTE is not present.
>>>
>>> Common usage for __set_pages_p() is to call it after __set_pages_np().
>>> Therefore calling __set_pages_p() after __set_pages_np() clears
>>> _PAGE_GLOBAL, making it unable to globally shared in TLB.
>>>
>>> As they are called by set_direct_map_{invalid,default}_noflush(),
>>> pages in direct map cannot be globally shared in TLB after being used by
>>> vmalloc, secretmem, and hibernation.
>>>
>>> So set PAGE_KERNEL isntead of __pgprot(_PAGE_PRESENT | _PAGE_RW) in
>>> __set_pages_p().
>>>
>>> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
>>> ---
>>>    arch/x86/mm/pat/set_memory.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
>>> index abf5ed76e4b7..fcb6147c4cd4 100644
>>> --- a/arch/x86/mm/pat/set_memory.c
>>> +++ b/arch/x86/mm/pat/set_memory.c
>>> @@ -2177,7 +2177,7 @@ static int __set_pages_p(struct page *page, int numpages)
>>>    	struct cpa_data cpa = { .vaddr = &tempaddr,
>>>    				.pgd = NULL,
>>>    				.numpages = numpages,
>>> -				.mask_set = __pgprot(_PAGE_PRESENT | _PAGE_RW),
>>> +				.mask_set = PAGE_KERNEL,
>>
>> With SME/SEV, this will also (unintentionally) set the encryption bit, so I
>> don't think this is correct.
>>
> 
> Thank you for catching this.
> It seems PAGE_KERNEL was too much for  __set_pages_p().
> 
> I think __pgprot_mask(_PAGE_KERNEL | _PAGE_RW | _PAGE_GLOBAL) would be correct.
> Thoughts?

That should work, but you are counting on this function being called in a 
specific situation. Should this function ever be called from some other 
place in the kernel, in the future, that might inadvertently apply the 
global setting when it shouldn't.

I'm wondering if adding a specific helper that takes a boolean to indicate 
whether to set the global flag would be best. I'll let some of the MM 
maintainers comment about that.

Thanks,
Tom

> 
>> Thanks,
>> Tom
>>
>>>    				.mask_clr = __pgprot(0),
>>>    				.flags = 0};
> 

  reply	other threads:[~2022-05-10 14:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06  5:19 Hyeonggon Yoo
2022-05-09 16:06 ` Tom Lendacky
2022-05-10 11:57   ` Hyeonggon Yoo
2022-05-10 13:35     ` Tom Lendacky [this message]
2022-05-10 14:39       ` Dave Hansen
2022-05-11  5:20         ` Is _PAGE_PROTNONE set only for user mappings? Hyeonggon Yoo
2022-05-12 10:37           ` Mel Gorman
2022-05-13  5:33             ` Hyeonggon Yoo
2022-05-16 13:03               ` Mel Gorman
2022-05-16 14:04               ` Dave Hansen
2022-05-22  3:56                 ` Hyeonggon Yoo
2022-05-24 20:22                   ` Sean Christopherson
2022-05-26 10:33                     ` Hyeonggon Yoo
2022-05-29 10:32                 ` Hyeonggon Yoo
2022-06-02 16:47                   ` Dave Hansen
2022-05-10  0:47 ` [PATCH] x86/mm/cpa: set PAGE_KERNEL in __set_pages_p() Edgecombe, Rick P
2022-05-10 11:50   ` Hyeonggon Yoo
2022-05-10 15:38     ` Edgecombe, Rick P

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=5fe161cb-6c55-6c4d-c208-16c77e115d3f@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=Tianyu.Lan@microsoft.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=tglx@linutronix.de \
    --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

all inboxes | Powered by JetHome®