linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Vacura <w36195@motorola.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	stable@vger.kernel.org,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Felipe Balbi <balbi@kernel.org>,
	Michael Grzeschik <m.grzeschik@pengutronix.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: uvc: fix sg handling in error case
Date: Tue, 27 Sep 2022 10:47:55 -0500	[thread overview]
Message-ID: <YzMbK0ZZ08WD8ql+@p1g3> (raw)
In-Reply-To: <YzK1Xry5KIrMr18F@kroah.com>

Hi Greg,

On Tue, Sep 27, 2022 at 10:33:34AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Sep 26, 2022 at 02:53:07PM -0500, Dan Vacura wrote:
> > If there is a transmission error the buffer will be returned too early,
> > causing a memory fault as subsequent requests for that buffer are still
> > queued up to be sent. Refactor the error handling to wait for the final
> > request to come in before reporting back the buffer to userspace for all
> > transfer types (bulk/isoc/isoc_sg) to ensure userspace knows if the
> > frame was successfully sent.
> > 
> > Fixes: e81e7f9a0eb9 ("usb: gadget: uvc: add scatter gather support")
> > Cc: <stable@vger.kernel.org> # 859c675d84d4: usb: gadget: uvc: consistently use define for headerlen
> > Cc: <stable@vger.kernel.org> # f262ce66d40c: usb: gadget: uvc: use on returned header len in video_encode_isoc_sg
> > Cc: <stable@vger.kernel.org> # 61aa709ca58a: usb: gadget: uvc: rework uvcg_queue_next_buffer to uvcg_complete_buffer
> > Cc: <stable@vger.kernel.org> # 9b969f93bcef: usb: gadget: uvc: giveback vb2 buffer on req complete
> > Cc: <stable@vger.kernel.org> # aef11279888c: usb: gadget: uvc: improve sg exit condition
> 
> I don't understand, why we backport all of these commits to 5.15.y if
> the original problem isn't in 5.15.y?
> 
> Or is it?
> 
> I'm confused,

It seems we have a regression in 5.15 with some recent, still in
development, features for the uvc gadget driver. Compared to the last
kernel I worked with, 5.10, I'm seeing stability and functional issues
in 5.15, explained in my summary here:
https://lore.kernel.org/all/20220926195307.110121-1-w36195@motorola.com/

I think we have few approaches.
1) Work through these issues and get the fixes into mainline and stable
versions, this patch starts that effort, but there's still more work to
be done.
2) Revert the changes that are causing regressions in 5.15 (two changes
from what I can see).
3) Add a configfs ability to allow sg isoc transfers and couple the
quarter interrupt logic to only sg xfers.

Approach 2 is my preference, as there are issues still present that need
to be figured out. However, I don't know how we can revert to just a
stable line. I'm basically looking for feedback and input for the next
steps, and if it's just me with these issues on 5.15.

