Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5733894pxb; Mon, 14 Feb 2022 06:27:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAwhsTqg7M1hd8VECVNkPSCBFNavfVhtXdAWOeVfsch0MAX5EZZMfiJy1A8n67AyR+nagr X-Received: by 2002:a05:6402:90b:: with SMTP id g11mr16362671edz.97.1644848834879; Mon, 14 Feb 2022 06:27:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644848834; cv=none; d=google.com; s=arc-20160816; b=oVnB7E5qQ3XdmNNEwOefOBUR2XCkg2LfoEOt1vNkqFy2R58MTN/eCp5KL/UQOvhyHc JKIu+zef7KY9bBbQ1OhWSujHrgRm3c6awQDZxyRvqOzQYDp0w+fscJvw+JfIa+rHDu8r bkBSxyAIUyXu89uRVUAbPrkMZjjxgONc8iKsqKx4jAzttqxXN0TZefP7xyYR11z3l7V7 k0CAwWbQhWKKej2VgVtQ/uFd+8f02XU2CieQI17UxCgWMHLkypwhxrqUcusw4b/PF8mo PtoiLm7JYJV4wSAYZe/WJMmgs8OPllzfNDSJKuO6iwJQ8y5CjL1oEGdNeuK9RtOvV6HW Zl0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=nq27xUONr/LHOVUtr5ANJy6/luhDDFe5s3c7vc5vMek=; b=Fcj2pnBQrLQJRXij7KECRSv/9H6NqshLbF3mmZWt3EFe1cX76JsgF3RY8eTxdMHCSQ lUodM/5VBpc/WIJE1ei6ZDhadTV4QnAxJw37S7Xu7Gc3j5FkufgSAvYcgUPxQca8PamE 5RhvknADdj+CcDPB241n2zLaTSdJt47osLYJ5LCHea7RxFFC5UZ71Ekl5MGMdBkW5UJF JryKPfgK1bkfkNbVo8Xpj7bo9QOmeouLGKKJnt4SazcpJxgvxddvCkGdwb7CE+rvyHGy cu5DlwBYo0IsdHhpWIbuxY91GjpyST+4QQUo/bk61f6g67zdrgVP8izQcFeoYBC1cAFp dw8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3si14779785edc.280.2022.02.14.06.26.51; Mon, 14 Feb 2022 06:27:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbiBNMJz (ORCPT + 99 others); Mon, 14 Feb 2022 07:09:55 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231234AbiBNMJy (ORCPT ); Mon, 14 Feb 2022 07:09:54 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A36FC488A8; Mon, 14 Feb 2022 04:09:46 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3E8861396; Mon, 14 Feb 2022 04:09:46 -0800 (PST) Received: from [10.57.70.89] (unknown [10.57.70.89]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3A6763F718; Mon, 14 Feb 2022 04:09:41 -0800 (PST) Message-ID: <43f2fc07-19ea-53a4-af86-a9192a950c96@arm.com> Date: Mon, 14 Feb 2022 12:09:36 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH v1 1/8] iommu: Add iommu_group_replace_domain() Content-Language: en-GB To: Lu Baolu , Joerg Roedel , Alex Williamson , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: kvm@vger.kernel.org, rafael@kernel.org, David Airlie , linux-pci@vger.kernel.org, Thierry Reding , Diana Craciun , Dmitry Osipenko , Will Deacon , Stuart Yoder , Jonathan Hunter , Chaitanya Kulkarni , Bjorn Helgaas , Dan Williams , Greg Kroah-Hartman , Cornelia Huck , linux-kernel@vger.kernel.org, Li Yang , iommu@lists.linux-foundation.org, Jacob jun Pan , Daniel Vetter References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> <20220106022053.2406748-2-baolu.lu@linux.intel.com> From: Robin Murphy In-Reply-To: <20220106022053.2406748-2-baolu.lu@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-01-06 02:20, Lu Baolu wrote: > Expose an interface to replace the domain of an iommu group for frameworks > like vfio which claims the ownership of the whole iommu group. But if the underlying point is the new expectation that iommu_{attach,detach}_device() operate on the device's whole group where relevant, why should we invent some special mechanism for VFIO to be needlessly inconsistent? I said before that it's trivial for VFIO to resolve a suitable device if it needs to; by now I've actually written the patch ;) https://gitlab.arm.com/linux-arm/linux-rm/-/commit/9f37d8c17c9b606abc96e1f1001c0b97c8b93ed5 Robin. > Signed-off-by: Lu Baolu > --- > include/linux/iommu.h | 10 ++++++++++ > drivers/iommu/iommu.c | 37 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 47 insertions(+) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 408a6d2b3034..66ebce3d1e11 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -677,6 +677,9 @@ void iommu_device_unuse_dma_api(struct device *dev); > int iommu_group_set_dma_owner(struct iommu_group *group, void *owner); > void iommu_group_release_dma_owner(struct iommu_group *group); > bool iommu_group_dma_owner_claimed(struct iommu_group *group); > +int iommu_group_replace_domain(struct iommu_group *group, > + struct iommu_domain *old, > + struct iommu_domain *new); > > #else /* CONFIG_IOMMU_API */ > > @@ -1090,6 +1093,13 @@ static inline bool iommu_group_dma_owner_claimed(struct iommu_group *group) > { > return false; > } > + > +static inline int > +iommu_group_replace_domain(struct iommu_group *group, struct iommu_domain *old, > + struct iommu_domain *new) > +{ > + return -ENODEV; > +} > #endif /* CONFIG_IOMMU_API */ > > /** > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 72a95dea688e..ab8ab95969f5 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -3431,3 +3431,40 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group) > return user; > } > EXPORT_SYMBOL_GPL(iommu_group_dma_owner_claimed); > + > +/** > + * iommu_group_replace_domain() - Replace group's domain > + * @group: The group. > + * @old: The previous attached domain. NULL for none. > + * @new: The new domain about to be attached. > + * > + * This is to support backward compatibility for vfio which manages the dma > + * ownership in iommu_group level. > + */ > +int iommu_group_replace_domain(struct iommu_group *group, > + struct iommu_domain *old, > + struct iommu_domain *new) > +{ > + int ret = 0; > + > + mutex_lock(&group->mutex); > + if (!group->owner || group->domain != old) { > + ret = -EPERM; > + goto unlock_out; > + } > + > + if (old) > + __iommu_detach_group(old, group); > + > + if (new) { > + ret = __iommu_attach_group(new, group); > + if (ret && old) > + __iommu_attach_group(old, group); > + } > + > +unlock_out: > + mutex_unlock(&group->mutex); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(iommu_group_replace_domain);