From patchwork Sat Jun 3 20:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1843677vqr; Sat, 3 Jun 2023 14:04:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ72CkOPvMmPJpN9TNF8PPEjT3SO6kRGXFEGdwJk0unzOpqPtWHPlP4Kv5DEb0XoGK5bC5pg X-Received: by 2002:a05:6a21:6d89:b0:105:e434:670b with SMTP id wl9-20020a056a216d8900b00105e434670bmr3426358pzb.4.1685826242993; Sat, 03 Jun 2023 14:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685826242; cv=none; d=google.com; s=arc-20160816; b=bFU/qkYxcIqavxVcKiunMMxdLcInvTNisD4Ecs6EazI2v5NqZOWkMmqjvR+iu5tj0s t+X+B38yjorYjXnhsMzvR3OXvQ6Imtw8f21dEh6peJgTdiAiTGsAt31dAnciR2f36wmf uIfvuyOWucsWV1V3ErFIMAz1HPmitIH5QGcWjBl3edxZKdrKncZ2xAJ65mnJOzG+wkNz TEJ7NFtd1LzKAFrzfgOMtN/KfnG8WggDhVLnO2xwummyAtn2Zs7RSDfYoE6dsJnCKOOK bNIzSHtmgF5Q9IGtIZGWv5HQePv16rxgtxWEZmVCmyCq/JeM6znCEUjkLDT0snUwrEbI KsYg== 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=PDBAwhjzQiqgrPTljhwk+nGe366nkV6M9z7XnlirNW8=; b=a2eyjSCEUyZZgaYKMKparQFCix99joMwF7iHW0/v887c8XqRx797OO75dS9xSptkfp sFKxnwYwHf/OzEASmMbVnB4GRQnSjI4gcMiBF8a98c/X5xcZQrxAerIqTLIVArYl98Uv kAGiWXUZqj3KWKgrma6J0t0im3tYHeN48Q9pinjCP3DoAklpaPP84WS7MFud93qEk7Sz Yc/yKWA7/W+aOncC8XbSwmYIBUZKrE6ijuJAu/rBUZ10LF/wG/J9BF1IB8ekXjyLXAqi WT2JEBexaG03yCJmIOyVEVzAR5/HZhr8ehzi3OsMVbJhD5ZbtHfTk34uf+k0nfcF3zI1 qLtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=FR3zMR8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a63cf0d000000b0052c54de0299si3137324pgg.637.2023.06.03.14.03.49; Sat, 03 Jun 2023 14:04:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=FR3zMR8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbjFCUzE (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232482AbjFCUyy (ORCPT ); Sat, 3 Jun 2023 16:54:54 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E26361B3; Sat, 3 Jun 2023 13:54:49 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 6A8285FD12; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825686; bh=PDBAwhjzQiqgrPTljhwk+nGe366nkV6M9z7XnlirNW8=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=FR3zMR8YRK5GQa6omA48DZfBFK8qiKu7IHMLXkG597CuAn/lHd3aksNa/DAsWDWr3 znvKwhkwL/AbKaVCrXJF2979aU1r3E6EitpbU2fSEEVoxRlpMonhjGiFuzC9wHFhz2 /MpQ0zde9leqwFIDj761TGWyyfiVehPnTI0QWIfvd/L0NgH/epWKA5ijaU5jjW5AHf UESxZn3ATlwRgymk0Xs2tTknuiMRjVREZamed1vSOjDxuJw05OW4/VIqDMyavuCIzI DmLHG8uP1E+vPCsZc31/nvPA7AwoQcl01X3ZHRbU6/r+nsr4IjIV1cJ+0GyDIT+Rsc FO6W8AEbCuObw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 01/17] vsock/virtio: read data from non-linear skb Date: Sat, 3 Jun 2023 23:49:23 +0300 Message-ID: <20230603204939.1598818-2-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716938147937909?= X-GMAIL-MSGID: =?utf-8?q?1767716938147937909?= This is preparation patch for non-linear skbuff handling. It replaces direct calls of 'memcpy_to_msg()' with 'skb_copy_datagram_iter()'. Main advantage of the second one is that is can handle paged part of the skb by using 'kmap()' on each page, but if there are no pages in the skb, it behaves like simple copying to iov iterator. This patch also adds new field to the control block of skb - this value shows current offset in the skb to read next portion of data (it doesn't matter linear it or not). Idea is that 'skb_copy_datagram_iter()' handles both types of skb internally - it just needs an offset from which to copy data from the given skb. This offset is incremented on each read from skb. This approach allows to avoid special handling of non-linear skbs: 1) We can't call 'skb_pull()' on it, because it updates 'data' pointer. 2) We need to update 'data_len' also on each read from this skb. Signed-off-by: Arseniy Krasnov Reviewed-by: Bobby Eshleman --- include/linux/virtio_vsock.h | 1 + net/vmw_vsock/virtio_transport_common.c | 26 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index c58453699ee9..17dbb7176e37 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -12,6 +12,7 @@ struct virtio_vsock_skb_cb { bool reply; bool tap_delivered; + u32 frag_off; }; #define VIRTIO_VSOCK_SKB_CB(skb) ((struct virtio_vsock_skb_cb *)((skb)->cb)) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index b769fc258931..5819a9cd4515 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -355,7 +355,7 @@ virtio_transport_stream_do_peek(struct vsock_sock *vsk, spin_lock_bh(&vvs->rx_lock); skb_queue_walk_safe(&vvs->rx_queue, skb, tmp) { - off = 0; + off = VIRTIO_VSOCK_SKB_CB(skb)->frag_off; if (total == len) break; @@ -370,7 +370,10 @@ virtio_transport_stream_do_peek(struct vsock_sock *vsk, */ spin_unlock_bh(&vvs->rx_lock); - err = memcpy_to_msg(msg, skb->data + off, bytes); + err = skb_copy_datagram_iter(skb, off, + &msg->msg_iter, + bytes); + if (err) goto out; @@ -414,24 +417,28 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, skb = skb_peek(&vvs->rx_queue); bytes = len - total; - if (bytes > skb->len) - bytes = skb->len; + if (bytes > skb->len - VIRTIO_VSOCK_SKB_CB(skb)->frag_off) + bytes = skb->len - VIRTIO_VSOCK_SKB_CB(skb)->frag_off; /* sk_lock is held by caller so no one else can dequeue. * Unlock rx_lock since memcpy_to_msg() may sleep. */ spin_unlock_bh(&vvs->rx_lock); - err = memcpy_to_msg(msg, skb->data, bytes); + err = skb_copy_datagram_iter(skb, + VIRTIO_VSOCK_SKB_CB(skb)->frag_off, + &msg->msg_iter, bytes); + if (err) goto out; spin_lock_bh(&vvs->rx_lock); total += bytes; - skb_pull(skb, bytes); - if (skb->len == 0) { + VIRTIO_VSOCK_SKB_CB(skb)->frag_off += bytes; + + if (skb->len == VIRTIO_VSOCK_SKB_CB(skb)->frag_off) { u32 pkt_len = le32_to_cpu(virtio_vsock_hdr(skb)->len); virtio_transport_dec_rx_pkt(vvs, pkt_len); @@ -503,7 +510,10 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, */ spin_unlock_bh(&vvs->rx_lock); - err = memcpy_to_msg(msg, skb->data, bytes_to_copy); + err = skb_copy_datagram_iter(skb, 0, + &msg->msg_iter, + bytes_to_copy); + if (err) { /* Copy of message failed. Rest of * fragments will be freed without copy. From patchwork Sat Jun 3 20:49:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841002vqr; Sat, 3 Jun 2023 13:56:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5pUw+wmYZpIThKnKQOrleKIzi5/4m1DlOYWJABf/ERpSvppNQKSmvDBWL18OfNstGAeWmI X-Received: by 2002:a17:902:9005:b0:1af:fbb6:23b7 with SMTP id a5-20020a170902900500b001affbb623b7mr3369437plp.3.1685825769880; Sat, 03 Jun 2023 13:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825769; cv=none; d=google.com; s=arc-20160816; b=EXF3vSLb0XBEfqTJpz1FKi/ISch1Anos+NyFBbyaUAWjCokQuNgqin2UfXRc/LUDHP 85vvNdCHQEKExZc0/Eu2K+DvjbmmWND0j8MKuQJvToXXlYk8f0MyU06krtgGslFNfFY3 HSm35dYOav0LvXBZczj4p5jVPg9Rv8vQlUaIs0JFn+WF3fa9zouiwXASQDbIzyhauY2p iCK6cFKfZy8dKQz6DKVjiupQLisQJZSCwm+D01v1505WN2bZQBu4kZ99rRYHuYWzNAed jzZWh5WugvOZ8TpillENYN/VNzCq+Zj7CE69X/bOI3/CrS5UZAG7fULjG/EK2eIYHYPj wPww== 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=igltWeKmorgVWzwhU5OIAduVRvDTNdsf6zEVkCG3inE=; b=T6WHvxHvXZTl28jL33/X7n+8e25M1O9RLMAQKTv19Ym7VAiMVnYim2+3akXOJH/l/M P8gjLnm/rp9t7xGaMrrxUbZfvam/VDhgb7d5T/ej7IxE+GWbbU8VH2r59Kr2Jgy15AuV rACfQyILJO0+hC9C07zYmoBj9zbO9h8tt7MJBHt2h3mpyVLf60g+57zNlBwY6z7IhRaS ey5wz2d7cv7kOdpeRePycGfnOG4rvQz1c/HtpkhmDdxHuXhrAkzFd+p43dNojuE2H4AO uvvnJPzGc2CX0D6HKuX6kscS+sWw3kiQcwb8Qpx5Hn1XQFlTsWwAZ+onEIc5MJF/TGh/ 9Qjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=cIi46CdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a170902c10600b001ab007aff67si3033324pli.32.2023.06.03.13.55.57; Sat, 03 Jun 2023 13:56:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=cIi46CdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232484AbjFCUy7 (ORCPT + 99 others); Sat, 3 Jun 2023 16:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232437AbjFCUyy (ORCPT ); Sat, 3 Jun 2023 16:54:54 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC9E11B4; Sat, 3 Jun 2023 13:54:49 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 8EA405FD13; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825686; bh=igltWeKmorgVWzwhU5OIAduVRvDTNdsf6zEVkCG3inE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cIi46CdNwdrGNMaH2xIlNdLoSFp8Nw/8YXjkcRw+A60vXrV/HreerMNjqhUg1A9HP m54vYaxqn8X33u6N2JW3VcP5SaOPznh7eto0w/pu2MrKgsOzPz0d8UnUHCEt9eHJEa 3IPmqy5Uv/vz6OVPFdOn6MyUMi+groTLrIbMhrr1+qYpvaP0t6c/3kTyGZUd/NGxjM jBxfDpjfbEFPLazKh8GCQA+1SJMgGSuE2vl7Jq9DN5mwiYjwn9a5AN4Bdtsa2N64Fc 05/PDM1Dj7eejcbTXIHm+IaTka8vL5+asKvW3cHKNqWIt2cV94rIc37rUPipJxEv6N EKn5xhZmRmQOg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 02/17] vhost/vsock: read data from non-linear skb Date: Sat, 3 Jun 2023 23:49:24 +0300 Message-ID: <20230603204939.1598818-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716442110758517?= X-GMAIL-MSGID: =?utf-8?q?1767716442110758517?= This adds copying to guest's virtio buffers from non-linear skbs. Such skbs are created by protocol layer when MSG_ZEROCOPY flags is used. It changes call of 'copy_to_iter()' to 'skb_copy_datagram_iter()'. Second function can read data from non-linear skb. See commit to 'net/vmw_vsock/virtio_transport_common.c' with the same name for more details. Signed-off-by: Arseniy Krasnov Reviewed-by: Bobby Eshleman --- drivers/vhost/vsock.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 6578db78f0ae..b254aa4b756a 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -156,7 +156,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, } iov_iter_init(&iov_iter, ITER_DEST, &vq->iov[out], in, iov_len); - payload_len = skb->len; + payload_len = skb->len - VIRTIO_VSOCK_SKB_CB(skb)->frag_off; hdr = virtio_vsock_hdr(skb); /* If the packet is greater than the space available in the @@ -197,8 +197,10 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, break; } - nbytes = copy_to_iter(skb->data, payload_len, &iov_iter); - if (nbytes != payload_len) { + if (skb_copy_datagram_iter(skb, + VIRTIO_VSOCK_SKB_CB(skb)->frag_off, + &iov_iter, + payload_len)) { kfree_skb(skb); vq_err(vq, "Faulted on copying pkt buf\n"); break; @@ -212,13 +214,13 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, vhost_add_used(vq, head, sizeof(*hdr) + payload_len); added = true; - skb_pull(skb, payload_len); + VIRTIO_VSOCK_SKB_CB(skb)->frag_off += payload_len; total_len += payload_len; /* If we didn't send all the payload we can requeue the packet * to send it with the next available buffer. */ - if (skb->len > 0) { + if (VIRTIO_VSOCK_SKB_CB(skb)->frag_off < skb->len) { hdr->flags |= cpu_to_le32(flags_to_restore); /* We are queueing the same skb to handle From patchwork Sat Jun 3 20:49:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102922 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1843842vqr; Sat, 3 Jun 2023 14:04:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+IG+k6+dTmD+mCigy/6jlXWYX7Es1zJNgl/csTQdTBbq8+f5hHz6maippgKYBXd/xTmQ0 X-Received: by 2002:a92:ca8a:0:b0:335:ebb8:1128 with SMTP id t10-20020a92ca8a000000b00335ebb81128mr12406082ilo.2.1685826265466; Sat, 03 Jun 2023 14:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685826265; cv=none; d=google.com; s=arc-20160816; b=klaQVgLA1swmx1AJuOBs2ak4Tr4y7K+RZcyYsQLPsQVlalLjC/KJAsLVEhYP+nT/Nf y0//j8uKmoAjg5T3wo0mKJi7WceHt4OsxZIJqfNgQSW2Cxtn7ESh6T9wKYLyyI4leBwa AueqdJAaLDglNrY+A5TNOnAbO1Zu/fykxf/4UieBrnF1PctPiPuITusB489TfmjYGUpe z4m1u0zWfI4JMbFEckT8q70uClthcIOOjoIUeQPcmAvovykOZcodreqUFimUwqR7NiMU TAnGopnoqkh2K2xL19OyxzbQexaNLhtlF6YEkBHylNuLFSZOhIgmY43D2slVkx+LOIrO jP2A== 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=12J3aUkd1001dQlCLmszH/Jlw+bRp81nuK6DQ+iFTnk=; b=peXh2fmvgMK69cTB7QjRi9wFEhJACJnoz4AYchbP6gaVavdqxEbwAp0yeEH+u5aWdW r4G5QPnJHKckclTA5fDZfXlYDqjpfpGF8cpc+Mb/s/FcdUR6tBQUt9JgWReRYeTZ2HP5 6IMPpp7JCuN7jToYP4T+1rQZHHOwHUgjgaU+KvCZZJ2ZLm5xMtjyErrsd/jCp1aFLhY5 R4GRtrOXA1LGPD+x/IzLXZ5lkxPwtwtZEGikY1pm6OjTrI8B7Ufi0J23ETlnZpM+w4R6 YCv7fbkhGZnaYKtv73BMhkteRCClITXZYywmnaGH/aq58RWioM/D5506vX/JCYm28Thd 9kcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=OzeEQXlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631753000000b005346bd7dee9si3093727pgx.682.2023.06.03.14.04.13; Sat, 03 Jun 2023 14:04:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=OzeEQXlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232941AbjFCUzJ (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbjFCUyy (ORCPT ); Sat, 3 Jun 2023 16:54:54 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A191B7; Sat, 3 Jun 2023 13:54:49 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id B18B55FD33; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825686; bh=12J3aUkd1001dQlCLmszH/Jlw+bRp81nuK6DQ+iFTnk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=OzeEQXlLUG5SLF1/btlSkjrBq7Gu1yg80/B6vqrl87g4u7MaLTpJaA5RHB0iNpE6e 6jMjrxTYvjBHo8xkTKp8dbedDsCpyZGSBMSCclSL/POgWCysWXX88ERx78+mBhyoaT KB+A3amjimOeeAQPX9tV19GRNC4FzEAaNdpZjFNkOiiOWULHWn1x3P76q5GRGd7Hex qwATekJY0ZJwGczQsqdREfumXHCxL9wpUgMczRSVbXp9CL5BDXYUsnd/rfnnpgL/d3 fQMJcz4y2sxpOtgLzlYda5qcZ4U0zFQnHN6B0i4zNTNA35ptEOiQYfoVU143e71lgQ eKFsuvFBrfydA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 03/17] vsock/virtio: support to send non-linear skb Date: Sat, 3 Jun 2023 23:49:25 +0300 Message-ID: <20230603204939.1598818-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716962199201786?= X-GMAIL-MSGID: =?utf-8?q?1767716962199201786?= For non-linear skb use its pages from fragment array as buffers in virtio tx queue. These pages are already pinned by 'get_user_pages()' during such skb creation. Signed-off-by: Arseniy Krasnov Reviewed-by: Bobby Eshleman --- net/vmw_vsock/virtio_transport.c | 37 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index e95df847176b..6053d8341091 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -100,7 +100,9 @@ virtio_transport_send_pkt_work(struct work_struct *work) vq = vsock->vqs[VSOCK_VQ_TX]; for (;;) { - struct scatterlist hdr, buf, *sgs[2]; + /* +1 is for packet header. */ + struct scatterlist *sgs[MAX_SKB_FRAGS + 1]; + struct scatterlist bufs[MAX_SKB_FRAGS + 1]; int ret, in_sg = 0, out_sg = 0; struct sk_buff *skb; bool reply; @@ -111,12 +113,35 @@ virtio_transport_send_pkt_work(struct work_struct *work) virtio_transport_deliver_tap_pkt(skb); reply = virtio_vsock_skb_reply(skb); + sg_init_one(&bufs[0], virtio_vsock_hdr(skb), sizeof(*virtio_vsock_hdr(skb))); + sgs[out_sg++] = &bufs[0]; + + if (skb_is_nonlinear(skb)) { + struct skb_shared_info *si; + int i; + + si = skb_shinfo(skb); + + for (i = 0; i < si->nr_frags; i++) { + skb_frag_t *skb_frag = &si->frags[i]; + void *va = page_to_virt(skb_frag->bv_page); + + /* We will use 'page_to_virt()' for userspace page here, + * because virtio layer will call 'virt_to_phys()' later + * to fill buffer descriptor. We don't touch memory at + * "virtual" address of this page. + */ + sg_init_one(&bufs[i + 1], + va + skb_frag->bv_offset, + skb_frag->bv_len); + sgs[out_sg++] = &bufs[i + 1]; + } + } else { + if (skb->len > 0) { + sg_init_one(&bufs[1], skb->data, skb->len); + sgs[out_sg++] = &bufs[1]; + } - sg_init_one(&hdr, virtio_vsock_hdr(skb), sizeof(*virtio_vsock_hdr(skb))); - sgs[out_sg++] = &hdr; - if (skb->len > 0) { - sg_init_one(&buf, skb->data, skb->len); - sgs[out_sg++] = &buf; } ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, GFP_KERNEL); From patchwork Sat Jun 3 20:49:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841686vqr; Sat, 3 Jun 2023 13:59:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XsTh5SV9IJZoMJGDrBsBh9yehiM6tdHyhDCOI3AsmhoLh92zdWYly9Xj4nB/qqENlCL78 X-Received: by 2002:a05:6358:428f:b0:118:daa:ce7 with SMTP id s15-20020a056358428f00b001180daa0ce7mr18865064rwc.0.1685825970964; Sat, 03 Jun 2023 13:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825970; cv=none; d=google.com; s=arc-20160816; b=H+SA08/sdFwK+ZLcCXE8Dk/Cmg9h6lFXA7P21cCS2BrdvZV/Rrb9TPiDXj6p2r7XO8 FkTkzRV1BOMGGo1tKm+ITI2QuD2OfLMhAmIAgTGDxtqBj7nhXrWhJv9RMOuoNcEwfgu/ yGFTkSOcFvR0XpY13AdEzXLW4z9ff7NeMAxtC0cMqga1OP/7Xu/UuFTYlCU9Nwgy6HwO mXHCFYJIBhbumEe/WfsW8hFq46iY/olr/bR3GWymg89ISDmPaMYDRktR64g+qIS4V7wB obIibcqPjGWeZv2/e7IxLlLUm2cQsC6lY6WCQLnzUJF/lTI836LapfZBWjFzu6hMtxXd 6ORA== 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=22Y5ntJ+4qJ6mCXCPM4xdNhop4Y9r+djJZMggy4Cf+Y=; b=w6CgM+qWQVyXkARyXp7ry9CSKpP3oZGtgzN9SCD/2gLmP2twbn/9q1B3QH2qqVYP1m 2wuUZja+ApntK2XBp1/rJDo/YSLavPKYiqLqw7uEWvhDyICks7qYGTl6JZCkAyTTVZk2 d0CVvxck2gIxuLlFJFyvrOSFyY3qNtJ9w9TRu/ULuzPz6yQ4peipwY07lfNH71kmv9Tp QSrST1qu0azE3QoE2s0WKEwJtQMpq2emDwbCCKyk/E6KLIgoZFQ2Ot/qIhdCLx+DJ+v3 3G+c/yUaU8wF7/f01Z+VexteEHgTVxMbCvYmfw6EsrdSuvSOusxKLGfp/s8H1ZgfYBYZ 7DsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b="JEMt/1+D"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k197-20020a633dce000000b005030eb175d1si3164865pga.107.2023.06.03.13.59.17; Sat, 03 Jun 2023 13:59:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b="JEMt/1+D"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232200AbjFCUy4 (ORCPT + 99 others); Sat, 3 Jun 2023 16:54:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232454AbjFCUyy (ORCPT ); Sat, 3 Jun 2023 16:54:54 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BB0C1B6; Sat, 3 Jun 2023 13:54:49 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 27D365FD34; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825687; bh=22Y5ntJ+4qJ6mCXCPM4xdNhop4Y9r+djJZMggy4Cf+Y=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=JEMt/1+DlvTGWX7tlvjoLwRd2mXXxqUGwlX5UMfrqSe4pFX5w5M/NPCNJg0uANqHS pkfrfGq6qIwucGph3vNh6zV6e2ie20Lo8R+EFOd5wvWdUJB96BJ0ENwWsE9uWCxwIu cAzFOaUobK4Q1N7sNiFSqRSW4egMXEfqMRr/CxrHB4gaKFyKMlf3j+GWRWjMhdqGjO n21mhYdI2YHUhZhBIeFPDFeywgZvzgrgfHlVU5XJ03qigw4MG0x8yEl/Zjrc/QpCOQ l3becVRU1ix74gnK3cYaMheezkrmoZQkYCMMC1kHPFrsyxbkM+Gn7PF++n0niOV9Wm rGM9gBZnHfyPA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 04/17] vsock/virtio: non-linear skb handling for tap Date: Sat, 3 Jun 2023 23:49:26 +0300 Message-ID: <20230603204939.1598818-5-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716653127805587?= X-GMAIL-MSGID: =?utf-8?q?1767716653127805587?= For tap device new skb is created and data from the current skb is copied to it. This adds copying data from non-linear skb to new the skb. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 31 ++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 5819a9cd4515..0de562c1dc4b 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -106,6 +106,27 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, return NULL; } +static void virtio_transport_copy_nonlinear_skb(struct sk_buff *skb, + void *dst, + size_t len) +{ + struct iov_iter iov_iter = { 0 }; + struct kvec kvec; + size_t to_copy; + + kvec.iov_base = dst; + kvec.iov_len = len; + + iov_iter.iter_type = ITER_KVEC; + iov_iter.kvec = &kvec; + iov_iter.nr_segs = 1; + + to_copy = min_t(size_t, len, skb->len); + + skb_copy_datagram_iter(skb, VIRTIO_VSOCK_SKB_CB(skb)->frag_off, + &iov_iter, to_copy); +} + /* Packet capture */ static struct sk_buff *virtio_transport_build_skb(void *opaque) { @@ -114,7 +135,6 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) struct af_vsockmon_hdr *hdr; struct sk_buff *skb; size_t payload_len; - void *payload_buf; /* A packet could be split to fit the RX buffer, so we can retrieve * the payload length from the header and the buffer pointer taking @@ -122,7 +142,6 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) */ pkt_hdr = virtio_vsock_hdr(pkt); payload_len = pkt->len; - payload_buf = pkt->data; skb = alloc_skb(sizeof(*hdr) + sizeof(*pkt_hdr) + payload_len, GFP_ATOMIC); @@ -165,7 +184,13 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) skb_put_data(skb, pkt_hdr, sizeof(*pkt_hdr)); if (payload_len) { - skb_put_data(skb, payload_buf, payload_len); + if (skb_is_nonlinear(pkt)) { + void *data = skb_put(skb, payload_len); + + virtio_transport_copy_nonlinear_skb(pkt, data, payload_len); + } else { + skb_put_data(skb, pkt->data, payload_len); + } } return skb; From patchwork Sat Jun 3 20:49:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1842653vqr; Sat, 3 Jun 2023 14:01:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YODe+wiPVGhk632eTacg8vUAYxQBDl3ZjoY6GbmNeZwi36Or4TRuU2KdXxgQgcxKk6m2g X-Received: by 2002:a05:6870:4515:b0:196:60e0:13d9 with SMTP id e21-20020a056870451500b0019660e013d9mr4824222oao.39.1685826112366; Sat, 03 Jun 2023 14:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685826112; cv=none; d=google.com; s=arc-20160816; b=WXsoonKt/z0wF5rPDzav5nZmnFCs9xEgE6NV01eX2QO+TEyCXGx67E5iWb64l6vYzM ZJF1O40ntGRK/rC52Lov3ep6Trys45CSyxdraPiYIb+YA+sb6Z4AdxxR5w8xKNiOQJtV u7wdgJ5SekLUQqgseSkhp9WOAUBMigQwnLPNVr0zSUIXXeEtkK9uirxOGlBJa55gs//h ZAEOIZu2PORfjHyzOofODkwiJIl2u44YwdKO9pwVchDCOOyotVXkprc8HLqPPbN54zWn iZcEeROY28zS2f8WUmWDqHZz/TIcMPJSi30ExxDID0PokmJb+fW/Hm84BjH+/BLAkLfy Be4w== 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=gjrU2ZbbMmbnxCk3LYtszb8+T6uwl8OE10aw4rHf0Yk=; b=UINTN7d/DjXSj8KnsipNmJFrChpY/i0BH11ROoYXrkUxR0XIcbYy46U0cipFy/CH76 IQG9blcgvupKNvfEmbJxMN2IDbZwNYhuJbj+vw+E4lpRZqJZtG/ftR83P9756kgQmsZl o7jPPXuQtiEr4D8AlX/AQGz902ID+GnW9KJsN/5XOJ5Pqb01Gb3QRaVBIgThMJDjNeKq TXMhTqsk6E6F0TV1IuyDAzWyODPDlJe1X3RnBTkkNefEv5IprpH7MNBF92FuSa6zb52e IXkHpThduNu46AIAG20wRS65AkP54MbvLc5pZr0KE004TdH/nHMA2NIFKN2qdwmRESo/ SYPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=WDFSjuoT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a170902c10600b001ab007aff67si3033324pli.32.2023.06.03.14.01.39; Sat, 03 Jun 2023 14:01:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=WDFSjuoT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233439AbjFCUzf (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232895AbjFCUzG (ORCPT ); Sat, 3 Jun 2023 16:55:06 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01B22196; Sat, 3 Jun 2023 13:54:55 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 6C0025FD35; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825687; bh=gjrU2ZbbMmbnxCk3LYtszb8+T6uwl8OE10aw4rHf0Yk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WDFSjuoTpEJ5d2U9/qlOG+hr8Jm/edDva61zdNA0koLQne3zc4PFMzI9oHX6aEWlp zqDhhjk0cjOg40axqYRrQodM6PcOEt4+CnttODCciLTvn6hB1PbqNQP5PKdjoX2pMg rXBiqBddv3zkZVKW2lLkm/kM11haVNf4X7JqrXMsa+NtdmcBWQMKXcdNET/DN/+dyk YTwWz03YiD/6c17/kQSQXf0zAVB86S0KiIgrxVD98unIqXaqzALDJmZ/RGYCdnqA4T db6zMH+49C9VtNxxVcWfDuyFsX49qm5FPy+fqfStwDgEg31PKKF8NyTDFR/BsscVXY 8opvgxx8ZZ95g== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 05/17] vsock/virtio: MSG_ZEROCOPY flag support Date: Sat, 3 Jun 2023 23:49:27 +0300 Message-ID: <20230603204939.1598818-6-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716801400156171?= X-GMAIL-MSGID: =?utf-8?q?1767716801400156171?= This adds handling of MSG_ZEROCOPY flag on transmission path: if this flag is set and zerocopy transmission is possible, then non-linear skb will be created and filled with the pages of user's buffer. Pages of user's buffer are locked in memory by 'get_user_pages()'. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 270 ++++++++++++++++++------ 1 file changed, 208 insertions(+), 62 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 0de562c1dc4b..f1ec38c72db7 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -37,27 +37,100 @@ virtio_transport_get_ops(struct vsock_sock *vsk) return container_of(t, struct virtio_transport, transport); } -/* Returns a new packet on success, otherwise returns NULL. - * - * If NULL is returned, errp is set to a negative errno. - */ -static struct sk_buff * -virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, - size_t len, - u32 src_cid, - u32 src_port, - u32 dst_cid, - u32 dst_port) -{ - const size_t skb_len = VIRTIO_VSOCK_SKB_HEADROOM + len; - struct virtio_vsock_hdr *hdr; - struct sk_buff *skb; +static bool virtio_transport_can_zcopy(struct virtio_vsock_pkt_info *info, + size_t max_to_send) +{ + struct iov_iter *iov_iter; + + if (!info->msg) + return false; + + iov_iter = &info->msg->msg_iter; + + /* Data is simple buffer. */ + if (iter_is_ubuf(iov_iter)) + return true; + + if (!iter_is_iovec(iov_iter)) + return false; + + if (iov_iter->iov_offset) + return false; + + /* We can't send whole iov. */ + if (iov_iter->count > max_to_send) + return false; + + return true; +} + +static int virtio_transport_init_zcopy_skb(struct vsock_sock *vsk, + struct sk_buff *skb, + struct msghdr *msg, + bool zerocopy) +{ + struct ubuf_info *uarg; + + if (msg->msg_ubuf) { + uarg = msg->msg_ubuf; + net_zcopy_get(uarg); + } else { + struct iov_iter *iter = &msg->msg_iter; + struct ubuf_info_msgzc *uarg_zc; + int len; + + /* Only ITER_IOVEC or ITER_UBUF are allowed and + * checked before. + */ + if (iter_is_iovec(iter)) + len = iov_length(iter->__iov, iter->nr_segs); + else + len = iter->count; + + uarg = msg_zerocopy_realloc(sk_vsock(vsk), + len, + NULL); + + if (!uarg) + return -1; + + uarg_zc = uarg_to_msgzc(uarg); + uarg_zc->zerocopy = zerocopy ? 1 : 0; + } + + skb_zcopy_init(skb, uarg); + + return 0; +} + +static int virtio_transport_fill_linear_skb(struct sk_buff *skb, + struct vsock_sock *vsk, + struct virtio_vsock_pkt_info *info, + size_t len) +{ void *payload; int err; - skb = virtio_vsock_alloc_skb(skb_len, GFP_KERNEL); - if (!skb) - return NULL; + payload = skb_put(skb, len); + err = memcpy_from_msg(payload, info->msg, len); + if (err) + return -1; + + if (msg_data_left(info->msg)) + return 0; + + return 0; +} + +static void virtio_transport_init_hdr(struct sk_buff *skb, + struct virtio_vsock_pkt_info *info, + u32 src_cid, + u32 src_port, + u32 dst_cid, + u32 dst_port, + size_t len) +{ + struct virtio_vsock_hdr *hdr; hdr = virtio_vsock_hdr(skb); hdr->type = cpu_to_le16(info->type); @@ -68,42 +141,6 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, hdr->dst_port = cpu_to_le32(dst_port); hdr->flags = cpu_to_le32(info->flags); hdr->len = cpu_to_le32(len); - - if (info->msg && len > 0) { - payload = skb_put(skb, len); - err = memcpy_from_msg(payload, info->msg, len); - if (err) - goto out; - - if (msg_data_left(info->msg) == 0 && - info->type == VIRTIO_VSOCK_TYPE_SEQPACKET) { - hdr->flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM); - - if (info->msg->msg_flags & MSG_EOR) - hdr->flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR); - } - } - - if (info->reply) - virtio_vsock_skb_set_reply(skb); - - trace_virtio_transport_alloc_pkt(src_cid, src_port, - dst_cid, dst_port, - len, - info->type, - info->op, - info->flags); - - if (info->vsk && !skb_set_owner_sk_safe(skb, sk_vsock(info->vsk))) { - WARN_ONCE(1, "failed to allocate skb on vsock socket with sk_refcnt == 0\n"); - goto out; - } - - return skb; - -out: - kfree_skb(skb); - return NULL; } static void virtio_transport_copy_nonlinear_skb(struct sk_buff *skb, @@ -214,6 +251,85 @@ static u16 virtio_transport_get_type(struct sock *sk) return VIRTIO_VSOCK_TYPE_SEQPACKET; } +/* Returns a new packet on success, otherwise returns NULL. + * + * If NULL is returned, errp is set to a negative errno. + */ +static struct sk_buff *virtio_transport_alloc_skb(struct vsock_sock *vsk, + struct virtio_vsock_pkt_info *info, + size_t payload_len, + bool zcopy, + u32 dst_cid, + u32 dst_port, + u32 src_cid, + u32 src_port) +{ + struct sk_buff *skb; + size_t skb_len; + + skb_len = VIRTIO_VSOCK_SKB_HEADROOM; + + if (!zcopy) + skb_len += payload_len; + + skb = virtio_vsock_alloc_skb(skb_len, GFP_KERNEL); + if (!skb) + return NULL; + + virtio_transport_init_hdr(skb, info, src_cid, src_port, + dst_cid, dst_port, + payload_len); + + /* Set owner here, because '__zerocopy_sg_from_iter()' uses + * owner of skb without check to update 'sk_wmem_alloc'. + */ + if (vsk) + skb_set_owner_w(skb, sk_vsock(vsk)); + + if (info->msg && payload_len > 0) { + int err; + + if (zcopy) { + err = __zerocopy_sg_from_iter(info->msg, NULL, skb, + &info->msg->msg_iter, + payload_len); + } else { + err = virtio_transport_fill_linear_skb(skb, vsk, info, payload_len); + } + + if (err) + goto out; + + VIRTIO_VSOCK_SKB_CB(skb)->frag_off = 0; + + if (info->type == VIRTIO_VSOCK_TYPE_SEQPACKET) { + struct virtio_vsock_hdr *hdr; + + hdr = virtio_vsock_hdr(skb); + + hdr->flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM); + + if (info->msg->msg_flags & MSG_EOR) + hdr->flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR); + } + } + + if (info->reply) + virtio_vsock_skb_set_reply(skb); + + trace_virtio_transport_alloc_pkt(src_cid, src_port, + dst_cid, dst_port, + payload_len, + info->type, + info->op, + info->flags); + + return skb; +out: + kfree_skb(skb); + return NULL; +} + /* This function can only be used on connecting/connected sockets, * since a socket assigned to a transport is required. * @@ -226,6 +342,8 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk, const struct virtio_transport *t_ops; struct virtio_vsock_sock *vvs; u32 pkt_len = info->pkt_len; + bool can_zcopy = false; + u32 max_skb_cap; u32 rest_len; int ret; @@ -254,22 +372,49 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk, if (pkt_len == 0 && info->op == VIRTIO_VSOCK_OP_RW) return pkt_len; + /* If zerocopy is not enabled by 'setsockopt()', we behave as + * there is no MSG_ZEROCOPY flag set. + */ + if (!sock_flag(sk_vsock(vsk), SOCK_ZEROCOPY)) + info->flags &= ~MSG_ZEROCOPY; + + if (info->flags & MSG_ZEROCOPY) + can_zcopy = virtio_transport_can_zcopy(info, pkt_len); + + if (can_zcopy) + max_skb_cap = min_t(u32, VIRTIO_VSOCK_MAX_PKT_BUF_SIZE, + (MAX_SKB_FRAGS * PAGE_SIZE)); + else + max_skb_cap = VIRTIO_VSOCK_MAX_PKT_BUF_SIZE; + rest_len = pkt_len; do { struct sk_buff *skb; size_t skb_len; - skb_len = min_t(u32, VIRTIO_VSOCK_MAX_PKT_BUF_SIZE, rest_len); + skb_len = min(max_skb_cap, rest_len); - skb = virtio_transport_alloc_skb(info, skb_len, - src_cid, src_port, - dst_cid, dst_port); + skb = virtio_transport_alloc_skb(vsk, info, skb_len, can_zcopy, + dst_cid, dst_port, + src_cid, src_port); if (!skb) { ret = -ENOMEM; break; } + /* This is last skb to send this portion of data. */ + if (skb_len == rest_len && + info->flags & MSG_ZEROCOPY && + info->op == VIRTIO_VSOCK_OP_RW) { + if (virtio_transport_init_zcopy_skb(vsk, skb, + info->msg, + can_zcopy)) { + ret = -ENOMEM; + break; + } + } + virtio_transport_inc_tx_pkt(vvs, skb); ret = t_ops->send_pkt(skb); @@ -884,6 +1029,7 @@ virtio_transport_stream_enqueue(struct vsock_sock *vsk, .msg = msg, .pkt_len = len, .vsk = vsk, + .flags = msg->msg_flags, }; return virtio_transport_send_pkt_info(vsk, &info); @@ -935,11 +1081,11 @@ static int virtio_transport_reset_no_sock(const struct virtio_transport *t, if (!t) return -ENOTCONN; - reply = virtio_transport_alloc_skb(&info, 0, - le64_to_cpu(hdr->dst_cid), - le32_to_cpu(hdr->dst_port), + reply = virtio_transport_alloc_skb(NULL, &info, 0, false, le64_to_cpu(hdr->src_cid), - le32_to_cpu(hdr->src_port)); + le32_to_cpu(hdr->src_port), + le64_to_cpu(hdr->dst_cid), + le32_to_cpu(hdr->dst_port)); if (!reply) return -ENOMEM; From patchwork Sat Jun 3 20:49:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841132vqr; Sat, 3 Jun 2023 13:56:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6vQmL5M3+LYZdukP852v8j5d7AS2OlIqXb+OHcdTznNKfMDfw4kbmgtlv8n/TDWrb7sM7t X-Received: by 2002:a05:6358:4411:b0:123:6652:f581 with SMTP id z17-20020a056358441100b001236652f581mr16872411rwc.4.1685825808542; Sat, 03 Jun 2023 13:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825808; cv=none; d=google.com; s=arc-20160816; b=0ZiGr6MV3daUbgc4PP1YoSIIfgwf1wa6Uxm8j8R7mG2zx0NBTIa8KmHw8jL8OQS4aG ddSN96vhSHzPkLDYPtppdVbw5vFIuZP8kOpIcedCLqEOSp7UfTP//YW/FRPQoICCXt76 a6xz+kKmQxP5XEqmEbSGFs2rEHFz7BXN1p/hOzY6GomeIunNcCCmmLNE2KVcF9MKzZRq t/wzj+IVbo8rtZSo55YdqKBHzqPtdb2CdjIddBwoegVDWs0GEQXEi9u5xlTp5We65ayn K7+jMZORARHoZbwBBApLf0SOTzf2mVKFPtqDXrxModLiamCKrgLdnpfEUaqA1qPvYLWK W+nw== 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=Lz8wUwmvEr3RVG1tld+2qsVDKoN2L55XiM0gSmTilXk=; b=dLmIsQxQwq9AYOcEvK1sdxir2naFvFFDEgYFk+K8IrB7UY6Wkkb9i1/TrnH6YFhCnN 2BIKUKyGH1zrnd9BXvOpJNUtsKJWdgtTBlzsalnbTE2+OaYuPKBxl/UeobHlcJenKZxL oV7nuO6EbWh44zpqDOYTqAB/UNKutzXS+trH/KV/D0zK5HO8OsEcZMq8NXsUxR5m64TK kicqHOHOoLGQZrKrdjk02FslnIgLlRGTX4GxqlWXcBSDEiAxGm4t1HVf1fYZ0fAmR+R8 a988tjDpq/SAefRM23nj/1zbephzwKMmPe2WnH5Wf/WeO4ULHoXNoS4nXAco++RxkhBm svhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=ZuNfwktT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a17090a2e1000b00258d8f6eabdsi3428373pjd.66.2023.06.03.13.56.36; Sat, 03 Jun 2023 13:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=ZuNfwktT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232898AbjFCUzt (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232390AbjFCUy7 (ORCPT ); Sat, 3 Jun 2023 16:54:59 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E8C19A; Sat, 3 Jun 2023 13:54:56 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id A12FD5FD36; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825687; bh=Lz8wUwmvEr3RVG1tld+2qsVDKoN2L55XiM0gSmTilXk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZuNfwktTwU0LX48iEAIFz2n10dgnL5mnVcLoEx1496yfGCwBz1AJhGKZdQ3XH38DZ ePCS0Cx5h6hMbQc4zlGJyMslh5wQ+aJa6DodmgQKMuvHJlE4HJf4ADGohtkr8cemeu wpr69g09J+z+ihNwbLBdVGkqmb6Ub+1CJbAAZK+f7hrz0kPxObuPSrANr91xyK67SN ZIKtExwgbdDnZGD+FLevtTsrzqIwFF0SOeQV5uVsF5ZcdxOgdMUC4CHcZHzkS9TFYl YLSg4SG2pntbamX9e2jBhnznNMihwoINiflyopoTmuj6IDrS9MVS68+1TOkTpyPepf 96sgS4sLs0XhQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 06/17] vsock: check error queue to set EPOLLERR Date: Sat, 3 Jun 2023 23:49:28 +0300 Message-ID: <20230603204939.1598818-7-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716483175080746?= X-GMAIL-MSGID: =?utf-8?q?1767716483175080746?= If socket's error queue is not empty, EPOLLERR must be set. Otherwise, reader of error queue won't detect data in it using EPOLLERR bit. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/af_vsock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index efb8a0937a13..45fd20c4ed50 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1030,7 +1030,7 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock, poll_wait(file, sk_sleep(sk), wait); mask = 0; - if (sk->sk_err) + if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue)) /* Signify that there has been an error on this socket. */ mask |= EPOLLERR; From patchwork Sat Jun 3 20:49:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841036vqr; Sat, 3 Jun 2023 13:56:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XSVQm3GDwAl3E1zQGt8qG9g32AcbnZJCcMC5f+c6WTmxjcR/QBIiwUQ0BwrUdvuXZnP55 X-Received: by 2002:a05:6358:e494:b0:123:4843:e7ea with SMTP id by20-20020a056358e49400b001234843e7eamr10301967rwb.21.1685825778630; Sat, 03 Jun 2023 13:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825778; cv=none; d=google.com; s=arc-20160816; b=h/Kmc2yvdd2ClKQzcTJ5XwANPbZHCSqlN8yJkuJ7cLqtQFagXLivMLjM6SMEsdr//9 6wwXRRZ1gr593U+3Q3y+GX2jU41d1kOcY6qSgUra0W8m1Y6HYY/ANzlqpodGwl8zg/Hk tRJS6mOrlTl8QZUxceXTSDv8M5m7SFEqz6MzZCSKXGSNw0flGlN8b+kKG8mK+BAxXzd6 o8Ld+IZAAe/c8HxVuHTYKAAsW/FCe+zN1q1Op92f02dlf694M9Hag47ncVO+Qe1Ly3XD bzDeLWBIfpc+9q3rIEjWd/6iM9zDufZwyFLJb8ZHhKYBe8ZQeFXFTN8Kd6F7GAxbOXsA D+MA== 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=ApoSi7ZfTEhQVGLgapLVsvDQGAGgUMVtdzLvgIwP5vU=; b=yxXUV/gTzWzOVCgfD4zyc37p/Ymx/CM5gEsokr3wndY2dM+oJNsY1XoWSFCgTpPRDL UfgjyVXeEYb8hAcbpk2weUoNHoMbUW6Rda1NP1osiHvn0+9suXFObs5hypFuQyc4DXBr p5MJR4t1xP3Yw2Aat8cYV+FcPqmHoTwi8v+3es8FkgrPtFIHwZyykI/Mgvl6f0IlmRy+ GBQlfkKOLccDsnqCCmNV2Kx8+alIRySY+NS7MmaT7pyaUfsb1xAtJ9J8ICfC9v+7YqD1 3ikoJ+Kz07yMMHlYfmRymRiRinlEZ4TqF1rszEqPsNiKIRLevAJ4FvYwjxL15r2mSQ1f aYWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=AtVJ9LHY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qi2-20020a17090b274200b00256a6aab74esi4916607pjb.111.2023.06.03.13.56.06; Sat, 03 Jun 2023 13:56:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=AtVJ9LHY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232651AbjFCUzQ (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbjFCUy6 (ORCPT ); Sat, 3 Jun 2023 16:54:58 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01AA5B3; Sat, 3 Jun 2023 13:54:55 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id E21A95FD37; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825687; bh=ApoSi7ZfTEhQVGLgapLVsvDQGAGgUMVtdzLvgIwP5vU=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AtVJ9LHYCx6rZSQS+YMDX5FaJbjdJxUrIEQ1YaCWynDCrMbEBlEfoKr1DYMS2Sub6 /HMXGkJS0o9xZFnLGQTRLswCddVWe7MYxm3FYN95KkPfdwzma4E6n251rr8XUFjAVR YfX2ftHGxjH4VWAUNnk8ngHJ+5f4pO+ZKmQuF2b0NQT4oZKKohvWWI2TxMH42efJHe kolX/+GqXDSoxE7cozf1cDcTK+YQzKzKFUTSaSR9Ig5pA4zFVAPkntVLdQd5DOU7ad lo9n0yT1SzjUKzfoNY6JtI9kQbYlBZFgw25V5ADfFGXZxhsRX5GKtOV7YvqnDubhD9 pQd48J4Waj8pQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:47 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 07/17] vsock: read from socket's error queue Date: Sat, 3 Jun 2023 23:49:29 +0300 Message-ID: <20230603204939.1598818-8-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716451364836082?= X-GMAIL-MSGID: =?utf-8?q?1767716451364836082?= This adds handling of MSG_ERRQUEUE input flag in receive call. This flag is used to read socket's error queue instead of data queue. Possible scenario of error queue usage is receiving completions for transmission with MSG_ZEROCOPY flag. Signed-off-by: Arseniy Krasnov --- include/linux/socket.h | 1 + net/vmw_vsock/af_vsock.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/linux/socket.h b/include/linux/socket.h index bd1cc3238851..d79efd026880 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -382,6 +382,7 @@ struct ucred { #define SOL_MPTCP 284 #define SOL_MCTP 285 #define SOL_SMC 286 +#define SOL_VSOCK 287 /* IPX options */ #define IPX_TYPE 1 diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 45fd20c4ed50..07803d9fbf6d 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -110,6 +110,7 @@ #include #include #include +#include static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr); static void vsock_sk_destruct(struct sock *sk); @@ -2135,6 +2136,10 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, int err; sk = sock->sk; + + if (unlikely(flags & MSG_ERRQUEUE)) + return sock_recv_errqueue(sk, msg, len, SOL_VSOCK, 0); + vsk = vsock_sk(sk); err = 0; From patchwork Sat Jun 3 20:49:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1842134vqr; Sat, 3 Jun 2023 14:00:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4I3pxiomNbpCLJSO/b1Qs+Ra7x2PuzdNeYIQanVp/FkA0/JQK9BPYpaMpr+CG58iPUsYbn X-Received: by 2002:a17:902:e88f:b0:1b0:6361:a1b3 with SMTP id w15-20020a170902e88f00b001b06361a1b3mr4562800plg.53.1685826037301; Sat, 03 Jun 2023 14:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685826037; cv=none; d=google.com; s=arc-20160816; b=Wdequpx/beBrqyXus0phOnrEhucaDKlrvWuo3VcjbcRTIu6XoZWO32QT/+/c2Ptpyh k2Zvo+Y44va4Ze8hRM0LlZUiyCXvdSO0f6cD+SVncE8wBO/InqerzifrUb5Mmm8me08u e4Z0x0QH1i12jXVCoUGVQH2xQuJwhuNNtY/eHnGywpCz/+yCcOOCZxJSBfkbMAxPjqli hDn59RBSfYbrYRLqyXaj5bcFmu6z7w1FApurl9yeLwtVXhNgwb9DNYUQC47iYq66fsJP 1yDsGKxKPsWVS25mCZbBKm9f9trU/xLu3vPv0WCrEaLTegdr2vFKyx1sNmaHaCJ9Ah7U 3zQA== 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=dXr+GIu8Zm+IAJzZ6mwmY2cDmvd5mo+b/fOvW2U8kdk=; b=kqD/Y0f4N3gV+4Nfv2CnyB3HbznSv7UKPT6hpHglCiDzkN4LdVP/Fsn6YD+yGL7DBj HQ8XHZqq2ITm37i8dL2qO0IfdTMXEmqDrHxZArs/L3eknYE8f2t++YfXIoupB7o84GB/ LxXr4abppyfTL1wodyFOqnYEEt+Y+yoLwF2irX4ecPOzvCWjORrMPzKsDzEIugHX+eeE KoUGKJSLLvIGVlM1EmuoaFwHgnmN4zsxiZkAR0pdAgG/8tClaCcfawpYpTyoXuGGT7tl mJ1gZtQIp0QSPjgIXtooaEoKAJZqouIdvIEftM5ArFlbdoMD/IX6WEx19LZrmYEpXarf ksSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b="ks/7oWLt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a170902c10600b001ab007aff67si3033324pli.32.2023.06.03.14.00.25; Sat, 03 Jun 2023 14:00:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b="ks/7oWLt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233584AbjFCUzX (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232378AbjFCUy7 (ORCPT ); Sat, 3 Jun 2023 16:54:59 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 095101A4; Sat, 3 Jun 2023 13:54:56 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 297185FD38; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825688; bh=dXr+GIu8Zm+IAJzZ6mwmY2cDmvd5mo+b/fOvW2U8kdk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ks/7oWLtr330mkiMnbGgANJJCiYqGyGQCEeTfb987iEuqYyr5+9r9b7DRlEB/pxeo ISh3gxPb/3LEcuMNoNYgRLI9Gptgxf2R2yCOxKCBkr157M2hIZ9joS9NM+YUMBok6U p1+9uCsE3tGbYXuxNX4vmmhNr/MdcYvLqq3M1x+VM/m/CVsPozGt4/AG2BTkDCfrWU yOJ7dLtrywEsY6o8xwEDzs54xtn/BRpJp+8AzoWNj1jLkKPUfjjKVotOBiEDG7yGau /w++evFeX9TSkItCLzrkwu1fNuixwtgHr+eix+AZ0W44OaOfJ3shSDNmdXkoe7Obm9 57Nn/Y8yExQnw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 08/17] vsock: check for MSG_ZEROCOPY support on send Date: Sat, 3 Jun 2023 23:49:30 +0300 Message-ID: <20230603204939.1598818-9-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716723072903966?= X-GMAIL-MSGID: =?utf-8?q?1767716723072903966?= This feature totally depends on transport, so if transport doesn't support it, return error. Signed-off-by: Arseniy Krasnov --- include/net/af_vsock.h | 7 +++++++ net/vmw_vsock/af_vsock.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 0e7504a42925..ec09edc5f3a0 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -177,6 +177,9 @@ struct vsock_transport { /* Read a single skb */ int (*read_skb)(struct vsock_sock *, skb_read_actor_t); + + /* Zero-copy. */ + bool (*msgzerocopy_allow)(void); }; /**** CORE ****/ @@ -243,4 +246,8 @@ static inline void __init vsock_bpf_build_proto(void) {} #endif +static inline bool vsock_msgzerocopy_allow(const struct vsock_transport *t) +{ + return t->msgzerocopy_allow && t->msgzerocopy_allow(); +} #endif /* __AF_VSOCK_H__ */ diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 07803d9fbf6d..033006e1b5ad 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1824,6 +1824,12 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg, goto out; } + if (msg->msg_flags & MSG_ZEROCOPY && + !vsock_msgzerocopy_allow(transport)) { + err = -EOPNOTSUPP; + goto out; + } + /* Wait for room in the produce queue to enqueue our user's data. */ timeout = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); From patchwork Sat Jun 3 20:49:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841685vqr; Sat, 3 Jun 2023 13:59:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6fD14aMJdHG3ngDR89i2gpFAYU7N6KdQngk1nH5qRz4FKG1uTyW88g7h9c29bEx2O/60IL X-Received: by 2002:a5b:48e:0:b0:bac:faf2:328f with SMTP id n14-20020a5b048e000000b00bacfaf2328fmr8013379ybp.6.1685825970887; Sat, 03 Jun 2023 13:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825970; cv=none; d=google.com; s=arc-20160816; b=ephK3D/eb3XjMOgtUfU3xgmlyC30vf8utN5xIHAnbzcIoA7DCnJQFxGKSJpS6OdpwN 2yg8V8UI/h7/CatArsbMDyVoJ2lu+88t0pReh+vDnwQCxpgCrTNoc37YjcXGg4az+QkH GDivvv/GMMplg+gRTzT8fQigDSYlrnVUBuTXL8smxWJED9Hz+yxV0mKQIJ7o9YgKJbka WiFNmi5R+yRL9oAUjhcn/d/IMpBIHLbwMFB66eo8kngUj9WaIEutWeadQ1qpChrI3slW Nr/8m5eztRzMPxgt8qTigeYn5+yatIb4imCxrwXgUYXYmI1uhwfa3fQnZR8OiIVNJAOR pNJQ== 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=HekjpGnl2zxNT3T4PtMzqPreuhYkvcvhGbre4mbN788=; b=xfH8bcFrsC3FcbNnFbuTyW19xxUJ90+UNZ7JU3UFDC3kRGleRmjetxuID2sdmz0Pt7 /up3Jh/5+jgOzDbfRXMYeyicqmaTT0F8+IIcxRYOcZ1SrOL5mvPFZNOBPUyTg+Fyyr+K KqkTGlm388SqZqlNBvYrqSgN+kHUEIdN95SsNaRAVw0bIeFToMvmmTWJ/rpCyAO/yGz8 pw+7ErNr+2XyWfDsK5U71SZb5hHwabqnZawbMzTJFd8PfVXuR0Rwq5b6YrW7bVmvPzKl cfy2gmSTUXZs5rkpCxLLiQi+XU/ppNO7FlfmiDNtaR3sAdtOH0pV9Z6173MlRLchRqmh 9Zsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=DOftSGo5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631753000000b005346bd7dee9si3093727pgx.682.2023.06.03.13.59.17; Sat, 03 Jun 2023 13:59:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=DOftSGo5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233669AbjFCUzz (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232454AbjFCUy7 (ORCPT ); Sat, 3 Jun 2023 16:54:59 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0614F197; Sat, 3 Jun 2023 13:54:56 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 6924E5FD39; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825688; bh=HekjpGnl2zxNT3T4PtMzqPreuhYkvcvhGbre4mbN788=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=DOftSGo5jo+m1kOZn1BX823Entw774YsTwmEx0s/oDAQnInujhEzATdLSri2+OWYa 437mQH8uge5FhXVuEjrmL9xzJINR9hE+wSYTkm8Go2L3tf9I/ZtqgsbRJiMFR/Bzh1 NZboWvgrY3W7o98G6QU7G7WFpM8jc9Z2ujC9WLSGWBeOEppHSsxBA+79ImUdNKQ8nG 0txlfzL06k/RoRXCiGw+xt3I+Bp+O5mfTBnzXlCGA8pIhx7jekcukLbkRJC1cOPhEW xE1xmwzhs1wdM6wvOzqcOMXatao06chVuQD2dzQhq9dtsw0UdPRpP5vMi+I+HqP8A2 pGbWf7fM5BHzw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 09/17] vsock: enable SOCK_SUPPORT_ZC bit Date: Sat, 3 Jun 2023 23:49:31 +0300 Message-ID: <20230603204939.1598818-10-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716653281509887?= X-GMAIL-MSGID: =?utf-8?q?1767716653281509887?= This bit is used by io_uring in case of zerocopy tx mode. io_uring code checks, that socket has this feature. This patch sets it in two places: 1) For socket in 'connect()' call. 2) For new socket which is returned by 'accept()' call. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/af_vsock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 033006e1b5ad..da22ae0ef477 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1406,6 +1406,9 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr, goto out; } + if (vsock_msgzerocopy_allow(transport)) + set_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); + err = vsock_auto_bind(vsk); if (err) goto out; @@ -1560,6 +1563,9 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags, } else { newsock->state = SS_CONNECTED; sock_graft(connected, newsock); + if (vsock_msgzerocopy_allow(vconnected->transport)) + set_bit(SOCK_SUPPORT_ZC, + &connected->sk_socket->flags); } release_sock(connected); From patchwork Sat Jun 3 20:49:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841046vqr; Sat, 3 Jun 2023 13:56:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5y3fIcTVbjWpCAgFT8h9bCUHGKhAxaNazZPTU9o/ffScX4BtpKQGf5JSxtPilQsUWNYknN X-Received: by 2002:a54:4593:0:b0:398:1186:88ba with SMTP id z19-20020a544593000000b00398118688bamr4039267oib.31.1685825780549; Sat, 03 Jun 2023 13:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825780; cv=none; d=google.com; s=arc-20160816; b=YTe/BIR4Q8m9iINK2hZMvmTm9LNP+0HGI2nnoMNyORH2EmnFo3O6r4EaWj1AWz7V8h O+zDYtQhVgtQY3XCqh+X+UYvv7M8Th2pgjTln/qkCCG6fSihuyzgiQJLAPHOm/XboS6n H/RVkVxKLWQQygn7k+rgjIj2rzEoe1fKi1Xz50JgXX44nSgCq6CLh5SHmp+obP98M/QH zbpGTvfqX1NZOyrxuvVUv3srPP+euMtwxCvwiKR+lNs9zsnHLS/E2afIDQrhs7hNkroC S+Hd6CRNwG5jrkbf8zWTqsvoMk+xx9eLfwowqgdbOI2U9do0Umb71nkfRn+FXEpzQHU/ SJXQ== 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=qcm1rcspds6nBbsYu4uQ/1LCrKuUtxLK5dK/r7j7bP0=; b=xSeo/lLm1aMt/6C7PeftvWEOrLbej0MSs/SZiU7AQfMyZ8JwDKRHcb7UhCdCG8PMM2 m+D5SzXCDCip8KyTnCND38HF9aMQLnHjX4STILUzJviIt11uGgJl0fQFSjmVLrLV1YLi +8gXFgCBPZ9leBabxdzU2bcMRW8MejuHjpV3PQgqIFrcybwRSB9mm9WBClARFFJP6pj3 QziWjxTG5V0U7VeOoUIBOrwf16oiS4LNcvNAeSqU4XqjadKiJdN0kbV/0rRFCBf09hcM au51tGewJBhhFBn6UHpv6GRELfYaGICYO73G30A5lZt+TAtLVT8TrKxG0c8YGAllIcTV eeaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=MmPb3KmO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a170902bd0500b001b0191881efsi3048578pls.37.2023.06.03.13.56.08; Sat, 03 Jun 2023 13:56:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=MmPb3KmO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbjFCUzU (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232349AbjFCUy7 (ORCPT ); Sat, 3 Jun 2023 16:54:59 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F4EF1AD; Sat, 3 Jun 2023 13:54:56 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id A6D9E5FD3A; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825688; bh=qcm1rcspds6nBbsYu4uQ/1LCrKuUtxLK5dK/r7j7bP0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=MmPb3KmOmDkAlNV7uQJUepnw9OHA0sbu+V9hSOt+o4uHHfRcTfkwCL7vVQHZecjf/ fz4LQ8/VsoT0rdtI7SQum1P2MpWfHGUIAVWncb8bZby02vbsO1G9+zBENFl0JTBlYC 2WRYJv0kDv7YSMr0DckwdUsXcRxBwaQSd0QhSLunG+Biu7ZzUo+gB3b8vk48YZtYPO 9j/RRyXAQxjLWQX+mJzGLhIoirDYwjUkY+qlVUH5odDLCfzASh5uzu+PxKjwLMK8Oh 3qcxsIwMIJS4sys8u6XnRtPn/1pAbAoMyRw5UIGYt7Dq15fT1T74dO5xp3omLGQaV0 Tmg/WZa4gz+wQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 10/17] vhost/vsock: support MSG_ZEROCOPY for transport Date: Sat, 3 Jun 2023 23:49:32 +0300 Message-ID: <20230603204939.1598818-11-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716453543612453?= X-GMAIL-MSGID: =?utf-8?q?1767716453543612453?= Add 'msgzerocopy_allow()' callback for vhost transport. Signed-off-by: Arseniy Krasnov --- drivers/vhost/vsock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index b254aa4b756a..318866713ef7 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -396,6 +396,11 @@ static bool vhost_vsock_more_replies(struct vhost_vsock *vsock) return val < vq->num; } +static bool vhost_transport_msgzerocopy_allow(void) +{ + return true; +} + static bool vhost_transport_seqpacket_allow(u32 remote_cid); static struct virtio_transport vhost_transport = { @@ -442,6 +447,7 @@ static struct virtio_transport vhost_transport = { .notify_buffer_size = virtio_transport_notify_buffer_size, .read_skb = virtio_transport_read_skb, + .msgzerocopy_allow = vhost_transport_msgzerocopy_allow, }, .send_pkt = vhost_transport_send_pkt, From patchwork Sat Jun 3 20:49:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1844759vqr; Sat, 3 Jun 2023 14:06:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5T/aQOoM3l6cKj6vXyyhTqMpbDTDWHCJDx1s3SGiAokj2g8PJojmC0Rx0eO4NeMds8Tvq8 X-Received: by 2002:a05:6a21:338f:b0:114:f824:655 with SMTP id yy15-20020a056a21338f00b00114f8240655mr330607pzb.58.1685826384906; Sat, 03 Jun 2023 14:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685826384; cv=none; d=google.com; s=arc-20160816; b=hIBErFhbmaTtRsh6NsBnLUfP3Wn4YqRyPtzvBMznOmCjd6NAF4cyohvObLoia5piZL exwAvS2p/rWP9X+xCjB6IY1M+SlASmmCqlSKK7y6ptqXf6t3E2Hl3PpmmLrhtYquGPPy QJki1r633ZZ8qETQLtLXc2D799TpQAYnV+K2vPOD3M3g8ey7A0mcUZstSmA4z00SD8JW NJh6YHkndXQatmhxa3LOia4AzQHBhRpS76DckT557aukAPNodaKZ/IjJJRcwXquQzavm V7Etrtpvf2hh8mqmxdctDs7oKQwZuvKNba1+YHniYHCkRReGqMu7b25dVSRYz2SHxgro IP8Q== 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=s7f/CfLQJryGc9if2/VYU5WFEpGy8lqbWfJnGVRm084=; b=mHrTXaGJoY3ro0S354xvDnFLMXn3iKUBSsrD80O2arIUgUN5DAKiK/s49goWSGaY8W oRhtOnv4QJf0NOOy8D/uSmT8HPzKsasIG+pvnAiyZNSs8Ff4nwa1/YBzKa0p1gyXxn3n 7yNkqNENaBuyxiPMHPXnc9Tc2wlQOWklY7UTuQ0SQlQ/QZkzKZW8cTv7UFAnbno4BE3U +yRkvuynPVnJVhFCPQ75jLuavGIc1otnf3grAEsCgTgSAp4vUmRrMvJ3gHv/2II17Xos DpaPid+5jcKmc/yc1n1jfcWQDAM6AP99sUCBQDVA08tPrVhF1n2xq1G9pgDqY9z1UkRD sCXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=RycjFhVi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631753000000b005346bd7dee9si3093727pgx.682.2023.06.03.14.06.12; Sat, 03 Jun 2023 14:06:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=RycjFhVi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbjFCUzb (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232738AbjFCUzF (ORCPT ); Sat, 3 Jun 2023 16:55:05 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E681B3; Sat, 3 Jun 2023 13:54:56 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id E6C6C5FD3B; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825688; bh=s7f/CfLQJryGc9if2/VYU5WFEpGy8lqbWfJnGVRm084=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=RycjFhViTCCFq7j0f484NCTdGFhR5aOYYJyrnGolcXq19hWg1MDLtcNa2f5NNUGEu cBqptqlP4FZzR9rZubfb8PhQCA30pChiPty3bxB+/nELqpRVsf6LKsSnvUMUhlsM+e skJ5TVarQ7GGpNbj0ppLHcCgMa/C8GVPg578oXNlkxkTrnYoxiYPadHsrJAz8tNu1D mdwZK62T8RqgAzifwok2MYd5Kyg6nqIDTi1EyCM6wvgotlBj8lmA+L7PfGsYoZXwpW 0RzzQMbi30g0aPKC0JSb2UG0Tmoi5XQlXyyhhUSAnvcXUSxbE7TKgWYjC4OEpdgCs+ 8U1nfszD18U2g== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:48 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 11/17] vsock/virtio: support MSG_ZEROCOPY for transport Date: Sat, 3 Jun 2023 23:49:33 +0300 Message-ID: <20230603204939.1598818-12-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767717087327056682?= X-GMAIL-MSGID: =?utf-8?q?1767717087327056682?= Add 'msgzerocopy_allow()' callback for virtio transport. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 6053d8341091..d9ffa16dda69 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -438,6 +438,11 @@ static void virtio_vsock_rx_done(struct virtqueue *vq) queue_work(virtio_vsock_workqueue, &vsock->rx_work); } +static bool virtio_transport_msgzerocopy_allow(void) +{ + return true; +} + static bool virtio_transport_seqpacket_allow(u32 remote_cid); static struct virtio_transport virtio_transport = { @@ -484,6 +489,8 @@ static struct virtio_transport virtio_transport = { .notify_buffer_size = virtio_transport_notify_buffer_size, .read_skb = virtio_transport_read_skb, + + .msgzerocopy_allow = virtio_transport_msgzerocopy_allow, }, .send_pkt = virtio_transport_send_pkt, From patchwork Sat Jun 3 20:49:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841298vqr; Sat, 3 Jun 2023 13:57:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7gqYX+JyE6bPuvuQRpYkBfs4d+XjQPhUZRuqLcx6gi2BLsazeCJHMhz84u47KPV0EgyySl X-Received: by 2002:a05:6358:4315:b0:123:3ea3:2bd2 with SMTP id r21-20020a056358431500b001233ea32bd2mr15406410rwc.32.1685825854440; Sat, 03 Jun 2023 13:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825854; cv=none; d=google.com; s=arc-20160816; b=LmM7mc/Lkbt8Us1TZ1SjYYmP+N7ufEXrM6ErcpZ4Y04id1+lKX0i5cM8vry5Q67lUK fa8IZmxn1Phncv3ZOrC783IMq221Bdgc9lAXhJ9rSdOZmMLDoTKyQxcaCw3TyUNSInsu lsSmNlb+NODr+RiY2ndiw6uxRWiu5AfG03HsESKDJQbuGY8JK/jRgaoNfY+rVwg+2ff6 uKmfT+dlRBgqdnSjm/Sw8CAY0MCk75g9Rd5cGkTZCG2UaUHocnn03yxzwMlKvU5A+8Vg PEARPpOeN+76PBKC7HJqkwRdKzdKhMdCzqqkCRXGCcT1kzt8xlya3FSy4Qh77ym3ZF9j UbkA== 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=26CL2gVE0g6kFd3ZFQdsGyNdyslfGmT/ZpPrRg3+nfI=; b=HdZxRPN2nptliGT1rzKVFvb2uPEfEVHd7Po5JBWoIOo0kPKptkAhOgN14ejMDvZ0JD SQOphc56jbgC8p9uS5yjr8v3qMq7Lgd83+qkAXG3+TG10JasqtiC5lqJWWrQ0NCpmVMx zKbDdGiPWy8iXjk77MIEBFD5ZCSM2mY203YqxQkMCZQl73U8UDF2KMwubgm4YLDp5KMi aFL2jh/CcREBjvGe30Lx3SSLNXfCd0qVNmTg3jzqskemd4TIckdcjE+H6MgtR67Ee765 AMeRGc1I2lQubhUYYSjbMeVodjVQGjPwFxmgVWDsc7sRa8ccQTyyysiETsw9y8bUSBXZ ZcBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=BKAbES7B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h27-20020a63385b000000b0051b37c000dcsi3059081pgn.81.2023.06.03.13.57.23; Sat, 03 Jun 2023 13:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=BKAbES7B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233657AbjFCUz2 (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232743AbjFCUzF (ORCPT ); Sat, 3 Jun 2023 16:55:05 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52D381B1; Sat, 3 Jun 2023 13:54:56 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 309645FD3C; Sat, 3 Jun 2023 23:54:49 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825689; bh=26CL2gVE0g6kFd3ZFQdsGyNdyslfGmT/ZpPrRg3+nfI=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=BKAbES7BoLlidpvw0rMtqdqB7xEXtgBURTVI82QeFolK4flgEV0OAt8pV9oMaKNMz G2bAelQ+UFia3yG6r0Sgbkso9tH0EJvEOrv3Oqdx9kU4YNtOAm5Qv66PI7Y61b5YqN FY07PX5itx9jBaOa4ekgBC+omDbdDXZCX8vRWlzXg23Rc/+/CRhW/rFg/fnVXbdFtt bRQiCz6elxUCfTWOcpa39yp30jI35ajzDyh8eIKXNbWtMyVhGPgM13+JcmFKbFaq9g oX0O+zH0GKH9U2Q/HqFll/NFiyHFYNCXjtZ0FvniLjLiViWUDJUkINLGTs4qMD5Pho aNOsouh71frMA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:49 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 12/17] vsock/loopback: support MSG_ZEROCOPY for transport Date: Sat, 3 Jun 2023 23:49:34 +0300 Message-ID: <20230603204939.1598818-13-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716531002311432?= X-GMAIL-MSGID: =?utf-8?q?1767716531002311432?= Add 'msgzerocopy_allow()' callback for loopback transport. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/vsock_loopback.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/vmw_vsock/vsock_loopback.c b/net/vmw_vsock/vsock_loopback.c index 5c6360df1f31..a2e4aeda2d92 100644 --- a/net/vmw_vsock/vsock_loopback.c +++ b/net/vmw_vsock/vsock_loopback.c @@ -47,6 +47,7 @@ static int vsock_loopback_cancel_pkt(struct vsock_sock *vsk) } static bool vsock_loopback_seqpacket_allow(u32 remote_cid); +static bool vsock_loopback_msgzerocopy_allow(void); static struct virtio_transport loopback_transport = { .transport = { @@ -92,11 +93,18 @@ static struct virtio_transport loopback_transport = { .notify_buffer_size = virtio_transport_notify_buffer_size, .read_skb = virtio_transport_read_skb, + + .msgzerocopy_allow = vsock_loopback_msgzerocopy_allow, }, .send_pkt = vsock_loopback_send_pkt, }; +static bool vsock_loopback_msgzerocopy_allow(void) +{ + return true; +} + static bool vsock_loopback_seqpacket_allow(u32 remote_cid) { return true; From patchwork Sat Jun 3 20:49:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841342vqr; Sat, 3 Jun 2023 13:57:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48XllRIJNsqYQu3EbOjN0yHPKSyzIL0aPHAbin1SDuNNDbMqRAVW91tNC/7+lcC/H+BcDO X-Received: by 2002:a05:6359:d08:b0:127:f952:6b9f with SMTP id gp8-20020a0563590d0800b00127f9526b9fmr4029362rwb.10.1685825865510; Sat, 03 Jun 2023 13:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825865; cv=none; d=google.com; s=arc-20160816; b=PfGpR8Vbb157bK6YXyb2Qp8v4u1d2YOdR3GGeP75rltH4/aqtdj0KErQll4ny+4QOA q1uEIJctFMFQ/lL7ElhBZnyI4nqCTPMVqMPCT8LJCRxBvp/owNuz21hH+qbbbMfqYCQb ezwwwUT4inLg1j8aP2bZ1offrIJSBgwV0MTStY/DIa3v/+kY0e6X6SMJ9q2emY0DuMtL PpPouoeXzLpiG9rGs7DysCRqGUYUqCMdZZGxDScYh0JSOggCSIR1Ba0pRVdK1eYbwI1V U3JzZmaspHvEb6+GqvFkAkHq+Z/NqCBJRP5eyTI7uuSc49j/eXa0ovL2E0ANTYTlesMV 7eiA== 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=Lcii1bQY+QJwpWB+RMSKu82Ek54JP6VHZpwuHhErzzg=; b=pGRKmptf8rnCAWvTVqyyVPDerQAXOfU4f4nc05VCIBKgLck/tF255/eTJJxFFCwoE1 NyQBuub7ig+TYgxkvjCEwlkYCgMIMLO318lPHhrkg8X/bivk8GrPJLBwHSTJvwMsrQzw cwEr3kfZHAe+AeO+gju7nmb6Et13EVAaE3NA994mQuFiOUQM7AP+cbBDzv+E+8Q2tVk9 W8U3YDCwUGT2XCvSQasKwudqOKDuO6ewz82VDqPFLSmPRCH30lVBwN7mM/wBeLU8G0CH 69KrV2CG5hLo8Q0a5WTMLZPS3fv/Igwi1YSEF6laNMxbcX/G2ugGu1iThm6qNoKZlEN5 fRFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Jg52u5GE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x18-20020a17090aca1200b002536c5eb7cfsi4983933pjt.58.2023.06.03.13.57.33; Sat, 03 Jun 2023 13:57:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Jg52u5GE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233642AbjFCUzl (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232898AbjFCUzG (ORCPT ); Sat, 3 Jun 2023 16:55:06 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 736911B5; Sat, 3 Jun 2023 13:54:57 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 745FE5FD3D; Sat, 3 Jun 2023 23:54:49 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825689; bh=Lcii1bQY+QJwpWB+RMSKu82Ek54JP6VHZpwuHhErzzg=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Jg52u5GEQEg5YduLkopjTNW3BjaxbL328jtMgCcJGiSHEe1c5falJz5UAYOmb8btl 7f+eJRuv3Sl6eX4w42HLrim/lrm6Jmi0hABMEJK1ZpKpIVg/qPJCqgcdAmvq725dJ5 7lNxZpdDEl9jm+a2IhMiHWQjyjDQeFfoRpRS/lzABhlrc4QyEEjLuYQ5jxIfWlN2vv YrxGR+OA1+/8rmM2/Zd9ESP90sE4ScNs4TcpAkZzXGHwTA5TI6EeX5B9PWsp0w9Etf 1huTfS4oouFZtvh/6LZeIZP/GfZIc+FGrSPJ3X6ACxZKCNqpFeX6KhEzv9q8K/ie1v nSE+Wie9B5LZg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:49 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 13/17] net/sock: enable setting SO_ZEROCOPY for PF_VSOCK Date: Sat, 3 Jun 2023 23:49:35 +0300 Message-ID: <20230603204939.1598818-14-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716542790421854?= X-GMAIL-MSGID: =?utf-8?q?1767716542790421854?= PF_VSOCK supports MSG_ZEROCOPY transmission, so SO_ZEROCOPY could be enabled. PF_VSOCK implementation is a little bit special comparing to PF_INET - MSG_ZEROCOPY support depends on transport layer of PF_VSOCK, but here we can't "ask" its transport, so setting of this option is always allowed, but if some transport doesn't support zerocopy tx, send callback of PF_VSOCK will return -EOPNOTSUPP. Signed-off-by: Arseniy Krasnov --- net/core/sock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/core/sock.c b/net/core/sock.c index 5440e67bcfe3..d558e541e6d7 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1452,9 +1452,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname, (sk->sk_type == SOCK_DGRAM && sk->sk_protocol == IPPROTO_UDP))) ret = -EOPNOTSUPP; - } else if (sk->sk_family != PF_RDS) { + } else if (sk->sk_family != PF_RDS && + sk->sk_family != PF_VSOCK) { ret = -EOPNOTSUPP; } + if (!ret) { if (val < 0 || val > 1) ret = -EINVAL; From patchwork Sat Jun 3 20:49:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841110vqr; Sat, 3 Jun 2023 13:56:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VgVVTrd8vKvF7LTUjfgv9yDA5YXhWPXDktzSGaDG45iTdKoxJasA/2Zv2FZMaa5I+fkEF X-Received: by 2002:a05:6870:a487:b0:18b:999:aa27 with SMTP id j7-20020a056870a48700b0018b0999aa27mr5105453oal.52.1685825799308; Sat, 03 Jun 2023 13:56:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825799; cv=none; d=google.com; s=arc-20160816; b=vSAVVxSG1XAMoBvD4cdm1mAHqegpib0uL35epUYQmeHJ9iOpVTrM52tnswNr/vBIl8 JapTDoC47d+YcB2vl3Uviw7BTElChEN83lM/o9kMaqsN/gZsd9S6e/8uia7on/vHYTvq MooaWpDcn84yKR6AuthtlETtQH8Dm+oj+P3/7LJ2wYL8Av6ntbbTcIyAjBK9TVqsu6+y 3bnTqFbR53cd7R24EILXW74/vgo9w6zHW3kSm7ChGG/KEtdxy7rpYeHYJ6ANb2Qaeaz4 tAStUTTuX/OxSkNokHV0kz8dsR+zSmjswSDVwAmvDHl4n5P9OJadCKz+IaK7rmObtwlk lirQ== 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=tL2E1Y90S5bBkA16ZM0oXYsz18KCFk1Zn9JPdTBbPT8=; b=Zu6nhdsa6UeRt1BDF6mQEHQJzudHWDpYylur4cDQePZ+FF8uXuQrKjjxm+OSXWTxGA vwg2dqwmHRJKCStStpKK313Ksccl9uh3vD+cdTZkYeFh0nOE76TfuUDPbBLdTn47cwAS 0DennDqyHT83QFms5iCy6A6BNAbB67N5bX7a1hPQRBFFLViRbRBXPGTlHzvcSi8bVXnl H2GcP6rRLayihKiJIgwqjuSWScyXyflxYGQSPZJ7cIRYFaUJoKnou2+whul1e6UuGINa Hi6hhb/gVYW1DEbsi2ar+rtbjbpq/vZXdpTaeeI3ujE07ojPm5aSyhiXcIPJuLVugN5Q z9Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=RkDGbgFF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u72-20020a63794b000000b0053f24deef11si3124344pgc.318.2023.06.03.13.56.27; Sat, 03 Jun 2023 13:56:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=RkDGbgFF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233786AbjFCUzi (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232935AbjFCUzG (ORCPT ); Sat, 3 Jun 2023 16:55:06 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 703E71B4; Sat, 3 Jun 2023 13:54:57 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id B1DF35FD3E; Sat, 3 Jun 2023 23:54:49 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825689; bh=tL2E1Y90S5bBkA16ZM0oXYsz18KCFk1Zn9JPdTBbPT8=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=RkDGbgFFU3bql1NGpMnKp+sa9IgXSPVYdj8wJKb0NlMmUzuWkI6vLkSJpc/A+hgXp kR74vj1zoSnvFHiZ/jjkyeTAL+IDmnGVsFcYNElktnQq56H/m8OuWBEgXWTWFEdEQE Pw/mXw40KB8+rXlmn1YmxHnmqkxOepdFxD9Z8klnFZAy8P83qOLcEx67Vyq8jVf7On K7URpoNHn090hPm81Ta1ZjcuFkpe9DSkSiPlOa47oadsbBuvBF3/xzUN4URPbFjO7W /zA3FCSJ+1IPqEFggnPF0HpLRlR9kK1qvFbnp5T5CZ2lcFlIqXdwDJ6Sk88BrGWVYR dmqRm3sQsVYew== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:49 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 14/17] docs: net: description of MSG_ZEROCOPY for AF_VSOCK Date: Sat, 3 Jun 2023 23:49:36 +0300 Message-ID: <20230603204939.1598818-15-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716473316667855?= X-GMAIL-MSGID: =?utf-8?q?1767716473316667855?= This adds description of MSG_ZEROCOPY flag support for AF_VSOCK type of socket. Signed-off-by: Arseniy Krasnov --- Documentation/networking/msg_zerocopy.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/msg_zerocopy.rst b/Documentation/networking/msg_zerocopy.rst index b3ea96af9b49..34bc7ff411ce 100644 --- a/Documentation/networking/msg_zerocopy.rst +++ b/Documentation/networking/msg_zerocopy.rst @@ -7,7 +7,8 @@ Intro ===== The MSG_ZEROCOPY flag enables copy avoidance for socket send calls. -The feature is currently implemented for TCP and UDP sockets. +The feature is currently implemented for TCP, UDP and VSOCK (with +virtio transport) sockets. Opportunity and Caveats @@ -174,7 +175,7 @@ read_notification() call in the previous snippet. A notification is encoded in the standard error format, sock_extended_err. The level and type fields in the control data are protocol family -specific, IP_RECVERR or IPV6_RECVERR. +specific, IP_RECVERR or IPV6_RECVERR (for TCP or UDP socket). Error origin is the new type SO_EE_ORIGIN_ZEROCOPY. ee_errno is zero, as explained before, to avoid blocking read and write system calls on @@ -201,6 +202,7 @@ undefined, bar for ee_code, as discussed below. printf("completed: %u..%u\n", serr->ee_info, serr->ee_data); +For VSOCK socket, cmsg_level will be SOL_VSOCK and cmsg_type will be 0. Deferred copies ~~~~~~~~~~~~~~~ @@ -235,12 +237,15 @@ Implementation Loopback -------- +For TCP and UDP: Data sent to local sockets can be queued indefinitely if the receive process does not read its socket. Unbound notification latency is not acceptable. For this reason all packets generated with MSG_ZEROCOPY that are looped to a local socket will incur a deferred copy. This includes looping onto packet sockets (e.g., tcpdump) and tun devices. +For VSOCK: +Data path sent to local sockets is the same as for non-local sockets. Testing ======= @@ -254,3 +259,6 @@ instance when run with msg_zerocopy.sh between a veth pair across namespaces, the test will not show any improvement. For testing, the loopback restriction can be temporarily relaxed by making skb_orphan_frags_rx identical to skb_orphan_frags. + +For VSOCK type of socket example can be found in tools/testing/vsock/ +vsock_test_zerocopy.c. From patchwork Sat Jun 3 20:49:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841167vqr; Sat, 3 Jun 2023 13:56:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5j0dpDEs3rQ9tsYexVVRuQ0YW4F4qvNIasOnObj69jESTMp0fJ9ubg4JQ9BUW7zta9JSl4 X-Received: by 2002:a05:6a20:3d05:b0:111:366:eea4 with SMTP id y5-20020a056a203d0500b001110366eea4mr3452983pzi.57.1685825816866; Sat, 03 Jun 2023 13:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825816; cv=none; d=google.com; s=arc-20160816; b=BG7ttS7V/h9ceIWlvh5/LiU2p58UwSXCP3r8n9FoQBEcGyY+ROr82u4PX2q5N8xyAj WtR0XdN2zIDV1r6coQpnH+4C28MeAwrW17bbVmzPVdzctD6AZGeivBcX1wABmpo1ISVd ldhqS3SuvOWIxCHZ0AKmLc/QqIR/K4GNPL8ThpFLoPsLVT9jW3ZHZfZW7Y2d7TfCXCXd ASCmwxD01zi+psOpQMuopus3sn4GkX2J82xEgliDJE3NcZwn1XmknCSN3AGUXMSc8VHe FO0fm1jvBiOWAHONVzdyw8mEm+q9spzzr8ByN2P7mDYg9Z69TFjvQjKK8o2CzgdpH/0X 6XyA== 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=viwHYEvceGtDMUIG+aX6fN6oIIWnfCEIyG3Bl7nwYVc=; b=zyZM/70j2ag8aNGsoQ6ILqbK7k97270+79UI1XU8GxaaxlVMDBgbH/7P+O0Qthmmo6 RcuzkMFrVAtANyOW4fhINrchImZFKoytZX/Ta/Pqfda9M8VALVuPM6jzVYsN3GfPadEb OdpzsXGH99zVf6GAa9Wb2k7y7d9DC9ttVixMgPT2WwsCe6mRjqGKoQdpcrCYNDEeimiG xxnNwodNrhujyYkAZ1Zj3GurbaTr8M3+GuYvSMG9OwTEffTZ66F2fuJ4vRdaM/l9jfiA ipAq2eXo9pXZVLKSF4Sz7T71Y2KoC0LlcGG0ApNAXELpepvqgDqIcNcWXGaPkW7VgOhH le+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=WpCnBw7x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631753000000b005346bd7dee9si3093727pgx.682.2023.06.03.13.56.44; Sat, 03 Jun 2023 13:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=WpCnBw7x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233900AbjFCU4B (ORCPT + 99 others); Sat, 3 Jun 2023 16:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbjFCUzH (ORCPT ); Sat, 3 Jun 2023 16:55:07 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F27711B8; Sat, 3 Jun 2023 13:54:59 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 04A085FD3F; Sat, 3 Jun 2023 23:54:50 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825690; bh=viwHYEvceGtDMUIG+aX6fN6oIIWnfCEIyG3Bl7nwYVc=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WpCnBw7xTxwmFDHHr1ihsxJZknnFcUKm3pLdKM+YSxGTUlmubcnI1smELp2XcMddv P8mqHc4Kv3JMK+9w2GTEUosfI+rB4ji1cyc948Guf1m8dHbfgA84/AzAE63GXJvhD9 jv8i/HsO8a3wRbwqgF9QtbOnHAplmosZoi/zA9FuRZb/pK+nlsgrrEqo563xwQ2Hlo iusUj7g9iHOT27mQiRayIjsOZcXpi7uvzEiYO3DMknBdSW3NvTJZWRM0fRiQ3nzeGG 0wiRZNuMaUTK20crgrNdauOYhGS64NqsGc8lZVt2Ux3hsvRASwwbwzhYifBtMiefyN cqr6CosXZWD5g== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:49 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 15/17] test/vsock: MSG_ZEROCOPY flag tests Date: Sat, 3 Jun 2023 23:49:37 +0300 Message-ID: <20230603204939.1598818-16-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716491764288464?= X-GMAIL-MSGID: =?utf-8?q?1767716491764288464?= This adds three tests for MSG_ZEROCOPY feature: 1) SOCK_STREAM tx with different buffers. 1) SOCK_SEQPACKET tx with different buffers. 1) SOCK_STREAM test to read empty error queue of the socket. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/Makefile | 2 +- tools/testing/vsock/util.c | 218 +++++++++++++++ tools/testing/vsock/util.h | 18 ++ tools/testing/vsock/vsock_test.c | 16 ++ tools/testing/vsock/vsock_test_zerocopy.c | 312 ++++++++++++++++++++++ tools/testing/vsock/vsock_test_zerocopy.h | 15 ++ 6 files changed, 580 insertions(+), 1 deletion(-) create mode 100644 tools/testing/vsock/vsock_test_zerocopy.c create mode 100644 tools/testing/vsock/vsock_test_zerocopy.h diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile index 43a254f0e14d..0a78787d1d92 100644 --- a/tools/testing/vsock/Makefile +++ b/tools/testing/vsock/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only all: test vsock_perf test: vsock_test vsock_diag_test -vsock_test: vsock_test.o timeout.o control.o util.o +vsock_test: vsock_test.o vsock_test_zerocopy.o timeout.o control.o util.o vsock_diag_test: vsock_diag_test.o timeout.o control.o util.o vsock_perf: vsock_perf.o diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 01b636d3039a..81bc7fdafe03 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -11,15 +11,23 @@ #include #include #include +#include #include #include #include #include +#include +#include +#include #include "timeout.h" #include "control.h" #include "util.h" +#ifndef SOL_VSOCK +#define SOL_VSOCK 287 +#endif + /* Install signal handlers */ void init_signals(void) { @@ -408,3 +416,213 @@ unsigned long hash_djb2(const void *data, size_t len) return hash; } + +void enable_so_zerocopy(int fd) +{ + int val = 1; + + if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val))) { + perror("mmap"); + exit(EXIT_FAILURE); + } +} + +static void *mmap_no_fail(size_t bytes) +{ + void *res; + + res = mmap(NULL, bytes, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); + if (res == MAP_FAILED) { + perror("mmap"); + exit(EXIT_FAILURE); + } + + return res; +} + +size_t iovec_bytes(const struct iovec *iov, size_t iovnum) +{ + size_t bytes; + int i; + + for (bytes = 0, i = 0; i < iovnum; i++) + bytes += iov[i].iov_len; + + return bytes; +} + +static void iovec_random_init(struct iovec *iov, + const struct vsock_test_data *test_data) +{ + int i; + + for (i = 0; i < test_data->vecs_cnt; i++) { + int j; + + if (test_data->vecs[i].iov_base == MAP_FAILED) + continue; + + for (j = 0; j < iov[i].iov_len; j++) + ((uint8_t *)iov[i].iov_base)[j] = rand() & 0xff; + } +} + +unsigned long iovec_hash_djb2(struct iovec *iov, size_t iovnum) +{ + unsigned long hash; + size_t iov_bytes; + size_t offs; + void *tmp; + int i; + + iov_bytes = iovec_bytes(iov, iovnum); + + tmp = malloc(iov_bytes); + if (!tmp) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + for (offs = 0, i = 0; i < iovnum; i++) { + memcpy(tmp + offs, iov[i].iov_base, iov[i].iov_len); + offs += iov[i].iov_len; + } + + hash = hash_djb2(tmp, iov_bytes); + free(tmp); + + return hash; +} + +struct iovec *iovec_from_test_data(const struct vsock_test_data *test_data) +{ + const struct iovec *test_iovec; + struct iovec *iovec; + int i; + + iovec = malloc(sizeof(*iovec) * test_data->vecs_cnt); + if (!iovec) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + test_iovec = test_data->vecs; + + for (i = 0; i < test_data->vecs_cnt; i++) { + iovec[i].iov_len = test_iovec[i].iov_len; + iovec[i].iov_base = mmap_no_fail(test_iovec[i].iov_len); + + if (test_iovec[i].iov_base != MAP_FAILED && + test_iovec[i].iov_base) + iovec[i].iov_base += (uintptr_t)test_iovec[i].iov_base; + } + + /* Unmap "invalid" elements. */ + for (i = 0; i < test_data->vecs_cnt; i++) { + if (test_iovec[i].iov_base == MAP_FAILED) { + if (munmap(iovec[i].iov_base, iovec[i].iov_len)) { + perror("munmap"); + exit(EXIT_FAILURE); + } + } + } + + iovec_random_init(iovec, test_data); + + return iovec; +} + +void free_iovec_test_data(const struct vsock_test_data *test_data, + struct iovec *iovec) +{ + int i; + + for (i = 0; i < test_data->vecs_cnt; i++) { + if (test_data->vecs[i].iov_base != MAP_FAILED) { + if (test_data->vecs[i].iov_base) + iovec[i].iov_base -= (uintptr_t)test_data->vecs[i].iov_base; + + if (munmap(iovec[i].iov_base, iovec[i].iov_len)) { + perror("munmap"); + exit(EXIT_FAILURE); + } + } + } + + free(iovec); +} + +#define POLL_TIMEOUT_MS 100 +void vsock_recv_completion(int fd, bool zerocopied, bool completion) +{ + struct sock_extended_err *serr; + struct msghdr msg = { 0 }; + struct pollfd fds = { 0 }; + char cmsg_data[128]; + struct cmsghdr *cm; + ssize_t res; + + fds.fd = fd; + fds.events = 0; + + if (poll(&fds, 1, POLL_TIMEOUT_MS) < 0) { + perror("poll"); + exit(EXIT_FAILURE); + } + + if (!(fds.revents & POLLERR)) { + if (completion) { + fprintf(stderr, "POLLERR expected\n"); + exit(EXIT_FAILURE); + } else { + return; + } + } + + msg.msg_control = cmsg_data; + msg.msg_controllen = sizeof(cmsg_data); + + res = recvmsg(fd, &msg, MSG_ERRQUEUE); + if (res) { + fprintf(stderr, "failed to read error queue: %zi\n", res); + exit(EXIT_FAILURE); + } + + cm = CMSG_FIRSTHDR(&msg); + if (!cm) { + fprintf(stderr, "cmsg: no cmsg\n"); + exit(EXIT_FAILURE); + } + + if (cm->cmsg_level != SOL_VSOCK) { + fprintf(stderr, "cmsg: unexpected 'cmsg_level'\n"); + exit(EXIT_FAILURE); + } + + if (cm->cmsg_type != 0) { + fprintf(stderr, "cmsg: unexpected 'cmsg_type'\n"); + exit(EXIT_FAILURE); + } + + serr = (void *)CMSG_DATA(cm); + if (serr->ee_origin != SO_EE_ORIGIN_ZEROCOPY) { + fprintf(stderr, "serr: wrong origin: %u\n", serr->ee_origin); + exit(EXIT_FAILURE); + } + + if (serr->ee_errno) { + fprintf(stderr, "serr: wrong error code: %u\n", serr->ee_errno); + exit(EXIT_FAILURE); + } + + if (zerocopied && (serr->ee_code & SO_EE_CODE_ZEROCOPY_COPIED)) { + fprintf(stderr, "serr: was copy instead of zerocopy\n"); + exit(EXIT_FAILURE); + } + + if (!zerocopied && !(serr->ee_code & SO_EE_CODE_ZEROCOPY_COPIED)) { + fprintf(stderr, "serr: was zerocopy instead of copy\n"); + exit(EXIT_FAILURE); + } +} diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index fb99208a95ea..d07c1a9c2e0a 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -2,6 +2,7 @@ #ifndef UTIL_H #define UTIL_H +#include #include #include @@ -18,6 +19,16 @@ struct test_opts { unsigned int peer_cid; }; +#define VSOCK_TEST_DATA_MAX_IOV 4 + +struct vsock_test_data { + bool zerocopied; /* Data must be zerocopied. */ + bool completion; /* Must dequeue completion. */ + int sendmsg_errno; /* 'errno' after 'sendmsg()'. */ + int vecs_cnt; /* Number of elements in 'vecs'. */ + struct iovec vecs[VSOCK_TEST_DATA_MAX_IOV]; +}; + /* A test case definition. Test functions must print failures to stderr and * terminate with exit(EXIT_FAILURE). */ @@ -50,4 +61,11 @@ void list_tests(const struct test_case *test_cases); void skip_test(struct test_case *test_cases, size_t test_cases_len, const char *test_id_str); unsigned long hash_djb2(const void *data, size_t len); +void enable_so_zerocopy(int fd); +size_t iovec_bytes(const struct iovec *iov, size_t iovnum); +unsigned long iovec_hash_djb2(struct iovec *iov, size_t iovnum); +struct iovec *iovec_from_test_data(const struct vsock_test_data *test_data); +void free_iovec_test_data(const struct vsock_test_data *test_data, + struct iovec *iovec); +void vsock_recv_completion(int fd, bool zerocopied, bool completion); #endif /* UTIL_H */ diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index ac1bd3ac1533..d576b18bd357 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -20,6 +20,7 @@ #include #include +#include "vsock_test_zerocopy.h" #include "timeout.h" #include "control.h" #include "util.h" @@ -1128,6 +1129,21 @@ static struct test_case test_cases[] = { .run_client = test_stream_virtio_skb_merge_client, .run_server = test_stream_virtio_skb_merge_server, }, + { + .name = "SOCK_STREAM MSG_ZEROCOPY", + .run_client = test_stream_msg_zcopy_client, + .run_server = test_stream_msg_zcopy_server, + }, + { + .name = "SOCK_SEQPACKET MSG_ZEROCOPY", + .run_client = test_seqpacket_msg_zcopy_client, + .run_server = test_seqpacket_msg_zcopy_server, + }, + { + .name = "SOCK_STREAM MSG_ZEROCOPY empty MSG_ERRQUEUE", + .run_client = test_stream_msg_zcopy_empty_errq_client, + .run_server = test_stream_msg_zcopy_empty_errq_server, + }, {}, }; diff --git a/tools/testing/vsock/vsock_test_zerocopy.c b/tools/testing/vsock/vsock_test_zerocopy.c new file mode 100644 index 000000000000..c5539c5dbded --- /dev/null +++ b/tools/testing/vsock/vsock_test_zerocopy.c @@ -0,0 +1,312 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* MSG_ZEROCOPY feature tests for vsock + * + * Copyright (C) 2023 SberDevices. + * + * Author: Arseniy Krasnov + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "control.h" +#include "vsock_test_zerocopy.h" + +#define PAGE_SIZE 4096 + +static struct vsock_test_data test_data_array[] = { + /* Last element has non-page aligned size. */ + { + .zerocopied = true, + .completion = true, + .sendmsg_errno = 0, + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { NULL, PAGE_SIZE }, + { NULL, 200 } + } + }, + /* All elements have page aligned base and size. */ + { + .zerocopied = true, + .completion = true, + .sendmsg_errno = 0, + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { NULL, PAGE_SIZE * 2 }, + { NULL, PAGE_SIZE * 3 } + } + }, + /* All elements have page aligned base and size. But + * data length is bigger than 64Kb. + */ + { + .zerocopied = true, + .completion = true, + .sendmsg_errno = 0, + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE * 16 }, + { NULL, PAGE_SIZE * 16 }, + { NULL, PAGE_SIZE * 16 } + } + }, + /* All elements have page aligned base and size. */ + { + .zerocopied = true, + .completion = true, + .sendmsg_errno = 0, + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { NULL, PAGE_SIZE }, + { NULL, PAGE_SIZE } + } + }, + /* Middle element has non-page aligned size. */ + { + .zerocopied = true, + .completion = true, + .sendmsg_errno = 0, + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { NULL, 100 }, + { NULL, PAGE_SIZE } + } + }, + /* Middle element has both non-page aligned base and size. */ + { + .zerocopied = true, + .completion = true, + .sendmsg_errno = 0, + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { (void *)1, 100 }, + { NULL, PAGE_SIZE } + } + }, + /* Middle element is unmapped. */ + { + .zerocopied = false, + .completion = false, + .sendmsg_errno = ENOMEM, + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { MAP_FAILED, PAGE_SIZE }, + { NULL, PAGE_SIZE } + } + }, + /* Valid data, but SO_ZEROCOPY is off. */ + { + .zerocopied = true, + .completion = false, + .sendmsg_errno = 0, + .vecs_cnt = 1, + { + { NULL, PAGE_SIZE } + } + }, +}; + +static void __test_msg_zerocopy_client(const struct test_opts *opts, + const struct vsock_test_data *test_data, + bool sock_seqpacket) +{ + struct msghdr msg = { 0 }; + ssize_t sendmsg_res; + struct iovec *iovec; + int fd; + + if (sock_seqpacket) + fd = vsock_seqpacket_connect(opts->peer_cid, 1234); + else + fd = vsock_stream_connect(opts->peer_cid, 1234); + + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + if (test_data->completion) + enable_so_zerocopy(fd); + + iovec = iovec_from_test_data(test_data); + + msg.msg_iov = iovec; + msg.msg_iovlen = test_data->vecs_cnt; + + errno = 0; + + sendmsg_res = sendmsg(fd, &msg, MSG_ZEROCOPY); + if (errno != test_data->sendmsg_errno) { + fprintf(stderr, "expected 'errno' == %i, got %i\n", + test_data->sendmsg_errno, errno); + exit(EXIT_FAILURE); + } + + if (!errno) { + if (sendmsg_res != iovec_bytes(iovec, test_data->vecs_cnt)) { + fprintf(stderr, "expected 'sendmsg()' == %li, got %li\n", + iovec_bytes(iovec, test_data->vecs_cnt), + sendmsg_res); + exit(EXIT_FAILURE); + } + } + + vsock_recv_completion(fd, test_data->zerocopied, test_data->completion); + + if (test_data->sendmsg_errno == 0) + control_writeulong(iovec_hash_djb2(iovec, test_data->vecs_cnt)); + else + control_writeulong(0); + + control_writeln("DONE"); + free_iovec_test_data(test_data, iovec); + close(fd); +} + +void test_stream_msg_zcopy_client(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + __test_msg_zerocopy_client(opts, &test_data_array[i], false); +} + +void test_seqpacket_msg_zcopy_client(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + __test_msg_zerocopy_client(opts, &test_data_array[i], true); +} + +static void __test_stream_server(const struct test_opts *opts, + const struct vsock_test_data *test_data, + bool sock_seqpacket) +{ + unsigned long remote_hash; + unsigned long local_hash; + ssize_t total_bytes_rec; + unsigned char *data; + size_t data_len; + int fd; + + if (sock_seqpacket) + fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); + else + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + data_len = iovec_bytes(test_data->vecs, test_data->vecs_cnt); + + data = malloc(data_len); + if (!data) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + total_bytes_rec = 0; + + while (total_bytes_rec != data_len) { + ssize_t bytes_rec; + + bytes_rec = read(fd, data + total_bytes_rec, + data_len - total_bytes_rec); + if (bytes_rec <= 0) + break; + + total_bytes_rec += bytes_rec; + } + + if (test_data->sendmsg_errno == 0) + local_hash = hash_djb2(data, data_len); + else + local_hash = 0; + + free(data); + + /* Waiting for some result. */ + remote_hash = control_readulong(); + if (remote_hash != local_hash) { + fprintf(stderr, "hash mismatch\n"); + exit(EXIT_FAILURE); + } + + control_expectln("DONE"); + close(fd); +} + +void test_stream_msg_zcopy_server(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + __test_stream_server(opts, &test_data_array[i], false); +} + +void test_seqpacket_msg_zcopy_server(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + __test_stream_server(opts, &test_data_array[i], true); +} + +void test_stream_msg_zcopy_empty_errq_client(const struct test_opts *opts) +{ + struct msghdr msg = { 0 }; + char cmsg_data[128]; + ssize_t res; + int fd; + + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + msg.msg_control = cmsg_data; + msg.msg_controllen = sizeof(cmsg_data); + + res = recvmsg(fd, &msg, MSG_ERRQUEUE); + if (res != -1) { + fprintf(stderr, "expected 'recvmsg(2)' failure, got %zi\n", + res); + exit(EXIT_FAILURE); + } + + control_writeln("DONE"); + close(fd); +} + +void test_stream_msg_zcopy_empty_errq_server(const struct test_opts *opts) +{ + int fd; + + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + control_expectln("DONE"); + close(fd); +} diff --git a/tools/testing/vsock/vsock_test_zerocopy.h b/tools/testing/vsock/vsock_test_zerocopy.h new file mode 100644 index 000000000000..220b4f94f042 --- /dev/null +++ b/tools/testing/vsock/vsock_test_zerocopy.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef VSOCK_TEST_ZEROCOPY_H +#define VSOCK_TEST_ZEROCOPY_H +#include "util.h" + +void test_stream_msg_zcopy_client(const struct test_opts *opts); +void test_stream_msg_zcopy_server(const struct test_opts *opts); + +void test_seqpacket_msg_zcopy_client(const struct test_opts *opts); +void test_seqpacket_msg_zcopy_server(const struct test_opts *opts); + +void test_stream_msg_zcopy_empty_errq_client(const struct test_opts *opts); +void test_stream_msg_zcopy_empty_errq_server(const struct test_opts *opts); + +#endif /* VSOCK_TEST_ZEROCOPY_H */ From patchwork Sat Jun 3 20:49:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841131vqr; Sat, 3 Jun 2023 13:56:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4eph95Htu+HMUxL0qaux9HCcRrM329yWfGjsAB+iODBrJVMWf1xqfhCmRSSb76eJ4SsQC/ X-Received: by 2002:a05:6808:3a87:b0:39a:622e:c824 with SMTP id fb7-20020a0568083a8700b0039a622ec824mr3921538oib.30.1685825808459; Sat, 03 Jun 2023 13:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825808; cv=none; d=google.com; s=arc-20160816; b=zGsjY0OiyANacy298UE8kBwqz9jFfd5ywFBpjcHizXqWlQ2iOykrkeS8SB4sikxoBF VxeHxnWPUhCEp5gwDaTJRw6wsVusnqSnt+STfcXJ/4HMigrR66R4Pk6G5vCs8MeEcrZU L5PTJQXDoWxFCXxN9EwnFwWc1hp1i5MN3u2ulBbNqRFbaxCzHyOSeZY/RbCSLVp4dAqa Q/rIzxcH1/0ytmZnf4u9ZCWllTAn6234zkWxEQXjFnUCL4VVC8EPu2p/I9GtaPj8C16z Z/W5fXhdlVknYtMav85F2oi2CV7nyd8ssln8yhtC+ul95m0QVw70UF55lp7LeRPI/7ik Zd/A== 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=FgPTGIGxeBtK5P9H+BLgs5wiavf5GzMitjxHRDrphMA=; b=kKJpYKqj9xktS9Sdsj9zmXz5w2uSIGm53BGR1qHcwqlBh7MsNTJ2iXxH0lFkL5yth9 hPBdumA2f0b7wMOYfzUGODrVgJMFPHK3RrVieM9LboBk4g4s/vBeufAmfqLJaBCkkgY2 lug69E35MA0gGHYdYKseqP4mo8bS5UvPNxmeQ2yQA6r7A8PRPxguu8LqxFZlHmg73AvP fVuvH6BcKQWpt52ClBr0j+6lW5FX02U9LkTL6hkPwqyL/MsuM7HSm0VVso3FlqSOZUXS 1aC25rCmgmSlLT+JOIlWMhRzCz2hJ7bdWPCQbNlYaTpc2MBQWWxRxESbTIO0zJq/Ggvg T27A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=BPLkTA1I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a63cf0d000000b0052c54de0299si3137324pgg.637.2023.06.03.13.56.36; Sat, 03 Jun 2023 13:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=BPLkTA1I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbjFCUzp (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232334AbjFCUzH (ORCPT ); Sat, 3 Jun 2023 16:55:07 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F23E11B7; Sat, 3 Jun 2023 13:54:59 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 4027C5FD40; Sat, 3 Jun 2023 23:54:50 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825690; bh=FgPTGIGxeBtK5P9H+BLgs5wiavf5GzMitjxHRDrphMA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=BPLkTA1IdyQHFINXouNlMNTBnYljhy3Pao3JcffEzGYHyJUDRJrIlwPXANH4q4OTq d0AtgctMHevEDTV9gEYtdOTCFuXZrrC/9+Nc+7J1M6LpVCpizanzjuGSrF0bs2qQu3 n22iOijNrxigaadZuT0Q9RCXDuLrAD6wsK7INncufOosIx03ILqkk95IbVix3kCNy1 r2rzg5JKE5oH+Ll+vp56ROV6ECpsqeuGyadfz3Ml0M+PbZ8dp6mBYrAQUyvgcj3cMd Nk1O24f4J9WBJd2TpmE2ltcegLZ4awOztC6bGRvJ5IDBRwH6PufWFpGVPlpW8weRtY YajyhMXndf5iA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:50 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 16/17] test/vsock: MSG_ZEROCOPY support for vsock_perf Date: Sat, 3 Jun 2023 23:49:38 +0300 Message-ID: <20230603204939.1598818-17-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716483081523023?= X-GMAIL-MSGID: =?utf-8?q?1767716483081523023?= To use this option pass '--zc' parameter: ./vsock_perf --zc --sender --port --bytes With this option MSG_ZEROCOPY flag will be passed to the 'send()' call. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_perf.c | 139 +++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 9 deletions(-) diff --git a/tools/testing/vsock/vsock_perf.c b/tools/testing/vsock/vsock_perf.c index a72520338f84..7fd76f7a3c16 100644 --- a/tools/testing/vsock/vsock_perf.c +++ b/tools/testing/vsock/vsock_perf.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #define DEFAULT_BUF_SIZE_BYTES (128 * 1024) #define DEFAULT_TO_SEND_BYTES (64 * 1024) @@ -28,9 +30,14 @@ #define BYTES_PER_GB (1024 * 1024 * 1024ULL) #define NSEC_PER_SEC (1000000000ULL) +#ifndef SOL_VSOCK +#define SOL_VSOCK 287 +#endif + static unsigned int port = DEFAULT_PORT; static unsigned long buf_size_bytes = DEFAULT_BUF_SIZE_BYTES; static unsigned long vsock_buf_bytes = DEFAULT_VSOCK_BUF_BYTES; +static bool zerocopy; static void error(const char *s) { @@ -247,15 +254,76 @@ static void run_receiver(unsigned long rcvlowat_bytes) close(fd); } +static void recv_completion(int fd) +{ + struct sock_extended_err *serr; + char cmsg_data[128]; + struct cmsghdr *cm; + struct msghdr msg = { 0 }; + ssize_t ret; + + msg.msg_control = cmsg_data; + msg.msg_controllen = sizeof(cmsg_data); + + ret = recvmsg(fd, &msg, MSG_ERRQUEUE); + if (ret) { + fprintf(stderr, "recvmsg: failed to read err: %zi\n", ret); + return; + } + + cm = CMSG_FIRSTHDR(&msg); + if (!cm) { + fprintf(stderr, "cmsg: no cmsg\n"); + return; + } + + if (cm->cmsg_level != SOL_VSOCK) { + fprintf(stderr, "cmsg: unexpected 'cmsg_level'\n"); + return; + } + + if (cm->cmsg_type) { + fprintf(stderr, "cmsg: unexpected 'cmsg_type'\n"); + return; + } + + serr = (void *)CMSG_DATA(cm); + if (serr->ee_origin != SO_EE_ORIGIN_ZEROCOPY) { + fprintf(stderr, "serr: wrong origin\n"); + return; + } + + if (serr->ee_errno) { + fprintf(stderr, "serr: wrong error code\n"); + return; + } + + if (zerocopy && (serr->ee_code & SO_EE_CODE_ZEROCOPY_COPIED)) + fprintf(stderr, "warning: copy instead of zerocopy\n"); +} + +static void enable_so_zerocopy(int fd) +{ + int val = 1; + + if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val))) + error("setsockopt(SO_ZEROCOPY)"); +} + static void run_sender(int peer_cid, unsigned long to_send_bytes) { time_t tx_begin_ns; time_t tx_total_ns; size_t total_send; + time_t time_in_send; void *data; int fd; - printf("Run as sender\n"); + if (zerocopy) + printf("Run as sender MSG_ZEROCOPY\n"); + else + printf("Run as sender\n"); + printf("Connect to %i:%u\n", peer_cid, port); printf("Send %lu bytes\n", to_send_bytes); printf("TX buffer %lu bytes\n", buf_size_bytes); @@ -265,38 +333,82 @@ static void run_sender(int peer_cid, unsigned long to_send_bytes) if (fd < 0) exit(EXIT_FAILURE); - data = malloc(buf_size_bytes); + if (zerocopy) { + enable_so_zerocopy(fd); - if (!data) { - fprintf(stderr, "'malloc()' failed\n"); - exit(EXIT_FAILURE); + data = mmap(NULL, buf_size_bytes, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (data == MAP_FAILED) { + perror("mmap"); + exit(EXIT_FAILURE); + } + } else { + data = malloc(buf_size_bytes); + + if (!data) { + fprintf(stderr, "'malloc()' failed\n"); + exit(EXIT_FAILURE); + } } memset(data, 0, buf_size_bytes); total_send = 0; + time_in_send = 0; tx_begin_ns = current_nsec(); while (total_send < to_send_bytes) { ssize_t sent; + size_t rest_bytes; + time_t before; - sent = write(fd, data, buf_size_bytes); + rest_bytes = to_send_bytes - total_send; + + before = current_nsec(); + sent = send(fd, data, (rest_bytes > buf_size_bytes) ? + buf_size_bytes : rest_bytes, + zerocopy ? MSG_ZEROCOPY : 0); + time_in_send += (current_nsec() - before); if (sent <= 0) error("write"); total_send += sent; + + if (zerocopy) { + struct pollfd fds = { 0 }; + + fds.fd = fd; + + if (poll(&fds, 1, -1) < 0) { + perror("poll"); + exit(EXIT_FAILURE); + } + + if (!(fds.revents & POLLERR)) { + fprintf(stderr, "POLLERR expected\n"); + exit(EXIT_FAILURE); + } + + recv_completion(fd); + } } tx_total_ns = current_nsec() - tx_begin_ns; printf("total bytes sent: %zu\n", total_send); printf("tx performance: %f Gbits/s\n", - get_gbps(total_send * 8, tx_total_ns)); - printf("total time in 'write()': %f sec\n", + get_gbps(total_send * 8, time_in_send)); + printf("total time in tx loop: %f sec\n", (float)tx_total_ns / NSEC_PER_SEC); + printf("time in 'send()': %f sec\n", + (float)time_in_send / NSEC_PER_SEC); close(fd); - free(data); + + if (zerocopy) + munmap(data, buf_size_bytes); + else + free(data); } static const char optstring[] = ""; @@ -336,6 +448,11 @@ static const struct option longopts[] = { .has_arg = required_argument, .val = 'R', }, + { + .name = "zc", + .has_arg = no_argument, + .val = 'Z', + }, {}, }; @@ -351,6 +468,7 @@ static void usage(void) " --help This message\n" " --sender Sender mode (receiver default)\n" " of the receiver to connect to\n" + " --zc Enable zerocopy\n" " --port Port (default %d)\n" " --bytes KMG Bytes to send (default %d)\n" " --buf-size KMG Data buffer size (default %d). In sender mode\n" @@ -413,6 +531,9 @@ int main(int argc, char **argv) case 'H': /* Help. */ usage(); break; + case 'Z': /* Zerocopy. */ + zerocopy = true; + break; default: usage(); } From patchwork Sat Jun 3 20:49:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841418vqr; Sat, 3 Jun 2023 13:58:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ZQ9TUvbogKPFyDM3+VsjNsDZy2JMb5FzmxEL/9XMkmaQH1IlSRz4y+QnNEh1rQ2C+fsuF X-Received: by 2002:a17:902:e543:b0:1b1:a617:7df3 with SMTP id n3-20020a170902e54300b001b1a6177df3mr4345102plf.30.1685825888349; Sat, 03 Jun 2023 13:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825888; cv=none; d=google.com; s=arc-20160816; b=SVzExlqWcxtndY3Khol45C9uHeJNs/VoZp7sJMLOjLl51hp2PegZtfAN/v0iwICL/7 XdiyxxmuAiGDNXSj5LTkYDpn44KladUcmmm+wER/1zvpgFGOAqvRNOoOfox7Pbs9lkeE N6ae1se0B/0l4xQYd75XBvGkF7T96LCI4dWPI2ORhmVodDFHH4M2a8J5M3lCJw+evD7N Lo5upB3znWFp6sfhdZ/zbK5c/XJ307Yn+vpWkb9srGXqqaFulHiCwkjxOrcaErIRtVcj Foxj57Wn4UbvllBDqpRz9/lZXREE5JrUDZVBCQCOvfA65FkaucAYTbkmQcH1N62z2Ovm FpRw== 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=XeBcocw7Ow0J3zl/HOChhEU6WoykzJ9fUhXcW0cNTyA=; b=tp2I+7aJ+4ediBrOVHjCaftKZov7tJG/g74l0IQtpINwyn6PuLvXUKOuYNsoBmwZYU bJKq+IdK0bxCenOrgIVB5NsYZOZlM+/pgr8dyNaVqGvg02oKjLF0tNPa+jG/H38HfVFt UdzJRA4ymEqK/uhlsUzyXLdQuO5qAV8nsHmbbHFDyQ2+uxJ/HQfUe0eEgdXH9gC4eeUy cXYOFex3v1zrHEBTMSJFQ/L6Eyqn3WGS4w7siyrJjqijEZ6IoATmN4511dtEw6/khhhr W3F5Ia+8irvxaBNbzY/E9dZ2aLYNhw7LR/BtFbW0dNzjterLKbwJO4RmMEt3maPefoPg yJPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Qi+UKDrr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a170902c10600b001ab007aff67si3033324pli.32.2023.06.03.13.57.55; Sat, 03 Jun 2023 13:58:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Qi+UKDrr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbjFCU4E (ORCPT + 99 others); Sat, 3 Jun 2023 16:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232482AbjFCUzH (ORCPT ); Sat, 3 Jun 2023 16:55:07 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BFFA6; Sat, 3 Jun 2023 13:55:00 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 849605FD41; Sat, 3 Jun 2023 23:54:50 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825690; bh=XeBcocw7Ow0J3zl/HOChhEU6WoykzJ9fUhXcW0cNTyA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Qi+UKDrrk4uptXQrUkjbCjFMH1jc+/cOOur3ibO0CxS4znMKH2i6BYESMKIZuLDCH mUasGCnY7jtIa1KVPx0J8PI43IvKoKoflxNJgPDnzRvIC2bpnf/+5P+Nnqna9fVRow JTnXBN3Y+eMbrdzMgpi28DApiHLD/m2v58/SA3LSWDxHHQEuUDhNHOaEsviSXhKViU y9yCsMLwTj1ddgPi6nkYpmbsqvDvMp81fqxqu1obS3NNnqlBUr+YP8YitYC6ySdWDI nHIfydEBicaebFDbG8wU5OQEQiz2QyvQPB4kzS7uC3mE2qxlcViNweO2YswkOS2yK5 mtFnmCFEBB9AQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:50 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v4 17/17] test/vsock: io_uring rx/tx tests Date: Sat, 3 Jun 2023 23:49:39 +0300 Message-ID: <20230603204939.1598818-18-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716566893927606?= X-GMAIL-MSGID: =?utf-8?q?1767716566893927606?= This adds set of tests which use io_uring for rx/tx. This test suite is implemented as separated util like 'vsock_test' and has the same set of input arguments as 'vsock_test'. These tests only cover cases of data transmission (no connect/bind/accept etc). Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/Makefile | 7 +- tools/testing/vsock/vsock_uring_test.c | 321 +++++++++++++++++++++++++ 2 files changed, 327 insertions(+), 1 deletion(-) create mode 100644 tools/testing/vsock/vsock_uring_test.c diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile index 0a78787d1d92..8621ae73051d 100644 --- a/tools/testing/vsock/Makefile +++ b/tools/testing/vsock/Makefile @@ -1,12 +1,17 @@ # SPDX-License-Identifier: GPL-2.0-only +ifeq ($(MAKECMDGOALS),vsock_uring_test) +LDFLAGS = -luring +endif + all: test vsock_perf test: vsock_test vsock_diag_test vsock_test: vsock_test.o vsock_test_zerocopy.o timeout.o control.o util.o vsock_diag_test: vsock_diag_test.o timeout.o control.o util.o vsock_perf: vsock_perf.o +vsock_uring_test: control.o util.o vsock_uring_test.o timeout.o $(LDFLAGS) CFLAGS += -g -O2 -Werror -Wall -I. -I../../include -I../../../usr/include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE .PHONY: all test clean clean: - ${RM} *.o *.d vsock_test vsock_diag_test + ${RM} *.o *.d vsock_test vsock_diag_test vsock_uring_test -include *.d diff --git a/tools/testing/vsock/vsock_uring_test.c b/tools/testing/vsock/vsock_uring_test.c new file mode 100644 index 000000000000..7637ff510490 --- /dev/null +++ b/tools/testing/vsock/vsock_uring_test.c @@ -0,0 +1,321 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* io_uring tests for vsock + * + * Copyright (C) 2023 SberDevices. + * + * Author: Arseniy Krasnov + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "control.h" + +#define PAGE_SIZE 4096 +#define RING_ENTRIES_NUM 4 + +static struct vsock_test_data test_data_array[] = { + /* All elements have page aligned base and size. */ + { + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { NULL, 2 * PAGE_SIZE }, + { NULL, 3 * PAGE_SIZE }, + } + }, + /* Middle element has both non-page aligned base and size. */ + { + .vecs_cnt = 3, + { + { NULL, PAGE_SIZE }, + { (void *)1, 200 }, + { NULL, 3 * PAGE_SIZE }, + } + } +}; + +static void vsock_io_uring_client(const struct test_opts *opts, + const struct vsock_test_data *test_data, + bool msg_zerocopy) +{ + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + struct io_uring ring; + struct iovec *iovec; + struct msghdr msg; + int fd; + + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + if (msg_zerocopy) + enable_so_zerocopy(fd); + + iovec = iovec_from_test_data(test_data); + + if (io_uring_queue_init(RING_ENTRIES_NUM, &ring, 0)) + error(1, errno, "io_uring_queue_init"); + + if (io_uring_register_buffers(&ring, iovec, test_data->vecs_cnt)) + error(1, errno, "io_uring_register_buffers"); + + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = iovec; + msg.msg_iovlen = test_data->vecs_cnt; + sqe = io_uring_get_sqe(&ring); + + if (msg_zerocopy) + io_uring_prep_sendmsg_zc(sqe, fd, &msg, 0); + else + io_uring_prep_sendmsg(sqe, fd, &msg, 0); + + if (io_uring_submit(&ring) != 1) + error(1, errno, "io_uring_submit"); + + if (io_uring_wait_cqe(&ring, &cqe)) + error(1, errno, "io_uring_wait_cqe"); + + io_uring_cqe_seen(&ring, cqe); + + control_writeulong(iovec_hash_djb2(iovec, test_data->vecs_cnt)); + + control_writeln("DONE"); + io_uring_queue_exit(&ring); + free_iovec_test_data(test_data, iovec); + close(fd); +} + +static void vsock_io_uring_server(const struct test_opts *opts, + const struct vsock_test_data *test_data) +{ + unsigned long remote_hash; + unsigned long local_hash; + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + struct io_uring ring; + struct iovec iovec; + size_t data_len; + void *data; + int fd; + + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + data_len = iovec_bytes(test_data->vecs, test_data->vecs_cnt); + + data = malloc(data_len); + if (!data) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + if (io_uring_queue_init(RING_ENTRIES_NUM, &ring, 0)) + error(1, errno, "io_uring_queue_init"); + + sqe = io_uring_get_sqe(&ring); + iovec.iov_base = data; + iovec.iov_len = data_len; + + io_uring_prep_readv(sqe, fd, &iovec, 1, 0); + + if (io_uring_submit(&ring) != 1) + error(1, errno, "io_uring_submit"); + + if (io_uring_wait_cqe(&ring, &cqe)) + error(1, errno, "io_uring_wait_cqe"); + + if (cqe->res != data_len) { + fprintf(stderr, "expected %zu, got %u\n", data_len, + cqe->res); + exit(EXIT_FAILURE); + } + + local_hash = hash_djb2(data, data_len); + + remote_hash = control_readulong(); + if (remote_hash != local_hash) { + fprintf(stderr, "hash mismatch\n"); + exit(EXIT_FAILURE); + } + + control_expectln("DONE"); + io_uring_queue_exit(&ring); + free(data); +} + +void test_stream_uring_server(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + vsock_io_uring_server(opts, &test_data_array[i]); +} + +void test_stream_uring_client(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + vsock_io_uring_client(opts, &test_data_array[i], false); +} + +void test_stream_uring_msg_zc_server(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + vsock_io_uring_server(opts, &test_data_array[i]); +} + +void test_stream_uring_msg_zc_client(const struct test_opts *opts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_data_array); i++) + vsock_io_uring_client(opts, &test_data_array[i], true); +} + +static struct test_case test_cases[] = { + { + .name = "SOCK_STREAM io_uring test", + .run_server = test_stream_uring_server, + .run_client = test_stream_uring_client, + }, + { + .name = "SOCK_STREAM io_uring MSG_ZEROCOPY test", + .run_server = test_stream_uring_msg_zc_server, + .run_client = test_stream_uring_msg_zc_client, + }, + {}, +}; + +static const char optstring[] = ""; +static const struct option longopts[] = { + { + .name = "control-host", + .has_arg = required_argument, + .val = 'H', + }, + { + .name = "control-port", + .has_arg = required_argument, + .val = 'P', + }, + { + .name = "mode", + .has_arg = required_argument, + .val = 'm', + }, + { + .name = "peer-cid", + .has_arg = required_argument, + .val = 'p', + }, + { + .name = "help", + .has_arg = no_argument, + .val = '?', + }, + {}, +}; + +static void usage(void) +{ + fprintf(stderr, "Usage: vsock_uring_test [--help] [--control-host=] --control-port= --mode=client|server --peer-cid=\n" + "\n" + " Server: vsock_uring_test --control-port=1234 --mode=server --peer-cid=3\n" + " Client: vsock_uring_test --control-host=192.168.0.1 --control-port=1234 --mode=client --peer-cid=2\n" + "\n" + "Run transmission tests using io_uring. Usage is the same as\n" + "in ./vsock_test\n" + "\n" + "Options:\n" + " --help This help message\n" + " --control-host Server IP address to connect to\n" + " --control-port Server port to listen on/connect to\n" + " --mode client|server Server or client mode\n" + " --peer-cid CID of the other side\n" + ); + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) +{ + const char *control_host = NULL; + const char *control_port = NULL; + struct test_opts opts = { + .mode = TEST_MODE_UNSET, + .peer_cid = VMADDR_CID_ANY, + }; + + init_signals(); + + for (;;) { + int opt = getopt_long(argc, argv, optstring, longopts, NULL); + + if (opt == -1) + break; + + switch (opt) { + case 'H': + control_host = optarg; + break; + case 'm': + if (strcmp(optarg, "client") == 0) { + opts.mode = TEST_MODE_CLIENT; + } else if (strcmp(optarg, "server") == 0) { + opts.mode = TEST_MODE_SERVER; + } else { + fprintf(stderr, "--mode must be \"client\" or \"server\"\n"); + return EXIT_FAILURE; + } + break; + case 'p': + opts.peer_cid = parse_cid(optarg); + break; + case 'P': + control_port = optarg; + break; + case '?': + default: + usage(); + } + } + + if (!control_port) + usage(); + if (opts.mode == TEST_MODE_UNSET) + usage(); + if (opts.peer_cid == VMADDR_CID_ANY) + usage(); + + if (!control_host) { + if (opts.mode != TEST_MODE_SERVER) + usage(); + control_host = "0.0.0.0"; + } + + control_init(control_host, control_port, + opts.mode == TEST_MODE_SERVER); + + run_tests(test_cases, &opts); + + control_cleanup(); + + return 0; +}