Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2202567imm; Mon, 16 Jul 2018 04:11:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpewJaX6gP9lnzPg4zdNmzv+wNuUzA+Gd2ekR5ijY/wlcK8lMkmexXIJ8UilnupcnXmjbvEk X-Received: by 2002:a62:8a4f:: with SMTP id y76-v6mr17602809pfd.233.1531739493660; Mon, 16 Jul 2018 04:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531739493; cv=none; d=google.com; s=arc-20160816; b=Rn8WT9qU2XQVvpOR2lq9jUpLXALjKbOtVjfUN9h+dp39ua3HCeAAEIV4Y/nshY9UIw x7SAsKpcBYViViTDF7meqo2bRGm5GWqSHZo+GYydgZ4necwodTET2YZE3K36sHGGp/ic DnjFrwQ+QUmjvApkviLJYklcOPUxAY1qiRJd/CeUZUqmHWIUhSLncOA2gaVW8mn32NoT K6vpvs/ydtgNOrZOuqc8+ve5sDfB8HCA1kWNj8Nwibmbj98uh2ZSqjQdqf2H0iXCX9Rr VQq2oxBOMGn2SwI9tHZD1h2jP1je0L0YnFVLag/IkUk22QO/msSDGZdz5v1mvdBO452O IH/A== 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=Um0F/p/7qh/qbSNTjevD3M+MB0i7PsfZCWBI2Fgimww=; b=CbgCBHb5XpMRUg7yjpv6NAkrZM2WtGuSjK7b3MC1e3LcgKH6b6QjvvRkRLvRTkAoGd Rdi/SF06wDWHiylqAFLY46vVaDO9ZLwlo3sr0oFv6tOLhwFQujguSP54dsiTJLghK+Iz T98TnTl0pM27eQz6jU30VHSbej1iGujUSljL1QEn4CcYEtC2Mho4Xu7j/IfYTyT0hPkE hVHJPk4fGlrk/p67GW7hoKsg4280fcUMXTIZp4q/3Tb9tS+RcLy1Fu3Lnymi/pqTE14Q u7okmQEUQ2B5z8OmxU1s0A9/+XP2XvAiHeMis6Jp45LvqAVyTTccunSLK7NmuH3KBvQF 3zlQ== 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 bh7-v6si29469394plb.367.2018.07.16.04.11.19; Mon, 16 Jul 2018 04:11:33 -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 S1730531AbeGPLgl (ORCPT + 99 others); Mon, 16 Jul 2018 07:36:41 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57130 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730272AbeGPLgk (ORCPT ); Mon, 16 Jul 2018 07:36:40 -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 6C66E18A; Mon, 16 Jul 2018 04:09:46 -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 E23CD3F589; Mon, 16 Jul 2018 04:09:45 -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 v6 3/8] KVM: arm/arm64: Introduce helpers to manipulate page table entries Date: Mon, 16 Jul 2018 12:08:52 +0100 Message-Id: <20180716110857.19310-4-punit.agrawal@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180716110857.19310-1-punit.agrawal@arm.com> References: <20180716110857.19310-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 Reviewed-by: Suzuki K Poulose 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 ea3d992e4fb7..e131b7f9b7d7 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1554,8 +1554,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, (fault_status == FSC_PERM && stage2_is_exec(kvm, fault_ipa)); 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); @@ -1564,7 +1566,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