> 
> greg k-h
> 
> 
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Dan Vacura <w36195@motorola.com>
> > 
> > ---
> >  drivers/usb/gadget/function/uvc_queue.c |  8 +++++---
> >  drivers/usb/gadget/function/uvc_queue.h |  2 +-
> >  drivers/usb/gadget/function/uvc_video.c | 18 ++++++++++++++----
> >  3 files changed, 20 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/usb/gadget/function/uvc_queue.c b/drivers/usb/gadget/function/uvc_queue.c
> > index ec500ee499ee..72e7ffd9a021 100644
> > --- a/drivers/usb/gadget/function/uvc_queue.c
> > +++ b/drivers/usb/gadget/function/uvc_queue.c
> > @@ -304,6 +304,7 @@ int uvcg_queue_enable(struct uvc_video_queue *queue, int enable)
> >  
> >  		queue->sequence = 0;
> >  		queue->buf_used = 0;
> > +		queue->flags &= ~UVC_QUEUE_MISSED_XFER;
> >  	} else {
> >  		ret = vb2_streamoff(&queue->queue, queue->queue.type);
> >  		if (ret < 0)
> > @@ -329,10 +330,11 @@ int uvcg_queue_enable(struct uvc_video_queue *queue, int enable)
> >  void uvcg_complete_buffer(struct uvc_video_queue *queue,
> >  					  struct uvc_buffer *buf)
> >  {
> > -	if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
> > -	     buf->length != buf->bytesused) {
> > -		buf->state = UVC_BUF_STATE_QUEUED;
> > +	if ((queue->flags & UVC_QUEUE_MISSED_XFER)) {
> > +		queue->flags &= ~UVC_QUEUE_MISSED_XFER;
> > +		buf->state = UVC_BUF_STATE_ERROR;
> >  		vb2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
> > +		vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_ERROR);
> >  		return;
> >  	}
> >  
> > diff --git a/drivers/usb/gadget/function/uvc_queue.h b/drivers/usb/gadget/function/uvc_queue.h
> > index 41f87b917f6b..741ec58ae9bb 100644
> > --- a/drivers/usb/gadget/function/uvc_queue.h
> > +++ b/drivers/usb/gadget/function/uvc_queue.h
> > @@ -42,7 +42,7 @@ struct uvc_buffer {
> >  };
> >  
> >  #define UVC_QUEUE_DISCONNECTED		(1 << 0)
> > -#define UVC_QUEUE_DROP_INCOMPLETE	(1 << 1)
> > +#define UVC_QUEUE_MISSED_XFER 		(1 << 1)
> 
> Why change the name of the error?

I thought MISSED_XFER was a more explicit name to what is going on,
instead of an action. I can change it back.

> 
> >  
> >  struct uvc_video_queue {
> >  	struct vb2_queue queue;
> > diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
> > index bb037fcc90e6..e46591b067a8 100644
> > --- a/drivers/usb/gadget/function/uvc_video.c
> > +++ b/drivers/usb/gadget/function/uvc_video.c
> > @@ -88,6 +88,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
> >  		struct uvc_buffer *buf)
> >  {
> >  	void *mem = req->buf;
> > +	struct uvc_request *ureq = req->context;
> >  	int len = video->req_size;
> >  	int ret;
> >  
> > @@ -113,13 +114,14 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
> >  		video->queue.buf_used = 0;
> >  		buf->state = UVC_BUF_STATE_DONE;
> >  		list_del(&buf->queue);
> > -		uvcg_complete_buffer(&video->queue, buf);
> >  		video->fid ^= UVC_STREAM_FID;
> > +		ureq->last_buf = buf;
> >  
> >  		video->payload_size = 0;
> >  	}
> >  
> >  	if (video->payload_size == video->max_payload_size ||
> > +	    video->queue.flags & UVC_QUEUE_MISSED_XFER ||
> >  	    buf->bytesused == video->queue.buf_used)
> >  		video->payload_size = 0;
> >  }
> > @@ -180,7 +182,8 @@ uvc_video_encode_isoc_sg(struct usb_request *req, struct uvc_video *video,
> >  	req->length -= len;
> >  	video->queue.buf_used += req->length - header_len;
> >  
> > -	if (buf->bytesused == video->queue.buf_used || !buf->sg) {
> > +	if (buf->bytesused == video->queue.buf_used || !buf->sg ||
> > +			video->queue.flags & UVC_QUEUE_MISSED_XFER) {
> >  		video->queue.buf_used = 0;
> >  		buf->state = UVC_BUF_STATE_DONE;
> >  		buf->offset = 0;
> > @@ -195,6 +198,7 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
> >  		struct uvc_buffer *buf)
> >  {
> >  	void *mem = req->buf;
> > +	struct uvc_request *ureq = req->context;
> >  	int len = video->req_size;
> >  	int ret;
> >  
> > @@ -209,12 +213,13 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
> >  
> >  	req->length = video->req_size - len;
> >  
> > -	if (buf->bytesused == video->queue.buf_used) {
> > +	if (buf->bytesused == video->queue.buf_used ||
> > +			video->queue.flags & UVC_QUEUE_MISSED_XFER) {
> >  		video->queue.buf_used = 0;
> >  		buf->state = UVC_BUF_STATE_DONE;
> >  		list_del(&buf->queue);
> > -		uvcg_complete_buffer(&video->queue, buf);
> >  		video->fid ^= UVC_STREAM_FID;
> > +		ureq->last_buf = buf;
> >  	}
> >  }
> >  
> > @@ -255,6 +260,11 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
> >  	case 0:
> >  		break;
> >  
> > +	case -EXDEV:
> > +		uvcg_info(&video->uvc->func, "VS request missed xfer.\n");
> 
> Why are you spamming the kernel logs at the info level for a USB
> transmission problem?   That could get very noisy, please change this to
> be at the debug level.

Previously this would printout as a dev_warn in a725d0f6dfc5 ("usb:
gadget: uvc: call uvc uvcg_warn on completed status instead of
uvcg_info"), which I think might be too noisy. Info is helpful to
see what's going on if there is video corruption, but I can change to a
dbg as well.

> 
> thanks,
> 
> greg k-h


Appreciate the input,

Dan

  reply	other threads:[~2022-09-27 15:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 19:53 [PATCH 0/1] uvc gadget sg performance issues Dan Vacura
2022-09-26 19:53 ` [PATCH] usb: gadget: uvc: fix sg handling in error case Dan Vacura
2022-09-27  8:33   ` Greg Kroah-Hartman
2022-09-27 15:47     ` Dan Vacura [this message]
2022-09-27 16:42       ` Greg Kroah-Hartman
2022-09-26 20:15 ` [PATCH 0/1] uvc gadget sg performance issues Michael Grzeschik
2022-09-26 20:51   ` Dan Vacura
2022-09-26 21:03     ` Michael Grzeschik

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=YzMbK0ZZ08WD8ql+@p1g3 \
    --to=w36195@motorola.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.grzeschik@pengutronix.de \
    --cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).