From patchwork Wed Nov 17 15:38:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12692940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5384C433EF for ; Wed, 17 Nov 2021 15:42:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 996B6613A9 for ; Wed, 17 Nov 2021 15:42:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 996B6613A9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type: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:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j0cnzMC1M+JVMroJ6gKY9sDJBNIq3Gk2EM4Lmp6cu/A=; b=etnwy8WatRWZBg 6cP7b4ON/MPDDBKL+Vs0qyaNrXERMTr2/oibrh8pEscvOVQHVLrat9bgZm98oFjIIBxRk/nBE3fkE XYKWrTLuIqjCoPfxQHkVpP9lOy3KiTsYH1RykRe5Zu0o+/Xlqvv7r7Y05NLBAq/zyGYNWcDZFkzNK LBCuk1aEuei25Fd6MI4Ba/VW91CtaLu8JkIILUJPotLSv4SrmfMSyRyHo6s62HR6POXza6uTBrF4f 2AW+mDuqjMzYyBHenJmuQdP4ZPD+vMjj8gR3q6PI5tUuq4MxaqvV+nz1gF5XskE/9d6FT702+RmMO iywZ4FTE2jd6MPe98NeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnN3A-005RSu-TR; Wed, 17 Nov 2021 15:40:41 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnMzs-005Pxb-Sf for linux-arm-kernel@lists.infradead.org; Wed, 17 Nov 2021 15:37:18 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6E0151FB; Wed, 17 Nov 2021 07:37:16 -0800 (PST) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 247EC3F5A1; Wed, 17 Nov 2021 07:37:15 -0800 (PST) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, mark.rutland@arm.com Subject: [RFC PATCH v5 08/38] KVM: arm64: Unlock memslots after stage 2 tables are freed Date: Wed, 17 Nov 2021 15:38:12 +0000 Message-Id: <20211117153842.302159-9-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211117153842.302159-1-alexandru.elisei@arm.com> References: <20211117153842.302159-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211117_073717_007075_A49BBCF5 X-CRM114-Status: UNSURE ( 9.82 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Unpin the backing pages mapped at stage 2 after the stage 2 translation tables are destroyed. Signed-off-by: Alexandru Elisei --- arch/arm64/kvm/mmu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index cd6f1bc7842d..072e2aba371f 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1627,11 +1627,19 @@ int kvm_mmu_lock_memslot(struct kvm *kvm, u64 slot, u64 flags) return ret; } -static void unlock_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) +static void __unlock_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) { bool writable = memslot->arch.flags & KVM_MEMSLOT_LOCK_WRITE; unsigned long npages = memslot->npages; + unpin_memslot_pages(memslot, writable); + account_locked_vm(current->mm, npages, false); + + memslot->arch.flags &= ~KVM_MEMSLOT_LOCK_MASK; +} + +static void unlock_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) +{ /* * MMU maintenace operations aren't performed on an unlocked memslot. * Unmap it from stage 2 so the abort handler performs the necessary @@ -1640,10 +1648,7 @@ static void unlock_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) if (kvm_mmu_has_pending_ops(kvm)) kvm_arch_flush_shadow_memslot(kvm, memslot); - unpin_memslot_pages(memslot, writable); - account_locked_vm(current->mm, npages, false); - - memslot->arch.flags &= ~KVM_MEMSLOT_LOCK_MASK; + __unlock_memslot(kvm, memslot); } int kvm_mmu_unlock_memslot(struct kvm *kvm, u64 slot, u64 flags) @@ -1951,7 +1956,15 @@ void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) void kvm_arch_flush_shadow_all(struct kvm *kvm) { + struct kvm_memory_slot *memslot; + kvm_free_stage2_pgd(&kvm->arch.mmu); + + kvm_for_each_memslot(memslot, kvm_memslots(kvm)) { + if (!memslot_is_locked(memslot)) + continue; + __unlock_memslot(kvm, memslot); + } } void kvm_arch_flush_shadow_memslot(struct kvm *kvm,