Skip to contentSkip to conversation

x86/mm: fix pg_level_to_pfn for 5-level paging mode.

PATCH Superseded Ashish Kalra 2 participants 4 messages Oct 13, 2023 – Oct 18, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: fix pg_level_to_pfn for 5-level paging mode.

From: Ashish Kalra <[email protected]>

Add support for 5-level paging in pg_level_to_pfn().

---
 arch/x86/mm/mem_encrypt_amd.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/mem_encrypt_amd.c +4 -0
index 6faea41e99b6..45914568596a 100644
@@ -267,6 +267,10 @@ static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
 		pfn = pud_pfn(*(pud_t *)kpte);
 		prot = pud_pgprot(*(pud_t *)kpte);
 		break;
+	case PG_LEVEL_512G:
+		pfn = p4d_pfn(*(p4d_t *)kpte);
+		prot = p4d_pgprot(*(p4d_t *)kpte);
+		break;
 	default:
 		WARN_ONCE(1, "Invalid level for kpte\n");
 		return 0;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 14 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

Add support for 5-level paging in pg_level_to_pfn().

---
 arch/x86/mm/mem_encrypt_amd.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/mem_encrypt_amd.c +0 -0
index 6faea41e99b6..45914568596a 100644

arch/x86/mm/mem_encrypt_amd.c static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot) · line 273

Quoted 7 lines
arch/x86/mm/mem_encrypt_amd.c +4 -0
@@ -267,6 +267,10 @@ static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
 		pfn = pud_pfn(*(pud_t *)kpte);
 		prot = pud_pgprot(*(pud_t *)kpte);
 		break;
+	case PG_LEVEL_512G:
+		pfn = p4d_pfn(*(p4d_t *)kpte);
+		prot = p4d_pgprot(*(p4d_t *)kpte);
+		break;

Mind explaining what happens if we don't have this fix, how you found it, which users are expected to be affected by it, whether that's the full known extent of 5-level paging support deficiencies in mem_encrypt_amd.c, etc?

In addition to such patches being much easier on the eyes, it also helps maintainers prioritize patches.

Thanks,

Ingo

#2 lore raw
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

Add support for 5-level paging in pg_level_to_pfn().

---
  arch/x86/mm/mem_encrypt_amd.c | 4 ++++
  1 file changed, 4 insertions(+)
Quoted 17 lines

arch/x86/mm/mem_encrypt_amd.c static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot) · line 273

Quoted 12 lines
arch/x86/mm/mem_encrypt_amd.c +4 -0
index 6faea41e99b6..45914568596a 100644
@@ -267,6 +267,10 @@ static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
  		pfn = pud_pfn(*(pud_t *)kpte);
  		prot = pud_pgprot(*(pud_t *)kpte);
  		break;
+	case PG_LEVEL_512G:
+		pfn = p4d_pfn(*(p4d_t *)kpte);
+		prot = p4d_pgprot(*(p4d_t *)kpte);
+		break;

Mind explaining what happens if we don't have this fix, how you found it, which users are expected to be affected by it, whether that's the full known extent of 5-level paging support deficiencies in mem_encrypt_amd.c,foud etc?

It was found during working on SNP guest kexec support, this helper function is used during early boot stage for setting of C-bit on the PTEs and additionally need this same helper for switching shared pages to private during guest kexec, so i believe this patch is needed.

Thanks,
Ashish

Quoted 7 lines

In addition to such patches being much easier on the eyes, it also helps maintainers prioritize patches.

Thanks,

Ingo

#3 lore raw
Quoted 33 lines · Kalra, Ashish
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

Add support for 5-level paging in pg_level_to_pfn().

---
  arch/x86/mm/mem_encrypt_amd.c | 4 ++++
  1 file changed, 4 insertions(+)
arch/x86/mm/mem_encrypt_amd.c +1 -0
index 6faea41e99b6..45914568596a 100644
@@ -267,6 +267,10 @@ static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
  		pfn = pud_pfn(*(pud_t *)kpte);
  		prot = pud_pgprot(*(pud_t *)kpte);
  		break;
+	case PG_LEVEL_512G:
Quoted 9 lines

arch/x86/mm/mem_encrypt_amd.c static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot) · line 273

Quoted 3 lines
arch/x86/mm/mem_encrypt_amd.c +3 -0
+		pfn = p4d_pfn(*(p4d_t *)kpte);
+		prot = p4d_pgprot(*(p4d_t *)kpte);
+		break;

Mind explaining what happens if we don't have this fix, how you found it, which users are expected to be affected by it, whether that's the full known extent of 5-level paging support deficiencies in mem_encrypt_amd.c,foud etc?

Quoted 4 lines

It was found during working on SNP guest kexec support, this helper function is used during early boot stage for setting of C-bit on the PTEs and additionally need this same helper for switching shared pages to private during guest kexec, so i believe this patch is needed.

Please integrate the information I suggested into the changelog and submit a v2 patch.

Thanks,

Ingo