From patchwork Mon Jul 25 07:54:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12927821 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 B3174CCA473 for ; Mon, 25 Jul 2022 07:54:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232291AbiGYHyp (ORCPT ); Mon, 25 Jul 2022 03:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbiGYHyn (ORCPT ); Mon, 25 Jul 2022 03:54:43 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C0EC12ADE; Mon, 25 Jul 2022 00:54:37 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id 85C7D5FD0C; Mon, 25 Jul 2022 10:54:33 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1658735673; bh=Jlqwz8Mf0SX+vFvr8bsEZwYRgZFGP2xbuZquqH8x8g4=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=BEI7uEFQVoAxVHxTvWWYevPIQjqaIvHrKIRspdaYFgpKxFafEMFZXVcgtZR/WAKFC 7YIxpUYoG8mMaEn77lC1W8S3C/EpcivFR3h+uO1yGDkrWTEzfVERFj4mUu2UoKZMT7 d9jgfNqCo9E94slr2h1KcV4HVZnPmbrhjiVpxbgb9dqAJhukv/4cOU/rJu84kWrLEn ckrMz7C+fMhSzA9NOs147nWzeHX6nfgvvQjMfZ6okAFH0i9mbKgxqYcb3ysexkYYwJ JHFlJRm2D7Yuqc6LHc3cxMQ4pLpKtPIIYwp4JzysxaP3etbozUD9DDkkeseQRyc3FH SAiup18Qa9Vng== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Mon, 25 Jul 2022 10:54:24 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , "David S. Miller" , "edumazet@google.com" , "Jakub Kicinski" , Paolo Abeni , Stefan Hajnoczi , "Michael S. Tsirkin" , "kys@microsoft.com" , "haiyangz@microsoft.com" , "sthemmin@microsoft.com" , "wei.liu@kernel.org" , Dexuan Cui , Arseniy Krasnov , Krasnov Arseniy CC: "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "kvm@vger.kernel.org" , kernel Subject: [RFC PATCH v2 0/9] vsock: updates for SO_RCVLOWAT handling Thread-Topic: [RFC PATCH v2 0/9] vsock: updates for SO_RCVLOWAT handling Thread-Index: AQHYn/u277di/gNdd06E3+5muuhZow== Date: Mon, 25 Jul 2022 07:54:05 +0000 Message-ID: <19e25833-5f5c-f9b9-ac0f-1945ea17638d@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: 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: 2022/07/25 03:52:00 #19956163 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hello, This patchset includes some updates for SO_RCVLOWAT: 1) af_vsock: During my experiments with zerocopy receive, i found, that in some cases, poll() implementation violates POSIX: when socket has non- default SO_RCVLOWAT(e.g. not 1), poll() will always set POLLIN and POLLRDNORM bits in 'revents' even number of bytes available to read on socket is smaller than SO_RCVLOWAT value. In this case,user sees POLLIN flag and then tries to read data(for example using 'read()' call), but read call will be blocked, because SO_RCVLOWAT logic is supported in dequeue loop in af_vsock.c. But the same time, POSIX requires that: "POLLIN Data other than high-priority data may be read without blocking. POLLRDNORM Normal data may be read without blocking." See https://www.open-std.org/jtc1/sc22/open/n4217.pdf, page 293. So, we have, that poll() syscall returns POLLIN, but read call will be blocked. Also in man page socket(7) i found that: "Since Linux 2.6.28, select(2), poll(2), and epoll(7) indicate a socket as readable only if at least SO_RCVLOWAT bytes are available." I checked TCP callback for poll()(net/ipv4/tcp.c, tcp_poll()), it uses SO_RCVLOWAT value to set POLLIN bit, also i've tested TCP with this case for TCP socket, it works as POSIX required. I've added some fixes to af_vsock.c and virtio_transport_common.c, test is also implemented. 2) virtio/vsock: It adds some optimization to wake ups, when new data arrived. Now, SO_RCVLOWAT is considered before wake up sleepers who wait new data. There is no sense, to kick waiter, when number of available bytes in socket's queue < SO_RCVLOWAT, because if we wake up reader in this case, it will wait for SO_RCVLOWAT data anyway during dequeue, or in poll() case, POLLIN/POLLRDNORM bits won't be set, so such exit from poll() will be "spurious". This logic is also used in TCP sockets. 3) vmci/vsock: Same as 2), but i'm not sure about this changes. Will be very good, to get comments from someone who knows this code. 4) Hyper-V: As Dexuan Cui mentioned, for Hyper-V transport it is difficult to support SO_RCVLOWAT, so he suggested to disable this feature for Hyper-V. Thank You Arseniy Krasnov(9): vsock: use sk_rcvlowat to set POLLIN/POLLRDNORM virtio/vsock: use 'target' in notify_poll_in callback vmci/vsock: use 'target' in notify_poll_in callback vsock_test: POLLIN + SO_RCVLOWAT test vsock: SO_RCVLOWAT transport set callback hv_sock: disable SO_RCVLOWAT support vsock: add API call for data ready virtio/vsock: check SO_RCVLOWAT before wake up reader vmci/vsock: check SO_RCVLOWAT before wake up reader include/net/af_vsock.h | 2 + net/vmw_vsock/af_vsock.c | 32 +++++++- net/vmw_vsock/hyperv_transport.c | 7 ++ net/vmw_vsock/virtio_transport_common.c | 7 +- net/vmw_vsock/vmci_transport_notify.c | 4 +- net/vmw_vsock/vmci_transport_notify_qstate.c | 6 +- tools/testing/vsock/vsock_test.c | 107 +++++++++++++++++++++++++++ 7 files changed, 154 insertions(+), 11 deletions(-)