Skip to contentSkip to conversation

PCI: ACPI: Allow internal devices to be marked as untrusted

PATCH Superseded Rajat Jain 8 participants 20 messages Jan 20, 2022 – Feb 2, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Rajat Jain

author
#0 lore raw

PATCH 1/1 PCI: ACPI: Allow internal devices to be marked as untrusted

Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" property). This however, disallows any internal devices to be marked as untrusted.

There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware, or offers an attack surface by handling untrusted network data etc).

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

---
 drivers/pci/pci-acpi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/pci/pci-acpi.c +13 -0
index a42dbf448860..3d9e5fa49451 100644
@@ -1350,12 +1350,25 @@ static void pci_acpi_set_external_facing(struct pci_dev *dev)
 		dev->external_facing = 1;
 }
 
+static void pci_acpi_set_untrusted(struct pci_dev *dev)
+{
+	u8 val;
+
+	if (device_property_read_u8(&dev->dev, "UntrustedDevice", &val))
+		return;
+
+	/* These PCI devices are not trustworthy */
+	if (val)
+		dev->untrusted = 1;
+}
+
 void pci_acpi_setup(struct device *dev, struct acpi_device *adev)
 {
 	struct pci_dev *pci_dev = to_pci_dev(dev);
 
 	pci_acpi_optimize_delay(pci_dev, adev->handle);
 	pci_acpi_set_external_facing(pci_dev);
+	pci_acpi_set_untrusted(pci_dev);
 	pci_acpi_add_edr_notifier(pci_dev);
 
 	pci_acpi_add_pm_notifier(adev, pci_dev);
Signature · 1 line
2.34.1.703.g22d0c6ccf7-goog
#1 lore raw

Hi Rajat,

Quoted 26 lines · Rajat Jain

Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" property). This however, disallows any internal devices to be marked as untrusted.

There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware, or offers an attack surface by handling untrusted network data etc).

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

---
 drivers/pci/pci-acpi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index a42dbf448860..3d9e5fa49451 100644
@@ -1350,12 +1350,25 @@ static void pci_acpi_set_external_facing(struct pci_dev *dev)
                dev->external_facing = 1;
 }
 

drivers/pci/pci-acpi.c static void pci_acpi_set_external_facing(struct pci_dev *dev) · line 1362

Quoted 10 lines
drivers/pci/pci-acpi.c +10 -0
+static void pci_acpi_set_untrusted(struct pci_dev *dev)
+{
+       u8 val;
+
+       if (device_property_read_u8(&dev->dev, "UntrustedDevice", &val))
+               return;
+
+       /* These PCI devices are not trustworthy */
+       if (val)
+               dev->untrusted = 1;

Should this all be replaced with:

dev->untrusted = device_property_read_bool(&dev->dev, "UntrustedDevice");

?

Also, is this ACPI-specific? Why won't we need this for DT systems (or do we already have this)?.

Thanks,
Dmitry

#2 lore raw

Hi Dmitry, Bjorn,

Thanks for your review and comments.

Quoted 43 lines · Dmitry Torokhov

Hi Rajat,

Quoted 26 lines · Rajat Jain

Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" property). This however, disallows any internal devices to be marked as untrusted.

There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware, or offers an attack surface by handling untrusted network data etc).

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

---
 drivers/pci/pci-acpi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index a42dbf448860..3d9e5fa49451 100644
@@ -1350,12 +1350,25 @@ static void pci_acpi_set_external_facing(struct pci_dev *dev)
                dev->external_facing = 1;
 }
 

drivers/pci/pci-acpi.c static void pci_acpi_set_external_facing(struct pci_dev *dev) · line 1362

Quoted 10 lines
drivers/pci/pci-acpi.c +10 -0
+static void pci_acpi_set_untrusted(struct pci_dev *dev)
+{
+       u8 val;
+
+       if (device_property_read_u8(&dev->dev, "UntrustedDevice", &val))
+               return;
+
+       /* These PCI devices are not trustworthy */
+       if (val)
+               dev->untrusted = 1;

Should this all be replaced with:

Quoted 3 lines

dev->untrusted = device_property_read_bool(&dev->dev, "UntrustedDevice");

?

Ack, yes, I will do this.

Quoted 3 lines

Also, is this ACPI-specific? Why won't we need this for DT systems (or do we already have this)?.

Good point. Ack, Yes, I don't mind doing this for DT systems also. I wanted to get some feedback and acceptance within the PCI subsystem on the general idea of this property though. Bjorn?

Thanks & Best Regards,

Rajat

Quoted 3 lines

Thanks,
Dmitry

author
#3 lore raw
In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 43 lines · Dmitry Torokhov

Hi Rajat,

Quoted 26 lines · Rajat Jain

Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" property). This however, disallows any internal devices to be marked as untrusted.

There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware, or offers an attack surface by handling untrusted network data etc).

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

