Received: by 10.192.165.148 with SMTP id m20csp582347imm; Fri, 27 Apr 2018 04:15:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo09V3X6IeUnpPpxjiAr71tLAxxGe9jzJtX3v+CKyeKRFro5IGLvZE2U9LTsFji0CDTq6MK X-Received: by 10.98.144.85 with SMTP id a82mr1874290pfe.14.1524827755057; Fri, 27 Apr 2018 04:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524827755; cv=none; d=google.com; s=arc-20160816; b=TdihcD2A22VhhHbYAS/+YEmbxoTo32e0x67jC9ELw+D+p3VxXRG1Q9PqYjkJ6dc30m ZRqK97u+OLbgmjPFrFAcpA8p1MvspbjccsBQ9GDWhkAHLJavUuQSL9vDHiWXz0NF5Qeh bkbloRkfd+J6/UCpzPl9YxfblSm/6JBFh8zNC7efrVtD/UdzVP3bMRtXGpwTqDLGF229 20oKZZnuuFK4+zUnS78YbHpCwUbo9mPEfyLGaqUBEbWibP8LSVhVAkfAnevC9U2yaG6G 93EUNNXEYAxDC6cCEsHf1nrB8AdznggkkLgG2uLQIf0J0J16+33wk4Nltll3VFTwzntI b82Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=FHIqau0PM8VnQ32VMUU9QLkUP9QWEkmH0rG0xqP0mgg=; b=N7ov6tqmN6QjreX+DZDeXsDgMGVNPhkvkqnEfmfuI5dKR1ueGtEqeapb0OozQaT+xW xZJZnkWYFHKuMIbj7JA7GQz78IrE8sVCSykhgqdkWq9GtErl8XYLVcFw0plTpuDbuAcL EyG/AtaPkPXYR8m0H+pH4JxTP6l6uZCODNZcklthX0eiDqNeAYsHaLYYMlRjXj9iCW88 QRWcCCEY7vPNCC1V7EAgauv+wPPxptMyFDFvu2yOn5HnA3lvbtGDIbNiI2chLf4odJVd l7lARk+RhefWxshb9AE+o4wDXslsLEJce/pIHxj46AtSY/DNeoUsH30NlEbg6fi2ZNp9 kJcw== 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 v25si1064548pff.217.2018.04.27.04.15.39; Fri, 27 Apr 2018 04:15:55 -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 S1757312AbeD0LOg (ORCPT + 99 others); Fri, 27 Apr 2018 07:14:36 -0400 Received: from foss.arm.com ([217.140.101.70]:38634 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbeD0LOd (ORCPT ); Fri, 27 Apr 2018 07:14: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 2C643165D; Fri, 27 Apr 2018 04:14:33 -0700 (PDT) Received: from localhost (unknown [10.37.9.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8E2053F4FF; Fri, 27 Apr 2018 04:14:32 -0700 (PDT) Date: Fri, 27 Apr 2018 13:14:29 +0200 From: Christoffer Dall To: Punit Agrawal Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, marc.zyngier@arm.com, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com Subject: Re: [PATCH 1/4] KVM: arm/arm64: Share common code in user_mem_abort() Message-ID: <20180427111429.GL13249@C02W217FHV2R.local> References: <20180420145409.24485-1-punit.agrawal@arm.com> <20180420145409.24485-2-punit.agrawal@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180420145409.24485-2-punit.agrawal@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 20, 2018 at 03:54:06PM +0100, Punit Agrawal wrote: > The code for operations such as marking the pfn as dirty, and > dcache/icache maintenance during stage 2 fault handling is duplicated > between normal pages and PMD hugepages. > > Instead of creating another copy of the operations when we introduce > PUD hugepages, let's share them across the different pagesizes. > > Signed-off-by: Punit Agrawal > Cc: Christoffer Dall > Cc: Marc Zyngier > --- > virt/kvm/arm/mmu.c | 36 +++++++++++++++++++++--------------- > 1 file changed, 21 insertions(+), 15 deletions(-) > > diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c > index 7f6a944db23d..db382c7c7cd7 100644 > --- a/virt/kvm/arm/mmu.c > +++ b/virt/kvm/arm/mmu.c > @@ -1428,7 +1428,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > kvm_pfn_t pfn; > pgprot_t mem_type = PAGE_S2; > bool logging_active = memslot_is_logging(memslot); > - unsigned long flags = 0; > + unsigned long vma_pagesize, flags = 0; > > write_fault = kvm_is_write_fault(vcpu); > exec_fault = kvm_vcpu_trap_is_iabt(vcpu); > @@ -1448,7 +1448,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > return -EFAULT; > } > > - if (vma_kernel_pagesize(vma) == PMD_SIZE && !logging_active) { > + vma_pagesize = vma_kernel_pagesize(vma); > + if (vma_pagesize == PMD_SIZE && !logging_active) { > hugetlb = true; > gfn = (fault_ipa & PMD_MASK) >> PAGE_SHIFT; > } else { > @@ -1517,23 +1518,33 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > if (mmu_notifier_retry(kvm, mmu_seq)) > goto out_unlock; > > - if (!hugetlb && !force_pte) > + if (!hugetlb && !force_pte) { > + /* > + * Only PMD_SIZE transparent hugepages(THP) are > + * currently supported. This code will need to be > + * updated if other THP sizes are supported. > + */ > hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa); > + vma_pagesize = PMD_SIZE; > + } > + > + if (writable) > + kvm_set_pfn_dirty(pfn); > + > + if (fault_status != FSC_PERM) > + clean_dcache_guest_page(pfn, vma_pagesize); > + > + if (exec_fault) > + invalidate_icache_guest_page(pfn, vma_pagesize); > > if (hugetlb) { > pmd_t new_pmd = pfn_pmd(pfn, mem_type); > new_pmd = pmd_mkhuge(new_pmd); > - if (writable) { > + if (writable) > new_pmd = kvm_s2pmd_mkwrite(new_pmd); > - kvm_set_pfn_dirty(pfn); > - } > - > - if (fault_status != FSC_PERM) > - clean_dcache_guest_page(pfn, PMD_SIZE); > > if (exec_fault) { > new_pmd = kvm_s2pmd_mkexec(new_pmd); > - invalidate_icache_guest_page(pfn, PMD_SIZE); > } else if (fault_status == FSC_PERM) { This could now be rewritten to: if (exec_fault || (fault_status == FSC_PERM && stage2_is_exec(kvm, fault_ipa))) new_pmd = kvm_s2pmd_mkexec(new_pmd); which we could even consider making static bool stage2_should_exec(struct kvm *kvm, phys_addr_t addr, bool exec_fault, unsigned long fault_status) { /* * If we took an execution fault we will have made the * icache/dcache coherent and should now let the s2 mapping be * executable. * * Write faults (!exec_fault && FSC_PERM) are orthogonal to * execute permissions, and we preserve whatever we have. */ return exec_fault || (fault_status == FSC_PERM && stage2_is_exec(kvm, fault_ipa)); } The benefit would be to have this documentation in a single place and slightly simply both the hugetlb and !hugetlb blocks. > /* Preserve execute if XN was already cleared */ > if (stage2_is_exec(kvm, fault_ipa)) > @@ -1546,16 +1557,11 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > > if (writable) { > new_pte = kvm_s2pte_mkwrite(new_pte); > - kvm_set_pfn_dirty(pfn); > mark_page_dirty(kvm, gfn); > } > > - if (fault_status != FSC_PERM) > - clean_dcache_guest_page(pfn, PAGE_SIZE); > - > if (exec_fault) { > new_pte = kvm_s2pte_mkexec(new_pte); > - invalidate_icache_guest_page(pfn, PAGE_SIZE); > } else if (fault_status == FSC_PERM) { > /* Preserve execute if XN was already cleared */ > if (stage2_is_exec(kvm, fault_ipa)) > -- > 2.17.0 > Notwithstanding my suggestion above: Reviewed-by: Christoffer Dall