From patchwork Tue Nov 28 09:49:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 13470755 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 89442C4167B for ; Tue, 28 Nov 2023 09:51:24 +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=gTDyDm9YSOoye7WYLOcUMxNMV/B6Ij3TKEpC+royk98=; b=yDQwQZZodyo44u wW57I93UeZF7Ehw3zUm2WPSNU2K4Bog0NVCkK5eRZFyMvuguAMzvHiITWW6mxNZRUWMl5aHftFfcr kdgJYZhb/TDfy4muMp875u88OBttucExEUxMXEelpwTOvw2qgjVFZl8j3VIDdq3LeARzlAmiJ5I59 7lfcIJ6DEep5TDZQp5vl93b7mnT51g+HuwvRuicBJb9r+db3+nSmDciEJHFaWJStlssmoAc4LUAE+ vJ9R2ohA4kqLkFYJ31T3yxefYmAVNV/THRVWxppJwzPgW5pdRLl1UyBIWapscGWXh64HfbD+tZh/M 2/i3WYXTnt4P9CZyzYNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7uk8-004mrx-0J; Tue, 28 Nov 2023 09:51:00 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7uk2-004mpE-1E for linux-arm-kernel@lists.infradead.org; Tue, 28 Nov 2023 09:50:56 +0000 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sfd4D2Y9jz6JB75; Tue, 28 Nov 2023 17:50:36 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id A77DD1400C9; Tue, 28 Nov 2023 17:50:52 +0800 (CST) Received: from A2006125610.china.huawei.com (10.202.227.178) 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; Tue, 28 Nov 2023 09:50:45 +0000 From: Shameer Kolothum To: , CC: , , , , , , , , , , , Subject: [PATCH 5/5] iommu/arm-smmu-v3: Enforce dirty tracking in domain attach/alloc Date: Tue, 28 Nov 2023 09:49:40 +0000 Message-ID: <20231128094940.1344-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20231128094940.1344-1-shameerali.kolothum.thodi@huawei.com> References: <20231128094940.1344-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.178] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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-20231128_015054_700545_7D634716 X-CRM114-Status: GOOD ( 11.87 ) 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 From: Joao Martins SMMUv3 implements all requirements of revoking device attachment if smmu does not support dirty tracking. Finally handle the IOMMU_CAP_DIRTY in iommu_capable for IOMMUFD_DEVICE_GET_HW_INFO. Signed-off-by: Joao Martins Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 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 c5eabdc29ba5..2c100f2136bc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2244,6 +2244,8 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) case IOMMU_CAP_NOEXEC: case IOMMU_CAP_DEFERRED_FLUSH: return true; + case IOMMU_CAP_DIRTY_TRACKING: + return arm_smmu_dbm_capable(master->smmu); default: return false; } @@ -2701,6 +2703,9 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master = dev_iommu_priv_get(dev); smmu = master->smmu; + if (domain->dirty_ops && !arm_smmu_dbm_capable(smmu)) + return -EINVAL; + mutex_lock(&smmu_domain->init_mutex); if (!smmu_domain->smmu) { @@ -3077,7 +3082,9 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, const struct iommu_user_data *user_data) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); - const u32 paging_flags = IOMMU_HWPT_ALLOC_NEST_PARENT; + const u32 paging_flags = IOMMU_HWPT_ALLOC_NEST_PARENT | + IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + bool enforce_dirty = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING; struct arm_smmu_domain *smmu_domain; int ret; @@ -3090,6 +3097,10 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, if (user_data) return ERR_PTR(-EINVAL); + if (enforce_dirty && + !device_iommu_capable(dev, IOMMU_CAP_DIRTY_TRACKING)) + return ERR_PTR(-EOPNOTSUPP); + smmu_domain = arm_smmu_domain_alloc(); if (!smmu_domain) return ERR_PTR(-ENOMEM); @@ -3104,6 +3115,9 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED; smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops; + if (enforce_dirty) + smmu_domain->domain.dirty_ops = &arm_smmu_dirty_ops; + ret = arm_smmu_domain_finalise(smmu_domain, master->smmu); if (ret) goto err_free; @@ -4152,11 +4166,13 @@ static void arm_smmu_get_httu(struct arm_smmu_device *smmu, u32 reg) if (smmu->dev->of_node) smmu->features |= features; - else if (features != fw_features) + else if (features != fw_features) { /* ACPI IORT sets the HTTU bits */ dev_warn(smmu->dev, - "IDR0.HTTU overridden by FW configuration (0x%x)\n", + "IDR0.HTTU not overridden by FW configuration (0x%x)\n", fw_features); + smmu->features |= features; + } } static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu)