Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2738298pxb; Tue, 13 Apr 2021 09:02:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDMScI6p2k045AE1BTY6B0htZmR5YWKc7EBleyedjsgKouv4zkHKvv78G++lQgGmb5Oobh X-Received: by 2002:a17:906:32da:: with SMTP id k26mr32804019ejk.483.1618329748755; Tue, 13 Apr 2021 09:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618329748; cv=none; d=google.com; s=arc-20160816; b=M0FguEAyc8pO0IkEhZanAihk7JjpCvAS2lNVxV0J/uhPCcWPLDysErfNAM+vdr4yl1 SpNDwdf3hPJIRV7NCEEhBKygGqkpFcH6dsCZRI5iKtClPQb2MFvn9hC8BLPQpVB9f5Oi 6TLOi8ysU5vdrVy+eH5qgct3YPq4BtfQNzdLZ/bqqucnZ0l8UhljmwxOKRFiyqZ2NGce JzmhyZ7yz0cw1gJDdjx+k/mdInFOaefr7vK+us9dBtjYZwHSJ4EHsCHgneMsDi3JE08L PaZ+fXMlZmSSSHgADC8qZpcbFFPLfNnR5AClR1iF0+7zkzwWi976OJAkTbX1SgkpAMwH 7P8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=OylTsk0m7c53/ZJn97+stU0rwiaLxLJZoWzTCxPwRuU=; b=ccIhGOxGsVE/H76cybN6uv46hawIVv7CrEHu5fRtmOal6XQrR3lmEYBqORMUBw4Jal XdkMZnUkFvzKT8YaImGcBX+bOF8KlkdWGdIsLRoD0HuYVjbbB6KM0EQ5PmHSNKLmcm6R fLln0wI7HvavktEeGi6IFbXXe4oEAVE6lwV2Zjvt/qksJ5mdhnru5mBlGlXVe3NZ4uuH lDfnxpNV/A8bWNyqdcT4RmziIy1Z/L9W0lr6HiJ4k4dCAmNpu7oXdWnPCFBpq3e/3p3K Xrj47oC7sFbAmPPtR7e5OF41wm9sz6dOse64pieaAy1MgJLbkAS7azVgbV6WLSWTBFCf Z5tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si10397168ejj.228.2021.04.13.09.02.04; Tue, 13 Apr 2021 09:02:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244872AbhDMI4M (ORCPT + 99 others); Tue, 13 Apr 2021 04:56:12 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:16546 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244156AbhDMIzn (ORCPT ); Tue, 13 Apr 2021 04:55:43 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FKK9q0617zPqkh; Tue, 13 Apr 2021 16:52:31 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.224) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 16:55:14 +0800 From: Keqian Zhu To: , , , Robin Murphy , "Will Deacon" , Joerg Roedel , Yi Sun , Jean-Philippe Brucker , Jonathan Cameron , Tian Kevin , Lu Baolu CC: Alex Williamson , Cornelia Huck , Kirti Wankhede , , , , Subject: [PATCH v3 09/12] iommu/arm-smmu-v3: Realize switch_dirty_log iommu ops Date: Tue, 13 Apr 2021 16:54:54 +0800 Message-ID: <20210413085457.25400-10-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210413085457.25400-1-zhukeqian1@huawei.com> References: <20210413085457.25400-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.224] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kunkun Jiang This realizes switch_dirty_log by invoking iommu_split_block() and iommu_merge_page(). HTTU HD feature is required. Co-developed-by: Keqian Zhu Signed-off-by: Kunkun Jiang --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) 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 4d8495d88be2..52c6f3e74d6f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2590,6 +2590,43 @@ static int arm_smmu_merge_page(struct iommu_domain *domain, return 0; } +static int arm_smmu_switch_dirty_log(struct iommu_domain *domain, bool enable, + unsigned long iova, size_t size, int prot) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_device *smmu = smmu_domain->smmu; + + if (!(smmu->features & ARM_SMMU_FEAT_HD)) + return -ENODEV; + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) + return -EINVAL; + + if (enable) { + /* + * For SMMU, the hardware dirty management is always enabled if + * hardware supports HTTU HD. The action to start dirty log is + * spliting block mapping. + * + * We don't return error even if the split operation fail, as we + * can still track dirty at block granule, which is still a much + * better choice compared to full dirty policy. + */ + iommu_split_block(domain, iova, size); + } else { + /* + * For SMMU, the hardware dirty management is always enabled if + * hardware supports HTTU HD. The action to start dirty log is + * merging page mapping. + * + * We don't return error even if the merge operation fail, as it + * just effects performace of DMA transaction. + */ + iommu_merge_page(domain, iova, size, prot); + } + + return 0; +} + static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args) { return iommu_fwspec_add_ids(dev, args->args, 1); @@ -2691,6 +2728,7 @@ static struct iommu_ops arm_smmu_ops = { .domain_set_attr = arm_smmu_domain_set_attr, .split_block = arm_smmu_split_block, .merge_page = arm_smmu_merge_page, + .switch_dirty_log = arm_smmu_switch_dirty_log, .of_xlate = arm_smmu_of_xlate, .get_resv_regions = arm_smmu_get_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions, -- 2.19.1