All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Potapenko <glider@google.com>
To: Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>,
	Damien Le Moal <damien.lemoal@wdc.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Dmitriy Vyukov <dvyukov@google.com>
Subject: Re: null_handle_cmd() doesn't initialize data when reading
Date: Sun, 10 May 2020 12:03:24 +0200	[thread overview]
Message-ID: <CAG_fn=WVHpRQ19MK12pxiizTEvUFLiV7LJgF_LrX_G2SYd=ivQ@mail.gmail.com> (raw)
In-Reply-To: <BYAPR04MB57495B31CEA65B2B5D76203C864A0@BYAPR04MB5749.namprd04.prod.outlook.com>

(+Damien Le Moal)
(more context at
https://lore.kernel.org/linux-block/CAG_fn=VBHmBgqLi35tD27NRLH2tEZLH=Y+rTfZ3rKNz9ipG+jQ@mail.gmail.com/)

On Mon, Nov 25, 2019 at 5:01 AM Chaitanya Kulkarni
<Chaitanya.Kulkarni@wdc.com> wrote:
>
> On 11/22/2019 03:58 AM, Alexander Potapenko wrote:
> > I'm using the following patch in KMSAN tree to suppress these bugs:
> >
> > diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> > index 0e7da5015ccd5..9e8e99bdc0db3 100644
> > --- a/drivers/block/null_blk_main.c
> > +++ b/drivers/block/null_blk_main.c
> > @@ -1235,8 +1235,16 @@ static blk_status_t null_handle_cmd(struct
> > nullb_cmd *cmd, sector_t sector,
> >          if (dev->memory_backed)
> >                  cmd->error = null_handle_memory_backed(cmd, op);
> >
> > -       if (!cmd->error && dev->zoned)
> > +       if (!cmd->error && dev->zoned) {
> >                  cmd->error = null_handle_zoned(cmd, op, sector, nr_sectors);
> > +       } else if (dev->queue_mode != NULL_Q_BIO) {
> > +               /*
> > +                * TODO(glider): this is a hack to suppress bugs in nullb
> > +                * driver. I have no idea what I'm doing, better wait for a
> > +                * proper fix from Jens Axboe.
> > +                */
> > +               cmd->error = null_handle_rq(cmd);
> > +       }
>
> This is just based on what I read in the code, I don't have
> the kmsan support.
>
> null_handle_rq() should not be called without checking the
> dev->memory_backed value since it handles memory backed operation,
> (it may be working because of the correct error handling done
> in the copy_from_nullb() when t_page == NULL).

Thanks for the explanation!
The code has changed recently, and my patch does not apply anymore,
yet the problem still persists.
I ended up just calling null_handle_rq() at the end of
null_process_cmd(), but we probably need a cleaner fix.

> Possible explanation could be for the above code fixing the problem
> is:-
>
> null_handle_cmd()
>         None of the ifs are handled (since it is default behavior)
>         calls null_handle_rq()
>                 Processes each bvec in this request :-
>                 rq_for_each_segment()
>                         calls null_transfer()
>                                 calls copy_from_null()
>
> Now here in copy_from_null(), null_lookup_page() returns
> NULL since it is not present in the radix tree(dev and cache
> since its !membacked && !cache_size I assume since I don't have
> the command line of modprobe null_blk),
>
> and then does the dest memset():-
>
> (from linux-block for-next)
> 1009                 if (!t_page) {
> 1010                         memset(dst + off + count, 0, temp);
> 1011                         goto next;
> 1012                 }
>
> which initializes the destination page to 0. This is what Jens
> is referring to I guess that we need to memset() it for the
> read when !membacked.
>
> It will be great if you can verify the above code path on your
> setup with above memset().
>
> The above patch does fix the problem but it is very confusing.
>
> What we need is to traverse the rq bvec and actually initialize
> the bvec.page and repeat the pattern present in the copy_from_null()
> in such a way this common code is shared between membacked and
> non-membacked mode for REQ_OP_READ.
>
> Jens can correct me if I'm wrong.
>
> I'll be happy to look into this if Jens is okay.
>
> >
> > It appears to fix the problem, but I'm not really sure this is the
> > right thing to do (e.g. whether it covers all invocations of
> > null_handle_cmd(), probably not)
> > I don't see an easy way to memset() the pages being read, as there're
> > no pages at this point.
> >
>
>
> >> >--
>


-- 
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

  reply	other threads:[~2020-05-10 10:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15 10:16 null_handle_cmd() doesn't initialize data when reading Alexander Potapenko
2019-11-20 23:12 ` Jens Axboe
2019-11-22 11:58   ` Alexander Potapenko
2019-11-25  4:01     ` Chaitanya Kulkarni
2020-05-10 10:03       ` Alexander Potapenko [this message]
2020-05-10 16:20         ` Bart Van Assche
2020-05-11 12:58           ` Alexander Potapenko
2020-05-11 13:01             ` Damien Le Moal
2020-05-11 13:09               ` Alexander Potapenko
2020-05-11 23:18             ` Bart Van Assche
2020-05-12  1:25               ` Bart Van Assche
2020-05-12  1:42                 ` Damien Le Moal
2020-05-12  2:43                   ` Bart Van Assche
2020-05-12  3:23                     ` Damien Le Moal

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='CAG_fn=WVHpRQ19MK12pxiizTEvUFLiV7LJgF_LrX_G2SYd=ivQ@mail.gmail.com' \
    --to=glider@google.com \
    --cc=Chaitanya.Kulkarni@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=damien.lemoal@wdc.com \
    --cc=dvyukov@google.com \
    --cc=linux-block@vger.kernel.org \
    --cc=willemb@google.com \
    /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.