Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp576852ybt; Mon, 6 Jul 2020 17:07:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8NheKm4wsJ2LI8O0Xac+mhtN/UfN8jSuqUock2/1t6VjxcM0/pcfcDPDWoiK6IWAQ326P X-Received: by 2002:a17:906:915:: with SMTP id i21mr46598499ejd.313.1594080426480; Mon, 06 Jul 2020 17:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594080426; cv=none; d=google.com; s=arc-20160816; b=ANpGg0ldaBcrPoNOGpak8y5UHN4X6pVk5MLYEBiyxjN4FEJqxOLGctGjwIPI6vAj5X T8qOVXBYL0yyR55PdIQPG4dKRsRiLC3ki5L0rsAyuETnUy9mnTzG4/+9NMaa8hd98Xfz 4uZsUqaVCEgeAePaicjAwcir1QNJUGxhI3JSSc+SesLD9y+WG3HHivmBm1zxDrdECC3t 9PCfRClc1tbSfzi1zOp1SLJOtLfx6QtL+kjyD5LaKBqECl7eKehiSAnnCHZkwmapglnO kMEBa8jrURvANXEA6Ri8qYaR0Q/xLpH451dSVT8eLvGQ/yQZ/VGXC4Tar78fcVjjkyyg c3WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=xLcKCmefqSVwMz+Mu2CSVvXH49JekS/DU2iP3EA5tM4=; b=b050cBwSJXSFe0jYZh/Jw88mVddyQp4YvrGnoIufccN5MVbv3YxU6Ff/KK2Xf/vtO8 GgCHkg66xLgtyLxM6s/qweD7qsTMK0GoeNSn2P045Av/NnjjL4tyz7xgE8yYM4zNTa5Y qiz/vOEtqz4xizM/XcddOD1yBzc7UNB6lgMv4doFV5Ynu/thNhdqgvNW5IqQhr20Fk3C XLSRFyIFCSWADBSTgGB/1J88pLrglzCOofMRbaqNMZF3RNThIlEjLt49k1lpBQdZzA9+ HXl2HUVsK+GrvXSLD6EfSp8CuD7YOpK5Xvy5yXn9oEtSSd4vfG2ettEBcqCqIdoX2mYp 1GGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si15276227edv.174.2020.07.06.17.06.43; Mon, 06 Jul 2020 17:07:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727891AbgGGAGZ (ORCPT + 99 others); Mon, 6 Jul 2020 20:06:25 -0400 Received: from mga07.intel.com ([134.134.136.100]:18975 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727834AbgGGAGV (ORCPT ); Mon, 6 Jul 2020 20:06:21 -0400 IronPort-SDR: kqeO1Uf0DMO5TOIXh8YIKjCG398g6pereSuujFFWB5gAbPsDe0uP1VQU7FDFFN1WnxxdjjZJxO YdjPTE6o4oFg== X-IronPort-AV: E=McAfee;i="6000,8403,9674"; a="212492296" X-IronPort-AV: E=Sophos;i="5.75,321,1589266800"; d="scan'208";a="212492296" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2020 17:06:17 -0700 IronPort-SDR: byETdNW/224UmBOYzS3zHbETVpwz5e+HdlvUr99SU6x/40NTLeOCmHEdswnUeckyBzyAkl0eVr BZpFzyZP08PA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,321,1589266800"; d="scan'208";a="456913828" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga005.jf.intel.com with ESMTP; 06 Jul 2020 17:06:17 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , "Lu Baolu" , Joerg Roedel , David Woodhouse Cc: Yi Liu , "Tian, Kevin" , Raj Ashok , Eric Auger , Jacob Pan Subject: [PATCH v4 5/7] iommu/vt-d: Fix devTLB flush for vSVA Date: Mon, 6 Jul 2020 17:12:52 -0700 Message-Id: <1594080774-33413-6-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594080774-33413-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1594080774-33413-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liu Yi L For guest SVA usage, in order to optimize for less VMEXIT, guest request of IOTLB flush also includes device TLB. On the host side, IOMMU driver performs IOTLB and implicit devTLB invalidation. When PASID-selective granularity is requested by the guest we need to derive the equivalent address range for devTLB instead of using the address information in the UAPI data. The reason for that is, unlike IOTLB flush, devTLB flush does not support PASID-selective granularity. This is to say, we need to set the following in the PASID based devTLB invalidation descriptor: - entire 64 bit range in address ~(0x1 << 63) - S bit = 1 (VT-d CH 6.5.2.6). Without this fix, device TLB flush range is not set properly for PASID selective granularity. This patch also merged devTLB flush code for both implicit and explicit cases. Fixes: 6ee1b77ba3ac ("iommu/vt-d: Add svm/sva invalidate function") Acked-by: Lu Baolu Reviewed-by: Eric Auger Signed-off-by: Liu Yi L Signed-off-by: Jacob Pan --- drivers/iommu/intel/iommu.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 96340da57075..3bf03c6cd15f 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -5408,7 +5408,7 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, sid = PCI_DEVID(bus, devfn); /* Size is only valid in address selective invalidation */ - if (inv_info->granularity != IOMMU_INV_GRANU_PASID) + if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) size = to_vtd_size(inv_info->addr_info.granule_size, inv_info->addr_info.nb_granules); @@ -5417,6 +5417,7 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, IOMMU_CACHE_INV_TYPE_NR) { int granu = 0; u64 pasid = 0; + u64 addr = 0; granu = to_vtd_granularity(cache_type, inv_info->granularity); if (granu == -EINVAL) { @@ -5456,24 +5457,33 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, (granu == QI_GRAN_NONG_PASID) ? -1 : 1 << size, inv_info->addr_info.flags & IOMMU_INV_ADDR_FLAGS_LEAF); + if (!info->ats_enabled) + break; /* * Always flush device IOTLB if ATS is enabled. vIOMMU * in the guest may assume IOTLB flush is inclusive, * which is more efficient. */ - if (info->ats_enabled) - qi_flush_dev_iotlb_pasid(iommu, sid, - info->pfsid, pasid, - info->ats_qdep, - inv_info->addr_info.addr, - size); - break; + fallthrough; case IOMMU_CACHE_INV_TYPE_DEV_IOTLB: + /* + * PASID based device TLB invalidation does not support + * IOMMU_INV_GRANU_PASID granularity but only supports + * IOMMU_INV_GRANU_ADDR. + * The equivalent of that is we set the size to be the + * entire range of 64 bit. User only provides PASID info + * without address info. So we set addr to 0. + */ + if (inv_info->granularity == IOMMU_INV_GRANU_PASID) { + size = 64 - VTD_PAGE_SHIFT; + addr = 0; + } else if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) + addr = inv_info->addr_info.addr; + if (info->ats_enabled) qi_flush_dev_iotlb_pasid(iommu, sid, info->pfsid, pasid, - info->ats_qdep, - inv_info->addr_info.addr, + info->ats_qdep, addr, size); else pr_warn_ratelimited("Passdown device IOTLB flush w/o ATS!\n"); -- 2.7.4