---
 drivers/pci/pci-acpi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index a42dbf448860..3d9e5fa49451 100644
@@ -1350,12 +1350,25 @@ static void pci_acpi_set_external_facing(struct pci_dev *dev)
                dev->external_facing = 1;
 }
 

drivers/pci/pci-acpi.c static void pci_acpi_set_external_facing(struct pci_dev *dev) · line 1362

Quoted 10 lines
drivers/pci/pci-acpi.c +10 -0
+static void pci_acpi_set_untrusted(struct pci_dev *dev)
+{
+       u8 val;
+
+       if (device_property_read_u8(&dev->dev, "UntrustedDevice", &val))
+               return;
+
+       /* These PCI devices are not trustworthy */
+       if (val)
+               dev->untrusted = 1;

Should this all be replaced with:

Quoted 1 line

dev->untrusted = device_property_read_bool(&dev->dev, "UntrustedDevice");

The device_property_read_bool() seems to be merely checking for property presence (and ignoring its value).

I checked with our BIOS / ACPI team. Per them, the ACPI properties always have a value associated with them.

So if I switch to device_property_read_bool(), "UntrustedDevice" property with a value of "0" in ACPI shall be marked as an untrusted device by the kernel. I understand that this may be a confusing corner case of bad ACPI, but I was thinking it may be better to use the ACPI value also in the kernel to decide. Thus I think the use of device_property_read_u8() (the current code) may be better. WDYT?

Thanks & Best Regards,

Rajat

Quoted 8 lines

?

Also, is this ACPI-specific? Why won't we need this for DT systems (or do we already have this)?.

Thanks,
Dmitry

#4 lore raw
In reply to Rajat Jain

[+cc Greg, Jean-Philippe, Mika, Pavel, Oliver, Joerg since they commented on previous "external-facing" discussion]

Quoted 3 lines · Rajat Jain

Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" property). This however, disallows any internal devices to be marked as untrusted.

This isn't stated quite accurately. "dev->untrusted" is currently set only by set_pcie_untrusted(), when "dev" has an upstream bridge that is either external-facing or untrusted.

But that doesn't disallow or prevent internal devices from being marked as untrusted; it just doesn't implement that.

Quoted 7 lines

There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware, or offers an attack surface by handling untrusted network data etc).

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think I'm OK with this. Write this last sentence in imperative mood; see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/maintainer-tip.rst?id=v5.16#n134
for examples.

Quoted 11 lines
---
 drivers/pci/pci-acpi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index a42dbf448860..3d9e5fa49451 100644
@@ -1350,12 +1350,25 @@ static void pci_acpi_set_external_facing(struct pci_dev *dev)
 		dev->external_facing = 1;

drivers/pci/pci-acpi.c static void pci_acpi_set_external_facing(struct pci_dev *dev) · line 1360

Quoted 10 lines
drivers/pci/pci-acpi.c +8 -0
 }
 
+static void pci_acpi_set_untrusted(struct pci_dev *dev)
+{
+	u8 val;
+
+	if (device_property_read_u8(&dev->dev, "UntrustedDevice", &val))
+		return;
+
+	/* These PCI devices are not trustworthy */

Comment is probably superfluous since the code seems obvious without it.

Quoted 17 lines
drivers/pci/pci-acpi.c +5 -0
+	if (val)
+		dev->untrusted = 1;
+}
+
 void pci_acpi_setup(struct device *dev, struct acpi_device *adev)
 {
 	struct pci_dev *pci_dev = to_pci_dev(dev);
 
 	pci_acpi_optimize_delay(pci_dev, adev->handle);
 	pci_acpi_set_external_facing(pci_dev);
+	pci_acpi_set_untrusted(pci_dev);
 	pci_acpi_add_edr_notifier(pci_dev);
 
 	pci_acpi_add_pm_notifier(adev, pci_dev);
Signature · 1 line
2.34.1.703.g22d0c6ccf7-goog
#5 lore raw
Quoted 8 lines · Bjorn Helgaas

[+cc Greg, Jean-Philippe, Mika, Pavel, Oliver, Joerg since they commented on previous "external-facing" discussion]

Quoted 3 lines · Rajat Jain

Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" property). This however, disallows any internal devices to be marked as untrusted.

Quoted 11 lines

This isn't stated quite accurately. "dev->untrusted" is currently set only by set_pcie_untrusted(), when "dev" has an upstream bridge that is either external-facing or untrusted.

But that doesn't disallow or prevent internal devices from being marked as untrusted; it just doesn't implement that.

Quoted 4 lines

There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware, or offers an attack surface by handling untrusted network data etc).

