Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2587024rwd; Fri, 2 Jun 2023 11:28:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bcv76dHg4+oXSbQkocHUEmV1uVreBiAXAWGD6uOgfaWZWjH/3gwEB4ebbPIluWp9NF2V3 X-Received: by 2002:a17:90a:aa04:b0:256:5b86:4f8c with SMTP id k4-20020a17090aaa0400b002565b864f8cmr570947pjq.43.1685730479782; Fri, 02 Jun 2023 11:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685730479; cv=none; d=google.com; s=arc-20160816; b=DqxQqB6XVlckqSk04Cwg3gVTf2+s+ZeAQoa3r7DpXQHfWIYGigkl7zPGFxGXRHK3HU ZLgNNv+tMz4QD8vm2oYCI6PaCGFnsVmW7IXsnhxp2fb96YGBTMXJO2mWvsteKrfLretM jEz/7ftzW6/1JURKS0jJ/SIb5Vsa/1+YieCZPzXSs+zBgvu2JpZxPE8QNaW5tLydn2xK R47hMOIbkLrV5CA3tZrjbEeFKu5SMI7KfvoXOHxIHprmpipjtpkrwWVuOYIbh9iz3KwV DzerOgtAfHlbTRsWbpGWHGW61a5iZjFhN0gAYG5T63/rAyiC0au1dcrUifayolaXduJ7 0dQg== 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=jASir5Qubpv/Yp/d/93aEWmRDyfqsd60EZ8GHvV+bak=; b=ScGNst6KJu0kMrwctw5QAawe5eFZDqdMJ0WJ+OTtpbIt8R2zu27OUwqT2OgTwixn6C tjIIzGGRz8qk0miHuZwwbXRGdfQ01G3Rpqe0czzITeTzAzZpJyOoX4WFbz10lhaOhkTE +cABGY6m0fl2qYEF/I3u6myqR+UEfhQl7AG02p/myi+xSMVQsrbRZCNdOGRKbDriqian pU3gW+jmIABUV+4RtQN/s+KsUW3oIjBFLQLpnVUOYutUeeWX/wGP52I2WajX0tysLUH5 47KgJdQswOWfE1REiL6G1XG+pO3DL6q5Qy8/jqVUO/dhAu4IcUH6TwglfM8qPEHsewgG CGOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ewvxt5VB; 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 p5-20020a17090a4f0500b002565045f145si3117855pjh.122.2023.06.02.11.27.45; Fri, 02 Jun 2023 11:27:59 -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=ewvxt5VB; 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 S236978AbjFBSRy (ORCPT + 99 others); Fri, 2 Jun 2023 14:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236869AbjFBSRo (ORCPT ); Fri, 2 Jun 2023 14:17:44 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4955123; Fri, 2 Jun 2023 11:17: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=1685729862; x=1717265862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4p3zIDhXUsEFoA0tsNg8+G8DCi8YsUnHZ4JrFrt/SXY=; b=ewvxt5VBrpIzcm4zCFYiMBj75RhX/OO/w11Tm/R0ZpzkzuiyuGoKkqVc YEQJIGkIYPI6TapJ5/3rVPvD7C/OPami4TIR+L1tVaBUyOtl/kmiSkMt6 L8I9D8yTJq5fStUSa1nh3gtfPfkLTXrsanF+mLau4nrBJ+f1sFp08BnZ/ IwrglVoJV51Ibuh5qdEY9Pr8DgjoWgmI2+M5opuzew1Qy4RAy1wPzUNx6 F94AwSuScxRs/m8QDQom3KvZ2ClH6iSJpvch9b5loE2cAuCejjLzGvARj ZMg6+V2c/ZJRds/JRJcnbOotlnxgT8084H+O8GdUODOSzKrRK/IYVyKUx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="442310232" X-IronPort-AV: E=Sophos;i="6.00,213,1681196400"; d="scan'208";a="442310232" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 11:17:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="832060965" X-IronPort-AV: E=Sophos;i="6.00,213,1681196400"; d="scan'208";a="832060965" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by orsmga004.jf.intel.com with ESMTP; 02 Jun 2023 11:17:38 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, Jason Gunthorpe , "Lu Baolu" , Joerg Roedel , "Robin Murphy" , Jean-Philippe Brucker , dmaengine@vger.kernel.org, vkoul@kernel.org Cc: "Will Deacon" , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , rex.zhang@intel.com, xiaochen.shen@intel.com, narayan.ranganathan@intel.com, Jacob Pan Subject: [PATCH v8 3/7] iommu/vt-d: Add domain_flush_pasid_iotlb() Date: Fri, 2 Jun 2023 11:22:08 -0700 Message-Id: <20230602182212.150825-4-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230602182212.150825-1-jacob.jun.pan@linux.intel.com> References: <20230602182212.150825-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 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. Signed-off-by: Lu Baolu Signed-off-by: Jacob Pan --- drivers/iommu/intel/iommu.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 4eba9973f537..3214990b69b7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1475,6 +1475,24 @@ static void iommu_flush_dev_iotlb(struct dmar_domain *domain, spin_unlock_irqrestore(&domain->lock, flags); } +/* + * The VT-d spec requires to use PASID-based-IOTLB Invalidation to + * invalidate IOTLB and the paging-structure-caches for a first-stage + * page table. + */ +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); + if (!list_empty(&domain->devices)) + 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, @@ -1492,7 +1510,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; @@ -1562,7 +1580,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