From nobody Fri Feb 13 15:06:15 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DADE814A9D for ; Mon, 27 May 2024 04:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716782877; cv=none; b=JYLWxgO2tF4MKT8QGKWp5qUzSZcFu9GyGbL2KYvkM4DKz1ULuxCmPcBCMIs7pKz8sjGs0T4//hv9hz+GKGhKNo5MS1mZkVdRWRnQeCg1eIKqLfMdIp4ESnmAvFom+mp7b6zhyrK9QAxwQznmUo763yDvi+gqANQ42P61lUlTqdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716782877; c=relaxed/simple; bh=zqFfjljFQ7bL1eow/Jlw1FxofoCmHNFJrcdwJL8lKvE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qrPFR/TrRC/vHhmFOwl736+LZ9QEQVenJ796eDSd46GqfnAOykU7SRjjyGyhlFvQ96zrI1YTJe7BLtvM8KjbP6mGnubjlaDY3QdsfWLdyQJczItpkWc46oDRUnMh75Ta7q0ZzbaYXwpMWPnt5sE2EGToPy7Cg+hqMPNWT9N9Pdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QhQkyaMm; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QhQkyaMm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716782876; x=1748318876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zqFfjljFQ7bL1eow/Jlw1FxofoCmHNFJrcdwJL8lKvE=; b=QhQkyaMmU9lQAnUJAi04K66NJ+fW0yPW2IK9hEocj2PnWOuaqyM9QNHG A7vBOG8fn4xVC4JsoFPlZMjUD0Yi1PNbxYSim71nyS+YF/awK5kKNd2iB 8FEqQBpOVEqLrd2f1RNXkgipioEApfvR3ziw+p59CHftWNmS1z4sX+JXn 3pPJLTX88Cd+8+gJTwAGONbXVkws1ZcAGAfPLpgtRpY14Ds2Z1qJmuwN+ g8dNv6VLXf0cpgUhpMM2F+nIpqMVJnUc6v38oKlkz/LZ5Tga+9Ru3o7JZ wO7XDEo+96xiKujdETu3dOi8C4Qy1F5nnwUuYighcwxOqXecugh7RRGj8 w==; X-CSE-ConnectionGUID: NpwBuiHcSEOoJ50OSg4COg== X-CSE-MsgGUID: uTUW207bTJC4vZSUlIY6xg== X-IronPort-AV: E=McAfee;i="6600,9927,11084"; a="13022753" X-IronPort-AV: E=Sophos;i="6.08,191,1712646000"; d="scan'208";a="13022753" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2024 21:07:40 -0700 X-CSE-ConnectionGUID: xjVXVygwQPatCCxROdW6hw== X-CSE-MsgGUID: Bauamti5QJeECuzxBFWsEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,191,1712646000"; d="scan'208";a="39399914" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by orviesa003.jf.intel.com with ESMTP; 26 May 2024 21:07:36 -0700 From: Lu Baolu To: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , Joel Granados Cc: iommu@lists.linux.dev, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v6 04/10] iommu: Extend domain attach group with handle support Date: Mon, 27 May 2024 12:05:11 +0800 Message-Id: <20240527040517.38561-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527040517.38561-1-baolu.lu@linux.intel.com> References: <20240527040517.38561-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Unlike the SVA case where each PASID of a device has an SVA domain attached to it, the I/O page faults are handled by the fault handler of the SVA domain. The I/O page faults for a user page table might be handled by the domain attached to RID or the domain attached to the PASID, depending on whether the PASID table is managed by user space or kernel. As a result, there is a need for the domain attach group interfaces to have attach handle support. The attach handle will be forwarded to the fault handler of the user domain. Add some variants of the domain attaching group interfaces so that they could support the attach handle and export them for use in IOMMUFD. Signed-off-by: Lu Baolu --- drivers/iommu/iommu-priv.h | 8 +++ drivers/iommu/iommu.c | 99 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h index f1536a5ebb0d..c37801c32f33 100644 --- a/drivers/iommu/iommu-priv.h +++ b/drivers/iommu/iommu-priv.h @@ -31,4 +31,12 @@ void iommu_device_unregister_bus(struct iommu_device *io= mmu, struct iommu_attach_handle *iommu_attach_handle_get(struct iommu_group *gr= oup, ioasid_t pasid, unsigned int type); +int iommu_attach_group_handle(struct iommu_domain *domain, + struct iommu_group *group, + struct iommu_attach_handle *handle); +void iommu_detach_group_handle(struct iommu_domain *domain, + struct iommu_group *group); +int iommu_replace_group_handle(struct iommu_group *group, + struct iommu_domain *new_domain, + struct iommu_attach_handle *handle); #endif /* __LINUX_IOMMU_PRIV_H */ diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index c506185a2fad..78e29fc97236 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3475,3 +3475,102 @@ iommu_attach_handle_get(struct iommu_group *group, = ioasid_t pasid, unsigned int return handle; } EXPORT_SYMBOL_NS_GPL(iommu_attach_handle_get, IOMMUFD_INTERNAL); + +/** + * iommu_attach_group_handle - Attach an IOMMU domain to an IOMMU group + * @domain: IOMMU domain to attach + * @group: IOMMU group that will be attached + * @handle: attach handle + * + * Returns 0 on success and error code on failure. + * + * This is a variant of iommu_attach_group(). It allows the caller to prov= ide + * an attach handle and use it when the domain is attached. This is curren= tly + * used by IOMMUFD to deliver the I/O page faults. + */ +int iommu_attach_group_handle(struct iommu_domain *domain, + struct iommu_group *group, + struct iommu_attach_handle *handle) +{ + int ret; + + mutex_lock(&group->mutex); + ret =3D xa_insert(&group->pasid_array, IOMMU_NO_PASID, handle, GFP_KERNEL= ); + if (ret) + goto err_unlock; + + ret =3D __iommu_attach_group(domain, group); + if (ret) + goto err_erase; + mutex_unlock(&group->mutex); + + return 0; +err_erase: + xa_erase(&group->pasid_array, IOMMU_NO_PASID); +err_unlock: + mutex_unlock(&group->mutex); + return ret; +} +EXPORT_SYMBOL_NS_GPL(iommu_attach_group_handle, IOMMUFD_INTERNAL); + +/** + * iommu_detach_group_handle - Detach an IOMMU domain from an IOMMU group + * @domain: IOMMU domain to attach + * @group: IOMMU group that will be attached + * + * Detach the specified IOMMU domain from the specified IOMMU group. + * It must be used in conjunction with iommu_attach_group_handle(). + */ +void iommu_detach_group_handle(struct iommu_domain *domain, + struct iommu_group *group) +{ + mutex_lock(&group->mutex); + __iommu_group_set_core_domain(group); + xa_erase(&group->pasid_array, IOMMU_NO_PASID); + mutex_unlock(&group->mutex); +} +EXPORT_SYMBOL_NS_GPL(iommu_detach_group_handle, IOMMUFD_INTERNAL); + +/** + * iommu_replace_group_handle - replace the domain that a group is attache= d to + * @group: IOMMU group that will be attached to the new domain + * @new_domain: new IOMMU domain to replace with + * @handle: attach handle + * + * This is a variant of iommu_group_replace_domain(). It allows the caller= to + * provide an attach handle for the new domain and use it when the domain = is + * attached. + */ +int iommu_replace_group_handle(struct iommu_group *group, + struct iommu_domain *new_domain, + struct iommu_attach_handle *handle) +{ + struct iommu_domain *old_domain =3D group->domain; + void *curr; + int ret; + + if (!new_domain) + return -EINVAL; + + mutex_lock(&group->mutex); + ret =3D __iommu_group_set_domain(group, new_domain); + if (ret) + goto err_unlock; + xa_erase(&group->pasid_array, IOMMU_NO_PASID); + if (handle) { + curr =3D xa_store(&group->pasid_array, IOMMU_NO_PASID, handle, GFP_KERNE= L); + if (xa_err(curr)) { + ret =3D xa_err(curr); + goto err_restore; + } + } + mutex_unlock(&group->mutex); + + return 0; +err_restore: + __iommu_group_set_domain(group, old_domain); +err_unlock: + mutex_unlock(&group->mutex); + return ret; +} +EXPORT_SYMBOL_NS_GPL(iommu_replace_group_handle, IOMMUFD_INTERNAL); --=20 2.34.1