Who is making this policy decision?

Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

Is this in the ACPI standard? If so, where?

This notion of "trust" for PCI devices is crazy, as I have stated a number of times before. But at least you are not trying to say kernel code is trusted or not.

thanks,

greg k-h

#6 lore raw
In reply to Bjorn Helgaas

Hi,

Quoted 8 lines · Bjorn Helgaas

[+cc Greg, Jean-Philippe, Mika, Pavel, Oliver, Joerg since they commented on previous "external-facing" discussion]

Quoted 3 lines · Rajat Jain

Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" property). This however, disallows any internal devices to be marked as untrusted.

Quoted 14 lines

This isn't stated quite accurately. "dev->untrusted" is currently set only by set_pcie_untrusted(), when "dev" has an upstream bridge that is either external-facing or untrusted.

But that doesn't disallow or prevent internal devices from being marked as untrusted; it just doesn't implement that.

Quoted 7 lines

There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware, or offers an attack surface by handling untrusted network data etc).

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

#7 lore raw
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Actually Microsoft has similar already:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

#8 lore raw
Quoted 9 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Quoted 5 lines

Actually Microsoft has similar already:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

But we do not have "dma protection" for Linux, so how will that value make sense?

And shouldn't this be an ACPI standard?

thanks,

greg k-h

#9 lore raw
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Quoted 8 lines
Quoted 5 lines

Actually Microsoft has similar already:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

But we do not have "dma protection" for Linux, so how will that value make sense?

Yes I think we do - IOMMU. That's the same thing what we do now for "External Facing Ports". This one just is for internal ones.

Quoted 1 line

And shouldn't this be an ACPI standard?

Probably should or some supplemental doc but not sure how easy these "properties" can be added there to be honest.

Some of these that we use in Linux too are from that same page:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports

Namely these: HotPlugSupportInD3, ExternalFacingPort, usb4-host-interface, usb4-port-number and StorageD3Enable.

#10 lore raw
Quoted 29 lines · Mika Westerberg
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Quoted 8 lines
Quoted 5 lines

Actually Microsoft has similar already:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

But we do not have "dma protection" for Linux, so how will that value make sense?

Yes I think we do - IOMMU. That's the same thing what we do now for "External Facing Ports". This one just is for internal ones.

Quoted 1 line

And shouldn't this be an ACPI standard?

Probably should or some supplemental doc but not sure how easy these "properties" can be added there to be honest.

Quoted 6 lines

Some of these that we use in Linux too are from that same page:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports

Namely these: HotPlugSupportInD3, ExternalFacingPort, usb4-host-interface, usb4-port-number and StorageD3Enable.

Right.

We are kind of on the receiving end here, because at the time we learn about these things the decisions to use them have been made already.

author
#11 lore raw

Hello Rafael, Bjorn, Mika, Dmitry, Greg,

Thanks a lot for your comments.

Quoted 15 lines · Rafael J. Wysocki
Quoted 12 lines · Mika Westerberg
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Actually Microsoft has similar already:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

But because this property also applies to a root port (only), it only helps if the device is downstream a PCIe root port. In our case, we have an internal (wifi) device 00:14.3 (sits on the internal PCI bus 0), so cannot use this.

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

But we do not have "dma protection" for Linux, so how will that value make sense?

Yes I think we do - IOMMU. That's the same thing what we do now for "External Facing Ports". This one just is for internal ones.

Quoted 1 line

And shouldn't this be an ACPI standard?

Probably should or some supplemental doc but not sure how easy these "properties" can be added there to be honest.

AIUI, the principal comment I have received here is that this property needs to be documented somewhere. I agree.

Rafael, do you know if this new property can be added to the ACPI spec, and if so, how to do so? I'm happy to initiate a process if someone can point me to, I just hope that publishing a new property to the ACPI does not have to block this patch.

