All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: kvm-ppc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org, Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH] KVM: PPC: Book3S HV: Fix reverse map real-mode address lookup with huge vmalloc
Date: Sun, 23 May 2021 15:53:38 +0000	[thread overview]
Message-ID: <20210523155338.3254465-1-npiggin@gmail.com> (raw)

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")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index 7af7c70f1468..5f68cb5cc009 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -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);
 }
 
-- 
2.23.0

WARNING: multiple messages have this Message-ID (diff)
From: Nicholas Piggin <npiggin@gmail.com>
To: kvm-ppc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org, Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH] KVM: PPC: Book3S HV: Fix reverse map real-mode address lookup with huge vmalloc
Date: Mon, 24 May 2021 01:53:38 +1000	[thread overview]
Message-ID: <20210523155338.3254465-1-npiggin@gmail.com> (raw)

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")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index 7af7c70f1468..5f68cb5cc009 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -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);
 }
 
-- 
2.23.0


             reply	other threads:[~2021-05-23 15:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23 15:53 Nicholas Piggin [this message]
2021-05-23 15:53 ` [PATCH] KVM: PPC: Book3S HV: Fix reverse map real-mode address lookup with huge vmalloc Nicholas Piggin
2021-05-23 16:10 ` Christophe Leroy
2021-05-23 16:10   ` Christophe Leroy
2021-05-24  7:47   ` Aneesh Kumar K.V
2021-05-24  7:59     ` Aneesh Kumar K.V

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=20210523155338.3254465-1-npiggin@gmail.com \
    --to=npiggin@gmail.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.