Skip to content

Commit

Permalink
vsock: return errors other than -ENOMEM to socket
Browse files Browse the repository at this point in the history
This commit allows vsock implementations to return errors
to the socket layer other than -ENOMEM. One immediate effect
of this is that upon the sk_sndbuf threshold being reached -EAGAIN
will be returned and userspace may throttle appropriately.

Resultingly, a known issue with uperf is resolved[1].

Additionally, to preserve legacy behavior for non-virtio
implementations, hyperv/vmci force errors to be -ENOMEM so that behavior
is unchanged.

[1]: https://gitlab.com/vsock/vsock/-/issues/1

Signed-off-by: Bobby Eshleman <bobby.eshleman@bytedance.com>
  • Loading branch information
beshleman authored and intel-lab-lkp committed Aug 15, 2022
1 parent 93afaf2 commit 68c9c82
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/linux/virtio_vsock.h
Expand Up @@ -8,6 +8,9 @@
#include <net/sock.h>
#include <net/af_vsock.h>

/* Threshold for detecting small packets to copy */
#define GOOD_COPY_LEN 128

enum virtio_vsock_metadata_flags {
VIRTIO_VSOCK_METADATA_FLAGS_REPLY = BIT(0),
VIRTIO_VSOCK_METADATA_FLAGS_TAP_DELIVERED = BIT(1),
Expand Down
3 changes: 2 additions & 1 deletion net/vmw_vsock/af_vsock.c
Expand Up @@ -1852,8 +1852,9 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
written = transport->stream_enqueue(vsk,
msg, len - total_written);
}

if (written < 0) {
err = -ENOMEM;
err = written;
goto out_err;
}

Expand Down
2 changes: 1 addition & 1 deletion net/vmw_vsock/hyperv_transport.c
Expand Up @@ -687,7 +687,7 @@ static ssize_t hvs_stream_enqueue(struct vsock_sock *vsk, struct msghdr *msg,
if (bytes_written)
ret = bytes_written;
kfree(send_buf);
return ret;
return ret < 0 ? -ENOMEM : ret;
}

static s64 hvs_stream_has_data(struct vsock_sock *vsk)
Expand Down
3 changes: 0 additions & 3 deletions net/vmw_vsock/virtio_transport_common.c
Expand Up @@ -23,9 +23,6 @@
/* How long to wait for graceful shutdown of a connection */
#define VSOCK_CLOSE_TIMEOUT (8 * HZ)

/* Threshold for detecting small packets to copy */
#define GOOD_COPY_LEN 128

static const struct virtio_transport *
virtio_transport_get_ops(struct vsock_sock *vsk)
{
Expand Down
9 changes: 8 additions & 1 deletion net/vmw_vsock/vmci_transport.c
Expand Up @@ -1838,7 +1838,14 @@ static ssize_t vmci_transport_stream_enqueue(
struct msghdr *msg,
size_t len)
{
return vmci_qpair_enquev(vmci_trans(vsk)->qpair, msg, len, 0);
int err;

err = vmci_qpair_enquev(vmci_trans(vsk)->qpair, msg, len, 0);

if (err < 0)
err = -ENOMEM;

return err;
}

static s64 vmci_transport_stream_has_data(struct vsock_sock *vsk)
Expand Down

0 comments on commit 68c9c82

Please sign in to comment.