All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Shilovsky <pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
To: Jeff Layton <jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
Cc: linux-cifs <linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Steve French <smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH v2 01/16] CIFS: Fix async reading on reconnects
Date: Thu, 3 Jul 2014 20:12:57 +0400	[thread overview]
Message-ID: <CAKywueSH2GLmzcVbeUbq5X4h7K_yfMawv+-sisXPF5g3hheYeQ@mail.gmail.com> (raw)
In-Reply-To: <20140703064549.7f6913f3-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>

2014-07-03 14:45 GMT+04:00 Jeff Layton <jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>:
> On Fri, 27 Jun 2014 20:06:48 +0400
> Pavel Shilovsky <pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org> wrote:
>
>> 2014-06-27 14:52 GMT+04:00 Jeff Layton <jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org>:
>> > On Fri, 27 Jun 2014 13:57:38 +0400
>> > Pavel Shilovsky <pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org> wrote:
>> >
>> >> If we get into read_into_pages() from cifs_readv_receive() and then
>> >> loose a network, we issue cifs_reconnect that moves all mids to
>> >> a private list and issue their callbacks. The callback of the async
>> >> read request sets a mid to retry, frees it and wakes up a process
>> >> that waits on the rdata completion.
>> >>
>> >> After the connection is established we return from read_into_pages()
>> >> with a short read, use the mid that was freed before and try to read
>> >> the remaining data from the a newly created socket. Both actions are
>> >> not what we want to do. In reconnect cases (-EAGAIN) we should not
>> >> mask off the error with a short read but should return the error
>> >> code instead.
>> >>
>> >
>> > I'm not sure I understand what problem this solves. Why is returning a
>> > short read wrong here?
>> >
>>
>> This patch solves several problems in cifs_readv_receive() when
>> read_into_pages() call ended up with cifs_reconnect inside it:
>>
>> 1) prevents use-after-free and a possible double free for "mid"
>> variable; this can cause kernel oopses.
>>
>> 2) prevents updating rdata->bytes with a short read length that causes
>> the cifs_async_readv() caller to retry write request with a shorten
>> wrong length; this can cause data coherency problems.
>>
>> 3) prevents reading an actual data from a newly created socket through
>> cifs_readv_discard() -- this data can be a part of a negotiate
>> response received from the server; this can cause the client to retry
>> negotiate or hang.
>>
>> Oopses from the 1st scenario was not observed since
>> cifs_readv_discard() returns negative value while trying to get a
>> remaining data. The 2nd and 3rd one were caught during testing: issue
>> reading with "dd", then switch off network on the server, wait 120 sec
>> and switch on network. The bug is caught when we are lucky enough to
>> stop the link while the client is in read_into_pages().
>>
>> The patch fixes all these problems for me. It stays on the following
>> logic if a reconnect has happened:
>> 1) all mids are already marked to retry and their callbacks are issued
>> - we shouldn't do anything with our mid/rdata since the requests will
>> be retried anyway.
>> 2) the socket is newly created - we shouldn't try to get any remaining
>> data of the previous connection.
>>
>> While -EAGAIN error code will be able to indicate something else in
>> possible future patches I prefer to leave it that way since the patch
>> is small and easy to apply that is critical for stable series. More
>> accurate way is to add a flag that is passed through
>> cifs_readv_from_socket() and switched on if cifs_reconnect() was
>> issued (like Steve suggested).
>>
>
> Hmm, ok. I think the best fix would be to use a different error code
> than -EAGAIN for the case where we have or are going to reconnect the
> socket.
>
> My main concern here is that you may end up doing 99% of a valid read
> into the set of pages, only to get a disconnect right at the end. If
> you eventually end up returning a non-retryable error back to userland,
> it may not expect that the pages it passed in were written to. If you
> don't return a short read in that situation then you're potentially not
> communicating what actually happened to userland.

In that case we should prevent cifs_reconnect from removing the MID we
are actually using in cifs_readv_receive() from the mid list. For
example by calling dequeue_mid() before read_into_pages() and then
returning a short read if reconnect happened?


