All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/9] vsock: updates for SO_RCVLOWAT handling
@ 2022-07-25  7:54 Arseniy Krasnov
  2022-07-25  7:56 ` [RFC PATCH v2 1/9] vsock: use sk_rcvlowat to set POLLIN/POLLRDNORM Arseniy Krasnov
                   ` (9 more replies)
  0 siblings, 10 replies; 32+ messages in thread
From: Arseniy Krasnov @ 2022-07-25  7:54 UTC (permalink / raw)
  To: Stefano Garzarella, David S. Miller, edumazet, Jakub Kicinski,
	Paolo Abeni, Stefan Hajnoczi, Michael S. Tsirkin, kys, haiyangz,
	sthemmin, wei.liu, Dexuan Cui, Arseniy Krasnov, Krasnov Arseniy
  Cc: virtualization, netdev, linux-kernel, linux-hyperv, kvm, kernel

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(-)

-- 
2.25.1

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2022-08-02  8:04 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-25  7:54 [RFC PATCH v2 0/9] vsock: updates for SO_RCVLOWAT handling Arseniy Krasnov
2022-07-25  7:56 ` [RFC PATCH v2 1/9] vsock: use sk_rcvlowat to set POLLIN/POLLRDNORM Arseniy Krasnov
2022-07-27 12:17   ` Stefano Garzarella
2022-07-27 12:17     ` Stefano Garzarella
2022-07-28  6:04     ` Arseniy Krasnov
2022-07-25  7:59 ` [RFC PATCH v2 2/9] virtio/vsock: use 'target' in notify_poll_in, callback Arseniy Krasnov
2022-07-25  8:01 ` [RFC PATCH v2 3/9] vmci/vsock: " Arseniy Krasnov
2022-07-27 12:22   ` Stefano Garzarella
2022-07-27 12:22     ` Stefano Garzarella
2022-07-27 12:29     ` Stefano Garzarella
2022-07-27 12:29       ` Stefano Garzarella
2022-07-28  6:05     ` Arseniy Krasnov
2022-07-25  8:03 ` [RFC PATCH v2 4/9] vsock_test: POLLIN + SO_RCVLOWAT test Arseniy Krasnov
2022-07-25  8:05 ` [RFC PATCH v2 5/9] vsock: SO_RCVLOWAT transport set callback Arseniy Krasnov
2022-07-27 12:24   ` Stefano Garzarella
2022-07-27 12:24     ` Stefano Garzarella
2022-07-28  6:06     ` Arseniy Krasnov
2022-07-25  8:07 ` [RFC PATCH v2 6/9] hv_sock: disable SO_RCVLOWAT support Arseniy Krasnov
2022-08-02  5:42   ` Dexuan Cui
2022-07-25  8:09 ` [RFC PATCH v2 7/9] vsock: add API call for data ready Arseniy Krasnov
2022-07-25  8:11 ` [RFC PATCH v2 8/9] virtio/vsock: check SO_RCVLOWAT before wake up reader Arseniy Krasnov
2022-07-25  8:13 ` [RFC PATCH v2 9/9] vmci/vsock: " Arseniy Krasnov
2022-07-27 12:37 ` [RFC PATCH v2 0/9] vsock: updates for SO_RCVLOWAT handling Stefano Garzarella
2022-07-27 12:37   ` Stefano Garzarella
2022-07-28  6:08   ` Arseniy Krasnov
2022-08-02  5:31     ` Vishnu Dasa
2022-08-02  5:31       ` Vishnu Dasa via Virtualization
2022-08-02  5:35       ` Arseniy Krasnov
2022-08-02  5:35   ` Vishnu Dasa
2022-08-02  5:35     ` Vishnu Dasa via Virtualization
2022-08-02  8:04     ` Stefano Garzarella
2022-08-02  8:04       ` Stefano Garzarella

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.