Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4623449pxj; Wed, 12 May 2021 09:27:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAOB/qvWPREuxe2nLlOOubQMXpTJ9C5tUSQ1Z/4VO7VnXIMe9T9pLppnFXftf4EODnvbRa X-Received: by 2002:a05:6512:24b:: with SMTP id b11mr25135809lfo.486.1620836866548; Wed, 12 May 2021 09:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836866; cv=none; d=google.com; s=arc-20160816; b=Ydn0GCN8FY5j1k1I1PFmnyYnHsAtmda9FQVjiUYqzuFdtfSG0LsHyuiIjLHaf+1AC4 w5nI+iZLLt9bXbACZFnUUJ7/ZJUUFP4Tf1qeQ79ETJQTrK1RWAjhfQ8oNrthIJ2qe3me 6JRWbjm62i/mMg8ckGotFUJIboyf3xzjwSiCN1JTHqWiA3RngMetd8GS3J43PCdFEtEM nxLtjc9fwwKy0G7Ft/0je6RN8x+yUAY8jxn7P2VZppqmRfFIRjiTs5XwBSk94m9wSx7N QqmX3dHwb1g99cHRmXxVz7No1vZ9RTqhDwr0iG6Eqv9du4ZZRtUuFVJctKJEUB8AksY4 y4HQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eO3U8wM9OE1V0TjfMsQtM3Ci4TGr+uQUOGfW0icA5ZI=; b=JpkuQEb2sjkG8fwhvKb3FaGJwbPkuVbRodDdqM8YJ3XPGwtFPgFDzcbPNGRW5w3Sx0 vYnZ9j5x0mVe1wPnVGsT/yM7KrPbbm4BfxOoORFNRbKRKKB23FfRm/ROSifJUlBiJ7sh rbyrYtiQOruBlwOhqkiOLLGFTLCb9uQAmdoug2wUmRdDpU2RbnG5nHZg/3eCBuMqAZRK zWXbCnJo15osvO0HW5Glh3xIbcCdggZPZPF/7Iw9ueNTV3x+DSWtR1bEtLEvNG6ayKDO DEpA197XcfVLoaeUvybkGy7dnEWyx4mSXR+cFok232AtipB2DR6sL9BhxRQ7EXveRksa ETQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T+i+HmOX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si371979lfb.172.2021.05.12.09.27.08; Wed, 12 May 2021 09:27:46 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T+i+HmOX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236953AbhELQXh (ORCPT + 99 others); Wed, 12 May 2021 12:23:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:54482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236167AbhELPhM (ORCPT ); Wed, 12 May 2021 11:37:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C2DE61440; Wed, 12 May 2021 15:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832717; bh=ToZsmUthcRYVdCtlOMRKKJIHnE8C9TgQyoL2eXMTSIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T+i+HmOXpjH1ukKufKh5EIgB/f56zYf3u70afL6W8cEfTXpCW9ZiUgXUqQKNOxWLq 8XXbSKiwg9ChmkxknE7EHAE7hCFJPybrSaYJbuU6/zJb7SjV42moN1bhtwatbXgWEn i6lDvAe+LWhgLL7lU7GbX2CC7ykVFt/EjSWzdEqs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ashok Raj , Lu Baolu , Joerg Roedel , Sasha Levin Subject: [PATCH 5.10 394/530] iommu/vt-d: Invalidate PASID cache when root/context entry changed Date: Wed, 12 May 2021 16:48:24 +0200 Message-Id: <20210512144832.723403472@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lu Baolu [ Upstream commit c0474a606ecb9326227b4d68059942f9db88a897 ] When the Intel IOMMU is operating in the scalable mode, some information from the root and context table may be used to tag entries in the PASID cache. Software should invalidate the PASID-cache when changing root or context table entries. Suggested-by: Ashok Raj Fixes: 7373a8cc38197 ("iommu/vt-d: Setup context and enable RID2PASID support") Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20210320025415.641201-4-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel/iommu.c | 18 +++++++++--------- include/linux/intel-iommu.h | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 30c2b52f7ea2..db9bf5ac0722 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1348,6 +1348,11 @@ static void iommu_set_root_entry(struct intel_iommu *iommu) readl, (sts & DMA_GSTS_RTPS), sts); raw_spin_unlock_irqrestore(&iommu->register_lock, flag); + + iommu->flush.flush_context(iommu, 0, 0, 0, DMA_CCMD_GLOBAL_INVL); + if (sm_supported(iommu)) + qi_flush_pasid_cache(iommu, 0, QI_PC_GLOBAL, 0); + iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH); } void iommu_flush_write_buffer(struct intel_iommu *iommu) @@ -2521,6 +2526,10 @@ static void domain_context_clear_one(struct intel_iommu *iommu, u8 bus, u8 devfn (((u16)bus) << 8) | devfn, DMA_CCMD_MASK_NOBIT, DMA_CCMD_DEVICE_INVL); + + if (sm_supported(iommu)) + qi_flush_pasid_cache(iommu, did_old, QI_PC_ALL_PASIDS, 0); + iommu->flush.flush_iotlb(iommu, did_old, 0, @@ -3387,8 +3396,6 @@ static int __init init_dmars(void) register_pasid_allocator(iommu); #endif iommu_set_root_entry(iommu); - iommu->flush.flush_context(iommu, 0, 0, 0, DMA_CCMD_GLOBAL_INVL); - iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH); } #ifdef CONFIG_INTEL_IOMMU_BROKEN_GFX_WA @@ -4166,12 +4173,7 @@ static int init_iommu_hw(void) } iommu_flush_write_buffer(iommu); - iommu_set_root_entry(iommu); - - iommu->flush.flush_context(iommu, 0, 0, 0, - DMA_CCMD_GLOBAL_INVL); - iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH); iommu_enable_translation(iommu); iommu_disable_protect_mem_regions(iommu); } @@ -4499,8 +4501,6 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru) goto disable_iommu; iommu_set_root_entry(iommu); - iommu->flush.flush_context(iommu, 0, 0, 0, DMA_CCMD_GLOBAL_INVL); - iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH); iommu_enable_translation(iommu); iommu_disable_protect_mem_regions(iommu); diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index ccaa057faf8c..c00ee3458a91 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -369,6 +369,7 @@ enum { /* PASID cache invalidation granu */ #define QI_PC_ALL_PASIDS 0 #define QI_PC_PASID_SEL 1 +#define QI_PC_GLOBAL 3 #define QI_EIOTLB_ADDR(addr) ((u64)(addr) & VTD_PAGE_MASK) #define QI_EIOTLB_IH(ih) (((u64)ih) << 6) -- 2.30.2