1 From b82e5b9ad86533fd2b65a3966a0133d4b2d1e1da Mon Sep 17 00:00:00 2001
2 From: Benjamin Block <bblock@linux.ibm.com>
3 Date: Thu, 21 Feb 2019 10:18:00 +0100
4 Subject: scsi: core: replace GFP_ATOMIC with GFP_KERNEL in scsi_scan.c
6 [ Upstream commit 1749ef00f7312679f76d5e9104c5d1e22a829038 ]
8 We had a test-report where, under memory pressure, adding LUNs to the
9 systems would fail (the tests add LUNs strictly in sequence):
11 [ 5525.853432] scsi 0:0:1:1088045124: Direct-Access IBM 2107900 .148 PQ: 0 ANSI: 5
12 [ 5525.853826] scsi 0:0:1:1088045124: alua: supports implicit TPGS
13 [ 5525.853830] scsi 0:0:1:1088045124: alua: device naa.6005076303ffd32700000000000044da port group 0 rel port 43
14 [ 5525.853931] sd 0:0:1:1088045124: Attached scsi generic sg10 type 0
15 [ 5525.854075] sd 0:0:1:1088045124: [sdk] Disabling DIF Type 1 protection
16 [ 5525.855495] sd 0:0:1:1088045124: [sdk] 2097152 512-byte logical blocks: (1.07 GB/1.00 GiB)
17 [ 5525.855606] sd 0:0:1:1088045124: [sdk] Write Protect is off
18 [ 5525.855609] sd 0:0:1:1088045124: [sdk] Mode Sense: ed 00 00 08
19 [ 5525.855795] sd 0:0:1:1088045124: [sdk] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
20 [ 5525.857838] sdk: sdk1
21 [ 5525.859468] sd 0:0:1:1088045124: [sdk] Attached SCSI disk
22 [ 5525.865073] sd 0:0:1:1088045124: alua: transition timeout set to 60 seconds
23 [ 5525.865078] sd 0:0:1:1088045124: alua: port group 00 state A preferred supports tolusnA
24 [ 5526.015070] sd 0:0:1:1088045124: alua: port group 00 state A preferred supports tolusnA
25 [ 5526.015213] sd 0:0:1:1088045124: alua: port group 00 state A preferred supports tolusnA
26 [ 5526.587439] scsi_alloc_sdev: Allocation failure during SCSI scanning, some SCSI devices might not be configured
27 [ 5526.588562] scsi_alloc_sdev: Allocation failure during SCSI scanning, some SCSI devices might not be configured
29 Looking at the code of scsi_alloc_sdev(), and all the calling contexts,
30 there seems to be no reason to use GFP_ATMOIC here. All the different
31 call-contexts use a mutex at some point, and nothing in between that
32 requires no sleeping, as far as I could see. Additionally, the code that
33 later allocates the block queue for the device (scsi_mq_alloc_queue())
34 already uses GFP_KERNEL.
36 There are similar allocations in two other functions:
37 scsi_probe_and_add_lun(), and scsi_add_lun(),; that can also be done with
40 Here is the contexts for the three functions so far:
43 scsi_probe_and_add_lun()
44 scsi_sequential_lun_scan()
49 scsi_scan_host_selected()
51 scsi_report_lun_scan()
58 scsi_report_lun_scan()
63 scsi_probe_and_add_lun()
67 scsi_probe_and_add_lun()
70 So replace all these, and give them a bit of a better chance to succeed,
71 with more chances of reclaim.
73 Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
74 Reviewed-by: Bart Van Assche <bvanassche@acm.org>
75 Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
76 Signed-off-by: Sasha Levin <sashal@kernel.org>
78 drivers/scsi/scsi_scan.c | 6 +++---
79 1 file changed, 3 insertions(+), 3 deletions(-)
81 diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
82 index 78ca63dfba4a..9a7e3a3bd5ce 100644
83 --- a/drivers/scsi/scsi_scan.c
84 +++ b/drivers/scsi/scsi_scan.c
85 @@ -220,7 +220,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
86 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
88 sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size,
94 @@ -796,7 +796,7 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
96 sdev->inquiry = kmemdup(inq_result,
97 max_t(size_t, sdev->inquiry_len, 36),
100 if (sdev->inquiry == NULL)
101 return SCSI_SCAN_NO_RESPONSE;
103 @@ -1087,7 +1087,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
107 - result = kmalloc(result_len, GFP_ATOMIC |
108 + result = kmalloc(result_len, GFP_KERNEL |
109 ((shost->unchecked_isa_dma) ? __GFP_DMA : 0));