Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp5799430imm; Sat, 19 May 2018 09:53:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZruNPP8/8GU6ajmJTUvUfAKbeJY5Iz/NCOqRZPWJQ/4YLzEPNWtoWMd85kecgatRlbZOdoP X-Received: by 2002:a63:93:: with SMTP id 141-v6mr11192665pga.322.1526748807142; Sat, 19 May 2018 09:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526748807; cv=none; d=google.com; s=arc-20160816; b=fRtFu5CkAgk+nD2nW8zbFazVsTT/F7G4Eb/fiuL2wIbgRDWSKnaLQhRqcb/DqVC5cf DmCLix79E95qEO6Kc5WcoMfxlqJjfAYVrXbZvMIm3K6AEr7hv9jrK/f2Dodkqo46bNQR Z8jGmXy3e3d/NwXDNBAH+6xwnin1jCrRloZ0TEdv5E+kjzrtYxNGsAvxfJUXpmZMkfpn VLEps13y/oIgdhhvY29AAtUedSiek/4v2Gv5OoSg0COddMRR2lu+xlV9vvIaRPaJ1oke 7BkwtBCRthoeyUQW7fgJ/O2b8j3264CaCYKzWWJxlx0rhyEd7ygSbelVzNRxUpvRjOSY v3rQ== 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 :message-id:date:subject:cc:to:from:dmarc-filter:dkim-signature :dkim-signature:arc-authentication-results; bh=bQ23jd/duB6m2ZzhTF1ANpItTOIycgGXT3fT3RYUlbM=; b=zTcYM4N+AnJiHndAd2DB6N3lDrMa20j5ZO1pEcUxlJBpna+QLnFG5aLr+pc+gx2gNW KHopsqblzEhh54hJ3jkhlln4ftjHZ8j98FAQ8f66nveynOYBIw+Ubu+zVq6gH1bKWkF8 NQsltvbamrMxS346GZ6I1wKd5LjErYX4YjJcKIFd9h4HmoBRLSjaGBkF+KtsIpKXpE2G GVja3kRpLHw2DGRjy4227W5JpH7u6zFsri013tU8C57/ZWTY9kVg65+X0Q/fYJtXRrZL l+MgTM9cII7L5q2uexZTqfWn5mGb3BP51XiTalazcY/z0volYF6J1AMxlX5nuuLpK8uG xNRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=DWNvCL1b; dkim=pass header.i=@codeaurora.org header.s=default header.b=DWNvCL1b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si7743017pgn.430.2018.05.19.09.53.10; Sat, 19 May 2018 09:53:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=DWNvCL1b; dkim=pass header.i=@codeaurora.org header.s=default header.b=DWNvCL1b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752515AbeESQw7 (ORCPT + 99 others); Sat, 19 May 2018 12:52:59 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:50914 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752344AbeESQw4 (ORCPT ); Sat, 19 May 2018 12:52:56 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F039460385; Sat, 19 May 2018 16:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526748775; bh=G4XTUHeXaj+O7VIeUp19a2h+O3Je7WjvCjvKUMUZNSo=; h=From:To:Cc:Subject:Date:From; b=DWNvCL1bwftwkkMDPBnGT9pGmaMUrUknDQKMHXF6Duan/2ERWIvPwXy/CPgbrhn3c BA/CcwXigiGj3K+/B+ToZBc5RUUZZvxTCIVV0Ri+CoEPsb6KUxsGNZH2SURCU/EXSw 8ObrSZlklVn6QvxrafoFP17YI7GAC9NSGAq0pAdo= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from drakthul.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 936FB602B6; Sat, 19 May 2018 16:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526748775; bh=G4XTUHeXaj+O7VIeUp19a2h+O3Je7WjvCjvKUMUZNSo=; h=From:To:Cc:Subject:Date:From; b=DWNvCL1bwftwkkMDPBnGT9pGmaMUrUknDQKMHXF6Duan/2ERWIvPwXy/CPgbrhn3c BA/CcwXigiGj3K+/B+ToZBc5RUUZZvxTCIVV0Ri+CoEPsb6KUxsGNZH2SURCU/EXSw 8ObrSZlklVn6QvxrafoFP17YI7GAC9NSGAq0pAdo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 936FB602B6 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=okaya@codeaurora.org From: Sinan Kaya To: linux-pci@vger.kernel.org, timur@codeaurora.org Cc: linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sinan Kaya , Bjorn Helgaas , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] PCI: Do not enable PASID when End-to-End TLP is not supported Date: Sat, 19 May 2018 12:52:49 -0400 Message-Id: <1526748769-701-1-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A PCIe endpoint carries the process address space identifier (PASID) in the TLP prefix as part of the memory read/write transaction. The address information in the TLP is relevant only for a given PASID context. A translation agent takes PASID value and the address information from the TLP to look up the physical address in the system. If a bridge drops the TLP prefix, the translation agent can resolve the address to an incorrect location and cause data corruption. Prevent this condition by requiring End-to-End TLP prefix to be supported on the entire data path between the endpoint and the root port. Signed-off-by: Sinan Kaya --- drivers/pci/ats.c | 16 ++++++++++++++++ include/uapi/linux/pci_regs.h | 1 + 2 files changed, 17 insertions(+) diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index 89305b5..0bcded5 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -265,7 +265,9 @@ EXPORT_SYMBOL_GPL(pci_reset_pri); int pci_enable_pasid(struct pci_dev *pdev, int features) { u16 control, supported; + struct pci_dev *bridge; int pos; + u32 cap; if (WARN_ON(pdev->pasid_enabled)) return -EBUSY; @@ -274,6 +276,20 @@ int pci_enable_pasid(struct pci_dev *pdev, int features) if (!pos) return -EINVAL; + bridge = pci_upstream_bridge(pdev); + while (bridge) { + if (!pci_find_capability(bridge, PCI_CAP_ID_EXP)) + return -EINVAL; + + if (pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap)) + return -EINVAL; + + if (!(cap & PCI_EXP_DEVCAP2_E2ETLP)) + return -EINVAL; + + bridge = pci_upstream_bridge(bridge); + } + pci_read_config_word(pdev, pos + PCI_PASID_CAP, &supported); supported &= PCI_PASID_CAP_EXEC | PCI_PASID_CAP_PRIV; diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index 103ba79..d91dea5 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -634,6 +634,7 @@ #define PCI_EXP_DEVCAP2_OBFF_MASK 0x000c0000 /* OBFF support mechanism */ #define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000 /* New message signaling */ #define PCI_EXP_DEVCAP2_OBFF_WAKE 0x00080000 /* Re-use WAKE# for OBFF */ +#define PCI_EXP_DEVCAP2_E2ETLP 0x00200000 /* End-to-End TLP Prefix */ #define PCI_EXP_DEVCTL2 40 /* Device Control 2 */ #define PCI_EXP_DEVCTL2_COMP_TIMEOUT 0x000f /* Completion Timeout Value */ #define PCI_EXP_DEVCTL2_COMP_TMOUT_DIS 0x0010 /* Completion Timeout Disable */ -- 2.7.4