Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp911634pxp; Wed, 16 Mar 2022 21:03:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8YkRJESRO25sJk9npfWAjG9s52RuB9Mhh3U+6WUh17ypLm8Gv7GG+F3SuThIcBZiBAsLl X-Received: by 2002:a17:90b:4b8d:b0:1bf:923e:a522 with SMTP id lr13-20020a17090b4b8d00b001bf923ea522mr13545215pjb.71.1647489792728; Wed, 16 Mar 2022 21:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647489792; cv=none; d=google.com; s=arc-20160816; b=oyqfLnsyfqOR4DjAdLKsUrJ5onAFzxgNGqCG7BBpMYKgZXBnvCiVgOdJEpZdZl1saO gqNC3jmjALps3S+wEDoNOcOQQmtrmW+nrqt+3mZ1fv9p93vbfHW+VVo59kLaJcyz4AAP 28AgLkec591cJ3ltbS/4g5SREr5M15YK8slJF4SyGO7QH8RQds0aKekYt9zq7by3HRfM atYpIhWE9cPggNg7/YHK2VQcZHhGbuzLPh9MzLI7CNev/DZUgS1UA407UReFWE8ArQF0 lgFA1V3R2bL+mXUn+y4LzsUK0hofE8ZP0BVgbEdaYGFq8YAREIj/QylqhnUBJgonux6y j+Lw== 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=QH/t2CqciYcVjhM4KKiN2cS6hqgyjuDz3OZm3P4TZ+Q=; b=OCcTpJq5USMS5kmrDbn1bzQNimeIVd37VZgkUKmZEbzvWLtatMy1+cA91vtTyElJjz lvb8iQKVmeyDGek2FxnIbv24ZtaZ4Sov2hzhoBZ3EnrsFTO5giN48AYph5/jGi/zfAPO bdUUsW5/oVgprTYGYRTyhEZPe+5xNo3sGKWrUr6PCcrt69Ryxn136WBPVCUasqKVzvfZ 4n03XUhvEFX9iVKVwEis2Ng1Kl8EBrSr8THMc+qQOrAUlClbaXZW2cuIN8yOot3Ebhr6 kgygd5X9S6Ed9EFHgmjzDVdjLFx7czLGQVADWLYvALIwu4G6E3Jh4SOApan8cMb6mhmu XHaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d9CYuwcT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m3-20020a654c83000000b003816043ee4csi929068pgt.65.2022.03.16.21.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d9CYuwcT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 085948F9BF; Wed, 16 Mar 2022 20:45:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344848AbiCOFNO (ORCPT + 99 others); Tue, 15 Mar 2022 01:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344851AbiCOFMV (ORCPT ); Tue, 15 Mar 2022 01:12:21 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 350304924A for ; Mon, 14 Mar 2022 22:11: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=1647321070; x=1678857070; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6uSpqGl1pbsEqnfIlo3vVDu6SwoYiBP9Hzf6kLLgWR8=; b=d9CYuwcTPTkqpN8Munh15JCMAam9CC9OQHu+6q9cM9/yQiUNvjQInBeq BpPhFDZvLJ99s0jsXx8atZwYoraF/IrqROn3+Ixd71q/GygZElT6+XzsJ KagRk0viMHoC+LDq4/z26xwyIoWsk6LMJKibFplDUEnbzUhMvo9CZGG3v Q1vwWuvRHrl+OvX5Mxxo2EkLkzB0WRDGvskOceC2FdjFxY3yt9JnVpGhC 5I6EJJOhk/KY7+kC9jFiBX3yxOdgf83fd0np42N1rJkfRqxoYsrCaYbPo qIc92tXKU5jXDFQeRI+CNoaHKH8STIO+tCIxi8bA0A05XQvu2kYRYoEG1 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10286"; a="236159110" X-IronPort-AV: E=Sophos;i="5.90,182,1643702400"; d="scan'208";a="236159110" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2022 22:04:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,182,1643702400"; d="scan'208";a="580383598" Received: from otc-wp-03.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.39.79]) by orsmga001.jf.intel.com with ESMTP; 14 Mar 2022 22:04:00 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , Jason Gunthorpe , "Christoph Hellwig" , "Lu Baolu" , Jean-Philippe Brucker Cc: Jacob Pan , Raj Ashok , "Kumar, Sanjay K" , Dave Jiang , Tony Luck , "Zanussi, Tom" , Dan Williams , "Tian, Kevin" , Yi Liu Subject: [PATCH v2 9/9] dmaengine: idxd: separate user and kernel pasid enabling Date: Mon, 14 Mar 2022 22:07:13 -0700 Message-Id: <20220315050713.2000518-10-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220315050713.2000518-1-jacob.jun.pan@linux.intel.com> References: <20220315050713.2000518-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Dave Jiang The idxd driver always gated the pasid enabling under a single knob and this assumption is incorrect. The pasid used for kernel operation can be independently toggled and has no dependency on the user pasid (and vice versa). Split the two so they are independent "enabled" flags. Signed-off-by: Dave Jiang Signed-off-by: Jacob Pan --- drivers/dma/idxd/cdev.c | 4 ++-- drivers/dma/idxd/idxd.h | 6 ++++++ drivers/dma/idxd/init.c | 30 ++++++++++++++++++------------ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c index 312ec37ebf91..addaebca7683 100644 --- a/drivers/dma/idxd/cdev.c +++ b/drivers/dma/idxd/cdev.c @@ -99,7 +99,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp) ctx->wq = wq; filp->private_data = ctx; - if (device_pasid_enabled(idxd)) { + if (device_user_pasid_enabled(idxd)) { sva = iommu_sva_bind_device(dev, current->mm); if (IS_ERR(sva)) { rc = PTR_ERR(sva); @@ -152,7 +152,7 @@ static int idxd_cdev_release(struct inode *node, struct file *filep) if (wq_shared(wq)) { idxd_device_drain_pasid(idxd, ctx->pasid); } else { - if (device_pasid_enabled(idxd)) { + if (device_user_pasid_enabled(idxd)) { /* The wq disable in the disable pasid function will drain the wq */ rc = idxd_wq_disable_pasid(wq); if (rc < 0) diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h index a09ab4a6e1c1..190b08bd7c08 100644 --- a/drivers/dma/idxd/idxd.h +++ b/drivers/dma/idxd/idxd.h @@ -239,6 +239,7 @@ enum idxd_device_flag { IDXD_FLAG_CONFIGURABLE = 0, IDXD_FLAG_CMD_RUNNING, IDXD_FLAG_PASID_ENABLED, + IDXD_FLAG_USER_PASID_ENABLED, }; struct idxd_dma_dev { @@ -468,6 +469,11 @@ static inline bool device_pasid_enabled(struct idxd_device *idxd) return test_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags); } +static inline bool device_user_pasid_enabled(struct idxd_device *idxd) +{ + return test_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags); +} + static inline bool device_swq_supported(struct idxd_device *idxd) { return (support_enqcmd && device_pasid_enabled(idxd)); diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 5d1f8dd4abf6..981150b7d09b 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -500,16 +500,19 @@ static int idxd_probe(struct idxd_device *idxd) if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) && sva) { rc = iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_SVA); - if (rc == 0) { - rc = idxd_enable_system_pasid(idxd); - if (rc < 0) { - iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_SVA); - dev_warn(dev, "Failed to enable PASID. No SVA support: %d\n", rc); - } else { - set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags); - } - } else { + if (rc) { + /* + * Do not bail here since legacy DMA is still + * supported, both user and in-kernel DMA with + * PASID rely on SVA feature. + */ dev_warn(dev, "Unable to turn on SVA feature.\n"); + } else { + set_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags); + if (idxd_enable_system_pasid(idxd)) + dev_warn(dev, "No in-kernel DMA with PASID.\n"); + else + set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags); } } idxd_read_caps(idxd); @@ -545,7 +548,8 @@ static int idxd_probe(struct idxd_device *idxd) err: if (device_pasid_enabled(idxd)) idxd_disable_system_pasid(idxd); - iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_SVA); + if (device_user_pasid_enabled(idxd) || device_pasid_enabled(idxd)) + iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_SVA); return rc; } @@ -558,7 +562,8 @@ static void idxd_cleanup(struct idxd_device *idxd) idxd_cleanup_internals(idxd); if (device_pasid_enabled(idxd)) idxd_disable_system_pasid(idxd); - iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_SVA); + if (device_user_pasid_enabled(idxd) || device_pasid_enabled(idxd)) + iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_SVA); } static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) @@ -677,7 +682,8 @@ static void idxd_remove(struct pci_dev *pdev) free_irq(irq_entry->vector, irq_entry); pci_free_irq_vectors(pdev); pci_iounmap(pdev, idxd->reg_base); - iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); + if (device_user_pasid_enabled(idxd) || device_pasid_enabled(idxd)) + iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); pci_disable_device(pdev); destroy_workqueue(idxd->wq); perfmon_pmu_remove(idxd); -- 2.25.1