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: 53028 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2087921wrn; Sun, 5 Feb 2023 22:58:12 -0800 (PST) X-Google-Smtp-Source: AK7set/HcgzQmZDtEiTViRAiam9w69y+0BqIVZk5x92yEiDrt08JlojPUKgwFZEt56zTYxU82KND X-Received: by 2002:a17:902:dac8:b0:196:38f4:78df with SMTP id q8-20020a170902dac800b0019638f478dfmr11888060plx.39.1675666691719; Sun, 05 Feb 2023 22:58:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675666691; cv=none; d=google.com; s=arc-20160816; b=mss7uvf/xBWYOL0IEZMb+k/z9ef/wXE1P/vupXUnwj/x2/U50l0jAEZdlIOqBVfCX7 eSyNTWgI/3fWwGVmD0yyNLGjn6a0BgIorM9tBranRhjKEP2F2Sj5JSC5Jh4pGsVJbKlW 4kTKuizp8OBpLu5jVv43CayvuL1brHNmtU61RPk+GhQWvmtwtSsyw8DDGVkaM3fEXdes BxoOXeB0k+maWR5HGLma5BVqhryDotYga5MUfjU6yDPd7wk7EyEYQx3dVhDE+r+2Y57c ErfdzFLYBNNFMdT2Xe+kozQ7I60jFYAopFHLyqRfVnDAYA86+ii20BU4Cw100AFzr5Qb xSqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=O6cNhFQfaQVbXViC73z339ui0JNnZlXbWLyqE8Ijrl8=; b=tiMYFQy8u9TIMFoU8yW7ParbxgMJP1XUiHpB+daOgmwjpCwSQ4bAqHcZcBGMtCuLHC wIB4T9ds5MEelWalOTUk28Fw+3x5FLsOxDqYRVsxxByA8nZjQInH5U5c43G00VS0WNaw 0VFgNDtpzxtcF7i4xOqsIqK9V6wawdpQ3pcTvgtyRqxaSe+Z5yBOhzQZRwCQDQAZg2aK HBRoLWyp1RoV1FkITNxe95RUM10jjyRUhCGa6+5dAXFdi0CuucB2Z2q0RpwVzfOwUazN Ful3qm1VxpZrbQDfHyH37zKPeHHRfUpL3l5TX7ywxfLWxEKXxrTNEz/qPlEE0xWeh+dX YAYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=iyMC2qGO; 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 h9-20020a170902748900b0019644d4246csi7717870pll.418.2023.02.05.22.57.59; Sun, 05 Feb 2023 22:58:11 -0800 (PST) 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=iyMC2qGO; 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 S229734AbjBFG4Y (ORCPT + 99 others); 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 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_PASS 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?1757063876801713980?= X-GMAIL-MSGID: =?utf-8?q?1757063876801713980?= 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(+) -- 2.25.1 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;