Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1460786rwo; Wed, 2 Aug 2023 14:41:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlGs1+cShF4azXvGs17tgKjag8jx5IFa2RqnQd07s36G+uN1yZFALZ35ZqoFfKhwN7VFM9ZS X-Received: by 2002:a17:907:78c5:b0:99b:ee8b:5707 with SMTP id kv5-20020a17090778c500b0099bee8b5707mr5538643ejc.74.1691012490328; Wed, 02 Aug 2023 14:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691012490; cv=none; d=google.com; s=arc-20160816; b=pupro5TwxdhjwlmpTYxRGCUOkZTgOJg8QlIb9O6fnm+dRFwNztVQliLo7Y3exnc/vI zHEE5ifUzv+PyIaNy0GhhPthutNOklS5MayfbZYVqY/bDGpedwaSRrl3DSDv+UQ7VT2p qn4jnteSXmllM6pvTibXucjdd9RmY5+mzHXPwxUeKN1GmxX58KMTOiYahb8xorOLQ9+R OXnGtDTrsD1GuZoDrpXMF8uYV6iANKNCWRNvYF429tL/f5wRtYFQzAE7I1tGBCHvC5ED Wq35CqP/xS2OjI3hiSCfftheKK7HMnchIyFj4jy0EZ5ZHNAgf5Vg1OTPJ4r7i1Fr04Hn 39wg== 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=sZeApCJ25qOPeg2WBcRHTJ99j/5hR6VhJRAj6AC7yjZd9hz91qvKQhYabk9rrswbK+ eyvTJyZL8j2eBzn9Ci9zRGvkdEWyR8voxLrA81steUDTnUeZ8GjCk482Ra8IOb9uvd7Q cRCQI2pKsiTSky4ggLcdl/Z+jyJOLHcTiUwenMON9+uJ30UXOvZOI5Fc3D+jNRrw4uhe tVzNqCOlnZNK0Enz0KT5g2mOpP6OmKgfa2hFYNS9ejQEe93VAPEsTCAht+CaPhwjAJpl Cjhlg8Epwa6CA7ERaG68tkMRC0z9nOuHksVJ/VYbNCI15N4G5lutATNbQS9cJNMKIvpn OBmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V5VQ6x9j; 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 me24-20020a170906aed800b0099bd03b30cbsi10045234ejb.627.2023.08.02.14.40.36; Wed, 02 Aug 2023 14:41:30 -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=V5VQ6x9j; 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 S232707AbjHBVTi (ORCPT + 99 others); Wed, 2 Aug 2023 17:19:38 -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 S232375AbjHBVTZ (ORCPT ); Wed, 2 Aug 2023 17:19:25 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910F02D40 for ; Wed, 2 Aug 2023 14:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691011164; x=1722547164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OatyZryBNY4xB7kd4cbR7STKN6zuyaLdEWJY1lw4WY0=; b=V5VQ6x9jnhx+9trW1m3x8TdTfN5RR+gVBgKRdn++nkRvQbl2o80SMlRS 2aJGKn1jlusiF7i53Nfn0ia52SfvpUgtmid2tY7Wh3295t9TWl9cX2PaB lLMmbD8HX/rThr1IoVoM3FtQ87otUUU1AbQWpM2ZC3VDpEVvqXBtP3pm4 t3Y5MTIgp3kW/zYRYZkgksK4jahnNbEkOCMRnq7uzhYGGisUOvfzzifyD JgFDQK0RVkzYzqzvh5UB7FqQ1iGHVxBH5ytFHmYHsPj0IAaUAAv2wgpfN nHN/sgcpxnNc1vW3L7TZY76xfiteZ+1ruNf3BcjvG/CX9vzeeMOOfH54t A==; X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="372436147" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="372436147" 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="729290784" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="729290784" 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:21 -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 3/8] iommu/vt-d: Add domain_flush_pasid_iotlb() Date: Wed, 2 Aug 2023 14:24:22 -0700 Message-Id: <20230802212427.1497170-4-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 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