From patchwork Tue Apr 11 06:48:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 81771 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2374772vqo; Mon, 10 Apr 2023 23:59:49 -0700 (PDT) X-Google-Smtp-Source: AKy350bxEwJWzEwN5F4dqqMrohXW7crP8E5KG2NmOHUZ+cUJsIIUj2fGiTV+q6qVlqfV78s7DWtN X-Received: by 2002:a17:90b:1bcf:b0:23d:39e0:142 with SMTP id oa15-20020a17090b1bcf00b0023d39e00142mr17749055pjb.42.1681196389579; Mon, 10 Apr 2023 23:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681196389; cv=none; d=google.com; s=arc-20160816; b=fucX7DSXoYZ9kfFz0YiouviKknyLDUM4hXCHTdjtKi4Snw5cdLIcNWEYSVx43AJX3W 9Le2i17bBMTow/MHUMnM5W+VjHHco+Ina1ABl92mt5pjsLbzvFj+8AbeCpjkM/E5qx6C dah1NvNOaw3f833ofT5z3VA82PzjxDZlM6JfK4Gn97CEWUnUbVa1SiNJ6ebtvqvPCqvS QxiDX6/xLk5RgYhalCikX4Yb6LlY4Wer4aUXKGMLbfOELmAHkzAwXSQ9E4Xnhl1YfVJ/ RTb+0aN/drkCh1+8D5FLMgSB1rrjUXl/rg99Jv1qnyKgOZaJ0UE1nGqaXtZ28JX4RhFe /oVg== 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=kHUpPjSNJ6c0EqsxjYcImO5F3N1y9C3adyprfWloZvw=; b=X2gJpGBhL1qBny4fPukUHwN0SNXxAY4dddsdlCs6bcp8Mo0vHgth17j61XAxLnfPE+ W7NWnmvl0PFetZcK9dEQWvWNi6VNSTzCJNIPSVxHsZSQCn/XS/bV3sTlJY6JsAGlX/ar HUdal+UZZEt5pXoGRtd6kx4rC8nNy70pKv+IfHUCwU0Xqgm8hgHIytQuwlSPmSdJr57X +/8cLLs7juq5ump+/wDbWIHPcvXR3i2oYipLB4sVYoStxrh1FZpV6Fw/Bp4nWJ4JLyWL d1d8tyC+fcOUey+gct1i1wG+R7hxmo0gaKDd2PFPAyJdEBySROgy+7M+NjLODWKfEtfh 6o5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cWQ5TCJE; 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 c4-20020a170902d90400b0019ac7319ecdsi6390698plz.409.2023.04.10.23.59.36; Mon, 10 Apr 2023 23:59:49 -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=cWQ5TCJE; 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 S229881AbjDKGtX (ORCPT + 99 others); Tue, 11 Apr 2023 02:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbjDKGs7 (ORCPT ); Tue, 11 Apr 2023 02:48:59 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A974496 for ; Mon, 10 Apr 2023 23:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195718; x=1712731718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AH2O7XJ83CyJq/BvNVtHKqMDArNO32apjduqQxjWqso=; b=cWQ5TCJEjNL1aWnMqBR8UzCGqH2DY9kLGPSCpeJ1FEU2AOfyPKD2UYPs GoThGqnamTXZD+XtpBDO6kqA6GB24iF8xjMMxNXWH9RfORYBjkDWKNz3w B2RBv4nqPL5cdY6LCADDQ2HKKrLVzMZbL0JP4/hivp0X2IEWqNZ76z1UI bqtrmtOlOXe+cE6eqUF1a0fuUjYtarcUmNqtSGAJcMhAocQ9qfmr9O6xV peyWC4wAerkfsENFEw5UY6DtxFaOH4l98PLKDETmehD3ki7/V4rM8roUi U16NxpHTn47Hj5Qo2BI/jVjr82WIEQ+AmuyO2cZ6c9ytjSS84OZ2YmNHg Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028514" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028514" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256547" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256547" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:15 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 03/17] iommu/vt-d: Move iopf code from SVA to IOPF enabling path Date: Tue, 11 Apr 2023 14:48:01 +0800 Message-Id: <20230411064815.31456-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1762862185499359222?= X-GMAIL-MSGID: =?utf-8?q?1762862185499359222?= Generally enabling IOMMU_DEV_FEAT_SVA requires IOMMU_DEV_FEAT_IOPF, but some devices manage I/O Page Faults themselves instead of relying on the IOMMU. Move IOPF related code from SVA to IOPF enabling path. For the device drivers that relies on the IOMMU for IOPF through PCI/PRI, IOMMU_DEV_FEAT_IOPF must be enabled before and disabled after IOMMU_DEV_FEAT_SVA. Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-4-baolu.lu@linux.intel.com --- drivers/iommu/intel/iommu.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index caf664448ee9..a6f07c74da2d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4638,7 +4638,6 @@ static int intel_iommu_enable_sva(struct device *dev) { struct device_domain_info *info = 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;