Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp643908imm; Wed, 11 Jul 2018 08:34:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd+P80670sFR6a+7kyIQ+5gljaqgS+8sIhLPFYBLqD1msJXHnVeq4H6Ua3CzMRyMbjhYz1M X-Received: by 2002:a63:1722:: with SMTP id x34-v6mr27353193pgl.268.1531323248320; Wed, 11 Jul 2018 08:34:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531323248; cv=none; d=google.com; s=arc-20160816; b=QrqjIv4YzQDH9bXKXsejJbyAifS0HgMER4IkMdF5Cr5gI/tMw+vV0uaR6cPOcFDbO1 TDtmuc0V9qsVW+LWxSlDnD6dVoEZOKWuUNKfotTFxjRa0FzVHSj3+H0BTZCQ65Bno7DQ n6wmM6kJi40T10WWc1LIRwcGkEOhtSxg4jLvwevkXkPClmvoPyLNltrg7JzfkRF4XFiM LRSKXE8B2PPXKFrKvjyD+l/MuXBiOR4IEVf0Jks81FdjmkAnkhdZ2TUIWvj0dvxKRF37 XyHJRdU+SdmxEhiI6fw2BJbyyxCCqHkhWkMH12+2jojoIlRuiAG5DNNIEkeUe2zsVYy4 KPwg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=0egWo/6q/+13hPTozJHd45Qzi8nShNOZp2KkVE5GSl4=; b=qzNDTGYFNJuybfurByD2Xw/i9n3yxz2phZ42tS9M83bVJ1IBfLz7MLsNx9825mREZZ jEVj/o0z6N2PwOWxATENlIinDfVqZrmfeYlyo5cNEm5hq49pTIttK1n295XItYT/zUHU 1PgYcEMdC1SfUFixJ1BKeK/hyZL9tt3xlc145dRyVI6bg3u29GrR5hwZ7y49C01rCppO zhpiIeDAud/g6iSJv9Bz+PZiLzP4yfLdu2iHEaxmWx5U+oaA/z32jAeu7VPFlup6l3Io iCDYfa+HTDOcSP1qa74Cujz6sRGy7CPkJlyJCYoP+E5yPCN2RSK0MIDwxXEJUSQFODJY SwDQ== 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 m32-v6si1034187pld.99.2018.07.11.08.33.52; Wed, 11 Jul 2018 08:34:08 -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 S2387752AbeGKNVT (ORCPT + 99 others); Wed, 11 Jul 2018 09:21:19 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:35594 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732311AbeGKNVT (ORCPT ); Wed, 11 Jul 2018 09:21:19 -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 C52EE7A9; Wed, 11 Jul 2018 06:17:00 -0700 (PDT) Received: from [10.1.206.73] (en101.cambridge.arm.com [10.1.206.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3F4E53F5AD; Wed, 11 Jul 2018 06:16:59 -0700 (PDT) Subject: Re: [PATCH v5 5/7] KVM: arm64: Support handling access faults for PUD hugepages To: Punit Agrawal , kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, marc.zyngier@arm.com, christoffer.dall@arm.com, linux-kernel@vger.kernel.org, will.deacon@arm.com, Russell King , Catalin Marinas References: <20180709143835.28971-1-punit.agrawal@arm.com> <20180709144124.29164-1-punit.agrawal@arm.com> <20180709144124.29164-5-punit.agrawal@arm.com> From: Suzuki K Poulose Message-ID: Date: Wed, 11 Jul 2018 14:16:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180709144124.29164-5-punit.agrawal@arm.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/07/18 15:41, Punit Agrawal wrote: > In preparation for creating larger hugepages at Stage 2, extend the > access fault handling at Stage 2 to support PUD hugepages when > encountered. > > Provide trivial helpers for arm32 to allow sharing of 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 | 8 ++++++++ > arch/arm64/include/asm/kvm_mmu.h | 7 +++++++ > arch/arm64/include/asm/pgtable.h | 6 ++++++ > virt/kvm/arm/mmu.c | 29 ++++++++++++++++------------- > 4 files changed, 37 insertions(+), 13 deletions(-) > > diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h > index d05c8986e495..a4298d429efc 100644 > --- a/arch/arm/include/asm/kvm_mmu.h > +++ b/arch/arm/include/asm/kvm_mmu.h > @@ -78,6 +78,8 @@ 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_pud_pfn(pud) (((pud_val(pud) & PUD_MASK) & PHYS_MASK) >> PAGE_SHIFT) Since we don't have PUD in arm32, it would be good to trigger a BUG() instead of silently doing something wrong. > @@ -102,6 +104,12 @@ static inline bool kvm_s2pud_exec(pud_t *pud) > return false; > } > > +static inline pud_t kvm_s2pud_mkyoung(pud_t pud) > +{ > + BUG(); > + return pud; > +} > + Like this. ^ > diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c > index e73909a31e02..d2c705e31584 100644 > --- a/virt/kvm/arm/mmu.c > +++ b/virt/kvm/arm/mmu.c > @@ -1637,33 +1637,36 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > */ > static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) > { > - pmd_t *pmd; > - pte_t *pte; > + pud_t *pud = NULL; > + pmd_t *pmd = NULL; > + pte_t *pte = NULL; > kvm_pfn_t pfn; > - bool pfn_valid = false; > + bool found, pfn_valid = false; nit: You could use pfn_valid instead of a new "found" variable. > > trace_kvm_access_fault(fault_ipa); > > spin_lock(&vcpu->kvm->mmu_lock); > > - pmd = stage2_get_pmd(vcpu->kvm, NULL, fault_ipa); > - if (!pmd || pmd_none(*pmd)) /* Nothing there */ > + found = stage2_get_leaf_entry(vcpu->kvm, fault_ipa, &pud, &pmd, &pte); > + if (!found) > goto out; > > - if (pmd_thp_or_huge(*pmd)) { /* THP, HugeTLB */ > + if (pud) { /* HugeTLB */ > + *pud = kvm_s2pud_mkyoung(*pud); > + pfn = kvm_pud_pfn(*pud); > + pfn_valid = true; > + goto out; You don't need these goto's and the out lable anymore. > + } else if (pmd) { /* THP, HugeTLB */ > *pmd = pmd_mkyoung(*pmd); > pfn = pmd_pfn(*pmd); > pfn_valid = true; > goto out; > + } else { > + *pte = pte_mkyoung(*pte); /* Just a page... */ > + pfn = pte_pfn(*pte); > + pfn_valid = true; > } > > - pte = pte_offset_kernel(pmd, fault_ipa); > - if (pte_none(*pte)) /* Nothing there either */ > - goto out; > - > - *pte = pte_mkyoung(*pte); /* Just a page... */ > - pfn = pte_pfn(*pte); > - pfn_valid = true; > out: > spin_unlock(&vcpu->kvm->mmu_lock); > if (pfn_valid) > Otherwise look good to me. Suzuki