vhost: scsi: add weight support [Linux 3.16.72]

This Linux kernel change "vhost: scsi: add weight support" is included in the Linux 3.16.72 release. This change is authored by Jason Wang <jasowang [at] redhat.com> on Fri May 17 00:29:52 2019 -0400. The commit for this change in Linux stable tree is 6c74f68 (patch) which is from upstream commit c1ea02f. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream c1ea02f.

vhost: scsi: add weight support

commit c1ea02f15ab5efb3e93fc3144d895410bf79fcf2 upstream.

This patch will check the weight and exit the loop if we exceeds the
weight. This is useful for preventing scsi kthread from hogging cpu
which is guest triggerable.

This addresses CVE-2019-3900.

Cc: Paolo Bonzini <[email protected]>
Cc: Stefan Hajnoczi <[email protected]>
Fixes: 057cbf49a1f0 ("tcm_vhost: Initial merge for vhost level target fabric driver")
Signed-off-by: Jason Wang <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
[bwh: Backported to 3.16:
 - Drop changes in vhost_scsi_ctl_handle_vq()
 - Adjust context]
Signed-off-by: Ben Hutchings <[email protected]>

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/vhost/scsi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index fc2febf..498de4b 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -998,7 +998,7 @@ static void tcm_vhost_submission_work(struct work_struct *work)
    u64 tag;
    u32 exp_data_len, data_first, data_num, data_direction, prot_first;
    unsigned out, in, i;
-   int head, ret, data_niov, prot_niov, prot_bytes;
+   int head, ret, data_niov, prot_niov, prot_bytes, c = 0;
    size_t req_size;
    u16 lun;
    u8 *target, *lunp, task_attr;
@@ -1016,7 +1016,7 @@ static void tcm_vhost_submission_work(struct work_struct *work)

    vhost_disable_notify(&vs->dev, vq);

-   for (;;) {
+   do {
        head = vhost_get_vq_desc(vq, vq->iov,
                    ARRAY_SIZE(vq->iov), &out, &in,
                    NULL, NULL);
@@ -1219,7 +1219,7 @@ static void tcm_vhost_submission_work(struct work_struct *work)
         */
        INIT_WORK(&cmd->work, tcm_vhost_submission_work);
        queue_work(tcm_vhost_workqueue, &cmd->work);
-   }
+   } while (likely(!vhost_exceeds_weight(vq, ++c, 0)));

    mutex_unlock(&vq->mutex);
    return;

Leave a Reply

Your email address will not be published. Required fields are marked *