public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Homura Akemi <a1134123566@gmail.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH v3 00/28] usb: gadget: f_tcm: Enhance UASP driver
Date: Fri, 20 Dec 2024 20:14:44 +0000	[thread overview]
Message-ID: <20241220201428.id3mocw5erctxkto@synopsys.com> (raw)
In-Reply-To: <CAC7i41Mqhfc7JOcF2SH4Mb2xm-Y1sD3c9Osty0SGxv7buYQYjQ@mail.gmail.com>

(Removed Cc invalid emails to Nicholas and Andrzej)

Hi,

On Fri, Dec 20, 2024, Homura Akemi wrote:
> Hi Thinh,
> 
> On 2024-12-11 0:31 UTC, Thinh Nguyen <Thinh.Nguyen@synopsys.com> wrote:
> > 1) Fix Data Corruption
> > ----------------------
> >
> > Properly increment the "len" base on the command requested length instead of
> > the SG entry length.
> >
> > If you're using File backend, then you need to fix target_core_file. If you're
> > using other backend such as Ramdisk, then you need a similar fix there.
> 
> I am trying to do some basic rw aging test with this serie on my gadget board.
> When it comes to target_core_iblock, the rw code is less similar to the one in
> target_core_file or ramdisk.
> Could you just spend some extra time explaining what cause the Data
> Corruption issue and how can this fix it ? So that I could perform
> similar fix in
> target_core_iblock on my own, so a full test could start soonner.
> 

When we prepare a new generic command for read/write, we call to
target_alloc_sgl(). This will allocate PAGE_SIZE SG entries enough to
handle the se_cmd read/write base on its length. The total length of all
the SG entries combine will be at least se_cmd->data_length.

The typical block size is 512 byte. A page size is typically 4KB. So,
the se_cmd->data_length may not be a multiple of PAGE_SiZE. In
target_core_file, it execute_rw() with this logic:

	for_each_sg(sgl, sg, sgl_nents, i) {
		bvec_set_page(&aio_cmd->bvecs[i], sg_page(sg), sg->length,
			      sg->offset);
		len += sg->length;
	}

// It sets the length to be the iter to be total length of the
// allocated SG entries and not the requested command length:

	iov_iter_bvec(&iter, is_write, aio_cmd->bvecs, sgl_nents, len);

	aio_cmd->cmd = cmd;
	aio_cmd->len = len;
	aio_cmd->iocb.ki_pos = cmd->t_task_lba * dev->dev_attrib.block_size;
	aio_cmd->iocb.ki_filp = file;
	aio_cmd->iocb.ki_complete = cmd_rw_aio_complete;
	aio_cmd->iocb.ki_flags = IOCB_DIRECT;

	if (is_write && (cmd->se_cmd_flags & SCF_FUA))
		aio_cmd->iocb.ki_flags |= IOCB_DSYNC;

// So when we do f_op read/write, we may do more than needed and may
// write bogus data from the extra SG entry length.

	if (is_write)
		ret = file->f_op->write_iter(&aio_cmd->iocb, &iter);
	else
		ret = file->f_op->read_iter(&aio_cmd->iocb, &iter);


I did not review target_core_iblock. It may or may not do things
properly.

BR,
Thinh

      reply	other threads:[~2024-12-20 20:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-11  0:31 [PATCH v3 00/28] usb: gadget: f_tcm: Enhance UASP driver Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 01/28] usb: gadget: f_tcm: Don't free command immediately Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 02/28] usb: gadget: f_tcm: Translate error to sense Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 03/28] usb: gadget: f_tcm: Decrement command ref count on cleanup Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 04/28] usb: gadget: f_tcm: Fix Get/SetInterface return value Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 05/28] usb: gadget: f_tcm: ep_autoconfig with fullspeed endpoint Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 06/28] usb: gadget: f_tcm: Don't prepare BOT write request twice Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 07/28] usb: gadget: f_tcm: Increase stream count Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 08/28] usb: gadget: f_tcm: Increase bMaxBurst Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 09/28] usb: gadget: f_tcm: Limit number of sessions Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 10/28] usb: gadget: f_tcm: Get stream by sbitmap number Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 11/28] usb: gadget: f_tcm: Don't set static stream_id Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 12/28] usb: gadget: f_tcm: Allocate matching number of commands to streams Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 13/28] usb: gadget: f_tcm: Handle multiple commands in parallel Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 14/28] usb: gadget: f_tcm: Use extra number of commands Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 15/28] usb: gadget: f_tcm: Return ATA cmd direction Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 16/28] usb: gadget: f_tcm: Execute command on write completion Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 17/28] usb: gadget: f_tcm: Minor cleanup redundant code Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 18/28] usb: gadget: f_tcm: Handle abort command Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 19/28] usb: gadget: f_tcm: Cleanup requests on ep disable Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 20/28] usb: gadget: f_tcm: Stop proceeding further on -ESHUTDOWN Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 21/28] usb: gadget: f_tcm: Save CPU ID per command Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 22/28] usb: gadget: f_tcm: Send sense on cancelled transfer Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 23/28] usb: gadget: f_tcm: Handle TASK_MANAGEMENT commands Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 24/28] usb: gadget: f_tcm: Check overlapped command Thinh Nguyen
2024-12-19 13:47   ` Dan Carpenter
2024-12-20  2:31     ` Thinh Nguyen
2025-01-06  8:01       ` Dan Carpenter
2024-12-11  0:34 ` [PATCH v3 25/28] usb: gadget: f_tcm: Stall on invalid CBW Thinh Nguyen
2024-12-11  0:34 ` [PATCH v3 26/28] usb: gadget: f_tcm: Requeue command request on error Thinh Nguyen
2024-12-11  0:34 ` [PATCH v3 27/28] usb: gadget: f_tcm: Track BOT command kref Thinh Nguyen
2024-12-11  0:34 ` [PATCH v3 28/28] usb: gadget: f_tcm: Refactor goto check_condition Thinh Nguyen
2024-12-11 10:42 ` [PATCH v3 00/28] usb: gadget: f_tcm: Enhance UASP driver Greg Kroah-Hartman
2024-12-11 17:11   ` Thinh Nguyen
2024-12-20 12:59 ` Homura Akemi
2024-12-20 20:14   ` Thinh Nguyen [this message]

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=20241220201428.id3mocw5erctxkto@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=a1134123566@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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