From nobody Wed Feb 11 18:10:14 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 62DC3C76196 for ; Tue, 11 Apr 2023 06:49:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbjDKGtO (ORCPT ); Tue, 11 Apr 2023 02:49:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbjDKGsx (ORCPT ); Tue, 11 Apr 2023 02:48:53 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4784B40FF for ; Mon, 10 Apr 2023 23:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195708; x=1712731708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fpVkDsplOKC7+81q+F4+kKKHQl9TZ6EMsQnwtXNojzI=; b=S6+7uKXHrVo3r2JxuG52joutgHQYSDd1VBtONTZA0/gtrQtY2Ikyal17 7JdTElYVxxxkuA7KUWR2UVshQAUrQk9anhAGbsG4zExyNo1k/kSwM2Cp/ x8FCp7oajvzELYd6SkpZTiN0rS3VlQFEV2d2qBCt2zzIAaIhrKp0fmdSe S1Tb9Y/PFgF2t3Cbq1qEjIIj0KaC1zOMfSb16iVPE+vyrbfwj2rTis1iT 2lWwq5fVOAP8SqG3zBvyzE047AeNjhuN+zGY1xGOHtxgJd5fiL5Nk07/i PXIVptBa0021Pf/BCdZ5AGL3hA1TpXUbPJdIACGjOKJ8bzKAoXBWLZwgm w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028496" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028496" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256517" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256517" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:11 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 01/17] dmaengine: idxd: Add enable/disable device IOPF feature Date: Tue, 11 Apr 2023 14:47:59 +0800 Message-Id: <20230411064815.31456-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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 iommu subsystem requires IOMMU_DEV_FEAT_IOPF must be enabled before and disabled after IOMMU_DEV_FEAT_SVA, if device's I/O page faults rely on the IOMMU. Add explicit IOMMU_DEV_FEAT_IOPF enabling/disabling in this driver. At present, missing IOPF enabling/disabling doesn't cause any real issue, because the IOMMU driver places the IOPF enabling/disabling in the path of SVA feature handling. But this may change. Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-2-baolu.lu@linux.inte= l.com Acked-by: Vinod Koul --- drivers/dma/idxd/init.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 640d3048368e..09ef62aa0635 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -516,6 +516,27 @@ static void idxd_disable_system_pasid(struct idxd_devi= ce *idxd) idxd->sva =3D NULL; } =20 +static int idxd_enable_sva(struct pci_dev *pdev) +{ + int ret; + + ret =3D iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); + if (ret) + return ret; + + ret =3D iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); + if (ret) + iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); + + return ret; +} + +static void idxd_disable_sva(struct pci_dev *pdev) +{ + iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); + iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); +} + static int idxd_probe(struct idxd_device *idxd) { struct pci_dev *pdev =3D idxd->pdev; @@ -530,7 +551,7 @@ static int idxd_probe(struct idxd_device *idxd) dev_dbg(dev, "IDXD reset complete\n"); =20 if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) && sva) { - if (iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_SVA)) { + if (idxd_enable_sva(pdev)) { dev_warn(dev, "Unable to turn on user SVA feature.\n"); } else { set_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags); @@ -578,21 +599,19 @@ static int idxd_probe(struct idxd_device *idxd) if (device_pasid_enabled(idxd)) idxd_disable_system_pasid(idxd); if (device_user_pasid_enabled(idxd)) - iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_SVA); + idxd_disable_sva(pdev); return rc; } =20 static void idxd_cleanup(struct idxd_device *idxd) { - struct device *dev =3D &idxd->pdev->dev; - perfmon_pmu_remove(idxd); idxd_cleanup_interrupts(idxd); idxd_cleanup_internals(idxd); if (device_pasid_enabled(idxd)) idxd_disable_system_pasid(idxd); if (device_user_pasid_enabled(idxd)) - iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_SVA); + idxd_disable_sva(idxd->pdev); } =20 static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id= *id) @@ -710,7 +729,7 @@ static void idxd_remove(struct pci_dev *pdev) pci_free_irq_vectors(pdev); pci_iounmap(pdev, idxd->reg_base); if (device_user_pasid_enabled(idxd)) - iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); + idxd_disable_sva(pdev); pci_disable_device(pdev); destroy_workqueue(idxd->wq); perfmon_pmu_remove(idxd); --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 38D65C76196 for ; Tue, 11 Apr 2023 06:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230414AbjDKGtU (ORCPT ); Tue, 11 Apr 2023 02:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230430AbjDKGsy (ORCPT ); Tue, 11 Apr 2023 02:48:54 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E45744AE for ; Mon, 10 Apr 2023 23:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195717; x=1712731717; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rMHo8yYSBVXvdzGdpugvYObeZKKcdE/cMZKOA3T4vNU=; b=TANIm8Aa2l+BxJt/94b5Eh4ELo/utgeM/03osoMLzbwrw0jZMk94pXq3 +xmoSgFB54tjLoppcGuDsckqwyB6/ZUiyd4ltn42ZGcLySdy4zWpGw97D HM4fDVxcQNAiwkh8gQ3UAHgEPy6C/Us2XhwQRr5z1eVQzSZFRAZVNQ363 v0n7bRimIMSTwZk4mHk5jbGctNyg0yr+ih3xkwIsENFrGuLSl+XWI9KjC 3O41Sl/F8o3QW7SFkHPFa2fZmVbDeM9S9NmjubhZ0hjKGmPQALtcNHbfZ 8OZSLMXNEbzUNElQeDpx/EJ/YOwPootmR8LZTFrsNn5fIT7rSqiSYtm9b A==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028504" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028504" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256541" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256541" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:13 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 02/17] iommu/vt-d: Allow SVA with device-specific IOPF Date: Tue, 11 Apr 2023 14:48:00 +0800 Message-Id: <20230411064815.31456-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" Currently enabling SVA requires IOPF support from the IOMMU and device PCI PRI. However, some devices can handle IOPF by itself without ever sending PCI page requests nor advertising PRI capability. Allow SVA support with IOPF handled either by IOMMU (PCI PRI) or device driver (device-specific IOPF). As long as IOPF could be handled, SVA should continue to work. Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-3-baolu.lu@linux.inte= l.com --- drivers/iommu/intel/iommu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 7c2f4bd33582..caf664448ee9 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4650,7 +4650,21 @@ static int intel_iommu_enable_sva(struct device *dev) if (!(iommu->flags & VTD_FLAG_SVM_CAPABLE)) return -ENODEV; =20 - if (!info->pasid_enabled || !info->pri_enabled || !info->ats_enabled) + if (!info->pasid_enabled || !info->ats_enabled) + return -EINVAL; + + /* + * Devices having device-specific I/O fault handling should not + * support PCI/PRI. The IOMMU side has no means to check the + * capability of device-specific IOPF. Therefore, IOMMU can only + * default that if the device driver enables SVA on a non-PRI + * device, it will handle IOPF in its own way. + */ + if (!info->pri_supported) + return 0; + + /* Devices supporting PRI should have it enabled. */ + if (!info->pri_enabled) return -EINVAL; =20 ret =3D iopf_queue_add_device(iommu->iopf_queue, dev); --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 58E0AC76196 for ; Tue, 11 Apr 2023 06:49:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230415AbjDKGtZ (ORCPT ); Tue, 11 Apr 2023 02:49:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbjDKGs7 (ORCPT ); Tue, 11 Apr 2023 02:48:59 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A974496 for ; Mon, 10 Apr 2023 23:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195718; x=1712731718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AH2O7XJ83CyJq/BvNVtHKqMDArNO32apjduqQxjWqso=; b=cWQ5TCJEjNL1aWnMqBR8UzCGqH2DY9kLGPSCpeJ1FEU2AOfyPKD2UYPs GoThGqnamTXZD+XtpBDO6kqA6GB24iF8xjMMxNXWH9RfORYBjkDWKNz3w B2RBv4nqPL5cdY6LCADDQ2HKKrLVzMZbL0JP4/hivp0X2IEWqNZ76z1UI bqtrmtOlOXe+cE6eqUF1a0fuUjYtarcUmNqtSGAJcMhAocQ9qfmr9O6xV peyWC4wAerkfsENFEw5UY6DtxFaOH4l98PLKDETmehD3ki7/V4rM8roUi U16NxpHTn47Hj5Qo2BI/jVjr82WIEQ+AmuyO2cZ6c9ytjSS84OZ2YmNHg Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028514" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028514" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256547" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256547" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:15 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 03/17] iommu/vt-d: Move iopf code from SVA to IOPF enabling path Date: Tue, 11 Apr 2023 14:48:01 +0800 Message-Id: <20230411064815.31456-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" Generally enabling IOMMU_DEV_FEAT_SVA requires IOMMU_DEV_FEAT_IOPF, but some devices manage I/O Page Faults themselves instead of relying on the IOMMU. Move IOPF related code from SVA to IOPF enabling path. For the device drivers that relies on the IOMMU for IOPF through PCI/PRI, IOMMU_DEV_FEAT_IOPF must be enabled before and disabled after IOMMU_DEV_FEAT_SVA. Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-4-baolu.lu@linux.inte= l.com --- drivers/iommu/intel/iommu.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index caf664448ee9..a6f07c74da2d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4638,7 +4638,6 @@ static int intel_iommu_enable_sva(struct device *dev) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu; - int ret; =20 if (!info || dmar_disabled) return -EINVAL; @@ -4667,6 +4666,21 @@ static int intel_iommu_enable_sva(struct device *dev) if (!info->pri_enabled) return -EINVAL; =20 + return 0; +} + +static int intel_iommu_enable_iopf(struct device *dev) +{ + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct intel_iommu *iommu; + int ret; + + if (!info || !info->ats_enabled || !info->pri_enabled) + return -ENODEV; + iommu =3D info->iommu; + if (!iommu) + return -EINVAL; + ret =3D iopf_queue_add_device(iommu->iopf_queue, dev); if (ret) return ret; @@ -4678,7 +4692,7 @@ static int intel_iommu_enable_sva(struct device *dev) return ret; } =20 -static int intel_iommu_disable_sva(struct device *dev) +static int intel_iommu_disable_iopf(struct device *dev) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu =3D info->iommu; @@ -4695,16 +4709,6 @@ static int intel_iommu_disable_sva(struct device *de= v) return ret; } =20 -static int intel_iommu_enable_iopf(struct device *dev) -{ - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - - if (info && info->pri_supported) - return 0; - - return -ENODEV; -} - static int intel_iommu_dev_enable_feat(struct device *dev, enum iommu_dev_features fe= at) { @@ -4725,10 +4729,10 @@ intel_iommu_dev_disable_feat(struct device *dev, en= um iommu_dev_features feat) { switch (feat) { case IOMMU_DEV_FEAT_IOPF: - return 0; + return intel_iommu_disable_iopf(dev); =20 case IOMMU_DEV_FEAT_SVA: - return intel_iommu_disable_sva(dev); + return 0; =20 default: return -ENODEV; --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 C8523C76196 for ; Tue, 11 Apr 2023 06:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230284AbjDKGtd (ORCPT ); Tue, 11 Apr 2023 02:49:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjDKGtE (ORCPT ); Tue, 11 Apr 2023 02:49:04 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94DAE30DC for ; Mon, 10 Apr 2023 23:48: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=1681195726; x=1712731726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=svE7EgjquyhwRZbom4QiBGJ7Mxb0NsfSfLHDW+HF/GA=; b=R7lUl7+hfgtUKRkPb+mVoNFLEYJz1jrvgduqPBljUQn8SOtFVfxVhZsO N1kIFY4vLMnh9EI+BeVP/rephmy6C6TLMgp+76Z4M8I0SR8c/sR2IkvU4 boqLANh0m21Qynp/TcWbR4Proir9D/bM3TvENcq0vfB0w/SREGDwloHk6 fMibS950OEKIGY9besAu7ybygXW+h0Z4L90Jv8qmHxAU+TY3nNY2HlWr0 dKvMwfcNrEjRpYfiFSW4K37i+PLjf3zyJoQCCbMCSmKKMF73nkRCKxWmz Oa5mAIRgVcbwoH9UswUu/lWiylZlmWf9SJUaPKb/OEv9PnMPiXCKxIn16 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028522" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028522" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256558" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256558" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:18 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 04/17] iommu/vt-d: Move pfsid and ats_qdep calculation to device probe path Date: Tue, 11 Apr 2023 14:48:02 +0800 Message-Id: <20230411064815.31456-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" They should be part of the per-device iommu private data initialization. Reviewed-by: Jacob Pan Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-5-baolu.lu@linux.inte= l.com --- drivers/iommu/intel/iommu.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a6f07c74da2d..6d77b4072fdd 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1406,20 +1406,6 @@ static void iommu_enable_pci_caps(struct device_doma= in_info *info) return; =20 pdev =3D to_pci_dev(info->dev); - /* For IOMMU that supports device IOTLB throttling (DIT), we assign - * PFSID to the invalidation desc of a VF such that IOMMU HW can gauge - * queue depth at PF level. If DIT is not set, PFSID will be treated as - * reserved, which should be set to 0. - */ - if (!ecap_dit(info->iommu->ecap)) - info->pfsid =3D 0; - else { - struct pci_dev *pf_pdev; - - /* pdev will be returned if device is not a vf */ - pf_pdev =3D pci_physfn(pdev); - info->pfsid =3D pci_dev_id(pf_pdev); - } =20 /* The PCIe spec, in its wisdom, declares that the behaviour of the device if you enable PASID support after ATS support is @@ -1438,7 +1424,6 @@ static void iommu_enable_pci_caps(struct device_domai= n_info *info) !pci_enable_ats(pdev, VTD_PAGE_SHIFT)) { info->ats_enabled =3D 1; domain_update_iotlb(info->domain); - info->ats_qdep =3D pci_ats_queue_depth(pdev); } } =20 @@ -4521,6 +4506,17 @@ static struct iommu_device *intel_iommu_probe_device= (struct device *dev) dmar_ats_supported(pdev, iommu)) { info->ats_supported =3D 1; info->dtlb_extra_inval =3D dev_needs_extra_dtlb_flush(pdev); + + /* + * For IOMMU that supports device IOTLB throttling + * (DIT), we assign PFSID to the invalidation desc + * of a VF such that IOMMU HW can gauge queue depth + * at PF level. If DIT is not set, PFSID will be + * treated as reserved, which should be set to 0. + */ + if (ecap_dit(iommu->ecap)) + info->pfsid =3D pci_dev_id(pci_physfn(pdev)); + info->ats_qdep =3D pci_ats_queue_depth(pdev); } if (sm_supported(iommu)) { if (pasid_supported(iommu)) { --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 3AF90C7619A for ; Tue, 11 Apr 2023 06:49:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230427AbjDKGti (ORCPT ); Tue, 11 Apr 2023 02:49:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbjDKGtM (ORCPT ); Tue, 11 Apr 2023 02:49:12 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0C043A84 for ; Mon, 10 Apr 2023 23:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195730; x=1712731730; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zGpEfMgloBsWMUOjxE9fyxNifshGPev/lcFUTQ3YvYY=; b=MsplvDpkX8w0xbmmj2l/+M3YZkteBa7x0uGxRC+nGfoPOhjJh1OaACfU qZovhQjwJ0sPHiHgOsUzJtssWeMsw+u1UEL3gdtGlFV5KsRgkRx8xKGpS IDZ/IrEZJVhwUrruRO+iCL4K34AsGzEdlqa894ziViDW7sn5rAmJGrgSL s6if2QVp7sjTYo6NzyC3TlYgu33Qs7iJo8cU3uTNUbU8e0qR4DTMDh+Ro yzg027ety1rZgDxPPiXzf3vEK9d5KSUMhie3rH0u1h8d4ZU+/nffN4WOY BITD4ENEkgiEmowZ4fsgzJOnOorKrfgxZ+KiYnLZnGnFqlRalWgnDe2Tk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028533" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028533" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256564" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256564" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:20 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 05/17] iommu/vt-d: Move PRI handling to IOPF feature path Date: Tue, 11 Apr 2023 14:48:03 +0800 Message-Id: <20230411064815.31456-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" PRI is only used for IOPF. With this move, the PCI/PRI feature could be controlled by the device driver through iommu_dev_enable/disable_feature() interfaces. Reviewed-by: Jacob Pan Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-6-baolu.lu@linux.inte= l.com --- drivers/iommu/intel/iommu.c | 53 ++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 6d77b4072fdd..cd3a3c4b5e64 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1415,11 +1415,6 @@ static void iommu_enable_pci_caps(struct device_doma= in_info *info) if (info->pasid_supported && !pci_enable_pasid(pdev, info->pasid_supporte= d & ~1)) info->pasid_enabled =3D 1; =20 - if (info->pri_supported && - (info->pasid_enabled ? pci_prg_resp_pasid_required(pdev) : 1) && - !pci_reset_pri(pdev) && !pci_enable_pri(pdev, PRQ_DEPTH)) - info->pri_enabled =3D 1; - if (info->ats_supported && pci_ats_page_aligned(pdev) && !pci_enable_ats(pdev, VTD_PAGE_SHIFT)) { info->ats_enabled =3D 1; @@ -1442,11 +1437,6 @@ static void iommu_disable_pci_caps(struct device_dom= ain_info *info) domain_update_iotlb(info->domain); } =20 - if (info->pri_enabled) { - pci_disable_pri(pdev); - info->pri_enabled =3D 0; - } - if (info->pasid_enabled) { pci_disable_pasid(pdev); info->pasid_enabled =3D 0; @@ -4667,23 +4657,48 @@ static int intel_iommu_enable_sva(struct device *de= v) =20 static int intel_iommu_enable_iopf(struct device *dev) { + struct pci_dev *pdev =3D dev_is_pci(dev) ? to_pci_dev(dev) : NULL; struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu; int ret; =20 - if (!info || !info->ats_enabled || !info->pri_enabled) + if (!pdev || !info || !info->ats_enabled || !info->pri_supported) return -ENODEV; + + if (info->pri_enabled) + return -EBUSY; + iommu =3D info->iommu; if (!iommu) return -EINVAL; =20 + /* PASID is required in PRG Response Message. */ + if (info->pasid_enabled && !pci_prg_resp_pasid_required(pdev)) + return -EINVAL; + + ret =3D pci_reset_pri(pdev); + if (ret) + return ret; + ret =3D iopf_queue_add_device(iommu->iopf_queue, dev); if (ret) return ret; =20 ret =3D iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); if (ret) - iopf_queue_remove_device(iommu->iopf_queue, dev); + goto iopf_remove_device; + + ret =3D pci_enable_pri(pdev, PRQ_DEPTH); + if (ret) + goto iopf_unregister_handler; + info->pri_enabled =3D 1; + + return 0; + +iopf_unregister_handler: + iommu_unregister_device_fault_handler(dev); +iopf_remove_device: + iopf_queue_remove_device(iommu->iopf_queue, dev); =20 return ret; } @@ -4694,6 +4709,20 @@ static int intel_iommu_disable_iopf(struct device *d= ev) struct intel_iommu *iommu =3D info->iommu; int ret; =20 + if (!info->pri_enabled) + return -EINVAL; + + /* + * PCIe spec states that by clearing PRI enable bit, the Page + * Request Interface will not issue new page requests, but has + * outstanding page requests that have been transmitted or are + * queued for transmission. This is supposed to be called after + * the device driver has stopped DMA, all PASIDs have been + * unbound and the outstanding PRQs have been drained. + */ + pci_disable_pri(to_pci_dev(dev)); + info->pri_enabled =3D 0; + ret =3D iommu_unregister_device_fault_handler(dev); if (ret) return ret; --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 78190C7619A for ; Tue, 11 Apr 2023 06:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230402AbjDKGts (ORCPT ); Tue, 11 Apr 2023 02:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjDKGtP (ORCPT ); Tue, 11 Apr 2023 02:49:15 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED093C00 for ; Mon, 10 Apr 2023 23:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195734; x=1712731734; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sDMJTalig0nzuhTIrI4QQ+mFyR3+Py8XwH5/FAztKD8=; b=PX8tR4A/a6qiofo1J0yikA1lOt+pphZCIffvIeq4NNrjm/tJp2gXgRWt nyWSSpp95c71fiwGa5SxdPQBlhoCnHhcejSPhstpLR9HSj4GyUEK88tGm 40R3Ux91WJlMpSLYPPbd+DjmCpUUBHDGH60AlLAKcazVakckggKodhpD1 gQ9hVyi+XCnsUhiirj4mp8MItk9lLBAdkU6w/v8LZRN7/xV18O5BSW3cM bsOUduwx309ZKUe+P8NYZOE1XZucmaHvbC0cZ/rtC4kPxLd+N2Ux0LWLF hwUcyBWkKef4522qWX9DH+0ra4VM1OKWfys7YmT4r+y2txI1K95VcebtI Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028540" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028540" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256574" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256574" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:22 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 06/17] iommu/vt-d: Remove unnecessary checks in iopf disabling path Date: Tue, 11 Apr 2023 14:48:04 +0800 Message-Id: <20230411064815.31456-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" iommu_unregister_device_fault_handler() and iopf_queue_remove_device() are called after device has stopped issuing new page falut requests and all outstanding page requests have been drained. They should never fail. Trigger a warning if it happens unfortunately. Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-7-baolu.lu@linux.inte= l.com --- drivers/iommu/intel/iommu.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index cd3a3c4b5e64..c771233d6f2a 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4707,7 +4707,6 @@ static int intel_iommu_disable_iopf(struct device *de= v) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu =3D info->iommu; - int ret; =20 if (!info->pri_enabled) return -EINVAL; @@ -4723,15 +4722,15 @@ static int intel_iommu_disable_iopf(struct device *= dev) pci_disable_pri(to_pci_dev(dev)); info->pri_enabled =3D 0; =20 - ret =3D iommu_unregister_device_fault_handler(dev); - if (ret) - return ret; - - ret =3D iopf_queue_remove_device(iommu->iopf_queue, dev); - if (ret) - iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); + /* + * With PRI disabled and outstanding PRQs drained, unregistering + * fault handler and removing device from iopf queue should never + * fail. + */ + WARN_ON(iommu_unregister_device_fault_handler(dev)); + WARN_ON(iopf_queue_remove_device(iommu->iopf_queue, dev)); =20 - return ret; + return 0; } =20 static int --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 0B93BC76196 for ; Tue, 11 Apr 2023 06:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbjDKGuD (ORCPT ); Tue, 11 Apr 2023 02:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjDKGth (ORCPT ); Tue, 11 Apr 2023 02:49:37 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469BB40DB for ; Mon, 10 Apr 2023 23:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195744; x=1712731744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KLcSzST6hDd+fcr/F74YMXpjYh9sQavSmsQ3e9U8YPk=; b=mMWV0gZF369JfYk0K9qcRLqRY1D8k4cXx7WLPcY0ABcB0Ctye7x6o8EH eJLOIzDvLiweUPWuZf0r5PUCUu0aMCrcR0Xn3yedv2wEUf+8SrgIuhvkI tWFaAxY7opeGypBTgXms5iaiGsW/NfuUnEjSkbjDuTx2HykG10rvxZxpo p6zplp/Eytu8n1We1ZUZmwaG2WYO8L4Zrn9IPr+bDyyDyRZThfT7UoVaB 94iw7bxLwI0uPeN1Zxt69BNR9XNmSfUH9rDGKr0t/ms+J2iWAmZzXdEi1 ivcMmnYFYNOFGa02jof6aqb1htqOObUVxfAYceLfIDbfXvSfykgATlEL+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028553" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028553" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256594" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256594" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:24 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 07/17] iommu/vt-d: Do not use GFP_ATOMIC when not needed Date: Tue, 11 Apr 2023 14:48:05 +0800 Message-Id: <20230411064815.31456-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Christophe JAILLET There is no need to use GFP_ATOMIC here. GFP_KERNEL is already used for some other memory allocations just a few lines above. Commit e3a981d61d15 ("iommu/vt-d: Convert allocations to GFP_KERNEL") has changed the other memory allocation flags. Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/e2a8a1019ffc8a86b4b4ed93def3623f60581274.16= 75542576.git.christophe.jaillet@wanadoo.fr Signed-off-by: Lu Baolu --- drivers/iommu/intel/irq_remapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_= remapping.c index df9e261af0b5..a1b987335b31 100644 --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -548,7 +548,7 @@ static int intel_setup_irq_remapping(struct intel_iommu= *iommu) goto out_free_table; } =20 - bitmap =3D bitmap_zalloc(INTR_REMAP_TABLE_ENTRIES, GFP_ATOMIC); + bitmap =3D bitmap_zalloc(INTR_REMAP_TABLE_ENTRIES, GFP_KERNEL); if (bitmap =3D=3D NULL) { pr_err("IR%d: failed to allocate bitmap\n", iommu->seq_id); goto out_free_pages; --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 206F5C7619A for ; Tue, 11 Apr 2023 06:50:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbjDKGuG (ORCPT ); Tue, 11 Apr 2023 02:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbjDKGtt (ORCPT ); Tue, 11 Apr 2023 02:49:49 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AA6240F6 for ; Mon, 10 Apr 2023 23:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195750; x=1712731750; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EXw7iRfpei7pJiqdEoClA47q842CS/GvW0oVWNgTE1k=; b=Kf8vI4wTA4MbtkAn6UOrlzFV9ziKBhCkMEnXypOe0WDkNiRNsCEJlRPi bysGOKzNJZmqP4+jcR4h17ZP44FxfVM8Wo35+w7hezPVwc4f0YoVimVBF HdqKfwRuc/ACIJlkU6/UJO6dK2cz7jgDfuEWytxE7v1VaWA4bK9zFehXC iDmRzoau/Ted+aIGabybd95Sy8G5XcmKpNlI4ZPgioQ7PR7x4+CmGB3gC 6eEOkSVIsUH4o19178DqTYf8tDWP7f7z9nHUURXwmNZ3Ekw1lnHcBMDwc 9ki68fKkk/X37koeP0qrQ2tXASRcC3TEnvq8VPuPDR1VN14KhID3wH0J2 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028565" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028565" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256599" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256599" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:27 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 08/17] iommu/vt-d: Remove extern from function prototypes Date: Tue, 11 Apr 2023 14:48:06 +0800 Message-Id: <20230411064815.31456-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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 kernel coding style does not require 'extern' in function prototypes in .h files, so remove them from drivers/iommu/intel/iommu.h as they are not needed. Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230331045452.500265-1-baolu.lu@linux.inte= l.com --- drivers/iommu/intel/iommu.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 694ab9b7d3e9..19494713d6b3 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -798,18 +798,18 @@ static inline bool context_present(struct context_ent= ry *context) return (context->lo & 1); } =20 -extern struct dmar_drhd_unit * dmar_find_matched_drhd_unit(struct pci_dev = *dev); - -extern int dmar_enable_qi(struct intel_iommu *iommu); -extern void dmar_disable_qi(struct intel_iommu *iommu); -extern int dmar_reenable_qi(struct intel_iommu *iommu); -extern void qi_global_iec(struct intel_iommu *iommu); - -extern void qi_flush_context(struct intel_iommu *iommu, u16 did, u16 sid, - u8 fm, u64 type); -extern void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, - unsigned int size_order, u64 type); -extern void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfs= id, +struct dmar_drhd_unit *dmar_find_matched_drhd_unit(struct pci_dev *dev); + +int dmar_enable_qi(struct intel_iommu *iommu); +void dmar_disable_qi(struct intel_iommu *iommu); +int dmar_reenable_qi(struct intel_iommu *iommu); +void qi_global_iec(struct intel_iommu *iommu); + +void qi_flush_context(struct intel_iommu *iommu, u16 did, + u16 sid, u8 fm, u64 type); +void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, + unsigned int size_order, u64 type); +void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, u16 qdep, u64 addr, unsigned mask); =20 void qi_flush_piotlb(struct intel_iommu *iommu, u16 did, u32 pasid, u64 ad= dr, @@ -832,7 +832,7 @@ int qi_submit_sync(struct intel_iommu *iommu, struct qi= _desc *desc, */ #define QI_OPT_WAIT_DRAIN BIT(0) =20 -extern int dmar_ir_support(void); +int dmar_ir_support(void); =20 void *alloc_pgtable_page(int node, gfp_t gfp); void free_pgtable_page(void *vaddr); @@ -840,9 +840,9 @@ void iommu_flush_write_buffer(struct intel_iommu *iommu= ); struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn= ); =20 #ifdef CONFIG_INTEL_IOMMU_SVM -extern void intel_svm_check(struct intel_iommu *iommu); -extern int intel_svm_enable_prq(struct intel_iommu *iommu); -extern int intel_svm_finish_prq(struct intel_iommu *iommu); +void intel_svm_check(struct intel_iommu *iommu); +int intel_svm_enable_prq(struct intel_iommu *iommu); +int intel_svm_finish_prq(struct intel_iommu *iommu); int intel_svm_page_response(struct device *dev, struct iommu_fault_event *= evt, struct iommu_page_response *msg); struct iommu_domain *intel_svm_domain_alloc(void); @@ -889,8 +889,8 @@ extern const struct iommu_ops intel_iommu_ops; =20 #ifdef CONFIG_INTEL_IOMMU extern int intel_iommu_sm; -extern int iommu_calculate_agaw(struct intel_iommu *iommu); -extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu); +int iommu_calculate_agaw(struct intel_iommu *iommu); +int iommu_calculate_max_sagaw(struct intel_iommu *iommu); int ecmd_submit_sync(struct intel_iommu *iommu, u8 ecmd, u64 oa, u64 ob); =20 static inline bool ecmd_has_pmu_essential(struct intel_iommu *iommu) --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 DF7ACC7619A for ; Tue, 11 Apr 2023 06:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230413AbjDKGuS (ORCPT ); Tue, 11 Apr 2023 02:50:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjDKGtu (ORCPT ); Tue, 11 Apr 2023 02:49:50 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 275922D6B for ; Mon, 10 Apr 2023 23:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195755; x=1712731755; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BV5LLOlacNTt4g++kWcPPRqikSTDi86tcqNaVPEHCy0=; b=WXJ3PtYfwrE0YDj0S1yGMr/0aaNQoCWDT3x4QcCajDQhxXaynhXZ9a1Y Hw5di0n+GXUmCjsQ6PFqRW2JqVRZ6MHm+N1Otudr0ryh0ttzRjWh/2KWb 8TlST+JP5UhvqRGIu8ULTKJX+Anp9HcqbjVlagdV3oGY190PbUT/UX1EH 6+OOaBj5FLIqo4s1mKM/6kNRTZ/hgL2jhBwI/IS889Xr44b0mIMRdJgD5 XkV/rsC9Pi34czv+MCcGeSyKW2E0Gn0CHZA2pXz3TbOJiJEe6xs22F5Vs C32NM1OjfBMigNn+evfp7LRTPSLXpxXguVFtn6IYjZdqBsaHR3ZdPu7gm w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028574" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028574" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256606" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256606" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:29 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 09/17] iommu/vt-d: Use non-privileged mode for all PASIDs Date: Tue, 11 Apr 2023 14:48:07 +0800 Message-Id: <20230411064815.31456-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Jacob Pan Supervisor Request Enable (SRE) bit in a PASID entry is for permission checking on DMA requests. When SRE =3D 0, DMA with supervisor privilege will be blocked. However, for in-kernel DMA this is not necessary in that we are targeting kernel memory anyway. There's no need to differentiate user and kernel for in-kernel DMA. Let's use non-privileged (user) permission for all PASIDs used in kernel, it will be consistent with DMA without PASID (RID_PASID) as well. Signed-off-by: Jacob Pan Link: https://lore.kernel.org/r/20230331231137.1947675-2-jacob.jun.pan@linu= x.intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c771233d6f2a..f4e536fd5a28 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2316,8 +2316,6 @@ static int domain_setup_first_level(struct intel_iomm= u *iommu, if (level !=3D 4 && level !=3D 5) return -EINVAL; =20 - if (pasid !=3D PASID_RID2PASID) - flags |=3D PASID_FLAG_SUPERVISOR_MODE; if (level =3D=3D 5) flags |=3D PASID_FLAG_FL5LP; =20 --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 3A879C76196 for ; Tue, 11 Apr 2023 06:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbjDKGue (ORCPT ); Tue, 11 Apr 2023 02:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbjDKGuN (ORCPT ); Tue, 11 Apr 2023 02:50:13 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47DB359F for ; Mon, 10 Apr 2023 23:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195777; x=1712731777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QWKb5WYVBBtztVXr3PHvMcXCQDDphOV1gmNATePnwEA=; b=hvV22duUxFlyJs24dtcFzQfK1SSsOOB18+dwbpOvrHxNUdXeQv/L4vUg mJgXZXVRlTKNwJq6RwLbAhahVsLj8IEWlK2dYG0zHcVzYRud2BMMImHUA 4mH1kzJyRA1VHah9T+QpO0CI5xtqd0odOQfbankpWFNjx/rQGDEgC5AP5 xLcb+uZo2e6ro3clA66PB/TIh3/4BKrzdTiTmQaz6q7zNmfIUCxsUJkRF p0kf531IwIEoPieFVs4qK9OW4DDur6ZzqVqAplUKBDxFaDrwgeNtiWGcp sUlTTVuMLmWkAcUSz8+RpGHQHrvTI1opcOKYt88XCbCwLS61f+R6dn5wC Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028588" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028588" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256614" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256614" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:31 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 10/17] iommu/vt-d: Remove PASID supervisor request support Date: Tue, 11 Apr 2023 14:48:08 +0800 Message-Id: <20230411064815.31456-11-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jacob Pan There's no more usage, remove PASID supervisor support. Suggested-by: Lu Baolu Reviewed-by: Lu Baolu Signed-off-by: Jacob Pan Link: https://lore.kernel.org/r/20230331231137.1947675-3-jacob.jun.pan@linu= x.intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.h | 7 ------ drivers/iommu/intel/pasid.c | 43 ------------------------------------- 2 files changed, 50 deletions(-) diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index 20c54e50f533..d6b7d21244b1 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -41,13 +41,6 @@ #define FLPT_DEFAULT_DID 1 #define NUM_RESERVED_DID 2 =20 -/* - * The SUPERVISOR_MODE flag indicates a first level translation which - * can be used for access to kernel addresses. It is valid only for - * access to the kernel's static 1:1 mapping of physical memory =E2=80=94 = not - * to vmalloc or even module mappings. - */ -#define PASID_FLAG_SUPERVISOR_MODE BIT(0) #define PASID_FLAG_NESTED BIT(1) #define PASID_FLAG_PAGE_SNOOP BIT(2) =20 diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 633e0a4a01e7..c5d479770e12 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -335,15 +335,6 @@ static inline void pasid_set_fault_enable(struct pasid= _entry *pe) pasid_set_bits(&pe->val[0], 1 << 1, 0); } =20 -/* - * Setup the SRE(Supervisor Request Enable) field (Bit 128) of a - * scalable mode PASID entry. - */ -static inline void pasid_set_sre(struct pasid_entry *pe) -{ - pasid_set_bits(&pe->val[2], 1 << 0, 1); -} - /* * Setup the WPE(Write Protect Enable) field (Bit 132) of a * scalable mode PASID entry. @@ -521,23 +512,6 @@ int intel_pasid_setup_first_level(struct intel_iommu *= iommu, return -EINVAL; } =20 - if (flags & PASID_FLAG_SUPERVISOR_MODE) { -#ifdef CONFIG_X86 - unsigned long cr0 =3D read_cr0(); - - /* CR0.WP is normally set but just to be sure */ - if (unlikely(!(cr0 & X86_CR0_WP))) { - pr_err("No CPU write protect!\n"); - return -EINVAL; - } -#endif - if (!ecap_srs(iommu->ecap)) { - pr_err("No supervisor request support on %s\n", - iommu->name); - return -EINVAL; - } - } - if ((flags & PASID_FLAG_FL5LP) && !cap_fl5lp_support(iommu->cap)) { pr_err("No 5-level paging support for first-level on %s\n", iommu->name); @@ -560,10 +534,6 @@ int intel_pasid_setup_first_level(struct intel_iommu *= iommu, =20 /* Setup the first level page table pointer: */ pasid_set_flptr(pte, (u64)__pa(pgd)); - if (flags & PASID_FLAG_SUPERVISOR_MODE) { - pasid_set_sre(pte); - pasid_set_wpe(pte); - } =20 if (flags & PASID_FLAG_FL5LP) pasid_set_flpm(pte, 1); @@ -658,12 +628,6 @@ 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 - /* - * Since it is a second level only translation setup, we should - * set SRE bit as well (addresses are expected to be GPAs). - */ - if (pasid !=3D PASID_RID2PASID && ecap_srs(iommu->ecap)) - pasid_set_sre(pte); pasid_set_present(pte); spin_unlock(&iommu->lock); =20 @@ -700,13 +664,6 @@ int intel_pasid_setup_pass_through(struct intel_iommu = *iommu, pasid_set_translation_type(pte, PASID_ENTRY_PGTT_PT); pasid_set_fault_enable(pte); pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); - - /* - * We should set SRE bit as well since the addresses are expected - * to be GPAs. - */ - if (ecap_srs(iommu->ecap)) - pasid_set_sre(pte); pasid_set_present(pte); spin_unlock(&iommu->lock); =20 --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 249EBC7619A for ; Tue, 11 Apr 2023 06:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbjDKGuk (ORCPT ); Tue, 11 Apr 2023 02:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbjDKGuR (ORCPT ); Tue, 11 Apr 2023 02:50:17 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BB7E423F for ; Mon, 10 Apr 2023 23:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195784; x=1712731784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fHc/Dt3WZSFDnH//DR0PtW4o8sOEHZYZ41tbx+9UmIU=; b=dwVhYuC2L1KsP/sTK63g3tc+rivKc/wENqYW8HWayZq2XZqNBc1r0RFe TYmd8gUEfEB7fR3S3nBuCfXv4cbcDZDyAeHUQJjIpjzHMQBQW4mv5/B5v P8VlcFxG/ymsuzAT96l7eIEujR+56Vrkm2/a6rcyKdKUIfcGZ1zU/rbIt T3kzz1pHBTOf9TguFoozkGjqdeLiRrpIdDdFmucQd7TWUwQnsdU1X146J oCQI4RX/bMUPEs245jCbxTAmElITh2wL/L5e/lamg8leiLXJ/R0dwTYnT KGPhSZIRohnIJzaGrvU+hQ7TfH+GesVjYHivmpTYNeOZdyi2AaUpXolmG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028600" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028600" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256620" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256620" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:33 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 11/17] iommu/vt-d: Fix operand size in bitwise operation Date: Tue, 11 Apr 2023 14:48:09 +0800 Message-Id: <20230411064815.31456-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Tina Zhang The patch fixes the klocwork issues that operands in a bitwise operation have different size at line 1692 of dmar.c, line 1898 and line 1907 of iommu.c. Reported-by: Yongwei Ma Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-2-tina.zhang@intel.c= om Signed-off-by: Lu Baolu Suggested-by: Yongwei Ma --- drivers/iommu/intel/dmar.c | 2 +- drivers/iommu/intel/iommu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 23828d189c2a..f0f51c957ccb 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -1690,7 +1690,7 @@ static void __dmar_enable_qi(struct intel_iommu *iomm= u) * is present. */ if (ecap_smts(iommu->ecap)) - val |=3D (1 << 11) | 1; + val |=3D BIT_ULL(11) | BIT_ULL(0); =20 raw_spin_lock_irqsave(&iommu->register_lock, flags); =20 diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f4e536fd5a28..acbf82fa90e7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1870,7 +1870,7 @@ context_set_sm_rid2pasid(struct context_entry *contex= t, unsigned long pasid) */ static inline void context_set_sm_dte(struct context_entry *context) { - context->lo |=3D (1 << 2); + context->lo |=3D BIT_ULL(2); } =20 /* @@ -1879,7 +1879,7 @@ static inline void context_set_sm_dte(struct context_= entry *context) */ static inline void context_set_sm_pre(struct context_entry *context) { - context->lo |=3D (1 << 4); + context->lo |=3D BIT_ULL(4); } =20 /* Convert value to context PASID directory size field coding. */ --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 6222EC7619A for ; Tue, 11 Apr 2023 06:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230209AbjDKGup (ORCPT ); Tue, 11 Apr 2023 02:50:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230417AbjDKGuS (ORCPT ); Tue, 11 Apr 2023 02:50:18 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F673AB8 for ; Mon, 10 Apr 2023 23:49: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=1681195786; x=1712731786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fSH+9CuukwrVCuz9aJxEFN4y0MR5HKb9VSv4IIAZmfM=; b=ai0sXJeg+xpfqy16spN0Y5xT8RWsQ14duWiBqNrHWgerd2B9sJnRvC+w dGyHwCjA4GH1f/D5dF/3ATwYs9kaT+xqRjP74kCljco+5dpcv0Wg4JJi2 5ztxAo/y+1aQvkBQi3qPY8vBQTB3QFg4QOoSj82+e8JMkGFkAe09sUKI9 78dTL1aH7UtcOsa2wk5hNaEY91DsO7QATTAgA/SCzHVdh9QXm8DHDyIzQ 5L3+PtVUAFd+CW9BC75m6XGTnKQKmfeKbXpjmP7jsG0yYZyselbdfvFy+ DmAsJqSh94nP8mav56QGMDGGxLWGWUGT0LLy+Sv4SDiRo/l8A8ZvFxirr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028610" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028610" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256626" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256626" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:35 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 12/17] iommu/vt-d: Remove BUG_ON on checking valid pfn range Date: Tue, 11 Apr 2023 14:48:10 +0800 Message-Id: <20230411064815.31456-13-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Tina Zhang When encountering an unexpected invalid pfn range, the kernel should attempt recovery and proceed with execution. Therefore, using WARN_ON to replace BUG_ON to avoid halting the machine. Besides, one redundant checking is reduced. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-3-tina.zhang@intel.c= om Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index acbf82fa90e7..c4847a5aaf52 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1005,9 +1005,9 @@ static void dma_pte_clear_range(struct dmar_domain *d= omain, unsigned int large_page; struct dma_pte *first_pte, *pte; =20 - BUG_ON(!domain_pfn_supported(domain, start_pfn)); - BUG_ON(!domain_pfn_supported(domain, last_pfn)); - BUG_ON(start_pfn > last_pfn); + if (WARN_ON(!domain_pfn_supported(domain, last_pfn)) || + WARN_ON(start_pfn > last_pfn)) + return; =20 /* we don't need lock here; nobody else touches the iova range */ do { @@ -1166,9 +1166,9 @@ static void dma_pte_clear_level(struct dmar_domain *d= omain, int level, static void domain_unmap(struct dmar_domain *domain, unsigned long start_p= fn, unsigned long last_pfn, struct list_head *freelist) { - BUG_ON(!domain_pfn_supported(domain, start_pfn)); - BUG_ON(!domain_pfn_supported(domain, last_pfn)); - BUG_ON(start_pfn > last_pfn); + if (WARN_ON(!domain_pfn_supported(domain, last_pfn)) || + WARN_ON(start_pfn > last_pfn)) + return; =20 /* we don't need lock here; nobody else touches the iova range */ dma_pte_clear_level(domain, agaw_to_level(domain->agaw), --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 90C61C7619A for ; Tue, 11 Apr 2023 06:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230479AbjDKGu7 (ORCPT ); Tue, 11 Apr 2023 02:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbjDKGuf (ORCPT ); Tue, 11 Apr 2023 02:50:35 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A1C40C6 for ; Mon, 10 Apr 2023 23:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195803; x=1712731803; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KoxeI8nGmhipdmhbf/hPatJykHf7P/Wr8q6XOawTXGM=; b=CoH5ldwtPZlPsq7JtPndgdle83aQ/P1RObsbKMqcXrS4Yd5YdT8nZ816 5o3YebNu/7KbDLlNydz3TFtGlRK3cEo+5ffopPBx9gjOfVfdWYJRXe0QA 0OY3+5qotXpZgvPUNC7Bis2oeiVnGRUnlX4A0ERriBknminZQeGaSBG6o TFfA2+4Ij4sCjrNoUSznP6Fmr2jr9n+6LLnSrrb1SVM5yJMTFK7srP2T6 7cFL+5MiqVZ1Srq5G2WEiNzZ+SPUQ8GUg3pp8FXyMQ4tg7dx7kYjLKR2h qWjkFS8v01V5IwYToQlAQDUlY6WI28t9RxAMJ3npaL8+G1m+B1pGP7pNX g==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028616" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028616" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256633" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256633" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:37 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 13/17] iommu/vt-d: Remove BUG_ON in handling iotlb cache invalidation Date: Tue, 11 Apr 2023 14:48:11 +0800 Message-Id: <20230411064815.31456-14-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Tina Zhang VT-d iotlb cache invalidation request with unexpected type is considered as a bug to developers, which can be fixed. So, when such kind of issue comes out, it needs to be reported through the kernel log, instead of halting the system. Replacing BUG_ON with warning reporting. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-4-tina.zhang@intel.c= om Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c4847a5aaf52..dd61bb554aa7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1272,7 +1272,9 @@ static void __iommu_flush_context(struct intel_iommu = *iommu, | DMA_CCMD_SID(source_id) | DMA_CCMD_FM(function_mask); break; default: - BUG(); + pr_warn("%s: Unexpected context-cache invalidation type 0x%llx\n", + iommu->name, type); + return; } val |=3D DMA_CCMD_ICC; =20 @@ -1308,7 +1310,9 @@ static void __iommu_flush_iotlb(struct intel_iommu *i= ommu, u16 did, val_iva =3D size_order | addr; break; default: - BUG(); + pr_warn("%s: Unexpected iotlb invalidation type 0x%llx\n", + iommu->name, type); + return; } /* Note: set drain read/write */ #if 0 @@ -1483,7 +1487,8 @@ static void iommu_flush_iotlb_psi(struct intel_iommu = *iommu, uint64_t addr =3D (uint64_t)pfn << VTD_PAGE_SHIFT; u16 did =3D domain_id_iommu(domain, iommu); =20 - BUG_ON(pages =3D=3D 0); + if (WARN_ON(!pages)) + return; =20 if (ih) ih =3D 1 << 6; --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 EC698C76196 for ; Tue, 11 Apr 2023 06:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230342AbjDKGvD (ORCPT ); Tue, 11 Apr 2023 02:51:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbjDKGuj (ORCPT ); Tue, 11 Apr 2023 02:50:39 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A0340FB for ; Mon, 10 Apr 2023 23:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195806; x=1712731806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n8EBKPy48sTV6ZkkN0Av9i1KZOvW3Gj5TdFWIOX431s=; b=NJ7+aF/Ko46KeXHGCNniHLhGa0y4cNbYp3EM0cM60iB9owfAecD65g1h c++gpGjNZjN//F222LPSwh/p5WqEyNK/AXyrJ6UMq1SWDEM+y0WyrXz2H awRmcav2I0cFu/GVSIk5/w8YsAekenKruCJigr5BQjS9dCAlvkF0bi4Cc XAXeLMmTSzlF7tyMs74HzV/JtEPFQzUxnkYC06D8Da/105hc3fzKVAWWC 5ygkjal+j08JysmoLo4nPpbIwajuLjZm7orDm8mciEDg3Ck0Q3w3aSCce mPK0GmjYoOtj23aFp+FaDy3PRIDQuLdF9LzrWxGwk5XGCv0iZRP1bgwg3 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028622" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028622" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256637" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256637" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:40 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 14/17] iommu/vt-d: Remove BUG_ON when domain->pgd is NULL Date: Tue, 11 Apr 2023 14:48:12 +0800 Message-Id: <20230411064815.31456-15-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Tina Zhang When performing domain_context_mapping or getting dma_pte of a pfn, the availability of the domain page table directory is ensured. Therefore, the domain->pgd checkings are unnecessary. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-5-tina.zhang@intel.c= om Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index dd61bb554aa7..f11347a590d7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -915,8 +915,6 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domai= n *domain, int level =3D agaw_to_level(domain->agaw); int offset; =20 - BUG_ON(!domain->pgd); - if (!domain_pfn_supported(domain, pfn)) /* Address beyond IOMMU's addressing capabilities. */ return NULL; @@ -1910,8 +1908,6 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, pr_debug("Set context mapping for %02x:%02x.%d\n", bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); =20 - BUG_ON(!domain->pgd); - spin_lock(&iommu->lock); ret =3D -ENOMEM; context =3D iommu_context_addr(iommu, bus, devfn, 1); --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 43FA4C7619A for ; Tue, 11 Apr 2023 06:51:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230489AbjDKGvG (ORCPT ); Tue, 11 Apr 2023 02:51:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbjDKGuk (ORCPT ); Tue, 11 Apr 2023 02:50:40 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F43A40C3 for ; Mon, 10 Apr 2023 23:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195807; x=1712731807; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=INsqM7kHCgplauDTVYgaDtYvmiBKWDtVPT9hnQCqHlE=; b=ZhKohr+JvuvXqI4h2urTfshrnA4wkEzkBZIPER09sseMaazD4y28Tin1 +T4CucQYtXn1dMGvqqB0aKYvhxERtUNG08cpfbacqnw5CA+LauXS2Eb6D C/kN4mTufWrGIci7Mza1dasMlbG+0Rdzr/pCp8baE6zrTFESlGNdB9/4z honY5Bie/aR7eTDeC8xXQTAk6JTZJZ8qRO87PakJMXjzwSLpE4LBP75cV jEeiRa8MysKZvtLVomwvarChfGHfJH74TkVi+HBcU4UlBLWMMu3BzP3lQ yk4Gg4rVP7C8nVUj2/6Strhuzh3NfRZhIDM8Nzc7gS8fhfgtYeoJYAT+l w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028628" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028628" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256651" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256651" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:42 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 15/17] iommu/vt-d: Remove BUG_ON in map/unmap() Date: Tue, 11 Apr 2023 14:48:13 +0800 Message-Id: <20230411064815.31456-16-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Tina Zhang Domain map/unmap with invalid parameters shouldn't crash the kernel. Therefore, using if() replaces the BUG_ON. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-6-tina.zhang@intel.c= om Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f11347a590d7..ab21ef1ddb3c 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2159,7 +2159,8 @@ __domain_mapping(struct dmar_domain *domain, unsigned= long iov_pfn, phys_addr_t pteval; u64 attr; =20 - BUG_ON(!domain_pfn_supported(domain, iov_pfn + nr_pages - 1)); + if (unlikely(!domain_pfn_supported(domain, iov_pfn + nr_pages - 1))) + return -EINVAL; =20 if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) =3D=3D 0) return -EINVAL; @@ -4314,8 +4315,9 @@ static size_t intel_iommu_unmap(struct iommu_domain *= domain, =20 /* Cope with horrid API which requires us to unmap more than the size argument if it happens to be a large-page mapping. */ - BUG_ON(!pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, &level, - GFP_ATOMIC)); + if (unlikely(!pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, + &level, GFP_ATOMIC))) + return 0; =20 if (size < VTD_PAGE_SIZE << level_to_offset_bits(level)) size =3D VTD_PAGE_SIZE << level_to_offset_bits(level); --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 93668C76196 for ; Tue, 11 Apr 2023 06:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbjDKGvY (ORCPT ); Tue, 11 Apr 2023 02:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjDKGu7 (ORCPT ); Tue, 11 Apr 2023 02:50:59 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2F07421F for ; Mon, 10 Apr 2023 23:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195822; x=1712731822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tiukwRnefzsk0G3cv6MPqdFvIODlX3L3N/gwsxTD9ak=; b=TYYmQlf23hKJlTZzzU/jBNfNjkpByVzD5po2+SkVTTo6BFrhfPXwxSgP 5GOt5+DDR+DuhLorLkJFQ5OA8aIgBEqj7y90w9k7fA5NzCZlIK2sVjtuT 6njGOqZ2CnieccwCmUSlhZFBPMPj/+QI2zJZ8arY/HSO9+LCscqY4VwH1 g3SBkXgvAIRW5gtCXnSXHXoBZzr+orSk/sFZzeDqkc23KwUsy36Rxkj8D r7OIfn8oWRh5Mii6rEHHLCV8BGMnkQbEgCbl25aXN6DNaim67UZnbxz6S yHemX15qNV3nBS1wjLcgdtcPuBWkOhf4zPxINfiQ072ftcF+RoPJGUqUa w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028633" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028633" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256657" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256657" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:44 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 16/17] iommu/vt-d: Remove a useless BUG_ON(dev->is_virtfn) Date: Tue, 11 Apr 2023 14:48:14 +0800 Message-Id: <20230411064815.31456-17-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Tina Zhang When dmar_alloc_pci_notify_info() is being invoked, the invoker has ensured the dev->is_virtfn is false. So, remove the useless BUG_ON in dmar_alloc_pci_notify_info(). Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-7-tina.zhang@intel.c= om Signed-off-by: Lu Baolu --- drivers/iommu/intel/dmar.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index f0f51c957ccb..9346c6e7ebae 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -127,8 +127,6 @@ dmar_alloc_pci_notify_info(struct pci_dev *dev, unsigne= d long event) struct pci_dev *tmp; struct dmar_pci_notify_info *info; =20 - BUG_ON(dev->is_virtfn); - /* * Ignore devices that have a domain number higher than what can * be looked up in DMAR, e.g. VMD subdevices with domain 0x10000 --=20 2.34.1 From nobody Wed Feb 11 18:10:14 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 3D741C7619A for ; Tue, 11 Apr 2023 06:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230420AbjDKGv0 (ORCPT ); Tue, 11 Apr 2023 02:51:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbjDKGvB (ORCPT ); Tue, 11 Apr 2023 02:51:01 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B6D53AA2 for ; Mon, 10 Apr 2023 23:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195826; x=1712731826; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fGa6nb2+nmNFRDt+vgd1O06FQw1KI1Dbhhp5ECOkeNE=; b=kIW+aCys4lD6hXZtiL/eY38VZpRNUEXGUnU2IGka7+I/EDddG/NC3A0X YtHTHVADt8IckfaouP2LRtuU/Pf1hNaD2ccmxnoeQFh3oJKSY2HB/twSg gxafYtrvy58YlJNt6dTGwN7wy9MVTRsYXR7AcNFnLuYkL3+TxxsykPCCk FyWLj59aFdt4P+4k684doDKHjsL2BWexkn3UHYryPOvx4xaUX2pfeMhqc o8BN9+OODFEDg/UokQtJtjI2m8ESJ6joPWAdEWaFgyxOlyXOE2OKrSwuU v65vgfcp11AlHaihglSXcl3NhmUVwkH4I9MO7QoN8sILh3uKxtble8LST Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028642" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028642" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256664" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256664" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:46 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 17/17] iommu/vt-d: Remove BUG_ON in dmar_insert_dev_scope() Date: Tue, 11 Apr 2023 14:48:15 +0800 Message-Id: <20230411064815.31456-18-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-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" From: Tina Zhang The dmar_insert_dev_scope() could fail if any unexpected condition is encountered. However, in this situation, the kernel should attempt recovery and proceed with execution. Remove BUG_ON with WARN_ON, so that kernel can avoid being crashed when an unexpected condition occurs. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-8-tina.zhang@intel.c= om Signed-off-by: Lu Baolu --- drivers/iommu/intel/dmar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 9346c6e7ebae..e35be3786bde 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -262,7 +262,8 @@ int dmar_insert_dev_scope(struct dmar_pci_notify_info *= info, get_device(dev)); return 1; } - BUG_ON(i >=3D devices_cnt); + if (WARN_ON(i >=3D devices_cnt)) + return -EINVAL; } =20 return 0; --=20 2.34.1