Skip to contentSkip to conversation

virtio on Type-1 hypervisor

PATCH In review Srivatsa Vaddagiri 7 participants 33 messages Apr 28, 2020 – Apr 30, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover virtio on Type-1 hypervisor

We ran into several problems in using virtio for IO paravirtualization on a Type-1 hypervisor with these characteristics:

* By default, all of a guests's memory is private to it (no other guest can access its memory).

* One of the VM is considered as primary and has access to most IO devices. This is similar to dom0 VM in case of Xen. All other VMs are considered as secondary VMs

* virtio-backend drivers for all secondary VMs need to be hosted in primary VM

* Since secondary VM's memory is not accessible to primary VM, to make virtio backend driver work, instead an additional piece of memory is provisioned by the hypervisor that is shared between primary and secondary VMs. This shared memory can be used, for example, to host virtio-ring structures and also to bounce IO buffers of secondary VM.

* Message-queue and doorbell interfaces available in hypervisor to support inter-VM communication. Messge-queue API (send/recv) allows one VM to send short messages to another VM. Doorbell interface allows a VM to inject an interrupt into another VM.

* No support for MMIO transport i.e hypervisor does not support trapping MMIO config space access by front-end driver and having it handled in backend drivers.

Few problem statements arising out of this:

1) How can we make use of the shared memory region effectively to make virtio work in this scenario?

What is proposed in the patch series for this problem is a virtio bounce driver that recognizes a shared memory region (shared between VMs) and makes use of swiotlb driver interfaces to bounce IO buffers between private and shared space. Some changes are proposed to swiotlb driver in this regard, that can let us reuse swiotlb functions to work with the shared memory pool. swiotlb driver can now recognize more than one pool of memory and extend its functions (allocate/free/bounce memory chunks) for each pool.

2) What transport mechanism works best in this case?

I realize that ivshmem2-virtio proposal has discussed the possibility of using shared memory + doorbell as a virtio transport option. We can consider using that as a transport in case it will be acceptable upstream. Other option we had considered was to modify virtio_mmio.c itself to use message_queue send/recv hypercall interface (in place of readl/writel). That could be abstracted via 'mmio_ops' structure providing suitable implementation of readl/writel. Another option suggested by Christopher Dall is to unmap the config space from kernel address space and as part of the fault handler, use hypervisor specific APIs to achieve config space IO.

3) Which virtio backend drivers to leverage?

We realized there are multiple implementations of virtio backend drivers, bundled as part of separate projects (Qemu, lkvm etc). We think it would be nice if we had some consolidation in that regard so that we can make use of the backend drivers that are not tightly coupled with a VMM. In our case, we need to be able to run virtio backend drivers as standalone programs (and not coupled with any VMM).

Srivatsa Vaddagiri (5):
swiotlb: Introduce concept of swiotlb_pool
swiotlb: Allow for non-linear mapping between paddr and vaddr
swiotlb: Add alloc and free APIs
swiotlb: Add API to register new pool
virtio: Add bounce DMA ops

 drivers/virtio/Makefile        |   2 +-
 drivers/virtio/virtio.c        |   2 +
 drivers/virtio/virtio_bounce.c | 150 +++++++++++
 drivers/xen/swiotlb-xen.c      |   4 +-
 include/linux/swiotlb.h        | 157 +++++++++++-
 include/linux/virtio.h         |   4 +
 kernel/dma/swiotlb.c           | 556 ++++++++++++++++++++++++-----------------
 7 files changed, 638 insertions(+), 237 deletions(-)
 create mode 100644 drivers/virtio/virtio_bounce.c
Signature · 5 lines
2.7.4

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH 1/5 swiotlb: Introduce concept of swiotlb_pool

Currently swiotlb driver manages a global pool of memory which acts as bounce buffers for memory that is not accessible to some devices. The core functions provides by this driver to allocate/free/bounce memory chunks will be more
useful if this driver can manage more than one pool. An immediate application of such extension to swiotlb driver is to bounce virtio buffers between private and shared space of a VM.

This patch introduces the concept of a swiotlb memory pool and reorganizes current driver to work with the default global pool. There is no functional change introduced by this patch. Subsequent patches allow the swiotlb driver to work with more than one pool of memory.

---
 drivers/xen/swiotlb-xen.c |   4 +-
 include/linux/swiotlb.h   | 129 ++++++++++++++++-
 kernel/dma/swiotlb.c      | 359 +++++++++++++++++++++++-----------------------
 3 files changed, 307 insertions(+), 185 deletions(-)
drivers/xen/swiotlb-xen.c +2 -2
index b6d2776..c2dc9c8 100644
@@ -190,8 +190,8 @@ int __ref xen_swiotlb_init(int verbose, bool early)
 	/*
 	 * IO TLB memory already allocated. Just use it.
 	 */
-	if (io_tlb_start != 0) {
-		xen_io_tlb_start = phys_to_virt(io_tlb_start);
+	if (swiotlb_start()) {
+		xen_io_tlb_start = phys_to_virt(swiotlb_start());
 		goto end;
 	}
 
include/linux/swiotlb.h +122 -7

163 lines not on this page · raw message

kernel/dma/swiotlb.c +183 -176

656 lines not on this page · raw message

Signature · 5 lines
2.7.4

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#3 lore raw

PATCH 2/5 swiotlb: Allow for non-linear mapping between paddr and vaddr

In reply to Srivatsa Vaddagiri

Some of the memory pool managed by swiotlb driver could fall outside the direct-mapped range, made accessible via memremap() routine. To facilitate easy conversion between virtual and physical address of such memory, store the virtual address of memory pool in addition to its physical address.

---
 include/linux/swiotlb.h |  2 ++
 kernel/dma/swiotlb.c    | 20 ++++++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)
