Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp618324imm; Mon, 9 Jul 2018 07:44:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgperqdb6TMkHpvKcnFtCdhunf5/sI7KAFw3VaXt7X3dYO+keU5+V8hWZy4vP8FjDn8FFf4xQ X-Received: by 2002:a17:902:d711:: with SMTP id w17-v6mr20438381ply.200.1531147496323; Mon, 09 Jul 2018 07:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531147496; cv=none; d=google.com; s=arc-20160816; b=Ejjcw30oWfJLmGmxeEkuCeFFJziI99necjcEUKcHsRtWkK0Q9sQqCxASmLg0cXP+U2 S3Jr/BeM4We+99QwCHqeuGVU50dA9xLvXoQG5nk2AGC+7Ywcwvffg5FoOODrlvz3VHJ8 yg0MvQoJkTc/vlwLDTzaDTABokIomSCbQZ6XEEvfRAY2OzpBtfpDBfpswX13pEdebV6l 8CPJJjhxzwapQR2QHiwoO6CpGfo8W3721ZoY976nuX02gUYNK+nwAqxDd9+7GeEKzG0V MoXbVOO31GZZ0ArGNIPqZgV2grnjfO/a1whIyPoBi4AfseXhnx+/HOUoMUo7aOJLC2no aaZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=YKL9MsXhuP6qeocB1YsvUpDsQiOjIgAjWlOviG9Lbis=; b=FynqbkKF0ade07z56gXj1y6L6SVltj7YEyuykB+1292/ix1uqxyNsE67rIJzwpYgOT MoMe/E4qOl6UjLJPDX7rOCZKM4e5HGDz+tRbEIzeiA/Iz6wnBOrTPhrJ4fENSyo6FNxj rDTp5ceWT9xwWi2J5ukKxTcEvDAU1Guq/kIvAMTWaKqVgPQ0MCpqnizF7BJlzo+EmjyN iPS3ot3EDQOYLTmmadPWwjPrOHJc73/RtqetD3V+Ix6CUaettcqPsfdyQ2eXFb6UuodJ wJRHKxXBzon2okFOCfZtURIQMCVbR75u8DuDO6sMpG1bbvuLWz7dPKTxFC34fsXPTINf dSWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q126-v6si7202439pfb.277.2018.07.09.07.44.41; Mon, 09 Jul 2018 07:44:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933097AbeGIOmL (ORCPT + 99 others); Mon, 9 Jul 2018 10:42:11 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:60418 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932824AbeGIOmJ (ORCPT ); Mon, 9 Jul 2018 10:42:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CE30C1682; Mon, 9 Jul 2018 07:42:08 -0700 (PDT) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.206.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 737ED3F589; Mon, 9 Jul 2018 07:42:08 -0700 (PDT) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu Cc: Punit Agrawal , linux-arm-kernel@lists.infradead.org, marc.zyngier@arm.com, christoffer.dall@arm.com, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com, will.deacon@arm.com, Russell King , Catalin Marinas Subject: [PATCH v5 6/7] KVM: arm64: Update age handlers to support PUD hugepages Date: Mon, 9 Jul 2018 15:41:23 +0100 Message-Id: <20180709144124.29164-6-punit.agrawal@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180709144124.29164-1-punit.agrawal@arm.com> References: <20180709143835.28971-1-punit.agrawal@arm.com> <20180709144124.29164-1-punit.agrawal@arm.com> X-ARM-No-Footer: FoSSMail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for creating larger hugepages at Stage 2, add support to the age handling notifiers for PUD hugepages when encountered. Provide trivial helpers for arm32 to allow sharing code. Signed-off-by: Punit Agrawal Cc: Christoffer Dall Cc: Marc Zyngier Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon --- arch/arm/include/asm/kvm_mmu.h | 6 ++++ arch/arm64/include/asm/kvm_mmu.h | 5 ++++ arch/arm64/include/asm/pgtable.h | 1 + virt/kvm/arm/mmu.c | 51 ++++++++++++++++++-------------- 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index a4298d429efc..8e1e8aee229e 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -110,6 +110,12 @@ static inline pud_t kvm_s2pud_mkyoung(pud_t pud) return pud; } +static inline bool kvm_s2pud_young(pud_t pud) +{ + BUG(); + return false; +} + static inline void kvm_set_pmd(pmd_t *pmd, pmd_t new_pmd) { *pmd = new_pmd; diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 4d2780c588b0..c542052fb199 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -261,6 +261,11 @@ static inline pud_t kvm_s2pud_mkyoung(pud_t pud) return pud_mkyoung(pud); } +static inline bool kvm_s2pud_young(pud_t pud) +{ + return pud_young(pud); +} + static inline bool kvm_page_empty(void *ptr) { struct page *ptr_page = virt_to_page(ptr); diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index a64a5c35beb1..4d9476e420d9 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -385,6 +385,7 @@ static inline int pmd_protnone(pmd_t pmd) #define pfn_pmd(pfn,prot) __pmd(__phys_to_pmd_val((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot)) #define mk_pmd(page,prot) pfn_pmd(page_to_pfn(page),prot) +#define pud_young(pud) pte_young(pud_pte(pud)) #define pud_mkyoung(pud) pte_pud(pte_mkyoung(pud_pte(pud))) #define pud_write(pud) pte_write(pud_pte(pud)) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index d2c705e31584..a6d3ac9d7c7a 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1172,6 +1172,11 @@ static int stage2_pmdp_test_and_clear_young(pmd_t *pmd) return stage2_ptep_test_and_clear_young((pte_t *)pmd); } +static int stage2_pudp_test_and_clear_young(pud_t *pud) +{ + return stage2_ptep_test_and_clear_young((pte_t *)pud); +} + /** * kvm_phys_addr_ioremap - map a device range to guest IPA * @@ -1879,42 +1884,42 @@ void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) static int kvm_age_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data) { - pmd_t *pmd; - pte_t *pte; + pud_t *pud = NULL; + pmd_t *pmd = NULL; + pte_t *pte = NULL; + bool found; - WARN_ON(size != PAGE_SIZE && size != PMD_SIZE); - pmd = stage2_get_pmd(kvm, NULL, gpa); - if (!pmd || pmd_none(*pmd)) /* Nothing there */ + WARN_ON(size != PAGE_SIZE && size != PMD_SIZE && size != PUD_SIZE); + found = stage2_get_leaf_entry(kvm, gpa, &pud, &pmd, &pte); + if (!found) return 0; - if (pmd_thp_or_huge(*pmd)) /* THP, HugeTLB */ + if (pud) + return stage2_pudp_test_and_clear_young(pud); + else if (pmd) return stage2_pmdp_test_and_clear_young(pmd); - - pte = pte_offset_kernel(pmd, gpa); - if (pte_none(*pte)) - return 0; - - return stage2_ptep_test_and_clear_young(pte); + else + return stage2_ptep_test_and_clear_young(pte); } static int kvm_test_age_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data) { - pmd_t *pmd; - pte_t *pte; + pud_t *pud = NULL; + pmd_t *pmd = NULL; + pte_t *pte = NULL; + bool found; - WARN_ON(size != PAGE_SIZE && size != PMD_SIZE); - pmd = stage2_get_pmd(kvm, NULL, gpa); - if (!pmd || pmd_none(*pmd)) /* Nothing there */ + WARN_ON(size != PAGE_SIZE && size != PMD_SIZE && size != PUD_SIZE); + found = stage2_get_leaf_entry(kvm, gpa, &pud, &pmd, &pte); + if (!found) return 0; - if (pmd_thp_or_huge(*pmd)) /* THP, HugeTLB */ + if (pud) + return kvm_s2pud_young(*pud); + else if (pmd) return pmd_young(*pmd); - - pte = pte_offset_kernel(pmd, gpa); - if (!pte_none(*pte)) /* Just a page... */ + else return pte_young(*pte); - - return 0; } int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) -- 2.17.1