Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6393669imd; Wed, 31 Oct 2018 11:00:12 -0700 (PDT) X-Google-Smtp-Source: AJdET5e6zkpxd45yEr5X3sUNVT8WhFGuI0o0/zGDRPr1mpWqWK6Bl1lIkMuX/kHUt8hF48vRRn1J X-Received: by 2002:a17:902:b403:: with SMTP id x3-v6mr4454262plr.237.1541008812115; Wed, 31 Oct 2018 11:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541008812; cv=none; d=google.com; s=arc-20160816; b=OiLjVwzenRMVwZT+ZS6vWqoZQEK1QUGj10gb1CHprnidzgSAYJZniYOY6vhBXeOVPU EY3Y6gFrLh8/FsMgXnXoQZgKQhZ3TLCUPDemSo6lCUMT7pg5NBuY4Ul444wfuq3+RIQn GUdDyMikI4J9uL6JHlYz3qmrBTnaNSXjwMe75/1lSj2B8BLpW3s9GmC728XIwAmdeOop ZgyExrE34w3Wpk9j6Rxjo8kQE63W/e18PHhpBxIqu91XrBE+ugQTj63XN2+ivrfjlirU rY22Hoo0IaT51//0EfRomYkuprVaLf/2MbKQ69/fPcOeOkkC0LaiLIFRTuQN1CzlyHat i63Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=H9VWG+TjIXqTzQQ4nrXIAq3u//slAKKL3Ba2Yf4cCaI=; b=NZliAnU7YuqJcgl3/j2EQiJnF6dFi4elXriXZjr3OpM3yFgbX79rn7cPOVSgJbCuoT kXBwN0sS+UiTznXgXSPQXTYHBRWFXkD5C5CQJJxaXgsXgXgQUQ+rJBJoFNGV8rjhu4E/ XNdhIgU+h+YJEAjS3+bumYy7yarDH7DZ9pDpr6HhnMWoGixRg5gteSomBK+sTm1qqZNd tmEyrb0KhXW1mvEMJ/TqLnppTinq7JvG7y+0pEad+4SBVefkA8Oz+YPmg5X/T/fmCFz1 4ryzVHg4SBQm8YO752OwywSV/ww0lg2pTGAbD2eQD6WpwnJ6IuKzqvXhD/Pl3Y4RfnDV vRig== 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 c141-v6si29724674pfb.78.2018.10.31.10.59.56; Wed, 31 Oct 2018 11:00:12 -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 S1730124AbeKAC5x (ORCPT + 99 others); Wed, 31 Oct 2018 22:57:53 -0400 Received: from foss.arm.com ([217.140.101.70]:44898 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729437AbeKAC5x (ORCPT ); Wed, 31 Oct 2018 22:57:53 -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 999C815BE; Wed, 31 Oct 2018 10:58:49 -0700 (PDT) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.197.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3D48C3F6A8; Wed, 31 Oct 2018 10:58:49 -0700 (PDT) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu Cc: Punit Agrawal , marc.zyngier@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com, punitagrawal@gmail.com, Christoffer Dall , Russell King , Catalin Marinas Subject: [PATCH v9 7/8] KVM: arm64: Update age handlers to support PUD hugepages Date: Wed, 31 Oct 2018 17:57:44 +0000 Message-Id: <20181031175745.18650-8-punit.agrawal@arm.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181031175745.18650-1-punit.agrawal@arm.com> References: <20181031175745.18650-1-punit.agrawal@arm.com> MIME-Version: 1.0 X-ARM-No-Footer: FoSSMail Content-Transfer-Encoding: 8bit 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 Reviewed-by: Suzuki K Poulose 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 | 39 ++++++++++++++++---------------- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index fea5e723e3ac..e62f0913ce7d 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -117,6 +117,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 pte_t kvm_s2pte_mkwrite(pte_t pte) { pte_val(pte) |= L_PTE_S2_RDWR; diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 612032bbb428..9f941f70775c 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -273,6 +273,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); +} + #define hyp_pte_table_empty(ptep) kvm_page_empty(ptep) #ifdef __PAGETABLE_PMD_FOLDED diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index f51e2271e6a3..bb0f3f17a7a9 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -386,6 +386,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 bd749601195f..3893ea6a50bf 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1225,6 +1225,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 * @@ -1932,42 +1937,38 @@ 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) { + pud_t *pud; pmd_t *pmd; pte_t *pte; - 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); + if (!stage2_get_leaf_entry(kvm, gpa, &pud, &pmd, &pte)) 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) { + pud_t *pud; pmd_t *pmd; pte_t *pte; - 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); + if (!stage2_get_leaf_entry(kvm, gpa, &pud, &pmd, &pte)) 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.19.1