From: Stefano Garzarella <sgarzare@redhat.com>
To: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Cc: "David S. Miller" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"kys@microsoft.com" <kys@microsoft.com>,
"haiyangz@microsoft.com" <haiyangz@microsoft.com>,
"sthemmin@microsoft.com" <sthemmin@microsoft.com>,
"wei.liu@kernel.org" <wei.liu@kernel.org>,
Dexuan Cui <decui@microsoft.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Bryan Tan <bryantan@vmware.com>, Vishnu Dasa <vdasa@vmware.com>,
VMware PV-Drivers Reviewers <pv-drivers@vmware.com>,
Krasnov Arseniy <oxffffaa@gmail.com>,
"virtualization@lists.linux-foundation.org"
<virtualization@lists.linux-foundation.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
kernel <kernel@sberdevices.ru>
Subject: Re: [RFC PATCH v3 1/9] vsock: SO_RCVLOWAT transport set callback
Date: Tue, 9 Aug 2022 12:03:58 +0200 [thread overview]
Message-ID: <20220809100358.xnxromtvrehsgpn3@sgarzare-redhat> (raw)
In-Reply-To: <d9bd1c16-7096-d267-a0ff-d3742b0dcf56@sberdevices.ru>
On Tue, Aug 09, 2022 at 09:45:47AM +0000, Arseniy Krasnov wrote:
>On 09.08.2022 12:37, Arseniy Krasnov wrote:
>> On 08.08.2022 13:30, Stefano Garzarella wrote:
>>> On Mon, Aug 8, 2022 at 12:23 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>>>>
>>>> On Wed, Aug 03, 2022 at 01:51:05PM +0000, Arseniy Krasnov wrote:
>>>>> This adds transport specific callback for SO_RCVLOWAT, because in some
>>>>> transports it may be difficult to know current available number of bytes
>>>>> ready to read. Thus, when SO_RCVLOWAT is set, transport may reject it.
>>>>>
>>>>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>>>>> ---
>>>>> include/net/af_vsock.h | 1 +
>>>>> net/vmw_vsock/af_vsock.c | 25 +++++++++++++++++++++++++
>>>>> 2 files changed, 26 insertions(+)
>>>>>
>>>>> diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
>>>>> index f742e50207fb..eae5874bae35 100644
>>>>> --- a/include/net/af_vsock.h
>>>>> +++ b/include/net/af_vsock.h
>>>>> @@ -134,6 +134,7 @@ struct vsock_transport {
>>>>> u64 (*stream_rcvhiwat)(struct vsock_sock *);
>>>>> bool (*stream_is_active)(struct vsock_sock *);
>>>>> bool (*stream_allow)(u32 cid, u32 port);
>>>>> + int (*set_rcvlowat)(struct vsock_sock *, int);
>>>>
>>>> checkpatch suggests to add identifier names. For some we put them in,
>>>> for others we didn't, but I suggest putting them in for the new ones
>>>> because I think it's clearer too.
>>>>
>>>> WARNING: function definition argument 'struct vsock_sock *' should also
>>>> have an identifier name
>>>> #25: FILE: include/net/af_vsock.h:137:
>>>> + int (*set_rcvlowat)(struct vsock_sock *, int);
>>>>
>>>> WARNING: function definition argument 'int' should also have an identifier name
>>>> #25: FILE: include/net/af_vsock.h:137:
>>>> + int (*set_rcvlowat)(struct vsock_sock *, int);
>>>>
>>>> total: 0 errors, 2 warnings, 0 checks, 44 lines checked
>>>>
>>>>>
>>>>> /* SEQ_PACKET. */
>>>>> ssize_t (*seqpacket_dequeue)(struct vsock_sock *vsk, struct msghdr *msg,
>>>>> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>>>>> index f04abf662ec6..016ad5ff78b7 100644
>>>>> --- a/net/vmw_vsock/af_vsock.c
>>>>> +++ b/net/vmw_vsock/af_vsock.c
>>>>> @@ -2129,6 +2129,30 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
>>>>> return err;
>>>>> }
>>>>>
>>>>> +static int vsock_set_rcvlowat(struct sock *sk, int val)
>>>>> +{
>>>>> + const struct vsock_transport *transport;
>>>>> + struct vsock_sock *vsk;
>>>>> + int err = 0;
>>>>> +
>>>>> + vsk = vsock_sk(sk);
>>>>> +
>>>>> + if (val > vsk->buffer_size)
>>>>> + return -EINVAL;
>>>>> +
>>>>> + transport = vsk->transport;
>>>>> +
>>>>> + if (!transport)
>>>>> + return -EOPNOTSUPP;
>>>>
>>>> I don't know whether it is better in this case to write it in
>>>> sk->sk_rcvlowat, maybe we can return EOPNOTSUPP only when the trasport
>>>> is assigned and set_rcvlowat is not defined. This is because usually the
>>>> options are set just after creation, when the transport is practically
>>>> unassigned.
>>>>
>>>> I mean something like this:
>>>>
>>>> if (transport) {
>>>> if (transport->set_rcvlowat)
>>>> return transport->set_rcvlowat(vsk, val);
>>>> else
>>>> return -EOPNOTSUPP;
>>>> }
>>>>
>>>> WRITE_ONCE(sk->sk_rcvlowat, val ? : 1);
>>>>
>>>> return 0;
>>>
>>> Since hv_sock implements `set_rcvlowat` to return EOPNOTSUPP. maybe we
>>> can just do the following:
>>>
>>> if (transport && transport->set_rcvlowat)
>>> return transport->set_rcvlowat(vsk, val);
>>>
>>> WRITE_ONCE(sk->sk_rcvlowat, val ? : 1);
>>> return 0;
>>>
>>> That is, the default behavior is to set sk->sk_rcvlowat, but for
>>> transports that want a different behavior, they need to define
>>> set_rcvlowat() (like hv_sock).
>> Hm ok, i see. I've implemented logic when non-empty transport is required, because hyperv transport
>> forbids to set SO_RCVLOWAT, so user needs to call this setsockopt AFTER transport is assigned(to check
>> that transport allows it. Not after socket creation as You mentioned above). Otherwise there is no sense
>> in such callback - it will be never used. Also in code above - for hyperv we will have different behavior
>> depends on when set_rcvlowat is called: before or after transport assignment. Is it ok?
>sorry, i mean: for hyperv, if user sets sk_rcvlowat before transport is assigned, it sees 0 - success, but in fact
>hyperv transport forbids this option.
I see, but I think it's better to set it and not respect in hyperv (as
we've practically done until now with all transports) than to prevent
the setting until we assign a transport.
At most when we use hyperv anyway we get notified per byte, so we should
just get more notifications than we expect.
Thanks,
Stefano
next prev parent reply other threads:[~2022-08-09 10:04 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 13:48 [RFC PATCH v3 0/9] vsock: updates for SO_RCVLOWAT handling Arseniy Krasnov
2022-08-03 13:51 ` [RFC PATCH v3 1/9] vsock: SO_RCVLOWAT transport set callback Arseniy Krasnov
2022-08-08 10:23 ` Stefano Garzarella
2022-08-08 10:30 ` Stefano Garzarella
2022-08-09 9:37 ` Arseniy Krasnov
2022-08-09 9:45 ` Arseniy Krasnov
2022-08-09 10:03 ` Stefano Garzarella [this message]
2022-08-09 10:13 ` Arseniy Krasnov
2022-08-03 13:53 ` [RFC PATCH v3 2/9] hv_sock: disable SO_RCVLOWAT support Arseniy Krasnov
2022-08-08 10:31 ` Stefano Garzarella
2022-08-03 13:55 ` [RFC PATCH v3 3/9] virtio/vsock: use 'target' in notify_poll_in callback Arseniy Krasnov
2022-08-08 10:33 ` Stefano Garzarella
2022-08-03 13:57 ` [RFC PATCH v3 4/9] vmci/vsock: " Arseniy Krasnov
2022-08-08 10:36 ` Stefano Garzarella
2022-08-19 4:49 ` Vishnu Dasa
2022-08-03 13:59 ` [RFC PATCH v3 5/9] vsock: pass sock_rcvlowat to notify_poll_in as target Arseniy Krasnov
2022-08-08 10:46 ` Stefano Garzarella
2022-08-03 14:01 ` [RFC PATCH v3 6/9] vsock: add API call for data ready Arseniy Krasnov
2022-08-08 10:53 ` Stefano Garzarella
2022-08-03 14:03 ` [RFC PATCH v3 7/9] virtio/vsock: check SO_RCVLOWAT before wake up reader Arseniy Krasnov
2022-08-08 10:58 ` Stefano Garzarella
2022-08-03 14:05 ` [RFC PATCH v3 8/9] vmci/vsock: " Arseniy Krasnov
2022-08-08 11:01 ` Stefano Garzarella
2022-08-19 4:46 ` Vishnu Dasa
2022-08-03 14:07 ` [RFC PATCH v3 9/9] vsock_test: POLLIN + SO_RCVLOWAT test Arseniy Krasnov
2022-08-08 11:10 ` Stefano Garzarella
2022-08-08 11:14 ` Stefano Garzarella
2022-08-05 16:05 ` [RFC PATCH v3 0/9] vsock: updates for SO_RCVLOWAT handling Stefano Garzarella
2022-08-08 6:30 ` Arseniy Krasnov
2022-08-08 11:22 ` Stefano Garzarella
2022-08-09 9:19 ` Arseniy Krasnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220809100358.xnxromtvrehsgpn3@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=AVKrasnov@sberdevices.ru \
--cc=bryantan@vmware.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=haiyangz@microsoft.com \
--cc=kernel@sberdevices.ru \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oxffffaa@gmail.com \
--cc=pabeni@redhat.com \
--cc=pv-drivers@vmware.com \
--cc=stefanha@redhat.com \
--cc=sthemmin@microsoft.com \
--cc=vdasa@vmware.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).