linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Fix coherence for VMbus and PCI pass-thru devices in Hyper-V VM
@ 2022-03-17 16:12 Michael Kelley
  2022-03-17 16:12 ` [PATCH 1/4] ACPI: scan: Export acpi_get_dma_attr() Michael Kelley
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michael Kelley @ 2022-03-17 16:12 UTC (permalink / raw)
  To: sthemmin, kys, haiyangz, wei.liu, decui, rafael, lenb,
	lorenzo.pieralisi, robh, kw, bhelgass, hch, m.szyprowski,
	robin.murphy, linux-acpi, linux-kernel, linux-hyperv, linux-pci,
	iommu
  Cc: mikelley

Hyper-V VMs have VMbus synthetic devices and PCI pass-thru devices that are added
dynamically via the VMbus protocol and are not represented in the ACPI DSDT. Only
the top level VMbus node exists in the DSDT. As such, on ARM64 these devices don't
pick up coherence information and default to not hardware coherent.  This results
in extra software coherence management overhead since the synthetic devices are
always hardware coherent. PCI pass-thru devices are also hardware coherent in all
current usage scenarios.

Fix this by propagating coherence information from the top level VMbus node in
the DSDT to all VMbus synthetic devices and PCI pass-thru devices. While smaller
granularity of control would be better, basing on the VMbus node in the DSDT
gives as escape path if a future scenario arises with devices that are not
hardware coherent.

The first two patches are prep to allow manipulating device coherence from a
module (since the VMbus driver can be built as a module) and from architecture
independent code without having a bunch of #ifdef's.

The third patch propagates the VMbus node coherence to VMbus synthetic devices.

The fourth patch propagates the coherence to PCI pass-thru devices.

Michael Kelley (4):
  ACPI: scan: Export acpi_get_dma_attr()
  dma-mapping: Add wrapper function to set dma_coherent
  Drivers: hv: vmbus: Propagate VMbus coherence to each VMbus device
  PCI: hv: Propagate coherence from VMbus device to PCI device

 drivers/acpi/scan.c                 |  1 +
 drivers/hv/vmbus_drv.c              | 15 +++++++++++++++
 drivers/pci/controller/pci-hyperv.c | 17 +++++++++++++----
 include/linux/dma-map-ops.h         |  9 +++++++++
 4 files changed, 38 insertions(+), 4 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] ACPI: scan: Export acpi_get_dma_attr()
  2022-03-17 16:12 [PATCH 0/4] Fix coherence for VMbus and PCI pass-thru devices in Hyper-V VM Michael Kelley
@ 2022-03-17 16:12 ` Michael Kelley
  2022-03-17 16:12 ` [PATCH 2/4] dma-mapping: Add wrapper function to set dma_coherent Michael Kelley
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Kelley @ 2022-03-17 16:12 UTC (permalink / raw)
  To: sthemmin, kys, haiyangz, wei.liu, decui, rafael, lenb,
	lorenzo.pieralisi, robh, kw, bhelgass, hch, m.szyprowski,
	robin.murphy, linux-acpi, linux-kernel, linux-hyperv, linux-pci,
	iommu
  Cc: mikelley

Export acpi_get_dma_attr() so that it can be used by the Hyper-V
VMbus driver, which may be built as a module. The related function
acpi_dma_configure_id() is already exported.

Signed-off-by: Michael Kelley <mikelley@microsoft.com>
---
 drivers/acpi/scan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 1331756..9f3c88f 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1489,6 +1489,7 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
 	else
 		return DEV_DMA_NON_COHERENT;
 }
+EXPORT_SYMBOL_GPL(acpi_get_dma_attr);
 
 /**
  * acpi_dma_get_range() - Get device DMA parameters.
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] dma-mapping: Add wrapper function to set dma_coherent
  2022-03-17 16:12 [PATCH 0/4] Fix coherence for VMbus and PCI pass-thru devices in Hyper-V VM Michael Kelley
  2022-03-17 16:12 ` [PATCH 1/4] ACPI: scan: Export acpi_get_dma_attr() Michael Kelley
