Received: by 10.192.165.148 with SMTP id m20csp778460imm; Fri, 27 Apr 2018 07:23:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZriqfEv0XN7EBYRmujFoH5kFl8YHPmRaAm1qHKsGIU4/XrN8guXVofNHS5C9D8VoeQw9Lxc X-Received: by 2002:a65:5d8e:: with SMTP id f14-v6mr2361159pgt.25.1524838998124; Fri, 27 Apr 2018 07:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524838998; cv=none; d=google.com; s=arc-20160816; b=aYNYh3sS1HrkEoJpxTvpSh0Lmtd3ZpT5ed+soeQVlU25pgnd6yPQ6uqwlbGVX5DqWK DgV1WbctZATYlxofImu7hO/u+Z6f6W0BbrIHwh5hfqwCpUGSBf4LvJ8xxhvoBYavvEe2 XA1628SCra/YpSwIBIpNQxxaCqq6XKqVS1zpg+uPuaIAR7ZLR+oeqfwfZXErp9grn4S1 cL7KD0PzyZLk98+K7g2nmqdDaIiwf8BrVoDfs2cgjCPyE+ZvJApi+yVnjSPSsm0H4Jag 0YWnFPso1nHp8JIT+fR3G5cmawX//26ZIVhbD7Kn2Um+VDBwDP2vQ1y3hs36UehEDvEE 56SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=cBdjRa9r3sMy2KJfuhuHB+uHYJiRcvIL4n1yxQuE2NE=; b=GO1QUXBKBBcCXaZ2MKhcy7fYjULVmPEFS8k2rMTvLH/ykGIyQtcKym/3nobbe/9nsW tD7IjMGhuKUWboUyfAtKxlyC+9p763lbswp9aKkfCGr83+8mX2lNcan3b9lCths4lWpP 4/oEyOdiJbCDh6PfI3zlOo5pis0pQmlgeFDW8JlODagey3kIeEu3PeODNiGejKv0uvTH wvM+rLZZx/ib9O+dh6QsqfaTCI7nnQdQZd4IeVUQ5ZVv7JU+V9vw6z5jdFnrNViU+ukZ e1XLTDZexMzgoxnC/I+5pU4b9vugJF65TdqcRQCrxvDDu89Op+f6VAdo64sQ7gvdCUOR umUA== 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 b65-v6si1328375plb.162.2018.04.27.07.23.04; Fri, 27 Apr 2018 07:23:18 -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 S935376AbeD0OV3 (ORCPT + 99 others); Fri, 27 Apr 2018 10:21:29 -0400 Received: from foss.arm.com ([217.140.101.70]:40890 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934990AbeD0OV0 (ORCPT ); Fri, 27 Apr 2018 10:21:26 -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 A35181529; Fri, 27 Apr 2018 07:21:25 -0700 (PDT) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.207.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3EE6C3F4FF; Fri, 27 Apr 2018 07:21:25 -0700 (PDT) From: Punit Agrawal To: Christoffer Dall 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() References: <20180420145409.24485-1-punit.agrawal@arm.com> <20180420145409.24485-2-punit.agrawal@arm.com> <20180427111429.GL13249@C02W217FHV2R.local> Date: Fri, 27 Apr 2018 15:21:23 +0100 In-Reply-To: <20180427111429.GL13249@C02W217FHV2R.local> (Christoffer Dall's message of "Fri, 27 Apr 2018 13:14:29 +0200") Message-ID: <87bme4zq58.fsf@e105922-lin.cambridge.arm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christoffer Dall writes: > 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. Makes sense. And saves another copy when we introduce PUD handling in a latter patch. I've rolled this in with minor changes. > > >> /* 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 Thanks, Punit