include/linux/swiotlb.h +2 -0
index 8c7843f..c634b4d 100644
@@ -61,6 +61,8 @@ struct swiotlb_pool {
 
 	phys_addr_t io_tlb_start, io_tlb_end;
 
+	void *io_tlb_vstart;
+
 	/*
 	 * The number of IO TLB blocks (in groups of 64) between io_tlb_start
 	 * and io_tlb_end.  This is command line adjustable via
kernel/dma/swiotlb.c +14 -6
index 9c504d3..8cf0b57 100644
@@ -178,6 +178,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 	default_swiotlb_pool.io_tlb_start = __pa(tlb);
 	default_swiotlb_pool.io_tlb_end =
 			default_swiotlb_pool.io_tlb_start + bytes;
+	default_swiotlb_pool.io_tlb_vstart = tlb;
 
 	/*
 	 * Allocate and initialize the free list array.  This array is used
@@ -307,6 +308,7 @@ static void swiotlb_cleanup(void)
 	default_swiotlb_pool.io_tlb_start = 0;
 	default_swiotlb_pool.io_tlb_nslabs = 0;
 	default_swiotlb_pool.max_segment = 0;
+	default_swiotlb_pool.io_tlb_vstart = NULL;
 }
 
 int
@@ -320,6 +322,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	default_swiotlb_pool.io_tlb_start = virt_to_phys(tlb);
 	default_swiotlb_pool.io_tlb_end =
 			default_swiotlb_pool.io_tlb_start + bytes;
+	default_swiotlb_pool.io_tlb_vstart = tlb;
 
 	set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
 	memset(tlb, 0, bytes);
@@ -400,11 +403,10 @@ void __init swiotlb_exit(void)
 /*
  * Bounce: copy the swiotlb buffer from or back to the original dma location
  */
-static void swiotlb_bounce(phys_addr_t orig_addr, phys_addr_t tlb_addr,
+static void swiotlb_bounce(phys_addr_t orig_addr, void *vaddr,
 			   size_t size, enum dma_data_direction dir)
 {
 	unsigned long pfn = PFN_DOWN(orig_addr);
-	unsigned char *vaddr = phys_to_virt(tlb_addr);
 
 	if (PageHighMem(pfn_to_page(pfn))) {
 		/* The buffer does not have a mapping.  Map it in and copy */
@@ -437,6 +439,11 @@ static void swiotlb_bounce(phys_addr_t orig_addr, phys_addr_t tlb_addr,
 	}
 }
 
+static inline void *tlb_vaddr(struct swiotlb_pool *pool, phys_addr_t tlb_addr)
+{
+	return pool->io_tlb_vstart + (tlb_addr - pool->io_tlb_start);
+}
+
 phys_addr_t _swiotlb_tbl_map_single(struct swiotlb_pool *pool,
 				   struct device *hwdev,
 				   dma_addr_t tbl_dma_addr,
@@ -569,7 +576,7 @@ phys_addr_t _swiotlb_tbl_map_single(struct swiotlb_pool *pool,
 						(i << IO_TLB_SHIFT);
 	if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
 	    (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
-		swiotlb_bounce(orig_addr, tlb_addr,
+		swiotlb_bounce(orig_addr, tlb_vaddr(pool, tlb_addr),
 					mapping_size, DMA_TO_DEVICE);
 
 	return tlb_addr;
@@ -594,7 +601,8 @@ void _swiotlb_tbl_unmap_single(struct swiotlb_pool *pool,
 	if (orig_addr != INVALID_PHYS_ADDR &&
 	    !(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
 	    ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL)))
-		swiotlb_bounce(orig_addr, tlb_addr, mapping_size, DMA_FROM_DEVICE);
+		swiotlb_bounce(orig_addr, tlb_vaddr(pool, tlb_addr),
+						mapping_size, DMA_FROM_DEVICE);
 
 	/*
 	 * Return the buffer to the free list by setting the corresponding
@@ -643,14 +651,14 @@ void _swiotlb_tbl_sync_single(struct swiotlb_pool *pool,
 	switch (target) {
 	case SYNC_FOR_CPU:
 		if (likely(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL))
-			swiotlb_bounce(orig_addr, tlb_addr,
+			swiotlb_bounce(orig_addr, tlb_vaddr(pool, tlb_addr),
 				       size, DMA_FROM_DEVICE);
 		else
 			BUG_ON(dir != DMA_TO_DEVICE);
 		break;
 	case SYNC_FOR_DEVICE:
 		if (likely(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
-			swiotlb_bounce(orig_addr, tlb_addr,
+			swiotlb_bounce(orig_addr, tlb_vaddr(pool, tlb_addr),
 				       size, DMA_TO_DEVICE);
 		else
 			BUG_ON(dir != DMA_FROM_DEVICE);
Signature · 5 lines
2.7.4

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#4 lore raw

PATCH 3/5 swiotlb: Add alloc and free APIs

In reply to Srivatsa Vaddagiri

Move the memory allocation and free portion of swiotlb driver into independent routines. They will be useful for drivers that need swiotlb driver to just allocate/free memory chunks and not additionally bounce memory.

---
 include/linux/swiotlb.h |  17 ++++++
 kernel/dma/swiotlb.c    | 151 ++++++++++++++++++++++++++++--------------------
 2 files changed, 106 insertions(+), 62 deletions(-)
include/linux/swiotlb.h +17 -0
index c634b4d..957697e 100644
@@ -186,6 +186,10 @@ void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(void);
+extern phys_addr_t swiotlb_alloc(struct swiotlb_pool *pool, size_t alloc_size,
+		unsigned long tbl_dma_addr, unsigned long mask);
+extern void swiotlb_free(struct swiotlb_pool *pool,
+			phys_addr_t tlb_addr, size_t alloc_size);
 #else
 #define swiotlb_force SWIOTLB_NO_FORCE
 
@@ -219,6 +223,19 @@ static inline bool is_swiotlb_active(void)
 {
 	return false;
 }
+
+static inline phys_addr_t swiotlb_alloc(struct swiotlb_pool *pool,
+		size_t alloc_size, unsigned long tbl_dma_addr,
+		unsigned long mask)
+{
+	return DMA_MAPPING_ERROR;
+}
+
+static inline void swiotlb_free(struct swiotlb_pool *pool,
+			phys_addr_t tlb_addr, size_t alloc_size)
+{
+}
+
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
kernel/dma/swiotlb.c +89 -62

186 lines not on this page · raw message

Signature · 5 lines
2.7.4

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#6 lore raw

PATCH 4/5 swiotlb: Add API to register new pool

In reply to Srivatsa Vaddagiri

This patch adds an interface for the swiotlb driver to recognize a new memory pool. Upon successful initialization of the pool, swiotlb returns a handle, which needs to be passed as an argument for any future operations on the pool (map/unmap/alloc/free).

---
 include/linux/swiotlb.h |  9 ++++++++
 kernel/dma/swiotlb.c    | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
include/linux/swiotlb.h +9 -0
index 957697e..97ac82a 100644
@@ -182,6 +182,9 @@ static inline bool is_swiotlb_buffer(phys_addr_t paddr)
 	return paddr >= swiotlb_start() && paddr < swiotlb_end();
 }
 
+extern struct swiotlb_pool *swiotlb_register_pool(char *name,
+		phys_addr_t start, void *vstart, size_t size);
+
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
@@ -236,6 +239,12 @@ static inline void swiotlb_free(struct swiotlb_pool *pool,
 {
 }
 
+static struct swiotlb_pool *swiotlb_register_pool(char *name,
+		phys_addr_t start, void *vstart, size_t size)
+{
+	return NULL;
+}
+
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
kernel/dma/swiotlb.c +60 -0

72 lines not on this page · raw message

Signature · 5 lines
2.7.4

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#7 lore raw

PATCH 5/5 virtio: Add bounce DMA ops

In reply to Srivatsa Vaddagiri

For better security, its desirable that a guest VM's memory is not accessible to any entity that executes outside the context of guest VM. In case of virtio, backend drivers execute outside the context of guest VM and in general will need access to complete guest VM memory. One option to restrict the access provided to backend driver is to make use of a bounce buffer. The bounce buffer is accessible to both backend and frontend drivers. All IO buffers that are in private space of guest VM are bounced to be accessible to backend.

This patch proposes a new memory pool to be used for this bounce purpose, rather than the default swiotlb memory pool. That will avoid any conflicts that may arise in situations where a VM needs to use swiotlb pool for driving any pass-through devices (in which case swiotlb memory needs not be shared with another VM) as well as virtio devices (which will require swiotlb memory to be shared with backend VM). As a possible extension to this patch, we can provide an option for virtio to make use of default swiotlb memory pool itself, where no such conflicts may exist in a given deployment.

---
 drivers/virtio/Makefile        |   2 +-
 drivers/virtio/virtio.c        |   2 +
 drivers/virtio/virtio_bounce.c | 150 +++++++++++++++++++++++++++++++++++++++++
 include/linux/virtio.h         |   4 ++
 4 files changed, 157 insertions(+), 1 deletion(-)
 create mode 100644 drivers/virtio/virtio_bounce.c
drivers/virtio/Makefile +1 -1
index 29a1386e..3fd3515 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
+obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o virtio_bounce.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
drivers/virtio/virtio.c +2 -0
index a977e32..bc2f779 100644
@@ -329,6 +329,7 @@ int register_virtio_device(struct virtio_device *dev)
 
 	dev->index = err;
 	dev_set_name(&dev->dev, "virtio%u", dev->index);
+	virtio_bounce_set_dma_ops(dev);
 
 	spin_lock_init(&dev->config_lock);
 	dev->config_enabled = false;
@@ -431,6 +432,7 @@ EXPORT_SYMBOL_GPL(virtio_device_restore);
 
 static int virtio_init(void)
 {
+	virtio_map_bounce_buffer();
 	if (bus_register(&virtio_bus) != 0)
 		panic("virtio bus registration failed");
 	return 0;
drivers/virtio/virtio_bounce.c new file +150 -0

150 lines not on this page · raw message

include/linux/virtio.h +4 -0
index a493eac..c4970c5 100644
@@ -134,12 +134,16 @@ void virtio_config_changed(struct virtio_device *dev);
 void virtio_config_disable(struct virtio_device *dev);
 void virtio_config_enable(struct virtio_device *dev);
 int virtio_finalize_features(struct virtio_device *dev);
+int virtio_register_bounce_buffer(phys_addr_t base, size_t size);
+
 #ifdef CONFIG_PM_SLEEP
 int virtio_device_freeze(struct virtio_device *dev);
 int virtio_device_restore(struct virtio_device *dev);
 #endif
 
 size_t virtio_max_dma_size(struct virtio_device *vdev);
+extern int virtio_map_bounce_buffer(void);
+extern void virtio_bounce_set_dma_ops(struct virtio_device *dev);
 
 #define virtio_device_for_each_vq(vdev, vq) \
 	list_for_each_entry(vq, &vdev->vqs, list)
Signature · 5 lines
2.7.4

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#8 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 21 lines · Srivatsa Vaddagiri

For better security, its desirable that a guest VM's memory is not accessible to any entity that executes outside the context of guest VM. In case of virtio, backend drivers execute outside the context of guest VM and in general will need access to complete guest VM memory. One option to restrict the access provided to backend driver is to make use of a bounce buffer. The bounce buffer is accessible to both backend and frontend drivers. All IO buffers that are in private space of guest VM are bounced to be accessible to backend.

This patch proposes a new memory pool to be used for this bounce purpose, rather than the default swiotlb memory pool. That will avoid any conflicts that may arise in situations where a VM needs to use swiotlb pool for driving any pass-through devices (in which case swiotlb memory needs not be shared with another VM) as well as virtio devices (which will require swiotlb memory to be shared with backend VM). As a possible extension to this patch, we can provide an option for virtio to make use of default swiotlb memory pool itself, where no such conflicts may exist in a given deployment.

Quoted 1 line

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.
All this can then maybe be hidden behind the DMA API.

Quoted 132 lines
---
 drivers/virtio/Makefile        |   2 +-
 drivers/virtio/virtio.c        |   2 +
 drivers/virtio/virtio_bounce.c | 150 +++++++++++++++++++++++++++++++++++++++++
 include/linux/virtio.h         |   4 ++
 4 files changed, 157 insertions(+), 1 deletion(-)
 create mode 100644 drivers/virtio/virtio_bounce.c
drivers/virtio/Makefile +1 -1
index 29a1386e..3fd3515 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
+obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o virtio_bounce.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
drivers/virtio/virtio.c +2 -0
index a977e32..bc2f779 100644
@@ -329,6 +329,7 @@ int register_virtio_device(struct virtio_device *dev)
 
 	dev->index = err;
 	dev_set_name(&dev->dev, "virtio%u", dev->index);
+	virtio_bounce_set_dma_ops(dev);
 
 	spin_lock_init(&dev->config_lock);
 	dev->config_enabled = false;
@@ -431,6 +432,7 @@ EXPORT_SYMBOL_GPL(virtio_device_restore);
 
 static int virtio_init(void)
 {
+	virtio_map_bounce_buffer();
 	if (bus_register(&virtio_bus) != 0)
 		panic("virtio bus registration failed");
 	return 0;
drivers/virtio/virtio_bounce.c new file +87 -0
new file mode 100644
index 0000000..3de8e0e
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Virtio DMA ops to bounce buffers
+ *
+ *  Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * This module allows bouncing of IO buffers to a region which will be
+ * accessible to backend drivers.
+ */
+
+#include <linux/virtio.h>
+#include <linux/io.h>
+#include <linux/swiotlb.h>
+#include <linux/dma-mapping.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/of.h>
+#include <linux/of_fdt.h>
+
+static phys_addr_t bounce_buf_paddr;
+static void *bounce_buf_vaddr;
+static size_t bounce_buf_size;
+struct swiotlb_pool *virtio_pool;
+
+#define VIRTIO_MAX_BOUNCE_SIZE	(16*4096)
+
+static void *virtio_alloc_coherent(struct device *dev, size_t size,
+		dma_addr_t *dma_handle, gfp_t gfp_flags, unsigned long attrs)
+{
+	phys_addr_t addr;
+
+	if (!virtio_pool)
+		return NULL;
+
+	addr = swiotlb_alloc(virtio_pool, size, bounce_buf_paddr, ULONG_MAX);
+	if (addr == DMA_MAPPING_ERROR)
+		return NULL;
+
+	*dma_handle = (addr - bounce_buf_paddr);
+
+	return bounce_buf_vaddr + (addr - bounce_buf_paddr);
+}
+
+static void virtio_free_coherent(struct device *dev, size_t size, void *vaddr,
+		dma_addr_t dma_handle, unsigned long attrs)
+{
+	phys_addr_t addr = (dma_handle + bounce_buf_paddr);
+
+	swiotlb_free(virtio_pool, addr, size);
+}
+
+static dma_addr_t virtio_map_page(struct device *dev, struct page *page,
+		unsigned long offset, size_t size,
+		enum dma_data_direction dir, unsigned long attrs)
+{
+	void *ptr = page_address(page) + offset;
+	phys_addr_t paddr = virt_to_phys(ptr);
+	dma_addr_t handle;
+
+	if (!virtio_pool)
+		return DMA_MAPPING_ERROR;
+
+	handle = _swiotlb_tbl_map_single(virtio_pool, dev, bounce_buf_paddr,
+					 paddr, size, size, dir, attrs);
+	if (handle == (phys_addr_t)DMA_MAPPING_ERROR)
+		return DMA_MAPPING_ERROR;
+
+	return handle - bounce_buf_paddr;
+}
+
+static void virtio_unmap_page(struct device *dev, dma_addr_t dev_addr,
+		size_t size, enum dma_data_direction dir, unsigned long attrs)
+{
+	phys_addr_t addr = dev_addr + bounce_buf_paddr;
+
+	_swiotlb_tbl_unmap_single(virtio_pool, dev, addr, size,
+					size, dir, attrs);
+}
+
+size_t virtio_max_mapping_size(struct device *dev)
+{
+	return VIRTIO_MAX_BOUNCE_SIZE;
+}
+
+static const struct dma_map_ops virtio_dma_ops = {
+	.alloc			= virtio_alloc_coherent,
+	.free			= virtio_free_coherent,
+	.map_page		= virtio_map_page,

drivers/virtio/virtio_bounce.c line 97

Quoted 10 lines
drivers/virtio/virtio_bounce.c new file +10 -0
+	.unmap_page		= virtio_unmap_page,
+	.max_mapping_size	= virtio_max_mapping_size,
+};
+
+void virtio_bounce_set_dma_ops(struct virtio_device *vdev)
+{
+	if (!bounce_buf_paddr)
+		return;
+
+	set_dma_ops(vdev->dev.parent, &virtio_dma_ops);

I don't think DMA API maintainers will be happy with new users of set_dma_ops.

Quoted 80 lines
drivers/virtio/virtio_bounce.c new file +53 -0
+}
+
+int virtio_map_bounce_buffer(void)
+{
+	int ret;
+
+	if (!bounce_buf_paddr)
+		return 0;
+
+	/*
+	 * Map region as 'cacheable' memory. This will reduce access latency for
+	 * backend.
+	 */
+	bounce_buf_vaddr = memremap(bounce_buf_paddr,
+				bounce_buf_size, MEMREMAP_WB);
+	if (!bounce_buf_vaddr)
+		return -ENOMEM;
+
+	memset(bounce_buf_vaddr, 0, bounce_buf_size);
+	virtio_pool = swiotlb_register_pool("virtio_swiotlb", bounce_buf_paddr,
+				bounce_buf_vaddr, bounce_buf_size);
+	if (IS_ERR(virtio_pool)) {
+		ret = PTR_ERR(virtio_pool);
+		virtio_pool = NULL;
+		memunmap(bounce_buf_vaddr);
+		return ret;
+	}
+
+	return 0;
+}
+
+int virtio_register_bounce_buffer(phys_addr_t base, size_t size)
+{
+	if (bounce_buf_paddr || !base || size < PAGE_SIZE)
+		return -EINVAL;
+
+	bounce_buf_paddr = base;
+	bounce_buf_size = size;
+
+	return 0;
+}
+
+static int __init virtio_bounce_setup(struct reserved_mem *rmem)
+{
+	unsigned long node = rmem->fdt_node;
+
+	if (!of_get_flat_dt_prop(node, "no-map", NULL))
+		return -EINVAL;
+
+	return virtio_register_bounce_buffer(rmem->base, rmem->size);
+}
+
+RESERVEDMEM_OF_DECLARE(virtio, "virtio_bounce_pool", virtio_bounce_setup);
include/linux/virtio.h +4 -0
index a493eac..c4970c5 100644
@@ -134,12 +134,16 @@ void virtio_config_changed(struct virtio_device *dev);
 void virtio_config_disable(struct virtio_device *dev);
 void virtio_config_enable(struct virtio_device *dev);
 int virtio_finalize_features(struct virtio_device *dev);
+int virtio_register_bounce_buffer(phys_addr_t base, size_t size);
+
 #ifdef CONFIG_PM_SLEEP
 int virtio_device_freeze(struct virtio_device *dev);
 int virtio_device_restore(struct virtio_device *dev);
 #endif
 
 size_t virtio_max_dma_size(struct virtio_device *vdev);
+extern int virtio_map_bounce_buffer(void);
+extern void virtio_bounce_set_dma_ops(struct virtio_device *dev);
 
 #define virtio_device_for_each_vq(vdev, vq) \
 	list_for_each_entry(vq, &vdev->vqs, list)
Signature · 5 lines
2.7.4

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#9 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)? If so, then yes it sounds like a good application of multiple swiotlb pools.

Quoted 1 line

All this can then maybe be hidden behind the DMA API.

Won't we still need some changes to virtio to make use of its own pool (to bounce buffers)? Something similar to its own DMA ops proposed in this patch?

Quoted 10 lines

drivers/virtio/virtio_bounce.c line 97

Quoted 6 lines
drivers/virtio/virtio_bounce.c new file +6 -0
+void virtio_bounce_set_dma_ops(struct virtio_device *vdev)
+{
+	if (!bounce_buf_paddr)
+		return;
+
+	set_dma_ops(vdev->dev.parent, &virtio_dma_ops);

I don't think DMA API maintainers will be happy with new users of set_dma_ops.

Is there an alternate API that is more preffered?

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#10 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 9 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

Even a hardware iommu does not imply a 100% security from malicious hardware. First lots of people use iommu=pt for performance reasons. Second even without pt, unmaps are often batched, and sub-page buffers might be used for DMA, so we are not 100% protected at all times.

Quoted 7 lines

If so, then yes it sounds like a
good application of multiple swiotlb pools.

Quoted 1 line

All this can then maybe be hidden behind the DMA API.

Won't we still need some changes to virtio to make use of its own pool (to bounce buffers)? Something similar to its own DMA ops proposed in this patch?

If you are doing this for all devices, you need to either find a way to do this without chaning DMA ops, or by doing some automatic change to all drivers.

Quoted 11 lines
Quoted 10 lines

drivers/virtio/virtio_bounce.c line 97

Quoted 6 lines
drivers/virtio/virtio_bounce.c new file +6 -0
+void virtio_bounce_set_dma_ops(struct virtio_device *vdev)
+{
+	if (!bounce_buf_paddr)
+		return;
+
+	set_dma_ops(vdev->dev.parent, &virtio_dma_ops);

I don't think DMA API maintainers will be happy with new users of set_dma_ops.

Quoted 1 line

Is there an alternate API that is more preffered?

all this is supposed to be part of DMA API itself. new drivers aren't supposed to have custom DMA ops.

Quoted 3 lines
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#28 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Srivatsa Vaddagiri
Thank you for the patch! Perhaps something to improve:

Hi Srivatsa,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on vhost/linux-next]
[also build test WARNING on xen-tip/linux-next linus/master v5.7-rc3 next-20200428] [cannot apply to swiotlb/linux-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Srivatsa-Vaddagiri/virtio-on-Type-1-hypervisor/20200429-032334
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
config: sh-randconfig-a001-20200428 (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

In file included from drivers/virtio/virtio_bounce.c:13:
include/linux/swiotlb.h: In function 'swiotlb_alloc':
include/linux/swiotlb.h:234:9: error: 'DMA_MAPPING_ERROR' undeclared (first use in this function)

     234 |  return DMA_MAPPING_ERROR;
         |         ^~~~~~~~~~~~~~~~~
   include/linux/swiotlb.h:234:9: note: each undeclared identifier is reported only once for each function it appears in
>> include/linux/swiotlb.h:235:1: warning: control reaches end of non-void function [-Wreturn-type]
     235 | }
         | ^

vim +235 include/linux/swiotlb.h

9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28  229  
9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28  230  static inline phys_addr_t swiotlb_alloc(struct swiotlb_pool *pool,
9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28  231  		size_t alloc_size, unsigned long tbl_dma_addr,
9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28  232  		unsigned long mask)
9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28  233  {
9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28  234  	return DMA_MAPPING_ERROR;

9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28 @235 } 9ab4c39d9f9298 Srivatsa Vaddagiri 2020-04-28 236

:::::: The code at line 235 was first introduced by commit
:::::: 9ab4c39d9f929840cb884e589f6112770dbc2f63 swiotlb: Add alloc and free APIs

:::::: TO: Srivatsa Vaddagiri <[email protected]> :::::: CC: 0day robot <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#29 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Srivatsa Vaddagiri
Thank you for the patch! Yet something to improve:

Hi Srivatsa,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on vhost/linux-next]
[also build test ERROR on xen-tip/linux-next linus/master v5.7-rc3 next-20200428] [cannot apply to swiotlb/linux-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Srivatsa-Vaddagiri/virtio-on-Type-1-hypervisor/20200429-032334
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
config: s390-randconfig-a001-20200428 (attached as .config)
compiler: s390-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=s390

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/virtio/virtio_bounce.c: In function 'virtio_bounce_setup':

>> drivers/virtio/virtio_bounce.c:144:7: error: implicit declaration of function 'of_get_flat_dt_prop' [-Werror=implicit-function-declaration]
     144 |  if (!of_get_flat_dt_prop(node, "no-map", NULL))
         |       ^~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/of_get_flat_dt_prop +144 drivers/virtio/virtio_bounce.c

139
140 static int __init virtio_bounce_setup(struct reserved_mem *rmem)
141 {
142 unsigned long node = rmem->fdt_node;
143

 > 144		if (!of_get_flat_dt_prop(node, "no-map", NULL))

145 return -EINVAL;
146
147 return virtio_register_bounce_buffer(rmem->base, rmem->size);
148 }
149

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#30 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Srivatsa Vaddagiri
Quoted 9 lines · Srivatsa Vaddagiri

For better security, its desirable that a guest VM's memory is not accessible to any entity that executes outside the context of guest VM. In case of virtio, backend drivers execute outside the context of guest VM and in general will need access to complete guest VM memory. One option to restrict the access provided to backend driver is to make use of a bounce buffer. The bounce buffer is accessible to both backend and frontend drivers. All IO buffers that are in private space of guest VM are bounced to be accessible to backend.

[...]

drivers/virtio/virtio_bounce.c line 150

Quoted 11 lines
drivers/virtio/virtio_bounce.c new file +11 -0
+static int __init virtio_bounce_setup(struct reserved_mem *rmem)
+{
+	unsigned long node = rmem->fdt_node;
+
+	if (!of_get_flat_dt_prop(node, "no-map", NULL))
+		return -EINVAL;
+
+	return virtio_register_bounce_buffer(rmem->base, rmem->size);
+}
+
+RESERVEDMEM_OF_DECLARE(virtio, "virtio_bounce_pool", virtio_bounce_setup);

Is this special reserved-memory region documented somewhere?

#11 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

The trust boundary is not a good way of describing the scenario and I think it leads to miscommunication.

A better way to describe the scenario would be that the device can only DMA to/from a small reserved-memory region advertised on device tree.

Do we have other instances of devices that can only DMA to/from very specific and non-configurable address ranges? If so, this series could follow their example.

Quoted 4 lines

Even a hardware iommu does not imply a 100% security from malicious hardware. First lots of people use iommu=pt for performance reasons. Second even without pt, unmaps are often batched, and sub-page buffers might be used for DMA, so we are not 100% protected at all times.

#2 lore raw

Re: [PATCH 1/5] swiotlb: Introduce concept of swiotlb_pool

In reply to Srivatsa Vaddagiri
Thank you for the patch! Yet something to improve:

Hi Srivatsa,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on vhost/linux-next]
[also build test ERROR on xen-tip/linux-next linus/master v5.7-rc3 next-20200428] [cannot apply to swiotlb/linux-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Srivatsa-Vaddagiri/virtio-on-Type-1-hypervisor/20200429-032334
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
config: x86_64-defconfig (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/iommu/intel-iommu.c: In function 'bounce_map_single':

>> drivers/iommu/intel-iommu.c:3990:24: error: 'io_tlb_start' undeclared (first use in this function); did you mean 'swiotlb_start'?
        __phys_to_dma(dev, io_tlb_start),
                           ^~~~~~~~~~~~
                           swiotlb_start

drivers/iommu/intel-iommu.c:3990:24: note: each undeclared identifier is reported only once for each function it appears in

vim +3990 drivers/iommu/intel-iommu.c

cfb94a372f2d4e Lu Baolu     2019-09-06  3941  
cfb94a372f2d4e Lu Baolu     2019-09-06  3942  static dma_addr_t
cfb94a372f2d4e Lu Baolu     2019-09-06  3943  bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
cfb94a372f2d4e Lu Baolu     2019-09-06  3944  		  enum dma_data_direction dir, unsigned long attrs,
cfb94a372f2d4e Lu Baolu     2019-09-06  3945  		  u64 dma_mask)
cfb94a372f2d4e Lu Baolu     2019-09-06  3946  {
cfb94a372f2d4e Lu Baolu     2019-09-06  3947  	size_t aligned_size = ALIGN(size, VTD_PAGE_SIZE);
cfb94a372f2d4e Lu Baolu     2019-09-06  3948  	struct dmar_domain *domain;
cfb94a372f2d4e Lu Baolu     2019-09-06  3949  	struct intel_iommu *iommu;
cfb94a372f2d4e Lu Baolu     2019-09-06  3950  	unsigned long iova_pfn;
cfb94a372f2d4e Lu Baolu     2019-09-06  3951  	unsigned long nrpages;
cfb94a372f2d4e Lu Baolu     2019-09-06  3952  	phys_addr_t tlb_addr;
cfb94a372f2d4e Lu Baolu     2019-09-06  3953  	int prot = 0;
cfb94a372f2d4e Lu Baolu     2019-09-06  3954  	int ret;
cfb94a372f2d4e Lu Baolu     2019-09-06  3955  
a11bfde9c77df1 Joerg Roedel 2020-02-17  3956  	if (unlikely(attach_deferred(dev)))
a11bfde9c77df1 Joerg Roedel 2020-02-17  3957  		do_deferred_attach(dev);
a11bfde9c77df1 Joerg Roedel 2020-02-17  3958  
96d170f3b1a607 Joerg Roedel 2020-02-17  3959  	domain = find_domain(dev);
a11bfde9c77df1 Joerg Roedel 2020-02-17  3960  
cfb94a372f2d4e Lu Baolu     2019-09-06  3961  	if (WARN_ON(dir == DMA_NONE || !domain))
cfb94a372f2d4e Lu Baolu     2019-09-06  3962  		return DMA_MAPPING_ERROR;
cfb94a372f2d4e Lu Baolu     2019-09-06  3963  
cfb94a372f2d4e Lu Baolu     2019-09-06  3964  	iommu = domain_get_iommu(domain);
cfb94a372f2d4e Lu Baolu     2019-09-06  3965  	if (WARN_ON(!iommu))
cfb94a372f2d4e Lu Baolu     2019-09-06  3966  		return DMA_MAPPING_ERROR;
cfb94a372f2d4e Lu Baolu     2019-09-06  3967  
cfb94a372f2d4e Lu Baolu     2019-09-06  3968  	nrpages = aligned_nrpages(0, size);
cfb94a372f2d4e Lu Baolu     2019-09-06  3969  	iova_pfn = intel_alloc_iova(dev, domain,
cfb94a372f2d4e Lu Baolu     2019-09-06  3970  				    dma_to_mm_pfn(nrpages), dma_mask);
cfb94a372f2d4e Lu Baolu     2019-09-06  3971  	if (!iova_pfn)
cfb94a372f2d4e Lu Baolu     2019-09-06  3972  		return DMA_MAPPING_ERROR;
cfb94a372f2d4e Lu Baolu     2019-09-06  3973  
cfb94a372f2d4e Lu Baolu     2019-09-06  3974  	/*
cfb94a372f2d4e Lu Baolu     2019-09-06  3975  	 * Check if DMAR supports zero-length reads on write only
cfb94a372f2d4e Lu Baolu     2019-09-06  3976  	 * mappings..
cfb94a372f2d4e Lu Baolu     2019-09-06  3977  	 */
cfb94a372f2d4e Lu Baolu     2019-09-06  3978  	if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL ||
cfb94a372f2d4e Lu Baolu     2019-09-06  3979  			!cap_zlr(iommu->cap))
cfb94a372f2d4e Lu Baolu     2019-09-06  3980  		prot |= DMA_PTE_READ;
cfb94a372f2d4e Lu Baolu     2019-09-06  3981  	if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
cfb94a372f2d4e Lu Baolu     2019-09-06  3982  		prot |= DMA_PTE_WRITE;
cfb94a372f2d4e Lu Baolu     2019-09-06  3983  
cfb94a372f2d4e Lu Baolu     2019-09-06  3984  	/*
cfb94a372f2d4e Lu Baolu     2019-09-06  3985  	 * If both the physical buffer start address and size are
cfb94a372f2d4e Lu Baolu     2019-09-06  3986  	 * page aligned, we don't need to use a bounce page.
cfb94a372f2d4e Lu Baolu     2019-09-06  3987  	 */
cfb94a372f2d4e Lu Baolu     2019-09-06  3988  	if (!IS_ALIGNED(paddr | size, VTD_PAGE_SIZE)) {
cfb94a372f2d4e Lu Baolu     2019-09-06  3989  		tlb_addr = swiotlb_tbl_map_single(dev,
cfb94a372f2d4e Lu Baolu     2019-09-06 @3990  				__phys_to_dma(dev, io_tlb_start),
cfb94a372f2d4e Lu Baolu     2019-09-06  3991  				paddr, size, aligned_size, dir, attrs);
cfb94a372f2d4e Lu Baolu     2019-09-06  3992  		if (tlb_addr == DMA_MAPPING_ERROR) {
cfb94a372f2d4e Lu Baolu     2019-09-06  3993  			goto swiotlb_error;
cfb94a372f2d4e Lu Baolu     2019-09-06  3994  		} else {
cfb94a372f2d4e Lu Baolu     2019-09-06  3995  			/* Cleanup the padding area. */
cfb94a372f2d4e Lu Baolu     2019-09-06  3996  			void *padding_start = phys_to_virt(tlb_addr);
cfb94a372f2d4e Lu Baolu     2019-09-06  3997  			size_t padding_size = aligned_size;
cfb94a372f2d4e Lu Baolu     2019-09-06  3998  
cfb94a372f2d4e Lu Baolu     2019-09-06  3999  			if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
cfb94a372f2d4e Lu Baolu     2019-09-06  4000  			    (dir == DMA_TO_DEVICE ||
cfb94a372f2d4e Lu Baolu     2019-09-06  4001  			     dir == DMA_BIDIRECTIONAL)) {
cfb94a372f2d4e Lu Baolu     2019-09-06  4002  				padding_start += size;
cfb94a372f2d4e Lu Baolu     2019-09-06  4003  				padding_size -= size;
cfb94a372f2d4e Lu Baolu     2019-09-06  4004  			}
cfb94a372f2d4e Lu Baolu     2019-09-06  4005  
cfb94a372f2d4e Lu Baolu     2019-09-06  4006  			memset(padding_start, 0, padding_size);
cfb94a372f2d4e Lu Baolu     2019-09-06  4007  		}
cfb94a372f2d4e Lu Baolu     2019-09-06  4008  	} else {
cfb94a372f2d4e Lu Baolu     2019-09-06  4009  		tlb_addr = paddr;
cfb94a372f2d4e Lu Baolu     2019-09-06  4010  	}
cfb94a372f2d4e Lu Baolu     2019-09-06  4011  
cfb94a372f2d4e Lu Baolu     2019-09-06  4012  	ret = domain_pfn_mapping(domain, mm_to_dma_pfn(iova_pfn),
cfb94a372f2d4e Lu Baolu     2019-09-06  4013  				 tlb_addr >> VTD_PAGE_SHIFT, nrpages, prot);
cfb94a372f2d4e Lu Baolu     2019-09-06  4014  	if (ret)
cfb94a372f2d4e Lu Baolu     2019-09-06  4015  		goto mapping_error;
cfb94a372f2d4e Lu Baolu     2019-09-06  4016  
cfb94a372f2d4e Lu Baolu     2019-09-06  4017  	trace_bounce_map_single(dev, iova_pfn << PAGE_SHIFT, paddr, size);
cfb94a372f2d4e Lu Baolu     2019-09-06  4018  
cfb94a372f2d4e Lu Baolu     2019-09-06  4019  	return (phys_addr_t)iova_pfn << PAGE_SHIFT;
cfb94a372f2d4e Lu Baolu     2019-09-06  4020  
cfb94a372f2d4e Lu Baolu     2019-09-06  4021  mapping_error:
cfb94a372f2d4e Lu Baolu     2019-09-06  4022  	if (is_swiotlb_buffer(tlb_addr))
cfb94a372f2d4e Lu Baolu     2019-09-06  4023  		swiotlb_tbl_unmap_single(dev, tlb_addr, size,
cfb94a372f2d4e Lu Baolu     2019-09-06  4024  					 aligned_size, dir, attrs);
cfb94a372f2d4e Lu Baolu     2019-09-06  4025  swiotlb_error:
cfb94a372f2d4e Lu Baolu     2019-09-06  4026  	free_iova_fast(&domain->iovad, iova_pfn, dma_to_mm_pfn(nrpages));
cfb94a372f2d4e Lu Baolu     2019-09-06  4027  	dev_err(dev, "Device bounce map: %zx@%llx dir %d --- failed\n",
cfb94a372f2d4e Lu Baolu     2019-09-06  4028  		size, (unsigned long long)paddr, dir);
cfb94a372f2d4e Lu Baolu     2019-09-06  4029  
cfb94a372f2d4e Lu Baolu     2019-09-06  4030  	return DMA_MAPPING_ERROR;
cfb94a372f2d4e Lu Baolu     2019-09-06  4031  }
cfb94a372f2d4e Lu Baolu     2019-09-06  4032  

:::::: The code at line 3990 was first introduced by commit
:::::: cfb94a372f2d4ee226247447c863f8709863d170 iommu/vt-d: Use bounce buffer for untrusted devices

:::::: TO: Lu Baolu <[email protected]>
:::::: CC: Joerg Roedel <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#13 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Quoted 7 lines
Quoted 2 lines

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

Even a hardware iommu does not imply a 100% security from malicious hardware. First lots of people use iommu=pt for performance reasons. Second even without pt, unmaps are often batched, and sub-page buffers might be used for DMA, so we are not 100% protected at all times.

For untrusted devices, IOMMU is forced on even iommu=pt is used; and iotlb flush is in strict mode (no batched flushes); ATS is also not allowed. Swiotlb is used to protect sub-page buffers since IOMMU can only apply page granularity protection. Swiotlb is now used for devices from different trust zone.

Best regards,
baolu

#27 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin
Quoted 2 lines

Won't we still need some changes to virtio to make use of its own pool (to bounce buffers)? Something similar to its own DMA ops proposed in this patch?

If you are doing this for all devices, you need to either find a way to do this without chaning DMA ops, or by doing some automatic change to all drivers.

Ok thanks for this input. I will see how we can obfuscate this in DMA APIs itself.

Can you also comment on the virtio transport problem I cited? The hypervisor we are dealing with does not support MMIO transport. It supports message queue send/recv and also doorbell, which I think can be used if we can make some change like this to virtio_mmio.c:

+static inline u32
+virtio_readl(struct virtio_mmio_device *vm_dev, u32 reg_offset) +{
+ return vm_dev->mmio_ops->readl(vm_dev, reg_offset);
+}
+
+static inline void
+virtio_writel(struct virtio_mmio_device *vm_dev, u32 reg_offset, u32 data) +{
+ vm_dev->mmio_ops->writel(vm_dev, reg_offset, data);
+}

        /* Check magic value */

- magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
+ magic = vrito_readl(vm_dev, VIRTIO_MMIO_MAGIC_VALUE);

mmio_ops->readl on most platforms can default to readl itself, while on a platform like us, it can boil down to message_queue send/recv. Would such a change be acceptable?

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#12 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Stefano Stabellini
Quoted 6 lines · Stefano Stabellini
Quoted 2 lines
Quoted 2 lines

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

The trust boundary is not a good way of describing the scenario and I think it leads to miscommunication.

Quoted 6 lines

A better way to describe the scenario would be that the device can only DMA to/from a small reserved-memory region advertised on device tree.

Do we have other instances of devices that can only DMA to/from very specific and non-configurable address ranges? If so, this series could follow their example.

AFAICT there is no such notion in current DMA API.

static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
bool is_ram)

{
        return end <= min_not_zero(*dev->dma_mask, dev->bus_dma_limit);
}

Only the max address a device can access is defined and not a range that we seem to need here. I think we need to set the bus_dma_limit to 0 for virtio devices which will force the use of swiotlb_map API. We should also have a per-device swiotlb pool defined, so that swiotlb can use the pool meant for the given device.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#14 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Lu Baolu
Quoted 10 lines · Lu Baolu
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

Quoted 7 lines
Quoted 5 lines

Even a hardware iommu does not imply a 100% security from malicious hardware. First lots of people use iommu=pt for performance reasons. Second even without pt, unmaps are often batched, and sub-page buffers might be used for DMA, so we are not 100% protected at all times.

For untrusted devices, IOMMU is forced on even iommu=pt is used;

I think you are talking about untrusted *drivers* like with VFIO.

On the other hand, I am talking about things like thunderbolt peripherals being less trusted than on-board ones.

Or possibly even using swiotlb for specific use-cases where speed is less of an issue.

E.g. my wifi is pretty slow anyway, and that card is exposed to malicious actors all the time, put just that behind swiotlb for security, and leave my graphics card with pt since I'm trusting it with secrets anyway.

Quoted 8 lines

and
iotlb flush is in strict mode (no batched flushes); ATS is also not allowed. Swiotlb is used to protect sub-page buffers since IOMMU can only apply page granularity protection. Swiotlb is now used for devices from different trust zone.

Best regards,
baolu

#15 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Lu Baolu
Quoted 14 lines · Michael S. Tsirkin
Quoted 8 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

Even a hardware iommu does not imply a 100% security from malicious hardware. First lots of people use iommu=pt for performance reasons. Second even without pt, unmaps are often batched, and sub-page buffers might be used for DMA, so we are not 100% protected at all times.

Quoted 3 lines
Quoted 1 line

For untrusted devices, IOMMU is forced on even iommu=pt is used;

I think you are talking about untrusted *drivers* like with VFIO.

No. I am talking about untrusted devices like thunderbolt peripherals. We always trust drivers hosted in kernel and the DMA APIs are designed for them, right?

Please refer to this series.

https://lkml.org/lkml/2019/9/6/39

Best regards,
baolu

Quoted 25 lines

On the other hand, I am talking about things like thunderbolt peripherals being less trusted than on-board ones.

Or possibly even using swiotlb for specific use-cases where speed is less of an issue.

E.g. my wifi is pretty slow anyway, and that card is exposed to malicious actors all the time, put just that behind swiotlb for security, and leave my graphics card with pt since I'm trusting it with secrets anyway.

Quoted 8 lines

and
iotlb flush is in strict mode (no batched flushes); ATS is also not allowed. Swiotlb is used to protect sub-page buffers since IOMMU can only apply page granularity protection. Swiotlb is now used for devices from different trust zone.

Best regards,
baolu

#16 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 26 lines · Lu Baolu
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Lu Baolu
Quoted 14 lines · Michael S. Tsirkin
Quoted 8 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

Even a hardware iommu does not imply a 100% security from malicious hardware. First lots of people use iommu=pt for performance reasons. Second even without pt, unmaps are often batched, and sub-page buffers might be used for DMA, so we are not 100% protected at all times.

Quoted 3 lines
Quoted 1 line

For untrusted devices, IOMMU is forced on even iommu=pt is used;

I think you are talking about untrusted *drivers* like with VFIO.

No. I am talking about untrusted devices like thunderbolt peripherals. We always trust drivers hosted in kernel and the DMA APIs are designed for them, right?

Quoted 6 lines

Please refer to this series.

https://lkml.org/lkml/2019/9/6/39

Best regards,
baolu

Oh, thanks for that! I didn't realize Linux is doing this.

So it seems that with modern Linux, all one needs
to do on x86 is mark the device as untrusted.
It's already possible to do this with ACPI and with OF - would that be sufficient for achieving what this patchset is trying to do?

Adding more ways to mark a device as untrusted, and adding support for more platforms to use bounce buffers sounds like a reasonable thing to do.

Quoted 25 lines
Quoted 25 lines

On the other hand, I am talking about things like thunderbolt peripherals being less trusted than on-board ones.

Or possibly even using swiotlb for specific use-cases where speed is less of an issue.

E.g. my wifi is pretty slow anyway, and that card is exposed to malicious actors all the time, put just that behind swiotlb for security, and leave my graphics card with pt since I'm trusting it with secrets anyway.

Quoted 8 lines

and
iotlb flush is in strict mode (no batched flushes); ATS is also not allowed. Swiotlb is used to protect sub-page buffers since IOMMU can only apply page granularity protection. Swiotlb is now used for devices from different trust zone.

Best regards,
baolu

#17 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Lu Baolu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Lu Baolu
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

Okay, but how is all this virtio specific? For example, why not allow separate swiotlbs for any type of device?
For example, this might make sense if a given device is from a different, less trusted vendor.

Is swiotlb commonly used for multiple devices that may be on different trust boundaries (and not behind a hardware iommu)?

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

Even a hardware iommu does not imply a 100% security from malicious hardware. First lots of people use iommu=pt for performance reasons. Second even without pt, unmaps are often batched, and sub-page buffers might be used for DMA, so we are not 100% protected at all times.

For untrusted devices, IOMMU is forced on even iommu=pt is used;

I think you are talking about untrusted*drivers* like with VFIO.

No. I am talking about untrusted devices like thunderbolt peripherals. We always trust drivers hosted in kernel and the DMA APIs are designed for them, right?

Please refer to this series.

https://lkml.org/lkml/2019/9/6/39

Quoted 8 lines
Quoted 2 lines

Best regards,
baolu

Oh, thanks for that! I didn't realize Linux is doing this.

So it seems that with modern Linux, all one needs
to do on x86 is mark the device as untrusted.
It's already possible to do this with ACPI and with OF - would that be sufficient for achieving what this patchset is trying to do?

Yes.

Quoted 5 lines

Adding more ways to mark a device as untrusted, and adding support for more platforms to use bounce buffers sounds like a reasonable thing to do.

Agreed.

Best regards,
baolu

#18 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Michael S. Tsirkin
Quoted 4 lines · Michael S. Tsirkin

So it seems that with modern Linux, all one needs
to do on x86 is mark the device as untrusted.
It's already possible to do this with ACPI and with OF - would that be sufficient for achieving what this patchset is trying to do?

In my case, its not sufficient to just mark virtio device untrusted and thus activate the use of swiotlb. All of the secondary VM memory, including those allocate by swiotlb driver, is private to it. An additional piece of memory is available to secondary VM which is shared between VMs and which is where I need swiotlb driver to do its work.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#19 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 10 lines · Srivatsa Vaddagiri
Quoted 4 lines · Michael S. Tsirkin

So it seems that with modern Linux, all one needs
to do on x86 is mark the device as untrusted.
It's already possible to do this with ACPI and with OF - would that be sufficient for achieving what this patchset is trying to do?

In my case, its not sufficient to just mark virtio device untrusted and thus activate the use of swiotlb. All of the secondary VM memory, including those allocate by swiotlb driver, is private to it.

So why not make the bounce buffer memory shared then?

Quoted 7 lines

An additional piece of memory is
available to secondary VM which is shared between VMs and which is where I need swiotlb driver to do its work.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#20 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 4 lines

So it seems that with modern Linux, all one needs
to do on x86 is mark the device as untrusted.
It's already possible to do this with ACPI and with OF - would that be sufficient for achieving what this patchset is trying to do?

In my case, its not sufficient to just mark virtio device untrusted and thus activate the use of swiotlb. All of the secondary VM memory, including those allocate by swiotlb driver, is private to it.

So why not make the bounce buffer memory shared then?

Its a limitation by our hypervisor. When a secondary VM is created, two memory segments are allocated - one private and other shared. There is no provision for the secondary VM to make part of its private memory shared after it boots. I can perhaps consider a change in swiotlb driver to accept the second shared memory segment as its main working area (rather than allocate its own).

That would still not work I think where swiotlb is used for pass-thr devices (when private memory is fine) as well as virtio devices (when shared memory is required).

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#21 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 3 lines · Srivatsa Vaddagiri

That would still not work I think where swiotlb is used for pass-thr devices (when private memory is fine) as well as virtio devices (when shared memory is required).

So that is a separate question. When there are multiple untrusted devices, at the moment it looks like a single bounce buffer is used.

Which to me seems like a security problem, I think we should protect untrusted devices from each other.

Quoted 3 lines
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#22 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 11 lines · Michael S. Tsirkin
Quoted 3 lines · Srivatsa Vaddagiri

That would still not work I think where swiotlb is used for pass-thr devices (when private memory is fine) as well as virtio devices (when shared memory is required).

So that is a separate question. When there are multiple untrusted devices, at the moment it looks like a single bounce buffer is used.

Which to me seems like a security problem, I think we should protect untrusted devices from each other.

Definitely. That's the model we have for ivshmem-virtio as well.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#25 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin
Quoted 3 lines · Srivatsa Vaddagiri

That would still not work I think where swiotlb is used for pass-thr devices (when private memory is fine) as well as virtio devices (when shared memory is required).

So that is a separate question. When there are multiple untrusted devices, at the moment it looks like a single bounce buffer is used.

Which to me seems like a security problem, I think we should protect untrusted devices from each other.

I think as first step, let me see if we can make swiotlb driver accept a target memory segment as its working area. That may suffice our needs I think. A subsequent step could be to make swiotlb driver recognize multiple pools.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#23 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Srivatsa Vaddagiri

That would still not work I think where swiotlb is used for pass-thr devices (when private memory is fine) as well as virtio devices (when shared memory is required).

So that is a separate question. When there are multiple untrusted devices, at the moment it looks like a single bounce buffer is used.

Quoted 7 lines
Quoted 3 lines

Which to me seems like a security problem, I think we should protect untrusted devices from each other.

Definitely. That's the model we have for ivshmem-virtio as well.

Jan

Want to try implementing that?

Quoted 3 lines
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#24 lore raw

Re: [virtio-dev] Re: [PATCH 5/5] virtio: Add bounce DMA ops

Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Jan Kiszka
Quoted 11 lines · Michael S. Tsirkin
Quoted 3 lines · Srivatsa Vaddagiri

That would still not work I think where swiotlb is used for pass-thr devices (when private memory is fine) as well as virtio devices (when shared memory is required).

So that is a separate question. When there are multiple untrusted devices, at the moment it looks like a single bounce buffer is used.

Which to me seems like a security problem, I think we should protect untrusted devices from each other.

Quoted 6 lines
Quoted 3 lines

Definitely. That's the model we have for ivshmem-virtio as well.

Jan

Want to try implementing that?

The desire is definitely there, currently "just" not the time.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#31 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Srivatsa Vaddagiri
Thank you for the patch! Perhaps something to improve:

Hi Srivatsa,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on vhost/linux-next]
[also build test WARNING on xen-tip/linux-next linus/master v5.7-rc3 next-20200428] [cannot apply to swiotlb/linux-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Srivatsa-Vaddagiri/virtio-on-Type-1-hypervisor/20200429-032334
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-191-gc51a0382-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> drivers/virtio/virtio_bounce.c:22:21: sparse: sparse: symbol 'virtio_pool' was not declared. Should it be static?
>> drivers/virtio/virtio_bounce.c:79:8: sparse: sparse: symbol 'virtio_max_mapping_size' was not declared. Should it be static?

Please review and possibly fold the followup patch.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#32 lore raw

[RFC PATCH] virtio: virtio_pool can be static

In reply to Srivatsa Vaddagiri
Signed-off-by: kbuild test robot <[email protected]>
---
 virtio_bounce.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virtio/virtio_bounce.c +2 -2
index 3de8e0eb71e48..5a68d48667c42 100644
@@ -19,7 +19,7 @@
 static phys_addr_t bounce_buf_paddr;
 static void *bounce_buf_vaddr;
 static size_t bounce_buf_size;
-struct swiotlb_pool *virtio_pool;
+static struct swiotlb_pool *virtio_pool;
 
 #define VIRTIO_MAX_BOUNCE_SIZE	(16*4096)
 
@@ -76,7 +76,7 @@ static void virtio_unmap_page(struct device *dev, dma_addr_t dev_addr,
 					size, dir, attrs);
 }
 
-size_t virtio_max_mapping_size(struct device *dev)
+static size_t virtio_max_mapping_size(struct device *dev)
 {
 	return VIRTIO_MAX_BOUNCE_SIZE;
 }
#5 lore raw

Re: [PATCH 3/5] swiotlb: Add alloc and free APIs

In reply to Srivatsa Vaddagiri
Thank you for the patch! Yet something to improve:

Hi Srivatsa,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on vhost/linux-next]
[also build test ERROR on xen-tip/linux-next linus/master v5.7-rc3 next-20200429] [cannot apply to swiotlb/linux-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Srivatsa-Vaddagiri/virtio-on-Type-1-hypervisor/20200429-032334
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
config: i386-randconfig-b002-20200429 (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from drivers/gpu/drm/i915/i915_scatterlist.h:12:0,

                    from drivers/gpu/drm/i915/i915_scatterlist.c:7:
   include/linux/swiotlb.h: In function 'swiotlb_alloc':
>> include/linux/swiotlb.h:231:9: error: 'DMA_MAPPING_ERROR' undeclared (first use in this function); did you mean 'APM_NO_ERROR'?
     return DMA_MAPPING_ERROR;
            ^~~~~~~~~~~~~~~~~
            APM_NO_ERROR

include/linux/swiotlb.h:231:9: note: each undeclared identifier is reported only once for each function it appears in

vim +231 include/linux/swiotlb.h

226
227 static inline phys_addr_t swiotlb_alloc(struct swiotlb_pool *pool,
228 size_t alloc_size, unsigned long tbl_dma_addr,
229 unsigned long mask)
230 {

 > 231		return DMA_MAPPING_ERROR;

232 }
233

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#26 lore raw

Re: [PATCH 5/5] virtio: Add bounce DMA ops

In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin
Quoted 3 lines · Srivatsa Vaddagiri

That would still not work I think where swiotlb is used for pass-thr devices (when private memory is fine) as well as virtio devices (when shared memory is required).

So that is a separate question. When there are multiple untrusted devices, at the moment it looks like a single bounce buffer is used.

Which to me seems like a security problem, I think we should protect untrusted devices from each other.

There are two DMA pools code in Linux already - the TTM one for graphics and the mm/dmapool.c - could those be used instead? Or augmented at least?
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu