From patchwork Thu Mar 9 02:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 66576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp61755wrd; Wed, 8 Mar 2023 18:59:33 -0800 (PST) X-Google-Smtp-Source: AK7set/7FgFqSXTJJgjR8vxyEesIzwPCEW6fRVBTtxVWFXsE+ckIFfvLe43aVQgDowSxW2yrMojf X-Received: by 2002:a05:6a20:ba94:b0:cd:f8c5:a9b4 with SMTP id fb20-20020a056a20ba9400b000cdf8c5a9b4mr17777190pzb.24.1678330773192; Wed, 08 Mar 2023 18:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678330773; cv=none; d=google.com; s=arc-20160816; b=wyTDZfToZ0oFw4YBXiSX5EH4fD2vCoZrqot6AoHq5CrjXobrE0wXzclRXZ6QpwLjjG NAJpZnGscW2zfm8TG7buu7oeLUQRR6lvPuMMqpYULH9oROi6mvymPoZBTZpEKRcJij2I km0CkBSqqcJUMuMJsepgqaSMgAO5SDhPVSCYwLhwYzf3kT+FunkqrrAFjy+mQxY4kuQX ek4x3m16wPebluAtMZKtvZJShHTcw21krvFNUbnrDbRSd4fG+htZS2rX6AVUR0RVsEza aGiqDDUtSrCC4jBNuIMVnwVar5pNqjPSseo7CmbqJnUYruhWaEuFmIGhcGWT0w8RgE/K vZaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4ZE88eSGzLZQlyDORv/e7uNbEVwJn9XL4MkjopoIa4g=; b=q6qTzxjEL5SjWxVQ7tGjCJv3rnus3wMnwRVY7cBPuCpnECH50+HkKdLFjkePq5J/Ij s+5gN/e6C4L+BDa0iY1Q8aWxC04Rrj3GOJyPykmR5mqV1g//KtIlQe6Rp+fPSoNEq8TO rmLH1U+36j1qjJva8RdswipLwcSj8zEQpcNfmNwZLOpgXXuJzXuuCQZD+xLM2LAdIxPS ZLloHRtmO9tZBnPnr6W2Fj2/Prfn1TL7fNn9GSXu9WdCnrXG1RU5m7wyVgPFk4rPUvBh RjgF465M2X2rfJbiobx1zM7nV+T4C+i7RzriWXWSou9hzCE154LBY4nAsTL9IfdHLzXc ICBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SL98nc+d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a63e24a000000b00502ea80c38esi15527334pgj.269.2023.03.08.18.59.17; Wed, 08 Mar 2023 18:59:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SL98nc+d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229972AbjCIC5w (ORCPT + 99 others); Wed, 8 Mar 2023 21:57:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbjCIC5t (ORCPT ); Wed, 8 Mar 2023 21:57:49 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 577BB91B4F; Wed, 8 Mar 2023 18:57:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678330668; x=1709866668; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Mr8/K6JBGpVgjtzlsLYvSNCRVB4WvcXxxyRVG14osPg=; b=SL98nc+dD5afs9cyGYSjig4cb5y9xRDawWza4Km/W1QlbUGntMdxXAZQ bPDExRvfbehP9GB2QNf6HDdZBOUWboW0HsKopo6E931AHGVZrjK0dB+ru aeHkExW6LZVBT1LGneXivUEfXV5Zc3gy6VFa9gc8Y4YE4MBQ33zOB3jYW fudLToUjkfnp1VAitFwBvizxVVPsKK1POwJH92EMp4UDCsk3MakU9szL+ rgPPjIQBRBhnXrXMniLN8g/gKp1hpVQJpBZQot+obYVxMdB5Uzfrmc36e vqR+UX6RanKrzVAbxQQmS85p6Fiv7Z+sjt2EMuK2dVabcq2dmbL6yUsEA Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="316732642" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="316732642" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2023 18:57:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="746144610" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="746144610" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga004.fm.intel.com with ESMTP; 08 Mar 2023 18:57:45 -0800 From: Lu Baolu To: iommu@lists.linux.dev, dmaengine@vger.kernel.org Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Fenghua Yu , Dave Jiang , Vinod Koul , Jacob Pan , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 1/5] dmaengine: idxd: Add enable/disable device IOPF feature Date: Thu, 9 Mar 2023 10:56:35 +0800 Message-Id: <20230309025639.26109-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309025639.26109-1-baolu.lu@linux.intel.com> References: <20230309025639.26109-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759857368867218179?= X-GMAIL-MSGID: =?utf-8?q?1759857368867218179?= 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 Signed-off-by: Lu Baolu Reviewed-by: Fenghua Yu Reviewed-by: Kevin Tian --- 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_device *idxd) idxd->sva = NULL; } +static int idxd_enable_sva(struct pci_dev *pdev) +{ + int ret; + + ret = iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); + if (ret) + return ret; + + ret = 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 = idxd->pdev; @@ -530,7 +551,7 @@ static int idxd_probe(struct idxd_device *idxd) dev_dbg(dev, "IDXD reset complete\n"); 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; } static void idxd_cleanup(struct idxd_device *idxd) { - struct device *dev = &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); } 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); From patchwork Thu Mar 9 02:56:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 66577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp61803wrd; Wed, 8 Mar 2023 18:59:41 -0800 (PST) X-Google-Smtp-Source: AK7set+PcSrPkLnUbKG1CcI4nL2pSJqJEnMngd8KSE9XIZ+0dN3t95bh8/AqqBS9hiCfnHzhkPsg X-Received: by 2002:a17:902:720b:b0:19a:7758:e5e6 with SMTP id ba11-20020a170902720b00b0019a7758e5e6mr17056142plb.48.1678330780866; Wed, 08 Mar 2023 18:59:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678330780; cv=none; d=google.com; s=arc-20160816; b=pkc0wkFYCDK9lyiEFZYXyS3z0iyminOxJFX6XadNsN5c7lsVUOOGwVEyLsY0aFKhYD uoCq47f9mVZCvFIXuHrY9bboyoMDAbK/7SojleBjC5eB0cIBPQSpmslq4HwbCyqGrC/L ZMe6B60mD72oqrZke7Ds0UVxvaTFx0ir507sgRrcAcxXLcEhdAbgSoXscquXnb/Y6KJi +on0y/JG3JR7a9oQ1C2cJvgMTveatcEYfqHAQTjEuod4+O+ZnyAluofD8wtCZVp3lA0J 0DQfBoP/+UoDnd+TdSAw1VIAGn0ehJqMiAHDIKSc/pn+TxrL1CmIHfwlHeFVNtwe/sEn V5tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cUqP0DoO5xn3OuP+kxqhlYJ/l6D8h5bmQOVw0yNk3OM=; b=xUMyuYszaXF+pk6/7fRQ/882/ymc5ZViGYKKnAxPwjGn83/z5KFQ6wCK9gYHsvG2uR HwYxk0jsnuD+5/R7QTCbrbYLSGcs9qq8TbwWzhVJ4+wbJdMk0Zn+iY5af+JhHWCO4ZvK 1qA/DSxG2F2QB+KmeB15BjJ5nKTRJ28uaHJcVtSs9dCRDKINVsJBO0NUjccUCzC3bFsH rlYmG/KccM44IZI07+ZkPTSVlr0ji+8EVmb+t9QLxg4jJ7YwUps0tw69V5en7eVZDf4h CkNUltiiB1Y/zXigPy4rMXnxQAxk98ABW4mnIvKMKzVlak3O9XOCyGTZ1DuEQJ2Bin0D g7IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PPxFmRDv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a1709027c8100b001943e4426a2si16212583pll.431.2023.03.08.18.59.26; Wed, 08 Mar 2023 18:59:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PPxFmRDv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbjCIC54 (ORCPT + 99 others); Wed, 8 Mar 2023 21:57:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjCIC5w (ORCPT ); Wed, 8 Mar 2023 21:57:52 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F6393E28; Wed, 8 Mar 2023 18:57:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678330671; x=1709866671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QiXay9B0/cIAt+xudzeSslyrWr7mHV5btFCAUOhzZSY=; b=PPxFmRDvHxBKoeUka0ZcsPRp+1bMbvOVNvUTRF6sCG8RvEAhHeQUsCx8 5gj2oscSkqY1mp6WQ5fGDHjN/UITF4VOIoQbtKW8gZCHDFz3mHblYoc1I WRxz4zjxF94NDjh3eYoxtwmLKR3eU74F6L+HQI78WKe4CJ9AbWGxtw0fA TNPIZe87cQyLpPU2rhpCnDQwmxj3G6i4zk1Bdo1ASdVrbnqlW85WFZG55 H3od8BtlvQoTt3AE6uJncYgSYBHn1oOgeZcBgk/yLVMtPTzTo57azl93G RHPbCAn2qAM1VovoZ+qqushtjm/FcRrXBCz4vcxrnk1DR4ntpNNiS//uU g==; X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="316732654" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="316732654" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2023 18:57:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="746144621" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="746144621" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga004.fm.intel.com with ESMTP; 08 Mar 2023 18:57:48 -0800 From: Lu Baolu To: iommu@lists.linux.dev, dmaengine@vger.kernel.org Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Fenghua Yu , Dave Jiang , Vinod Koul , Jacob Pan , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 2/5] iommu/vt-d: Allow SVA with device-specific IOPF Date: Thu, 9 Mar 2023 10:56:36 +0800 Message-Id: <20230309025639.26109-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309025639.26109-1-baolu.lu@linux.intel.com> References: <20230309025639.26109-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759857376917498734?= X-GMAIL-MSGID: =?utf-8?q?1759857376917498734?= 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. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 7c2f4bd33582..d2fcab9d8f61 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4650,7 +4650,18 @@ static int intel_iommu_enable_sva(struct device *dev) if (!(iommu->flags & VTD_FLAG_SVM_CAPABLE)) return -ENODEV; - if (!info->pasid_enabled || !info->pri_enabled || !info->ats_enabled) + if (!info->pasid_enabled) + return -EINVAL; + + /* + * Devices having device-specific I/O fault handling should not + * support PCI/PRI. + */ + if (!info->pri_supported) + return 0; + + /* Devices supporting ATS/PRI should have it enabled. */ + if (!info->pri_enabled || !info->ats_enabled) return -EINVAL; ret = iopf_queue_add_device(iommu->iopf_queue, dev); From patchwork Thu Mar 9 02:56:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 66580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp66776wrd; Wed, 8 Mar 2023 19:12:03 -0800 (PST) X-Google-Smtp-Source: AK7set/Zlsd7JUg6kIvVq762K2r4I9Tf7ExJjiV7mXsPaqwlZ6+lGYvB7I7xQy5kMu1SnEQHwz1F X-Received: by 2002:aa7:8f04:0:b0:5a9:d58e:796f with SMTP id x4-20020aa78f04000000b005a9d58e796fmr18460277pfr.29.1678331522880; Wed, 08 Mar 2023 19:12:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678331522; cv=none; d=google.com; s=arc-20160816; b=M3vVlJ8LMwwdNAHU+0srWxfEBKpijS0iRThik85uVb4vOGkp03RI/ci+cXDU99K5Ea coaPe3PsOz6isQkLgnlXKFpcD9/oKPykLb4XZAHM7Pg8QZDNHpZYUv2h+dCOTBGoWxJ9 l8pTufoH9rpXk7ttcEbrl/9jLDd6e8qL3R4KSB2PEgEfpOEtlRrErXb9hKUfDgOI8EJf WFab682TN+RzLBczL6esffTa1j4dT0PsLkxJ8SuKzo1fHeJFxgSbJvo8qKNCQqx4XWKn BnagYTKh+XdRUVHwL13AAmSB1MX2pXjr8/Veb12OyhAa54dRqtYaesyuk5gW0Y0LXe+f rRTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bsHsyakN/HeFH+oxKZKgKSqrL+LypyADpdpa08QS5qQ=; b=YzIBxbJiToCLlyuulG9Ng9XHnVFhI08oetihy2sIf8z7AEeJCHZnKD4f142CbUtdUx Gd48JTNPRmfgQcnm0yBprRaov380mmlI1h1GHdBdZWegR9UfAM3V1Zzprg5pijGbftoy l9OjnPEDXhf33cKJN7k6L78MRFfts6k4N6gfw9wpukCe50eZ3tZDGmm0RYG/Wu6CdOX9 tHmimdICEKNjh+5BP0sYh/whC2kxABiGZoJ8tyGO0ARz2ORe9zalqtOV5QshCb3+CvIl b68Pj4h9vd1j0d4G/T6yyC500m5Ydu56PSmJR7nJB43TSNnakDx68OSXJT+N7ZF7ruJi derw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T1jtIMoj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a63f14f000000b004fbd2b7c90bsi16268299pgk.586.2023.03.08.19.11.49; Wed, 08 Mar 2023 19:12:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T1jtIMoj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjCIC6H (ORCPT + 99 others); Wed, 8 Mar 2023 21:58:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbjCIC57 (ORCPT ); Wed, 8 Mar 2023 21:57:59 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE117C2; Wed, 8 Mar 2023 18:57:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678330673; x=1709866673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=etYi5IgjOwIgLSDHDiUJVx1EpEQNh0CUBtN03FXsKLI=; b=T1jtIMoj/pvcqeSe6RpJP3cWUpGcC3CSakeV73Nlvd4OyQQAptfk2wtl ZgKrhALURGcqyhee9pnjjq9z3OiymoBwLxbb6t9eHFgFEn0hDgKail+3t RYPVsD9PnAUL6MJ5jSF7sDxG7RCl2fN5Fa2MyBm+auTZBdXEWp6IsD1pY 9ryiAoeN1au9wR/xh1EuftSQP2McLqTWDBw8V7KixEaSZq3BiVa7kdZvy hR40+0RNbwhmL9NJN7B5DgOLq2nbRGFjGof4O198+BDSlVYd6tTzpktPJ r7YXoBsq+9SGhEjAxCKYpn+9+soP3pWTrIlriiHqtdgeP4azGoXJ94b8o g==; X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="316732664" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="316732664" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2023 18:57:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="746144632" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="746144632" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga004.fm.intel.com with ESMTP; 08 Mar 2023 18:57:51 -0800 From: Lu Baolu To: iommu@lists.linux.dev, dmaengine@vger.kernel.org Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Fenghua Yu , Dave Jiang , Vinod Koul , Jacob Pan , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 3/5] iommu/vt-d: Move iopf code from SVA to IOPF enabling path Date: Thu, 9 Mar 2023 10:56:37 +0800 Message-Id: <20230309025639.26109-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309025639.26109-1-baolu.lu@linux.intel.com> References: <20230309025639.26109-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759858155106042231?= X-GMAIL-MSGID: =?utf-8?q?1759858155106042231?= 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. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- 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 d2fcab9d8f61..9ada12bf38dd 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 = dev_iommu_priv_get(dev); struct intel_iommu *iommu; - int ret; if (!info || dmar_disabled) return -EINVAL; @@ -4664,6 +4663,21 @@ static int intel_iommu_enable_sva(struct device *dev) if (!info->pri_enabled || !info->ats_enabled) return -EINVAL; + return 0; +} + +static int intel_iommu_enable_iopf(struct device *dev) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct intel_iommu *iommu; + int ret; + + if (!info || !info->ats_enabled || !info->pri_enabled) + return -ENODEV; + iommu = info->iommu; + if (!iommu) + return -EINVAL; + ret = iopf_queue_add_device(iommu->iopf_queue, dev); if (ret) return ret; @@ -4675,7 +4689,7 @@ static int intel_iommu_enable_sva(struct device *dev) return ret; } -static int intel_iommu_disable_sva(struct device *dev) +static int intel_iommu_disable_iopf(struct device *dev) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu = info->iommu; @@ -4692,16 +4706,6 @@ static int intel_iommu_disable_sva(struct device *dev) return ret; } -static int intel_iommu_enable_iopf(struct device *dev) -{ - struct device_domain_info *info = 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 feat) { @@ -4722,10 +4726,10 @@ intel_iommu_dev_disable_feat(struct device *dev, enum iommu_dev_features feat) { switch (feat) { case IOMMU_DEV_FEAT_IOPF: - return 0; + return intel_iommu_disable_iopf(dev); case IOMMU_DEV_FEAT_SVA: - return intel_iommu_disable_sva(dev); + return 0; default: return -ENODEV; From patchwork Thu Mar 9 02:56:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 66579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp62951wrd; Wed, 8 Mar 2023 19:01:52 -0800 (PST) X-Google-Smtp-Source: AK7set/AtZ74cWsdYhSYHHb0cf7gRDgSvp58xMAJigwOZm2npCjzMSYSZk2CUcoGalpHYNBOYq1j X-Received: by 2002:a05:6a20:7f5c:b0:c2:b6cf:96db with SMTP id e28-20020a056a207f5c00b000c2b6cf96dbmr16241592pzk.39.1678330912536; Wed, 08 Mar 2023 19:01:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678330912; cv=none; d=google.com; s=arc-20160816; b=fzQGeHatpbQn5enypDIfs5zLt3impbuQRa3MVMBR19x8kXdY+jLTCw7kuLZOjhPxEK /xpbFfsM9eSLUeddSZ8K9FFYVK2q1XRiVkoymJpx4L1Qt1cTX1rVLYPisGmWzg1PGqFa WO7q5vdulac0b38LNy7Imv1qvGdVZdAQAEFMfvl+qD6MPiRk4A4JxXuw7n5sKIJKK3Ou 5+0uwtXUxK51fR4/YfGgQTXxCLghy7zdeK7EbhdiGY4QILzLa+fNv6R5XEbi7WegtaT3 BLwjIHFk4zlg/hf91WNt89FORHyacIV6msJiatUsU0HBs6KiOeP5vNuk9tdI1ul5Gprx wzWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VJjXP53j8KX77+LAr0EZKnG+N1prrviSIVvCAMcwsxY=; b=uDMjS+IaIE8cNKnR8406WTk9reAtENucOHSbMexRPAq8qflIaUqIcYFBmkroHNjI2+ PiRGg7TNXYVakpgp4s3BFrB01mStOQDc16Nmw4KV2J+RE+Q8Tf7tevMNukZiYBanFBkE wTheotFoK2TW5kIoMGWQA/DE/Tc4PvTcHaJDrNAsLck8sgoFDuvXDhiNNGYFtiZJqfcW +khku+WqxPxI6ktzaJSthD6SbrO/XNEmCVTt14/Nt+W8DG4N/0oFil2h0AtOZFcQ+fsX JG6q1z99Yzpx8zyDuQ5XG87zb3tnCNE4Ij0tm8ahrGXihNrlaDWFNWIv72esjE+fX0dS lmoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g4CZfSAQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t186-20020a6381c3000000b00502f4fd0c16si16813499pgd.653.2023.03.08.19.01.35; Wed, 08 Mar 2023 19:01:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g4CZfSAQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbjCIC6K (ORCPT + 99 others); Wed, 8 Mar 2023 21:58:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbjCIC6B (ORCPT ); Wed, 8 Mar 2023 21:58:01 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0407DBDE; Wed, 8 Mar 2023 18:57:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678330677; x=1709866677; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ue30EGl5GVT7NuvhkyMNOql0d+yRmWolurmgmiReO2I=; b=g4CZfSAQb1LE6z95oBCs0Js4HWV1KZOsB+JApu2+eowu3QYFDLokPpww 5m06CdAn0HeDPd+CZr4zszTdItrsH9hDn+aoJWXA0kD8RMWt6GkgCKIeP Ok1HyeoejD7Ni0ddtr9wl1gaJ/xlNJUGHqCdbXezCRz3oQhne8bZTQC9h o9I0oGZ3uI6mxwScDNEtxysZDDbbN5grKUy8Nbxrdg03ecpjDm/Q2r0zw gYaHQqyP69mSzzvPqYOP+mmi43wYInjPMF66cEOVIQ76s5j/yBTNdx05j cudPwIo5wo4kFvrqfShOGRa6/bcyJ855uGA1rybTBdDRGsxEf2mqHWaR4 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="316732675" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="316732675" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2023 18:57:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="746144644" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="746144644" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga004.fm.intel.com with ESMTP; 08 Mar 2023 18:57:53 -0800 From: Lu Baolu To: iommu@lists.linux.dev, dmaengine@vger.kernel.org Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Fenghua Yu , Dave Jiang , Vinod Koul , Jacob Pan , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 4/5] iommu/vt-d: Move pfsid and ats_qdep calculation to device probe path Date: Thu, 9 Mar 2023 10:56:38 +0800 Message-Id: <20230309025639.26109-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309025639.26109-1-baolu.lu@linux.intel.com> References: <20230309025639.26109-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759857514771196503?= X-GMAIL-MSGID: =?utf-8?q?1759857514771196503?= They should be part of the per-device iommu private data initialization. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Jacob Pan --- 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 9ada12bf38dd..fb64ab8358a9 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_domain_info *info) return; pdev = 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 = 0; - else { - struct pci_dev *pf_pdev; - - /* pdev will be returned if device is not a vf */ - pf_pdev = pci_physfn(pdev); - info->pfsid = pci_dev_id(pf_pdev); - } /* 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_domain_info *info) !pci_enable_ats(pdev, VTD_PAGE_SHIFT)) { info->ats_enabled = 1; domain_update_iotlb(info->domain); - info->ats_qdep = pci_ats_queue_depth(pdev); } } @@ -4521,6 +4506,17 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) dmar_ats_supported(pdev, iommu)) { info->ats_supported = 1; info->dtlb_extra_inval = 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 = pci_dev_id(pci_physfn(pdev)); + info->ats_qdep = pci_ats_queue_depth(pdev); } if (sm_supported(iommu)) { if (pasid_supported(iommu)) { From patchwork Thu Mar 9 02:56:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 66578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp62427wrd; Wed, 8 Mar 2023 19:00:53 -0800 (PST) X-Google-Smtp-Source: AK7set8/zM0/8Wvut4wmSZrDDnz1GbQCmuC3Uv1JzKZ1WZmzvWMhIu335NZQTwqUJi5ucSxDh87S X-Received: by 2002:a17:90b:3841:b0:237:461c:b31a with SMTP id nl1-20020a17090b384100b00237461cb31amr21609082pjb.32.1678330853545; Wed, 08 Mar 2023 19:00:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678330853; cv=none; d=google.com; s=arc-20160816; b=NkkZ+EjIrmaK+0TET1dAzjZBJsMzQczPTz2DEzEJ1/C5Dce5NEaYvpDhUCb66hgGUU OWNGlD1emTjErOw5DTv2rMihW9r8F0vu9/9bUixx3ClXeDmm80AfJ/JC5UCP0Z6ffirJ uVdWzmMGUpuTpR+dJ8sVS3Lesveds/4BeyBa9/voGsy2P+gkVNVxA29ybzxlwjWwZ42g 5ew+j3j1j1+lf/AtPvKXbJMzGOn7YYpLvvS+kKHyjMrMRSBjyxOs+oZ9UQvu31qgPzN/ I3SBKT1rPmDMBX7/mNnw58QSMMQ8NjmZQAxHOjiFwZeiFPug8ja0bQKo7QdaWbrBQlJ3 AXvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iasINMQeEXUib4jj/xG77E0o3Jpcn8+Tr+Z8aqUrLno=; b=vQt0ryXyWiMk1SB8/mOkrRo/F7fyJakk4lzX5uOHz1spuuWj4I7vBCLOcdpxJukzuq tel+LC9aW73GKIMOnLoQoBdfDbvBmiCZJ1PrnC4tXPzrThkE/ghUbemfIW/+W4VBGbru PpSkMg4tvzCriqfgjZINCtdekCTTYuuWOzhZFh9aNYfRzZj3+Bz+e1ZpOUIHVUU+7Wn+ nCtTAiVP2dW6nM+UPKzkK2dTtztWi+hZZPNf0hUbHzUwnMkefzWYqEWt9w7HpvgPB6Wf O5OSUACMfqFnQouEC1XxNwSNM8RN6H2acKwlRYZ+fgqp5hI3z67qWSnki9NNMNPdYcY2 iSww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HUYjJpUu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a63e855000000b004786e4563c3si16547265pgk.751.2023.03.08.19.00.37; Wed, 08 Mar 2023 19:00:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HUYjJpUu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230110AbjCIC6P (ORCPT + 99 others); Wed, 8 Mar 2023 21:58:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbjCIC6E (ORCPT ); Wed, 8 Mar 2023 21:58:04 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF7B2244B3; Wed, 8 Mar 2023 18:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678330679; x=1709866679; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hyRAeVg/VZEIlAorH/vE8IpPiieMJP0llhhFp7ElHnk=; b=HUYjJpUuAfVFpx0LrgbR1Y23EX3ApUBeCDzIAGfCk6CgqgYQU40Ml6vh iEX9zsTWCy5mQLi7hMu4sBcVpwtl24YAc8Sv66pBxx/UzRq6TvVDfd+ta lVm8bNhVWQiHSJI4xctLt/lt9ZC86h1b/nnJMc0MNoArmTMu7H4BXA1aT aapUg5a0QQWRitTAFIeg2GU8JX7wcZREV1JMwRxA3FddcBLiVDyi6ID+V bPobRnfcwodojfCxZVYN1Ww3Kd1qKMjqradbajb5tFdfo2Bj4z4FiPe5e DVBht3TZ2HOwsNnYwzcBn1XxK49JmllTKuaIScpHgrkZKEQnMLDehkO38 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="316732691" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="316732691" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2023 18:57:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="746144657" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="746144657" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga004.fm.intel.com with ESMTP; 08 Mar 2023 18:57:56 -0800 From: Lu Baolu To: iommu@lists.linux.dev, dmaengine@vger.kernel.org Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Fenghua Yu , Dave Jiang , Vinod Koul , Jacob Pan , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 5/5] iommu/vt-d: Move PRI handling to IOPF feature path Date: Thu, 9 Mar 2023 10:56:39 +0800 Message-Id: <20230309025639.26109-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309025639.26109-1-baolu.lu@linux.intel.com> References: <20230309025639.26109-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759857453010175123?= X-GMAIL-MSGID: =?utf-8?q?1759857453010175123?= 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. Signed-off-by: Lu Baolu Reviewed-by: Jacob Pan --- drivers/iommu/intel/iommu.c | 59 ++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index fb64ab8358a9..4ed32bde4287 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_domain_info *info) if (info->pasid_supported && !pci_enable_pasid(pdev, info->pasid_supported & ~1)) info->pasid_enabled = 1; - 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 = 1; - if (info->ats_supported && pci_ats_page_aligned(pdev) && !pci_enable_ats(pdev, VTD_PAGE_SHIFT)) { info->ats_enabled = 1; @@ -1442,11 +1437,6 @@ static void iommu_disable_pci_caps(struct device_domain_info *info) domain_update_iotlb(info->domain); } - if (info->pri_enabled) { - pci_disable_pri(pdev); - info->pri_enabled = 0; - } - if (info->pasid_enabled) { pci_disable_pasid(pdev); info->pasid_enabled = 0; @@ -4664,23 +4654,48 @@ static int intel_iommu_enable_sva(struct device *dev) static int intel_iommu_enable_iopf(struct device *dev) { + struct pci_dev *pdev = dev_is_pci(dev) ? to_pci_dev(dev) : NULL; struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu; int ret; - 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 = info->iommu; if (!iommu) return -EINVAL; + /* PASID is required in PRG Response Message. */ + if (info->pasid_enabled && !pci_prg_resp_pasid_required(pdev)) + return -EINVAL; + + ret = pci_reset_pri(pdev); + if (ret) + return ret; + ret = iopf_queue_add_device(iommu->iopf_queue, dev); if (ret) return ret; ret = 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 = pci_enable_pri(pdev, PRQ_DEPTH); + if (ret) + goto iopf_unregister_handler; + info->pri_enabled = 1; + + return 0; + +iopf_unregister_handler: + iommu_unregister_device_fault_handler(dev); +iopf_remove_device: + iopf_queue_remove_device(iommu->iopf_queue, dev); return ret; } @@ -4689,17 +4704,21 @@ static int intel_iommu_disable_iopf(struct device *dev) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu = info->iommu; - int ret; - ret = iommu_unregister_device_fault_handler(dev); - if (ret) - return ret; + if (!info->pri_enabled) + return -EINVAL; - ret = iopf_queue_remove_device(iommu->iopf_queue, dev); - if (ret) - iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); + pci_disable_pri(to_pci_dev(dev)); + info->pri_enabled = 0; - return ret; + /* + * With pri_enabled checked, unregistering fault handler and + * removing device from iopf queue should never fail. + */ + iommu_unregister_device_fault_handler(dev); + iopf_queue_remove_device(iommu->iopf_queue, dev); + + return 0; } static int