From patchwork Tue Aug 18 13:28:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11720865 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A33361392 for ; Tue, 18 Aug 2020 13:31:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79BF020738 for ; Tue, 18 Aug 2020 13:31:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UYX3ZwV1"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="QlNEHKq3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79BF020738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g4MiQDntYY5vSC7ODdqgYAW+QbThxkqtFJMdza4+cDU=; b=UYX3ZwV1oh0MnDEr4vExvLfdC WbaA8gK4UJ0xlvHpYipppp8nCUKjZ5zKIIViFIR2ut4XkPF0Mg7Twy2Q/D3bZ5z4dldQYp7NA8ibx YwYZ1dE+oYORU1yQHHxp0tEk1xwHJeVCW446QMYQt3ZShwhFOMXSoJNQxUiJNaLnCWx+wnYi/xs/I ESfIMkFlY94soOKGh8mYi1Ynhm6yDipaibbJQsputxMtwraDDxceXBbTrlRm5FPlxsOrUdkUkRajr IyQlxcgs1v+s7LJlzg6Vy27ku5Tdp3CVCLPASggTOSDUpBYehk5SCOngJRyRjnSU5tYDKfYdi1+8k 7ygFGr4mQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k81g9-00080t-89; Tue, 18 Aug 2020 13:29:29 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k81fR-0007jK-Q5 for linux-arm-kernel@lists.infradead.org; Tue, 18 Aug 2020 13:28:46 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC6212080C; Tue, 18 Aug 2020 13:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597757325; bh=ACqhtHGEaXcrBdy4vRFcQ2jhx5ymsCcPP2XZ8YuvUwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QlNEHKq3zB5kDS/UJLZts++zk6rD69VpT8pmRQ6RsYv6BL4M2yjHqzCYZuGbbZmwK DVDb5HjM2dWKv34cezDdA7zOFZp2ZGmZq6E1sMKcqpaAL4WGgWkx4Cw/oWigdjTkaY vq0R5UHuf68kXhvsLkb1oGqu/1deBDvxrtb+56Uk= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v2 08/22] KVM: arm64: Convert kvm_phys_addr_ioremap() to generic page-table API Date: Tue, 18 Aug 2020 14:28:04 +0100 Message-Id: <20200818132818.16065-9-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200818132818.16065-1-will@kernel.org> References: <20200818132818.16065-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200818_092846_003830_CF0BD1D5 X-CRM114-Status: GOOD ( 16.53 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-team@android.com, Suzuki Poulose , Marc Zyngier , Quentin Perret , James Morse , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Convert kvm_phys_addr_ioremap() to use kvm_pgtable_stage2_map() instead of stage2_set_pte(). Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/pgtable.c | 14 +------------- arch/arm64/kvm/mmu.c | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 41ee8f3c0369..6f65d3841ec9 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -439,18 +439,6 @@ struct stage2_map_data { struct kvm_mmu_memory_cache *memcache; }; -static kvm_pte_t *stage2_memcache_alloc_page(struct stage2_map_data *data) -{ - kvm_pte_t *ptep = NULL; - struct kvm_mmu_memory_cache *mc = data->memcache; - - /* Allocated with GFP_PGTABLE_USER, so no need to zero */ - if (mc && mc->nobjs) - ptep = mc->objects[--mc->nobjs]; - - return ptep; -} - static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot, struct stage2_map_data *data) { @@ -531,7 +519,7 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, if (WARN_ON(level == KVM_PGTABLE_MAX_LEVELS - 1)) return -EINVAL; - childp = stage2_memcache_alloc_page(data); + childp = kvm_mmu_memory_cache_alloc(data->memcache); if (!childp) return -ENOMEM; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index fdca6b69944b..d0c440e2622d 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1154,32 +1154,28 @@ static int stage2_pudp_test_and_clear_young(pud_t *pud) int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, phys_addr_t pa, unsigned long size, bool writable) { - phys_addr_t addr, end; + phys_addr_t addr; int ret = 0; - unsigned long pfn; struct kvm_mmu_memory_cache cache = { 0, __GFP_ZERO, NULL, }; + struct kvm_pgtable *pgt = kvm->arch.mmu.pgt; + enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_DEVICE | + KVM_PGTABLE_PROT_R | + (writable ? KVM_PGTABLE_PROT_W : 0); - end = (guest_ipa + size + PAGE_SIZE - 1) & PAGE_MASK; - pfn = __phys_to_pfn(pa); - - for (addr = guest_ipa; addr < end; addr += PAGE_SIZE) { - pte_t pte = kvm_pfn_pte(pfn, PAGE_S2_DEVICE); - - if (writable) - pte = kvm_s2pte_mkwrite(pte); - + for (addr = guest_ipa; addr < guest_ipa + size; addr += PAGE_SIZE) { ret = kvm_mmu_topup_memory_cache(&cache, kvm_mmu_cache_min_pages(kvm)); if (ret) break; + spin_lock(&kvm->mmu_lock); - ret = stage2_set_pte(&kvm->arch.mmu, &cache, addr, &pte, - KVM_S2PTE_FLAG_IS_IOMAP); + ret = kvm_pgtable_stage2_map(pgt, addr, PAGE_SIZE, pa, prot, + &cache); spin_unlock(&kvm->mmu_lock); if (ret) break; - pfn++; + pa += PAGE_SIZE; } return ret;