-- 
Best regards,
Pavel Shilovsky.

  parent reply	other threads:[~2014-07-03 16:12 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27  9:57 [PATCH v2 00/16] SMB 2.1/3 multicredit requests for reading/writing Pavel Shilovsky
     [not found] ` <1403863073-19526-1-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-06-27  9:57   ` [PATCH v2 01/16] CIFS: Fix async reading on reconnects Pavel Shilovsky
     [not found]     ` <1403863073-19526-2-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-06-27 10:52       ` Jeff Layton
     [not found]         ` <CAH2r5mvWfmgZb=7oGqbqbRDKv4xPP3RszHXpe-rxGv5FbGBerw@mail.gmail.com>
     [not found]           ` <CAH2r5mvWfmgZb=7oGqbqbRDKv4xPP3RszHXpe-rxGv5FbGBerw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-06-27 14:14             ` Fwd: " Steve French
     [not found]         ` <20140627065222.434cd5ea-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-06-27 16:06           ` Pavel Shilovsky
     [not found]             ` <CAKywueSpPjEpyQYLvrSixf4tasxd5v4a51EBKhBboaTXcs5O1A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-03 10:45               ` Jeff Layton
     [not found]                 ` <20140703064549.7f6913f3-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-07-03 16:12                   ` Pavel Shilovsky [this message]
2014-07-03 16:39                   ` Jeff Layton
     [not found]                     ` <20140703123930.5feb046f-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-07-21 15:41                       ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 02/16] CIFS: Separate page processing from writepages Pavel Shilovsky
     [not found]     ` <1403863073-19526-3-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-09 12:59       ` Jeff Layton
2014-06-27  9:57   ` [PATCH v2 03/16] CIFS: Separate page sending " Pavel Shilovsky
     [not found]     ` <1403863073-19526-4-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-09 13:08       ` Jeff Layton
     [not found]         ` <20140709090823.08bbd37b-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-07-21 15:53           ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 04/16] CIFS: Separate pages initialization " Pavel Shilovsky
     [not found]     ` <1403863073-19526-5-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-19  6:24       ` Shirish Pargaonkar
2014-06-27  9:57   ` [PATCH v2 05/16] CIFS: Fix wsize usage in writepages Pavel Shilovsky
     [not found]     ` <1403863073-19526-6-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-20 15:17       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+ce727VwQD6WmhY_SWG_Xm+2JxGuC2GnPZG==nv9FgxQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-20 17:41           ` Pavel Shilovsky
     [not found]             ` <CAKywueRP6y7gdyXCYVBCXQU3_65=rU7+cP-UdgBrO5cwx+_nCA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-20 18:13               ` Shirish Pargaonkar
     [not found]                 ` <CADT32eK15DRUnrogmFFv2TicqhOhcNA0Y62dUeM+41YtjrZwFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  7:03                   ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 06/16] CIFS: Fix cifs_writev_requeue when wsize changes Pavel Shilovsky
     [not found]     ` <1403863073-19526-7-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-20 19:49       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+kGf-b989EFr4c_-e9+_MCVMkDShkh_30an8YKLiD6Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  6:43           ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 07/16] CIFS: Separate filling pages from iovec write Pavel Shilovsky
     [not found]     ` <1403863073-19526-8-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-21  3:59       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+RhpebBn-2k-GrNomJ_=uY8v12KmWHFbd+NozNSi1t9w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  6:48           ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 08/16] CIFS: Separate writing " Pavel Shilovsky
     [not found]     ` <1403863073-19526-9-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-21  5:05       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+2Z_ryfg8JznJoFt9=4mSU1bVYmeR-+nguXUq1vQVMMg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  6:56           ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 09/16] CIFS: Fix wsize usage in " Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 10/16] CIFS: Use multicredits for SMB 2.1/3 writes Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 11/16] CIFS: Separate page search from readpages Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 12/16] CIFS: Fix rsize usage in readpages Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 13/16] CIFS: Separate page reading from user read Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 14/16] CIFS: Fix rsize usage in " Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 15/16] CIFS: Fix rsize usage for sync read Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 16/16] CIFS: Use multicredits for SMB 2.1/3 reads Pavel Shilovsky

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=CAKywueSH2GLmzcVbeUbq5X4h7K_yfMawv+-sisXPF5g3hheYeQ@mail.gmail.com \
    --to=pshilovsky-eunubhrolfbytjvyw6ydsg@public.gmane.org \
    --cc=jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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 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.