From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 3ABE0221290 for ; Fri, 20 Jun 2025 06:10:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750399836; cv=none; b=UpGYwM6P+OANbFg4Qr2FdxzXpwWb5bBYGC3Fc9TXhdjXitdphYrQU9/8IS+pm6KhAu6wp9QNQvZTpRG82FZZveHC5CQIElK7p2OkURGc1n6uFKS0mQK5Z170oceCynq9wYOg2JkhaTfU25o4iEAIiY6QA+4+BkUm5FSvRO0qL6A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750399836; c=relaxed/simple; bh=MHJanwY6fC5DvEjyFwwCVe+35ey974zZGBx0Y330LEw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=i/Pt9wLcPPBjHoRbd2Lh0grbKgQuoQTn+IDfuHqZrf5/evxQN0HTjLASfTL4iQ+ugi3XI0VaQwrft9XwNaw1Q/TtAKXZojD3QQ5xY+tgFdh4+i8Ab+pBjqDL8wuR5VDvmNPM+MYdOMZh8ZEyzs16hH4cgAHazv6fRIUy2aJkPGI= 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=DUdaOiXp; arc=none smtp.client-ip=198.175.65.16 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="DUdaOiXp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750399835; x=1781935835; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=MHJanwY6fC5DvEjyFwwCVe+35ey974zZGBx0Y330LEw=; b=DUdaOiXpAIEGV214C05ePN8vd0mO89QCX/2PGDbYRPzqUlOPmA0MKloh F584RjnZxhCfvl+HDAXQl+mx2PmCuBrEf7BHcKbUhZrVXsI9huaoX2wtE K869IM9auY1sUyBRtI7JPqj8baMLxnJjwkGv2M7N9FKyr6+N4eiIo92ss TZXBQP2uspEX3WuPtgeah/QbzNzLsV+Q7fZtgxBMRXwSEGNev2ZYY7nfs mu6MaGoEVT1B9VzClqVxR8PbDijU1VW2viPuNtThcbcxW+w2r9BVpd5/Q 03XHbP1riFF0KRseuV/GGt8xWiHNp0aKfELw4RkMpHDKwhk9QagUKUSfu A==; X-CSE-ConnectionGUID: aN/z/ItzSZa750bXwhD5Dg== X-CSE-MsgGUID: TWewbuOPRze8l4bBrQIEfg== X-IronPort-AV: E=McAfee;i="6800,10657,11469"; a="52739741" X-IronPort-AV: E=Sophos;i="6.16,250,1744095600"; d="scan'208";a="52739741" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2025 23:10:35 -0700 X-CSE-ConnectionGUID: xuRE8HhTQvmuxZy4+OJG+A== X-CSE-MsgGUID: YihgLFvVT2SqD8EF48tANA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,250,1744095600"; d="scan'208";a="150412278" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa007.fm.intel.com with ESMTP; 19 Jun 2025 23:10:32 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , stable@vger.kernel.org Subject: [PATCH 1/1] iommu/vt-d: Enable ATS before cache tag assignment Date: Fri, 20 Jun 2025 14:08:02 +0800 Message-ID: <20250620060802.3036137-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit <4f1492efb495> ("iommu/vt-d: Revert ATS timing change to fix boot failure") placed the enabling of ATS in the probe_finalize callback. This occurs after the default domain attachment, which is when the ATS cache tag is assigned. Consequently, the device TLB cache tag is missed when the domain is attached, leading to the device TLB not being invalidated in the iommu_unmap paths. Fix it by moving the ATS enabling to the default domain attachment path, ensuring ATS is enabled before the cache tag assignment. Fixes: 4f1492efb495 ("iommu/vt-d: Revert ATS timing change to fix boot failure") Cc: stable@vger.kernel.org Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 7aa3932251b2..863ccb47bcca 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -54,6 +54,7 @@ __DOMAIN_MAX_PFN(gaw), (unsigned long)-1)) #define DOMAIN_MAX_ADDR(gaw) (((uint64_t)__DOMAIN_MAX_PFN(gaw)) << VTD_PAGE_SHIFT) +static void sm_iommu_enable_pcicaps(struct device *dev); static void __init check_tylersburg_isoch(void); static int rwbf_quirk; @@ -1825,10 +1826,11 @@ static int dmar_domain_attach_device(struct dmar_domain *domain, else ret = domain_setup_second_level(iommu, domain, dev, IOMMU_NO_PASID, NULL); - if (ret) goto out_block_translation; + /* PCI ATS enablement must happen before cache tag assigning. */ + sm_iommu_enable_pcicaps(dev); ret = cache_tag_assign_domain(domain, dev, IOMMU_NO_PASID); if (ret) goto out_block_translation; @@ -3765,11 +3767,18 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) return ERR_PTR(ret); } -static void intel_iommu_probe_finalize(struct device *dev) +static void sm_iommu_enable_pcicaps(struct device *dev) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu = info->iommu; + /* + * Called only in iommu_device_register() path when iommu is + * configured in the scalable mode. + */ + if (!sm_supported(iommu) || READ_ONCE(iommu->iommu.ready)) + return; + /* * The PCIe spec, in its wisdom, declares that the behaviour of the * device is undefined if you enable PASID support after ATS support. @@ -3780,7 +3789,7 @@ static void intel_iommu_probe_finalize(struct device *dev) !pci_enable_pasid(to_pci_dev(dev), info->pasid_supported & ~1)) info->pasid_enabled = 1; - if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) + if (!dev_is_real_dma_subdevice(dev)) iommu_enable_pci_ats(info); iommu_enable_pci_pri(info); } @@ -4309,6 +4318,7 @@ static int identity_domain_attach_dev(struct iommu_domain *domain, struct device ret = intel_pasid_setup_pass_through(iommu, dev, IOMMU_NO_PASID); else ret = device_setup_pass_through(dev); + sm_iommu_enable_pcicaps(dev); if (!ret) info->domain_attached = true; @@ -4359,7 +4369,6 @@ const struct iommu_ops intel_iommu_ops = { .domain_alloc_sva = intel_svm_domain_alloc, .domain_alloc_nested = intel_iommu_domain_alloc_nested, .probe_device = intel_iommu_probe_device, - .probe_finalize = intel_iommu_probe_finalize, .release_device = intel_iommu_release_device, .get_resv_regions = intel_iommu_get_resv_regions, .device_group = intel_iommu_device_group, -- 2.43.0