Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4744702pxj; Wed, 12 May 2021 12:13:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykg4Hji0IS6HUNHpUor82P6v8uufMjQercijULSLvkHi4HqiFM/vki9CbmoYlH/uFVN0Nj X-Received: by 2002:a05:6512:402:: with SMTP id u2mr24987250lfk.68.1620846806913; Wed, 12 May 2021 12:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620846806; cv=none; d=google.com; s=arc-20160816; b=S9UDMx0/TkpVvp9Cf50CbNztyAIX2n1CRKmkyNLiMw+INjYU9qX9aBmeWZnP7dtTBr YsZUrfxgjUp1d4IE3M9NbQsHiezjW2evG+qpAbMIvho6C7Le3eaaaidriyXNEpeIxItn 0Jq2nATGqmMoY4/6Tm2VfxApz8LW8flX0YAdy+L8Vyy1MP/8GWCMcmOl2Ef/KGYpzc0q ux7MPllwufcoXixAjXhOYPwe4y2rPlqLiE5T2Kd4NrvvUcWc50UtNF5fEQEGT1CUa8Wy o8tl3KtCM/ABgbtoQo3WeWf3H0ArD6lSC83MMCIOmR1+r/NsGzHkH62gUkUaEToI109R tAbw== 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=G4OiOBoEz7u9T3XFJFd5SbF9Us7BwyscaDEE4q4TqdI=; b=Gc1Cs4RqPZI0bM/t5MK4l76sY/9nZS9599mOyPDp4LfrEA5/0IVpBXFND67uppwCtY YlyYvceOihTYtMcsQ5hV0APwq6ZqFY443LGUaxzqYBO7fjJCDQsQmcMhi2Bz9QzZS20S zxqkiEkYuCqbWGgVWLoa2smOhKu4LlMwyP4Rle19Ya47SiXPXDKo6r0t21JOpCFdOMg7 mR894ViGwmnM7+wXcogfj+wTZIyWvsgIfPWPxqeMy0mOtzftdalzVOnZIx4L324GQ5i5 wqr6V7TZjuIjYljhO6PRU7GdOBi2uVblc6CIzBuajgunOPGZnJbMuQ9QFherOljhP4bq pQPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gZ7nC7Hn; 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 w15si696157lfa.362.2021.05.12.12.12.56; Wed, 12 May 2021 12:13:26 -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=gZ7nC7Hn; 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 S1376568AbhELSzH (ORCPT + 99 others); Wed, 12 May 2021 14:55:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:34162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244087AbhELQmd (ORCPT ); Wed, 12 May 2021 12:42:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1BA2661D26; Wed, 12 May 2021 16:10:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835814; bh=vCfPbGyg61AkflSrAvwiNdKbnF6rqjHHgc7yrzsWR64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gZ7nC7HnyfBuurYIdfNb/1BV6Qm35F45lx5GZmnZMnM/aHily6zQDMnGXr5j+7ijI OQHy2Iq16p5QHxjaK5XQKvwqDIU8WH4mMAnoWGrKisfdAlTZhspS1i8bibR2uHfLWB 2Bve5PTexK4Wi0U2KLvcMT56DYWQsD7FJkm2AJdA= 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.12 496/677] iommu/vt-d: Invalidate PASID cache when root/context entry changed Date: Wed, 12 May 2021 16:49:02 +0200 Message-Id: <20210512144853.861462453@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@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 36d60536ae8d..7e551da6c1fb 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1346,6 +1346,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) @@ -2453,6 +2458,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, @@ -3301,8 +3310,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 @@ -3492,12 +3499,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); } @@ -3880,8 +3882,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 1bc46b88711a..d1f32b33415a 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -372,6 +372,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