Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp281719rdh; Thu, 26 Oct 2023 01:54:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbeMtJNA1Nll4/4GIBLNWOUPGYopBdiVd59SkqITSSBSf7CcRrXlLuU1W0TcRtyBK+vwyd X-Received: by 2002:a05:690c:709:b0:5ae:15bb:466a with SMTP id bs9-20020a05690c070900b005ae15bb466amr3464436ywb.14.1698310457785; Thu, 26 Oct 2023 01:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698310457; cv=none; d=google.com; s=arc-20160816; b=QJ3z0DAX9LVEMMvMKKZkD+xEtQowUiY0FSTlCW5z1dSWcR7nHKcBOSSjs5LCiD3TA6 c3/zF6B8/WZ/CQPvMZiQnByxakqG+5CGb2Z5zcQkRZXi11pO4KADO0N2Wv05bTdNGv2w eV9GEmD/OiUW4BLXWM5BwKqidgt+Q7DfaR1R3jYWDMEtu/ooicK9m5qwQIkQWc3/84+N xyKfsnpwGN3E25rrxJsckhrlwFBo4SBe5XXF5DxCLHySxkaPlphYpUGp9ar3vGsHc4qn kbs6Tq8RGQ8BXVfMzzAy+4RGMQ+CklupOni3PAy0+3mwXgn9vU8KCrKFqAtkOX+avLP7 WVOw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=hbGjDOm9YYrpK2mEcitCcJBUSp5b/kIoTYTqJIjVp1c=; fh=Tlu/8+h9mgmKVptbDXa61RIqygMdrvIuCgFgX7Qgbl8=; b=xh1boQYqufrl8aatM1fgHU/0JnKU4gaxBVcewSpAQxagEnJOpqDcS29RXsiBPv3Q1O yYACXvAw4U07qIDZHyFW1NqJ6j0ftsjKShIMTtRlQ3OAaoWTEBllRsOvnE8iFN22NdRx Piy29FqMjVOP0bnz02wDH6Fa/Z41rmrev+k03iPC3lI3txDJOpmTWhSeUzg+ekJ55Vwq 5JvXMvdBXb+mb0JRG0CprdTSbTCa1bOM9Q4ESBoTHP2+qK+SIdGXhE9O36WAcv6lhtsd XK8sGHrqMdgcH438ZtIZnrMm3jefCmKnJq9xwceV7qs1onH5nYeY72gnwNgCGtyclCBG o9tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SKf8lRq2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z82-20020a814c55000000b005a88b1c3dcasi1499738ywa.368.2023.10.26.01.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 01:54:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SKf8lRq2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C84F4820E537; Thu, 26 Oct 2023 01:54:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234917AbjJZIyI (ORCPT + 99 others); Thu, 26 Oct 2023 04:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344743AbjJZIxh (ORCPT ); Thu, 26 Oct 2023 04:53:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21C191B9 for ; Thu, 26 Oct 2023 01:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698310415; x=1729846415; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=SGBMlTmr6toh8djYlkspv5ApDTa9BRAdKaaxwXIo8zw=; b=SKf8lRq2c+q3PQ8l7PQqWnP71ipUV/m695uvAS1XADhI04uR6LsXJELL wGKr6NprCmiXwFn1fZ8tHDL2CVuYrhjAIUySiOdLEFT5ypctsRFM3OKD2 tHVClW7LacFCDqsI3KWV6q5egsn6TbQg0Lj+JxMTkTvcvLP3fKLVj0cA+ 3BtYrAyL7n/eYF6THSdnSaL2wWQGHYFAGBTb32S2+XbQ3SfUUyRcEqJoz 4zAb4O2vFfjTj/sVhc+Cie/jk4itjqX/2FifeAJHN6OK/w4QUeD8p/6/n MQGFBYgQGd3KnJg7BtH+7Wkr0t2TOoNr3VKGPnW2u851/l6gLkWMEtGz7 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="391361929" X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="391361929" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2023 01:53:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="708996342" X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="708996342" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga003.jf.intel.com with ESMTP; 26 Oct 2023 01:53:32 -0700 From: Lu Baolu To: Joerg Roedel Cc: Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 1/1] iommu: Avoid unnecessary cache invalidations Date: Thu, 26 Oct 2023 16:49:42 +0800 Message-Id: <20231026084942.17387-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 01:54:14 -0700 (PDT) The iommu_create_device_direct_mappings() only needs to flush the caches when the mappings are changed in the affected domain. This is not true for non-DMA domains, or for devices attached to the domain that have no reserved regions. To avoid unnecessary cache invalidations, add a check before iommu_flush_iotlb_all(). Fixes: a48ce36e2786 ("iommu: Prevent RESV_DIRECT devices from blocking domains") Signed-off-by: Lu Baolu --- drivers/iommu/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 00d0a2b5d7dc..0cb676590bfa 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1114,7 +1114,8 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain, } - iommu_flush_iotlb_all(domain); + if (!list_empty(&mappings) && iommu_is_dma_domain(domain)) + iommu_flush_iotlb_all(domain); out: iommu_put_resv_regions(dev, &mappings); -- 2.34.1