Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1460656rwo; Wed, 2 Aug 2023 14:41:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlG72e293zVECXyxE1P/+nKLi/Jf0YLV1P4tm2YpPF22vhkb+LCTjMPt7UOLrps93DJLlanQ X-Received: by 2002:a05:6512:3a6:b0:4fd:f84f:83c1 with SMTP id v6-20020a05651203a600b004fdf84f83c1mr4778827lfp.64.1691012482139; Wed, 02 Aug 2023 14:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691012482; cv=none; d=google.com; s=arc-20160816; b=ntQ1JKYH+HM1A0h86WMh2hGbatNxfsbIqLLkhIGtYuMdIL32czMe0bNxgqmcqgtAVf ZRoIVvQmgtFrhowVDukybnEEsT7XYpSJpDbQHK9Tlt7Ggk8wNXdvx4BlnoOcPG47EoN9 EisAs84bIZElLNltbQ5rlaiBU7nZJa+n8Cwo5AhokZ7nGhgWUCdc+qvGBl6RpyK6kTbD QHynLrRwQnh2LQ5Y1VrILPQEXXI7sPDcCdOmNDeEa+fVWzutDsDeqvS9rh3HPzV8d4w6 gFp91Ri06hR/dOp0/kTpEoa6EU0ctEJCOqjkwc/a5Bo/W35z8kGrc/ln3GI/keMMwSt4 W4Mw== 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=tugn23N5j1xUPnXTFYpvR3R0rTwdfmAPP2juyaMYan8=; fh=bGo/Q4ro8pFaOByjLYWhYmu9zFeFMbnTLIEA0/9l4hc=; b=hiy37aXtZHVJvC4SUT/XiztMwSxj7ns1QbObWbygCxtdeRA5ItVN+0jKXuoI7OFYnA nDcSZ2uy90hmiUJsZlNoJ1S9rKOFjzH1yAO0YR7+XBj1VD6j+HH8p1eglwmBFjv4Ftdr WgwHOqSiImShHhRetAhcQQnjABpessw46y+x+4+88H+tuNnIv0koRsgWqbO7UR9WIHbW 71gHLJ0CLbX8OsdwJt7Cl9jRG+DOMCp+8+98Kyg8WzF2W8x87w+d4qsyW0cL3qwyTOu7 iPTc4uLMWiGbilMhG7oOyyoU7zg7smgm/vKo9RdW2SqOjlkL9PdAC4Y7/A1R0hNf2/Fy DUOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MV7GYAbY; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a056402020800b005223ebc9b97si1404812edv.131.2023.08.02.14.40.51; Wed, 02 Aug 2023 14:41:22 -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=MV7GYAbY; 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 S232802AbjHBVTo (ORCPT + 99 others); Wed, 2 Aug 2023 17:19:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232403AbjHBVT0 (ORCPT ); Wed, 2 Aug 2023 17:19:26 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 867B0273C for ; Wed, 2 Aug 2023 14:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691011165; x=1722547165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QTcWjAJeCsBne8ZdeKn434F2uIWuBkEgxK9GMvAl9eo=; b=MV7GYAbY5bGXxM7FZ2bOVQ1I8wBJKnYCHm0R9k+xuSmbEb7IeyIyKNvr 5tosKMpmhz/fRN77O0FwQtnZ97q8r7eau6ax6VlINopgOb8J6R4yjdHZT r1tUhy6KH2Norxl+QZr3QDKcOdHZfcmpJrBJ1cWm3MjR29sMN8T+FS1qk nHyNsUPuT00n6O9/7oYNeSZYDBtDTKWLf8zu9uYzEXSj6VFfPWXvvA9dj Uzb3IP5lEcH4a0neCh1RIRZuMnID4UdazPuBaAqmgjZ32VNQ/Vw1x0mlC UosCaAyNjaJUB+Ok1QC6+XMUgUvwj+RmLd/LrPW4Yu5WiAIBkieYEJ0st g==; X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="372436170" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="372436170" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2023 14:19:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="729290796" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="729290796" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by orsmga002.jf.intel.com with ESMTP; 02 Aug 2023 14:19:22 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, "Lu Baolu" , Joerg Roedel , Jean-Philippe Brucker , "Robin Murphy" Cc: Jason Gunthorpe , "Will Deacon" , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Tony Luck , Jacob Pan Subject: [PATCH v12 6/8] iommu/vt-d: Prepare for set_dev_pasid callback Date: Wed, 2 Aug 2023 14:24:25 -0700 Message-Id: <20230802212427.1497170-7-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230802212427.1497170-1-jacob.jun.pan@linux.intel.com> References: <20230802212427.1497170-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,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 From: Lu Baolu The domain_flush_pasid_iotlb() helper function is used to flush the IOTLB entries for a given PASID. Previously, this function assumed that RID2PASID was only used for the first-level DMA translation. However, with the introduction of the set_dev_pasid callback, this assumption is no longer valid. Add a check before using the RID2PASID for PASID invalidation. This check ensures that the domain has been attached to a physical device before using RID2PASID. Signed-off-by: Lu Baolu Signed-off-by: Jacob Pan Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index bdde38a5e43a..4a41aca6a2ba 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1475,7 +1475,8 @@ static void domain_flush_pasid_iotlb(struct intel_iommu *iommu, unsigned long flags; spin_lock_irqsave(&domain->lock, flags); - qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, npages, ih); + if (!list_empty(&domain->devices)) + qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, npages, ih); spin_unlock_irqrestore(&domain->lock, flags); } -- 2.25.1