mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Viresh Kumar <viresh.kumar@st.com>
Cc: shiraz.hashim@st.com, vinod.koul@intel.com,
	linux-kernel@vger.kernel.org, armando.visconti@st.com,
	viresh.linux@gmail.com, dan.j.williams@intel.com,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH V3 2/7] dmaengine/dw_dmac: Replace spin_lock* with irqsave variants
Date: Fri, 29 Apr 2011 10:15:57 +0100	[thread overview]
Message-ID: <20110429091557.GZ17290@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20110428171020.GB17290@n2100.arm.linux.org.uk>

On Thu, Apr 28, 2011 at 06:10:20PM +0100, Russell King - ARM Linux wrote:
> On Wed, Apr 27, 2011 at 03:06:44PM +0530, Viresh Kumar wrote:
> > @@ -407,6 +410,8 @@ EXPORT_SYMBOL(dw_dma_get_dst_addr);
> >  static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc,
> >  		u32 status_block, u32 status_err, u32 status_xfer)
> >  {
> > +	unsigned long flags;
> > +
> >  	if (status_block & dwc->mask) {
> >  		void (*callback)(void *param);
> >  		void *callback_param;
> > @@ -418,9 +423,9 @@ static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc,
> >  		callback = dwc->cdesc->period_callback;
> >  		callback_param = dwc->cdesc->period_callback_param;
> >  		if (callback) {
> > -			spin_unlock(&dwc->lock);
> > +			spin_unlock_irqrestore(&dwc->lock, flags);
> >  			callback(callback_param);
> > -			spin_lock(&dwc->lock);
> > +			spin_lock_irqsave(&dwc->lock, flags);
> 
> I'm really not convinced that this is anywhere near correct.  I'm
> surprised this doesn't spit out a compiler warning.
> 
> spin_unlock_irqrestore() reads the flags argument and puts it into
> the PSR.  spin_lock_irqsave() reads the PSR, puts it into the flags
> argument, sets the interrupt mask bit and writes back to the PSR.
> 
> So, if you do:
> 
> 	unsigned long flags;
> 
> 	spin_unlock_irqrestore(&dwc->lock, flags);
> 	...
> 	spin_lock_irqsave(&dwc->lock, flags);
> 
> you're going to end up corrupting the PSR.
> 
> In any case, releasing a spinlock temporarily within a called function
> is _really_ not a nice thing to do.  It makes code review rather
> difficult as called functions become non-atomic when called within
> an atomic region.

BTW, how this gets handled in other drivers is basically as follows in
the tasklet:

tasklet()
{
	LIST_HEAD(completed);

	spin_lock_irqsave(lock, flags);
	for each txd(txd) {
		if (completed(txd))
			list_move_tail(&txd->node, &completed);
	}
	try to start new txd();
	spin_unlock_irqrestore(lock, flags);

	for each list entry safe(txd, &completed) {
		void (*callback)(void *) = txd->callback;
		void *param = txd->callback_param;

		free_txd(txd);

		if (callback)
			callback(param);
	}
}

I'm not sure how easy it is to move dw_dmac to that kind of structure,
but I think this is what is required rather than dropping locks within
functions which they haven't themselves taken.

  reply	other threads:[~2011-04-29  9:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-27  9:36 [PATCH V3 0/7] dmaengine/dw_dmac updates Viresh Kumar
2011-04-27  9:36 ` [PATCH V3 2/7] dmaengine/dw_dmac: Replace spin_lock* with irqsave variants Viresh Kumar
2011-04-28 17:10   ` Russell King - ARM Linux
2011-04-29  9:15     ` Russell King - ARM Linux [this message]
2011-04-29 10:17       ` viresh kumar
2011-04-29 10:18     ` viresh kumar
2011-04-27  9:36 ` [PATCH V3 3/7] dmaengine/dw_dmac: don't call callback routine in case dmaengine_terminate_all() is called Viresh Kumar
2011-04-28 17:11   ` Russell King - ARM Linux
2011-04-29  3:25     ` viresh kumar
2011-04-27  9:36 ` [PATCH V3 4/7] dmaengine/dw_dmac: Enable resubmission from callback routine Viresh Kumar
2011-04-28 17:12   ` Russell King - ARM Linux
2011-04-27  9:36 ` [PATCH V3 5/7] dmaengine/dw_dmac: set residue as total len in dwc_tx_status if status is !DMA_SUCCESS Viresh Kumar
2011-04-27  9:36 ` [PATCH V3 6/7] dmaengine/dw_dmac: Divide one sg to many desc, if sg len is greater than DWC_MAX_COUNT Viresh Kumar
2011-04-27  9:36 ` [PATCH V3 7/7] dmaengine/dw_dmac: implement pause and resume in dwc_control Viresh Kumar
2011-04-27  9:36 ` [PATCH V3 1/7] dmaengine/dw_dmac: call dwc_descriptor_complete from dwc_control with lock held Viresh Kumar
2011-04-27  9:40 ` [PATCH V3 0/7] dmaengine/dw_dmac updates viresh kumar

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=20110429091557.GZ17290@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=armando.visconti@st.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shiraz.hashim@st.com \
    --cc=vinod.koul@intel.com \
    --cc=viresh.kumar@st.com \
    --cc=viresh.linux@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

all inboxes | Powered by JetHome®