linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "42.hyeyoo@gmail.com" <42.hyeyoo@gmail.com>
Cc: "kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"Lutomirski, Andy" <luto@kernel.org>,
	"bp@alien8.de" <bp@alien8.de>,
	"Tianyu.Lan@microsoft.com" <Tianyu.Lan@microsoft.com>,
	"aneesh.kumar@linux.ibm.com" <aneesh.kumar@linux.ibm.com>,
	"thomas.lendacky@amd.com" <thomas.lendacky@amd.com>,
	"brijesh.singh@amd.com" <brijesh.singh@amd.com>
Subject: Re: [PATCH] x86/mm/cpa: set PAGE_KERNEL in __set_pages_p()
Date: Tue, 10 May 2022 15:38:30 +0000	[thread overview]
Message-ID: <e93470ca9c969246b68338fe04e64fb32262b266.camel@intel.com> (raw)
In-Reply-To: <YnpRhT68kwaMBEHF@hyeyoo>

On Tue, 2022-05-10 at 20:50 +0900, Hyeonggon Yoo wrote:
> Thanks for review!
> 
> IIUC __pgprot_mask() already clears _PAGE_GLOBAL from PAGE_KERNEL
> when PTI is used.
> 
> #define __pgprot_mask(x)        __pgprot((x) &
> __default_kernel_pte_mask)
> #define PAGE_KERNEL             __pgprot_mask(__PAGE_KERNEL | _ENC)
> 
> But yeah, it seems PAGE_KERNEL is too much for this.

Oh, yep, you're right.

> 
> > Maybe something like this?
> > (_PAGE_PRESENT | _PAGE_RW | _PAGE_GLOBAL) &
> > __default_kernel_pte_mask
> > 
> 
> What about __pgprot_mask(_PAGE_PRESENT | _PAGE_RW | _PAGE_GLOBAL)?
> 
> > That would add back in a little of the "default global" behavior
> > that
> > was removed in d1440b2, but I think it should be ok because it is
> > limited to the direct map. 
> > Otherwise, I wonder if the existing global
> > clearing logic is really needed.
> 
> I think it's still needed. pte_present() returning true due to
> _PAGE_PROTNONE
> after __set_pages_np() simply doesn't make sense. No?

Yea, I just meant we don't need PROTNONE in the kernel PTEs (I think),
so the kernel is forced to do weird stuff in CPA so that it can share
the pte helpers with userspace.

I have not thought this all the way through, but say we declared that
PROT_NONE doesn't exist in kernel pte's, then pte_present() could be
like:

static inline int pte_present(pte_t a)
{
	pteval_t val = pte_flags(a)
	bool kernel_p = val & (_PAGE_USER | _PAGE_PRESENT) ==
			_PAGE_PRESENT;
	bool user_p = (val & _PAGE_USER) &&
		      (val & (_PAGE_PRESENT | _PAGE_PROTNONE));

	/*
	 * PROT_NONE does not exist for kernel PTEs, but global and
	 * not present can appear in other cases. Check each
	 * differently depending on the user bit.
	 */
	return kernel_p || user_p;
}

Not sure where else it ties in. I think that is what Dave was getting
at in the other thread - to figure out all the places that need to
change to remove the meaning from kernel PTEs.

Re-setting global seems valid too.


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

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06  5:19 [PATCH] x86/mm/cpa: set PAGE_KERNEL in __set_pages_p() Hyeonggon Yoo
2022-05-09 16:06 ` Tom Lendacky
2022-05-10 11:57   ` Hyeonggon Yoo
2022-05-10 13:35     ` Tom Lendacky
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 [this message]

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=e93470ca9c969246b68338fe04e64fb32262b266.camel@intel.com \
    --to=rick.p.edgecombe@intel.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=Tianyu.Lan@microsoft.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=brijesh.singh@amd.com \
    --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=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --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;
as well as URLs for NNTP newsgroup(s).