From patchwork Thu Feb 22 09:02:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ethan Zhao X-Patchwork-Id: 204689 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp186982dyb; Thu, 22 Feb 2024 03:30:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXYaa+PCq3IqbBRmnLj31RFdsnymsENYNMr3qZi9xQ0aKl22OK7o3YtmZF+uYw7Wlk9Zygl01WfQF8ZjEVwykMv1IodKw== X-Google-Smtp-Source: AGHT+IH38QaFDCYJOr0vbPa63rRTGriCiVMHIs51eM48/PBdCEdw07aTOm843EkbQHxxxP28Van9 X-Received: by 2002:a92:de48:0:b0:365:4b91:7cf9 with SMTP id e8-20020a92de48000000b003654b917cf9mr6364350ilr.26.1708601417267; Thu, 22 Feb 2024 03:30:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708601417; cv=pass; d=google.com; s=arc-20160816; b=cy9Yhy88FDe45sn0RhhHhJ0GJ2UvaxhjEFKzMbI6JjCQbr61Eh32iHc/ilSnYktAfQ nMLoZdkdmFWmiYjWAYce6U0Cl9FOBUxu9/3xY+epQVmB1AI8jUXiScvOB/zmPdoNZ3Fq MQUs97QPYeyUGRJC5fqHZrxtJQZ+eTUfbswJlTBe20ZAhavuxUir+jkiQBLjbZjTvdFJ ifAsZ7Uq/4MBuYGCUqBzYQge1aZfFfJACU/l7hQkKJCw9lN2GzFIjUoYIYZeAAp36wT8 xsZkKXFmwBN1wnxdnkeklq7OPBXFpnhv6r5ruBjzQiH5jzHHUNT2BcE63Y6iN7Zwtvbg M1zA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=D+b2YYnMcglSGwbebBuWw2/9+8HM1SsUieOBFSaXBS4=; fh=1X0ut6BtlQnZ1MoQItaqwKIGCqk6qNGAbHMp6ZD3eIQ=; b=CHzpfjD4hxeQq3j3jr4/HBg0/qDLH5ZP0WcreSpZpdif7Ewrbe6hrghNPgEKKSSX6B zPdRavToJzGmSwb3U0EMPoRcHjEZq85A66XIDs3CET5OYtxVAmbM3kLeEBaTHrkaXfbP YNHQ9VD1cVTFczrrtP0oeznYjeLib4gSorVINVS4b41t2Kx1juIDcmCvqQhlR4jHVI4t 7D+5XzEkg04l0WmR86fkvRB94+7K9csdvGkObLdZHJkKciQ7USw5hDf8H/YBpG1t6gu1 kFrHRRfKInS2Ntq0i7r5SdIMFrBI4Kzd8tVjoiuiSjJc296OtIbfioTTtWBoU9SBwxGi fsbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jPtVE1rM; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76171-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76171-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l25-20020a63ba59000000b005d64d951c89si10356624pgu.143.2024.02.22.03.30.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:30:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76171-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jPtVE1rM; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76171-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76171-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E27A42855EC for ; Thu, 22 Feb 2024 09:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EAE4381B4; Thu, 22 Feb 2024 09:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jPtVE1rM" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 A54F52261F; Thu, 22 Feb 2024 09:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592600; cv=none; b=bgAmgNy09GXei7DLfkBYHE93Z6G07sW5la1NoJgyaA68slq9vZ+PIepaFWMGvwIHw3hHmbeCnQKsDRlVSNe2jwXXIzqtRIIPMZfdBC7XzUcq69f7Hl4aUfPE+jUumb63GbddupmokzfP0U8IgsiDKMbieOjYoCuXkwoP+5Dt2Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592600; c=relaxed/simple; bh=qGvJdjdFOeQfZsaVurZBwtpkSGEkZOdq9FP4c2dHoM4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=To5J69wEInxLDajnhYrGD4sWKv0/CMO1Xf7bMJLn+GgJRhdOeZnHJh4D//7Zx8gRmSD0kEMILgCXwH0R8mLa92mrzZF2YEBiGE5rXHZhZC6sOUULvFMC2eQK1EgrVcLUWezV679hpQsV7vlnEDucN4Iv0v/RyS/fL+GUxHqbdjY= 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=jPtVE1rM; arc=none smtp.client-ip=198.175.65.9 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=1708592599; x=1740128599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qGvJdjdFOeQfZsaVurZBwtpkSGEkZOdq9FP4c2dHoM4=; b=jPtVE1rMxKHh2Ugo3xYKE74tM0fGb/N47Igw5vE6QKjmAqbwzWy5ah8F vCeoD31d4w92b8bJ+dxNoFj+C5+2XJb29DFfm/8von0aL2p7ouWok9UH9 GOo+ap0J8tGGdQEH/Rh70MbD45rwnco6BAoifXnPRKqjqkvu3taT0fX0q nreS5Ho0hsULeVVTEB03xvRF4xGzbRimA7tW47X2gvZYSZnWfIEdrRDwS 1KXkHYuHmFDqz0+0HbeGi5gjOAoHtcaJPFxpoUu+Yl2VGGm6KrmwN+oVq SV91V0GeP+r6PK9IrIO5XRTq4tjhLNU4MqokRc5mYS2E4yO9eTE7dFNpm A==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="25264451" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="25264451" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 01:03:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="10122632" Received: from unknown (HELO ply01-vm-store.amr.corp.intel.com) ([10.238.153.201]) by orviesa003.jf.intel.com with ESMTP; 22 Feb 2024 01:03:14 -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, dan.carpenter@linaro.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Ethan Zhao , Haorong Ye Subject: [PATCH v13 1/3] PCI: make pci_dev_is_disconnected() helper public for other drivers Date: Thu, 22 Feb 2024 04:02:49 -0500 Message-Id: <20240222090251.2849702-2-haifeng.zhao@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240222090251.2849702-1-haifeng.zhao@linux.intel.com> References: <20240222090251.2849702-1-haifeng.zhao@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791598439860825140 X-GMAIL-MSGID: 1791598439860825140 Make pci_dev_is_disconnected() public so that it can be called from Intel VT-d driver to quickly fix/workaround the surprise removal unplug hang issue for those ATS capable devices on PCIe switch downstream hotplug capable ports. Beside pci_device_is_present() function, this one has no config space space access, so is light enough to optimize the normal pure surprise removal and safe removal flow. Tested-by: Haorong Ye Signed-off-by: Ethan Zhao Reviewed-by: Dan Carpenter Acked-by: Bjorn Helgaas --- drivers/pci/pci.h | 5 ----- include/linux/pci.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index e9750b1b19ba..bfc56f7bee1c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -368,11 +368,6 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) return 0; } -static inline bool pci_dev_is_disconnected(const struct pci_dev *dev) -{ - return dev->error_state == pci_channel_io_perm_failure; -} - /* pci_dev priv_flags */ #define PCI_DEV_ADDED 0 #define PCI_DPC_RECOVERED 1 diff --git a/include/linux/pci.h b/include/linux/pci.h index 7ab0d13672da..213109d3c601 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2517,6 +2517,11 @@ static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev) return NULL; } +static inline bool pci_dev_is_disconnected(const struct pci_dev *dev) +{ + return dev->error_state == pci_channel_io_perm_failure; +} + void pci_request_acs(void); bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags); bool pci_acs_path_enabled(struct pci_dev *start, From patchwork Thu Feb 22 09:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ethan Zhao X-Patchwork-Id: 204690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp187031dyb; Thu, 22 Feb 2024 03:30:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU48F8aHb9L+YnyDf2XzqfjNIgTYTUt1V7QvTrBIo6jJNnA8ksXchDrFb/XxJ2IsPLKxRMwpts7AKmFnhWy2r7oQlzPiw== X-Google-Smtp-Source: AGHT+IHjNoLQQu6vXB9DSPikbzS9l7bUMVxUH+GSRwl2BysMUYSPDXC1vknV/+iv51X5iPljXMc7 X-Received: by 2002:a9d:6a8c:0:b0:6e2:dd76:1ee0 with SMTP id l12-20020a9d6a8c000000b006e2dd761ee0mr19959036otq.35.1708601422558; Thu, 22 Feb 2024 03:30:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708601422; cv=pass; d=google.com; s=arc-20160816; b=TakUAu3Z+Su0Rj4obr0g7ETGeMq1JAPbNAPIkwMJwC/ZkbzVqAdapIQsFYyLurnYj+ CrW70KrQOt/r8G5bm9x6K5r60DnEhaJZvchRsu/BI8pMryXIWGuDO+xQxGn+CIhfqG5A B57psJL1bhn1hIzTKgxElFQSgN9ql7esYVUGRUz/CdTArqh2GUHjNVtrw9LYhvUqC3Cc Q2zIm1S5w3GGK2tFoH+ng1V9/5IIueacCojFaU678qbZZpVYbDoYbdnz1wB1hs/4+YQE i9GCK4y/jz3EnL76cb1CATbGB7BsuK23H42NYMBFCoQlJpDjSfzayHbkv2+w8+GG+TE5 oJcw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Pgw/dTsbYpZhiEJ2SlY6woRny9ug9Q2R+gY4ePzbnao=; fh=1X0ut6BtlQnZ1MoQItaqwKIGCqk6qNGAbHMp6ZD3eIQ=; b=z9e6IyloBgTMO4opraopaK9H0miDhDRXBy5VoNZautWOO6WSansNIZlMb7N1qLXjvN od8aVfOK9zIH15/2srtGkAl/CQbBGC6w5kLYzUdz+vEKO0VTV/V6IrWa8vqlrHJENXpH +lAe+qmQbiNBMWFeMJfwWX2mR0K3t5LXbijTlh4VBLQZ8tYJuKlcRtCm4eoDemDdUwjs sJyfzi3uosyb8z0Zz7gKTT7JumrEqyR1cd194qgejX7vYT0URIybRQpuQccuoZkdalPs 9v3ldnqCE0YGJBncwjLAWZQYlaieG27kqXJxSmD6SVOGAntE+lL7bWbhxRk5KsFNcGbu pF4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="mz/+7ioc"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76172-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76172-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w23-20020a639357000000b005dbedf04f68si10548936pgm.10.2024.02.22.03.30.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:30:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76172-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="mz/+7ioc"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76172-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76172-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2495D2858EC for ; Thu, 22 Feb 2024 09:04:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3292D374DB; Thu, 22 Feb 2024 09:03:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mz/+7ioc" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 5B03F381D0; Thu, 22 Feb 2024 09:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592606; cv=none; b=U6NZdCBo75D0zdTT4SDrGv8u52bd2rZKnu06Vh55Zz24+yR65ZaL+xdNE6OJNDSw0TDf5XFtQucHmyuxaVZ7FZ2MRPDVuYcHVTTNI1BIe0BOghfMdvH8P2pdmKQMwTtbLWdrXqc7YzCiUdGr7fz9hVOehsGvErhXg/ezDPBdrMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592606; c=relaxed/simple; bh=a7XdviOurXqd+UxiwOvQTQYdFqRYCE9FWEvr4+FRLAA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gsm/1v+Pt8HmZyX++2pJCJmnoNiU1xaRMWDV8BYiVT3FBCkiVyoF1YnyBbxm9wgE3yTTMfpaXwIhNAIjsLmw0b7b6SrEOtmSm8IFpTuDsFIjxWQof+c9cpu9KarnP23LZu9oQqABC+nDd+93kR/A0qyrTDFjtWJKGClZiKrhw94= 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=mz/+7ioc; arc=none smtp.client-ip=198.175.65.9 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=1708592605; x=1740128605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a7XdviOurXqd+UxiwOvQTQYdFqRYCE9FWEvr4+FRLAA=; b=mz/+7iocUshVzC7gVnrX7J33X/4PHSNNTVUf6KSngaNoy82LGfqg+KVv dsmUr8hsKT0jbonEffJJCGX7LKY9exhWd5CYBtc4N4SnTWlS096OZLjhv RulBioy3YwOBSQzCsAvtPnQZ/6JMYQJHPlf7YdsW5sbND7tOGvEq5aK28 +IjfnmZjMPPyMCsHBZ/fIj6g1brT9+6C2fsWwp7KwVqAk8AI2jWEGxct0 V1GFU4lMHgIta3uw6Ax+7QRkdMtZMjYJo5/vvoogFKuNNYsYnmE1hxign y4wNjR7ki4MPZhF3MCH9aVv1ixcTla01iFfiDj1o61gUq/I2+woOWS6ys g==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="25264474" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="25264474" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 01:03:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="10122658" Received: from unknown (HELO ply01-vm-store.amr.corp.intel.com) ([10.238.153.201]) by orviesa003.jf.intel.com with ESMTP; 22 Feb 2024 01:03: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, dan.carpenter@linaro.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Ethan Zhao , Haorong Ye Subject: [PATCH v13 2/3] iommu/vt-d: don't issue ATS Invalidation request when device is disconnected Date: Thu, 22 Feb 2024 04:02:50 -0500 Message-Id: <20240222090251.2849702-3-haifeng.zhao@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240222090251.2849702-1-haifeng.zhao@linux.intel.com> References: <20240222090251.2849702-1-haifeng.zhao@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791598445156165011 X-GMAIL-MSGID: 1791598445156165011 For those endpoint devices connect to system via hotplug capable ports, users could request a hot reset to the device by flapping device's link through setting the slot's link control register, as pciehp_ist() DLLSC interrupt sequence response, pciehp will unload the device driver and then power it off. thus cause an IOMMU device-TLB invalidation (Intel VT-d spec, or ATS Invalidation in PCIe spec r6.1) request for non-existence target device to be sent and deadly loop to retry that request after ITE fault triggered in interrupt context. That would cause following continuous hard lockup warning and system hang [ 4211.433662] pcieport 0000:17:01.0: pciehp: Slot(108): Link Down [ 4211.433664] pcieport 0000:17:01.0: pciehp: Slot(108): Card not present [ 4223.822591] NMI watchdog: Watchdog detected hard LOCKUP on cpu 144 [ 4223.822622] CPU: 144 PID: 1422 Comm: irq/57-pciehp Kdump: loaded Tainted: G S OE kernel version xxxx [ 4223.822623] Hardware name: vendorname xxxx 666-106, BIOS 01.01.02.03.01 05/15/2023 [ 4223.822623] RIP: 0010:qi_submit_sync+0x2c0/0x490 [ 4223.822624] Code: 48 be 00 00 00 00 00 08 00 00 49 85 74 24 20 0f 95 c1 48 8b 57 10 83 c1 04 83 3c 1a 03 0f 84 a2 01 00 00 49 8b 04 24 8b 70 34 <40> f6 c6 1 0 74 17 49 8b 04 24 8b 80 80 00 00 00 89 c2 d3 fa 41 39 [ 4223.822624] RSP: 0018:ffffc4f074f0bbb8 EFLAGS: 00000093 [ 4223.822625] RAX: ffffc4f040059000 RBX: 0000000000000014 RCX: 0000000000000005 [ 4223.822625] RDX: ffff9f3841315800 RSI: 0000000000000000 RDI: ffff9f38401a8340 [ 4223.822625] RBP: ffff9f38401a8340 R08: ffffc4f074f0bc00 R09: 0000000000000000 [ 4223.822626] R10: 0000000000000010 R11: 0000000000000018 R12: ffff9f384005e200 [ 4223.822626] R13: 0000000000000004 R14: 0000000000000046 R15: 0000000000000004 [ 4223.822626] FS: 0000000000000000(0000) GS:ffffa237ae400000(0000) knlGS:0000000000000000 [ 4223.822627] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 4223.822627] CR2: 00007ffe86515d80 CR3: 000002fd3000a001 CR4: 0000000000770ee0 [ 4223.822627] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 4223.822628] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400 [ 4223.822628] PKRU: 55555554 [ 4223.822628] Call Trace: [ 4223.822628] qi_flush_dev_iotlb+0xb1/0xd0 [ 4223.822628] __dmar_remove_one_dev_info+0x224/0x250 [ 4223.822629] dmar_remove_one_dev_info+0x3e/0x50 [ 4223.822629] intel_iommu_release_device+0x1f/0x30 [ 4223.822629] iommu_release_device+0x33/0x60 [ 4223.822629] iommu_bus_notifier+0x7f/0x90 [ 4223.822630] blocking_notifier_call_chain+0x60/0x90 [ 4223.822630] device_del+0x2e5/0x420 [ 4223.822630] pci_remove_bus_device+0x70/0x110 [ 4223.822630] pciehp_unconfigure_device+0x7c/0x130 [ 4223.822631] pciehp_disable_slot+0x6b/0x100 [ 4223.822631] pciehp_handle_presence_or_link_change+0xd8/0x320 [ 4223.822631] pciehp_ist+0x176/0x180 [ 4223.822631] ? irq_finalize_oneshot.part.50+0x110/0x110 [ 4223.822632] irq_thread_fn+0x19/0x50 [ 4223.822632] irq_thread+0x104/0x190 [ 4223.822632] ? irq_forced_thread_fn+0x90/0x90 [ 4223.822632] ? irq_thread_check_affinity+0xe0/0xe0 [ 4223.822633] kthread+0x114/0x130 [ 4223.822633] ? __kthread_cancel_work+0x40/0x40 [ 4223.822633] ret_from_fork+0x1f/0x30 [ 4223.822633] Kernel panic - not syncing: Hard LOCKUP [ 4223.822634] CPU: 144 PID: 1422 Comm: irq/57-pciehp Kdump: loaded Tainted: G S OE kernel version xxxx [ 4223.822634] Hardware name: vendorname xxxx 666-106, BIOS 01.01.02.03.01 05/15/2023 [ 4223.822634] Call Trace: [ 4223.822634] [ 4223.822635] dump_stack+0x6d/0x88 [ 4223.822635] panic+0x101/0x2d0 [ 4223.822635] ? ret_from_fork+0x11/0x30 [ 4223.822635] nmi_panic.cold.14+0xc/0xc [ 4223.822636] watchdog_overflow_callback.cold.8+0x6d/0x81 [ 4223.822636] __perf_event_overflow+0x4f/0xf0 [ 4223.822636] handle_pmi_common+0x1ef/0x290 [ 4223.822636] ? __set_pte_vaddr+0x28/0x40 [ 4223.822637] ? flush_tlb_one_kernel+0xa/0x20 [ 4223.822637] ? __native_set_fixmap+0x24/0x30 [ 4223.822637] ? ghes_copy_tofrom_phys+0x70/0x100 [ 4223.822637] ? __ghes_peek_estatus.isra.16+0x49/0xa0 [ 4223.822637] intel_pmu_handle_irq+0xba/0x2b0 [ 4223.822638] perf_event_nmi_handler+0x24/0x40 [ 4223.822638] nmi_handle+0x4d/0xf0 [ 4223.822638] default_do_nmi+0x49/0x100 [ 4223.822638] exc_nmi+0x134/0x180 [ 4223.822639] end_repeat_nmi+0x16/0x67 [ 4223.822639] RIP: 0010:qi_submit_sync+0x2c0/0x490 [ 4223.822639] Code: 48 be 00 00 00 00 00 08 00 00 49 85 74 24 20 0f 95 c1 48 8b 57 10 83 c1 04 83 3c 1a 03 0f 84 a2 01 00 00 49 8b 04 24 8b 70 34 <40> f6 c6 10 74 17 49 8b 04 24 8b 80 80 00 00 00 89 c2 d3 fa 41 39 [ 4223.822640] RSP: 0018:ffffc4f074f0bbb8 EFLAGS: 00000093 [ 4223.822640] RAX: ffffc4f040059000 RBX: 0000000000000014 RCX: 0000000000000005 [ 4223.822640] RDX: ffff9f3841315800 RSI: 0000000000000000 RDI: ffff9f38401a8340 [ 4223.822641] RBP: ffff9f38401a8340 R08: ffffc4f074f0bc00 R09: 0000000000000000 [ 4223.822641] R10: 0000000000000010 R11: 0000000000000018 R12: ffff9f384005e200 [ 4223.822641] R13: 0000000000000004 R14: 0000000000000046 R15: 0000000000000004 [ 4223.822641] ? qi_submit_sync+0x2c0/0x490 [ 4223.822642] ? qi_submit_sync+0x2c0/0x490 [ 4223.822642] [ 4223.822642] qi_flush_dev_iotlb+0xb1/0xd0 [ 4223.822642] __dmar_remove_one_dev_info+0x224/0x250 [ 4223.822643] dmar_remove_one_dev_info+0x3e/0x50 [ 4223.822643] intel_iommu_release_device+0x1f/0x30 [ 4223.822643] iommu_release_device+0x33/0x60 [ 4223.822643] iommu_bus_notifier+0x7f/0x90 [ 4223.822644] blocking_notifier_call_chain+0x60/0x90 [ 4223.822644] device_del+0x2e5/0x420 [ 4223.822644] pci_remove_bus_device+0x70/0x110 [ 4223.822644] pciehp_unconfigure_device+0x7c/0x130 [ 4223.822644] pciehp_disable_slot+0x6b/0x100 [ 4223.822645] pciehp_handle_presence_or_link_change+0xd8/0x320 [ 4223.822645] pciehp_ist+0x176/0x180 [ 4223.822645] ? irq_finalize_oneshot.part.50+0x110/0x110 [ 4223.822645] irq_thread_fn+0x19/0x50 [ 4223.822646] irq_thread+0x104/0x190 [ 4223.822646] ? irq_forced_thread_fn+0x90/0x90 [ 4223.822646] ? irq_thread_check_affinity+0xe0/0xe0 [ 4223.822646] kthread+0x114/0x130 [ 4223.822647] ? __kthread_cancel_work+0x40/0x40 [ 4223.822647] ret_from_fork+0x1f/0x30 [ 4223.822647] Kernel Offset: 0x6400000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) Such issue could be triggered by all kinds of regular surprise removal hotplug operation. like: 1. pull EP(endpoint device) out directly. 2. turn off EP's power. 3. bring the link down. etc. this patch aims to work for regular safe removal and surprise removal unplug. these hot unplug handling process could be optimized for fix the ATS Invalidation hang issue by calling pci_dev_is_disconnected() in function devtlb_invalidation_with_pasid() to check target device state to avoid sending meaningless ATS Invalidation request to iommu when device is gone. (see IMPLEMENTATION NOTE in PCIe spec r6.1 section 10.3.1) For safe removal, device wouldn't be removed until the whole software handling process is done, it wouldn't trigger the hard lock up issue caused by too long ATS Invalidation timeout wait. In safe removal path, device state isn't set to pci_channel_io_perm_failure in pciehp_unconfigure_device() by checking 'presence' parameter, calling pci_dev_is_disconnected() in devtlb_invalidation_with_pasid() will return false there, wouldn't break the function. For surprise removal, device state is set to pci_channel_io_perm_failure in pciehp_unconfigure_device(), means device is already gone (disconnected) call pci_dev_is_disconnected() in devtlb_invalidation_with_pasid() will return true to break the function not to send ATS Invalidation request to the disconnected device blindly, thus avoid to trigger further ITE fault, and ITE fault will block all invalidation request to be handled. furthermore retry the timeout request could trigger hard lockup. safe removal (present) & surprise removal (not present) pciehp_ist() pciehp_handle_presence_or_link_change() pciehp_disable_slot() remove_board() pciehp_unconfigure_device(presence) { if (!presence) pci_walk_bus(parent, pci_dev_set_disconnected, NULL); } this patch works for regular safe removal and surprise removal of ATS capable endpoint on PCIe switch downstream ports. Fixes: 6f7db75e1c46 ("iommu/vt-d: Add second level page table interface") Tested-by: Haorong Ye Signed-off-by: Ethan Zhao --- drivers/iommu/intel/pasid.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 108158e2b907..746c7abe2237 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -214,6 +214,9 @@ devtlb_invalidation_with_pasid(struct intel_iommu *iommu, if (!info || !info->ats_enabled) return; + if (pci_dev_is_disconnected(to_pci_dev(dev))) + return; + sid = info->bus << 8 | info->devfn; qdep = info->ats_qdep; pfsid = info->pfsid; From patchwork Thu Feb 22 09:02:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ethan Zhao X-Patchwork-Id: 204735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp208082dyb; Thu, 22 Feb 2024 04:13:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUkwVuEhQbOD1Aj7iiaLnvJTX22IwU/v/2L7tLgu+EsbhqUXonSDUbJ8qwUyxQ2O88/NcO3GRMnAITE/Q3koRO3BWF35A== X-Google-Smtp-Source: AGHT+IEillMA7NHU2zBsO9I8iI2BFlAW6XUx+GNuwoMArh/Nb88vKg+RLGMAfJBcEpihUhCF5um1 X-Received: by 2002:a17:902:e74d:b0:1db:a7bb:492d with SMTP id p13-20020a170902e74d00b001dba7bb492dmr3869411plf.5.1708603992488; Thu, 22 Feb 2024 04:13:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708603992; cv=pass; d=google.com; s=arc-20160816; b=SJ1mwi/Vdiztj3cbLmq7VRU+/4b6NsWUmViIBuZIwnGjkzqy4JEFCHiqY7aAuyDkQb sxYgHMjBJcx1umJWxqRmOobm6v82GH0JYKMG8LZZ20tQw3mYzNP7Q3EaGmL+fCvi9290 Vx67IgRkvFG4/qYDBQMaA1Ugq5037QmzjacmFyU46KeYoCJ9LRgejmdoSn9PpiUqCCPr njtbCJ5GgTDizz8GBgeB70BPO0LzWmxnvvIcmZsQt2Iq0nAlehsPzHN+zTOuSyHgb2+L FXz30akbuoavr+aZy4ipJ5cm9krm4nrmsdlWvlj5KwzXbtLe9balU3dcKKTBXHR4xmar b1ZQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PLJ+T6WgZfQgfk7JAxosBbzyNz5CaDh/l6tJpypOhUY=; fh=62zCyG6BMACN0313G+YF0v6oBqRpWy19jEzQzayzTn8=; b=ZYXgDwHBUZ3XrCRipn2zzTMkaEJ86zUpTS/NqYW1QgjQ1CEwsFAs6jbSD6vhz2H/J0 BMiyP/FJDhqEawajAoFjaO/uQEDwCwX17o5X9K0kokuZrb4YHLGGLitmMrekhnsrOcEq 36CNEmusa46fEg1B9m8WYx3+lMcLf9LkYlK4VDzraDLR/lM81AmYN60z3fb0Xnb5Fhel kpEEnvbKhmbWnDyVrDrwYqZLZq930LimmVvMcFGCSjfPySKJhJjUTuvl/YawSKurmCJw l0dpPH7H95S2VDJ5Gjo250/MK97x0Uy4TcCf4miPb3xmSngMIhXosMIz6URenR0Ou9Jp BR3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=An46a9oW; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76173-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76173-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o9-20020a170902d4c900b001d944e92be8si10125869plg.146.2024.02.22.04.13.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 04:13:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76173-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=An46a9oW; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76173-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76173-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 25E4DB255F8 for ; Thu, 22 Feb 2024 09:04:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6702F38FB9; Thu, 22 Feb 2024 09:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="An46a9oW" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 76C2C374E6; Thu, 22 Feb 2024 09:03:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592612; cv=none; b=DaS8AV9PdNlFIVAH7HWKcdxoAhKy3/dC1EyVX8d/ez4XMNQPo031iiAxquPOer2S99BXEF+8kmg0yoZ7CerC6SQh68uUFYjRZckNDwmM5sU2L0flZAk0qry836mXjAVlS/I6XVwprmdbrlCW1oX9Kr+IPI9JJBTEpM60Pr488+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592612; c=relaxed/simple; bh=Ufbfc9qGqnc9GmviuGU5ACXNF84S20F4WyXi3i5SB2A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aKos6oZ/fgEePtEhTTiZBi8czhxej1HUK9epkaq48jSVE0Viv9hMXFaw0DOYqaoTcu7AUkvcONJEHBDwKQHYWIoduwoilQoGdEyj6FosEOGg1nmFZ60o7I7nU6+jx66BH5y7dHLcp/wHGy2yJojjJmkTsTN/K6/O+DJjVhC/nOQ= 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=An46a9oW; arc=none smtp.client-ip=198.175.65.9 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=1708592612; x=1740128612; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ufbfc9qGqnc9GmviuGU5ACXNF84S20F4WyXi3i5SB2A=; b=An46a9oWu7+08JXZGZIDKX428jFFteAKwCuhJuUnQTlRKL8uZKKXLAR1 SGmAl4qwqkm4XFYI0jBEXRM/+G7fHZmEGSSkQ85P9gfBfEo2GvdM54Are MPXXoSVpdC1wk7cRd95j2noF8mvbRmkFuR28KxiT50V+Xmvz3J/ATA+tJ AtvJQ3myqfeLEOGccmadheoOfvLtzrzHE60zU8PpOMzqcUw/kNMIEPEpK 5z2E1evEB4g/sqES/E5Snd3CcIWjfMwgo3Xr7o+gwQxGqfo/COdCeQjax BZW55863HAKWhGsXyt5uVS+BzSp3NXVgpYLUBWYhDNLbH4h84cr63HXdg g==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="25264497" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="25264497" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 01:03:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="10122703" Received: from unknown (HELO ply01-vm-store.amr.corp.intel.com) ([10.238.153.201]) by orviesa003.jf.intel.com with ESMTP; 22 Feb 2024 01:03:27 -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, dan.carpenter@linaro.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Ethan Zhao Subject: [PATCH v13 3/3] iommu/vt-d: improve ITE fault handling if target device isn't valid Date: Thu, 22 Feb 2024 04:02:51 -0500 Message-Id: <20240222090251.2849702-4-haifeng.zhao@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240222090251.2849702-1-haifeng.zhao@linux.intel.com> References: <20240222090251.2849702-1-haifeng.zhao@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791598081273975017 X-GMAIL-MSGID: 1791601139791379141 Because surprise removal could happen anytime, e.g. user could request safe removal to EP(endpoint device) via sysfs and brings its link down to do surprise removal cocurrently. such aggressive cases would cause ATS invalidation request issued to non-existence target device, then deadly loop to retry that request after ITE fault triggered in interrupt context. this patch aims to optimize the ITE handling by checking the target device presence state to avoid retrying the timeout request blindly, thus avoid hard lockup or system hang. Devices are valid ATS invalidation request target only when they reside in the iommu->device_rbtre (probed, not released) and present. Signed-off-by: Ethan Zhao --- drivers/iommu/intel/dmar.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index d14797aabb7a..d01d68205557 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -1273,6 +1273,9 @@ static int qi_check_fault(struct intel_iommu *iommu, int index, int wait_index) { u32 fault; int head, tail; + u64 iqe_err, ite_sid; + struct device *dev = NULL; + struct pci_dev *pdev = NULL; struct q_inval *qi = iommu->qi; int shift = qi_shift(iommu); @@ -1317,6 +1320,13 @@ static int qi_check_fault(struct intel_iommu *iommu, int index, int wait_index) tail = readl(iommu->reg + DMAR_IQT_REG); tail = ((tail >> shift) - 1 + QI_LENGTH) % QI_LENGTH; + /* + * SID field is valid only when the ITE field is Set in FSTS_REG + * see Intel VT-d spec r4.1, section 11.4.9.9 + */ + iqe_err = dmar_readq(iommu->reg + DMAR_IQER_REG); + ite_sid = DMAR_IQER_REG_ITESID(iqe_err); + writel(DMA_FSTS_ITE, iommu->reg + DMAR_FSTS_REG); pr_info("Invalidation Time-out Error (ITE) cleared\n"); @@ -1326,6 +1336,21 @@ static int qi_check_fault(struct intel_iommu *iommu, int index, int wait_index) head = (head - 2 + QI_LENGTH) % QI_LENGTH; } while (head != tail); + /* + * If got ITE, we need to check if the sid of ITE is one of the + * current valid ATS invalidation target devices, if no, or the + * target device isn't presnet, don't try this request anymore. + * 0 value of ite_sid means old VT-d device, no ite_sid value. + */ + if (ite_sid) { + dev = device_rbtree_find(iommu, ite_sid); + if (!dev || !dev_is_pci(dev)) + return -ETIMEDOUT; + pdev = to_pci_dev(dev); + if (!pci_device_is_present(pdev) && + ite_sid == pci_dev_id(pci_physfn(pdev))) + return -ETIMEDOUT; + } if (qi->desc_status[wait_index] == QI_ABORT) return -EAGAIN; }