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 5/5] KVM: arm/arm64: Add support for creating PMD contiguous hugepages at stage2
Date: Wed, 1 May 2019 09:44:27 +0000 [thread overview]
Message-ID: <1556703867-22396-6-git-send-email-yuzenghui@huawei.com> (raw)
In-Reply-To: <1556703867-22396-1-git-send-email-yuzenghui@huawei.com>
With this patch, we now support PMD contiguous hugepages at stage2, with
following additional page size at stage2:
CONT PMD
--------
4K granule: 32M
16K granule: 1G
64K granule: 16G
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
---
virt/kvm/arm/mmu.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
index fdd6314..7173589 100644
--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -1125,6 +1125,66 @@ static pte_t *stage2_get_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache
return pte_offset_kernel(pmd, addr);
}
+static inline pgprot_t pmd_pgprot(pmd_t pmd)
+{
+ unsigned long pfn = pmd_pfn(pmd);
+
+ return __pgprot(pmd_val(pfn_pmd(pfn, __pgprot(0))) ^ pmd_val(pmd));
+}
+
+static int stage2_set_cont_pmds(struct kvm *kvm, struct kvm_mmu_memory_cache
+ *cache, phys_addr_t addr, const pmd_t *new_pmd)
+{
+ pmd_t *pmd, old_pmd;
+ unsigned long pfn, dpfn;
+ int i;
+ pgprot_t hugeprot;
+ phys_addr_t baddr;
+
+ /* Start with the first pmd. */
+ addr &= CONT_PMD_MASK;
+ pfn = pmd_pfn(*new_pmd);
+ dpfn = PMD_SIZE >> PAGE_SHIFT;
+ hugeprot = pmd_pgprot(*new_pmd);
+
+retry:
+ pmd = stage2_get_pmd(kvm, cache, addr);
+ VM_BUG_ON(!pmd);
+
+ old_pmd = *pmd;
+
+ /* Skip page table update if there is no change */
+ if (pmd_val(old_pmd) == pmd_val(*new_pmd))
+ return 0;
+
+ /*
+ * baddr and the following loop is for only one scenario:
+ * logging cancel ... Can we do it better?
+ */
+ baddr = addr;
+ for (i = 0; i < CONT_PMDS; i++, pmd++, baddr += PMD_SIZE) {
+ if (pmd_present(*pmd) && !pmd_thp_or_huge(*pmd)) {
+ unmap_stage2_range(kvm, baddr, S2_PMD_SIZE);
+ goto retry;
+ }
+ }
+
+ pmd = stage2_get_pmd(kvm, cache, addr);
+
+ for (i = 0; i < CONT_PMDS; i++, pmd++, addr += PMD_SIZE, pfn += dpfn) {
+ if (pmd_present(old_pmd)) {
+ pmd_clear(pmd);
+ kvm_tlb_flush_vmid_ipa(kvm, addr);
+ } else {
+ get_page(virt_to_page(pmd));
+ }
+
+ kvm_set_pmd(pmd, pfn_pmd(pfn, hugeprot));
+ }
+
+ return 0;
+}
+
static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache
*cache, phys_addr_t addr, const pmd_t *new_pmd)
{
@@ -1894,6 +1954,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
* 3 levels, i.e, PMD is not folded.
*/
if (vma_pagesize == CONT_PTE_SIZE || vma_pagesize == PMD_SIZE ||
+ vma_pagesize == CONT_PMD_SIZE ||
(vma_pagesize == PUD_SIZE && kvm_stage2_has_pmd(kvm)))
gfn = (fault_ipa & huge_page_mask(hstate_vma(vma))) >> PAGE_SHIFT;
up_read(¤t->mm->mmap_sem);
@@ -1982,6 +2043,11 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
needs_exec);
ret = stage2_set_pud_huge(kvm, memcache, fault_ipa, &new_pud);
+ } else if (vma_pagesize == CONT_PMD_SIZE) {
+ pmd_t new_pmd = stage2_build_pmd(pfn, mem_type, writable,
+ needs_exec, true);
+
+ ret = stage2_set_cont_pmds(kvm, memcache, fault_ipa, &new_pmd);
} else if (vma_pagesize == PMD_SIZE) {
pmd_t new_pmd = stage2_build_pmd(pfn, mem_type, writable,
needs_exec, false);
--
1.8.3.1
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 ` [PATCH 3/5] KVM: arm/arm64: Support dirty page tracking for contiguous hugepages Zenghui Yu
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 ` Zenghui Yu [this message]
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-6-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).