public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: Stefan Metzmacher <[email protected]>
Cc: io-uring <[email protected]>
Subject: Re: [PATCH] io_uring/net: save msghdr->msg_control for retries
Date: Mon, 19 Jun 2023 08:38:47 -0600	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 6/19/23 7:27?AM, Stefan Metzmacher wrote:
> Am 19.06.23 um 15:09 schrieb Stefan Metzmacher:
>> Am 19.06.23 um 15:05 schrieb Jens Axboe:
>>> On 6/19/23 3:57?AM, Stefan Metzmacher wrote:
>>>> Hi Jens,
>>>>
>>>>> If the application sets ->msg_control and we have to later retry this
>>>>> command, or if it got queued with IOSQE_ASYNC to begin with, then we
>>>>> need to retain the original msg_control value. This is due to the net
>>>>> stack overwriting this field with an in-kernel pointer, to copy it
>>>>> in. Hitting that path for the second time will now fail the copy from
>>>>> user, as it's attempting to copy from a non-user address.
>>>>
>>>> I'm not 100% sure about the impact of this change.
>>>>
>>>> But I think the logic we need is that only the
>>>> first __sys_sendmsg_sock() that returns > 0 should
>>>> see msg_control. A retry because of MSG_WAITALL should
>>>> clear msg_control[len] for a follow up __sys_sendmsg_sock().
>>>> And I fear the patch below would not clear it...
>>>>
>>>> Otherwise the receiver/socket-layer will get the same msg_control twice,
>>>> which is unexpected.
>>>
>>> Yes agree, if we do transfer some (but not all) data and WAITALL is set,
>>> it should get cleared. I'll post a patch for that.
>>
>> Thanks!
>>
>>> Note that it was also broken before, just differently broken. The most
>>> likely outcome here was a full retry and now getting -EFAULT.
>>
>> Yes, I can see that it was broken before...
> 
> I haven't checked myself, but I'm wondering about the recvmsg case,
> I guess we would need to advance the msg_control buffer after each
> iteration, in order to avoid overwritting the already received messages
> on retry.
> 
> This all gets complicated with things like MSG_CTRUNC.
> 
> I guess it's too late to reject MSG_WAITALL together with msg_control
> for io_recvmsg() because of compat reasons,
> but as MSG_WAITALL is also processed in the socket layer, we could keep it
> simple for now and skip the this retry logic:
> 
>         if (flags & MSG_WAITALL)
>                 min_ret = iov_iter_count(&kmsg->msg.msg_iter);
> 
> This might become something similar to this,
> but likely more complex, as would need to record kmsg->controllen == 0
> condition already in io_recvmsg_prep:
> 
>         if (flags & MSG_WAITALL && kmsg->controllen == 0)
>                 min_ret = iov_iter_count(&kmsg->msg.msg_iter);

Yep agree, I think this is the best way - ensure that once we transfer
data with cmsg, it's a one-shot kind of deal.

Do you want to cut a patch for that one?

-- 
Jens Axboe


  reply	other threads:[~2023-06-19 14:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 19:56 [PATCH] io_uring/net: save msghdr->msg_control for retries Jens Axboe
2023-06-19  9:57 ` Stefan Metzmacher
2023-06-19 13:05   ` Jens Axboe
2023-06-19 13:09     ` Stefan Metzmacher
2023-06-19 13:27       ` Stefan Metzmacher
2023-06-19 14:38         ` Jens Axboe [this message]
2023-06-19 14:40           ` Stefan Metzmacher
2023-06-19 14:40             ` Jens Axboe

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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