Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4688196pxj; Wed, 12 May 2021 10:55:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD0tWwUFbwbHOBqrolHZvg7KMsph3Tt7vUvPCaZ94wPJOJIFVi7ky2OMgAVao+6ZAwQP1T X-Received: by 2002:aa7:c9cf:: with SMTP id i15mr45223892edt.4.1620842045615; Wed, 12 May 2021 10:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842045; cv=none; d=google.com; s=arc-20160816; b=fzrYUmI5azREVbeidVnhUgxwuI74A2UIMOs9fiWbTXMIsIR9XZyqmVCBMjuyKJN3aw gsT0nD9WlX5BM2T2vl/uXLvkkKwrKbHSY5e+ZQuvBJLZITLlNgadUCgxPVJv06vxtFEb sker+Njuh5Qyo9YOXC1i4pyCC68lCgHNXPDqL+lT/e77WQkyP43woa+igk4ht5tY6V9t oQbnEa/AsGBHx5c0T8aZLlHximT4FLOTr9uVFGsXC5P7pfE8lN0Mn6w5QniGZJy0veH2 JYb3ATQ+H3p3vFmUpl+u4ceaVbTJnE+bk4WFznhLa6XHpguvv2Iw4bXO67cJjbd1cggE ASDg== 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=BclEK7ZJHPjOWg6RgVPysuyxjfqGtc3KjIgNMUHtdA4=; b=p039ZEFKjbceh3Q+l7LG4Vrp8BuhmGafmBeXaDhiOuextAbAw4Sbq4AB/TD/Uz76nG 8GaAVhX7dvZvUetJgaTl0FQoKIOcvLTz+1sIaiisEJzINELuHYy9jb6CajLNzdZoywg4 Sr3sVUgaXCe1SHpE/DIIIBP4AuV6I2sd1fCLj8ZR1nzZ4y/XcDHDWb16IElp+92YV/vT S8wyXKhUSYvTWHKn/ylPkkvgl5n3FSPjdVnqkGvApIxSM6dVNH73HNe3/VXjqvi+RsOR /wAGjsShiGLs7idYgAvwZSqNkXVXpAvwmfS/fsAitB6kW75FApE1Cymy+OyXkW4XOjW9 NoaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w3Fgh5c0; 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 v7si456925edj.328.2021.05.12.10.53.40; Wed, 12 May 2021 10:54:05 -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=w3Fgh5c0; 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 S1350149AbhELRri (ORCPT + 99 others); Wed, 12 May 2021 13:47:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:58050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240126AbhELQRO (ORCPT ); Wed, 12 May 2021 12:17:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DE6FE61C7E; Wed, 12 May 2021 15:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834202; bh=/KxQ6l34LVY5e9xrrsw9nn+mBVdI45Q7yJKb8+S8w7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w3Fgh5c0n/O42V/zWgU0yiaO3nEt8R7yJ/CpBHtlasNZtaUOs5kTDE7CJSJ7seX/6 b8d9jc41wEgZeM+Djo8hPIocRZXGITqAWhc0MW1xPHQAaN1C69J3lcnrzI4dyJJ+gk p1bTZkkSsDy3I4Bt0cv5kbgW0vBe58sfGWKzp9XM= 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.11 442/601] iommu/vt-d: Invalidate PASID cache when root/context entry changed Date: Wed, 12 May 2021 16:48:39 +0200 Message-Id: <20210512144842.403119073@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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 82300b0d3074..93f17a8a42e2 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1336,6 +1336,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) @@ -2481,6 +2486,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, @@ -3325,8 +3334,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 @@ -3516,12 +3523,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); } @@ -3849,8 +3851,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 ecb35fdff03e..ce30ea103b8d 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