From: Arseniy Krasnov <oxffffaa@gmail.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Arseniy Krasnov <AVKrasnov@sberdevices.ru>,
Stefan Hajnoczi <stefanha@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Bobby Eshleman <bobby.eshleman@bytedance.com>,
kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@sberdevices.ru
Subject: Re: [RFC PATCH v1 1/2] vsock: send SIGPIPE on write to shutdowned socket
Date: Fri, 4 Aug 2023 19:24:02 +0300 [thread overview]
Message-ID: <15ba8dc5-0bab-1829-16f5-54de14cef5a7@gmail.com> (raw)
In-Reply-To: <e2ytj5asmxnyb7oebxpzfuithtidwzcwxki7aao2q344sg3yru@ezqk5iezf3i4>
On 04.08.2023 18:02, Stefano Garzarella wrote:
> On Fri, Aug 04, 2023 at 05:34:20PM +0300, Arseniy Krasnov wrote:
>>
>>
>> On 04.08.2023 17:28, Stefano Garzarella wrote:
>>> On Fri, Aug 04, 2023 at 03:46:47PM +0300, Arseniy Krasnov wrote:
>>>> Hi Stefano,
>>>>
>>>> On 02.08.2023 10:46, Stefano Garzarella wrote:
>>>>> On Tue, Aug 01, 2023 at 05:17:26PM +0300, Arseniy Krasnov wrote:
>>>>>> POSIX requires to send SIGPIPE on write to SOCK_STREAM socket which was
>>>>>> shutdowned with SHUT_WR flag or its peer was shutdowned with SHUT_RD
>>>>>> flag. Also we must not send SIGPIPE if MSG_NOSIGNAL flag is set.
>>>>>>
>>>>>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>>>>>> ---
>>>>>> net/vmw_vsock/af_vsock.c | 3 +++
>>>>>> 1 file changed, 3 insertions(+)
>>>>>>
>>>>>> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>>>>>> index 020cf17ab7e4..013b65241b65 100644
>>>>>> --- a/net/vmw_vsock/af_vsock.c
>>>>>> +++ b/net/vmw_vsock/af_vsock.c
>>>>>> @@ -1921,6 +1921,9 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
>>>>>> err = total_written;
>>>>>> }
>>>>>> out:
>>>>>> + if (sk->sk_type == SOCK_STREAM)
>>>>>> + err = sk_stream_error(sk, msg->msg_flags, err);
>>>>>
>>>>> Do you know why we don't need this for SOCK_SEQPACKET and SOCK_DGRAM?
>>>>
>>>> Yes, here is my explanation:
>>>>
>>>> This function checks that input error is SIGPIPE, and if so it sends SIGPIPE to the 'current' thread
>>>> (except case when MSG_NOSIGNAL flag is set). This behaviour is described in POSIX:
>>>>
>>>> Page 367 (description of defines from sys/socket.h):
>>>> MSG_NOSIGNAL: No SIGPIPE generated when an attempt to send is made on a stream-
>>>> oriented socket that is no longer connected.
>>>>
>>>> Page 497 (description of SOCK_STREAM):
>>>> A SIGPIPE signal is raised if a thread sends on a broken stream (one that is
>>>> no longer connected).
>>>
>>> Okay, but I think we should do also for SEQPACKET:
>>>
>>> https://pubs.opengroup.org/onlinepubs/009696699/functions/xsh_chap02_10.html
>>>
>>> In 2.10.6 Socket Types:
>>>
>>> "The SOCK_SEQPACKET socket type is similar to the SOCK_STREAM type, and
>>> is also connection-oriented. The only difference between these types is
>>> that record boundaries ..."
>>>
>>> Then in 2.10.14 Signals:
>>>
>>> "The SIGPIPE signal shall be sent to a thread that attempts to send data
>>> on a socket that is no longer able to send. In addition, the send
>>> operation fails with the error [EPIPE]."
>>>
>>> It's honestly not super clear, but I assume the problem is similar with
>>> seqpacket since it's connection-oriented, or did I miss something?
>>>
>>> For example in sctp_sendmsg() IIUC we raise a SIGPIPE regardless of
>>> whether the socket is STREAM or SEQPACKET.
>>
>> Hm, yes, you're right. Seems check for socket type is not needed in this case,
>> as this function is only for connection oriented sockets.
>
> Ack!
>
>>
>>>
>>>>
>>>> Page 1802 (description of 'send()' call):
>>>> MSG_NOSIGNAL
>>>>
>>>> Requests not to send the SIGPIPE signal if an attempt to
>>>> send is made on a stream-oriented socket that is no
>>>> longer connected. The [EPIPE] error shall still be
>>>> returned
>>>>
>>>> And the same for 'sendto()' and 'sendmsg()'
>>>>
>>>> Link to the POSIX document:
>>>> https://www.open-std.org/jtc1/sc22/open/n4217.pdf
>>>>
>>>> TCP (I think we must rely on it), KCM, SMC sockets (all of them are stream) work in the same
>>>> way by calling this function. AF_UNIX also works in the same way, but it implements SIGPIPE handling
>>>> without this function.
>>>
>>> I'm okay calling this function.
>>>
>>>>
>>>> The only thing that confused me a little bit, that sockets above returns EPIPE when
>>>> we have only SEND_SHUTDOWN set, but for AF_VSOCK EPIPE is returned for RCV_SHUTDOWN
>>>> also, but I think it is related to this patchset.
>>>
>>> Do you mean that it is NOT related to this patchset?
>>
>> Yes, **NOT**
>
> Got it, so if you have time when you're back, let's check also that
> (not for this series as you mentioned).
Sure!
Thanks, Arseniy
>
> Thanks,
> Stefano
>
next prev parent reply other threads:[~2023-08-04 16:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 14:17 [RFC PATCH v1 0/2] vsock: handle writes to shutdowned socket Arseniy Krasnov
2023-08-01 14:17 ` [RFC PATCH v1 1/2] vsock: send SIGPIPE on write " Arseniy Krasnov
2023-08-02 7:46 ` Stefano Garzarella
2023-08-04 12:46 ` Arseniy Krasnov
2023-08-04 14:28 ` Stefano Garzarella
2023-08-04 14:34 ` Arseniy Krasnov
2023-08-04 15:02 ` Stefano Garzarella
2023-08-04 16:24 ` Arseniy Krasnov [this message]
2023-08-14 19:40 ` Arseniy Krasnov
2023-08-22 9:36 ` Stefano Garzarella
2023-08-14 19:46 ` Arseniy Krasnov
2023-08-22 9:39 ` Stefano Garzarella
2023-08-22 12:51 ` Arseniy Krasnov
2023-08-01 14:17 ` [RFC PATCH v1 2/2] test/vsock: shutdowned socket test Arseniy Krasnov
2023-08-02 8:00 ` Stefano Garzarella
2023-08-04 12:48 ` 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=15ba8dc5-0bab-1829-16f5-54de14cef5a7@gmail.com \
--to=oxffffaa@gmail.com \
--cc=AVKrasnov@sberdevices.ru \
--cc=bobby.eshleman@bytedance.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jasowang@redhat.com \
--cc=kernel@sberdevices.ru \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux-foundation.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).