Skip to content

Commit 6398dd0

Browse files
mikechristiegregkh
authored andcommitted
vhost-scsi: Return queue full for page alloc failures during copy
[ Upstream commit 891b99e ] This has us return queue full if we can't allocate a page during the copy operation so the initiator can retry. Signed-off-by: Mike Christie <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 7eb29d7 commit 6398dd0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/vhost/scsi.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
762762
size_t len = iov_iter_count(iter);
763763
unsigned int nbytes = 0;
764764
struct page *page;
765-
int i;
765+
int i, ret;
766766

767767
if (cmd->tvc_data_direction == DMA_FROM_DEVICE) {
768768
cmd->saved_iter_addr = dup_iter(&cmd->saved_iter, iter,
@@ -775,15 +775,18 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
775775
page = alloc_page(GFP_KERNEL);
776776
if (!page) {
777777
i--;
778+
ret = -ENOMEM;
778779
goto err;
779780
}
780781

781782
nbytes = min_t(unsigned int, PAGE_SIZE, len);
782783
sg_set_page(&sg[i], page, nbytes, 0);
783784

784785
if (cmd->tvc_data_direction == DMA_TO_DEVICE &&
785-
copy_page_from_iter(page, 0, nbytes, iter) != nbytes)
786+
copy_page_from_iter(page, 0, nbytes, iter) != nbytes) {
787+
ret = -EFAULT;
786788
goto err;
789+
}
787790

788791
len -= nbytes;
789792
}
@@ -798,7 +801,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
798801
for (; i >= 0; i--)
799802
__free_page(sg_page(&sg[i]));
800803
kfree(cmd->saved_iter_addr);
801-
return -ENOMEM;
804+
return ret;
802805
}
803806

804807
static int
@@ -1282,9 +1285,9 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
12821285
" %d\n", cmd, exp_data_len, prot_bytes, data_direction);
12831286

12841287
if (data_direction != DMA_NONE) {
1285-
if (unlikely(vhost_scsi_mapal(cmd, prot_bytes,
1286-
&prot_iter, exp_data_len,
1287-
&data_iter))) {
1288+
ret = vhost_scsi_mapal(cmd, prot_bytes, &prot_iter,
1289+
exp_data_len, &data_iter);
1290+
if (unlikely(ret)) {
12881291
vq_err(vq, "Failed to map iov to sgl\n");
12891292
vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd);
12901293
goto err;

0 commit comments

Comments
 (0)