Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp389425pxb; Mon, 13 Sep 2021 22:57:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykfHAGbt5r2IKL85Rtsnc4+OyaGNC3X3tdoKgOIAVQPP3hhZ5GibpiXxdUAiOB02Q8hEPI X-Received: by 2002:a05:6402:299:: with SMTP id l25mr17131961edv.343.1631599039654; Mon, 13 Sep 2021 22:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631599039; cv=none; d=google.com; s=arc-20160816; b=0h3FwIpCetM5DtiyjD87s59vzAdq37i7ylK1jIAErpMJ+a79E6lnZ82COE5Ay+OBE6 I7CVFz6++uobKJxQOnmmUl2d0jjTDq8Ll1AhkcfGaWLbU/dRXWXwFIztoThpfFc12I+/ 5XkXd8khlMFUsHNxQww0DOXGoASAlM01fBCckzNEND6mln8GFqGUT/2vIJMRB3bKB8XU mZH2i9pZsm24q9UNEH7qSD1apKm6SQIh7DvcUo1EvR7dYQFnEd6+LMpd3laX/BQoNVcQ zoW9qwWP9dbqj/zQAooeE5R3vndcgzgRbokbbSucOkBm6c9FmURrG8mG31e7gKUQK/6O ogPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fcrREBHmUss8HUTYx3tNLzB0BZ/FP/l7HKKTmPrsNB0=; b=J7mcY3NhgYDZaERR7FOdJdzFtz/lwNJ3gem6BJ2w9gadLXFMU0D1KeBE/x5iP2HOM1 QMIIIhtdOz3L/7EpydsC9hAEYk4yEp4pjXpBkUXK+6dT+vz1pw0t590D8nrYQdLqphiT X46vs3+NLq9Lq+PvthXPFRJUclnwz7TWBDStGfLAzRezvSciRNEth5PVwfOvK81mbw+h vD4fo+rkoFNSOw3erVVE5hHOktpYID2JDUkoSvmFX3iFYbEIxpeBGrRJWgyOg2ikY7uo hFAL0eR3grrfrAwm0D3ifPazqn02iPQgQhTrllePlO5KA0pnFcAdjSuRcWIDo8U3bq1n 9l7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=g8225Mo4; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si9294137edt.384.2021.09.13.22.56.56; Mon, 13 Sep 2021 22:57:19 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=g8225Mo4; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239985AbhINF4q (ORCPT + 99 others); Tue, 14 Sep 2021 01:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239912AbhINF4k (ORCPT ); Tue, 14 Sep 2021 01:56:40 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFA7BC061766 for ; Mon, 13 Sep 2021 22:55:23 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id m26so11147811pff.3 for ; Mon, 13 Sep 2021 22:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fcrREBHmUss8HUTYx3tNLzB0BZ/FP/l7HKKTmPrsNB0=; b=g8225Mo4a48P+CZC64h/29+Mrj5CMYapoXxB6t3Q8hqT/hIbf/ybQ/zOm1Mj1DCdzR AGqxPG34/pJm+uVVr3VYNgwu0O8oJkCJ1IJQ7KxQcnHGX/XvOZOQ9/rzx1MXKBzRjVO2 2zFCnzovaRErZIMGVpBYTCcqb2nCdMooQyq6U9DQkFDOUoNOdW2G/aRsZ5l5fVR87FO7 3VBB8kJ7j0d5Ggk8bEqPYA0JNtgn/DgV9GZPIg+DOVzM+BIGIcdBwZPZ1vglavSpaoFC xYjW/V0yLUaZ7G/TYw6MiryPR4CHi8EKzVH4T1zFKpISXVI/Eu8WO1GsMgPgLoK3Y+Js 73Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fcrREBHmUss8HUTYx3tNLzB0BZ/FP/l7HKKTmPrsNB0=; b=p7wOPBLsqYxAO4VdYJXgXPrjHmb168lu+jzy14cyNtKhJUc0G1P4yKEw5XNrH+Y4jO qD7Atwc5iS2xX5yajAw1J6ACgifJMI/flHqDE+pj7CcYruMamDR1j0r7SYI8xTmgrPQh 2QpjWrPgv6A5+Jqd+CGwk+VTNgLJvyuPCkgEVVvSQMflbCQoFyiV401dUs5UiORg0tYT t0COqqkYSEzMeu8/TniUZ05DIdxcQYniP6SZR+tI3P6eg29Hf2ivYI/OvUMdQ6moYV78 3XnsC11HYH6kOa282FYu18hJ+i8iv4BT42IwTZ632YLwtB5JJmdXRaE9Oh9cYgL6XQTV c1Iw== X-Gm-Message-State: AOAM531p990NE4yJl2FTGzOs1chwPUMnV/0NSys+XAD3o7nwoeTEUp8W ejqvpnP65My0keaWZRWjsA6R6g== X-Received: by 2002:a63:ec06:: with SMTP id j6mr14261115pgh.259.1631598923320; Mon, 13 Sep 2021 22:55:23 -0700 (PDT) Received: from ip-10-124-121-13.byted.org (ec2-54-241-92-238.us-west-1.compute.amazonaws.com. [54.241.92.238]) by smtp.gmail.com with ESMTPSA id v14sm719432pfi.111.2021.09.13.22.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 22:55:22 -0700 (PDT) From: Jiang Wang To: jiangleetcode@gmail.com Cc: virtualization@lists.linux-foundation.org, stefanha@redhat.com, sgarzare@redhat.com, mst@redhat.com, arseny.krasnov@kaspersky.com, jhansen@vmware.com, cong.wang@bytedance.com, duanxiongchun@bytedance.com, xieyongji@bytedance.com, chaiwen.cc@bytedance.com, Jason Wang , "David S. Miller" , Jakub Kicinski , Steven Rostedt , Ingo Molnar , kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 1/5] virtio/vsock: add VIRTIO_VSOCK_F_DGRAM feature bit Date: Tue, 14 Sep 2021 05:54:34 +0000 Message-Id: <20210914055440.3121004-2-jiang.wang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210914055440.3121004-1-jiang.wang@bytedance.com> References: <20210914055440.3121004-1-jiang.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When this feature is enabled, allocate 5 queues, otherwise, allocate 3 queues to be compatible with old QEMU versions. Signed-off-by: Jiang Wang --- drivers/vhost/vsock.c | 3 +- include/linux/virtio_vsock.h | 9 ++++ include/uapi/linux/virtio_vsock.h | 2 + net/vmw_vsock/virtio_transport.c | 79 +++++++++++++++++++++++++++---- 4 files changed, 82 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index f249622ef11b..c79789af0365 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -32,7 +32,8 @@ enum { VHOST_VSOCK_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_F_ACCESS_PLATFORM) | - (1ULL << VIRTIO_VSOCK_F_SEQPACKET) + (1ULL << VIRTIO_VSOCK_F_SEQPACKET) | + (1ULL << VIRTIO_VSOCK_F_DGRAM) }; enum { diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index 35d7eedb5e8e..87d849aeb3ec 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -18,6 +18,15 @@ enum { VSOCK_VQ_MAX = 3, }; +enum { + VSOCK_VQ_STREAM_RX = 0, /* for host to guest data */ + VSOCK_VQ_STREAM_TX = 1, /* for guest to host data */ + VSOCK_VQ_DGRAM_RX = 2, + VSOCK_VQ_DGRAM_TX = 3, + VSOCK_VQ_EX_EVENT = 4, + VSOCK_VQ_EX_MAX = 5, +}; + /* Per-socket state (accessed via vsk->trans) */ struct virtio_vsock_sock { struct vsock_sock *vsk; diff --git a/include/uapi/linux/virtio_vsock.h b/include/uapi/linux/virtio_vsock.h index 3dd3555b2740..cff54ba9b924 100644 --- a/include/uapi/linux/virtio_vsock.h +++ b/include/uapi/linux/virtio_vsock.h @@ -40,6 +40,8 @@ /* The feature bitmap for virtio vsock */ #define VIRTIO_VSOCK_F_SEQPACKET 1 /* SOCK_SEQPACKET supported */ +/* The feature bitmap for virtio net */ +#define VIRTIO_VSOCK_F_DGRAM 0 /* Host support dgram vsock */ struct virtio_vsock_config { __le64 guest_cid; diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 4f7c99dfd16c..bb89f538f5f3 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -27,7 +27,8 @@ static DEFINE_MUTEX(the_virtio_vsock_mutex); /* protects the_virtio_vsock */ struct virtio_vsock { struct virtio_device *vdev; - struct virtqueue *vqs[VSOCK_VQ_MAX]; + struct virtqueue **vqs; + bool has_dgram; /* Virtqueue processing is deferred to a workqueue */ struct work_struct tx_work; @@ -334,7 +335,10 @@ static int virtio_vsock_event_fill_one(struct virtio_vsock *vsock, struct scatterlist sg; struct virtqueue *vq; - vq = vsock->vqs[VSOCK_VQ_EVENT]; + if (vsock->has_dgram) + vq = vsock->vqs[VSOCK_VQ_EX_EVENT]; + else + vq = vsock->vqs[VSOCK_VQ_EVENT]; sg_init_one(&sg, event, sizeof(*event)); @@ -352,7 +356,10 @@ static void virtio_vsock_event_fill(struct virtio_vsock *vsock) virtio_vsock_event_fill_one(vsock, event); } - virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]); + if (vsock->has_dgram) + virtqueue_kick(vsock->vqs[VSOCK_VQ_EX_EVENT]); + else + virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]); } static void virtio_vsock_reset_sock(struct sock *sk) @@ -395,7 +402,10 @@ static void virtio_transport_event_work(struct work_struct *work) container_of(work, struct virtio_vsock, event_work); struct virtqueue *vq; - vq = vsock->vqs[VSOCK_VQ_EVENT]; + if (vsock->has_dgram) + vq = vsock->vqs[VSOCK_VQ_EX_EVENT]; + else + vq = vsock->vqs[VSOCK_VQ_EVENT]; mutex_lock(&vsock->event_lock); @@ -415,7 +425,10 @@ static void virtio_transport_event_work(struct work_struct *work) } } while (!virtqueue_enable_cb(vq)); - virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]); + if (vsock->has_dgram) + virtqueue_kick(vsock->vqs[VSOCK_VQ_EX_EVENT]); + else + virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]); out: mutex_unlock(&vsock->event_lock); } @@ -438,6 +451,10 @@ static void virtio_vsock_tx_done(struct virtqueue *vq) queue_work(virtio_vsock_workqueue, &vsock->tx_work); } +static void virtio_vsock_dgram_tx_done(struct virtqueue *vq) +{ +} + static void virtio_vsock_rx_done(struct virtqueue *vq) { struct virtio_vsock *vsock = vq->vdev->priv; @@ -449,6 +466,10 @@ static void virtio_vsock_rx_done(struct virtqueue *vq) static bool virtio_transport_seqpacket_allow(u32 remote_cid); +static void virtio_vsock_dgram_rx_done(struct virtqueue *vq) +{ +} + static struct virtio_transport virtio_transport = { .transport = { .module = THIS_MODULE, @@ -571,13 +592,29 @@ static int virtio_vsock_probe(struct virtio_device *vdev) virtio_vsock_tx_done, virtio_vsock_event_done, }; + vq_callback_t *ex_callbacks[] = { + virtio_vsock_rx_done, + virtio_vsock_tx_done, + virtio_vsock_dgram_rx_done, + virtio_vsock_dgram_tx_done, + virtio_vsock_event_done, + }; + static const char * const names[] = { "rx", "tx", "event", }; + static const char * const ex_names[] = { + "rx", + "tx", + "dgram_rx", + "dgram_tx", + "event", + }; + struct virtio_vsock *vsock = NULL; - int ret; + int ret, max_vq; ret = mutex_lock_interruptible(&the_virtio_vsock_mutex); if (ret) @@ -598,9 +635,30 @@ static int virtio_vsock_probe(struct virtio_device *vdev) vsock->vdev = vdev; - ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX, - vsock->vqs, callbacks, names, - NULL); + if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_DGRAM)) + vsock->has_dgram = true; + + if (vsock->has_dgram) + max_vq = VSOCK_VQ_EX_MAX; + else + max_vq = VSOCK_VQ_MAX; + + vsock->vqs = kmalloc_array(max_vq, sizeof(struct virtqueue *), GFP_KERNEL); + if (!vsock->vqs) { + ret = -ENOMEM; + goto out; + } + + if (vsock->has_dgram) { + ret = virtio_find_vqs(vsock->vdev, max_vq, + vsock->vqs, ex_callbacks, ex_names, + NULL); + } else { + ret = virtio_find_vqs(vsock->vdev, max_vq, + vsock->vqs, callbacks, names, + NULL); + } + if (ret < 0) goto out; @@ -725,7 +783,8 @@ static struct virtio_device_id id_table[] = { }; static unsigned int features[] = { - VIRTIO_VSOCK_F_SEQPACKET + VIRTIO_VSOCK_F_SEQPACKET, + VIRTIO_VSOCK_F_DGRAM }; static struct virtio_driver virtio_vsock_driver = { -- 2.20.1