Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1519492ybt; Sat, 11 Jul 2020 12:54:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/vKUEmAa8e6KRi5QA+r88AQPxLc8SgJRyfqEeJZ0tcXo4ozeaqV2qFSPC2Z3GEpsA09uY X-Received: by 2002:a17:906:c453:: with SMTP id ck19mr40475479ejb.185.1594497261884; Sat, 11 Jul 2020 12:54:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594497261; cv=none; d=google.com; s=arc-20160816; b=SXPzTJgNMgMFyGqqrVo1ih9bIbXucFpE5p754WjloByP1neP7ACSvGt1O23C/Jz66z 4N0noO+LZWGj3oHBM+eLPVoOkmDbKekP+dAaHzn4RagdKQOoYvqShYkDc/jrYBB4WiRR LLeNuIBn+zJbI+PsDWZbMGSisd8hCxpeaNBP4QOK56ID3riMuvI4U4adpct0rpUomgQR CoDNulFuEUMRZ2+FOh1fVj1BPKt/3cfD0aIrK0uiLPgZ8begQkRzguLHjlvxDnGzU8mR 4JfWi+ot0pEv4Qm99/QH0XZtEYN/7o1tNCDVqLmxgWx3fU65BuXWilI9Pjb7tr5d+kZq 2XLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=8miKi6Xq1FyJeorpwJvlO4hqmskJW/q651F/Ck8IVEA=; b=b7Jv4wusIrdlf3JsUG2iZ35sR+R0DMXl1bGFgWG+60rOAESqFgPW9VBC/9kyyIFbHN pxh6Xk/vMnYH0lnamqY5o8DkBKwZD0+GyrvWKY6jipJO/6fVG2RPof6njUCLxpZP2Udz JhkrP66D5mfrzcQ5b7LAR0WwOHJPejknVyhKLU3bN5mFFzhytC+7GoxzEbm4K1BGmKh+ PWrDuU1lzMdlQ7VAnFYhLbM+mMZKzZB/1JYBRD0GMpPFuqI9hxv3VX2m2wWTbRN+wXB4 VTQ0qAnUHPusNfhPCsfAA5hSEa25jVTydMfElzsBrGUYk40mCZ9IiodnWLeL6y75DSPZ 0Jew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="j5yQ/Coh"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si6162820ejs.512.2020.07.11.12.53.58; Sat, 11 Jul 2020 12:54:21 -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="j5yQ/Coh"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbgGKTxt (ORCPT + 99 others); Sat, 11 Jul 2020 15:53:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:51866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726606AbgGKTxs (ORCPT ); Sat, 11 Jul 2020 15:53:48 -0400 Received: from localhost (mobile-166-175-191-139.mycingular.net [166.175.191.139]) (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 939A820725; Sat, 11 Jul 2020 19:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594497228; bh=Z16Tvyu00GM8lWPjZaVxUYQVl8q4upyC4+JAo11HVT4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=j5yQ/CohDw63QZlCRPNpB3igj8YUwmWz54kQmR+NLDemFBfMmRRyj9/fuFXIS/v5l 3+MtbbkCOKqOka1dDKyYWRtf6hATIydJPL9bZqOY/LWXNw0x+EsedbDrP/UmzD93DF 3kZBjfdZw4jfkVJfgeBp42Hfh+z3ro3SuIb9JwjA= Date: Sat, 11 Jul 2020 14:53:46 -0500 From: Bjorn Helgaas To: Rajat Jain Cc: "Raj, Ashok" , David Woodhouse , Lu Baolu , Joerg Roedel , Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown , "open list:AMD IOMMU (AMD-VI)" , Linux Kernel Mailing List , linux-pci , ACPI Devel Maling List , "Krishnakumar, Lalithambika" , Mika Westerberg , Jean-Philippe Brucker , Prashant Malani , Benson Leung , Todd Broch , Alex Levin , Mattias Nissler , Rajat Jain , Bernie Keany , Aaron Durbin , Diego Rivas , Duncan Laurie , Furquan Shaikh , Jesse Barnes , Christian Kellner , Alex Williamson , Greg Kroah-Hartman , Oliver O'Halloran , Saravana Kannan , Suzuki K Poulose , Arnd Bergmann , Heikki Krogerus Subject: Re: [PATCH v4 4/4] PCI/ACS: Enable PCI_ACS_TB for untrusted/external-facing devices Message-ID: <20200711195346.GA132330@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 10, 2020 at 03:53:59PM -0700, Rajat Jain wrote: > On Fri, Jul 10, 2020 at 2:29 PM Raj, Ashok wrote: > > On Fri, Jul 10, 2020 at 03:29:22PM -0500, Bjorn Helgaas wrote: > > > On Tue, Jul 07, 2020 at 03:46:04PM -0700, Rajat Jain wrote: > > > > When enabling ACS, enable translation blocking for external facing ports > > > > and untrusted devices. > > > > > > > > Signed-off-by: Rajat Jain > > > > --- > > > > v4: Add braces to avoid warning from kernel robot > > > > print warning for only external-facing devices. > > > > v3: print warning if ACS_TB not supported on external-facing/untrusted ports. > > > > Minor code comments fixes. > > > > v2: Commit log change > > > > > > > > drivers/pci/pci.c | 8 ++++++++ > > > > drivers/pci/quirks.c | 15 +++++++++++++++ > > > > 2 files changed, 23 insertions(+) > > > > > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > > > index 73a8627822140..a5a6bea7af7ce 100644 > > > > --- a/drivers/pci/pci.c > > > > +++ b/drivers/pci/pci.c > > > > @@ -876,6 +876,14 @@ static void pci_std_enable_acs(struct pci_dev *dev) > > > > /* Upstream Forwarding */ > > > > ctrl |= (cap & PCI_ACS_UF); > > > > > > > > + /* Enable Translation Blocking for external devices */ > > > > + if (dev->external_facing || dev->untrusted) { > > > > + if (cap & PCI_ACS_TB) > > > > + ctrl |= PCI_ACS_TB; > > > > + else if (dev->external_facing) > > > > + pci_warn(dev, "ACS: No Translation Blocking on external-facing dev\n"); > > > > + } > > > > > > IIUC, this means that external devices can *never* use ATS and > > > can never cache translations. > > Yes, but it already exists today (and this patch doesn't change that): > 521376741b2c2 "PCI/ATS: Only enable ATS for trusted devices" > > IMHO any external device trying to send ATS traffic despite having ATS > disabled should count as a bad intent. And this patch is trying to > plug that loophole, by blocking the AT traffic from devices that we do > not expect to see AT from anyway. Thinking about this some more, I wonder if Linux should: - Explicitly disable ATS for every device at enumeration-time, e.g., in pci_init_capabilities(), - Enable PCI_ACS_TB for every device (not just external-facing or untrusted ones), - Disable PCI_ACS_TB for the relevant devices along the path only when enabling ATS. One nice thing about doing that is that the "untrusted" test would be only in pci_enable_ats(), and we wouldn't need one in pci_std_enable_acs(). It's possible BIOS gives us devices with ATS enabled, and this might break them, but that seems like something we'd want to find out about. Bjorn