From: Clay Mayers <Clay.Mayers@kioxia.com>
To: Kanchan Joshi <joshiiitr@gmail.com>, Christoph Hellwig <hch@lst.de>
Cc: Kanchan Joshi <joshi.k@samsung.com>,
"kbusch@kernel.org" <kbusch@kernel.org>,
"axboe@kernel.dk" <axboe@kernel.dk>,
"sagi@grimberg.me" <sagi@grimberg.me>,
"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
"vincentfu@gmail.com" <vincentfu@gmail.com>,
"ankit.kumar@samsung.com" <ankit.kumar@samsung.com>,
"cpgs@samsung.com" <cpgs@samsung.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
Vincent Fu <vincent.fu@samsung.com>
Subject: RE: [PATCH v3] nvme: fix memory corruption for passthrough metadata
Date: Tue, 10 Oct 2023 15:31:23 +0000 [thread overview]
Message-ID: <8a0e5f41559646d9b505b11386142b55@kioxia.com> (raw)
In-Reply-To: <CA+1E3r+2Ce4BCZ2feJX37e1-dtvpZtY6ajiaO_orn8Airu2Bqg@mail.gmail.com>
On Tuesday, October 10, 2023 6:40 AM Kanchan Joshi <joshi.k@samsung.com> wrote:
>
> On Tue, Oct 10, 2023 at 1:16 PM Christoph Hellwig <hch@lst.de> wrote:
> >
> > On Fri, Oct 06, 2023 at 07:17:06PM +0530, Kanchan Joshi wrote:
> > > Same issue is possible for extended-lba case also. When user specifies a
> > > short unaligned buffer, the kernel makes a copy and uses that for DMA.
> >
> > I fail to understand the extent LBA case, and also from looking at the
> > code mixing it up with validation of the metadata_len seems very
> > confusion. Can you try to clearly explain it and maybe split it into a
> > separate patch?
>
> The case is for the single interleaved buffer with both data and
> metadata. When the driver sends this buffer to blk_rq_map_user_iov(),
> it may make a copy of it.
> This kernel buffer will be used for DMA rather than user buffer. If
> the user-buffer is short, the kernel buffer is also short.
>
> Does this explanation help?
> I can move the part to a separate patch.
>
> > > Fixes: 456cba386e94 ("nvme: wire-up uring-cmd support for io-passthru on
> char-device")
> >
> > Is this really io_uring specific? I think we also had the same issue
> > before and this should go back to adding metadata support to the
> > general passthrough ioctl?
>
> Yes, not io_uring specific.
> Just that I was not sure on (i) whether to go back that far in
> history, and (ii) what patch to tag.
>
> > > +static inline bool nvme_nlb_in_cdw12(u8 opcode)
> > > +{
> > > + switch (opcode) {
> > > + case nvme_cmd_read:
> > > + case nvme_cmd_write:
> > > + case nvme_cmd_compare:
> > > + case nvme_cmd_zone_append:
> > > + return true;
> > > + }
> > > + return false;
> > > +}
> >
> > Nitpick: I find it nicer to read to have a switch that catches
> > everything with a default statement instead of falling out of it
> > for checks like this. It's not making any different in practice
> > but just reads a little nicer.
>
> Sure, I can change it.
>
What if the ns used the KV CS? Store and retrieve are the same
op codes as nvme_cmd_write and nvme_cmd_read.
> > > + /* Exclude commands that do not have nlb in cdw12 */
> > > + if (!nvme_nlb_in_cdw12(c->common.opcode))
> > > + return true;
> >
> > So we can still get exactly the same corruption for all commands that
> > are not known? That's not a very safe way to deal with the issue..
>
> Given the way things are in NVMe, I do not find a better way.
> Maybe another day for commands that do (or can do) things very
> differently for nlb and PI representation.
>
> > > + control = upper_16_bits(le32_to_cpu(c->common.cdw12));
> > > + /* Exclude when meta transfer from/to host is not done */
> > > + if (control & NVME_RW_PRINFO_PRACT && ns->ms == ns->pi_size)
> > > + return true;
> > > +
> > > + nlb = lower_16_bits(le32_to_cpu(c->common.cdw12));
> >
> > I'd use the rw field of the union and the typed control and length
> > fields to clean this up a bit.
> >
> > > if (bdev && meta_buffer && meta_len) {
> > > + if (!nvme_validate_passthru_meta(ns, nvme_req(req)->cmd,
> > > + meta_len, bufflen)) {
> > > + ret = -EINVAL;
> > > + goto out_unmap;
> > > + }
> > > +
> > > meta = nvme_add_user_metadata(req, meta_buffer, meta_len,
> >
> > I'd move the check into nvme_add_user_metadata to keep it out of the
> > hot path.
> >
> > FYI: here is what I'd do for the external metadata only case:
>
> Since you have improvised comments too, I may just use this for the
> next iteration.
next prev parent reply other threads:[~2023-10-10 15:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20231006135322epcas5p1c9acf38b04f35017181c715c706281dc@epcas5p1.samsung.com>
2023-10-06 13:47 ` [PATCH v3] nvme: fix memory corruption for passthrough metadata Kanchan Joshi
2023-10-10 7:46 ` Christoph Hellwig
2023-10-10 13:39 ` Kanchan Joshi
2023-10-10 15:31 ` Clay Mayers [this message]
2023-10-11 5:03 ` Christoph Hellwig
2023-10-11 5:02 ` Christoph Hellwig
2023-10-11 5:26 ` Kanchan Joshi
2023-10-11 6:36 ` Christoph Hellwig
2023-10-11 17:04 ` Keith Busch
2023-10-12 4:36 ` Christoph Hellwig
2023-10-12 15:31 ` Keith Busch
2023-10-12 15:46 ` Christoph Hellwig
2023-10-13 2:19 ` Kanchan Joshi
2023-10-13 4:38 ` Christoph Hellwig
2023-10-13 5:50 ` Kanchan Joshi
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=8a0e5f41559646d9b505b11386142b55@kioxia.com \
--to=clay.mayers@kioxia.com \
--cc=ankit.kumar@samsung.com \
--cc=axboe@kernel.dk \
--cc=cpgs@samsung.com \
--cc=hch@lst.de \
--cc=joshi.k@samsung.com \
--cc=joshiiitr@gmail.com \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=stable@vger.kernel.org \
--cc=vincent.fu@samsung.com \
--cc=vincentfu@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox