Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp873698lqe; Sun, 7 Apr 2024 07:43:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV46AxU9W8hbZVl2IqHmSeBLdZoI1HnDyZCaeJ4CFyi3yUNMEC3Gb/pnJKZEM373Y2c7hwHRjhy+PezhzOn7epWrApaXsFohHAxFutCpg== X-Google-Smtp-Source: AGHT+IG8GOpv8DFTALJSj3Yfw/5pmc9RFZhYqyn9X9ySi5kYHH6/JaXQQAw4/aDGh2D4+BRb4ZbU X-Received: by 2002:a50:8ad2:0:b0:56e:c16:fbf2 with SMTP id k18-20020a508ad2000000b0056e0c16fbf2mr4778732edk.23.1712501031550; Sun, 07 Apr 2024 07:43:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712501031; cv=pass; d=google.com; s=arc-20160816; b=hABUbPGEB1tMZgHZ5Out2E5BifiE2cBoGZRkjK2J6RDvq5Xbswm3XtMrv3PmZUMDFU TmjTVbZ6WHpY2Sw/KBEUR6RGXcSBGCkoWYHLxD1rVcM8K7Lc6kT/ouQRRVjXzDhRA20B 6IM+n25BcHwtMeRJPmKmKYuRWYick4Blo1w03IZQAOVacMWRgAfIGphXgDkn20fB1az7 5BWKFg1eFMLGbvCv2blVhkGCqT5bC7wEHZ8khaUTtu0oH/58NV1+683XY0lMF7wQvwMQ jJU5nHUmMicSJrAC2bt29ghVj4SLDNKnp46iv/NYvJgkTisdpAlcxIgHQMNI+NC0FFSr MAUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=8F8D6nX/knbdzZrD8N0geUThQHRWKBY4qvVovmw6D2U=; fh=mBnuy+TuxYd2sqzXdSewSjXhKXAxaVbJeFsFZqVLbQo=; b=uKkOf9p3P8g7bay2aFPJMwStmDdB9xqmLFcvVaTD5tpeUAGEMf8YHBj6EIR9Rs0VZJ 17zBsqtZyWmThw/dt1UO/mkKx6gFOOLrQeT8a50eZbhGlS/n8T0m8KK6s9rJKquDEV2O 41ldmk9gZyEGXPH7bUED9L6ewQR4FWZWVBGJbZ18WWfOIxw8zd+He/AIWvudDWq/Mx96 tujvqZLn7EMr2Lrid9YmSzDbXDHDhQ7FsEB6UWYBXcqpweZ3Bqez8cNYAsqO4CMboeJy FYHxdoHiqsZ4owK/M30NuTFxZkbcY1jFtOfo4r/BHzIljmaLvei7n1wrf/3rGsbBl5jY fRoQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m1wJ8IVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-134526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134526-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m22-20020a50d7d6000000b0056e03ca8417si2738777edj.258.2024.04.07.07.43.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 07:43:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m1wJ8IVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-134526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134526-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 403411F21B08 for ; Sun, 7 Apr 2024 14:43:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9447B39AF2; Sun, 7 Apr 2024 14:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="m1wJ8IVA" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 C32B3381BA for ; Sun, 7 Apr 2024 14:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712501024; cv=none; b=X5sv29i/ZgDvGixAK0XI8G9gWvY5T7Mec65/EKnQDjJA5QQ6/olOI5wIpjzGeHh5kiPPPTGXkkc4zIAj7KxyHTbUFuAifTL77lrsMiF1so71hYLPNCT9F6RUFtcVtiU94qwVZc2lkwzCx0UvwvD/Qu/GFEluWFVrWQRghtGvxTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712501024; c=relaxed/simple; bh=0mfpprZXYGxKzZyNx4TVkJXtwvzmtLRy2Ftcxt1I2yY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=N34qS2aCFtIXqvBVqtrt1Ah/VPTRK4R+8nwZD4MkfgmScZBM9n9v5pSLQh4oy1phFLuwvrPWWq+yfxdUPnS6ga47bic1w5l404yzgBYPAoBoRBtciYpBM7cTmXnT37SgSVlfegKUspdX5eY/LWRMBqDHQbRIABgC0xLOFhMDZL4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=m1wJ8IVA; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712501022; x=1744037022; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=0mfpprZXYGxKzZyNx4TVkJXtwvzmtLRy2Ftcxt1I2yY=; b=m1wJ8IVAiA5zHCHzJg35ZF/ONcoGULD+KTVseOgGCJSqNl1JM1D81aF1 faeGBzc90oG/Z0iLW1MTfKtIEobRUpaJrEgqMwg1PoU8NEHEBuWVuFEOb 0afkYuv1Gd8EpSXPc3bz7jtZT+JuCzPSklnzqF8eFxb9QAQmOhR8CV3gi j1LsQjnZ9CTKQhK5deh0EbWCl5DYPAg8prsv8ayIaPbXhiKyL+dM8EQ7P OFalxfAjUbHYynbNT9/ZynGHl6zl12pFtCPOzbaDU5glwDF7bBHnyw+Cy pxc0mwOwNTvsSs2pfkt+yl2nNIEZ7jJ5hSOLrpxmq4ZMhBm5WAfi5USoy Q==; X-CSE-ConnectionGUID: wcyKNzpuR1uX1/9VQ9Y0AQ== X-CSE-MsgGUID: 8tAWA/4fRnWlGI/4h36MYA== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="11607278" X-IronPort-AV: E=Sophos;i="6.07,185,1708416000"; d="scan'208";a="11607278" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2024 07:43:42 -0700 X-CSE-ConnectionGUID: rXfPtQCcRI6idTnFo9xCqA== X-CSE-MsgGUID: wsx/XXD/STqif26NWWu56A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,185,1708416000"; d="scan'208";a="57102676" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa001.jf.intel.com with ESMTP; 07 Apr 2024 07:43:39 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Kevin Tian , Yi Liu , Joerg Roedel , Will Deacon , Robin Murphy , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 1/2] iommu/vt-d: Avoid unnecessary device TLB flush in map path Date: Sun, 7 Apr 2024 22:42:31 +0800 Message-Id: <20240407144232.190355-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit iommu_flush_iotlb_psi() is called in map and unmap paths. The caching mode check before device TLB invalidation will cause device TLB invalidation always issued if IOMMU is not running in the caching mode. This is inefficient and causes performance overhead. Make device TLB invalidation behavior consistent between batched mode unmapping and strict mode unmapping. Device TLB invalidation should only be requested in the unmap path if the IOMMU is not in caching mode. Fixes: bf92df30df90 ("intel-iommu: Only avoid flushing device IOTLB for domain ID 0 in caching mode") Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 50eb9aed47cc..493b6a600394 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1501,11 +1501,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, else __iommu_flush_iotlb_psi(iommu, did, pfn, pages, ih); - /* - * In caching mode, changes of pages from non-present to present require - * flush. However, device IOTLB doesn't need to be flushed in this case. - */ - if (!cap_caching_mode(iommu->cap) || !map) + if (!cap_caching_mode(iommu->cap) && !map) iommu_flush_dev_iotlb(domain, addr, mask); } -- 2.34.1