Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7148673ybi; Mon, 8 Jul 2019 15:37:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6pBBRr9mT7sYwEAATRSmDnwbgp35oLC/I4xxwdWuIR/0F9kaTRDQVLjQIHiWK0N1zeqDe X-Received: by 2002:a17:90a:20c6:: with SMTP id f64mr28835953pjg.57.1562625435938; Mon, 08 Jul 2019 15:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625435; cv=none; d=google.com; s=arc-20160816; b=iQSLY+lqawuSB7b/jW4WBQTzEX1Q+Y7fnbL79bAsMBsZagLYjrecFR0VMwhuYf9yMI AnzMFvcS069aUCtSfCRRdfz6/PPmSkKuWwYTtzJhZZt2YZD12vo2K+CR4j1tEEDpG0bC 3az0EFp4zfGaV5c64f/jaEyyJGx1/8Yii6szGmT2eDpokrlXo01sjQurH5ZhJ1vyP5yd lB4NcGk9sEB7jI9Hr6N78v0vbxGEdPD0HCgWN6RM8U7zQIj4xEEnqz3yB14iQfgwfqUL oZdK2A9qAskrGdHfsXZXvtC4M/a3TekT70w7naFnASC2A+rlNSZ9atNclJQP51+RYtR4 wRuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BlOSJ8CZ06gqax3lI6whSAy0Klxd6jqwryCtPEhfHaU=; b=0Uqxsb/dycZifwOayq8deyJFKlGY4m7nDHzQemVSa/6o6ftB9Mx2II/qpu4MB2LSbY HFag2cnBXYWgGBhSCabDMqvTNYj+IW076dGzFaXQhweKZJmgPFhecmrwMn1LZLxvQMYn BK27P+YqJUeEhvElzQxjsk7nobfPWcRv5AljdxoK4Tt4FTdVjRGTTtDEzehZvie+Izhk /a2sWxCeacvLoaWeEd0bF0+EaXKdQdNlFUHWyzzXP2z/J7eq4IJ4RAnl3ooYJt+wNk5r t75F/NHKlE9if7uWLnvdD0YU898bmho1/j6Zz9f5q4C/ZgtdDmlhk0tywUkVugQhf9jw +uDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lzyUuYRU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 130si2650150pfb.117.2019.07.08.15.37.01; Mon, 08 Jul 2019 15:37:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lzyUuYRU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388638AbfGHPZj (ORCPT + 99 others); Mon, 8 Jul 2019 11:25:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:53074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388621AbfGHPZg (ORCPT ); Mon, 8 Jul 2019 11:25:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49B83204EC; Mon, 8 Jul 2019 15:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599534; bh=XVuAWszYVeibjwhmGPgW2IVQzZdDJVBK+SeBtBXbb9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lzyUuYRU2paVRWcRwwVgEAw3Yo0jccYNNQ3YG9vVLsnLAQypmMqute3oNlHEgWgkG LM3h0MLWwwnz0r9ilWcN9Yl7C4hUSCeYhdPa+IWm+VPNIj8YkCntRJZoHK/eZFqpr8 8Bsvx1sIIWMilFL5QytsvNKWiQ7W2XIaw4SsxR5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Balbir Singh Subject: [PATCH 4.14 46/56] vhost: vsock: add weight support Date: Mon, 8 Jul 2019 17:13:38 +0200 Message-Id: <20190708150523.850047024@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150514.376317156@linuxfoundation.org> References: <20190708150514.376317156@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Wang commit e79b431fb901ba1106670bcc80b9b617b25def7d upstream. This patch will check the weight and exit the loop if we exceeds the weight. This is useful for preventing vsock kthread from hogging cpu which is guest triggerable. The weight can help to avoid starving the request from on direction while another direction is being processed. The value of weight is picked from vhost-net. This addresses CVE-2019-3900. Cc: Stefan Hajnoczi Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko") Signed-off-by: Jason Wang Reviewed-by: Stefan Hajnoczi Signed-off-by: Michael S. Tsirkin Signed-off-by: Balbir Singh Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vsock.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -86,6 +86,7 @@ vhost_transport_do_send_pkt(struct vhost struct vhost_virtqueue *vq) { struct vhost_virtqueue *tx_vq = &vsock->vqs[VSOCK_VQ_TX]; + int pkts = 0, total_len = 0; bool added = false; bool restart_tx = false; @@ -97,7 +98,7 @@ vhost_transport_do_send_pkt(struct vhost /* Avoid further vmexits, we're already processing the virtqueue */ vhost_disable_notify(&vsock->dev, vq); - for (;;) { + do { struct virtio_vsock_pkt *pkt; struct iov_iter iov_iter; unsigned out, in; @@ -182,8 +183,9 @@ vhost_transport_do_send_pkt(struct vhost */ virtio_transport_deliver_tap_pkt(pkt); + total_len += pkt->len; virtio_transport_free_pkt(pkt); - } + } while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len))); if (added) vhost_signal(&vsock->dev, vq); @@ -358,7 +360,7 @@ static void vhost_vsock_handle_tx_kick(s struct vhost_vsock *vsock = container_of(vq->dev, struct vhost_vsock, dev); struct virtio_vsock_pkt *pkt; - int head; + int head, pkts = 0, total_len = 0; unsigned int out, in; bool added = false; @@ -368,7 +370,7 @@ static void vhost_vsock_handle_tx_kick(s goto out; vhost_disable_notify(&vsock->dev, vq); - for (;;) { + do { u32 len; if (!vhost_vsock_more_replies(vsock)) { @@ -409,9 +411,11 @@ static void vhost_vsock_handle_tx_kick(s else virtio_transport_free_pkt(pkt); - vhost_add_used(vq, head, sizeof(pkt->hdr) + len); + len += sizeof(pkt->hdr); + vhost_add_used(vq, head, len); + total_len += len; added = true; - } + } while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len))); no_more_replies: if (added)