Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754395AbdGUI77 (ORCPT ); Fri, 21 Jul 2017 04:59:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37182 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753365AbdGUI75 (ORCPT ); Fri, 21 Jul 2017 04:59:57 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6DC284620F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=bhe@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6DC284620F From: Baoquan He To: jroedel@suse.de Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v8 12/13] iommu/amd: Clear out the GV flag when handle deferred domain attach Date: Fri, 21 Jul 2017 16:59:10 +0800 Message-Id: <1500627551-12930-13-git-send-email-bhe@redhat.com> In-Reply-To: <1500627551-12930-1-git-send-email-bhe@redhat.com> References: <1500627551-12930-1-git-send-email-bhe@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 21 Jul 2017 08:59:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1909 Lines: 58 When handle deferred domain attach, we need check if the domain is v2. If not, should try to clear out the GV flag which could be copied from the old device table entry. Signed-off-by: Baoquan He --- drivers/iommu/amd_iommu.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 46d077784da0..98aaccecbb76 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2085,6 +2085,11 @@ static void clear_dte_entry(u16 devid) amd_iommu_apply_erratum_63(devid); } +static void clear_dte_flag_gv(u16 devid) +{ + amd_iommu_dev_table[devid].data[0] &= (~DTE_FLAG_GV); +} + static void do_attach(struct iommu_dev_data *dev_data, struct protection_domain *domain) { @@ -2459,6 +2464,7 @@ static struct iommu_group *amd_iommu_device_group(struct device *dev) */ static struct protection_domain *get_domain(struct device *dev) { + struct iommu_dev_data *dev_data = get_dev_data(dev); struct protection_domain *domain; struct iommu_domain *io_domain; @@ -2466,11 +2472,21 @@ static struct protection_domain *get_domain(struct device *dev) return ERR_PTR(-EINVAL); domain = get_dev_data(dev)->domain; - if (domain == NULL && get_dev_data(dev)->defer_attach) { + if (domain == NULL && dev_data->defer_attach) { + u16 alias = amd_iommu_alias_table[dev_data->devid]; get_dev_data(dev)->defer_attach = false; io_domain = iommu_get_domain_for_dev(dev); domain = to_pdomain(io_domain); attach_device(dev, domain); + /* + * If the deferred attached domain is not v2, should clear out + * the old GV flag. + */ + if (!(domain->flags & PD_IOMMUV2_MASK)) { + clear_dte_flag_gv(dev_data->devid); + if (alias != dev_data->devid) + clear_dte_flag_gv(dev_data->devid); + } } if (!dma_ops_domain(domain)) return ERR_PTR(-EBUSY); -- 2.5.5