Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp399398rdb; Thu, 25 Jan 2024 21:16:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZCuyR2ZKZVhcoOkSTwcSmSeZFYqf9XSZKO2iBhLoY2wWa2Bk57GadpBur/uqb7ufaBIPz X-Received: by 2002:a17:906:3488:b0:a2f:1df3:9912 with SMTP id g8-20020a170906348800b00a2f1df39912mr298580ejb.48.1706246176461; Thu, 25 Jan 2024 21:16:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706246176; cv=pass; d=google.com; s=arc-20160816; b=QWiLWC7ZBekMO9hn/6VnWd4kojbAQfCZdbOJgXx2qeq4x8Dh0bHYlmhfFOK0P9/HSh wfYZd6pNx6nZY7eGV6k+Foa1l/y/F4Ckhv2MYK4wWIC6Ed2qbHmwqNsBFHOUuBWGRkzE yiLMopoj8HyeR5xbcr15Z8pe5teodypStkea+oTncwixJD53QvUOAikOqdWnNFEAVf86 77RyDgOt7UWEVBOVGWQQMb5QwmDSm38jXmq+OUf6Fvg2/Nf1modIcm9cvITKCp/+bokS YXhMYCYsUUhSXMNfNdZm5Da45amGfZvlv5VeIfiprG84gV7r4OjMUhDKK07O3bhuc0sb RjkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=BaWVULQTC5vwGlu2YpDAvXNs5T6pEOM+s4aGHY4tf/Y=; fh=/SLtzouTDi4mp2pDtrWVI57CT6E/9R7N6aU04uxBbCs=; b=gLV1wn8JO0cwxa+uNQGU5DzOomvtVn7shVknXaLW4qqWwTr8eh6qut9W9R1L8RyXsH KL7gJlR6Vjh4CUBXL4fNrljRvY9ptbKBdB/0R7EmTrQWdC3FKMpH3cS/XnyuL3D+YajS ZRN2KtcwuW/IzKuqzB9ebYKcVhUm/BeE9qLVY+Ds2kAHSv2U3tjDvSVbn7LfSfkA0dPX wmrM43lOIq55Hwx4QTqOMFJJXBpGFh/xhiyLC/FJWvj/ZyIeDLYVVYfFTz3bXuAbrJ7z jaThquH4yaYVUCwMuw2FDFW3Uv1I0v+EFfd6GRS6G2QT0rJ6FKheDtix4QHRs/i9lrWE 4DHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oJZxwOJh; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u14-20020a1709063b8e00b00a34ac15e351si200375ejf.651.2024.01.25.21.16.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 21:16:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oJZxwOJh; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7AF1F1F21600 for ; Fri, 26 Jan 2024 01:40:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4F3867C54; Fri, 26 Jan 2024 01:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="oJZxwOJh" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 718D8EC3; Fri, 26 Jan 2024 01:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706233225; cv=none; b=jPAkGOpqRj8PVZmBFwLLyGuGNI2mywM3wxyKntasNJJ4XfjY4HOp3P5MiAvjeUlS1jI0SVGp0jcaCmCUcrWGB7swz+olVcx0tYBIdh6qXY22ZtmNHc/RR9mNki3N5i3DWlhuzFi7Zp9aRTTzo6fAV6fNtH2x1vZVdQ3Z1fD2DBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706233225; c=relaxed/simple; bh=4dlBSbHCmNEO4tqCGXWVdwuxmbBaTOw3I9YxMiM23sY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=eXOf4j7aiQBhzmr7/ILb/zd1dEvPnkAJYQKCy78i/UdaVlkJe55I2G7a6M+phWJXjpHSmPZmsvNqAMY30EALD8LD9/0S6DRpiaau36OQMTpyH3zgww/ixkZMjQMvzDl1NhJhiIdz4wLYcGCK2N8eaJ5jMf+4WxTsy2c3lP7fLKo= 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=oJZxwOJh; arc=none smtp.client-ip=198.175.65.10 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706233223; x=1737769223; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4dlBSbHCmNEO4tqCGXWVdwuxmbBaTOw3I9YxMiM23sY=; b=oJZxwOJhsAqNhJVm4g3ruRTDE6g42ggsxbm8+cC/Kl+t1ipTODVQNMsh veENgtfDmqJcXIciRD9SQoMrzT52yohmm4EfpmJAHW0ZbBSFu9cJUS+jo 9UYgxwPhie0L6WlYTanE3dOFeKb3gMJ9jcjT9gb62Hwii2sNa0xPBXanb NX85HazPbPEZy3LlNlJzjsdAU4LL673buAt9QjgqEa1+tn2P8yIKpvBtt dCpcDvcouUzkh6JwnX1GP9LYq7evz1yP3AkJsFBwx3NNv1/EBjzB3gE/A KDiUaZy4C8zwgGGuwGzZ+91AxQqKd1whORPhuq3kj+jrxU+fxSVr6XUIe A==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="15718431" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="15718431" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2024 17:40:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="2533076" Received: from unknown (HELO ply01-vm-store.amr.corp.intel.com) ([10.238.153.201]) by fmviesa003.fm.intel.com with ESMTP; 25 Jan 2024 17:40:19 -0800 From: Ethan Zhao To: baolu.lu@linux.intel.com, bhelgaas@google.com, robin.murphy@arm.com, jgg@ziepe.ca Cc: kevin.tian@intel.com, dwmw2@infradead.org, will@kernel.org, lukas@wunner.de, yi.l.liu@intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Ethan Zhao Subject: [PATCH v11 0/5] fix vt-d hard lockup when hotplug ATS capable device Date: Thu, 25 Jan 2024 20:39:57 -0500 Message-Id: <20240126014002.481294-1-haifeng.zhao@linux.intel.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patchset is used to fix vt-d hard lockup reported when surprise unplug ATS capable endpoint device connects to system via PCIe switch as following topology. +-[0000:15]-+-00.0 Intel Corporation Ice Lake Memory Map/VT-d | +-00.1 Intel Corporation Ice Lake Mesh 2 PCIe | +-00.2 Intel Corporation Ice Lake RAS | +-00.4 Intel Corporation Device 0b23 | \-01.0-[16-1b]----00.0-[17-1b]--+-00.0-[18]----00.0 NVIDIA Corporation Device 2324 | +-01.0-[19]----00.0 Mellanox Technologies MT2910 Family [ConnectX-7] User brought endpoint device 19:00.0's link down by flapping it's hotplug capable slot 17:01.0 link control register, as sequence DLLSC response, pciehp_ist() will unload device driver and power it off, durning device driver is unloading an iommu device-TLB invalidation (Intel VT-d spec, or 'ATS Invalidation' in PCIe spec) request issued to that link down device, thus a long time completion/timeout waiting in interrupt context causes continuous hard lockup warnning and system hang. Other detail, see every patch commit log. patch [1&2] were tested by yehaorong@bytedance.com on stable v6.7-rc4. patch [1-5] passed compiling on stable v6.8rc1. change log: v11: - update per latest comment and suggestion from Baolu and YiLiu. - split refactoring patch into two patches, [3/5] for simplify parameters and [4/5] for pdev parameter passing. - re-order patches. - fold target device presence check into qi_check_fault(). - combine patch[2][5] in v10 into one patch[5]. - some commit description correctness. - add fixes tag to patch[2/5]. - rebased on 6.8rc1 v10: - refactor qi_submit_sync() and its callers to get pci_dev instance, as Kevin pointed out add target_flush_dev to iommu is not right. v9: - unify all spelling of ATS Invalidation adhere to PCIe spec per Bjorn's suggestion. v8: - add a patch to break the loop for timeout device-TLB invalidation, as Bjorn said there is possibility device just no response but not gone. v7: - reorder patches and revise commit log per Bjorn's guide. - other code and commit log revise per Lukas' suggestion. - rebased to stable v6.7-rc6. v6: - add two patches to break out device-TLB invalidation if device is gone. v5: - add a patch try to fix the rare case (surprise remove a device in safe removal process). not work because surprise removal handling can't re-enter when another safe removal is in process. v4: - move the PCI device state checking after ATS per Baolu's suggestion. v3: - fix commit description typo. v2: - revise commit[1] description part according to Lukas' suggestion. - revise commit[2] description to clarify the issue's impact. v1: - https://lore.kernel.org/lkml/20231213034637.2603013-1-haifeng.zhao@ linux.intel.com/T/ Thanks, Ethan Ethan Zhao (5): PCI: make pci_dev_is_disconnected() helper public for other drivers iommu/vt-d: don't issue ATS Invalidation request when device is disconnected iommu/vt-d: simplify parameters of qi_submit_sync() ATS invalidation callers iommu/vt-d: pass pdev parameter for qi_check_fault() and refactor callers iommu/vt-d: improve ITE fault handling if target device isn't present drivers/iommu/intel/dmar.c | 71 +++++++++++++++++++++++------ drivers/iommu/intel/iommu.c | 26 +++-------- drivers/iommu/intel/iommu.h | 20 ++++---- drivers/iommu/intel/irq_remapping.c | 2 +- drivers/iommu/intel/nested.c | 9 +--- drivers/iommu/intel/pasid.c | 12 ++--- drivers/iommu/intel/svm.c | 13 +++--- drivers/pci/pci.h | 5 -- include/linux/pci.h | 5 ++ 9 files changed, 93 insertions(+), 70 deletions(-) -- 2.31.1