Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4687041pxj; Wed, 12 May 2021 10:54:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRuezswtEkBKWBmcZZRGYjcQO7xa5o9+cztKN6aS2kKUxdjM0JxE8GVutVejyIv2kL61oH X-Received: by 2002:aa7:dd41:: with SMTP id o1mr44143661edw.361.1620842044552; Wed, 12 May 2021 10:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842044; cv=none; d=google.com; s=arc-20160816; b=jMOriDPnM/rwgXfq3mbOGHC+rzb7LrOcQN26z+2A6/DAljSdj/E8SzZIAJwbP3Lns7 Oe2ab4u1jjO1A7hZoLxW8GKpQwAv37nmT3284ShMNcHcdGtZipMcbGppfxN2ZPnr248q cJ5mWaz2NTyuuPV8VndEiCoucOjIm0qGB/06pUr80fIlAfhgDeGBOSn0jvRyJ9xCMhXM dTqBGaAz+FtpW48CoiL1dE714lntFNkqjo+CguwvSkNkejI2S1SgC1ylT6CP//yPOjDc x9g0p18S0HSpveg0I8cRoOaQvpJm5BWaAsnNo+0N1Sp4v/VtYhZXa6IV4wtmlQ3UjiK+ n0tg== 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=nBJUGjO+5e4xQ16HZYHxMpmZ6vA8+KWtgHl8C0jillo=; b=QRHWr2w3hwlbv+W4jgRGL3XgjqIN1KKXk+k0w4tdI23rhZXw8Ur43tKbxyqYomk6Ln e80gjj0VZhRs+spDxzlcuyAjYa0bUeRLKE0pltzxRnmpB8DluCG6HmKyXjBnaDpJXX1c X1R/G8USH2B54E7qKkAZEiEKdkkO4bFP8VGbpygl/c89vnuFgrKYiqjJfEMZVBzjAYvw J6EQFD4xeAIXpn8c4R2ZpEoHqXY2N8WTtHKdRKxSJn73dnloayfzllcRrYJxWZe4qk+G zcHHP6na2IeRINmws6U1uS724L8+jzJbyy+rhQuA/i/bDl0v/ZDAcK0aDmYp7kyn5+qo lQcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Aqf0hXov; 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 jz1si505684ejb.461.2021.05.12.10.53.40; Wed, 12 May 2021 10:54:04 -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=Aqf0hXov; 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 S1350065AbhELRrR (ORCPT + 99 others); Wed, 12 May 2021 13:47:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:53912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239965AbhELQQj (ORCPT ); Wed, 12 May 2021 12:16:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 989BE61D61; Wed, 12 May 2021 15:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834178; bh=3wKZGAE2na+RHOc7ImlLNBOKC2OrFtGU3peSdJACK80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Aqf0hXovvS7rwVRsVpCNn1OdPLzNvYcw80gn56y3Pa30vbt9JejonNDfwYHPVxCy9 ksVb15+eWsP5hw7/wFNhZlGtFIb9Gz3oZ90s9fzoPr7Y74SteuGRAdFzpCmsoHZ1Dx C5GkINvnaB00tXPj+x/aaUhHx4G1BtGNGtigWHQs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rajesh Sankaran , Kevin Tian , Ashok Raj , Lu Baolu , Joerg Roedel , Sasha Levin Subject: [PATCH 5.11 438/601] iommu/vt-d: Report right snoop capability when using FL for IOVA Date: Wed, 12 May 2021 16:48:35 +0200 Message-Id: <20210512144842.266441311@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 6c00612d0cba10f7d0917cf1f73c945003ed4cd7 ] The Intel VT-d driver checks wrong register to report snoop capablility when using first level page table for GPA to HPA translation. This might lead the IOMMU driver to say that it supports snooping control, but in reality, it does not. Fix this by always setting PASID-table-entry.PGSNP whenever a pasid entry is setting up for GPA to HPA translation so that the IOMMU driver could report snoop capability as long as it runs in the scalable mode. Fixes: b802d070a52a1 ("iommu/vt-d: Use iova over first level") Suggested-by: Rajesh Sankaran Suggested-by: Kevin Tian Suggested-by: Ashok Raj Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20210330021145.13824-1-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel/iommu.c | 12 +++++++++++- drivers/iommu/intel/pasid.c | 16 ++++++++++++++++ drivers/iommu/intel/pasid.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 005daf50107d..026041308409 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -647,7 +647,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip) rcu_read_lock(); for_each_active_iommu(iommu, drhd) { if (iommu != skip) { - if (!ecap_sc_support(iommu->ecap)) { + /* + * If the hardware is operating in the scalable mode, + * the snooping control is always supported since we + * always set PASID-table-entry.PGSNP bit if the domain + * is managed outside (UNMANAGED). + */ + if (!sm_supported(iommu) && + !ecap_sc_support(iommu->ecap)) { ret = 0; break; } @@ -2546,6 +2553,9 @@ static int domain_setup_first_level(struct intel_iommu *iommu, flags |= (level == 5) ? PASID_FLAG_FL5LP : 0; + if (domain->domain.type == IOMMU_DOMAIN_UNMANAGED) + flags |= PASID_FLAG_PAGE_SNOOP; + return intel_pasid_setup_first_level(iommu, dev, (pgd_t *)pgd, pasid, domain->iommu_did[iommu->seq_id], flags); diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index b92af83b79bd..ce4ef2d245e3 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -411,6 +411,16 @@ static inline void pasid_set_page_snoop(struct pasid_entry *pe, bool value) pasid_set_bits(&pe->val[1], 1 << 23, value << 23); } +/* + * Setup the Page Snoop (PGSNP) field (Bit 88) of a scalable mode + * PASID entry. + */ +static inline void +pasid_set_pgsnp(struct pasid_entry *pe) +{ + pasid_set_bits(&pe->val[1], 1ULL << 24, 1ULL << 24); +} + /* * Setup the First Level Page table Pointer field (Bit 140~191) * of a scalable mode PASID entry. @@ -579,6 +589,9 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu, } } + if (flags & PASID_FLAG_PAGE_SNOOP) + pasid_set_pgsnp(pte); + pasid_set_domain_id(pte, did); pasid_set_address_width(pte, iommu->agaw); pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); @@ -657,6 +670,9 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, pasid_set_fault_enable(pte); pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); + if (domain->domain.type == IOMMU_DOMAIN_UNMANAGED) + pasid_set_pgsnp(pte); + /* * Since it is a second level only translation setup, we should * set SRE bit as well (addresses are expected to be GPAs). diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index 444c0bec221a..086ebd697319 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -48,6 +48,7 @@ */ #define PASID_FLAG_SUPERVISOR_MODE BIT(0) #define PASID_FLAG_NESTED BIT(1) +#define PASID_FLAG_PAGE_SNOOP BIT(2) /* * The PASID_FLAG_FL5LP flag Indicates using 5-level paging for first- -- 2.30.2