From patchwork Mon May 10 14:17:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433152 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895859jao; Mon, 10 May 2021 07:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ98fiAZpEf5vfXmkXqo6PFLSocid2eNVyA57CmM90l/ICzX9FNDyaT8s4EAdlVnO0L4K7 X-Received: by 2002:a02:c98a:: with SMTP id b10mr21987436jap.103.1620656787658; Mon, 10 May 2021 07:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656787; cv=none; d=google.com; s=arc-20160816; b=SL/KT7RhsRk/sUovwwkBlmjb8oSan0eK3US/mPBlOHm99KEUTteJSaEDbSrjIJ2drN BlgjTT3audeIzoQTqraQ9w/jYLWHLl3PSmK2Z/WGMGvh18EyR9X5tXUkjrFmq9zQ9u6G uQowKJ7JXwLCJDdjbpxGJTKHPFDdMdu3/OOOetLmbN2V4+nuWjh8I0dtOfjNoWACm/T2 xJd02zMGhmun6u7kxczKb0OsjsnqQfxMejcHZT6YxLAKEzmDCazIGxdVcM6TnPceT/m3 WLimXZapalmnHQL5cZ+hQUQzESNgY0u1LBNE7yfZWakItxmuhO7QC5T4peFgyaFV9NAP BnVA== 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=YtVsHa0yfZheRmVM3+/Q2d3OzhUuveI8U36N59XcsF8=; b=RWhArXEYghQhVzSFbKbRozcTXDqu1WBFkftJirEBKfYgTEBCU0J0tFs0JtTsN5XO3z DOXKHmokLDKiAvEGNNGrF3MRVXdwQ7JB8Iblp4uyrOZzVdAfVk5VDfJaNsm7vKgngWkF V7A5rvitPSB8Lla1i08R6vxYI/yMOuXe4ESdHiU/Iye+rbwYlgh2tvFr2q5ea6oUe8rI XHYUUPoNKf9GRDEnDulAOPuahQyRNt658xnvscYed0hnJH0vCX1QOu1UuEVxt4eiVabu mo0kG4kwmveYIB7oPTWvg9S1eBCuI9XM7sREkX17BDbeqPmNaTx0ioNfYaCAuInjwPxj xwSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-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 a13si13610863ilr.121.2021.05.10.07.26.27 for ; Mon, 10 May 2021 07:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-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-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-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 S237680AbhEJO1H (ORCPT ); Mon, 10 May 2021 10:27:07 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2757 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235166AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H6LJkzqTs0; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:25 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 03/15] iommu: Allow max opt DMA len be set for a group via sysfs Date: Mon, 10 May 2021 22:17:17 +0800 Message-ID: <1620656249-68890-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add support to allow the maximum optimised DMA len be set for an IOMMU group via sysfs. This much the same with the method to change the default domain type for a group. However, unlike changing the default domain type, the new domains will be allocated on a member device reprobe path. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4d12b607918c..63cdfb11ebed 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -45,6 +45,7 @@ struct iommu_group { struct iommu_domain *default_domain; struct iommu_domain *domain; struct list_head entry; + size_t max_opt_dma_size; }; struct group_device { @@ -86,6 +87,9 @@ static int iommu_create_device_direct_mappings(struct iommu_group *group, static struct iommu_group *iommu_group_get_for_dev(struct device *dev); static ssize_t iommu_group_store_type(struct iommu_group *group, const char *buf, size_t count); +static ssize_t iommu_group_store_max_opt_dma_size(struct iommu_group *group, + const char *buf, + size_t count); #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \ struct iommu_group_attribute iommu_group_attr_##_name = \ @@ -554,6 +558,12 @@ static ssize_t iommu_group_show_type(struct iommu_group *group, return strlen(type); } +static ssize_t iommu_group_show_max_opt_dma_size(struct iommu_group *group, + char *buf) +{ + return sprintf(buf, "%zu\n", group->max_opt_dma_size); +} + static IOMMU_GROUP_ATTR(name, S_IRUGO, iommu_group_show_name, NULL); static IOMMU_GROUP_ATTR(reserved_regions, 0444, @@ -562,6 +572,9 @@ static IOMMU_GROUP_ATTR(reserved_regions, 0444, static IOMMU_GROUP_ATTR(type, 0644, iommu_group_show_type, iommu_group_store_type); +static IOMMU_GROUP_ATTR(max_opt_dma_size, 0644, iommu_group_show_max_opt_dma_size, + iommu_group_store_max_opt_dma_size); + static void iommu_group_release(struct kobject *kobj) { struct iommu_group *group = to_iommu_group(kobj); @@ -648,6 +661,10 @@ struct iommu_group *iommu_group_alloc(void) if (ret) return ERR_PTR(ret); + ret = iommu_group_create_file(group, &iommu_group_attr_max_opt_dma_size); + if (ret) + return ERR_PTR(ret); + pr_debug("Allocated group %d\n", group->id); return group; @@ -3279,3 +3296,29 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, return iommu_group_store_common(group, buf, count, iommu_group_store_type_cb); } + +static int iommu_group_store_max_opt_dma_size_cb(const char *buf, + struct iommu_group *group, + struct device *dev) +{ + unsigned long val; + char *endp; + + val = simple_strtoul(buf, &endp, 0); + if (endp == buf) + return -EINVAL; + + mutex_lock(&group->mutex); + group->max_opt_dma_size = val; + mutex_unlock(&group->mutex); + + return 0; +} + +static ssize_t iommu_group_store_max_opt_dma_size(struct iommu_group *group, + const char *buf, + size_t count) +{ + return iommu_group_store_common(group, buf, count, + iommu_group_store_max_opt_dma_size_cb); +}