From patchwork Tue Aug 26 23:58:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Smarduch X-Patchwork-Id: 4784741 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9C3ACC0338 for ; Wed, 27 Aug 2014 00:01:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B40F1201FE for ; Wed, 27 Aug 2014 00:01:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C394D201F7 for ; Wed, 27 Aug 2014 00:01:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XMQds-00020p-N1; Tue, 26 Aug 2014 23:59:12 +0000 Received: from mailout4.w2.samsung.com ([211.189.100.14] helo=usmailout4.samsung.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XMQdq-0001hQ-Eb for linux-arm-kernel@lists.infradead.org; Tue, 26 Aug 2014 23:59:11 +0000 Received: from uscpsbgex3.samsung.com (u124.gpu85.samsung.co.kr [203.254.195.124]) by usmailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NAX00EJFUM13160@usmailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 26 Aug 2014 19:58:49 -0400 (EDT) X-AuditID: cbfec37c-b7fde6d000000c64-a7-53fd1f39254e Received: from usmmp1.samsung.com ( [203.254.195.77]) by uscpsbgex3.samsung.com (USCPEXMTA) with SMTP id F5.01.03172.93F1DF35; Tue, 26 Aug 2014 19:58:49 -0400 (EDT) Received: from sisasmtp.sisa.samsung.com ([105.144.21.116]) by usmmp1.samsung.com (Oracle Communications Messaging Server 7u4-27.01(7.0.4.27.0) 64bit (built Aug 30 2012)) with ESMTP id <0NAX00N34UM12360@usmmp1.samsung.com>; Tue, 26 Aug 2014 19:58:49 -0400 (EDT) Received: from mjsmard-530U3C-530U4C-532U3C.sisa.samsung.com (105.144.129.72) by SISAEX02SJ.sisa.samsung.com (105.144.21.116) with Microsoft SMTP Server (TLS) id 14.1.421.2; Tue, 26 Aug 2014 16:58:48 -0700 From: Mario Smarduch To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, ralf@linux-mips.org, gleb@kernel.org, agraf@suse.de, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, xiaoguangrong@linux.vnet.ibm.com Subject: [PATCH v10 6/6] arm: KVM: ARMv7 dirty page logging 2nd stage page fault handling support Date: Tue, 26 Aug 2014 16:58:46 -0700 Message-id: <1409097526-1225-1-git-send-email-m.smarduch@samsung.com> X-Mailer: git-send-email 1.7.9.5 MIME-version: 1.0 X-Originating-IP: [105.144.129.72] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPLMWRmVeSWpSXmKPExsVy+t9hX11L+b/BBtvfa1mcuPKP0WL6iu0s Fi9eA1nzmxsZLb78vM5oMWdqocWmx9dYLf7e+cdmsX/bP1aLS3tULCa92cZksfD/TUYHHo81 89Ywehx8dIjNY9OqTjaPO9f2sHkcXbmWyePBoc0sHpuX1Hu833eVzWPz6WqPz5vkAriiuGxS UnMyy1KL9O0SuDKmLTzOUnBCqeLY72XMDYzTZLoYOTkkBEwkDk15zAxhi0lcuLeerYuRi0NI YBmjxN8LJ1kgnF4mibYDD6Cci4wSh5Y9ZgdpYRPQldh/byOYLSJwnVHi7YcqEJtZoE7iwd5n rCC2sECyxOK1yxlBbBYBVYlb126D1fMKuEr0L+sHWscBtFpBYs4kG4iwoMSPyfdYQMLMAhIS zz8rgYSFgDq33XzOCHGoksTVuTNZJjAKzELSMQuhYwEj0ypGsdLi5ILipPTUCmO94sTc4tK8 dL3k/NxNjJBIqdnBeO+rzSFGAQ5GJR7eDwv+BAuxJpYVV+YeYpTgYFYS4f2RBBTiTUmsrEot yo8vKs1JLT7EyMTBKdXAWMOQxP5qUvvZjbJtGvffv1yhweHoeMPh+vmsC8qZDzmu5ESbHJ/o N213432ZsJL3+jqH9TZ9t/LWqBGffeba7cnLyoxM5O7nfJSMvc3jqcg7bc6JezoTbt/rS1j8 Jm/3EeMPb6xUr+3JfLhgncHTxHmvJi4L5HQ/25Fj8cjed8+53O+zXPNCi5VYijMSDbWYi4oT AWetYhRyAgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140826_165910_574419_276138A7 X-CRM114-Status: GOOD ( 13.37 ) X-Spam-Score: -5.0 (-----) Cc: Mario Smarduch , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, steve.capper@arm.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for handling 2nd stage page faults during migration, it disables faulting in huge pages, and dissolves huge pages to page tables. In case migration is canceled huge pages may be used again. Signed-off-by: Mario Smaduch --- arch/arm/kvm/mmu.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index f176edf..0d79db04 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -47,6 +47,15 @@ static phys_addr_t hyp_idmap_vector; #define kvm_pmd_huge(_x) (pmd_huge(_x) || pmd_trans_huge(_x)) #define kvm_pud_huge(_x) pud_huge(_x) +static bool kvm_get_logging_state(unsigned long *dirty_bitmap) +{ +#ifdef CONFIG_ARM + return !!dirty_bitmap; +#else + return false; +#endif +} + static void kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) { /* @@ -626,7 +635,8 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache } static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, - phys_addr_t addr, const pte_t *new_pte, bool iomap) + phys_addr_t addr, const pte_t *new_pte, bool iomap, + bool logging_active) { pmd_t *pmd; pte_t *pte, old_pte; @@ -641,6 +651,18 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, return 0; } + /* + * While dirty memory logging, clear PMD entry for huge page and split + * into smaller pages, to track dirty memory at page granularity. + */ + if (logging_active && kvm_pmd_huge(*pmd)) { + phys_addr_t ipa = pmd_pfn(*pmd) << PAGE_SHIFT; + + pmd_clear(pmd); + kvm_tlb_flush_vmid_ipa(kvm, ipa); + put_page(virt_to_page(pmd)); + } + /* Create stage-2 page mappings - Level 2 */ if (pmd_none(*pmd)) { if (!cache) @@ -693,7 +715,7 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, if (ret) goto out; spin_lock(&kvm->mmu_lock); - ret = stage2_set_pte(kvm, &cache, addr, &pte, true); + ret = stage2_set_pte(kvm, &cache, addr, &pte, true, false); spin_unlock(&kvm->mmu_lock); if (ret) goto out; @@ -909,6 +931,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; struct vm_area_struct *vma; pfn_t pfn; + bool logging_active = kvm_get_logging_state(memslot->dirty_bitmap); write_fault = kvm_is_write_fault(kvm_vcpu_get_hsr(vcpu)); if (fault_status == FSC_PERM && !write_fault) { @@ -919,7 +942,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, /* Let's check if we will get back a huge page backed by hugetlbfs */ down_read(¤t->mm->mmap_sem); vma = find_vma_intersection(current->mm, hva, hva + 1); - if (is_vm_hugetlb_page(vma)) { + if (is_vm_hugetlb_page(vma) && !logging_active) { hugetlb = true; gfn = (fault_ipa & PMD_MASK) >> PAGE_SHIFT; } else { @@ -962,7 +985,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, spin_lock(&kvm->mmu_lock); if (mmu_notifier_retry(kvm, mmu_seq)) goto out_unlock; - if (!hugetlb && !force_pte) + if (!hugetlb && !force_pte && !logging_active) hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa); if (hugetlb) { @@ -981,9 +1004,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, kvm_set_pfn_dirty(pfn); } coherent_cache_guest_page(vcpu, hva, PAGE_SIZE); - ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte, false); + ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte, false, + logging_active); } + if (write_fault) + mark_page_dirty(kvm, gfn); out_unlock: spin_unlock(&kvm->mmu_lock); @@ -1134,7 +1160,14 @@ static void kvm_set_spte_handler(struct kvm *kvm, gpa_t gpa, void *data) { pte_t *pte = (pte_t *)data; - stage2_set_pte(kvm, NULL, gpa, pte, false); + /* + * We can always call stage2_set_pte with logging_active == false, + * because MMU notifiers will have unmapped a huge PMD before calling + * ->change_pte() (which in turn calls kvm_set_spte_hva()) and therefore + * stage2_set_pte() never needs to clear out a huge PMD through this + * calling path. + */ + stage2_set_pte(kvm, NULL, gpa, pte, false, false); }