Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1007624ybt; Fri, 19 Jun 2020 21:25:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY7h1B4C3jzXbPxlFBeZbEMXkmTFctlpmoRlimnlynciETTVdR4Vw/dDNrAllYZXcVNrJb X-Received: by 2002:a17:906:2e4b:: with SMTP id r11mr1116256eji.227.1592627114695; Fri, 19 Jun 2020 21:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592627114; cv=none; d=google.com; s=arc-20160816; b=tOk2qZq4Ube7DONdYNMvoqkcytZpwcAwxGaZG3v5Pdrl8oJSz27R/41LUphfUnjdQ1 Ooh2IP0EYmfzbOcVj3PZ1TLPeDqtGW5DHQee7u0bzG5/nRaQjJv3GdWKUZP5YS5yo7D6 VJOfzYGMdErjMYi5JHJak7kmw3E/U3jK2iON14mF2oU4Zfik18eIWQVSR+OjRg4sIDPn jnDuPXPzf+1nA5ATyg3NWVcBA43RUJ6JMY0MHDhhXOa8LZ1zY5mjGyYDm074LWFU5ZqJ rcC7H3/FKFRQb3R+NMH88gLHwvte65Y8Z2ivJN9joaQLOvslZfnWDIktQC8pGVWJCxUA 7lsw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qkSO6uAew6y5ogpj/Gk8Z9+bhI6aspDyhTULUBQkJkA=; b=i+tVkZ/46e2nEJvByuriJUkJHdQC2qDcExNB+kMPMDUEASILETPaFNgfCqtMp3jLh1 1IUOF5k+yETutXDv6dokSvI3O6FKpAj5QFHOz9aigkA9aWgChv1w3wbLjC4aF/mfOEyT lOgV1S1POqjvb5OP17XZq0aJSgSNypFGGK2/ZrVWBftcZJgpfTZklngsPIA/QCfU0C/P 7jiE81ibZ65Md6sW0t2RMZQRosJJBF2MFN3Cc1cK1FGklePRnr2OLTMMyC6joLl9hxjG gsaBFpG7ygDIIZQe1KQRSg0wM5MkDnXZbPN2ACkIjR0Vck/BxM0HmZROXZxiHrtXQ43W WVCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MTXeeE3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k19si1051140ejc.167.2020.06.19.21.24.52; Fri, 19 Jun 2020 21:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MTXeeE3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436627AbgFSSYS (ORCPT + 99 others); Fri, 19 Jun 2020 14:24:18 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:28719 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2405783AbgFSSXq (ORCPT ); Fri, 19 Jun 2020 14:23:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592591025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qkSO6uAew6y5ogpj/Gk8Z9+bhI6aspDyhTULUBQkJkA=; b=MTXeeE3Hq9eDG/V8DYhTY4eAKtb8HUPITc/c+RyMGpCrDC4Qi2ew6I2ZbbRUXTUkF1ZidP uq5HAjPvgqw+lHOgvqoMd0W0l5MUk8E8/B6oaR1IIqCfCsNqzjhHCPGtzFjbKz2JqtxhLc JSwVF6qkGCzA7fR9/uVPQU54ExORO1U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-dJw4fSr5P9ej4gAyiHZ2Ww-1; Fri, 19 Jun 2020 14:23:42 -0400 X-MC-Unique: dJw4fSr5P9ej4gAyiHZ2Ww-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDA1F835B8E; Fri, 19 Jun 2020 18:23:41 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-14.ams2.redhat.com [10.36.113.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id D91011C8; Fri, 19 Jun 2020 18:23:39 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: mst@redhat.com Cc: kvm list , Stefano Garzarella , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Stefan Hajnoczi , Jason Wang Subject: [RFC v9 10/11] vhost/vsock: switch to the buf API Date: Fri, 19 Jun 2020 20:23:01 +0200 Message-Id: <20200619182302.850-11-eperezma@redhat.com> In-Reply-To: <20200619182302.850-1-eperezma@redhat.com> References: <20200619182302.850-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Michael S. Tsirkin" A straight-forward conversion. Signed-off-by: Michael S. Tsirkin Signed-off-by: Eugenio PĂ©rez --- drivers/vhost/vsock.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index a483cec31d5c..61c6d3dd2ae3 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -103,7 +103,8 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, unsigned out, in; size_t nbytes; size_t iov_len, payload_len; - int head; + struct vhost_buf buf; + int ret; spin_lock_bh(&vsock->send_pkt_list_lock); if (list_empty(&vsock->send_pkt_list)) { @@ -117,16 +118,17 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, list_del_init(&pkt->list); spin_unlock_bh(&vsock->send_pkt_list_lock); - head = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov), - &out, &in, NULL, NULL); - if (head < 0) { + ret = vhost_get_avail_buf(vq, &buf, + vq->iov, ARRAY_SIZE(vq->iov), + &out, &in, NULL, NULL); + if (ret < 0) { spin_lock_bh(&vsock->send_pkt_list_lock); list_add(&pkt->list, &vsock->send_pkt_list); spin_unlock_bh(&vsock->send_pkt_list_lock); break; } - if (head == vq->num) { + if (!ret) { spin_lock_bh(&vsock->send_pkt_list_lock); list_add(&pkt->list, &vsock->send_pkt_list); spin_unlock_bh(&vsock->send_pkt_list_lock); @@ -186,7 +188,8 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, */ virtio_transport_deliver_tap_pkt(pkt); - vhost_add_used(vq, head, sizeof(pkt->hdr) + payload_len); + buf.in_len = sizeof(pkt->hdr) + payload_len; + vhost_put_used_buf(vq, &buf); added = true; pkt->off += payload_len; @@ -440,7 +443,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) struct vhost_vsock *vsock = container_of(vq->dev, struct vhost_vsock, dev); struct virtio_vsock_pkt *pkt; - int head, pkts = 0, total_len = 0; + int ret, pkts = 0, total_len = 0; + struct vhost_buf buf; unsigned int out, in; bool added = false; @@ -461,12 +465,13 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) goto no_more_replies; } - head = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov), - &out, &in, NULL, NULL); - if (head < 0) + ret = vhost_get_avail_buf(vq, &buf, + vq->iov, ARRAY_SIZE(vq->iov), + &out, &in, NULL, NULL); + if (ret < 0) break; - if (head == vq->num) { + if (!ret) { if (unlikely(vhost_enable_notify(&vsock->dev, vq))) { vhost_disable_notify(&vsock->dev, vq); continue; @@ -494,7 +499,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) virtio_transport_free_pkt(pkt); len += sizeof(pkt->hdr); - vhost_add_used(vq, head, len); + buf.in_len = len; + vhost_put_used_buf(vq, &buf); total_len += len; added = true; } while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len))); -- 2.18.1