The other option I was thinking of was to use the same property name (say "untrusted-device") for both ACPI and device tree platforms, and document it in Documentation/devicetree/bindings/pci/pci.txt along with others. Since there are other properties there that seem to be used similarly (Mika highlighted some below), perhaps that is an acceptable solution?

I had one last question on the property name itself. I was trying to understand why a property might have 2 names i.e. "external-facing" for DT and "ExternalFacingPort" in ACPI? Are there any naming convention requirements that require ACPI and DT property names to be different? Is "untrusted-device" an acceptable ACPI property name?

Thanks & Best Regards,

Rajat

Quoted 12 lines
Quoted 7 lines

Some of these that we use in Linux too are from that same page:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports

Namely these: HotPlugSupportInD3, ExternalFacingPort, usb4-host-interface, usb4-port-number and StorageD3Enable.

Right.

We are kind of on the receiving end here, because at the time we learn about these things the decisions to use them have been made already.

#12 lore raw

Hi,

Quoted 22 lines · Rajat Jain

Hello Rafael, Bjorn, Mika, Dmitry, Greg,

Thanks a lot for your comments.

Quoted 17 lines · Rafael J. Wysocki
Quoted 14 lines · Mika Westerberg
Quoted 12 lines · Greg Kroah-Hartman
Quoted 11 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Actually Microsoft has similar already:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

But because this property also applies to a root port (only), it only helps if the device is downstream a PCIe root port. In our case, we have an internal (wifi) device 00:14.3 (sits on the internal PCI bus 0), so cannot use this.

Right. I wonder if we can expand it to cover all internal devices, not just PCIe root ports? We anyways need to support that property so does not make much sense to me to invent yet another that does pretty much the same thing.

author
#13 lore raw

Hi Mika, All,

Quoted 35 lines · Mika Westerberg

Hi,

Quoted 22 lines · Rajat Jain

Hello Rafael, Bjorn, Mika, Dmitry, Greg,

Thanks a lot for your comments.

Quoted 17 lines · Rafael J. Wysocki
Quoted 14 lines · Mika Westerberg
Quoted 12 lines · Greg Kroah-Hartman
Quoted 11 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Actually Microsoft has similar already:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

But because this property also applies to a root port (only), it only helps if the device is downstream a PCIe root port. In our case, we have an internal (wifi) device 00:14.3 (sits on the internal PCI bus 0), so cannot use this.

Quoted 4 lines

Right. I wonder if we can expand it to cover all internal devices, not just PCIe root ports? We anyways need to support that property so does not make much sense to me to invent yet another that does pretty much the same thing.

I'm open to doing so if the others also feel the same way. IMHO though, the semantics of ACPI "DmaProperty" differ from the semantics of the property I'm proposing here.

The current (documented) semantics (of "DmaProperty"): *This device (root port) is trusted*, but any devices downstream are not to be trusted.

What I need and am proposing (new "UntrustedDevice"): *This device as well as any downstream devices* are untrusted.

Note that there may be firmware implementing "DmaProperty" already out there (for windows), and if we decide to use it for my purposes, then there shall be a discrepancy in how Linux uses that property vs Windows. Is that acceptable?

Thanks & Best Regards,

Rajat

#14 lore raw
Quoted 53 lines · Rajat Jain

Hi Mika, All,

Quoted 35 lines · Mika Westerberg

Hi,

Quoted 22 lines · Rajat Jain

Hello Rafael, Bjorn, Mika, Dmitry, Greg,

Thanks a lot for your comments.

Quoted 17 lines · Rafael J. Wysocki
Quoted 14 lines · Mika Westerberg
Quoted 12 lines · Greg Kroah-Hartman
Quoted 11 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Actually Microsoft has similar already:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

But because this property also applies to a root port (only), it only helps if the device is downstream a PCIe root port. In our case, we have an internal (wifi) device 00:14.3 (sits on the internal PCI bus 0), so cannot use this.

Quoted 4 lines

Right. I wonder if we can expand it to cover all internal devices, not just PCIe root ports? We anyways need to support that property so does not make much sense to me to invent yet another that does pretty much the same thing.

I'm open to doing so if the others also feel the same way. IMHO though, the semantics of ACPI "DmaProperty" differ from the semantics of the property I'm proposing here.

