From 941ff3c4ec793ddd9553142553f253c0c60958b8 Mon Sep 17 00:00:00 2001
From: Sergio Lopez <slp@sinrega.org>
Date: Fri, 10 Sep 2021 13:05:01 +0200
Subject: [PATCH 12/15] virtio: enable DMA API if memory is restricted

When running on a system with restricted memory access, the driver
can't have direct access to the memory. In this scenario,
automatically enable the use of the DMA API, which knows how to
operate in this context (usually by using bounce buffers).

Signed-off-by: Sergio Lopez <slp@redhat.com>
---
 drivers/virtio/virtio.c      | 6 ------
 drivers/virtio/virtio_ring.c | 4 ++++
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 3893dc29eb26..1c1821200ff4 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -180,12 +180,6 @@ static int virtio_features_ok(struct virtio_device *dev)
 				 "device must provide VIRTIO_F_VERSION_1\n");
 			return -ENODEV;
 		}
-
-		if (!virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM)) {
-			dev_warn(&dev->dev,
-				 "device must provide VIRTIO_F_ACCESS_PLATFORM\n");
-			return -ENODEV;
-		}
 	}
 
 	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index c5310eaf8b46..a41287dc476d 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -6,6 +6,7 @@
 #include <linux/virtio.h>
 #include <linux/virtio_ring.h>
 #include <linux/virtio_config.h>
+#include <linux/virtio_anchor.h>
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/module.h>
@@ -274,6 +275,9 @@ static bool vring_use_dma_api(const struct virtio_device *vdev)
 	if (!virtio_has_dma_quirk(vdev))
 		return true;
 
+	if (virtio_check_mem_acc_cb(vdev))
+		return true;
+
 	/* Otherwise, we are left to guess. */
 	/*
 	 * In theory, it's possible to have a buggy QEMU-supposed
-- 
2.40.0

