public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3 for-next] pvscsi: Limit ring pages for swiotlb
@ 2020-08-12 20:55 Jim Gill
  2020-08-13  7:26 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Gill @ 2020-08-12 20:55 UTC (permalink / raw)
  To: pv-drivers; +Cc: jgill, jejb, martin.petersen, linux-scsi

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.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
[jgill@vmware.com: Forwarding patch on behalf of thellstrom]
Acked-by: jgill@vmware.com
---
 drivers/scsi/vmw_pvscsi.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 0573e94..fa2748f 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -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);
-- 
2.7.4


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

* Re: [PATCH 2/3 for-next] pvscsi: Limit ring pages for swiotlb
  2020-08-12 20:55 [PATCH 2/3 for-next] pvscsi: Limit ring pages for swiotlb Jim Gill
@ 2020-08-13  7:26 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2020-08-13  7:26 UTC (permalink / raw)
  To: Jim Gill; +Cc: pv-drivers, jejb, martin.petersen, linux-scsi

On Wed, Aug 12, 2020 at 01:55:02PM -0700, Jim Gill wrote:
> 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().

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

end of thread, other threads:[~2020-08-13  7:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-12 20:55 [PATCH 2/3 for-next] pvscsi: Limit ring pages for swiotlb Jim Gill
2020-08-13  7:26 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox