From patchwork Thu Feb 8 15:18:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 13549966 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 3537AC48260 for ; Thu, 8 Feb 2024 15:21:53 +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=LKoFdhWIrRR/LQ9kQTHfhi76LoiCmmwD/8dcsSksvp8=; b=gmmVw9MM0/FbBy VkW3qxHjecbWnC1fcME/XUh3Ik30A6hLy7Salh91UcX4AUg4vivJ8lIPR9G2nPBm4MiSeCunswvwW Yp2PKVcxlsbQ3DwRcUuVT72zKG5JycaBV7SEEXW21hJ9eTGjJShD9esvufqqSKNpSxSz+H59NkCP1 hJFHw/6AAXtOCTrjsEJvnvTJyco0h3VLnEbZ8HshfWaGpz1aIHehMmDQ199NY6bGZG8oe6c3vW8P0 0kIGIMweRT8Z2FU6lvD48GhHe1aVwjQ3KeFeNx39E4A+A5OyIPY5WwV7eXD+BWnp2f2aawgE+QYR3 RNPYeEcdLN6IG67BKCDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY6Db-0000000E9dB-1f3m; Thu, 08 Feb 2024 15:21:39 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY6DY-0000000E9bZ-0OWu for linux-arm-kernel@lists.infradead.org; Thu, 08 Feb 2024 15:21:37 +0000 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TW0wb3l9fz6JB4j; Thu, 8 Feb 2024 23:17:51 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 56D82140B2F; Thu, 8 Feb 2024 23:21:34 +0800 (CST) Received: from A2303104131.china.huawei.com (10.202.227.28) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 8 Feb 2024 15:21:27 +0000 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 6/7] iommu/arm-smmu-v3: Use KVM VMID for s2 stage Date: Thu, 8 Feb 2024 15:18:36 +0000 Message-ID: <20240208151837.35068-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com> References: <20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.28] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_072136_465021_F34118C2 X-CRM114-Status: GOOD ( 13.13 ) 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 If kvm is available make use of kvm pinned VMID interfaces to set the s2 stage VMID for nested domains. Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 18 +++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index b41d77787a2f..18e3e04b50f4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -2399,9 +2400,13 @@ int arm_smmu_domain_alloc_id(struct arm_smmu_device *smmu, } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S2) { int vmid; - /* Reserve VMID 0 for stage-2 bypass STEs */ - vmid = ida_alloc_range(&smmu->vmid_map, 1, - (1 << smmu->vmid_bits) - 1, GFP_KERNEL); + if (smmu_domain->kvm) { + vmid = kvm_pinned_vmid_get(smmu_domain->kvm); + } else { + /* Reserve VMID 0 for stage-2 bypass STEs */ + vmid = ida_alloc_range(&smmu->vmid_map, 1, + (1 << smmu->vmid_bits) - 1, GFP_KERNEL); + } if (vmid < 0) return vmid; smmu_domain->vmid = vmid; @@ -2431,7 +2436,10 @@ void arm_smmu_domain_free_id(struct arm_smmu_domain *smmu_domain) } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S2 && smmu_domain->vmid) { arm_smmu_tlb_inv_all_s2(smmu_domain); - ida_free(&smmu->vmid_map, smmu_domain->vmid); + if (smmu_domain->kvm) + kvm_pinned_vmid_put(smmu_domain->kvm); + else + ida_free(&smmu->vmid_map, smmu_domain->vmid); } } @@ -3217,7 +3225,7 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, goto err_free; } smmu_domain->stage = ARM_SMMU_DOMAIN_S2; - smmu_domain->nesting_parent = true; + smmu_domain->kvm = kvm; } smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 45bcd72fcda4..7d732ea2a6ee 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -758,6 +758,8 @@ struct arm_smmu_domain { struct mmu_notifier mmu_notifier; bool btm_invalidation : 1; bool nesting_parent : 1; + + struct kvm *kvm; }; struct arm_smmu_nested_domain {