kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: Andrew Jones <drjones@redhat.com>,
	Nikos Nikoleris <nikos.nikoleris@arm.com>
Cc: kvm@vger.kernel.org, mark.rutland@arm.com, jade.alglave@arm.com,
	luc.maranget@inria.fr, andre.przywara@arm.com
Subject: Re: [kvm-unit-tests PATCH 1/2] arm64: Add support for configuring the translation granule
Date: Tue, 3 Nov 2020 16:25:15 +0000	[thread overview]
Message-ID: <2f2a6f1a-2893-2a45-8145-8c013237025e@arm.com> (raw)
In-Reply-To: <20201103161038.32orgisio5xy5cn2@kamzik.brq.redhat.com>

Hi,

On 11/3/20 4:10 PM, Andrew Jones wrote:
> On Tue, Nov 03, 2020 at 03:49:32PM +0000, Nikos Nikoleris wrote:
>>>> diff --git a/lib/arm64/asm/page.h b/lib/arm64/asm/page.h
>>>> index 46af552..2a06207 100644
>>>> --- a/lib/arm64/asm/page.h
>>>> +++ b/lib/arm64/asm/page.h
>>>> @@ -10,38 +10,51 @@
>>>>    * This work is licensed under the terms of the GNU GPL, version 2.
>>>>    */
>>>> +#include <config.h>
>>>>   #include <linux/const.h>
>>>> -#define PGTABLE_LEVELS		2
>>>>   #define VA_BITS			42
>>> Let's bump VA_BITS to 48 while we're at it.
> I tried my suggestion to go to 48 VA bits, but it seems to break
> things for 64K pages.

I believe that is because we end up with PGTABLE_LEVELS=3 and in
mmu_set_ranges_sect() we try to install a block mapping at the PUD level, which is
forbidden by the architecture.

I think the easiest fix for that is to always try to install block mapping at the
pmd level. The diff below fixed all errors (with 16k and 64k pages):

diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index 6d1c75b00eaa..d33948a8a06a 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -134,20 +134,22 @@ void mmu_set_range_sect(pgd_t *pgtable, uintptr_t virt_offset,
                        phys_addr_t phys_start, phys_addr_t phys_end,
                        pgprot_t prot)
 {
-       phys_addr_t paddr = phys_start & PUD_MASK;
-       uintptr_t vaddr = virt_offset & PUD_MASK;
+       phys_addr_t paddr = phys_start & PMD_MASK;
+       uintptr_t vaddr = virt_offset & PMD_MASK;
        uintptr_t virt_end = phys_end - paddr + vaddr;
        pgd_t *pgd;
        pud_t *pud;
-       pud_t entry;
+       pmd_t *pmd;
+       pmd_t entry;
 
-       for (; vaddr < virt_end; vaddr += PUD_SIZE, paddr += PUD_SIZE) {
-               pud_val(entry) = paddr;
-               pud_val(entry) |= PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S;
-               pud_val(entry) |= pgprot_val(prot);
+       for (; vaddr < virt_end; vaddr += PMD_SIZE, paddr += PMD_SIZE) {
+               pmd_val(entry) = paddr;
+               pmd_val(entry) |= PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S;
+               pmd_val(entry) |= pgprot_val(prot);
                pgd = pgd_offset(pgtable, vaddr);
                pud = pud_alloc(pgd, vaddr);
-               WRITE_ONCE(*pud, entry);
+               pmd = pmd_alloc(pud, vaddr);
+               WRITE_ONCE(*pmd, entry);
                flush_tlb_page(vaddr);
        }
 }
diff --git a/lib/arm64/asm/page.h b/lib/arm64/asm/page.h
index 2a06207444aa..f649f56bf16f 100644
--- a/lib/arm64/asm/page.h
+++ b/lib/arm64/asm/page.h
@@ -13,7 +13,7 @@
 #include <config.h>
 #include <linux/const.h>
 
-#define VA_BITS                        42
+#define VA_BITS                        46
 
 #define PAGE_SIZE              CONFIG_PAGE_SIZE
 #if PAGE_SIZE == 65536

Thanks,

Alex


  reply	other threads:[~2020-11-03 16:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02 11:34 [kvm-unit-tests PATCH 0/2] arm64: Add support for configuring the translation granule Nikos Nikoleris
2020-11-02 11:34 ` [kvm-unit-tests PATCH 1/2] " Nikos Nikoleris
2020-11-03 13:04   ` Andrew Jones
2020-11-03 15:49     ` Nikos Nikoleris
2020-11-03 16:10       ` Andrew Jones
2020-11-03 16:25         ` Alexandru Elisei [this message]
2020-11-03 16:39           ` Andrew Jones
2020-11-03 16:46             ` Alexandru Elisei
2020-11-03 16:21   ` Alexandru Elisei
2020-11-03 17:14     ` Nikos Nikoleris
2020-11-02 11:34 ` [kvm-unit-tests PATCH 2/2] arm64: Check if the configured translation granule is supported Nikos Nikoleris
2020-11-03 10:02   ` Andrew Jones
2020-11-03 10:21     ` Nikos Nikoleris
2020-11-03 17:03     ` Alexandru Elisei
2020-11-03 17:36       ` Andrew Jones
2020-11-03 18:14         ` Nikos Nikoleris
2020-11-03 18:23           ` Andrew Jones

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=2f2a6f1a-2893-2a45-8145-8c013237025e@arm.com \
    --to=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=drjones@redhat.com \
    --cc=jade.alglave@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=luc.maranget@inria.fr \
    --cc=mark.rutland@arm.com \
    --cc=nikos.nikoleris@arm.com \
    /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 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).