From: Christoffer Dall <c.dall@virtualopensystems.com>
To: android-virt@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: tech@virtualopensystems.com
Subject: [PATCH v6 03/12] ARM: KVM: Hypervisor identity mapping
Date: Thu, 23 Feb 2012 02:32:33 -0500 [thread overview]
Message-ID: <20120223073233.3266.67561.stgit@ubuntu> (raw)
In-Reply-To: <20120223073159.3266.45217.stgit@ubuntu>
From: Christoffer Dall <c.dall@virtualopensystems.com>
Adds support in the identity mapping feature that allows KVM to setup
identity mapping for the Hyp mode with the AP[1] bit set as required by
the specification and also supports freeing created sub pmd's after
finished use.
These two functions:
- hyp_idmap_add(pgd, addr, end);
- hyp_idmap_del(pgd, addr, end);
are essentially calls to the same function as the non-hyp versions but
with a different argument value. KVM calls these functions to setup
and teardown the identity mapping used to initialize the hypervisor.
Note, the hyp-version of the _del function actually frees the pmd's
pointed to by the pgd as opposed to the non-hyp version which just
clears them.
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
---
arch/arm/include/asm/pgtable-3level-hwdef.h | 1 +
arch/arm/include/asm/pgtable.h | 5 +++
arch/arm/kvm/guest.c | 1 -
arch/arm/mm/idmap.c | 47 +++++++++++++++++++++++++--
4 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
index d795282..a2d404e 100644
--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
@@ -44,6 +44,7 @@
#define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
#define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
#define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
+#define PMD_SECT_AP1 (_AT(pmdval_t, 1) << 6)
#define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
/*
diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index f66626d..c7bd809 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -310,6 +310,11 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
#define pgtable_cache_init() do { } while (0)
+#ifdef CONFIG_KVM_ARM_HOST
+void hyp_idmap_add(pgd_t *, unsigned long, unsigned long);
+void hyp_idmap_del(pgd_t *pgd, unsigned long addr, unsigned long end);
+#endif
+
#endif /* !__ASSEMBLY__ */
#endif /* CONFIG_MMU */
diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c
index 9c75ec4..c0adab0 100644
--- a/arch/arm/kvm/guest.c
+++ b/arch/arm/kvm/guest.c
@@ -24,7 +24,6 @@
#include <asm/kvm_asm.h>
#include <asm/kvm_emulate.h>
-
struct kvm_stats_debugfs_item debugfs_entries[] = {
{ NULL }
};
diff --git a/arch/arm/mm/idmap.c b/arch/arm/mm/idmap.c
index feacf4c..35902d7 100644
--- a/arch/arm/mm/idmap.c
+++ b/arch/arm/mm/idmap.c
@@ -1,3 +1,4 @@
+#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/cputype.h>
@@ -58,11 +59,13 @@ static void idmap_add_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
} while (pud++, addr = next, addr != end);
}
-static void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
+static void identity_mapping_add(pgd_t *pgd, unsigned long addr,
+ unsigned long end, unsigned long prot)
{
- unsigned long prot, next;
+ unsigned long next;
+
+ prot |= PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_AF;
- prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_AF;
if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
prot |= PMD_BIT4;
@@ -89,12 +92,48 @@ static int __init init_static_idmap(void)
pr_info("Setting up static identity map for 0x%llx - 0x%llx\n",
(long long)idmap_start, (long long)idmap_end);
- identity_mapping_add(idmap_pgd, idmap_start, idmap_end);
+ identity_mapping_add(idmap_pgd, idmap_start, idmap_end, 0);
return 0;
}
early_initcall(init_static_idmap);
+#ifdef CONFIG_KVM_ARM_HOST
+void hyp_idmap_add(pgd_t *pgd, unsigned long addr, unsigned long end)
+{
+ identity_mapping_add(pgd, addr, end, PMD_SECT_AP1);
+}
+EXPORT_SYMBOL_GPL(hyp_idmap_add);
+
+static void hyp_idmap_del_pmd(pgd_t *pgd, unsigned long addr)
+{
+ pud_t *pud;
+ pmd_t *pmd;
+
+ pud = pud_offset(pgd, addr);
+ pmd = pmd_offset(pud, addr);
+ pmd_free(NULL, pmd);
+ pud_clear(pud);
+}
+
+/*
+ * This version actually frees the underlying pmds for all pgds in range and
+ * clear the pgds themselves afterwards.
+ */
+void hyp_idmap_del(pgd_t *pgd, unsigned long addr, unsigned long end)
+{
+ unsigned long next;
+
+ pgd += pgd_index(addr);
+ do {
+ next = pgd_addr_end(addr, end);
+ if (!pgd_none_or_clear_bad(pgd))
+ hyp_idmap_del_pmd(pgd, addr);
+ } while (pgd++, addr = next, addr < end);
+}
+EXPORT_SYMBOL_GPL(hyp_idmap_del);
+#endif
+
/*
* In order to soft-boot, we need to switch to a 1:1 mapping for the
* cpu_reset functions. This will then ensure that we have predictable
next prev parent reply other threads:[~2012-02-23 7:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-23 7:32 [PATCH v6 00/12] KVM/ARM Implementation Christoffer Dall
2012-02-23 7:32 ` [PATCH v6 01/12] KVM: Introduce __KVM_HAVE_IRQ_LINE Christoffer Dall
2012-02-23 7:32 ` [PATCH v6 02/12] ARM: KVM: Initial skeleton to compile KVM support Christoffer Dall
2012-02-24 3:32 ` Rusty Russell
2012-02-24 4:43 ` Christoffer Dall
2012-02-25 3:50 ` Rusty Russell
2012-02-25 15:20 ` Christoffer Dall
2012-03-11 21:41 ` Christoffer Dall
2012-02-23 7:32 ` Christoffer Dall [this message]
2012-02-24 3:33 ` [PATCH v6 03/12] ARM: KVM: Hypervisor identity mapping Rusty Russell
2012-02-23 7:32 ` [PATCH v6 04/12] ARM: KVM: Hypervisor inititalization Christoffer Dall
2012-02-24 4:00 ` Rusty Russell
2012-03-11 22:24 ` Christoffer Dall
2012-03-13 3:20 ` Rusty Russell
2012-03-05 1:12 ` Rusty Russell
2012-03-05 2:13 ` Christoffer Dall
2012-02-23 7:32 ` [PATCH v6 05/12] ARM: KVM: Memory virtualization setup Christoffer Dall
2012-02-23 7:32 ` [PATCH v6 06/12] ARM: KVM: Inject IRQs and FIQs from userspace Christoffer Dall
2012-02-23 7:32 ` [PATCH v6 07/12] ARM: KVM: World-switch implementation Christoffer Dall
2012-02-23 7:33 ` [PATCH v6 08/12] ARM: KVM: Emulation framework and CP15 emulation Christoffer Dall
2012-02-23 7:33 ` [PATCH v6 09/12] ARM: KVM: Handle guest faults in KVM Christoffer Dall
2012-02-23 7:33 ` [PATCH v6 10/12] ARM: KVM: Handle I/O aborts Christoffer Dall
2012-02-23 7:33 ` [PATCH v6 11/12] ARM: KVM: Guest wait-for-interrupts (WFI) support Christoffer Dall
2012-02-23 7:33 ` [PATCH v6 12/12] ARM: KVM: Handle CP15 CR9 accesses for L2CTLR emulation Christoffer Dall
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=20120223073233.3266.67561.stgit@ubuntu \
--to=c.dall@virtualopensystems.com \
--cc=android-virt@lists.cs.columbia.edu \
--cc=kvm@vger.kernel.org \
--cc=tech@virtualopensystems.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