The current (documented) semantics (of "DmaProperty"): *This device (root port) is trusted*, but any devices downstream are not to be trusted.

Quoted 7 lines

What I need and am proposing (new "UntrustedDevice"): *This device as well as any downstream devices* are untrusted.

Note that there may be firmware implementing "DmaProperty" already out there (for windows), and if we decide to use it for my purposes, then there shall be a discrepancy in how Linux uses that property vs Windows. Is that acceptable?

It may be confusing, so I'd rather not do that.

The platform firmware will use it with the Windows use case in mind and if it has side effects in Linux, problems are likely to appear in the field.

So the question is rather not about it being acceptable, but about whether or not this is generally going to work.

#15 lore raw

Hi,

Quoted 16 lines · Rafael J. Wysocki
Quoted 8 lines

I'm open to doing so if the others also feel the same way. IMHO though, the semantics of ACPI "DmaProperty" differ from the semantics of the property I'm proposing here.

The current (documented) semantics (of "DmaProperty"): *This device (root port) is trusted*, but any devices downstream are not to be trusted.

Quoted 7 lines

What I need and am proposing (new "UntrustedDevice"): *This device as well as any downstream devices* are untrusted.

Note that there may be firmware implementing "DmaProperty" already out there (for windows), and if we decide to use it for my purposes, then there shall be a discrepancy in how Linux uses that property vs Windows. Is that acceptable?

Quoted 8 lines

It may be confusing, so I'd rather not do that.

The platform firmware will use it with the Windows use case in mind and if it has side effects in Linux, problems are likely to appear in the field.

So the question is rather not about it being acceptable, but about whether or not this is generally going to work.

I was kind of implying that we could perhaps contact Microsoft and ask them if the wording could be changed to cover all the devices, not just PCIe root ports. I think this is something they will also need for things like internal WI-FI controllers.

If that's not possible then no objections adding "UntrustedDevice". We just need to deal with the "DmaProperty" anyway and both end up setting pdev->untrusted in the similar manner.

author
#16 lore raw

Hello Mika, Rafael,

Quoted 26 lines · Mika Westerberg

Hi,

Quoted 22 lines · Rafael J. Wysocki
Quoted 8 lines

I'm open to doing so if the others also feel the same way. IMHO though, the semantics of ACPI "DmaProperty" differ from the semantics of the property I'm proposing here.

The current (documented) semantics (of "DmaProperty"): *This device (root port) is trusted*, but any devices downstream are not to be trusted.

Quoted 7 lines

What I need and am proposing (new "UntrustedDevice"): *This device as well as any downstream devices* are untrusted.

Note that there may be firmware implementing "DmaProperty" already out there (for windows), and if we decide to use it for my purposes, then there shall be a discrepancy in how Linux uses that property vs Windows. Is that acceptable?

It may be confusing, so I'd rather not do that.

The platform firmware will use it with the Windows use case in mind and if it has side effects in Linux, problems are likely to appear in the field.

Quoted 7 lines
Quoted 2 lines

So the question is rather not about it being acceptable, but about whether or not this is generally going to work.

I was kind of implying that we could perhaps contact Microsoft and ask them if the wording could be changed to cover all the devices, not just PCIe root ports. I think this is something they will also need for things like internal WI-FI controllers.

We (Chromeos) do not have a contact at Microsoft, not sure if Intel does. If someone can point me to a contact I will be happy to initiate a conversation. However, given that they have already published it, and changing the semantics might mean they will also have to change windows implementation. Not sure if we have enough leverage with Microsoft here, so I wouldn't have any high hopes though. Like Rafael said, we're on the receiving end here.

Rafael, one last question: is "untrusted-device" an acceptable ACPI property name, or does it have to be Camel case?

Thanks & Best Regards,

Rajat

Quoted 4 lines

If that's not possible then no objections adding "UntrustedDevice". We just need to deal with the "DmaProperty" anyway and both end up setting pdev->untrusted in the similar manner.

author
#17 lore raw
Quoted 39 lines · Rajat Jain

Hello Mika, Rafael,

Quoted 26 lines · Mika Westerberg

Hi,

Quoted 22 lines · Rafael J. Wysocki
Quoted 8 lines

I'm open to doing so if the others also feel the same way. IMHO though, the semantics of ACPI "DmaProperty" differ from the semantics of the property I'm proposing here.

The current (documented) semantics (of "DmaProperty"): *This device (root port) is trusted*, but any devices downstream are not to be trusted.

