Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3713537rwo; Mon, 24 Jul 2023 15:46:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlGE+QQjWSiZRC6DVKPAjUJTEPTmiINuiG0OK/8l498RHJiDZw957WRza9XZMVKCDU66EU4o X-Received: by 2002:a17:907:2c41:b0:98a:29ca:c58e with SMTP id hf1-20020a1709072c4100b0098a29cac58emr9891671ejc.27.1690238783788; Mon, 24 Jul 2023 15:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690238783; cv=none; d=google.com; s=arc-20160816; b=B18bXVwDVVF0bQD2L19RPVKFThyJAsz2C6CYpr4wC3q5WnCDWbgAaA9wTew1n9G2GX r7yAdIeW8ca97rtYjgi8nj/jwxWpKJsFxwJy7UdQCGE5Ib+irnJMs9f64fuGK7gEfx/F cgdzyWgaxDh5E/PA+YNTvry3YGA7TCd4uy0XJMQhKS4ygzD55PiK+iZAO3RfBXHY7tbo ywLtXcByVFLTpb4adiP26XEUFMyK6IcGIpqt6AhLUuJeafPm70l4t59HrhmnE+rj1sTe Fe7DGTMNiHT6K4Z+bWK6VI5TMakzlG0zTyZ/zTMkN27vr1xwiI1U0yy5AknHHDoHeoDP Ujsw== 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=Z5s5tAg7GNibbjEifTt3rl5QNHPUR8TiZf/kiZizQfg=; fh=bGo/Q4ro8pFaOByjLYWhYmu9zFeFMbnTLIEA0/9l4hc=; b=Xb/TJQtZFUruyz0Rdxr55mSh5dET6GSokCinjcdXhyroardNwS8zMay290OMl77j9y E6WpP3r8gVw9kqA6VI/5JDkXzPB0145gEZXWpVWJBuy8X3abOTaA1OguqYTR6COi76qu hg0wMTIwyfRUfJBZI6t5marlFgiiKDhYt9XWG77AAPuJay5sDGm+Vb0RMb2CFuYfjum6 cwbOrkfmOdG2CFbJ/Z7WZKPoRB4K2t0eS82vZEBLJjONkTmgjGy7lX6h+JnGOEU5nKz8 7+R6hKViWsYLZ9MyTapC48hikhY2NNcphZNcx9Z/EWJ4PSmFHQ92JcrhaSAy88GXibE1 35dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O6ySXO9B; 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 pj13-20020a170906d78d00b00993860a6d38si7456426ejb.314.2023.07.24.15.45.58; Mon, 24 Jul 2023 15:46:23 -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=O6ySXO9B; 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 S231452AbjGXWUw (ORCPT + 99 others); Mon, 24 Jul 2023 18:20:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbjGXWUn (ORCPT ); Mon, 24 Jul 2023 18:20:43 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A79B10FD for ; Mon, 24 Jul 2023 15:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690237242; x=1721773242; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OatyZryBNY4xB7kd4cbR7STKN6zuyaLdEWJY1lw4WY0=; b=O6ySXO9Bq0pDP5aMruCabQGo1MRDhihkIrdjZ4VERiw8YbvWnVvwbfvK ikkytp/6hwNUlTIJCAJmSU8CFAvWhVaje6K8+9tyXRsbcvZ2gunNpAyeu Ly4ps1rX6vraR5sYUmip+dJ6zFRME7tBjiDHvEC6ilrUR5Xe2t4IqU+Pm 2sIeXKOs8rImDUdVbBd5b6lWXbcdKNj+FT95TgM1ouSb8uQLNRTb6WFoE rN00dL5G02sQdsHqV2ACzw6KxFue41QBSomhlwCwNcadwv1VnkSrWZENI nVyvBH2XGWc/zAlLw/xgShv519WXl8xCArpppdcBCohOUK+mKcLR8AVO4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="398476705" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="398476705" 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:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="899675501" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="899675501" 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:40 -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 3/8] iommu/vt-d: Add domain_flush_pasid_iotlb() Date: Mon, 24 Jul 2023 15:25:33 -0700 Message-Id: <20230724222538.3902553-4-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 VT-d spec requires to use PASID-based-IOTLB invalidation descriptor to invalidate IOTLB and the paging-structure caches for a first-stage page table. Add a generic helper to do this. RID2PASID is used if the domain has been attached to a physical device, otherwise real PASIDs that the domain has been attached to will be used. The 'real' PASID attachment is handled in the subsequent change. Signed-off-by: Lu Baolu Signed-off-by: Jacob Pan Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 89013a2913af..bb8316fec1aa 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1467,6 +1467,18 @@ static void iommu_flush_dev_iotlb(struct dmar_domain *domain, spin_unlock_irqrestore(&domain->lock, flags); } +static void domain_flush_pasid_iotlb(struct intel_iommu *iommu, + struct dmar_domain *domain, u64 addr, + unsigned long npages, bool ih) +{ + u16 did = domain_id_iommu(domain, iommu); + unsigned long flags; + + spin_lock_irqsave(&domain->lock, flags); + qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, npages, ih); + spin_unlock_irqrestore(&domain->lock, flags); +} + static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, struct dmar_domain *domain, unsigned long pfn, unsigned int pages, @@ -1484,7 +1496,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, ih = 1 << 6; if (domain->use_first_level) { - qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, pages, ih); + domain_flush_pasid_iotlb(iommu, domain, addr, pages, ih); } else { unsigned long bitmask = aligned_pages - 1; @@ -1554,7 +1566,7 @@ static void intel_flush_iotlb_all(struct iommu_domain *domain) u16 did = domain_id_iommu(dmar_domain, iommu); if (dmar_domain->use_first_level) - qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, 0, -1, 0); + domain_flush_pasid_iotlb(iommu, dmar_domain, 0, -1, 0); else iommu->flush.flush_iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH); -- 2.25.1