From patchwork Fri Sep 22 05:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13394930 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 D4968E7D0CB for ; Fri, 22 Sep 2023 05:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbjIVFbz (ORCPT ); Fri, 22 Sep 2023 01:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjIVFbx (ORCPT ); Fri, 22 Sep 2023 01:31:53 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 621F9196; Thu, 21 Sep 2023 22:31:45 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 38691120008; Fri, 22 Sep 2023 08:31:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 38691120008 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1695360703; bh=ucQ5J3kddO4tOPd0QjgadrTOZY9KNSh2ycNCTudGEcI=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=JjtoSWdeQKLpSzZeVAhqK+DfPAwjAKnRAoZBcP1a94FWIqpzWQ2Dq501zu0vAB+AL DW9vYcTeZ7XVX8Qwh+vxVkhdtOHkWHbucFw0YVv+bFl/0kLkCBSNIdJl6Lki5WoxGC UFV7Mp2n8KrKTwaP8VJgQV9It8ytVTZWsPI9PquEuR3caS/vg4qVIAKpJtF0h6kq9n 7YiokoZ8A6dVR4nRnw8N3jn9lb5Na7j59dI+kkkrUKjXiYqwg3Xj//TAEewyh5yNri rVusR2Cl7FrfcmoMNXfkPrzty12WBnd22Cx0e9qQ9JKLoOW/29WkMtHllYjnNey2od bAvdkVwFrpFlQ== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Fri, 22 Sep 2023 08:31:43 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Fri, 22 Sep 2023 08:31:42 +0300 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: , , , , , , Subject: [PATCH net-next v1 02/12] vsock: read from socket's error queue Date: Fri, 22 Sep 2023 08:24:18 +0300 Message-ID: <20230922052428.4005676-3-avkrasnov@salutedevices.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230922052428.4005676-1-avkrasnov@salutedevices.com> References: <20230922052428.4005676-1-avkrasnov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 180033 [Sep 21 2023] X-KSMG-AntiSpam-Version: 5.9.59.0 X-KSMG-AntiSpam-Envelope-From: avkrasnov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 534 534 808c2ea49f7195c68d40844e073217da4fa0d1e3, {Tracking_from_domain_doesnt_match_to}, 100.64.160.123:7.1.2;127.0.0.199:7.1.2;salutedevices.com:7.1.1;p-i-exch-sc-m01.sberdevices.ru:5.0.1,7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/09/22 02:22:00 #21944311 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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. This patch also adds new defines: 'SOL_VSOCK' and 'VSOCK_RECVERR'. Signed-off-by: Arseniy Krasnov --- Changelog: v5(big patchset) -> v1: * R-b tag removed, due to added defines to 'include/uapi/linux/vsock.h'. Both 'SOL_VSOCK' and 'VSOCK_RECVERR' are needed by userspace, so they were placed to 'include/uapi/linux/vsock.h'. At the same time, the same define for 'SOL_VSOCK' was placed to 'include/linux/socket.h'. This is needed because this file contains SOL_XXX defines for different types of socket, so it prevents situation when another new SOL_XXX will use constant 287. include/linux/socket.h | 1 + include/uapi/linux/vsock.h | 9 +++++++++ net/vmw_vsock/af_vsock.c | 6 ++++++ 3 files changed, 16 insertions(+) create mode 100644 include/uapi/linux/vsock.h diff --git a/include/linux/socket.h b/include/linux/socket.h index 39b74d83c7c4..cfcb7e2c3813 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -383,6 +383,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/include/uapi/linux/vsock.h b/include/uapi/linux/vsock.h new file mode 100644 index 000000000000..b25c1347a3b8 --- /dev/null +++ b/include/uapi/linux/vsock.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_VSOCK_H +#define _UAPI_LINUX_VSOCK_H + +#define SOL_VSOCK 287 + +#define VSOCK_RECVERR 1 + +#endif /* _UAPI_LINUX_VSOCK_H */ diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index d841f4de33b0..4fd11bf34bc7 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -110,6 +110,8 @@ #include #include #include +#include +#include static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr); static void vsock_sk_destruct(struct sock *sk); @@ -2137,6 +2139,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, VSOCK_RECVERR); + vsk = vsock_sk(sk); err = 0;