From nobody Wed Dec 17 02:25:59 2025 Received: from sg-1-103.ptr.blmpb.com (sg-1-103.ptr.blmpb.com [118.26.132.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 475751A9B46 for ; Thu, 11 Dec 2025 04:01:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.103 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765425700; cv=none; b=AgioW32jpgPaLztNGZSqo1OoRvOQp3gQC+oTyBMis4VCU+Zl2xYcK+z7uNxXU3jq9E7WhtfbMY7DIAIkPWlv9aN2+EfDvCuos0lb7CN5J1/AE+hfOZsmXJkMBQkLNTo3Bex4deZz/hdGS6axnUeo0fNnvA8Q4SbKTUa33s6rytM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765425700; c=relaxed/simple; bh=4Q6NgeycfZthGEeAHFhDPjP2yvbchRqZ4whFCZCWnBg=; h=References:To:Cc:Subject:Date:Mime-Version:Message-Id:In-Reply-To: Content-Type:From; b=dcfV9uZD5SGVd0xgL3XcImnrQsZ1RrmJXgH9BCISnOpKtl1tMvOWr/N9cwIk4XziZYCEU0jL5xy2bjuMq8yW0MzlKn8Po5ddhLS2GKN/ES4rvjy4+dGlFubKy/ynYGgWJgdpzO7Ez0TwKJEQiRQuNRZB2/2NUc7S+rxBnhyGIVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=j5xh8t2i; arc=none smtp.client-ip=118.26.132.103 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="j5xh8t2i" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1765425691; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=9UfJ9VIVOS38iGxyFptQJegd8mcO/MEORiq3nC7/r9Y=; b=j5xh8t2iNTYYp1IriO5eV6INcxfxegpTIEQCJ0G8/rfhyMTaZZqoXbpYR0uK1iYPAn2dAZ Td7NMVAdd5Jo9epajNyM5uacgDbuZNbi/ezrM/Rq4EWMP0kj0y6yZPpJNeTbbsMtMk0Jey ttCwiX6Ze8YGTZXEdw1P8nZtkd/JQDTD3l4XH0wbQzxA/67OTFSQHrbwAgysBbwS8G5LSk t1LiZR87/FhdofDjr24Qdjdm3uEidsnvNffXDJ/WdvOn+xVuenhMLNL+w+48Y0iYEYUP8p xTcdNBBNxXt8RIXS8x9WIJSNlyieeNIlaafxC39+QfDne2BFNKIQlrc456gurA== References: <20251211035946.2071-1-guojinhui.liam@bytedance.com> X-Lms-Return-Path: Content-Transfer-Encoding: quoted-printable To: , , , Cc: , , , Subject: [PATCH v2 2/2] iommu/vt-d: Flush dev-IOTLB only when PCIe device is accessible in scalable mode Date: Thu, 11 Dec 2025 11:59:46 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Original-From: Jinhui Guo Message-Id: <20251211035946.2071-3-guojinhui.liam@bytedance.com> In-Reply-To: <20251211035946.2071-1-guojinhui.liam@bytedance.com> From: "Jinhui Guo" X-Mailer: git-send-email 2.17.1 Content-Type: text/plain; charset="utf-8" Commit 4fc82cd907ac ("iommu/vt-d: Don't issue ATS Invalidation request when device is disconnected") relies on pci_dev_is_disconnected() to skip ATS invalidation for safely-removed devices, but it does not cover link-down caused by faults, which can still hard-lock the system. For example, if a VM fails to connect to the PCIe device, "virsh destroy" is executed to release resources and isolate the fault, but a hard-lockup occurs while releasing the group fd. Call Trace: qi_submit_sync qi_flush_dev_iotlb intel_pasid_tear_down_entry device_block_translation blocking_domain_attach_dev __iommu_attach_device __iommu_device_set_domain __iommu_group_set_domain_internal iommu_detach_group vfio_iommu_type1_detach_group vfio_group_detach_container vfio_group_fops_release __fput Although pci_device_is_present() is slower than pci_dev_is_disconnected(), it still takes only ~70 =C2=B5s on a ConnectX-5 (8 GT/s, x2) and becomes even faster as PCIe speed and width increase. Besides, devtlb_invalidation_with_pasid() is called only in the paths below, which are far less frequent than memory map/unmap. 1. mm-struct release 2. {attach,release}_dev 3. set/remove PASID 4. dirty-tracking setup The gain in system stability far outweighs the negligible cost of using pci_device_is_present() instead of pci_dev_is_disconnected() to decide when to skip ATS invalidation, especially under GDR high-load conditions. Fixes: 4fc82cd907ac ("iommu/vt-d: Don't issue ATS Invalidation request when= device is disconnected") Cc: stable@vger.kernel.org Signed-off-by: Jinhui Guo --- drivers/iommu/intel/pasid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index a369690f5926..e64d445de964 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -218,7 +218,7 @@ devtlb_invalidation_with_pasid(struct intel_iommu *iomm= u, if (!info || !info->ats_enabled) return; =20 - if (pci_dev_is_disconnected(to_pci_dev(dev))) + if (!pci_device_is_present(to_pci_dev(dev))) return; =20 sid =3D PCI_DEVID(info->bus, info->devfn); --=20 2.20.1