Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3752807rwo; Mon, 24 Jul 2023 16:31:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlG4OwWcyz1uo4HWRC9j6pkukuRSdoN6OWkFY5TxlE1+H1rwL1XrWR46wFrIMn0ykbyZxNMj X-Received: by 2002:a05:6e02:c63:b0:348:c041:abd7 with SMTP id f3-20020a056e020c6300b00348c041abd7mr1306684ilj.13.1690241499081; Mon, 24 Jul 2023 16:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690241499; cv=none; d=google.com; s=arc-20160816; b=wok727F2ynb/F5biL9vF9TvQOunZ6flayn8VoUP/3fG7oBcWmnbhJpyptqPpTRXzqv YI3Zn+hSnAqcLC5NriwYTkja69iB3U3sJPfwy1y3vJAODRRQUKh1lJ9VqpVkiF13LfJi nc2a3W72+TUyCAyL/DpUMGc78zwTeEcwn4HgKGc2pEsUHmVETAh0dz9kbEHSY/v0SCDT npRTjKIzlzzDHluUEig5xK/YhlmjM3EbYT2Dd4afv7bK3EA/AQhmfiouHdhqGNHRre82 Cl790Th+SDl6sN7rsWhplrjBYj1ikhYs8tLa5cKhBYP/BGKA6P0AGlaq8ATIugCrwLFf hkfw== 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=5939neY9BRIT3NUsPdUQg9mrjFVFZjfinH4ixqP2AhY=; fh=bGo/Q4ro8pFaOByjLYWhYmu9zFeFMbnTLIEA0/9l4hc=; b=eSG6j+PTmi0zDT8fyHkhl3W4RX0x7m/qtHA9/hvHAW5so1l4iHicHmvUqrEPz4xWST UzD/ax6XmzrByQMHesWsqlSO/f96qerqgjrcdeSRbAfUNRru383sg/wje7pkMX8W04iJ xMKk6EoJ4QmBtH15ZABNPB/p2xIHg3i062VJ8h2KlHH/I+fEGeu6Uv+fXBiLLpXH8aPW xmWF6wXYO5SI8NYj+NYms1QVW+JuKP4gRb80AYkQ6KwZOpVWkHQHbENbDHyK+yCHgYQs Z7qnZKDnj+YpEq0Ijkh89kHhaNEFqUZSU8LzQMeUO90nbJI0Fl4vNNHqUu9fB/FmeeGN k1EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QwEmCVRC; 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 t13-20020a63954d000000b0055b2c94e7b1si9729291pgn.190.2023.07.24.16.31.24; Mon, 24 Jul 2023 16:31:39 -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=QwEmCVRC; 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 S231391AbjGXWVA (ORCPT + 99 others); Mon, 24 Jul 2023 18:21:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231416AbjGXWUp (ORCPT ); Mon, 24 Jul 2023 18:20:45 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50E9A172D for ; Mon, 24 Jul 2023 15:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690237243; x=1721773243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T7pEMVnY38ePZ+dddDqL9MVthVOhVNl5Cd66gkfRILA=; b=QwEmCVRCoT7cpqEFZNgeFR8gzCMcqupNgYSH019rosh12IOIImGsYZE5 6S3osSpkqUDygmZfJaCJnjAOp2KRuA6u6zJvPE4vrsJacpOBBUr7mNH6T XgNEErnAX5ZO3GDsHRIs2/wdGzOBrFzSTsUABWd8mn/ke8GL3uSQgud6K 7x+e936HEI9H6GpCcgdhxhNxIWTLWROu1QihDGxyDi1sALsZ+U7hfZUds fTlIO/VNkK+/x0JeT3FS1ZHsFYs20thhgoMkB45q+31FI6Ue9Ilfj1vU5 B3RUskHWwqLlM+moYhveYMUtWTZMnLg81VymPDIPD8ThXnXoKaR3b1ppr A==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="398476725" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="398476725" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 15:20:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="899675512" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="899675512" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by orsmga005.jf.intel.com with ESMTP; 24 Jul 2023 15:20:41 -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 v11 6/8] iommu/vt-d: Prepare for set_dev_pasid callback Date: Mon, 24 Jul 2023 15:25:36 -0700 Message-Id: <20230724222538.3902553-7-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724222538.3902553-1-jacob.jun.pan@linux.intel.com> References: <20230724222538.3902553-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 --- 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