From patchwork Tue Apr 11 06:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 81781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2381004vqo; Tue, 11 Apr 2023 00:12:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ZX8HIdfuEgEiGXCLR+koPD/77Qw6l471lPFCS11FEvfHkRqtTUExvJLhrk0WSRKHFiKNRJ X-Received: by 2002:a17:903:24c:b0:19e:500b:517a with SMTP id j12-20020a170903024c00b0019e500b517amr17040252plh.69.1681197164014; Tue, 11 Apr 2023 00:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681197163; cv=none; d=google.com; s=arc-20160816; b=GzAjq04ZcvR8EJlb5Oljjb6Pm17HR4TiLRcvxbpcB/OjXCWVLWxAWnfWq/LCx0c5p7 5T6e2umDLZZgymaVvZgA/zwcADqz2/xWOVehn2I65y7ls9Aiqo71+Be+nbk71RJP7Bz0 ZTsbJQ08Xst1rWeHHU5wWRvIEEufOEptilofnJsamgGnyD+AWz1w59bML66c94MzOBEa ck5bn+5aMXREk5ihfE/amswT9bSnWwAhV0Gb6EMYpb0l6zEGfvDZRZ1u1q6nd17oS17m cpmep4CkDKZYuB7c5fiiw0w3zVPtFT5EXkLQotS7BqHONn8LX4l3dsbJgcNig2ixv5Ga UAEA== 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=0qpVKpdfS2rOt2uWXdNUxmiFJBJ3pg8rxrl91vZoM2E=; b=CbgxuE1vMddTDIT1TvgIN5Uaeoc/ai1FszWQxoogAbC5SS1c8KdiguvTq9bIkSvQ5Y g32VyM03AKUCz3gMlhmsFBGf6nSoo3GdpXzgJe0X2zi7yLgThQjCLbRi4f1+4/9E0kPN X/dKmAo01PclKJYZEP9ye2k5xgqoeRdRJmN8j9Z4cIaGevd5yrAfx4ELfVedeJARg88J 4WWPgixdBRxXu8BrE9scc/j+cIpklDup5U2prEPg1C6+pkCDXtGZfNqeUDP7BfAJ+l31 BqgUd0OO6XTmWPKsprxfSolNHJmKKOBf6Y5kyOIIqoQSaMYgEtgidiQ5xIGrZZxDgCF2 Cvow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MsplvDpk; 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 w23-20020a63c117000000b0050bebc3e35bsi12759792pgf.766.2023.04.11.00.12.31; Tue, 11 Apr 2023 00:12:43 -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=MsplvDpk; 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 S230377AbjDKGtg (ORCPT + 99 others); Tue, 11 Apr 2023 02:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbjDKGtM (ORCPT ); Tue, 11 Apr 2023 02:49:12 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0C043A84 for ; Mon, 10 Apr 2023 23:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195730; x=1712731730; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zGpEfMgloBsWMUOjxE9fyxNifshGPev/lcFUTQ3YvYY=; b=MsplvDpkX8w0xbmmj2l/+M3YZkteBa7x0uGxRC+nGfoPOhjJh1OaACfU qZovhQjwJ0sPHiHgOsUzJtssWeMsw+u1UEL3gdtGlFV5KsRgkRx8xKGpS IDZ/IrEZJVhwUrruRO+iCL4K34AsGzEdlqa894ziViDW7sn5rAmJGrgSL s6if2QVp7sjTYo6NzyC3TlYgu33Qs7iJo8cU3uTNUbU8e0qR4DTMDh+Ro yzg027ety1rZgDxPPiXzf3vEK9d5KSUMhie3rH0u1h8d4ZU+/nffN4WOY BITD4ENEkgiEmowZ4fsgzJOnOorKrfgxZ+KiYnLZnGnFqlRalWgnDe2Tk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028533" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028533" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256564" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256564" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:20 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 05/17] iommu/vt-d: Move PRI handling to IOPF feature path Date: Tue, 11 Apr 2023 14:48:03 +0800 Message-Id: <20230411064815.31456-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 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?1762862997340802548?= X-GMAIL-MSGID: =?utf-8?q?1762862997340802548?= PRI is only used for IOPF. With this move, the PCI/PRI feature could be controlled by the device driver through iommu_dev_enable/disable_feature() interfaces. Reviewed-by: Jacob Pan Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230324120234.313643-6-baolu.lu@linux.intel.com --- drivers/iommu/intel/iommu.c | 53 ++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 6d77b4072fdd..cd3a3c4b5e64 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1415,11 +1415,6 @@ static void iommu_enable_pci_caps(struct device_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;