From nobody Sun May 10 23:25:58 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4BDCC433F5 for ; Thu, 21 Apr 2022 11:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388898AbiDULlh (ORCPT ); Thu, 21 Apr 2022 07:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347487AbiDULle (ORCPT ); Thu, 21 Apr 2022 07:41:34 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D83E2BB37 for ; Thu, 21 Apr 2022 04:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650541125; x=1682077125; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=osVQwJV/ZujaTApdG5eicPwbXUjaErfT37EPkI8Lc0g=; b=bWs+UoAx6K2+ayqtJoBqIGIU+US9H5/45d4wjJ1InKlRZeLO1Mldyh6H M7Wz2xKrwqYicaUd0WoFxSQdksQiXsZRtkNvMiBwhxxS/86YqobcLJlHm wrmx3KVtXeFEzlL9OPeqimci3r0/neh/0KAd+Rpz2l0tJdRFjN/xqXDCy mZRgA36kKim/j0BEXJnFgXqozM68Ne7icG+8PmkFDnoVF8gzU7CwtVp8S 8R5gVfKRepztWyqyeli4UHveAI61kqN6qYX6Qu9iR3MFemHP3M2gHjBHb zvz/kG7PD/5MDcS1wsN8FTf6t4ETVcXLfL+F3YYn38Q1pqmZY6KlKWE1y Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="264492183" X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="264492183" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 04:38:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="703047918" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga001.fm.intel.com with ESMTP; 21 Apr 2022 04:38:43 -0700 From: Lu Baolu To: Jacob jun Pan , Kevin Tian , Ashok Raj , Liu Yi L Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 1/4] iommu/vt-d: Check before setting PGSNP bit in pasid table entry Date: Thu, 21 Apr 2022 19:35:55 +0800 Message-Id: <20220421113558.3504874-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421113558.3504874-1-baolu.lu@linux.intel.com> References: <20220421113558.3504874-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The latest VT-d specification states that the PGSNP field in the pasid table entry should be treated as Reserved(0) for implementations not supporting Snoop Control (SC=3D0 in the Extended Capability Register). This adds a check before setting the field. Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index f8d215d85695..5cb2daa2b8cb 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -625,8 +625,14 @@ int intel_pasid_setup_first_level(struct intel_iommu *= iommu, } } =20 - if (flags & PASID_FLAG_PAGE_SNOOP) - pasid_set_pgsnp(pte); + if (flags & PASID_FLAG_PAGE_SNOOP) { + if (ecap_sc_support(iommu->ecap)) { + pasid_set_pgsnp(pte); + } else { + pasid_clear_entry(pte); + return -EINVAL; + } + } =20 pasid_set_domain_id(pte, did); pasid_set_address_width(pte, iommu->agaw); @@ -710,7 +716,8 @@ int intel_pasid_setup_second_level(struct intel_iommu *= iommu, pasid_set_fault_enable(pte); pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); =20 - if (domain->domain.type =3D=3D IOMMU_DOMAIN_UNMANAGED) + if (ecap_sc_support(iommu->ecap) && + domain->domain.type =3D=3D IOMMU_DOMAIN_UNMANAGED) pasid_set_pgsnp(pte); =20 /* --=20 2.25.1 From nobody Sun May 10 23:25:58 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3C7BC433F5 for ; Thu, 21 Apr 2022 11:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388910AbiDULlm (ORCPT ); Thu, 21 Apr 2022 07:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244998AbiDULlg (ORCPT ); Thu, 21 Apr 2022 07:41:36 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 022DF2C106 for ; Thu, 21 Apr 2022 04:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650541126; x=1682077126; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t+FgniAGQmeXacymlT2gSb61V603jB6flixJAZie7ew=; b=I2PlLDcve7ja5qOIfWmTnr8HJVRXqHB9UXHfsHLv73qJQGLD0EJWKuI9 oV3b/FO5Bk5LTYgndQ/rWqlpIp5Li/x0T6CE/EbegFo3Na8R5/aaOZEmZ h/nUXpG326qer4q//bBAT+JkDgcG9wXblzite1zt2PbC5UlRrVn7o/zon sVac8y4Xa/xXMylTsioDGl3Cl+fCwaIqwiZHH1tc/T8U+7t7FUiPjRDMv Z3Ck1aNtcdMhog3/U9H1Nqm7oVfj60+/ql+zCyZloLdRWJajMIEbwRDWB at7Hi6LsEgs+EhPUnKOHVaiNJuMxV2b1dXusnO7vOsm2rSag1oOX/fmdp g==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="264492186" X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="264492186" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 04:38:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="703047926" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga001.fm.intel.com with ESMTP; 21 Apr 2022 04:38:45 -0700 From: Lu Baolu To: Jacob jun Pan , Kevin Tian , Ashok Raj , Liu Yi L Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 2/4] iommu/vt-d: Set PGSNP bit in pasid table entry for SVA binding Date: Thu, 21 Apr 2022 19:35:56 +0800 Message-Id: <20220421113558.3504874-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421113558.3504874-1-baolu.lu@linux.intel.com> References: <20220421113558.3504874-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This field make the requests snoop processor caches irrespective of other attributes in the request or other fields in paging structure entries used to translate the request. Signed-off-by: Lu Baolu --- drivers/iommu/intel/svm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 23a38763c1d1..c720d1be992d 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -391,9 +391,12 @@ static struct iommu_sva *intel_svm_bind_mm(struct inte= l_iommu *iommu, } =20 /* Setup the pasid table: */ - sflags =3D (flags & SVM_FLAG_SUPERVISOR_MODE) ? - PASID_FLAG_SUPERVISOR_MODE : 0; - sflags |=3D cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; + sflags =3D PASID_FLAG_PAGE_SNOOP; + if (flags & SVM_FLAG_SUPERVISOR_MODE) + sflags |=3D PASID_FLAG_SUPERVISOR_MODE; + if (cpu_feature_enabled(X86_FEATURE_LA57)) + sflags |=3D PASID_FLAG_FL5LP; + spin_lock_irqsave(&iommu->lock, iflags); ret =3D intel_pasid_setup_first_level(iommu, dev, mm->pgd, mm->pasid, FLPT_DEFAULT_DID, sflags); --=20 2.25.1 From nobody Sun May 10 23:25:58 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32AE2C433F5 for ; Thu, 21 Apr 2022 11:38:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388914AbiDULlo (ORCPT ); Thu, 21 Apr 2022 07:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388901AbiDULli (ORCPT ); Thu, 21 Apr 2022 07:41:38 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25B1D2C124 for ; Thu, 21 Apr 2022 04:38:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650541129; x=1682077129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m643EXK7yOsfDONzYaJXtxPMlW05HUDqdqLxYq7AN30=; b=DE70bKoUYKqTBBTcb3S6BC4hsjAdEkhvGpGfSX//Cy7ZuBQFvLiyjqaX bAmoil/oLG2IHriQDUazNgIgUZk0G3SITGRz3cWcaLSRUHF2q3wdIBlbj 7no7oXDFky7frOh7Cy9pueZhhqOIne7S+XRX7MUrwhckCvQBlhdXytRx3 YPXeEyJ8ZSLdHIsu9VUk3lgRA6P5Xyuph61Once3G/G6KzaqUfnnnfHXe eTe4Sm+FNmLpqtJ1XTcxbfFGfXQR0YGbRfUNLe0dlvAVkK43xuP7Y1Dtg bBOO9DBTRLwiimc7xkpv58w/sWgvknuiI0dLuK6rRKXO0w8xaE8hPx8Vq Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="264492198" X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="264492198" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 04:38:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="703047933" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga001.fm.intel.com with ESMTP; 21 Apr 2022 04:38:47 -0700 From: Lu Baolu To: Jacob jun Pan , Kevin Tian , Ashok Raj , Liu Yi L Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [PATCH v2 3/4] iommu/vt-d: Drop stop marker messages Date: Thu, 21 Apr 2022 19:35:57 +0800 Message-Id: <20220421113558.3504874-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421113558.3504874-1-baolu.lu@linux.intel.com> References: <20220421113558.3504874-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The page fault handling framework in the IOMMU core explicitly states that it doesn't handle PCI PASID Stop Marker and the IOMMU drivers must discard them before reporting faults. This handles Stop Marker messages in prq_event_thread() before reporting events to the core. The VT-d driver explicitly drains the pending page requests when a CPU page table (represented by a mm struct) is unbound from a PASID according to the procedures defined in the VT-d spec. The Stop Marker messages do not need a response. Hence, it is safe to drop the Stop Marker messages silently if any of them is found in the page request queue. Fixes: d5b9e4bfe0d88 ("iommu/vt-d: Report prq to io-pgfault framework") Signed-off-by: Lu Baolu Reviewed-by: Jacob Pan Reviewed-by: Kevin Tian --- drivers/iommu/intel/svm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index c720d1be992d..0741ec165673 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -760,6 +760,10 @@ static irqreturn_t prq_event_thread(int irq, void *d) goto bad_req; } =20 + /* Drop Stop Marker message. No need for a response. */ + if (unlikely(req->lpig && !req->rd_req && !req->wr_req)) + goto prq_advance; + if (!svm || svm->pasid !=3D req->pasid) { /* * It can't go away, because the driver is not permitted --=20 2.25.1 From nobody Sun May 10 23:25:58 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EAF9C433EF for ; Thu, 21 Apr 2022 11:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388918AbiDULlt (ORCPT ); Thu, 21 Apr 2022 07:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388912AbiDULlm (ORCPT ); Thu, 21 Apr 2022 07:41:42 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E7232C111 for ; Thu, 21 Apr 2022 04:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650541131; x=1682077131; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TlJ1+MVmh4jBiR+OUjOQpWZePfw1j7kEuRwY1xJFAsk=; b=Jtf4JQyjLKDURaBJyxF1trWLqhaSkS8nWANhkEZygxiWJEcqlU3DnNOu wj8sgILxScmm43BnNUexyWxx4ARtXw2FE2PVSGH6SMcOyCplJtgrg8vfp C3m4LtSwqaLvop8RTxurTBjATrnEsbYsSbptdnUc83sW4lkWUjyugBQKU tk1Rw+wpJYYEL8Pd/q7frzsU0tQ5hf0FbsJp0eg9z7q4ulcZjdoYKjyXl +6JlIoVTqUgO9C5sYNS21X7dquuoQyiMMwDKs11Uk+YomvGwjXFjdPCbl 9hEXQpwAUzbTpchsDQvtupaaEHg6AleY7GDqkeUo2UaUthFrg2+TsYL8v Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="264492206" X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="264492206" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 04:38:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="703047964" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga001.fm.intel.com with ESMTP; 21 Apr 2022 04:38:49 -0700 From: Lu Baolu To: Jacob jun Pan , Kevin Tian , Ashok Raj , Liu Yi L Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 4/4] iommu/vt-d: Size Page Request Queue to avoid overflow condition Date: Thu, 21 Apr 2022 19:35:58 +0800 Message-Id: <20220421113558.3504874-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421113558.3504874-1-baolu.lu@linux.intel.com> References: <20220421113558.3504874-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" PRQ overflow may cause I/O throughput congestion, resulting in unnecessary degradation of I/O performance. Appropriately increasing the length of PRQ can greatly reduce the occurrence of PRQ overflow. The count of maximum page requests that can be generated in parallel by a PCIe device is statically defined in the Outstanding Page Request Capacity field of the PCIe ATS configure space. The new length of PRQ is calculated by summing up the value of Outstanding Page Request Capacity register across all devices where Page Requests are supported on the real PR-capable platform (Intel Sapphire Rapids). The result is round to the nearest higher power of 2. The PRQ length is also double sized as the VT-d IOMMU driver only updates the Page Request Queue Head Register (PQH_REG) after processing the entire queue. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- include/linux/intel-svm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/intel-svm.h b/include/linux/intel-svm.h index b3b125b332aa..207ef06ba3e1 100644 --- a/include/linux/intel-svm.h +++ b/include/linux/intel-svm.h @@ -9,7 +9,7 @@ #define __INTEL_SVM_H__ =20 /* Page Request Queue depth */ -#define PRQ_ORDER 2 +#define PRQ_ORDER 4 #define PRQ_RING_MASK ((0x1000 << PRQ_ORDER) - 0x20) #define PRQ_DEPTH ((0x1000 << PRQ_ORDER) >> 5) =20 --=20 2.25.1