Quoted 7 lines

What I need and am proposing (new "UntrustedDevice"): *This device as well as any downstream devices* are untrusted.

Note that there may be firmware implementing "DmaProperty" already out there (for windows), and if we decide to use it for my purposes, then there shall be a discrepancy in how Linux uses that property vs Windows. Is that acceptable?

It may be confusing, so I'd rather not do that.

The platform firmware will use it with the Windows use case in mind and if it has side effects in Linux, problems are likely to appear in the field.

Quoted 7 lines
Quoted 2 lines

So the question is rather not about it being acceptable, but about whether or not this is generally going to work.

I was kind of implying that we could perhaps contact Microsoft and ask them if the wording could be changed to cover all the devices, not just PCIe root ports. I think this is something they will also need for things like internal WI-FI controllers.

Quoted 6 lines

We (Chromeos) do not have a contact at Microsoft, not sure if Intel does. If someone can point me to a contact I will be happy to initiate a conversation. However, given that they have already published it, and changing the semantics might mean they will also have to change windows implementation. Not sure if we have enough leverage with Microsoft here, so I wouldn't have any high hopes though.

To keep everyone updated, Mika has helped me initiate a conversation with Microsoft on this (Thanks a lot Mika!). We're still waiting to hear their feedback. Until then, I've posted a v2 for review at:
https://patchwork.kernel.org/project/linux-pci/patch/[email protected]/

If we can reach an agreement with Microsoft, I can change the property name in the patch (to "DmaProperty"), but would appreciate review of any other aspects of v2 in the meantime.

Thanks & Best Regards,

Rajat

Quoted 14 lines

Like Rafael
said, we're on the receiving end here.

Rafael, one last question: is "untrusted-device" an acceptable ACPI property name, or does it have to be Camel case?

Thanks & Best Regards,

Rajat

Quoted 4 lines

If that's not possible then no objections adding "UntrustedDevice". We just need to deal with the "DmaProperty" anyway and both end up setting pdev->untrusted in the similar manner.

#18 lore raw
In reply to Rajat Jain
Quoted 20 lines · Rajat Jain
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

And shouldn't this be an ACPI standard?

Probably should or some supplemental doc but not sure how easy these "properties" can be added there to be honest.

AIUI, the principal comment I have received here is that this property needs to be documented somewhere. I agree.

Rafael, do you know if this new property can be added to the ACPI spec, and if so, how to do so? I'm happy to initiate a process if someone can point me to, I just hope that publishing a new property to the ACPI does not have to block this patch.

The other option I was thinking of was to use the same property name (say "untrusted-device") for both ACPI and device tree platforms, and document it in Documentation/devicetree/bindings/pci/pci.txt along with others. Since there are other properties there that seem to be used similarly (Mika highlighted some below), perhaps that is an acceptable solution?

Quoted 3 lines

I had one last question on the property name itself. I was trying to understand why a property might have 2 names i.e. "external-facing" for DT and "ExternalFacingPort" in ACPI?

I picked "external-facing" for DT to be consistent with other device tree property names. There doesn't seem to be any CamelCase in device trees [1], so we should probably keep that convention for new properties as well. The internal device_property could use the DT name and the ACPI name can be different. We do something similar with properties "pasid-num-bits" and "dma-can-stall" which are extracted from the IORT table in iort_named_component_init()

Thanks,
Jean

[1] git grep "\<[A-Z][,a-zA-Z0-9]\+ =" -- '*.dts'

Quoted 7 lines

Are there any naming
convention requirements that require ACPI and DT property names to be different? Is "untrusted-device" an acceptable ACPI property name?

Thanks & Best Regards,

Rajat

#19 lore raw
In reply to Mika Westerberg
Quoted 10 lines · Mika Westerberg
Quoted 7 lines · Mika Westerberg
Quoted 2 lines
Quoted 2 lines

This patch introduces a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted.

I think this new property should be documented somewhere too (also explain when to use it instead of ExternalFacingPort). If not in the next ACPI spec or some supplemental doc then perhaps in the DT bindings under Documentation/devicetree/bindings.

Quoted 5 lines

Actually Microsoft has similar already:

https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-internal-pcie-ports-accessible-to-users-and-requiring-dma-protection

I think we should use that too here.

Agreed.

This is what the platform firmware will need to use anyway for Windows compatibility and OEMs may not care about running Linux on their platforms.