aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2015-04-13 10:21:57 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2015-04-16 01:47:25 -0400
commitc836777830428372074d5129ac513e1472c99791 (patch)
tree85165572a184002414e48a76d9b7170aab727161 /drivers/target
parent38da0f49e8aa1649af397d53f88e163d0e60c058 (diff)
target/file: Fix SG table for prot_buf initialization
In fd_do_prot_rw(), it allocates prot_buf which is used to copy from se_cmd->t_prot_sg by sbc_dif_copy_prot(). The SG table for prot_buf is also initialized by allocating 'se_cmd->t_prot_nents' entries of scatterlist and setting the data length of each entry to PAGE_SIZE at most. However if se_cmd->t_prot_sg contains a clustered entry (i.e. sg->length > PAGE_SIZE), the SG table for prot_buf can't be initialized correctly and sbc_dif_copy_prot() can't copy to prot_buf. (This actually happened with TCM loopback fabric module) As prot_buf is allocated by kzalloc() and it's physically contiguous, we only need a single scatterlist entry. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: Sagi Grimberg <sagig@mellanox.com> Cc: "Martin K. Petersen" <martin.petersen@oracle.com> Cc: Christoph Hellwig <hch@lst.de> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: <stable@vger.kernel.org> # v3.14+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r--drivers/target/target_core_file.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 3dcfc73528ec..1284fec63db8 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -264,11 +264,10 @@ static int fd_do_prot_rw(struct se_cmd *cmd, struct fd_prot *fd_prot,
264 struct se_device *se_dev = cmd->se_dev; 264 struct se_device *se_dev = cmd->se_dev;
265 struct fd_dev *dev = FD_DEV(se_dev); 265 struct fd_dev *dev = FD_DEV(se_dev);
266 struct file *prot_fd = dev->fd_prot_file; 266 struct file *prot_fd = dev->fd_prot_file;
267 struct scatterlist *sg;
268 loff_t pos = (cmd->t_task_lba * se_dev->prot_length); 267 loff_t pos = (cmd->t_task_lba * se_dev->prot_length);
269 unsigned char *buf; 268 unsigned char *buf;
270 u32 prot_size, len, size; 269 u32 prot_size;
271 int rc, ret = 1, i; 270 int rc, ret = 1;
272 271
273 prot_size = (cmd->data_length / se_dev->dev_attrib.block_size) * 272 prot_size = (cmd->data_length / se_dev->dev_attrib.block_size) *
274 se_dev->prot_length; 273 se_dev->prot_length;
@@ -281,24 +280,16 @@ static int fd_do_prot_rw(struct se_cmd *cmd, struct fd_prot *fd_prot,
281 } 280 }
282 buf = fd_prot->prot_buf; 281 buf = fd_prot->prot_buf;
283 282
284 fd_prot->prot_sg_nents = cmd->t_prot_nents; 283 fd_prot->prot_sg_nents = 1;
285 fd_prot->prot_sg = kzalloc(sizeof(struct scatterlist) * 284 fd_prot->prot_sg = kzalloc(sizeof(struct scatterlist),
286 fd_prot->prot_sg_nents, GFP_KERNEL); 285 GFP_KERNEL);
287 if (!fd_prot->prot_sg) { 286 if (!fd_prot->prot_sg) {
288 pr_err("Unable to allocate fd_prot->prot_sg\n"); 287 pr_err("Unable to allocate fd_prot->prot_sg\n");
289 kfree(fd_prot->prot_buf); 288 kfree(fd_prot->prot_buf);
290 return -ENOMEM; 289 return -ENOMEM;
291 } 290 }
292 sg_init_table(fd_prot->prot_sg, fd_prot->prot_sg_nents); 291 sg_init_table(fd_prot->prot_sg, fd_prot->prot_sg_nents);
293 size = prot_size; 292 sg_set_buf(fd_prot->prot_sg, buf, prot_size);
294
295 for_each_sg(fd_prot->prot_sg, sg, fd_prot->prot_sg_nents, i) {
296
297 len = min_t(u32, PAGE_SIZE, size);
298 sg_set_buf(sg, buf, len);
299 size -= len;
300 buf += len;
301 }
302 } 293 }
303 294
304 if (is_write) { 295 if (is_write) {