From mboxrd@z Thu Jan 1 00:00:00 1970 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 1E730C4332F for ; Tue, 18 Oct 2022 01:22:14 +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-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:To:Subject:MIME-Version: Date:Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gpQ4uffNUgsbHeYAJq03r5jVgnaef71z8Vf58ChXdwE=; b=NLYQ6dleVairCxToyZQxhb9cRZ 1TJmfk1OIWcObikjnkUJ6K77OA5o56pOo9Sm/oy0+evS/1Va9RzKnqZrE4Nj35E1DxLH3/Zp/V3HH DU9WDyUSNkyPs/0SZkfK9Oj8KjjVBWQ5k6pDeHxSZeuAno6g2Ory5jv2AS35YpipOEee9DV7qI4vE JldQmVUXtNWZLLLbPsZDMI0UUaVuPYEosVU5c81HHj8Uu+oSeGDIo/JwYJwXnxf6IiIFXCeCdeel+ PBKZueNRxfbjj/qhTP2sJo1jaYd7yQPD5g23dhr/EvvIH2y7O83ojVk3vgynAiNKT3Rt9PNPSmWA7 E558GKDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1okbI7-000sfo-Kn; Tue, 18 Oct 2022 01:21:11 +0000 Received: from mga06b.intel.com ([134.134.136.31] helo=mga06.intel.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1okbI2-000se2-E1; Tue, 18 Oct 2022 01:21:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666056066; x=1697592066; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=su5zkI72C0sQs7FAa4bTuhB/QJ0TTUO44k56XMq6UHE=; b=X/VutGM/GI8x4Js6r2gwIBIesk6KPM53mgvWnFwc3I6Fbkb2W+9R5QQD ppy0L1AbjI/SlYaCtDOkBHLLuJkwoLdaze/uobeEGx7WjW2m4S9zKJzrH UzKLN6FKYLRSvkU6DP4TBkv4NA1uPLMv+8HAHU6tuo0puPpU7WzaeQT7E EVZHHgcUKPOCKFnuG+j2018+tcATJYtDxuRJhpqCJHv9DKsAoqvpF23GC erA5jO3F8W43q5IF4tyqmq6xWI2TE1GvVxRH1xT/ng8a5XbZBCE0JyHOO 6OR99sfqrqfltyPunUeoWxxfZ3l1gtborH4GvNTW7zEDlnwWjxQsRf8Ev A==; X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="367991494" X-IronPort-AV: E=Sophos;i="5.95,192,1661842800"; d="scan'208";a="367991494" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 18:21:02 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="659576177" X-IronPort-AV: E=Sophos;i="5.95,192,1661842800"; d="scan'208";a="659576177" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.211.49]) ([10.254.211.49]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 18:20:54 -0700 Message-ID: Date: Tue, 18 Oct 2022 09:20:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v7 2/5] iommu: Add return value rules to attach_dev op and APIs To: Nicolin Chen , joro@8bytes.org, will@kernel.org, robin.murphy@arm.com References: Content-Language: en-US From: Baolu Lu In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221017_182106_569686_832AC9E7 X-CRM114-Status: GOOD ( 28.28 ) 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: , Cc: quic_saipraka@quicinc.com, yangyicong@hisilicon.com, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jean-philippe@linaro.org, zhang.lyra@gmail.com, jon@solid-run.com, jonathanh@nvidia.com, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, jgg@nvidia.com, yangyingliang@huawei.com, orsonzhai@gmail.com, kevin.tian@intel.com, linux-arm-msm@vger.kernel.org, christophe.jaillet@wanadoo.fr, baolin.wang@linux.alibaba.com, matthias.bgg@gmail.com, tglx@linutronix.de, virtualization@lists.linux-foundation.org, yong.wu@mediatek.com, quic_jjohnson@quicinc.com, linux-kernel@vger.kernel.org, shameerali.kolothum.thodi@huawei.com, robdclark@gmail.com, suravee.suthikulpanit@amd.com, linux-mediatek@lists.infradead.org, dwmw2@infradead.org, baolu.lu@linux.intel.com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2022/10/18 7:01, Nicolin Chen wrote: > Cases like VFIO wish to attach a device to an existing domain that was > not allocated specifically from the device. This raises a condition > where the IOMMU driver can fail the domain attach because the domain and > device are incompatible with each other. > > This is a soft failure that can be resolved by using a different domain. > > Provide a dedicated errno EINVAL from the IOMMU driver during attach that > the reason why the attach failed is because of domain incompatibility. > > VFIO can use this to know that the attach is a soft failure and it should > continue searching. Otherwise, the attach will be a hard failure and VFIO > will return the code to userspace. > > Update kdocs to add rules of return value to the attach_dev op and APIs. > > Suggested-by: Jason Gunthorpe > Reviewed-by: Kevin Tian > Reviewed-by: Jason Gunthorpe > Signed-off-by: Nicolin Chen > --- > drivers/iommu/iommu.c | 24 ++++++++++++++++++++++++ > include/linux/iommu.h | 12 ++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 4893c2429ca5..3c0c5d64bb50 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -1949,6 +1949,18 @@ static int __iommu_attach_device(struct iommu_domain *domain, > return ret; > } > > +/** > + * iommu_attach_device - Attach an IOMMU domain to a device > + * @domain: IOMMU domain to attach > + * @dev: Device that will be attached > + * > + * Returns 0 on success and error code on failure > + * > + * Note that EINVAL can be treated as a soft failure, indicating > + * that certain configuration of the domain is incompatible with > + * the device. In this case attaching a different domain to the > + * device may succeed. > + */ > int iommu_attach_device(struct iommu_domain *domain, struct device *dev) > { > struct iommu_group *group; > @@ -2075,6 +2087,18 @@ static int __iommu_attach_group(struct iommu_domain *domain, > return ret; > } > > +/** > + * iommu_attach_group - Attach an IOMMU domain to an IOMMU group > + * @domain: IOMMU domain to attach > + * @group: IOMMU group that will be attached > + * > + * Returns 0 on success and error code on failure > + * > + * Note that EINVAL can be treated as a soft failure, indicating > + * that certain configuration of the domain is incompatible with > + * the group. In this case attaching a different domain to the > + * group may succeed. > + */ > int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group) > { > int ret; > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index a325532aeab5..6f3569340e8a 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -266,6 +266,18 @@ struct iommu_ops { > /** > * struct iommu_domain_ops - domain specific operations > * @attach_dev: attach an iommu domain to a device > + * Return: > + * * 0 - success > + * * EINVAL - can indicate that device and domain are incompatible due to > + * some previous configuration of the domain, in which case the > + * driver shouldn't log an error, since it is legitimate for a > + * caller to test reuse of existing domains. Otherwise, it may > + * still represent some other fundamental problem > + * * ENOMEM - out of memory > + * * ENOSPC - non-ENOMEM type of resource allocation failures > + * * EBUSY - device is attached to a domain and cannot be changed > + * * ENODEV - device specific errors, not able to be attached > + * * - treated as ENODEV by the caller. Use is discouraged > * @detach_dev: detach an iommu domain from a device > * @map: map a physically contiguous memory region to an iommu domain > * @map_pages: map a physically contiguous set of pages of the same size to Reviewed-by: Lu Baolu Best regards, baolu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel