Skip to contentSkip to conversation

KVM: PPC: Book3S HV: Fix reverse map real-mode address lookup with huge vmalloc

PATCH Superseded Nicholas Piggin 3 participants 3 messages May 23, 2021 – May 24, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

PATCH 1/1 KVM: PPC: Book3S HV: Fix reverse map real-mode address lookup with huge vmalloc

real_vmalloc_addr() does not currently work for huge vmalloc, which is what the reverse map can be allocated with for radix host, hash guest.

Add huge page awareness to the function.

Fixes 8abddd968a30 ("powerpc/64s/radix: Enable huge vmalloc mappings")
---
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_hv_rm_mmu.c +12 -5
index 7af7c70f1468..5f68cb5cc009 100644
@@ -26,16 +26,23 @@
 static void *real_vmalloc_addr(void *x)
 {
 	unsigned long addr = (unsigned long) x;
+	unsigned long mask;
+	int shift;
 	pte_t *p;
+
 	/*
-	 * assume we don't have huge pages in vmalloc space...
-	 * So don't worry about THP collapse/split. Called
-	 * Only in realmode with MSR_EE = 0, hence won't need irq_save/restore.
+	 * This is called only in realmode with MSR_EE = 0, hence won't need
+	 * irq_save/restore around find_init_mm_pte.
 	 */
-	p = find_init_mm_pte(addr, NULL);
+	p = find_init_mm_pte(addr, &shift);
 	if (!p || !pte_present(*p))
 		return NULL;
-	addr = (pte_pfn(*p) << PAGE_SHIFT) | (addr & ~PAGE_MASK);
+	if (!shift)
+		shift = PAGE_SHIFT;
+
+	mask = (1UL << shift) - 1;
+	addr = (pte_pfn(*p) << PAGE_SHIFT) | (addr & mask);
+
 	return __va(addr);
 }
 
Signature · 1 line
2.23.0
#1 lore raw

Nicholas Piggin <[email protected]> a écrit :

Quoted 30 lines

real_vmalloc_addr() does not currently work for huge vmalloc, which is what the reverse map can be allocated with for radix host, hash guest.

Add huge page awareness to the function.

Fixes 8abddd968a30 ("powerpc/64s/radix: Enable huge vmalloc mappings")
---
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_hv_rm_mmu.c +5 -3
index 7af7c70f1468..5f68cb5cc009 100644
@@ -26,16 +26,23 @@
 static void *real_vmalloc_addr(void *x)
 {
 	unsigned long addr = (unsigned long) x;
+	unsigned long mask;
+	int shift;
 	pte_t *p;
+
 	/*
-	 * assume we don't have huge pages in vmalloc space...
-	 * So don't worry about THP collapse/split. Called
-	 * Only in realmode with MSR_EE = 0, hence won't need irq_save/restore.
+	 * This is called only in realmode with MSR_EE = 0, hence won't need
+	 * irq_save/restore around find_init_mm_pte.
 	 */

arch/powerpc/kvm/book3s_hv_rm_mmu.c line 44

Quoted 10 lines
arch/powerpc/kvm/book3s_hv_rm_mmu.c +6 -2
-	p = find_init_mm_pte(addr, NULL);
+	p = find_init_mm_pte(addr, &shift);
 	if (!p || !pte_present(*p))
 		return NULL;
-	addr = (pte_pfn(*p) << PAGE_SHIFT) | (addr & ~PAGE_MASK);
+	if (!shift)
+		shift = PAGE_SHIFT;
+
+	mask = (1UL << shift) - 1;
+	addr = (pte_pfn(*p) << PAGE_SHIFT) | (addr & mask);

Looks strange, before we have ~MASK now we have mask without the ~

Also use PFN_PHYS() instead of open coding ?

Quoted 6 lines
arch/powerpc/kvm/book3s_hv_rm_mmu.c +1 -1
+
 	return __va(addr);
 }
 
--

2.23.0

#2 lore raw
Quoted 37 lines · Christophe Leroy

Nicholas Piggin <[email protected]> a écrit :

Quoted 35 lines

real_vmalloc_addr() does not currently work for huge vmalloc, which is what the reverse map can be allocated with for radix host, hash guest.

Add huge page awareness to the function.

Fixes 8abddd968a30 ("powerpc/64s/radix: Enable huge vmalloc mappings")
---
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_hv_rm_mmu.c +6 -4
index 7af7c70f1468..5f68cb5cc009 100644
@@ -26,16 +26,23 @@
 static void *real_vmalloc_addr(void *x)
 {
 	unsigned long addr = (unsigned long) x;
+	unsigned long mask;
+	int shift;
 	pte_t *p;
+
 	/*
-	 * assume we don't have huge pages in vmalloc space...
-	 * So don't worry about THP collapse/split. Called
-	 * Only in realmode with MSR_EE = 0, hence won't need irq_save/restore.
+	 * This is called only in realmode with MSR_EE = 0, hence won't need
+	 * irq_save/restore around find_init_mm_pte.
 	 */
-	p = find_init_mm_pte(addr, NULL);
+	p = find_init_mm_pte(addr, &shift);
 	if (!p || !pte_present(*p))
 		return NULL;
Quoted 8 lines

arch/powerpc/kvm/book3s_hv_rm_mmu.c line 44

Quoted 6 lines
arch/powerpc/kvm/book3s_hv_rm_mmu.c +5 -1
-	addr = (pte_pfn(*p) << PAGE_SHIFT) | (addr & ~PAGE_MASK);
+	if (!shift)
+		shift = PAGE_SHIFT;
+
+	mask = (1UL << shift) - 1;
+	addr = (pte_pfn(*p) << PAGE_SHIFT) | (addr & mask);

Looks strange, before we have ~MASK now we have mask without the ~

#define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))

-aneesh