linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/mm/ptdump: display page encryption state
@ 2022-04-19 14:35 Mike Rapoport
  2022-04-19 18:57 ` Dave Hansen
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Rapoport @ 2022-04-19 14:35 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Andy Lutomirski, Dave Hansen, H. Peter Anvin, Ingo Molnar,
	Mike Rapoport, Mike Rapoport, Thomas Gleixner, x86, linux-kernel

From: Mike Rapoport <rppt@linux.ibm.com>

When memory encryption is enabled, for instance in SEV guest, it is useful
to see what memory ranges are mapped as encrypted in the kernel page tables
and what ranges are left plain.

Add printing of 'ENC' for the encrypted ranges to the page table dumps.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 arch/x86/mm/dump_pagetables.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index e1b599ecbbc2..187dd17b8780 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -201,6 +201,10 @@ static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg
 			pt_dump_cont_printf(m, dmsg, "PCD ");
 		else
 			pt_dump_cont_printf(m, dmsg, "    ");
+		if (pr & _PAGE_ENC)
+			pt_dump_cont_printf(m, dmsg, "ENC ");
+		else
+			pt_dump_cont_printf(m, dmsg, "    ");
 
 		/* Bit 7 has a different meaning on level 3 vs 4 */
 		if (level <= 3 && pr & _PAGE_PSE)

base-commit: b2d229d4ddb17db541098b83524d901257e93845
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/mm/ptdump: display page encryption state
  2022-04-19 14:35 [PATCH] x86/mm/ptdump: display page encryption state Mike Rapoport
@ 2022-04-19 18:57 ` Dave Hansen
  2022-04-20  7:17   ` Mike Rapoport
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Hansen @ 2022-04-19 18:57 UTC (permalink / raw)
  To: Mike Rapoport, Borislav Petkov
  Cc: Andy Lutomirski, Dave Hansen, H. Peter Anvin, Ingo Molnar,
	Mike Rapoport, Thomas Gleixner, x86, linux-kernel

On 4/19/22 07:35, Mike Rapoport wrote:
> When memory encryption is enabled, for instance in SEV guest, it is useful
> to see what memory ranges are mapped as encrypted in the kernel page tables
> and what ranges are left plain.
> 
> Add printing of 'ENC' for the encrypted ranges to the page table dumps.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
>  arch/x86/mm/dump_pagetables.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
> index e1b599ecbbc2..187dd17b8780 100644
> --- a/arch/x86/mm/dump_pagetables.c
> +++ b/arch/x86/mm/dump_pagetables.c
> @@ -201,6 +201,10 @@ static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg
>  			pt_dump_cont_printf(m, dmsg, "PCD ");
>  		else
>  			pt_dump_cont_printf(m, dmsg, "    ");
> +		if (pr & _PAGE_ENC)
> +			pt_dump_cont_printf(m, dmsg, "ENC ");
> +		else
> +			pt_dump_cont_printf(m, dmsg, "    ");

_PAGE_ENC is AMD-specific.  Could we do this with a new generic "cc_"
function, maybe cc_is_enc()?

Something like this would (I think) work for both SEV and TDX:

bool cc_is_enc(u64 prot)
{
	return cc_mkdec(prot) != prot;
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/mm/ptdump: display page encryption state
  2022-04-19 18:57 ` Dave Hansen
@ 2022-04-20  7:17   ` Mike Rapoport
  2022-04-20 14:30     ` Dave Hansen
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Rapoport @ 2022-04-20  7:17 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Borislav Petkov, Andy Lutomirski, Dave Hansen, H. Peter Anvin,
	Ingo Molnar, Mike Rapoport, Thomas Gleixner, x86, linux-kernel

On Tue, Apr 19, 2022 at 11:57:47AM -0700, Dave Hansen wrote:
> On 4/19/22 07:35, Mike Rapoport wrote:
> > When memory encryption is enabled, for instance in SEV guest, it is useful
> > to see what memory ranges are mapped as encrypted in the kernel page tables
> > and what ranges are left plain.
> > 
> > Add printing of 'ENC' for the encrypted ranges to the page table dumps.
> > 
> > Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> > ---
> >  arch/x86/mm/dump_pagetables.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
> > index e1b599ecbbc2..187dd17b8780 100644
> > --- a/arch/x86/mm/dump_pagetables.c
> > +++ b/arch/x86/mm/dump_pagetables.c
> > @@ -201,6 +201,10 @@ static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg
> >  			pt_dump_cont_printf(m, dmsg, "PCD ");
> >  		else
> >  			pt_dump_cont_printf(m, dmsg, "    ");
> > +		if (pr & _PAGE_ENC)
> > +			pt_dump_cont_printf(m, dmsg, "ENC ");
> > +		else
> > +			pt_dump_cont_printf(m, dmsg, "    ");
> 
> _PAGE_ENC is AMD-specific.  Could we do this with a new generic "cc_"
> function, maybe cc_is_enc()?
> 
> Something like this would (I think) work for both SEV and TDX:
> 
> bool cc_is_enc(u64 prot)
> {
> 	return cc_mkdec(prot) != prot;
> }

It works for SEV. I can repost with this and you'll confirm it works on
TDX?

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/mm/ptdump: display page encryption state
  2022-04-20  7:17   ` Mike Rapoport
@ 2022-04-20 14:30     ` Dave Hansen
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Hansen @ 2022-04-20 14:30 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Borislav Petkov, Andy Lutomirski, Dave Hansen, H. Peter Anvin,
	Ingo Molnar, Mike Rapoport, Thomas Gleixner, x86, linux-kernel,
	Shutemov, Kirill, Kuppuswamy Sathyanarayanan

On 4/20/22 00:17, Mike Rapoport wrote:
>> _PAGE_ENC is AMD-specific. Could we do this with a new generic "cc_"
>> function, maybe cc_is_enc()?
>>
>> Something like this would (I think) work for both SEV and TDX:
>>
>> bool cc_is_enc(u64 prot)
>> {
>> 	return cc_mkdec(prot) != prot;
>> }
> It works for SEV. I can repost with this and you'll confirm it works on
> TDX?

I don't have a TDX setup handy, but Kirill certainly does.  I'm sure
he'd be happy to give you a tested-by.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-20 14:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 14:35 [PATCH] x86/mm/ptdump: display page encryption state Mike Rapoport
2022-04-19 18:57 ` Dave Hansen
2022-04-20  7:17   ` Mike Rapoport
2022-04-20 14:30     ` Dave Hansen

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).