summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2024-06-04 19:16:18 +0300
committerJani Nikula <jani.nikula@intel.com>2024-08-22 16:29:49 +0300
commit5d4f308a0cd71418b7a8f9a09a24f230b4b217e6 (patch)
tree1be64349a8e56ee31df0556e9e2778301c523c5f
parent0eb127a7dd4f1be63c4cc0d00e7a2c2d0bcf36a5 (diff)
thunderbolt: Add Kconfig option to disable PCIe tunneling
In typical cases PCIe tunneling is needed to make the devices fully usable for the host system. However, it poses a security issue because they can also use DMA to access the host memory. We already have two ways of preventing this, one an IOMMU that is enabled on recent systems by default and the second is the "authorized" attribute under each connected device that needs to be written by userspace before a PCIe tunnel is created. This option adds one more by adding a Kconfig option, which is enabled by default, that can be used to make kernel binaries where PCIe tunneling is completely disabled. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> References: https://intel-gfx-ci.01.org/tree/drm-tip/Trybot_134314v1/bat-mtlp-9/boot0.txt References: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11261 Signed-off-by: Imre Deak <imre.deak@intel.com> Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240604161618.1958674-1-imre.deak@intel.com Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
-rw-r--r--drivers/thunderbolt/Kconfig18
-rw-r--r--drivers/thunderbolt/tb.c2
-rw-r--r--drivers/thunderbolt/tb.h9
-rw-r--r--drivers/thunderbolt/tunnel.c8
-rw-r--r--drivers/thunderbolt/usb4.c2
5 files changed, 33 insertions, 6 deletions
diff --git a/drivers/thunderbolt/Kconfig b/drivers/thunderbolt/Kconfig
index 0abdb69ee9f4..8bf4ecf7f76e 100644
--- a/drivers/thunderbolt/Kconfig
+++ b/drivers/thunderbolt/Kconfig
@@ -18,6 +18,24 @@ menuconfig USB4
if USB4
+config USB4_PCIE_TUNNELING
+ bool "Allow PCI Express tunneling over USB4 fabric"
+ depends on PCI
+ default y
+ help
+ USB4 and Thunderbolt devices typically include PCIe switch
+ with a number of PCIe endpoints such as USB host controllers,
+ GPUs and network adapters. These are made available to the
+ host system through PCIe tunneling. These can use DMA and
+ therefore have access to the host memory which is typically
+ guarded by an IOMMU. This option allows disabling PCIe
+ tunneling completely.
+
+ For devices to be usable it is recommended to say Y here.
+
+ Note this only works with systems that use Software Based
+ Connection Manager (this is most USB4 hosts).
+
config USB4_DEBUGFS_WRITE
bool "Enable write by debugfs to configuration spaces (DANGEROUS)"
help
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 10e719dd837c..7d71ff3f82c1 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -3181,7 +3181,7 @@ struct tb *tb_probe(struct tb_nhi *nhi)
if (!tb)
return NULL;
- if (tb_acpi_may_tunnel_pcie())
+ if (tb_may_tunnel_pcie())
tb->security_level = TB_SECURITY_USER;
else
tb->security_level = TB_SECURITY_NOPCIE;
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index b47f7873c847..4a39a9a84832 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -1457,6 +1457,15 @@ static inline int tb_acpi_power_on_retimers(struct tb_port *port) { return 0; }
static inline int tb_acpi_power_off_retimers(struct tb_port *port) { return 0; }
#endif
+static inline bool tb_may_tunnel_pcie(void)
+{
+#ifdef CONFIG_USB4_PCIE_TUNNELING
+ return tb_acpi_may_tunnel_pcie();
+#else
+ return false;
+#endif
+}
+
#ifdef CONFIG_DEBUG_FS
void tb_debugfs_init(void);
void tb_debugfs_exit(void);
diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
index 41cf6378ad25..7c8397c135ba 100644
--- a/drivers/thunderbolt/tunnel.c
+++ b/drivers/thunderbolt/tunnel.c
@@ -101,7 +101,7 @@ static unsigned int tb_available_credits(const struct tb_port *port,
size_t ndp;
usb3 = tb_acpi_may_tunnel_usb3() ? sw->max_usb3_credits : 0;
- pcie = tb_acpi_may_tunnel_pcie() ? sw->max_pcie_credits : 0;
+ pcie = tb_may_tunnel_pcie() ? sw->max_pcie_credits : 0;
if (tb_acpi_is_xdomain_allowed()) {
spare = min_not_zero(sw->max_dma_credits, dma_credits);
@@ -426,7 +426,7 @@ bool tb_tunnel_reserved_pci(struct tb_port *port, int *reserved_up,
if (WARN_ON_ONCE(!port->remote))
return false;
- if (!tb_acpi_may_tunnel_pcie())
+ if (!tb_may_tunnel_pcie())
return false;
if (tb_port_get_link_generation(port) < 4)
@@ -1510,7 +1510,7 @@ static unsigned int tb_dma_available_credits(const struct tb_port *port)
int credits;
credits = tb_available_credits(port, NULL);
- if (tb_acpi_may_tunnel_pcie())
+ if (tb_may_tunnel_pcie())
credits -= sw->max_pcie_credits;
credits -= port->dma_credits;
@@ -1821,7 +1821,7 @@ static int tb_usb3_consumed_bandwidth(struct tb_tunnel *tunnel,
int *consumed_up, int *consumed_down)
{
struct tb_port *port = tb_upstream_port(tunnel->dst_port->sw);
- int pcie_weight = tb_acpi_may_tunnel_pcie() ? TB_PCI_WEIGHT : 0;
+ int pcie_weight = tb_may_tunnel_pcie() ? TB_PCI_WEIGHT : 0;
/*
* PCIe tunneling, if enabled, affects the USB3 bandwidth so
diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c
index 4d83b65afb5b..4054bafba6a6 100644
--- a/drivers/thunderbolt/usb4.c
+++ b/drivers/thunderbolt/usb4.c
@@ -276,7 +276,7 @@ int usb4_switch_setup(struct tb_switch *sw)
* Only enable PCIe tunneling if the parent router supports it
* and it is not disabled.
*/
- if (tb_acpi_may_tunnel_pcie() &&
+ if (tb_may_tunnel_pcie() &&
tb_switch_find_port(parent, TB_TYPE_PCIE_DOWN)) {
val |= ROUTER_CS_5_PTO;
/*