Skip to contentSkip to conversation

x86/mm/ptdump: display page encryption state

PATCH Superseded Mike Rapoport 2 participants 4 messages Apr 19, 2022 – Apr 20, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm/ptdump: display page encryption state

From: Mike Rapoport <[email protected]>

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.

---
 arch/x86/mm/dump_pagetables.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/dump_pagetables.c +4 -0
index e1b599ecbbc2..187dd17b8780 100644
@@ -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

Signature · 1 line
2.28.0
#1 lore raw
Quoted 16 lines · Mike Rapoport

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.

---
 arch/x86/mm/dump_pagetables.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/dump_pagetables.c +0 -0
index e1b599ecbbc2..187dd17b8780 100644

arch/x86/mm/dump_pagetables.c static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg · line 207

Quoted 7 lines
arch/x86/mm/dump_pagetables.c +4 -0
@@ -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;
}
#2 lore raw
Quoted 28 lines · Dave Hansen
Quoted 16 lines · Mike Rapoport

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.

---
 arch/x86/mm/dump_pagetables.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/dump_pagetables.c +0 -0
index e1b599ecbbc2..187dd17b8780 100644

arch/x86/mm/dump_pagetables.c static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg · line 207

Quoted 7 lines
arch/x86/mm/dump_pagetables.c +4 -0
@@ -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()?

Quoted 6 lines

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?

Signature · 2 lines
Sincerely yours,
Mike.
#3 lore raw
Quoted 11 lines · Mike Rapoport
Quoted 9 lines

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