From: Zenghui Yu <yuzenghui@huawei.com>
To: <linux-arm-kernel@lists.infradead.org>,
<kvmarm@lists.cs.columbia.edu>, <linux-kernel@vger.kernel.org>,
<kvm@vger.kernel.org>
Cc: <marc.zyngier@arm.com>, <christoffer.dall@arm.com>,
<linux@armlinux.org.uk>, <catalin.marinas@arm.com>,
<will.deacon@arm.com>, <james.morse@arm.com>,
<julien.thierry@arm.com>, <suzuki.poulose@arm.com>,
<steve.capper@arm.com>, <wanghaibin.wang@huawei.com>,
Zenghui Yu <yuzenghui@huawei.com>
Subject: [PATCH 3/5] KVM: arm/arm64: Support dirty page tracking for contiguous hugepages
Date: Wed, 1 May 2019 09:44:25 +0000 [thread overview]
Message-ID: <1556703867-22396-4-git-send-email-yuzenghui@huawei.com> (raw)
In-Reply-To: <1556703867-22396-1-git-send-email-yuzenghui@huawei.com>
When logging is enabled, we should keep tracking of normal size pages.
If the memslot is backed by contiguous hugepages, we should dissolve
the contiguous hugepages - clear the whole contiguous range and flush
corresponding TLB entry.
Move kvm_set_{pte,pmd} to the front of stage2_dissolve_cont_{pte,pmd}s
to avoid one more declaration.
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
---
arch/arm/include/asm/pgtable-hwdef.h | 8 ++++
virt/kvm/arm/mmu.c | 76 ++++++++++++++++++++++++++++++------
2 files changed, 72 insertions(+), 12 deletions(-)
diff --git a/arch/arm/include/asm/pgtable-hwdef.h b/arch/arm/include/asm/pgtable-hwdef.h
index 8426229..41f4633 100644
--- a/arch/arm/include/asm/pgtable-hwdef.h
+++ b/arch/arm/include/asm/pgtable-hwdef.h
@@ -16,4 +16,12 @@
#include <asm/pgtable-2level-hwdef.h>
#endif
+/* dummy definition */
+#define CONT_PTES (0)
+#define CONT_PTE_SIZE (0)
+#define CONT_PTE_MASK (0)
+#define CONT_PMDS (0)
+#define CONT_PMD_SIZE (0)
+#define CONT_PMD_MASK (0)
+
#endif
diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
index cf8b035..36c863f 100644
--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -96,6 +96,58 @@ static bool kvm_is_device_pfn(unsigned long pfn)
return !pfn_valid(pfn);
}
+static inline void kvm_set_pte(pte_t *ptep, pte_t new_pte)
+{
+ WRITE_ONCE(*ptep, new_pte);
+ dsb(ishst);
+}
+
+static inline void kvm_set_pmd(pmd_t *pmdp, pmd_t new_pmd)
+{
+ WRITE_ONCE(*pmdp, new_pmd);
+ dsb(ishst);
+}
+
+static void stage2_dissolve_cont_ptes(struct kvm *kvm, phys_addr_t addr,
+ pte_t *pte)
+{
+ phys_addr_t addrp;
+ pte_t *ptep;
+ int i;
+
+ if (!kvm_s2pte_cont(*pte))
+ return;
+
+ /* Start with the first pte */
+ addrp = addr & CONT_PTE_MASK;
+ ptep = pte - (addr - addrp) / PAGE_SIZE;
+
+ for (i = 0; i < CONT_PTES; i++, ptep++, addrp += PAGE_SIZE) {
+ kvm_set_pte(ptep, __pte(0));
+ kvm_tlb_flush_vmid_ipa(kvm, addrp);
+ put_page(virt_to_page(ptep));
+ }
+}
+
+static void stage2_dissolve_cont_pmds(struct kvm *kvm, phys_addr_t addr,
+ pmd_t *pmd)
+{
+ phys_addr_t addrp;
+ pmd_t *pmdp;
+ int i;
+
+ /* Start with the first pmd */
+ addr &= PMD_MASK;
+ addrp = addr & CONT_PMD_MASK;
+ pmdp = pmd - (addr - addrp) / PMD_SIZE;
+
+ for (i = 0; i < CONT_PMDS; i++, pmdp++, addrp += PMD_SIZE) {
+ pmd_clear(pmdp);
+ kvm_tlb_flush_vmid_ipa(kvm, addrp);
+ put_page(virt_to_page(pmdp));
+ }
+}
+
/**
* stage2_dissolve_pmd() - clear and flush huge PMD entry
* @kvm: pointer to kvm structure.
@@ -109,6 +161,11 @@ static void stage2_dissolve_pmd(struct kvm *kvm, phys_addr_t addr, pmd_t *pmd)
if (!pmd_thp_or_huge(*pmd))
return;
+ if (kvm_s2pmd_cont(*pmd)) {
+ stage2_dissolve_cont_pmds(kvm, addr, pmd);
+ return;
+ }
+
pmd_clear(pmd);
kvm_tlb_flush_vmid_ipa(kvm, addr);
put_page(virt_to_page(pmd));
@@ -193,18 +250,6 @@ static void clear_stage2_pmd_entry(struct kvm *kvm, pmd_t *pmd, phys_addr_t addr
put_page(virt_to_page(pmd));
}
-static inline void kvm_set_pte(pte_t *ptep, pte_t new_pte)
-{
- WRITE_ONCE(*ptep, new_pte);
- dsb(ishst);
-}
-
-static inline void kvm_set_pmd(pmd_t *pmdp, pmd_t new_pmd)
-{
- WRITE_ONCE(*pmdp, new_pmd);
- dsb(ishst);
-}
-
static inline void kvm_pmd_populate(pmd_t *pmdp, pte_t *ptep)
{
kvm_set_pmd(pmdp, kvm_mk_pmd(ptep));
@@ -1289,6 +1334,13 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache,
pte = pte_offset_kernel(pmd, addr);
+ /*
+ * While dirty page logging - dissolve contiguous PTE pages, then
+ * continue on to allocate page.
+ */
+ if (logging_active)
+ stage2_dissolve_cont_ptes(kvm, addr, pte);
+
if (iomap && pte_present(*pte))
return -EFAULT;
--
1.8.3.1
next prev parent reply other threads:[~2019-05-01 9:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-01 9:44 [RFC PATCH 0/5] KVM: arm64: Add support for contiguous PTE/PMD hugepages at stage2 Zenghui Yu
2019-05-01 9:44 ` [PATCH 1/5] KVM: arm/arm64: Introduce helpers for page table enties with contiguous bit Zenghui Yu
2019-05-01 9:44 ` [PATCH 2/5] KVM: arm/arm64: Re-factor building the stage2 page table entries Zenghui Yu
2019-05-01 9:44 ` Zenghui Yu [this message]
2019-05-01 9:44 ` [PATCH 4/5] KVM: arm/arm64: Add support for creating PTE contiguous hugepages at stage2 Zenghui Yu
2019-05-01 9:44 ` [PATCH 5/5] KVM: arm/arm64: Add support for creating PMD " Zenghui Yu
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=1556703867-22396-4-git-send-email-yuzenghui@huawei.com \
--to=yuzenghui@huawei.com \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@arm.com \
--cc=james.morse@arm.com \
--cc=julien.thierry@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=marc.zyngier@arm.com \
--cc=steve.capper@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=wanghaibin.wang@huawei.com \
--cc=will.deacon@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).