Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp578655ybt; Fri, 19 Jun 2020 08:34:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfdZpP0jh5QyRQlFHo/qgDL3MlI4rV9D9HbOkN0vajrQJF5WU3X9c0nqTy6jS6jKQGNjdr X-Received: by 2002:a17:907:20e5:: with SMTP id rh5mr4372978ejb.80.1592580886231; Fri, 19 Jun 2020 08:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592580886; cv=none; d=google.com; s=arc-20160816; b=eB2gJxFEJGAtZp9BxzFpGDhPnbJkoPJrRvnpeEq1ogpWjEo5gFfogyg1uykqIU1am9 iliz5IywpnTBvcDSV/xpCGiyj/HQCNGhrvqYPErLnmBqKRQ1YxMvs7kIcuqNWJMfKbnv jHl4nQZCyFrT1dRiZydNlFEmod8nboGD+o1wlP2RcAtTwzSahi+364UAxVO2G39kkePs zHvt1+vum/Z+8SPaMGeYwN3Ly04hWJkDnXH7qWSUHa8mq083ONDn0UTvBerHUXLfCDDL apjAJDxvKBRc6JDQaNOzoG5vyFYqFHPlNIkstLI0oE5I7j69B+Hgw6PSJ5kkAt14Vblt UObQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AKOv1+FL25a5ZaYvNWELtAr4G6k4fmCx9RKsp5nwrUk=; b=rVO5Js2/7RJ7k0Htxcdx5/Ee+WAPGNeADIIinwXOXS+MnRRWMbubQ/wXB7NacVJLSk DSOz7/l+WC4LKfLsuIoupSRicoJBU9rsjUiK5fcY/2w4tavRr9WZnmdgSn83DC0lGhCw knVE6MuRMrGAPHwZtKMcqVvRxp2fvftPnP81Eu/R8vZWCMuQejyPnb23xhg2asG8QyHU PQ3WvVFA+uqrm4CcUmO3ueMMBA9TO5idrnIR/ln0QhhHbceJhxpRjI5lRtNHzX/dUGc2 V/FYDhbB5cwbanNy+EJERBVj5+LLhki9ufcoRg08DhBVmyLftXxiABChZYYG3vN7wKPy Dr4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GOgSIkGI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s9si4075220ejq.422.2020.06.19.08.34.23; Fri, 19 Jun 2020 08:34: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=@kernel.org header.s=default header.b=GOgSIkGI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404850AbgFSPbg (ORCPT + 99 others); Fri, 19 Jun 2020 11:31:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:35436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404800AbgFSPbZ (ORCPT ); Fri, 19 Jun 2020 11:31:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 35EB620734; Fri, 19 Jun 2020 15:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592580684; bh=Y/Lb5lAdvhdVexwD+MUXXAuDp4qFi/nlRnJwPonoEWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GOgSIkGIJt/YnW8ihkhCogXvKNBg87CbpVoWWv6yX2axJwzs+hRDkn/sJiocvg+hN m1tKxA8KZPcpJzIE4tEJKjoAM4JmEgrCuWrnffZv7s4WaLrow4obVCvXoKAs6yoXg5 fj2C79V0mRprL0RrpAP3S554DkSuadPLB24MM4w4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Derrick , Lu Baolu , Joerg Roedel Subject: [PATCH 5.7 313/376] iommu/vt-d: Only clear real DMA devices context entries Date: Fri, 19 Jun 2020 16:33:51 +0200 Message-Id: <20200619141725.153453612@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jon Derrick commit 8038bdb8553313ad53bfcffcf8294dd0ab44618f upstream. Domain context mapping can encounter issues with sub-devices of a real DMA device. A sub-device cannot have a valid context entry due to it potentially aliasing another device's 16-bit ID. It's expected that sub-devices of the real DMA device uses the real DMA device's requester when context mapping. This is an issue when a sub-device is removed where the context entry is cleared for all aliases. Other sub-devices are still valid, resulting in those sub-devices being stranded without valid context entries. The correct approach is to use the real DMA device when programming the context entries. The insertion path is correct because device_to_iommu() will return the bus and devfn of the real DMA device. The removal path needs to only operate on the real DMA device, otherwise the entire context entry would be cleared for all sub-devices of the real DMA device. This patch also adds a helper to determine if a struct device is a sub-device of a real DMA device. Fixes: 2b0140c69637e ("iommu/vt-d: Use pci_real_dma_dev() for mapping") Cc: stable@vger.kernel.org # v5.6+ Signed-off-by: Jon Derrick Acked-by: Lu Baolu Link: https://lore.kernel.org/r/20200527165617.297470-2-jonathan.derrick@intel.com Signed-off-by: Joerg Roedel Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/intel-iommu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2582,6 +2582,12 @@ static int domain_setup_first_level(stru flags); } +static bool dev_is_real_dma_subdevice(struct device *dev) +{ + return dev && dev_is_pci(dev) && + pci_real_dma_dev(to_pci_dev(dev)) != to_pci_dev(dev); +} + static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, int bus, int devfn, struct device *dev, @@ -5286,7 +5292,8 @@ static void __dmar_remove_one_dev_info(s PASID_RID2PASID); iommu_disable_dev_iotlb(info); - domain_context_clear(iommu, info->dev); + if (!dev_is_real_dma_subdevice(info->dev)) + domain_context_clear(iommu, info->dev); intel_pasid_free_table(info->dev); }