From nobody Thu Apr 2 00:12:59 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 815BF3BA23D; Mon, 30 Mar 2026 10:11:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865483; cv=none; b=arE7R3vgEMzWyKFZ0CxHJiefhThVfR8+W6NzGnIhLbbchteui+EfJB6Wrj3mwnG4TXSO3Wx5cOPW0skT0dJ4cNJrJB7Px9Xu83l6f09h3RHKitjvSzf4f2K9/q+z+ciTOQbVcuhAVDMLr5Vp5KFFqov9DWUhN4ADVwujDpgf0WA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865483; c=relaxed/simple; bh=EGxIrnSiCc0r/A40It2qhOffrUuycMftQdxuwrCg0o4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UNF8YikVhMdHFnx1BJFrJrRT09czGURC8rVVzuKcvoBJfWyNL/nU0HkwUjFJf/zapL1T00A4CjYCftzm2mIV7csdt7mKL1EzIBfLjAHP4dpBH586VJjrQYpuTeKdcWC1VZsQA4Ex89ydf8F9OOU+ybM+J/ZM2aVI2MaXTdXvgS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=L+1RntwR; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="L+1RntwR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774865482; x=1806401482; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EGxIrnSiCc0r/A40It2qhOffrUuycMftQdxuwrCg0o4=; b=L+1RntwRF/isVcfZ2yPSm+nRa368o0zI5j6MTo7rjz+xWPGHDYHdCX+H zw+HeNBQQDCpNNWnnvuD1Wj+CgIQGyWjnID9FI8l3VeDhsZvaFtPtS6o2 /LiCsXPCWhP+66g6y+hq9lZHpB+O+0V2Fa9US/wEaNWofAFDrygDcod6R lx2Dx9bvUTnNsm1eaGKI5fqvZpjqGo4y+fX5Pt0s2dETWm6KwErV/bdJE qN+86fl+JzichgrS6OYJWgcyMOzNXofzgq9X4m1Uu6blY6UnUUpDOzACC Rza3TN/TUrwAYzPeXldM0ycc42qTCfRXSuHL9RMaI7dPl7K8VH2PbhNzj g==; X-CSE-ConnectionGUID: 16LX1xQZTlemSclXesUXwA== X-CSE-MsgGUID: fp4le8k/ThaNDqx9PQDUKA== X-IronPort-AV: E=McAfee;i="6800,10657,11743"; a="75921156" X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="75921156" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:22 -0700 X-CSE-ConnectionGUID: dFt7b/aVQXGo+Eo0pJRHbQ== X-CSE-MsgGUID: gE/uhu0iSn2I/UWmpWh10w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="225913432" Received: from spr-duan.bj.intel.com ([172.16.114.123]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:19 -0700 From: Zhenzhong Duan To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: dwmw2@infradead.org, jgg@ziepe.ca, kevin.tian@intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, baolu.lu@linux.intel.com, yi.l.liu@intel.com, Zhenzhong Duan , stable@vger.kernel.org, Joao Martins Subject: [PATCH v2 1/4] iommu/vt-d: Block PASID attachment to nested domain with dirty tracking Date: Mon, 30 Mar 2026 06:11:04 -0400 Message-ID: <20260330101108.12594-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260330101108.12594-1-zhenzhong.duan@intel.com> References: <20260330101108.12594-1-zhenzhong.duan@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" Kernel lacks dirty tracking support on nested domain attached to PASID, fails the attachment early if nesting parent domain is dirty tracking configured, otherwise dirty pages would be lost. Cc: stable@vger.kernel.org Fixes: f35f22cc760e ("iommu/vt-d: Access/Dirty bit support for SS domains") Suggested-by: Kevin Tian Signed-off-by: Zhenzhong Duan Reviewed-by: Kevin Tian Reviewed-by: Yi Liu --- drivers/iommu/intel/nested.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index 2b979bec56ce..16c82ba47d30 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -148,6 +148,7 @@ static int intel_nested_set_dev_pasid(struct iommu_doma= in *domain, { struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct dmar_domain *dmar_domain =3D to_dmar_domain(domain); + struct iommu_domain *s2_domain =3D &dmar_domain->s2_domain->domain; struct intel_iommu *iommu =3D info->iommu; struct dev_pasid_info *dev_pasid; int ret; @@ -155,10 +156,13 @@ static int intel_nested_set_dev_pasid(struct iommu_do= main *domain, if (!pasid_supported(iommu) || dev_is_real_dma_subdevice(dev)) return -EOPNOTSUPP; =20 + if (s2_domain->dirty_ops) + return -EINVAL; + if (context_copied(iommu, info->bus, info->devfn)) return -EBUSY; =20 - ret =3D paging_domain_compatible(&dmar_domain->s2_domain->domain, dev); + ret =3D paging_domain_compatible(s2_domain, dev); if (ret) return ret; =20 --=20 2.47.3 From nobody Thu Apr 2 00:12:59 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 03BDC3BAD8D for ; Mon, 30 Mar 2026 10:11:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865488; cv=none; b=czrAEK1OsvV+rvy56Wy3GlnBJil0zJ3+V+sWC4+yu9pkawxlUrhHmh0ZD4myxAVaT5oIPceViKrJtIXAD4sX74up2zhi8R6p0WJi1TUNpicc4pYdKMpmKKmlGytijy4oeodA4mfoB34SKRy5euO6ktAyYEKFTKpoIolb98YHAtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865488; c=relaxed/simple; bh=Q+qunl396kXFXB5Cvwi9Oeb21eUaoU8dWojLR4cn3m8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=duR1jeDnsZOTYz4/OKni07WaxzaPpZIjiCUZ+w7gX3RqxN6/UxpDM5mkGmB5wlNAXRWrU2TqM5MqVal1ruvVTgeDsySg0e1jdo0olboHscCPu2384ntAv98cgnkhhW8ZcXyJzOWX1niKIhVy+0yAGkg+cMntsb5BFeCXZBqqLWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OiruIpr1; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OiruIpr1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774865486; x=1806401486; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q+qunl396kXFXB5Cvwi9Oeb21eUaoU8dWojLR4cn3m8=; b=OiruIpr1wk/cFL/1ZGw1cZTJugMcrZJfh6K8C4tzJd8TrpKNmxHAPjIO KzvVCW6aJiUSvaU8djcuXgYLJMWEZqXMBO5r7SCZgwtUvNctb/ZALBsmx KEZrM9Kmlb0jwSOEpgBocSOyw+OyW2afYwMThdkLuFVVsPeDnJJSmJSvN T/SlH23ocGg4HvLjtUY62q/R4rvdyTR5X1A71r0HOdRwtCzqmJQhaBFRQ lU36rOzBC+cQBensLkRiJYJkKOOQh6eB6yjU7L4HvnF4EBNStL/abU++x Qk+uBPK4ergLeow9L8sR5Da32JZU/kVGP3Esnevr2sEhpxxw6TTJLoK4D Q==; X-CSE-ConnectionGUID: XQOATdCKSaq5qORVs2wqTA== X-CSE-MsgGUID: KTRmSvmASHa6AJKZnLbdOQ== X-IronPort-AV: E=McAfee;i="6800,10657,11743"; a="75921169" X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="75921169" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:25 -0700 X-CSE-ConnectionGUID: iu5QfUCfTYaja9xAK+J55g== X-CSE-MsgGUID: qJ3KZnPWT+iz9IMOqB9biQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="225913450" Received: from spr-duan.bj.intel.com ([172.16.114.123]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:22 -0700 From: Zhenzhong Duan To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: dwmw2@infradead.org, jgg@ziepe.ca, kevin.tian@intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, baolu.lu@linux.intel.com, yi.l.liu@intel.com, Zhenzhong Duan Subject: [PATCH v2 2/4] iommupt/vtd: Rename device_set_dirty_tracking() and pass dmar_domain pointer Date: Mon, 30 Mar 2026 06:11:05 -0400 Message-ID: <20260330101108.12594-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260330101108.12594-1-zhenzhong.duan@intel.com> References: <20260330101108.12594-1-zhenzhong.duan@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" device_set_dirty_tracking() sets dirty tracking on all devices attached to a domain, also on all PASIDs attached to same domain in subsequent patch. So rename it as domain_set_dirty_tracking() and pass dmar_domain pointer to better align to what it does. No functional changes intended. Suggested-by: Lu Baolu Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index ef7613b177b9..965e0330ec4b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3684,16 +3684,15 @@ static void *intel_iommu_hw_info(struct device *dev= , u32 *length, return vtd; } =20 -/* - * Set dirty tracking for the device list of a domain. The caller must - * hold the domain->lock when calling it. - */ -static int device_set_dirty_tracking(struct list_head *devices, bool enabl= e) +/* Set dirty tracking for the devices that the domain has been attached. */ +static int domain_set_dirty_tracking(struct dmar_domain *domain, bool enab= le) { struct device_domain_info *info; int ret =3D 0; =20 - list_for_each_entry(info, devices, link) { + lockdep_assert_held(&domain->lock); + + list_for_each_entry(info, &domain->devices, link) { ret =3D intel_pasid_setup_dirty_tracking(info->iommu, info->dev, IOMMU_NO_PASID, enable); if (ret) @@ -3713,7 +3712,7 @@ static int parent_domain_set_dirty_tracking(struct dm= ar_domain *domain, spin_lock(&domain->s1_lock); list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) { spin_lock_irqsave(&s1_domain->lock, flags); - ret =3D device_set_dirty_tracking(&s1_domain->devices, enable); + ret =3D domain_set_dirty_tracking(s1_domain, enable); spin_unlock_irqrestore(&s1_domain->lock, flags); if (ret) goto err_unwind; @@ -3724,8 +3723,7 @@ static int parent_domain_set_dirty_tracking(struct dm= ar_domain *domain, err_unwind: list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) { spin_lock_irqsave(&s1_domain->lock, flags); - device_set_dirty_tracking(&s1_domain->devices, - domain->dirty_tracking); + domain_set_dirty_tracking(s1_domain, domain->dirty_tracking); spin_unlock_irqrestore(&s1_domain->lock, flags); } spin_unlock(&domain->s1_lock); @@ -3742,7 +3740,7 @@ static int intel_iommu_set_dirty_tracking(struct iomm= u_domain *domain, if (dmar_domain->dirty_tracking =3D=3D enable) goto out_unlock; =20 - ret =3D device_set_dirty_tracking(&dmar_domain->devices, enable); + ret =3D domain_set_dirty_tracking(dmar_domain, enable); if (ret) goto err_unwind; =20 @@ -3759,8 +3757,7 @@ static int intel_iommu_set_dirty_tracking(struct iomm= u_domain *domain, return 0; =20 err_unwind: - device_set_dirty_tracking(&dmar_domain->devices, - dmar_domain->dirty_tracking); + domain_set_dirty_tracking(dmar_domain, dmar_domain->dirty_tracking); spin_unlock(&dmar_domain->lock); return ret; } --=20 2.47.3 From nobody Thu Apr 2 00:12:59 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 D0C8D3BA238 for ; Mon, 30 Mar 2026 10:11:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865490; cv=none; b=uFf5jfsa6rTFJA5HzEPOzMqjpz8CPMAUxTpKPvCT/zk7ME3T0Gy4qF+7RGlZpRKDG1hNHSyEMUZuDzbBCOeRwoWbP8KNLcTCeSA3DqgIsIIDHN2/515jrkBVi02zXSjTsCG6tN5wdE7ZEP5qGqJbbGhMHsv0vxkAM1uW/PggYsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865490; c=relaxed/simple; bh=SDRNjY/Jps9VCguyId/vKnlzor/cfLxoAmP9kkLJMtQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M2oV2yag/gws/N6tV5FbJ/fpj/P3FiKkOHTTLbhrSEXcKznj/YPAWTBFQJ3KXkBoGx+iVW0i4c817Vme6KGx/73eSxLn3CwOcxK29kKiAq2yHiVvEPQZy9wNSuc99T5SZcfOt6vHe4vZaDOTJsdKHZqRciW68GPs0v7inXyXJz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Z3kAwhUf; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Z3kAwhUf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774865488; x=1806401488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SDRNjY/Jps9VCguyId/vKnlzor/cfLxoAmP9kkLJMtQ=; b=Z3kAwhUfvwejUTPFLT8afrc1qQ2Vnq/cmbC1M+kOic3X5PKUO3qfPowh ycvCTggTGvjY1heByyD5gVX3A52HWb/7AVI4NxJ9nM6sbeEFGMoQ65+DV jE8ief7xQZlFMAoTWGDOyLqYqamVjXSvjsXS+cm0LWjxAvZJHPayPaEC1 xNbgT/TRiDWT3YxDbo7CfZ5dhcN7HDrlDFU8uAI7gw4p1WEnm1/5g9IlN a7IYJtg5DYxVc2dsf9m7Nsgjuj/LH6UmPAwOJUBB4QkKFbNOa432UHMm/ c3M5wAkG8aWnXCk+hEMTJKuIkub0A686o8+6hTcyDGheawiKLxQMLZ4f0 Q==; X-CSE-ConnectionGUID: JUlgsxPPS2KbON0W1F2ajw== X-CSE-MsgGUID: 6uJySVDgTzuBPAdUa+QKeg== X-IronPort-AV: E=McAfee;i="6800,10657,11743"; a="75921177" X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="75921177" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:28 -0700 X-CSE-ConnectionGUID: kGkOWTMwQYWJeXIr2cZu7A== X-CSE-MsgGUID: s+511YDnRrCCgdVU3dOfSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="225913458" Received: from spr-duan.bj.intel.com ([172.16.114.123]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:26 -0700 From: Zhenzhong Duan To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: dwmw2@infradead.org, jgg@ziepe.ca, kevin.tian@intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, baolu.lu@linux.intel.com, yi.l.liu@intel.com, Zhenzhong Duan Subject: [PATCH v2 3/4] iommupt/vtd: Support dirty tracking on PASID Date: Mon, 30 Mar 2026 06:11:06 -0400 Message-ID: <20260330101108.12594-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260330101108.12594-1-zhenzhong.duan@intel.com> References: <20260330101108.12594-1-zhenzhong.duan@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" In order to support passthrough device with PASID capability in QEMU, e.g., DSA device, kernel needs to support attaching PASID to a domain. But attaching is not allowed if the domain is a second stage domain or nested domain with dirty tracking. The reason is kernel lacking support for dirty tracking on such domain attached to PASID. By adding dirty tracking on PASID, the check can be removed. Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 12 +++++++++--- drivers/iommu/intel/nested.c | 6 +----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 965e0330ec4b..26135ff3a289 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3618,9 +3618,6 @@ static int intel_iommu_set_dev_pasid(struct iommu_dom= ain *domain, if (!pasid_supported(iommu) || dev_is_real_dma_subdevice(dev)) return -EOPNOTSUPP; =20 - if (domain->dirty_ops) - return -EINVAL; - if (context_copied(iommu, info->bus, info->devfn)) return -EBUSY; =20 @@ -3688,6 +3685,7 @@ static void *intel_iommu_hw_info(struct device *dev, = u32 *length, static int domain_set_dirty_tracking(struct dmar_domain *domain, bool enab= le) { struct device_domain_info *info; + struct dev_pasid_info *dev_pasid; int ret =3D 0; =20 lockdep_assert_held(&domain->lock); @@ -3695,6 +3693,14 @@ static int domain_set_dirty_tracking(struct dmar_dom= ain *domain, bool enable) list_for_each_entry(info, &domain->devices, link) { ret =3D intel_pasid_setup_dirty_tracking(info->iommu, info->dev, IOMMU_NO_PASID, enable); + if (ret) + return ret; + } + + list_for_each_entry(dev_pasid, &domain->dev_pasids, link_domain) { + info =3D dev_iommu_priv_get(dev_pasid->dev); + ret =3D intel_pasid_setup_dirty_tracking(info->iommu, info->dev, + dev_pasid->pasid, enable); if (ret) break; } diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index 16c82ba47d30..2b979bec56ce 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -148,7 +148,6 @@ static int intel_nested_set_dev_pasid(struct iommu_doma= in *domain, { struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct dmar_domain *dmar_domain =3D to_dmar_domain(domain); - struct iommu_domain *s2_domain =3D &dmar_domain->s2_domain->domain; struct intel_iommu *iommu =3D info->iommu; struct dev_pasid_info *dev_pasid; int ret; @@ -156,13 +155,10 @@ static int intel_nested_set_dev_pasid(struct iommu_do= main *domain, if (!pasid_supported(iommu) || dev_is_real_dma_subdevice(dev)) return -EOPNOTSUPP; =20 - if (s2_domain->dirty_ops) - return -EINVAL; - if (context_copied(iommu, info->bus, info->devfn)) return -EBUSY; =20 - ret =3D paging_domain_compatible(s2_domain, dev); + ret =3D paging_domain_compatible(&dmar_domain->s2_domain->domain, dev); if (ret) return ret; =20 --=20 2.47.3 From nobody Thu Apr 2 00:12:59 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 0911D3BD24D; Mon, 30 Mar 2026 10:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865494; cv=none; b=dp40z3j7jTlZjoG58LiXndDRsU0TIupl5n2n+MiSpnOl570e97gCsfD8+oh86qixabFW6fk9dPkkVcdDdlDngfbfeeyLKKkHbn4DHWdRHQyWeQTjM6rNP5Jl31D/6h8QYCseYx7MHEKCYtuJe2nHJFrvf+AcRSVq5J8DmTo3F0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865494; c=relaxed/simple; bh=2Qwo3uvG4BlcBg2j7lWvEfKP/WdTuzKegEOP6jT7zlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r+g5c/MKz/m+yXVoc9a9VWaDvOZzRciPH+I4EJ32F90xhUqACk7Iw7yU2TDLr8oI4vWn65FVyOPemoVNd6rb7jgPLuJ+4bRw9ItwtZm7gd8kgyc+JuFet/cbyigLujXYwBm8KXgmUAPHrLeNLTND3BZd0D8yL0wllp1VBEkBBr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=m7mfUpN/; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="m7mfUpN/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774865493; x=1806401493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2Qwo3uvG4BlcBg2j7lWvEfKP/WdTuzKegEOP6jT7zlA=; b=m7mfUpN/o4Nu3aNdb6RK86SA4pcsKcbM7hjch4hsUDW4p9HGRF7+yxME oxZvWzUHsb41z5TXt3M2vHYxe0tLJxJBMxgAXJDuqnC+ggwO/1OFct4yy 0F/Ro8ASgVCxelQblNAq4q8gVSToaXnam4TnghsJT4A/QBZY6qc13PX2N +KLwaN7RIx3/Hj9Mjfcukd3MkHmtP4GOXsv+cxMQZiWQjkmvD1MDvhOgV 9TSOvzUbRx4fVOVh2aqjRlNO2pMoqNk3nmhRcSmovxxps82QuQ2dUJh2j jxEfAuXbyo6osGIH/Q2Z12/eQOU5u81DbkOuHnORAdCfd+uWATxI66viO Q==; X-CSE-ConnectionGUID: C8+s+giSTLu5TXFFSZ5F5w== X-CSE-MsgGUID: zfuEydHiQQ2kAME1/DFzRg== X-IronPort-AV: E=McAfee;i="6800,10657,11743"; a="75921189" X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="75921189" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:32 -0700 X-CSE-ConnectionGUID: QUjg63azR2qn4fFKmRPPaw== X-CSE-MsgGUID: DERAIapcTVGHpQMHZco16A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,149,1770624000"; d="scan'208";a="225913477" Received: from spr-duan.bj.intel.com ([172.16.114.123]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 03:11:29 -0700 From: Zhenzhong Duan To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: dwmw2@infradead.org, jgg@ziepe.ca, kevin.tian@intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, baolu.lu@linux.intel.com, yi.l.liu@intel.com, Zhenzhong Duan , linux-kselftest@vger.kernel.org Subject: [PATCH v2 4/4] iommufd/selftest: Test dirty tracking on PASID Date: Mon, 30 Mar 2026 06:11:07 -0400 Message-ID: <20260330101108.12594-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260330101108.12594-1-zhenzhong.duan@intel.com> References: <20260330101108.12594-1-zhenzhong.duan@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" Add test case for dirty tracking on a domain attached to PASID, also confirm attachment to PASID fail if device doesn't support dirty tracking. Suggested-by: Lu Baolu Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Reviewed-by: Kevin Tian --- tools/testing/selftests/iommu/iommufd.c | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selfte= sts/iommu/iommufd.c index dadad277f4eb..d1fe5dbc2813 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -2275,6 +2275,33 @@ TEST_F(iommufd_dirty_tracking, set_dirty_tracking) test_ioctl_destroy(hwpt_id); } =20 +TEST_F(iommufd_dirty_tracking, pasid_set_dirty_tracking) +{ + uint32_t stddev_id, ioas_id, hwpt_id, pasid =3D 100; + uint32_t dev_flags =3D MOCK_FLAGS_DEVICE_PASID; + + /* Regular case */ + test_cmd_hwpt_alloc(self->idev_id, self->ioas_id, + IOMMU_HWPT_ALLOC_PASID | IOMMU_HWPT_ALLOC_DIRTY_TRACKING, + &hwpt_id); + test_cmd_mock_domain_flags(hwpt_id, dev_flags, &stddev_id, NULL, NULL); + ASSERT_EQ(0, _test_cmd_pasid_attach(self->fd, stddev_id, pasid, hwpt_id)); + test_cmd_set_dirty_tracking(hwpt_id, true); + test_cmd_set_dirty_tracking(hwpt_id, false); + ASSERT_EQ(0, _test_cmd_pasid_detach(self->fd, stddev_id, pasid)); + + test_ioctl_destroy(stddev_id); + + /* IOMMU device does not support dirty tracking */ + dev_flags |=3D MOCK_FLAGS_DEVICE_NO_DIRTY; + test_ioctl_ioas_alloc(&ioas_id); + test_cmd_mock_domain_flags(ioas_id, dev_flags, &stddev_id, NULL, NULL); + EXPECT_ERRNO(EINVAL, _test_cmd_pasid_attach(self->fd, stddev_id, pasid, h= wpt_id)); + + test_ioctl_destroy(stddev_id); + test_ioctl_destroy(hwpt_id); +} + TEST_F(iommufd_dirty_tracking, device_dirty_capability) { uint32_t caps =3D 0; --=20 2.47.3