Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[muen/linux.git] / drivers / scsi / scsi_lib.c
index c9844043504e18de606b07e87e0fc7ccabf65920..c84f931388f226cdab2071245f7308d2c0b035b3 100644 (file)
@@ -79,14 +79,15 @@ int scsi_init_sense_cache(struct Scsi_Host *shost)
        if (shost->unchecked_isa_dma) {
                scsi_sense_isadma_cache =
                        kmem_cache_create("scsi_sense_cache(DMA)",
-                       SCSI_SENSE_BUFFERSIZE, 0,
-                       SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA, NULL);
+                               SCSI_SENSE_BUFFERSIZE, 0,
+                               SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA, NULL);
                if (!scsi_sense_isadma_cache)
                        ret = -ENOMEM;
        } else {
                scsi_sense_cache =
-                       kmem_cache_create("scsi_sense_cache",
-                       SCSI_SENSE_BUFFERSIZE, 0, SLAB_HWCACHE_ALIGN, NULL);
+                       kmem_cache_create_usercopy("scsi_sense_cache",
+                               SCSI_SENSE_BUFFERSIZE, 0, SLAB_HWCACHE_ALIGN,
+                               0, SCSI_SENSE_BUFFERSIZE, NULL);
                if (!scsi_sense_cache)
                        ret = -ENOMEM;
        }
@@ -1987,6 +1988,8 @@ static bool scsi_mq_get_budget(struct blk_mq_hw_ctx *hctx)
 out_put_device:
        put_device(&sdev->sdev_gendev);
 out:
+       if (atomic_read(&sdev->device_busy) == 0 && !scsi_device_blocked(sdev))
+               blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY);
        return false;
 }
 
@@ -2048,9 +2051,9 @@ out_put_budget:
        case BLK_STS_OK:
                break;
        case BLK_STS_RESOURCE:
-               if (atomic_read(&sdev->device_busy) == 0 &&
-                   !scsi_device_blocked(sdev))
-                       blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY);
+               if (atomic_read(&sdev->device_busy) ||
+                   scsi_device_blocked(sdev))
+                       ret = BLK_STS_DEV_RESOURCE;
                break;
        default:
                /*
@@ -2168,11 +2171,13 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
                q->limits.cluster = 0;
 
        /*
-        * set a reasonable default alignment on word boundaries: the
-        * host and device may alter it using
-        * blk_queue_update_dma_alignment() later.
+        * Set a reasonable default alignment:  The larger of 32-byte (dword),
+        * which is a common minimum for HBAs, and the minimum DMA alignment,
+        * which is set by the platform.
+        *
+        * Devices that require a bigger alignment can increase it later.
         */
-       blk_queue_dma_alignment(q, 0x03);
+       blk_queue_dma_alignment(q, max(4, dma_get_cache_alignment()) - 1);
 }
 EXPORT_SYMBOL_GPL(__scsi_init_queue);