From patchwork Mon May 10 14:17:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433147 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895351jao; Mon, 10 May 2021 07:25:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcBv1xkdyVLQLObWVdbErzCHpgasMnJckSEP17FdYj5rBJkFOYB3hSANdw+cckJDtAD6VE X-Received: by 2002:a05:6e02:527:: with SMTP id h7mr20482535ils.293.1620656752745; Mon, 10 May 2021 07:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656752; cv=none; d=google.com; s=arc-20160816; b=i5kq6XnkuQMeHVtfnmUhVepJxjpU1qPIL4wBW0emlACnEwpln8FJdvjq7TWC5GCEX/ dEM8g+QcKqTUYgiR931nfcoS4KlXI83jBWmbEpFX0WsrOswZqvgfGX5daQ3vJ4wc9QkG q3C6azNX7NOOgBbJSgEmfdyih8+KLh8RtZ2CEl7Tu6eDs6xvwtFe65VBrt9TybOHWtK5 AgOVusLTSCHsOuhvXpjiuHYG0v/Uh5m72MC+Ameh0oRSuh71be2yVH0UbfIjPLu1cyRN aMWY+hooDVSU13cXaOGhl+hMR5niz1VuqzXfcQChzNFRxtZwds7lA5wRHBXJ3KHsaPHd 3DCA== 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=hfLFINyeWMlChJXjiJey+tFDP5zA0+KVvEEzk5hf1CA=; b=bsjPMZhQ16D7HPIoJyiwC3JBplCp9a9fg7WypYAtH34Uj+huDVMXdZHBVwp1uCYlMW O0M6WA4O67p8b15o9EQztf9kEbzENVsGCCwNjw5qG6N0uAl3fL++wqssM2TIzZWCrYAO 7CKv30X+0qeSfnn/+oB9K7KTXr1rzjNK5IwCQZ64wWrsIHqJQ2f6UvmdGVvk90OwBpFe HNRWAN636EZ8jfX9QytmuOO1wwpNn7SLTFhiwXN5amxKZFsClsMupVy2GrWHLSdHQPfw cUiCQ3Xmd9Gn0C9gMq+8A9nDyqL6DidSkJCQb+A35ma48xe3dxOdyXrEGvQcQJ8PbbXM Ya5Q== 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 g19si19729924jat.91.2021.05.10.07.25.52 for ; Mon, 10 May 2021 07:25:52 -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 S231341AbhEJO0x (ORCPT ); Mon, 10 May 2021 10:26:53 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2758 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235168AbhEJOXq (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 4Ff38H4mTnzqTrf; 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:26 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 06/15] iommu: Allow iommu_change_dev_def_domain() realloc default domain for same type Date: Mon, 10 May 2021 22:17:20 +0800 Message-ID: <1620656249-68890-7-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 Allow iommu_change_dev_def_domain() to create a new default domain, keeping the same as current in case type argument is not set. Also remove comment about function purpose, which will become stale. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 53 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 62e4491f32e0..f7253a973ab9 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3065,16 +3065,13 @@ EXPORT_SYMBOL_GPL(iommu_sva_get_pasid); * @prev_dev: The device in the group (this is used to make sure that the device * hasn't changed after the caller has called this function) * @type: The type of the new default domain that gets associated with the group + * @new: Allocate new default domain, keeping same type when no type passed * * Returns 0 on success and error code on failure * - * Note: - * 1. Presently, this function is called only when user requests to change the - * group's default domain type through /sys/kernel/iommu_groups//type - * Please take a closer look if intended to use for other purposes. */ static int iommu_change_dev_def_domain(struct iommu_group *group, - struct device *prev_dev, int type) + struct device *prev_dev, int type, bool new) { struct iommu_domain *prev_dom; struct group_device *grp_dev; @@ -3127,28 +3124,32 @@ static int iommu_change_dev_def_domain(struct iommu_group *group, goto out; } - dev_def_dom = iommu_get_def_domain_type(dev); - if (!type) { + if (new && !type) { + type = prev_dom->type; + } else { + dev_def_dom = iommu_get_def_domain_type(dev); + if (!type) { + /* + * If the user hasn't requested any specific type of domain and + * if the device supports both the domains, then default to the + * domain the device was booted with + */ + type = dev_def_dom ? : iommu_def_domain_type; + } else if (dev_def_dom && type != dev_def_dom) { + dev_err_ratelimited(prev_dev, "Device cannot be in %s domain\n", + iommu_domain_type_str(type)); + ret = -EINVAL; + goto out; + } + /* - * If the user hasn't requested any specific type of domain and - * if the device supports both the domains, then default to the - * domain the device was booted with + * Switch to a new domain only if the requested domain type is different + * from the existing default domain type */ - type = dev_def_dom ? : iommu_def_domain_type; - } else if (dev_def_dom && type != dev_def_dom) { - dev_err_ratelimited(prev_dev, "Device cannot be in %s domain\n", - iommu_domain_type_str(type)); - ret = -EINVAL; - goto out; - } - - /* - * Switch to a new domain only if the requested domain type is different - * from the existing default domain type - */ - if (prev_dom->type == type) { - ret = 0; - goto out; + if (prev_dom->type == type) { + ret = 0; + goto out; + } } /* Sets group->default_domain to the newly allocated domain */ @@ -3292,7 +3293,7 @@ static int iommu_group_store_type_cb(const char *buf, else return -EINVAL; - return iommu_change_dev_def_domain(group, dev, type); + return iommu_change_dev_def_domain(group, dev, type, false); } static ssize_t iommu_group_store_type(struct iommu_group *group,