From patchwork Mon Feb 6 06:54:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13129365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0652C05027 for ; Mon, 6 Feb 2023 06:56:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbjBFG4Y (ORCPT ); Mon, 6 Feb 2023 01:56:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbjBFG4X (ORCPT ); Mon, 6 Feb 2023 01:56:23 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B268A1C334; Sun, 5 Feb 2023 22:55:41 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id EFD595FD03; Mon, 6 Feb 2023 09:54:51 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1675666492; bh=O6cNhFQfaQVbXViC73z339ui0JNnZlXbWLyqE8Ijrl8=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=iyMC2qGOlxJHnyrtSHhiLmBbkFt1ReQMWF6JCPtKx1U3BHXEZzSg/vvvrhTRxOBHQ SARUIdXkMVs4hgCp+RjZT3HFbSIn7thgeGXq1S7Q9/73C3ae4bGoc8m7qroQIysiXe gUK6ZTwdE0IeB4CNRQJ6YiovOZSIIl+4gD00vpovkGqSVFToVlvhdrt2csc81sOvfr ahuKwjdBHwzkx5hsGImwK2Z1f+/R5LgAldHJTjzI7pnuQ5xSG8cKpKwFDqWWkvNfK4 9vAtQnpkZQf9Rsyol7bryGyBe8zVDCwJ7uqjcdUvzHYFT/+q1Ke+wyYMh5fkRM0BjV qe9nS0kFeRteA== Received: from S-MS-EXCH02.sberdevices.ru (S-MS-EXCH02.sberdevices.ru [172.16.1.5]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 6 Feb 2023 09:54:51 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Arseniy Krasnov , "Krasnov Arseniy" CC: "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , kernel Subject: [RFC PATCH v1 02/12] vsock: read from socket's error queue Thread-Topic: [RFC PATCH v1 02/12] vsock: read from socket's error queue Thread-Index: AQHZOffoRZzBrg9vIUiTEqCzeANM9A== Date: Mon, 6 Feb 2023 06:54:51 +0000 Message-ID: <7b2f00ce-296c-3f59-9861-468c6340300e@sberdevices.ru> In-Reply-To: <0e7c6fc4-b4a6-a27b-36e9-359597bba2b5@sberdevices.ru> Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-ID: <2E161FFF127651478A2DC3B377174E34@sberdevices.ru> MIME-Version: 1.0 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/02/06 01:18:00 #20834045 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This adds handling of MSG_ERRQUEUE input flag for receive call, thus skb from socket's error queue is read. Signed-off-by: Arseniy Krasnov --- include/linux/socket.h | 1 + net/vmw_vsock/af_vsock.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/socket.h b/include/linux/socket.h index 13c3a237b9c9..19a6f39fa014 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -379,6 +379,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 b5e51ef4a74c..f752b30b71d6 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); @@ -2086,6 +2087,27 @@ static int __vsock_seqpacket_recvmsg(struct sock *sk, struct msghdr *msg, return err; } +static int vsock_err_recvmsg(struct sock *sk, struct msghdr *msg) +{ + struct sock_extended_err *ee; + struct sk_buff *skb; + int err; + + lock_sock(sk); + skb = sock_dequeue_err_skb(sk); + release_sock(sk); + + if (!skb) + return -EAGAIN; + + ee = &SKB_EXT_ERR(skb)->ee; + err = put_cmsg(msg, SOL_VSOCK, 0, sizeof(*ee), ee); + msg->msg_flags |= MSG_ERRQUEUE; + consume_skb(skb); + + return err; +} + static int vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, int flags) @@ -2096,6 +2118,10 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, int err; sk = sock->sk; + + if (unlikely(flags & MSG_ERRQUEUE)) + return vsock_err_recvmsg(sk, msg); + vsk = vsock_sk(sk); err = 0;