@ 2022-03-17 16:12 ` Michael Kelley
  2022-03-17 16:12 ` [PATCH 3/4] Drivers: hv: vmbus: Propagate VMbus coherence to each VMbus device Michael Kelley
  2022-03-17 16:12 ` [PATCH 4/4] PCI: hv: Propagate coherence from VMbus device to PCI device Michael Kelley
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Kelley @ 2022-03-17 16:12 UTC (permalink / raw)
  To: sthemmin, kys, haiyangz, wei.liu, decui, rafael, lenb,
	lorenzo.pieralisi, robh, kw, bhelgass, hch, m.szyprowski,
	robin.murphy, linux-acpi, linux-kernel, linux-hyperv, linux-pci,
	iommu
  Cc: mikelley

Add a wrapper function to set dma_coherent, avoiding the need for
complex #ifdef's when setting it in architecture independent code.

Signed-off-by: Michael Kelley <mikelley@microsoft.com>
---
 include/linux/dma-map-ops.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 0d5b06b..3350e7a 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -254,11 +254,20 @@ static inline bool dev_is_dma_coherent(struct device *dev)
 {
 	return dev->dma_coherent;
 }
+static inline void dev_set_dma_coherent(struct device *dev,
+		bool coherent)
+{
+	dev->dma_coherent = coherent;
+}
 #else
 static inline bool dev_is_dma_coherent(struct device *dev)
 {
 	return true;
 }
+static inline void dev_set_dma_coherent(struct device *dev,
+		bool coherent)
+{
+}
 #endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */
 
 void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] Drivers: hv: vmbus: Propagate VMbus coherence to each VMbus device
  2022-03-17 16:12 [PATCH 0/4] Fix coherence for VMbus and PCI pass-thru devices in Hyper-V VM Michael Kelley
  2022-03-17 16:12 ` [PATCH 1/4] ACPI: scan: Export acpi_get_dma_attr() Michael Kelley
  2022-03-17 16:12 ` [PATCH 2/4] dma-mapping: Add wrapper function to set dma_coherent Michael Kelley
@ 2022-03-17 16:12 ` Michael Kelley
  2022-03-17 16:12 ` [PATCH 4/4] PCI: hv: Propagate coherence from VMbus device to PCI device Michael Kelley
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Kelley @ 2022-03-17 16:12 UTC (permalink / raw)
  To: sthemmin, kys, haiyangz, wei.liu, decui, rafael, lenb,
	lorenzo.pieralisi, robh, kw, bhelgass, hch, m.szyprowski,
	robin.murphy, linux-acpi, linux-kernel, linux-hyperv, linux-pci,
	iommu
  Cc: mikelley

VMbus synthetic devices are not represented in the ACPI DSDT -- only
the top level VMbus device is represented. As a result, on ARM64
coherence information in the _CCA method is not specified for
synthetic devices, so they default to not hardware coherent.
Drivers for some of these synthetic devices have been recently
updated to use the standard DMA APIs, and they are incurring extra
overhead of unneeded software coherence management.

Fix this by propagating coherence information from the VMbus node
in ACPI to the individual synthetic devices. There's no effect on
x86/x64 where devices are always hardware coherent.

Signed-off-by: Michael Kelley <mikelley@microsoft.com>
---
 drivers/hv/vmbus_drv.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 12a2b37..c0e993ad 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -904,6 +904,21 @@ static int vmbus_probe(struct device *child_device)
 			drv_to_hv_drv(child_device->driver);
 	struct hv_device *dev = device_to_hv_device(child_device);
 	const struct hv_vmbus_device_id *dev_id;
+	enum dev_dma_attr coherent;
+
+	/*
+	 * On ARM64, propagate the DMA coherence setting from the top level
+	 * VMbus ACPI device to the child VMbus device being added here.
+	 * Older Hyper-V ARM64 versions don't set the _CCA method on the
+	 * top level VMbus ACPI device as they should.  Treat these cases
+	 * as DMA coherent since that's the assumption made by Hyper-V.
+	 *
+	 * On x86/x64 these calls assume coherence and have no effect.
+	 */
+	coherent = acpi_get_dma_attr(hv_acpi_dev);
+	if (coherent == DEV_DMA_NOT_SUPPORTED)
+		coherent = DEV_DMA_COHERENT;
+	acpi_dma_configure(child_device, coherent);
 
 	dev_id = hv_vmbus_get_id(drv, dev);
 	if (drv->probe) {
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] PCI: hv: Propagate coherence from VMbus device to PCI device
  2022-03-17 16:12 [PATCH 0/4] Fix coherence for VMbus and PCI pass-thru devices in Hyper-V VM Michael Kelley
                   ` (2 preceding siblings ...)
  2022-03-17 16:12 ` [PATCH 3/4] Drivers: hv: vmbus: Propagate VMbus coherence to each VMbus device Michael Kelley
@ 2022-03-17 16:12 ` Michael Kelley
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Kelley @ 2022-03-17 16:12 UTC (permalink / raw)
  To: sthemmin, kys, haiyangz, wei.liu, decui, rafael, lenb,
	lorenzo.pieralisi, robh, kw, bhelgass, hch, m.szyprowski,
	robin.murphy, linux-acpi, linux-kernel, linux-hyperv, linux-pci,
	iommu
  Cc: mikelley

