From patchwork Wed Feb 1 12:52:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 13124381 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8CA55C636CD for ; Wed, 1 Feb 2023 14:04:20 +0000 (UTC) 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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0jrb3PA0Z7d9onYui07EBkWRqOGV6i6CQWoZLGslras=; b=qiNSS96bt3xRWQ QYdOPgj5AKws3dS8breoexWvNOo5jepMZl3fKTcbJx8RIAsC5F1Xss2CeDOuQv1+yyumzFz7jd/vQ Ds1+WvWnxTd4LOGBfnjiJurzcjKekPk7dOdTWpyT+Dfq84HjI8iMsQldKOr1n+Ct55PxixnEo9xZ0 Syp/QOCe7xgsib4+r44fYz73MmK+itqE4s4FZoDUUzYTTZGsw4mfXh78xHlt/iTUlSz+/pNZwLaim Ussy3tW8YtRyYSR1+lvxmXsNOVE561kUZBBNlo/0qqI7AkHqrzyoYRe4RO/N3cd5ZWygzjBQu79FR cuJhC97OHGYE7gTAjvQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNDi0-00CBwU-Qi; Wed, 01 Feb 2023 14:03:33 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNCi2-00BnIT-E7 for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 12:59:35 +0000 Received: by mail-wr1-x42d.google.com with SMTP id bk16so17209936wrb.11 for ; Wed, 01 Feb 2023 04:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JL+q7powKXjRQBM9aUxd/Ixujr3/xsGD0eW5qeS08kg=; b=XvIuhKnbdaSJmJH8iDjgXLwNO9bmY/agjJa9GYHK5fvNc0rbxK9E8+MePeO1hYYVkj BLoKe4FnYGZ+IcTOkZe7A/26QsSpzsLPFCxLtdFiID61kSy1LAZHhSepPc/I0WjajANX zqcV2727uc8XO/ZvNCcb3Dwjpmq+TZk1Mq07dsMCgGcMTplN5QoiX9TyV73FJGwuWPl5 VVfuWMPqHgHHXae2ZU0wPy/5nRKQ4LHuLzsStjXWsObRhMnAWkK+9/ljtH6QUPqObP0o 1KVNZv0lWLfSW5q9HV60q+XYtLC9dKPNWlqVRI8Ylf60E6JZU9bJG0pBGfBHyapeYBxY IujA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JL+q7powKXjRQBM9aUxd/Ixujr3/xsGD0eW5qeS08kg=; b=P/yiMDUhKzp18Vq3P1HHLiKRYEWUnTgSLVGp9ojfkbMOfwnF+5sJnQWk24QGJ83GWi /keCbBVRUs2ESwF9GQy4gEGA82rB4lImnCt8E+pN2JRvX7AIOTV/CJ3bx6Hax97vRzss WESouzIwFBB+GY8qZAvETjWPpZuLvu/Ry7IlwKsFa0aIf3R6EIjkHxBA281eHsDeIlgm 4B9MixX8MQc8Mk5OUyAE3TAZcdAgHd98i9rcIlLyyLucO0SgVYQJpR+fqFUfjBvNO1KJ Zh3n0s0bwsEkwBXA8jiSZwy6dAUCbO6H3doyIndTBZ1Kp3rs9N3IGSlfq18TuRPPpySo lXDw== X-Gm-Message-State: AO0yUKVPYLO7gLpDk4442P6j9kQ3RRuxcVb8hvysk4DdF2tail4mZJKR 4c7eNKb3Zpm9pAJcKtrazRdbpw== X-Google-Smtp-Source: AK7set/b2J59uvwFQEz7jZcXjC6ArgctU3mXzzUT7UxY8LgLmGH7l73VT4ZIMiNBTG1OX7/4xi4JWw== X-Received: by 2002:a05:6000:188f:b0:2bf:cb6a:a7e with SMTP id a15-20020a056000188f00b002bfcb6a0a7emr2957190wri.42.1675256367258; Wed, 01 Feb 2023 04:59:27 -0800 (PST) Received: from localhost.localdomain (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id m15-20020a056000024f00b002bfae16ee2fsm17972811wrz.111.2023.02.01.04.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 04:59:26 -0800 (PST) From: Jean-Philippe Brucker To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, joro@8bytes.org Cc: robin.murphy@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, smostafa@google.com, dbrazdil@google.com, ryan.roberts@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, Jean-Philippe Brucker Subject: [RFC PATCH 10/45] KVM: arm64: pkvm: Expose pkvm_map/unmap_donated_memory() Date: Wed, 1 Feb 2023 12:52:54 +0000 Message-Id: <20230201125328.2186498-11-jean-philippe@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230201125328.2186498-1-jean-philippe@linaro.org> References: <20230201125328.2186498-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_045930_536828_E7289A6F X-CRM114-Status: GOOD ( 12.23 ) 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 Allow the IOMMU driver to use pkvm_map/unmap_donated memory() Signed-off-by: Jean-Philippe Brucker --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 3 +++ arch/arm64/kvm/hyp/nvhe/pkvm.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index 38e5e9b259fc..40decbe4cc70 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -86,6 +86,9 @@ void reclaim_guest_pages(struct pkvm_hyp_vm *vm, struct kvm_hyp_memcache *mc); int refill_memcache(struct kvm_hyp_memcache *mc, unsigned long min_pages, struct kvm_hyp_memcache *host_mc); +void *pkvm_map_donated_memory(unsigned long host_va, size_t size); +void pkvm_unmap_donated_memory(void *va, size_t size); + static __always_inline void __load_host_stage2(void) { if (static_branch_likely(&kvm_protected_mode_initialized)) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 905c05c7e9bf..a3711979bbd3 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -592,7 +592,7 @@ static void *map_donated_memory_noclear(unsigned long host_va, size_t size) return va; } -static void *map_donated_memory(unsigned long host_va, size_t size) +void *pkvm_map_donated_memory(unsigned long host_va, size_t size) { void *va = map_donated_memory_noclear(host_va, size); @@ -608,7 +608,7 @@ static void __unmap_donated_memory(void *va, size_t size) PAGE_ALIGN(size) >> PAGE_SHIFT)); } -static void unmap_donated_memory(void *va, size_t size) +void pkvm_unmap_donated_memory(void *va, size_t size) { if (!va) return; @@ -668,11 +668,11 @@ int __pkvm_init_vm(struct kvm *host_kvm, unsigned long vm_hva, ret = -ENOMEM; - hyp_vm = map_donated_memory(vm_hva, vm_size); + hyp_vm = pkvm_map_donated_memory(vm_hva, vm_size); if (!hyp_vm) goto err_remove_mappings; - last_ran = map_donated_memory(last_ran_hva, last_ran_size); + last_ran = pkvm_map_donated_memory(last_ran_hva, last_ran_size); if (!last_ran) goto err_remove_mappings; @@ -699,9 +699,9 @@ int __pkvm_init_vm(struct kvm *host_kvm, unsigned long vm_hva, err_unlock: hyp_spin_unlock(&vm_table_lock); err_remove_mappings: - unmap_donated_memory(hyp_vm, vm_size); - unmap_donated_memory(last_ran, last_ran_size); - unmap_donated_memory(pgd, pgd_size); + pkvm_unmap_donated_memory(hyp_vm, vm_size); + pkvm_unmap_donated_memory(last_ran, last_ran_size); + pkvm_unmap_donated_memory(pgd, pgd_size); err_unpin_kvm: hyp_unpin_shared_mem(host_kvm, host_kvm + 1); return ret; @@ -726,7 +726,7 @@ int __pkvm_init_vcpu(pkvm_handle_t handle, struct kvm_vcpu *host_vcpu, unsigned int idx; int ret; - hyp_vcpu = map_donated_memory(vcpu_hva, sizeof(*hyp_vcpu)); + hyp_vcpu = pkvm_map_donated_memory(vcpu_hva, sizeof(*hyp_vcpu)); if (!hyp_vcpu) return -ENOMEM; @@ -754,7 +754,7 @@ int __pkvm_init_vcpu(pkvm_handle_t handle, struct kvm_vcpu *host_vcpu, hyp_spin_unlock(&vm_table_lock); if (ret) - unmap_donated_memory(hyp_vcpu, sizeof(*hyp_vcpu)); + pkvm_unmap_donated_memory(hyp_vcpu, sizeof(*hyp_vcpu)); return ret; }