From patchwork Fri Mar 24 12:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 74504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp578276vqo; Fri, 24 Mar 2023 05:16:07 -0700 (PDT) X-Google-Smtp-Source: AKy350ZpC6DO1HGgoDczACqKEdQ115lr1yGPr+mH5EvDJoVMnkRyyKovCgpK73Zbz3mNYToJnhYc X-Received: by 2002:aa7:dac6:0:b0:4fd:2363:16fa with SMTP id x6-20020aa7dac6000000b004fd236316famr2358620eds.41.1679660167099; Fri, 24 Mar 2023 05:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679660167; cv=none; d=google.com; s=arc-20160816; b=akClURMdO8EXPmTPzlvPc7rfzsly8Abd4C27ZQgV2iz3lCXadSyCo15G6uBszeXSSy L8p03CTKYd3EXUSllepYX5Hq7vZaKduWCnEozVh1cJD9aP5AEyzCKE4ZbSor4Nt/88Oj gJXF2BJJTF6N+X3B6IvsIY1BS19kiqDtKvaJ/4DU7joJ1rGEQ5XZp1mkrH9VjXa4CWmf KBBITlZI4pxgM0hKzIKjNsV3IfuqyNHo0V9aeU3WdqJ1oz2SCWDjfXLw28vePTcrtQeL jt9i/jjN26JGxPXluICssNQ5+VAvBvWtfTYU/fdSxXKLxO8wl+NAAwUqGiQXcemtORiN WuNQ== 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=B6aJHChCGFAPxVdUmCn98+T8sMZsy/AopGhIPbh5AAE=; b=TdhSeUXkEHUKtG+kqcfk3k8N5TdOSHzwWUdW90C/WxU3Tf5lhMZ0qX53uMRAHt2t9d KewQpvmHxQYBfXMbc7uPS0gsznIJfKyjNArbN8XuOTZesRdZX6YPvZbcSKn7gSsL38L1 BDRojbMvpKq7IYCjuon1uiCiJyF6GNKtdGCsyCJXPj9mFjVgQ62+V8gnA22BoIE1NuD9 DZ/ssxpzFacshnQBRYeX3cQOozXvCQpZrbWMC3EOetcAw7FKcHi3efRr07AFf2GoMje3 kq5k9k+eMCgZuSXVJyDz8hJTqhXcF8jOXRhEWmMWeEnY/PMlqMTsFnAgoOYL59ycFK+M xaIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DiFQlU9V; 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 w13-20020aa7dccd000000b004c5a8aa02fcsi22504984edu.435.2023.03.24.05.15.40; Fri, 24 Mar 2023 05:16:07 -0700 (PDT) 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=DiFQlU9V; 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 S231737AbjCXMC3 (ORCPT + 99 others); Fri, 24 Mar 2023 08:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbjCXMC1 (ORCPT ); Fri, 24 Mar 2023 08:02:27 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924CE23DBA; Fri, 24 Mar 2023 05:02: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=1679659346; x=1711195346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6qHH3kdmqICVZ9+zA4TiLrfUZ5cUI9ZxES/yWptHuC0=; b=DiFQlU9Vf64fnPa11KS8FDtZZJ2EKVuFQtZveMXYA8NmEoEwWx/LzNvJ MxdFy9hPhPRKC00u2JnxWeg0YrIjxN1a+XlqKBTi4df2CB2FrJZqjRRw8 +zWENGCQjlywANjBoq/koDEyqAnjLEfTpDV7YlyiupdjG4+qQLmDrTxxe bfY8XBZCpRwxqPFTaTYsQQXKUESvaonlIaa2eONd0YTV2u3j6fcPaeO6g XpeudK60LdyzcqZwsbmpOYsa4nhEpZwRYDVLdtSLWBbjFW5VAbI0vz9ba 2RJigUFL3RhCCy0t412CR88KfsIsXwv6FWZ16jyRuj8i59sa1YMR8hWVK A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="323634139" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="323634139" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 05:02:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="682674713" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="682674713" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 24 Mar 2023 05:02:23 -0700 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 v3 1/6] dmaengine: idxd: Add enable/disable device IOPF feature Date: Fri, 24 Mar 2023 20:02:29 +0800 Message-Id: <20230324120234.313643-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230324120234.313643-1-baolu.lu@linux.intel.com> References: <20230324120234.313643-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1761251339283465021?= X-GMAIL-MSGID: =?utf-8?q?1761251339283465021?= 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 --- 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 Fri Mar 24 12:02:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 74503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp577725vqo; Fri, 24 Mar 2023 05:15:21 -0700 (PDT) X-Google-Smtp-Source: AKy350bRB3DbeiwgIQcwOg0c5lOnyiCz8Tt6dlH9IEnb7iydwE0KZmY9hwkBgxYtsPFqZ5qgnxyd X-Received: by 2002:a17:906:3a45:b0:88a:cbd1:e663 with SMTP id a5-20020a1709063a4500b0088acbd1e663mr2664911ejf.6.1679660121818; Fri, 24 Mar 2023 05:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679660121; cv=none; d=google.com; s=arc-20160816; b=Lg4XfrS7hvh4u2VH/oMw9EctCAsMD7bVX4aB0S4czPLtCd6CME7J3QLHjH+hmzCCtK ZPk9sGqZQLS9VEBOnJe4enjbdbaMV0GVHt9u4smHRxPOG9a4Xp7r0yDq2AfvMKdSadbi Fpo/T/9lAXdat8djJ6Uvogga2UlSlE7+/IvYR5/oQrrikfJPZ3D6o777z8iV88d0Hi5/ cUtpFqMEo/NvxCyjEInvpaYsLnijv6S4Urv69tGOIVcrRk8Ut7WkK0/PXtCxOkKFEB7F Tfgmr6ryAsJsokLfeTJVwXKyE9LCWvhUDzH3kkOWQ4bixWIBdfC23mLt98BUt+akd/DQ 87mw== 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=Ksh6ctl3nmMpEdIYxe3rGXQPoy8q/FM63XcBO+hezMs=; b=hwdRjtX9aXsaJZP3jPJfug+1yYu3yI/tmakmvJyiqhsc257Y9BgBcOzZZt9gWfaUNn 28px2iZEW++A3LhpTSzXlu0aEtt+K+swjOAnppjF+FWMyO8zGAc50XphUjo1mAOrawQH sOmiM0LNRNircNe3oHHHIXKi3ymzGBxR7EeeViDJ1tMMDwVajNmGR2bVqO4Xieli9M+p WV6ta7aXhUxB1ZgX4fFkhwJUg5qTzyaWbx4vOjz71AkAIYXAPUm2U2VVwxxJO50zstu5 j1sJQlmLyZsMLWl0z4H93sVeyisjfpx5VyWP31uHKIwnc/6orwdfrbtzL7xsKAeF78/d gRPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gqITNorM; 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 wf11-20020a170907d68b00b0092ffc08bcffsi20552308ejc.535.2023.03.24.05.14.40; Fri, 24 Mar 2023 05:15:21 -0700 (PDT) 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=gqITNorM; 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 S231773AbjCXMCd (ORCPT + 99 others); Fri, 24 Mar 2023 08:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbjCXMCa (ORCPT ); Fri, 24 Mar 2023 08:02:30 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F2E923C68; Fri, 24 Mar 2023 05:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679659349; x=1711195349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6HPFNPQDz5pHaQknWW/YnEHrxyK/c9dkAaXEif8vAkY=; b=gqITNorM+C+pnjn4SwX5m1sFUFHtTtPw42toi+mIMcZtcPRZ2Q1BEyZd qlu1R3dlBKIxJWhaGt3I8TTazSRwhs4HKKforPWRQt4k/vsIHCEPvK28P NJ9IB4lq19RiirBJWdFG0iYh4eoQxpEE+fvCq728IWECY2r+fu4dJddqz PDbPBD15iLk5SR3A+r5g7kHxaxFJpEBzRkNFhcfa1nG1OU2bW/8H+FGG8 j/mAj3JMmGw2qLlYViGJrO0rUPpErisotfF8PQAq3X9gOuZPyqk7dV9QM I6xB5ktNLHly0n1TKmJCGIKEPA05TlNyrlXJHZ3h8D5xkLYgV02DuscjH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="323634149" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="323634149" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 05:02:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="682674743" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="682674743" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 24 Mar 2023 05:02:26 -0700 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 v3 2/6] iommu/vt-d: Allow SVA with device-specific IOPF Date: Fri, 24 Mar 2023 20:02:30 +0800 Message-Id: <20230324120234.313643-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230324120234.313643-1-baolu.lu@linux.intel.com> References: <20230324120234.313643-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1761251291709953065?= X-GMAIL-MSGID: =?utf-8?q?1761251291709953065?= 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 Reviewed-by: Kevin Tian --- 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; - 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; ret = iopf_queue_add_device(iommu->iopf_queue, dev); From patchwork Fri Mar 24 12:02:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 74500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp575357vqo; Fri, 24 Mar 2023 05:11:35 -0700 (PDT) X-Google-Smtp-Source: AKy350b9rc6vzrTEHYK78/S3BGma27Y5Gtz06P0AqGytciohp65KX5Co7lIE91pSl/+PYGg13t+8 X-Received: by 2002:a62:3897:0:b0:594:26a7:cbd2 with SMTP id f145-20020a623897000000b0059426a7cbd2mr2141730pfa.8.1679659895105; Fri, 24 Mar 2023 05:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679659895; cv=none; d=google.com; s=arc-20160816; b=dwp1j5KtnavQNG54F0RrzXjw5a78Hhw+7q0lmb+Yw54fdsjubUbLSdqIqc5zVnpi1Q 47WMeWmjjGsBvxmVtV3oavRGimTlCeAEU0VGRtUpKP9B9Nlaldptnrgjbu+7DnKlZPWG JAFqh3d2tArQzaMBBss0Z+u+3tLU7OjQ1NE9r73jboAY3wvq9sFpifjZidBtx3S/HaMn LLsOfcNxexlVIpCXkHpVYohIk2LPty3KZgftX5cSwH6YKyAj3/e0B2ndiNkwSJ4jYa1w HV93ekkTAf41pCnJJTuuAdB2gC8O3P6ASxd0TjTAQacyY11mwznetu6ZljjgczkzU2A4 uxeg== 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=gWgpbFHoFxODYgEW0zuoQ6H+mBOOazaN53iUY9CmKgs=; b=F4DVhBAvVFp5tmpKQYC1M546lNcJDAlU1YXb3dfe+VLRE3E/yTEzDZBiX8SJJJKynu boX5/++NiQXXzupCZASunnvD+Q3blI4UAg70Lf28bgevdwUWoRBEbV5Xt3RvoH0yJqWG s89YiBFWLKI+hhwovby0p+cJnmtHud8SkI66UOHiYJnfNiC6IideG7GHD7rHIvnwRU9J Pa+YU8pf5QVKK3XqaHsfq/G1Ceyupj2krjyg1A8stGu6OZ0RydUw44BOpxe+ORW/WRo3 RgAqqj0i6MYZ/MGP9lOc00nCDrLD4tQFxLWO5H7ZUuKWstz9Oc4dwW/n7OWWj/moZoGx LsOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mKWkI3tk; 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 r137-20020a632b8f000000b0050fbc594e1asi7540271pgr.207.2023.03.24.05.11.22; Fri, 24 Mar 2023 05:11:35 -0700 (PDT) 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=mKWkI3tk; 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 S231796AbjCXMCm (ORCPT + 99 others); Fri, 24 Mar 2023 08:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231655AbjCXMCd (ORCPT ); Fri, 24 Mar 2023 08:02:33 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44357241DE; Fri, 24 Mar 2023 05:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679659352; x=1711195352; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HlO9DJUB1VeUc0i1Z73Y/pek9tXf+C6otlR5IrcBXs8=; b=mKWkI3tkbYguRG4hfd0Vxh5zmLMtQfSXqG6g7fubW7ZC4xaIlP3hB2jN oMzCC4gWH6G8xqSOONZqo3Ud4OvWKULPApYZl2V4D3iTosTHedbbRa9wO RuDuOHUNDia6if7vXC94K3TZMVP1w7WwUf7plKR6rkpY7WcsCOkW6iI+1 QGocNBywheSpZGlIu9Z1r0zSe6ouvqBS9HJcrMRbyeN8bxZeakWdUT6fc Vgi1hTfJAs1RhLfVJO4TbxfUKMfO8sZc5/tmwgEcFwBPBmCzFweQH/KDC ZVtzGC+MXUw4kPXdR9I0IboIkJLz0IeOTDuGPZw9uzhGHXkJYySZJLdr5 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="323634155" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="323634155" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 05:02:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="682674777" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="682674777" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 24 Mar 2023 05:02:29 -0700 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 v3 3/6] iommu/vt-d: Move iopf code from SVA to IOPF enabling path Date: Fri, 24 Mar 2023 20:02:31 +0800 Message-Id: <20230324120234.313643-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230324120234.313643-1-baolu.lu@linux.intel.com> References: <20230324120234.313643-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1761251053961083706?= X-GMAIL-MSGID: =?utf-8?q?1761251053961083706?= 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 --- 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 = dev_iommu_priv_get(dev); struct intel_iommu *iommu; - int ret; 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; + 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; @@ -4678,7 +4692,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; @@ -4695,16 +4709,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) { @@ -4725,10 +4729,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 Fri Mar 24 12:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 74496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp571236vqo; Fri, 24 Mar 2023 05:05:54 -0700 (PDT) X-Google-Smtp-Source: AKy350YxE/EjrG7VKeXUHVojb9woyEBtfm366KBssbU+WdCVhxdeGHDrqIzEG4IoGL+dPBG5Hpds X-Received: by 2002:a17:907:c304:b0:931:b34:4172 with SMTP id tl4-20020a170907c30400b009310b344172mr3003343ejc.3.1679659554769; Fri, 24 Mar 2023 05:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679659554; cv=none; d=google.com; s=arc-20160816; b=iMJDCfO2KPOgr8old+RERFlNPI0OUmvY/dp5hCH6zMjDZRL31w3ympswjRzeGzzz6R anTaFcYi1YKGrm/tuKWYmNtDUgQRdoqpvE/p+tFoxLgE8oBNQ+9zkBLiReqJqWdBk3MO ISKmd/T6ftPMdhdrKf8x3lYCEn+r08Zux362NkOfm494fz8M7VUTSUvgy7I9PiB9Ec9s YW3Wq9rxFIYlwpqEmihUTwRJk2ejef2onWMH229iNSLGgjyGb84JXDqSWQP5+hLiwqqH iE0yJHV5x6tIofg4abbcmIpy0qLKQXVXRInvvemghHgFB39e04fcvDWhBmWdGyIqRO6t TmAw== 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=QgcDFR8T3T9VrARoIwv5Qb77OoMeX1anopeHzlaF3OE=; b=iG1UY/vgnmm0z0EC2XUnjqhYMb9I6JA3qMxtlReSx6UMgXKSAV0EuGYSpQd73eHNby 6H44b5xCgnLxCWxwc+zYI4gKAru1nVGE/+i0nG9oxU1R/2CQ5ggsSLJEMD2umhHhoQwI Ll8BLd7Hag6kWT1phDqGDcptO+v6CyN/wLo0U/wJBRl9W7epePxDbsRdS8z/zpRFrzU/ 8yH38rbUPMDbdDk/vpjch+BnVqjRPW6RzkYBTn38Ojf7Nw7xyPSC2i3wz5dwimS9rDhu bKUJThmWWro83qTD+ZjDFcrXMNHfCRDiAhdL9RlAhiIrI+8BKdP3+IyCODNpPQFqmy+P hsYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iEwNKOgj; 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 be19-20020a0564021a3300b004ad7ac04a59si389096edb.389.2023.03.24.05.05.30; Fri, 24 Mar 2023 05:05:54 -0700 (PDT) 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=iEwNKOgj; 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 S231795AbjCXMCs (ORCPT + 99 others); Fri, 24 Mar 2023 08:02:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231792AbjCXMCm (ORCPT ); Fri, 24 Mar 2023 08:02:42 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D6C7241DA; Fri, 24 Mar 2023 05:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679659355; x=1711195355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J8yNL0xsswqSZQ3dx1kUSPhIC1pxHFcfvF18SpMWQe8=; b=iEwNKOgjgV1jHggFkxUNPb36K7099jnco1mNGGWu5Dev1nys4vh3/aGz MhoowBbaUW72dKTqhh9D1NqGe5svBoA9MSEh/Ss6N+xLAOsiqTTqmwZ2H D3hKajKQ2ztElwm+THeM5m56GVv2ulRIRLM4JEbx7+5xpuUJ5nVG4urah 6meXjltwSHPxnhb8km19C19x8EAGZBpyP/0Om8C6n/ZzcvKYJZU1ueQ6E qFkAsLyWZdRhoI8EEUlXMJ/4ut5yUorAy909ExoUVCVQx4UUkdNv6SbKj iB/UEubMwxxXHwxNpCBOJqKXbmo84WbOzaJiO3eWq/0wklIqIQwl2uNKA A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="323634165" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="323634165" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 05:02:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="682674824" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="682674824" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 24 Mar 2023 05:02:32 -0700 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 v3 4/6] iommu/vt-d: Move pfsid and ats_qdep calculation to device probe path Date: Fri, 24 Mar 2023 20:02:32 +0800 Message-Id: <20230324120234.313643-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230324120234.313643-1-baolu.lu@linux.intel.com> References: <20230324120234.313643-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1761250697289480022?= X-GMAIL-MSGID: =?utf-8?q?1761250697289480022?= 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 --- 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_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 Fri Mar 24 12:02:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 74505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp579532vqo; Fri, 24 Mar 2023 05:18:08 -0700 (PDT) Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="U8cC2O/x" X-Google-Smtp-Source: AKy350ah2ZzLS0nZw2V1Asgc2Tvm13cZqFWjG3gbH9Mq2AUsJKIs3ujC/7PZhP8KBTd24PL+F3YN X-Received: by 2002:a17:90b:4b51:b0:22b:b375:ec3f with SMTP id mi17-20020a17090b4b5100b0022bb375ec3fmr2576210pjb.21.1679660288036; Fri, 24 Mar 2023 05:18:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679660288; cv=none; d=google.com; s=arc-20160816; b=p5X1hMVChG5ZN5dU96ejaSr9mS+Md/gw1Suc1bBvSG6see3McIqYtt2LlNoN+XX7Kf nZGLPczxcKnCl/EGY5DLjPkjxkVnAsnqInnSqXiTRS6rV3RJNd5uQxgmdLjK/As8PDLr X7e93JlLHuNzkr/CZdFftNqjc2yqj6/FdAlGtO3hSLKbhzJDKL3dFUB89gFpdhLX3GCV clRW1o6EXwCsOwQRqnJtqIEmGS968m9WkljB+l5TZlYToWfV2aX3O8Kzf1YZ7ylpUOb1 xiFAQI98MV0d8nrhtou433e3F6qzopf86nOvWGFcBbEzgOsYmKMlmK2lXEPVWIFOY7V7 oP7w== 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=/3m/BmZUYmYRPLtuCCw7FF5IJTTRNdNUyIAiYQK0LJY=; b=aNadOINMSMWj0oI56amOp5zDh0G3K0FtKEg8DeXoNqvXyJX6/R71q0htLQN+54ul+w a33mga1EseojicsGXbl2dlwf4RIzvYAk1yco5FMSOYrK60R77N0Zs2qijIlRn3ndxeUN auQf+DdKWfDwafbQvDXoGE9kz6S4t2csQRYNcbFMgzjArMRjyHro/fzzrSUTPIQ/GabP 9v8yUAfT1IKstw3k55fgddSRa8EjgHIvXJhPuyGztazjsLxZ9Lr5mcARHAYhNv3XCrhh /8W6x9YL5nZ1Pvyh4NCjIJbW5xe9kYAaFiC2b19HIiXKxIXMahcdt5eGy1/+S/P7MYH1 x2YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="U8cC2O/x"; 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 o3-20020a17090ab88300b00228e80888c9si4292949pjr.14.2023.03.24.05.17.55; Fri, 24 Mar 2023 05:18:08 -0700 (PDT) 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="U8cC2O/x"; 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 S231748AbjCXMC6 (ORCPT + 99 others); Fri, 24 Mar 2023 08:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231840AbjCXMCr (ORCPT ); Fri, 24 Mar 2023 08:02:47 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96E5C244B6; Fri, 24 Mar 2023 05:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679659358; x=1711195358; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nDsWWHt3XXkQGYiQaHFSNmSDapZTcbGSD8doZIV3ewQ=; b=U8cC2O/xvTnOy8Be1KmMz5zPdVy3edAdm5TraWFz42koY+b4X5NaoFyu Q+oglOYYjPAO/2RgSL6dsiU4ysLshElpyuMysMEGa26dOjRVVBtgcID93 6iXtZS/Q/3L/dF3OdsLrdm86nRpgTF+/OIXt5tDxBHwFNDmyU+LA3drVf YNAYD1cHvsedMA4aONdRnT1YSsT6gDGuwlmYWS6ltKx19LArX870HaxgA F1l+ZM7/Xsmaaxw9sY0xb25dod3yxZa6i0zlkSP0N82+/ZbdoDCA/eZIk UnSNFv0C4Ts6rxZ258nyPYt7iBFkHLICX6lyOzop9fqFMah/3oR3/b0EP g==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="323634179" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="323634179" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 05:02:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="682674883" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="682674883" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 24 Mar 2023 05:02:35 -0700 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 v3 5/6] iommu/vt-d: Move PRI handling to IOPF feature path Date: Fri, 24 Mar 2023 20:02:33 +0800 Message-Id: <20230324120234.313643-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230324120234.313643-1-baolu.lu@linux.intel.com> References: <20230324120234.313643-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1761251466457229835?= X-GMAIL-MSGID: =?utf-8?q?1761251466457229835?= 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 Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- 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_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; @@ -4667,23 +4657,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; } @@ -4694,6 +4709,20 @@ static int intel_iommu_disable_iopf(struct device *dev) struct intel_iommu *iommu = info->iommu; int ret; + 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 = 0; + ret = iommu_unregister_device_fault_handler(dev); if (ret) return ret; From patchwork Fri Mar 24 12:02:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 74499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp574583vqo; Fri, 24 Mar 2023 05:10:24 -0700 (PDT) X-Google-Smtp-Source: AKy350Z45JhZODSwi8hM1tJAzkCdwXdzlbvxQekyQJanemZ9cdGA3LqpdvQQSpRChy5cEHKQKAYV X-Received: by 2002:a17:903:2451:b0:1a1:8f1b:ed9d with SMTP id l17-20020a170903245100b001a18f1bed9dmr2692736pls.50.1679659823319; Fri, 24 Mar 2023 05:10:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679659823; cv=none; d=google.com; s=arc-20160816; b=v4zJaYreD7Q7bp2Ni1ovfQBwYpjY7a/dS9/fgsV2g9wESYRANNDtxLC9KwcTS5QDWf luvNy3CO+MTZzLMEV4tgnbdZFhiexbI1lm/EBxBblEnaRZK/2wT0myAjQvrWGdoVQuTV SqGxOfsIhLesgpLlm9MPaP+lTDeE9DvOvuxidu0AFkT0bO0F3vrVerF0Jpht21FWHOj+ wMoH9y+YaJ68qGfr7F47o5WoZyb7ZQBmwiasHmRTmFxtIQGvpg3/hFqKZS3gthSyenie EV4VrD3OMdKZ9qiJts9o0vql4aYF04yOaCMcosxhAf725I0UO3rF6zeJ3GxJcpzXtBbA bupA== 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=VqftfafkG8Qc4HhH2K2mFjxYxGgS4ILhCjDbKnbYsIU=; b=h3EUC9mYQb6E2MezpcM6RGK/k1JfhJ4zQLNahqRrmSLLqI6NnxFz4Ye9OwOYHFHKXX XwRK2psTAY95C7DYypbQg7ewDc6saeuO+GwnFcK7BCTouBPJU7Y8hiF2w7b25BNPCpyZ AKap1tmgaHVfrbwSCfeTQ1+XNEei6L868j9NXFinjkdJnf5stfFoqBRHpy1Dpd6fJwMK NRaI6Yejfh41eKHDlc2R1Zdj47u49LuSkaJBrA6tFEmMVeH2bxbbkBPScg5ckrnpMuV5 Vv2Xv3zJNOoEx3UC7hSKZ8HdJFIT/L9h4WVUdRE7FU28WnPhb0WsmArn/fEzbgba1hn5 dvnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tp5a5DlI; 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 bf8-20020a170902b90800b0019abdf99d41si20396297plb.157.2023.03.24.05.10.10; Fri, 24 Mar 2023 05:10:23 -0700 (PDT) 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=Tp5a5DlI; 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 S231899AbjCXMDJ (ORCPT + 99 others); Fri, 24 Mar 2023 08:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231833AbjCXMCv (ORCPT ); Fri, 24 Mar 2023 08:02:51 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A205265B8; Fri, 24 Mar 2023 05:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679659361; x=1711195361; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M/Jk/NyOL6YOkh9WpMFp/FMLnkzRYwNbBzLyoNFzzAU=; b=Tp5a5DlI92vpGpnCNmXRTLEMyGYXWHELMjRzcubt+IXqopxokZmzqfSW KVSN/K4KyaboIXyMOiehaL3XB5f6R1ZWMjduEBj56Sv/oZXVUYU2goAvK 5VbV+QrGuVMk4L6DHat3uMMRt2WcZF2ZUdb0TLcB4k+AxCRd8QucJSKys 89HQLLUybgG+nAwV4980m3FlgoSsJcBkHx0+kbrPL2hWtRBdAYUFeKtkf kQzvBdqY6XWAu2splMDWXmziMo4J5r/lzKq+O0+b3GvVF5j4tqjQkSkLO 9dgZMZzQ+W1F1XjNd3hPwzDnhrb28DP2wakcng75YVM0MXbDF7p1Fwe8o g==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="323634194" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="323634194" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 05:02:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="682674914" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="682674914" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 24 Mar 2023 05:02:38 -0700 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 v3 6/6] iommu/vt-d: Remove unnecessary checks in iopf disabling path Date: Fri, 24 Mar 2023 20:02:34 +0800 Message-Id: <20230324120234.313643-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230324120234.313643-1-baolu.lu@linux.intel.com> References: <20230324120234.313643-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1761250979009072701?= X-GMAIL-MSGID: =?utf-8?q?1761250979009072701?= 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. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- 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 *dev) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu = info->iommu; - int ret; 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 = 0; - ret = iommu_unregister_device_fault_handler(dev); - if (ret) - return ret; - - ret = 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)); - return ret; + return 0; } static int