Skip to content

Commit a24a4fe

Browse files
mikechristieopsiff
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 <michael.christie@oracle.com> Message-Id: <20241203191705.19431-5-michael.christie@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit f5121d5ba7ce412d9e6e8287cc83b3e80c56586e)
1 parent 65c7b6c commit a24a4fe

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

drivers/vhost/scsi.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
751751
size_t len = iov_iter_count(iter);
752752
unsigned int nbytes = 0;
753753
struct page *page;
754-
int i;
754+
int i, ret;
755755

756756
if (cmd->tvc_data_direction == DMA_FROM_DEVICE) {
757757
cmd->saved_iter_addr = dup_iter(&cmd->saved_iter, iter,
@@ -764,15 +764,18 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
764764
page = alloc_page(GFP_KERNEL);
765765
if (!page) {
766766
i--;
767+
ret = -ENOMEM;
767768
goto err;
768769
}
769770

770771
nbytes = min_t(unsigned int, PAGE_SIZE, len);
771772
sg_set_page(&sg[i], page, nbytes, 0);
772773

773774
if (cmd->tvc_data_direction == DMA_TO_DEVICE &&
774-
copy_page_from_iter(page, 0, nbytes, iter) != nbytes)
775+
copy_page_from_iter(page, 0, nbytes, iter) != nbytes) {
776+
ret = -EFAULT;
775777
goto err;
778+
}
776779

777780
len -= nbytes;
778781
}
@@ -787,7 +790,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
787790
for (; i >= 0; i--)
788791
__free_page(sg_page(&sg[i]));
789792
kfree(cmd->saved_iter_addr);
790-
return -ENOMEM;
793+
return ret;
791794
}
792795

793796
static int
@@ -1226,9 +1229,9 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
12261229
" %d\n", cmd, exp_data_len, prot_bytes, data_direction);
12271230

12281231
if (data_direction != DMA_NONE) {
1229-
if (unlikely(vhost_scsi_mapal(cmd, prot_bytes,
1230-
&prot_iter, exp_data_len,
1231-
&data_iter))) {
1232+
ret = vhost_scsi_mapal(cmd, prot_bytes, &prot_iter,
1233+
exp_data_len, &data_iter);
1234+
if (unlikely(ret)) {
12321235
vq_err(vq, "Failed to map iov to sgl\n");
12331236
vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd);
12341237
goto err;

0 commit comments

Comments
 (0)