linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Sean O. Stalley" <sean.stalley@intel.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Stephanie Wallick <stephanie.s.wallick@intel.com>,
	linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, devel@driverdev.osuosl.org
Subject: Re: [V2 PATCH 01/10] added media agnostic (MA) USB HCD driver
Date: Wed, 12 Nov 2014 13:40:21 -0800	[thread overview]
Message-ID: <20141112214021.GA3531@sean.stalley.intel.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1411111042160.8671-100000@netrider.rowland.org>

Thanks for reviewing. My responses are inline.

Greg has asked that we clean up this code internally before we
send out another patchset to the mailing list. I will address
the issues you pointed out, but it may be a while before you see
another patchset.

Thanks Again,
Sean

On Tue, Nov 11, 2014 at 10:54:30AM -0500, Alan Stern wrote:
> On Mon, 10 Nov 2014, Stephanie Wallick wrote:
> 
> > +static struct mausb_hcd mhcd;
> 
> Only one statically-allocated structure?  What if somebody wants to 
> have more than one of these things in their system?
> 

Our plan to support multiple MA devices is to have them all connected
to the same virtual host controller, so only 1 would be needed.

Would you prefer we have 1 host controller instance per MA device?
We are definitely open to suggestions on how this should be architected.

> > +/**
> > + * @maurb:	Media agnostic structure with URB to release.
> > + * @status:	Status for URB that is getting released.
> > + *
> > + * Removes an URB from the queue, deletes the media agnostic information in
> > + * the urb, and gives the URB back to the HCD. Caller must be holding the
> > + * driver's spinlock.
> > + */
> > +void mausb_unlink_giveback_urb(struct mausb_urb *maurb, int status)
> > +{
> > +	struct urb		*urb;
> > +	struct usb_hcd		*hcd;
> > +	struct api_context	*ctx = NULL;
> > +	unsigned long		irq_flags;
> > +
> > +	hcd = mausb_hcd_to_usb_hcd(&mhcd);
> > +
> > +	spin_lock_irqsave(&mhcd.giveback_lock, irq_flags);
> 
> Why do you need multiple spinlocks?  Isn't one lock sufficient?
> 
We will simplify the locking scheme before resubmitting.

I think it might be worthwhile to have a per-endpoint lock, see below.

> > +	if (!maurb) {
> > +		mausb_err(&mhcd, "%s: no maurb\n", __func__);
> > +		spin_unlock_irqrestore(&mhcd.giveback_lock, irq_flags);
> > +		return;
> > +	} else {
> > +		urb = maurb->urb;
> > +		ctx = urb->context;
> > +	}
> > +
> > +	if (!urb) {
> > +		mausb_err(&mhcd, "%s: no urb\n", __func__);
> > +		mausb_internal_drop_maurb(maurb, &mhcd);
> > +		spin_unlock_irqrestore(&mhcd.giveback_lock, irq_flags);
> > +		return;
> > +	}
> > +
> > +	mausb_dbg(&mhcd, "%s: returning urb with status %i\n", __func__, status);
> > +
> > +	usb_hcd_unlink_urb_from_ep(hcd, urb);
> > +	usb_hcd_giveback_urb(hcd, urb, status);
> 
> You must not call this function while holding any spinlocks.  What happens
> if the URB's completion routine tries to resubmit?
> 

This works with our multi-lock scheme, but I will fix when we move to 1 lock.

> > +
> > +	/* remove the mausb-specific data */
> > +	mausb_internal_drop_maurb(maurb, &mhcd);
> > +
> > +	spin_unlock_irqrestore(&mhcd.giveback_lock, irq_flags);
> > +}
> > +
> > +/**
> > + * Adds an URB to the endpoint queue then calls the URB handler. URB is wrapped
> > + * in media agnostic structure before being enqueued.
> > + */
> > +static int mausb_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
> > +		gfp_t memflags)
> > +{
> > +	int			ret = 0;
> > +	struct mausb_urb	*maurb;
> > +	struct mausb_host_ep	*ep;
> > +	unsigned long		irq_flags;
> > +
> > +	if (!hcd || !urb) {
> > +		pr_err("%s: no %s\n", __func__, (hcd ? "urb" : "USB hcd"));
> > +	}
> 
> This can never happen.  The USB core guarantees it; you don't need 
> to check.
> 

I will remove this check (along with any other unnecessary checks for things
guaranteed from usbcore).

> > +	ep   = usb_to_ma_endpoint(urb->ep);
> > +
> > +	if (!ep) {
> > +		mausb_err(&mhcd, "%s: no endpoint\n", __func__);
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (urb->status != -EINPROGRESS) {
> > +		mausb_err(&mhcd, "%s: urb already unlinked, status is %i\n",
> > +			__func__, urb->status);
> > +		return urb->status;
> > +	}
> 
> You also don't need to check this.
> 
Will remove.

> > +	/* If the endpoint isn't activated, we can't enqueue anything. */
> > +	if (MAUSB_EP_HANDLE_UNASSIGNED == ep->ep_handle_state) {
> > +		mausb_err(&mhcd, "%s: endpoint handle unassigned\n", __func__);
> > +		return -EPIPE;
> > +	}
> > +
> > +	if (USB_SPEED_FULL != urb->dev->speed) /* suppress checks */
> > +		ep->max_pkt = usb_endpoint_maxp(&urb->ep->desc);
> 
> What happens to full-speed devices?  Don't they have maxpacket values?
> 
> > +
> > +	/* initialize the maurb */
> > +	maurb = mausb_alloc_maurb(ep, memflags);
> > +	if (!maurb) {
> > +		mausb_err(&mhcd, "could not allocate memory for MA USB urb\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	/* set maurb member values */
> > +	maurb->urb = urb;
> > +	urb->hcpriv = maurb;
> > +
> > +	/* submit urb to hcd and add to endpoint queue */
> > +	ret = usb_hcd_link_urb_to_ep(hcd, urb);
> 
> Read the kerneldoc for this function.  You must hold your private
> spinlock when you call it.
> 

Will fix this & make sure we hold our lock.

> > +	if (ret < 0) {
> > +		mausb_err(&mhcd, "urb enqueue failed: error %d\n", ret);
> > +		usb_hcd_unlink_urb_from_ep(hcd, urb);
> > +		return ret;
> > +	}
> > +
> > +	/* get usb device and increment reference counter */
> > +	if (!mhcd.udev) {
> > +		mhcd.udev = urb->dev;
> > +		usb_get_dev(mhcd.udev);
> > +	}
> 
> What happens if more than one device is in use at a time?
> 
> > +
> > +	/* add urb to queue list */
> > +	spin_lock_irqsave(&ep->ep_lock, irq_flags);
> > +	list_add_tail(&maurb->urb_list, &ep->urb_list);
> > +	spin_unlock_irqrestore(&ep->ep_lock, irq_flags);
> 
> Yet another class of spinlocks!
> 

If we get rid of these locks, endpoints can't run simultaneously.
MA USB IN endpoints have to copy data, which could take a while.

Couldn't this cause a bottleneck?

> > +	/* add urb to ma hcd urb list */
> > +	spin_lock_irqsave(&mhcd.urb_list_lock, irq_flags);
> 
> And another!  You really shouldn't need more than one lock.
> 

Will remove.

> > +	list_add_tail(&maurb->ma_hcd_urb_list, &mhcd.enqueue_urb_list);
> > +	spin_unlock_irqrestore(&mhcd.urb_list_lock, irq_flags);
> > +
> > +	/* send to MA transfer process */
> > +	wake_up(&mhcd.waitq);
> > +
> > +	return ret;
> > +}
> > +
> > +/**
> > + * Dequeues an URB.
> > + */
> > +static int mausb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
> > +{
> > +	int			ret	= 0;
> > +	struct mausb_host_ep	*ep = usb_to_ma_endpoint(urb->ep);
> > +	struct mausb_urb	*maurb = usb_urb_to_mausb_urb(urb);
> > +	unsigned long		irq_flags;
> > +
> > +	/* For debugging - we want to know who initiated URB dequeue. */
> > +	dump_stack();
> 
> Debugging things like this should be removed before a patch is submitted.

Will grep & remove all debugging messages before we release the next patchset.

> 
> That's enough for now.  Obviously there are a lot of issues in this 
> driver which need to be fixed up.

We will try to address all the obvious issues before submitting again.

> 
> Alan Stern
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  reply	other threads:[~2014-11-12 21:40 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <MA USB drivers>
2014-11-03 20:42 ` [PATCH 00/10] MA USB drivers cover letter Stephanie Wallick
2014-11-03 20:42   ` [PATCH 01/10] added media agnostic (MA) USB HCD driver Stephanie Wallick
2014-11-03 21:18     ` Greg KH
2014-11-03 23:47       ` steph
2014-11-03 21:21     ` Greg KH
2014-11-04  0:04       ` steph
2014-11-04  0:13         ` Greg KH
2014-11-04  0:59           ` steph
2014-11-05 20:14           ` sostalle
2014-11-05 22:08             ` Greg KH
2014-11-03 20:42   ` [PATCH 02/10] added media agnostic (MA) USB HCD roothubs Stephanie Wallick
2014-11-03 20:42   ` [PATCH 03/10] added media agnostic (MA) data structures and handling Stephanie Wallick
2014-11-03 20:42   ` [PATCH 04/10] added media agnostic (MA) USB packet handling Stephanie Wallick
2014-11-03 20:42   ` [PATCH 05/10] added media specific (MS) TCP drivers Stephanie Wallick
2014-11-04  8:48     ` Tobias Klauser
2014-11-04 18:02       ` Greg KH
2014-11-12 19:36       ` Sean O. Stalley
2014-11-03 20:42   ` [PATCH 06/10] added media agnostic (MA) UDC Stephanie Wallick
2014-11-03 20:42   ` [PATCH 07/10] added media agnostic (MA) USB management packet handling Stephanie Wallick
2014-11-03 20:42   ` [PATCH 08/10] added media agnostic (MA) USB data " Stephanie Wallick
2014-11-03 20:42   ` [PATCH 09/10] added tools for building/loading media agnostic (MA) USB drivers Stephanie Wallick
2014-11-03 20:42   ` [PATCH 10/10] added kernel build, configuration, and TODO files Stephanie Wallick
2014-11-03 21:22     ` Greg KH
2014-11-03 21:24     ` Greg KH
     [not found]       ` <54591319.c3b5440a.7374.5f85SMTPIN_ADDED_BROKEN@mx.google.com>
2014-11-04 18:02         ` Greg KH
2014-11-04  9:00   ` [PATCH 00/10] MA USB drivers cover letter Bjørn Mork
2014-11-05  1:31     ` sostalle
2014-11-11  2:09 ` [V2 PATCH 01/10] added media agnostic (MA) USB HCD driver Stephanie Wallick
2014-11-11  2:09   ` [V2 PATCH 02/10] added media agnostic (MA) USB HCD roothubs Stephanie Wallick
2014-11-12  8:35     ` Oliver Neukum
2014-11-12 19:28       ` Sean O. Stalley
2014-11-12 19:52         ` Alan Stern
2014-11-11  2:09   ` [V2 PATCH 03/10] added media agnostic (MA) data structures and handling Stephanie Wallick
2014-11-11  4:38     ` Greg KH
2014-11-11 22:42       ` Sean O. Stalley
2014-11-12  1:14         ` Greg KH
2014-11-12  2:01           ` steph
2014-11-11  2:09   ` [V2 PATCH 04/10] added media agnostic (MA) USB packet handling Stephanie Wallick
2014-11-12 14:01     ` Oliver Neukum
2014-11-11  2:09   ` [V2 PATCH 05/10] added media specific (MS) TCP drivers Stephanie Wallick
2014-11-11  4:21     ` Greg KH
2014-11-11  2:09   ` [V2 PATCH 06/10] added media agnostic (MA) UDC Stephanie Wallick
2014-11-11  2:09   ` [V2 PATCH 07/10] added media agnostic (MA) USB management packet handling Stephanie Wallick
2014-11-11  2:09   ` [V2 PATCH 08/10] added media agnostic (MA) USB data " Stephanie Wallick
2014-11-11  2:09   ` [V2 PATCH 09/10] added tools for building/loading media agnostic (MA) USB drivers Stephanie Wallick
2014-11-11  2:09   ` [V2 PATCH 10/10] added kernel build, configuration, and TODO files Stephanie Wallick
2014-11-11  4:23     ` Greg KH
2014-11-11  4:08   ` [V2 PATCH 01/10] added media agnostic (MA) USB HCD driver Greg KH
2014-11-11 15:54   ` Alan Stern
2014-11-12 21:40     ` Sean O. Stalley [this message]
2014-11-12 22:03       ` Alan Stern
2014-11-14 22:48         ` Sean O. Stalley
2014-11-15 21:29           ` Alan Stern
2014-11-12 22:58       ` Sean O. Stalley

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=20141112214021.GA3531@sean.stalley.intel.com \
    --to=sean.stalley@intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stephanie.s.wallick@intel.com \
    --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;
as well as URLs for NNTP newsgroup(s).