Skip to contentSkip to conversation

pvscsi: Limit ring pages for swiotlb

PATCH In review Jim Gill 2 participants 2 messages Aug 12, 2020 – Aug 13, 2020

Subsystems (2)
lore
Share & tools
lore

Jim Gill

author
#0 lore raw

PATCH 2/3 pvscsi: Limit ring pages for swiotlb

A large number of outstanding scsi commands can
completely fill up the allowable DMA size. Typically this happens with SWIOTLB and SEV encryption active. While this is harmless for the scsi middle layer, it floods the kernel log with error messages and can cause other device drivers to error. Reduce the number of ring pages to 1 if we detect DMA size restrictions.

[[email protected]: Forwarding patch on behalf of thellstrom]
---
 drivers/scsi/vmw_pvscsi.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)
drivers/scsi/vmw_pvscsi.c +22 -8
index 0573e94..fa2748f 100644
@@ -28,6 +28,7 @@
 #include <linux/workqueue.h>
 #include <linux/pci.h>
 #include <linux/dmapool.h>
+#include <linux/mem_encrypt.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_host.h>
@@ -45,6 +46,7 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(PVSCSI_DRIVER_VERSION_STRING);
 
 #define PVSCSI_DEFAULT_NUM_PAGES_PER_RING	8
+#define PVSCSI_RESTRICT_NUM_PAGES_PER_RING      1
 #define PVSCSI_DEFAULT_NUM_PAGES_MSG_RING	1
 #define PVSCSI_DEFAULT_QUEUE_DEPTH		254
 #define SGL_SIZE				PAGE_SIZE
@@ -1416,14 +1418,26 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	max_id = pvscsi_get_max_targets(adapter);
 	printk(KERN_INFO "vmw_pvscsi: max_id: %u\n", max_id);
 
-	if (pvscsi_ring_pages == 0)
-		/*
-		 * Set the right default value. Up to 16 it is 8, above it is
-		 * max.
-		 */
-		pvscsi_ring_pages = (max_id > 16) ?
-			PVSCSI_SETUP_RINGS_MAX_NUM_PAGES :
-			PVSCSI_DEFAULT_NUM_PAGES_PER_RING;
+	if (pvscsi_ring_pages == 0) {
+		struct sysinfo si;
+
+		si_meminfo(&si);
+		if (mem_encrypt_active())
+			/*
+			 * There are DMA size restrictions. Reduce the queue
+			 * depth to try to avoid exhausting DMA size and trigger
+			 * dma mapping errors.
+			 */
+			pvscsi_ring_pages = PVSCSI_RESTRICT_NUM_PAGES_PER_RING;
+		else
+			/*
+			 * Set the right default value. Up to 16 it is 8,
+			 * above it is max.
+			 */
+			pvscsi_ring_pages = (max_id > 16) ?
+				PVSCSI_SETUP_RINGS_MAX_NUM_PAGES :
+				PVSCSI_DEFAULT_NUM_PAGES_PER_RING;
+	}
 	printk(KERN_INFO
 	       "vmw_pvscsi: setting ring_pages to %d\n",
 	       pvscsi_ring_pages);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · Jim Gill

A large number of outstanding scsi commands can
completely fill up the allowable DMA size. Typically this happens with SWIOTLB and SEV encryption active. While this is harmless for the scsi middle layer, it floods the kernel log with error messages and can cause other device drivers to error. Reduce the number of ring pages to 1 if we detect DMA size restrictions.

Umm, no. Drivers have absolutely no business checking mem_encrypt_active().