]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.20.16/scsi-scsi_debug-fix-write_same-with-virtual_gb-probl.patch
Linux 4.20.16
[thirdparty/kernel/stable-queue.git] / releases / 4.20.16 / scsi-scsi_debug-fix-write_same-with-virtual_gb-probl.patch
1 From a1925624dff2f9cbf1551c652b0357ab0af5c918 Mon Sep 17 00:00:00 2001
2 From: Douglas Gilbert <dgilbert@interlog.com>
3 Date: Fri, 25 Jan 2019 12:46:09 -0500
4 Subject: scsi: scsi_debug: fix write_same with virtual_gb problem
5
6 [ Upstream commit 40d07b523cf434f252b134c86b1f8f2d907ffb0b ]
7
8 The WRITE SAME(10) and (16) implementations didn't take account of the
9 buffer wrap required when the virtual_gb parameter is greater than 0.
10
11 Fix that and rename the fake_store() function to lba2fake_store() to lessen
12 confusion with the global fake_storep pointer. Bump version date.
13
14 Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
15 Reported-by: Bart Van Assche <bvanassche@acm.org>
16 Tested by: Bart Van Assche <bvanassche@acm.org>
17 Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
18 Signed-off-by: Sasha Levin <sashal@kernel.org>
19 ---
20 drivers/scsi/scsi_debug.c | 41 ++++++++++++++++++++-------------------
21 1 file changed, 21 insertions(+), 20 deletions(-)
22
23 diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
24 index 60bcc6df97a9..65305b3848bc 100644
25 --- a/drivers/scsi/scsi_debug.c
26 +++ b/drivers/scsi/scsi_debug.c
27 @@ -62,7 +62,7 @@
28
29 /* make sure inq_product_rev string corresponds to this version */
30 #define SDEBUG_VERSION "0188" /* format to fit INQUIRY revision field */
31 -static const char *sdebug_version_date = "20180128";
32 +static const char *sdebug_version_date = "20190125";
33
34 #define MY_NAME "scsi_debug"
35
36 @@ -735,7 +735,7 @@ static inline bool scsi_debug_lbp(void)
37 (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10);
38 }
39
40 -static void *fake_store(unsigned long long lba)
41 +static void *lba2fake_store(unsigned long long lba)
42 {
43 lba = do_div(lba, sdebug_store_sectors);
44
45 @@ -2514,8 +2514,8 @@ static int do_device_access(struct scsi_cmnd *scmd, u32 sg_skip, u64 lba,
46 return ret;
47 }
48
49 -/* If fake_store(lba,num) compares equal to arr(num), then copy top half of
50 - * arr into fake_store(lba,num) and return true. If comparison fails then
51 +/* If lba2fake_store(lba,num) compares equal to arr(num), then copy top half of
52 + * arr into lba2fake_store(lba,num) and return true. If comparison fails then
53 * return false. */
54 static bool comp_write_worker(u64 lba, u32 num, const u8 *arr)
55 {
56 @@ -2643,7 +2643,7 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
57 if (sdt->app_tag == cpu_to_be16(0xffff))
58 continue;
59
60 - ret = dif_verify(sdt, fake_store(sector), sector, ei_lba);
61 + ret = dif_verify(sdt, lba2fake_store(sector), sector, ei_lba);
62 if (ret) {
63 dif_errors++;
64 return ret;
65 @@ -3261,10 +3261,12 @@ static int resp_write_scat(struct scsi_cmnd *scp,
66 static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
67 u32 ei_lba, bool unmap, bool ndob)
68 {
69 + int ret;
70 unsigned long iflags;
71 unsigned long long i;
72 - int ret;
73 - u64 lba_off;
74 + u32 lb_size = sdebug_sector_size;
75 + u64 block, lbaa;
76 + u8 *fs1p;
77
78 ret = check_device_access_params(scp, lba, num);
79 if (ret)
80 @@ -3276,31 +3278,30 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
81 unmap_region(lba, num);
82 goto out;
83 }
84 -
85 - lba_off = lba * sdebug_sector_size;
86 + lbaa = lba;
87 + block = do_div(lbaa, sdebug_store_sectors);
88 /* if ndob then zero 1 logical block, else fetch 1 logical block */
89 + fs1p = fake_storep + (block * lb_size);
90 if (ndob) {
91 - memset(fake_storep + lba_off, 0, sdebug_sector_size);
92 + memset(fs1p, 0, lb_size);
93 ret = 0;
94 } else
95 - ret = fetch_to_dev_buffer(scp, fake_storep + lba_off,
96 - sdebug_sector_size);
97 + ret = fetch_to_dev_buffer(scp, fs1p, lb_size);
98
99 if (-1 == ret) {
100 write_unlock_irqrestore(&atomic_rw, iflags);
101 return DID_ERROR << 16;
102 - } else if (sdebug_verbose && !ndob && (ret < sdebug_sector_size))
103 + } else if (sdebug_verbose && !ndob && (ret < lb_size))
104 sdev_printk(KERN_INFO, scp->device,
105 "%s: %s: lb size=%u, IO sent=%d bytes\n",
106 - my_name, "write same",
107 - sdebug_sector_size, ret);
108 + my_name, "write same", lb_size, ret);
109
110 /* Copy first sector to remaining blocks */
111 - for (i = 1 ; i < num ; i++)
112 - memcpy(fake_storep + ((lba + i) * sdebug_sector_size),
113 - fake_storep + lba_off,
114 - sdebug_sector_size);
115 -
116 + for (i = 1 ; i < num ; i++) {
117 + lbaa = lba + i;
118 + block = do_div(lbaa, sdebug_store_sectors);
119 + memmove(fake_storep + (block * lb_size), fs1p, lb_size);
120 + }
121 if (scsi_debug_lbp())
122 map_region(lba, num);
123 out:
124 --
125 2.19.1
126