Skip to content

Commit 891b99e

Browse files
mikechristiemstsirkin
authored andcommitted
vhost-scsi: Return queue full for page alloc failures during copy
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>
1 parent 3ca5166 commit 891b99e

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
@@ -756,7 +756,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
756756
size_t len = iov_iter_count(iter);
757757
unsigned int nbytes = 0;
758758
struct page *page;
759-
int i;
759+
int i, ret;
760760

761761
if (cmd->tvc_data_direction == DMA_FROM_DEVICE) {
762762
cmd->saved_iter_addr = dup_iter(&cmd->saved_iter, iter,
@@ -769,15 +769,18 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
769769
page = alloc_page(GFP_KERNEL);
770770
if (!page) {
771771
i--;
772+
ret = -ENOMEM;
772773
goto err;
773774
}
774775

775776
nbytes = min_t(unsigned int, PAGE_SIZE, len);
776777
sg_set_page(&sg[i], page, nbytes, 0);
777778

778779
if (cmd->tvc_data_direction == DMA_TO_DEVICE &&
779-
copy_page_from_iter(page, 0, nbytes, iter) != nbytes)
780+
copy_page_from_iter(page, 0, nbytes, iter) != nbytes) {
781+
ret = -EFAULT;
780782
goto err;
783+
}
781784

782785
len -= nbytes;
783786
}
@@ -792,7 +795,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
792795
for (; i >= 0; i--)
793796
__free_page(sg_page(&sg[i]));
794797
kfree(cmd->saved_iter_addr);
795-
return -ENOMEM;
798+
return ret;
796799
}
797800

798801
static int
@@ -1249,9 +1252,9 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
12491252
" %d\n", cmd, exp_data_len, prot_bytes, data_direction);
12501253

12511254
if (data_direction != DMA_NONE) {
1252-
if (unlikely(vhost_scsi_mapal(cmd, prot_bytes,
1253-
&prot_iter, exp_data_len,
1254-
&data_iter))) {
1255+
ret = vhost_scsi_mapal(cmd, prot_bytes, &prot_iter,
1256+
exp_data_len, &data_iter);
1257+
if (unlikely(ret)) {
12551258
vq_err(vq, "Failed to map iov to sgl\n");
12561259
vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd);
12571260
goto err;

0 commit comments

Comments
 (0)