Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp681029imm; Thu, 5 Jul 2018 07:12:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfYddYbRF4n1Op/wjKVBvkTchk4lESu4cEs2YQCV1WNcSN3yIAAbA9bfpqPp7HtOc+PSC80 X-Received: by 2002:a17:902:b604:: with SMTP id b4-v6mr6365307pls.18.1530799921641; Thu, 05 Jul 2018 07:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530799921; cv=none; d=google.com; s=arc-20160816; b=nckrZE4wXGr3bFVRCSPUIDzRjY3GB5RmDgjIiyDEiPAMHBiXpMJXEwpe5birI8/Z2l /ritVMfnAjlkh2ZumUQhFvpoP4Yd+MT4rCoeF3p2f+uP2jW+tASRzG5aaAiLi1t40Tqi wGjwVWa0UhQMGD44S8kr7fXTTN1Jpci7EGzfRVvOe+n6QM1wOc7tW4YIMkXcXlL9sWa0 scGPzuzI01+uRkxdeIT3AAdLKJpv2bu1ZtGRtBLuAEOkSei0ZNfLPI5moesNiLod/mIa RHVPEXCRT3o4QeNgn4zDdxQLtdADOuhpt977jL5ItHYXKRKsJaMdoxXMEEm0IGhK6v9G 3CDg== 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=cu3jWl1MoZqSjFAo6N6PrDWEqjCOBk5saEOJG5fGQoA=; b=A5GY7Qqj2Pcq9M/RM0067R2fa9FH/eC3g8xdi1aEaasmNpPRDFeJn7WWsyKiyghdi6 tLOMAOQTE6kaYNt4zXrkUmOOdimiN0V/G+1qaMOtgGczDC8z+zzvxvcy7k351xAVERCD WMgBT8w0ms9zqkmVE2OhdvT5JOVDDdGOROKqQA6ZRPpiFSzUZifHov6DeTycFFowGcc3 uoI1KGhSiUPo5OgMWH8X48m/+RMgqDP+w9FNtJQwUlru1PtMBbLkU82h9lcrYaSbSX4o z3e0K6Ecn4vaFchIYz4QNfudAz+zOrWaogBZ+wrua9dB7s6ue/IUndwN4NRalAJPtUd9 ZCrg== 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 s4-v6si5917574pfh.256.2018.07.05.07.11.34; Thu, 05 Jul 2018 07:12:01 -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 S1753895AbeGEOJf (ORCPT + 99 others); Thu, 5 Jul 2018 10:09:35 -0400 Received: from foss.arm.com ([217.140.101.70]:50258 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753449AbeGEOJd (ORCPT ); Thu, 5 Jul 2018 10:09:33 -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 16E111595; Thu, 5 Jul 2018 07:09:33 -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 8AA4F3F5BA; Thu, 5 Jul 2018 07:09:32 -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, Russell King , Catalin Marinas , Will Deacon Subject: [PATCH v4 2/7] KVM: arm/arm64: Introduce helpers to manupulate page table entries Date: Thu, 5 Jul 2018 15:08:45 +0100 Message-Id: <20180705140850.5801-3-punit.agrawal@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180705140850.5801-1-punit.agrawal@arm.com> References: <20180705140850.5801-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 Introduce helpers to abstract architectural handling of the conversion of pfn to page table entries and marking a PMD page table entry as a block entry. The helpers are introduced in preparation for supporting PUD hugepages at stage 2 - which are supported on arm64 but do not exist on arm. Signed-off-by: Punit Agrawal Acked-by: Christoffer Dall Cc: Marc Zyngier Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon --- arch/arm/include/asm/kvm_mmu.h | 5 +++++ arch/arm64/include/asm/kvm_mmu.h | 5 +++++ virt/kvm/arm/mmu.c | 8 +++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index 8553d68b7c8a..d095c2d0b284 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -75,6 +75,11 @@ phys_addr_t kvm_get_idmap_vector(void); int kvm_mmu_init(void); void kvm_clear_hyp_idmap(void); +#define kvm_pfn_pte(pfn, prot) pfn_pte(pfn, prot) +#define kvm_pfn_pmd(pfn, prot) pfn_pmd(pfn, prot) + +#define kvm_pmd_mkhuge(pmd) pmd_mkhuge(pmd) + 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 fb9a7127bb75..689def9bb9d5 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -172,6 +172,11 @@ void kvm_clear_hyp_idmap(void); #define kvm_set_pte(ptep, pte) set_pte(ptep, pte) #define kvm_set_pmd(pmdp, pmd) set_pmd(pmdp, pmd) +#define kvm_pfn_pte(pfn, prot) pfn_pte(pfn, prot) +#define kvm_pfn_pmd(pfn, prot) pfn_pmd(pfn, prot) + +#define kvm_pmd_mkhuge(pmd) pmd_mkhuge(pmd) + static inline pte_t kvm_s2pte_mkwrite(pte_t pte) { pte_val(pte) |= PTE_S2_RDWR; diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index dd14cc36c51c..040cd0bce5e1 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1557,8 +1557,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, invalidate_icache_guest_page(pfn, vma_pagesize); if (hugetlb && vma_pagesize == PMD_SIZE) { - pmd_t new_pmd = pfn_pmd(pfn, mem_type); - new_pmd = pmd_mkhuge(new_pmd); + pmd_t new_pmd = kvm_pfn_pmd(pfn, mem_type); + + new_pmd = kvm_pmd_mkhuge(new_pmd); + if (writable) new_pmd = kvm_s2pmd_mkwrite(new_pmd); @@ -1567,7 +1569,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, ret = stage2_set_pmd_huge(kvm, memcache, fault_ipa, &new_pmd); } else { - pte_t new_pte = pfn_pte(pfn, mem_type); + pte_t new_pte = kvm_pfn_pte(pfn, mem_type); if (writable) { new_pte = kvm_s2pte_mkwrite(new_pte); -- 2.17.1