PCI pass-thru devices in a Hyper-V VM are represented as a VMBus
device and as a PCI device.  The coherence of the VMbus device is
set based on the VMbus node in ACPI, but the PCI device has no
ACPI node and defaults to not hardware coherent.  This results
in extra software coherence management overhead on ARM64 when
devices are hardware coherent.

Fix this by propagating the coherence of the VMbus device to the
PCI device.  There's no effect on x86/x64 where devices are
always hardware coherent.

Signed-off-by: Michael Kelley <mikelley@microsoft.com>
---
 drivers/pci/controller/pci-hyperv.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index ae0bc2f..14276f5 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -49,6 +49,7 @@
 #include <linux/refcount.h>
 #include <linux/irqdomain.h>
 #include <linux/acpi.h>
+#include <linux/dma-map-ops.h>
 #include <asm/mshyperv.h>
 
 /*
@@ -2142,9 +2143,9 @@ static void hv_pci_remove_slots(struct hv_pcibus_device *hbus)
 }
 
 /*
- * Set NUMA node for the devices on the bus
+ * Set NUMA node and DMA coherence for the devices on the bus
  */
-static void hv_pci_assign_numa_node(struct hv_pcibus_device *hbus)
+static void hv_pci_assign_properties(struct hv_pcibus_device *hbus)
 {
 	struct pci_dev *dev;
 	struct pci_bus *bus = hbus->bridge->bus;
@@ -2167,6 +2168,14 @@ static void hv_pci_assign_numa_node(struct hv_pcibus_device *hbus)
 				     numa_map_to_online_node(
 					     hv_dev->desc.virtual_numa_node));
 
+		/*
+		 * On ARM64, propagate the DMA coherence from the VMbus device
+		 * to the corresponding PCI device. On x86/x64, these calls
+		 * have no effect because DMA is always hardware coherent.
+		 */
+		dev_set_dma_coherent(&dev->dev,
+			dev_is_dma_coherent(&hbus->hdev->device));
+
 		put_pcichild(hv_dev);
 	}
 }
@@ -2191,7 +2200,7 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus)
 		return error;
 
 	pci_lock_rescan_remove();
-	hv_pci_assign_numa_node(hbus);
+	hv_pci_assign_properties(hbus);
 	pci_bus_assign_resources(bridge->bus);
 	hv_pci_assign_slots(hbus);
 	pci_bus_add_devices(bridge->bus);
@@ -2458,7 +2467,7 @@ static void pci_devices_present_work(struct work_struct *work)
 		 */
 		pci_lock_rescan_remove();
 		pci_scan_child_bus(hbus->bridge->bus);
-		hv_pci_assign_numa_node(hbus);
+		hv_pci_assign_properties(hbus);
 		hv_pci_assign_slots(hbus);
 		pci_unlock_rescan_remove();
 		break;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-17 16:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-17 16:12 [PATCH 0/4] Fix coherence for VMbus and PCI pass-thru devices in Hyper-V VM Michael Kelley
2022-03-17 16:12 ` [PATCH 1/4] ACPI: scan: Export acpi_get_dma_attr() Michael Kelley
2022-03-17 16:12 ` [PATCH 2/4] dma-mapping: Add wrapper function to set dma_coherent Michael Kelley
2022-03-17 16:12 ` [PATCH 3/4] Drivers: hv: vmbus: Propagate VMbus coherence to each VMbus device Michael Kelley
2022-03-17 16:12 ` [PATCH 4/4] PCI: hv: Propagate coherence from VMbus device to PCI device Michael Kelley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).