Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5950B64A for ; Thu, 9 Feb 2023 17:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675964997; x=1707500997; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=GwZqwD+2jAddPIK4L4H7lS4Vi9Kqr7gLONerEQg6hm8=; b=dSmN1hozhRVShUAYG2dSMAYhA40FbjkBor6BmYLnav0ONpbmIcno2OR6 edqBuHovEeDtLpWAoUwfFg65SPy2oF3cgHuq6u6UOt25NyrGDR/CmsqU7 AZnlyOnKtr+cvybb3lQfxEIEgk8VhO9Z8YDo5eyb4BsyTZ82XXeOZC3tO xaGhT+fNTdWN0ShCilqPFGh+2XKro7jAGyaAOoFSN2+GLuVce/BJmp+Aw iWamT5JTSMEF0cGis4rDs8W6ZDbVihY5C5Z4JmMXs1DICV8XRQCyYIaFC NNXDxsgQnJQKh7WUl4E8TkUrfKL5CPXTtQL2c/8edNXybmrDrXhEm47PC A==; X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="416412325" X-IronPort-AV: E=Sophos;i="5.97,284,1669104000"; d="scan'208";a="416412325" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2023 09:49:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="810466350" X-IronPort-AV: E=Sophos;i="5.97,284,1669104000"; d="scan'208";a="810466350" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.39.106]) by fmsmga001.fm.intel.com with ESMTP; 09 Feb 2023 09:49:54 -0800 From: Jacob Pan To: LKML , iommu@lists.linux.dev, "Lu Baolu" , Joerg Roedel Cc: "Robin Murphy" , "Will Deacon" , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , Jacob Pan , stable@vger.kernel.org, Sanjay Kumar Subject: [PATCH v3] iommu/vt-d: Avoid superfluous IOTLB tracking in lazy mode Date: Thu, 9 Feb 2023 09:53:30 -0800 Message-Id: <20230209175330.1783556-1-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Intel IOMMU driver implements IOTLB flush queue with domain selective or PASID selective invalidations. In this case there's no need to track IOVA page range and sync IOTLBs, which may cause significant performance hit. This patch adds a check to avoid IOVA gather page and IOTLB sync for the lazy path. The performance difference on Sapphire Rapids 100Gb NIC is improved by the following (as measured by iperf send): w/o this fix~48 Gbits/s. with this fix ~54 Gbits/s Cc: Fixes: 2a2b8eaa5b25 ("iommu: Handle freelists when using deferred flushing in iommu drivers") Reviewed-by: Robin Murphy Reviewed-by: Kevin Tian Tested-by: Sanjay Kumar Signed-off-by: Sanjay Kumar Signed-off-by: Jacob Pan --- v3: reword comments, add reviewed by tag. (Kevin) v2: use helper function iommu_iotlb_gather_queued() instead of open coding --- drivers/iommu/intel/iommu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 59df7e42fd53..2ee270e4d484 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4346,7 +4346,12 @@ static size_t intel_iommu_unmap(struct iommu_domain *domain, if (dmar_domain->max_addr == iova + size) dmar_domain->max_addr = iova; - iommu_iotlb_gather_add_page(domain, gather, iova, size); + /* + * We do not use page-selective IOTLB invalidation in flush queue, + * so there is no need to track page and sync iotlb. + */ + if (!iommu_iotlb_gather_queued(gather)) + iommu_iotlb_gather_add_page(domain, gather, iova, size); return size; } -- 2.25.1