linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: CK Hu <ck.hu@mediatek.com>
To: Bibby Hsieh <bibby.hsieh@mediatek.com>
Cc: devicetree@vger.kernel.org,
	Nicolas Boichat <drinkcat@chromium.org>,
	srv_heupstream@mediatek.com,
	Jassi Brar <jassisinghbrar@gmail.com>,
	linux-kernel@vger.kernel.org,
	Houlong Wei <houlong.wei@mediatek.com>,
	Dennis-YC Hsieh <dennis-yc.hsieh@mediatek.com>,
	Rob Herring <robh+dt@kernel.org>,
	linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] soc: mediatek: cmdq: avoid racing condition with mutex
Date: Mon, 30 Dec 2019 10:02:41 +0800	[thread overview]
Message-ID: <1577671361.8160.2.camel@mtksdaap41> (raw)
In-Reply-To: <1575426135.31411.2.camel@mtksdaap41>

Hi, Jassi:

Ping again.

Are mbox_send_message() and mbox_client_txdone() thread-safe? If these
two are thread-safe, this bug should be fixed in mailbox core not
client.

Regards,
CK

On Wed, 2019-12-04 at 10:22 +0800, CK Hu wrote:
> Hi, Jassi:
> 
> Are mbox_send_message() and mbox_client_txdone() thread-safe? If these
> two are thread-safe, this bug should be fixed in mailbox core not
> client.
> 
> Regards,
> CK
> 
> On Thu, 2019-11-21 at 15:29 +0800, Bibby Hsieh wrote:
> > If cmdq client is multi thread user, racing will occur without mutex
> > protection. It will make the C message queued in mailbox's queue
> > always need D message's triggering.
> > 
> > Thread A		Thread B		  Thread C		Thread D...
> > -----------------------------------------------------------------------------------
> > mbox_send_message()
> > 	send_data()
> > 			mbox_send_message()
> > 				*exit
> > 						mbox_send_message()
> > 							*exit
> > mbox_client_txdone()
> > 	tx_tick()
> > 			mbox_client_txdone()
> > 				tx_tick()
> > 						mbox_client_txdone()
> > 							tx_tick()
> > msg_submit()
> > 	send_data()
> > 			msg_submit()
> > 				*exit
> > 						msg_submit()
> > 							*exit
> > -----------------------------------------------------------------------------------
> > 
> > Signed-off-by: Bibby Hsieh <bibby.hsieh@mediatek.com>
> > ---
> >  drivers/soc/mediatek/mtk-cmdq-helper.c | 3 +++
> >  include/linux/soc/mediatek/mtk-cmdq.h  | 1 +
> >  2 files changed, 4 insertions(+)
> > 
> > diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c
> > index 9add0fd5fa6c..9e35e0beffaa 100644
> > --- a/drivers/soc/mediatek/mtk-cmdq-helper.c
> > +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c
> > @@ -81,6 +81,7 @@ struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
> >  	client->client.dev = dev;
> >  	client->client.tx_block = false;
> >  	client->chan = mbox_request_channel(&client->client, index);
> > +	mutex_init(&client->mutex);
> >  
> >  	if (IS_ERR(client->chan)) {
> >  		long err;
> > @@ -352,9 +353,11 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
> >  		spin_unlock_irqrestore(&client->lock, flags);
> >  	}
> >  
> > +	mutex_lock(&client->mutex);
> >  	mbox_send_message(client->chan, pkt);
> >  	/* We can send next packet immediately, so just call txdone. */
> >  	mbox_client_txdone(client->chan, 0);
> > +	mutex_unlock(&client->mutex);
> >  
> >  	return 0;
> >  }
> > diff --git a/include/linux/soc/mediatek/mtk-cmdq.h b/include/linux/soc/mediatek/mtk-cmdq.h
> > index a74c1d5acdf3..0f9071cd1bc7 100644
> > --- a/include/linux/soc/mediatek/mtk-cmdq.h
> > +++ b/include/linux/soc/mediatek/mtk-cmdq.h
> > @@ -28,6 +28,7 @@ struct cmdq_client {
> >  	struct mbox_chan *chan;
> >  	struct timer_list timer;
> >  	u32 timeout_ms; /* in unit of microsecond */
> > +	struct mutex mutex;
> >  };
> >  
> >  /**
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-12-30  2:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-21  7:29 [PATCH] soc: mediatek: cmdq: avoid racing condition with mutex Bibby Hsieh
2019-12-04  2:22 ` CK Hu
2019-12-30  2:02   ` CK Hu [this message]
2019-12-30  3:28   ` Jassi Brar
2019-12-30  6:44 ` CK Hu

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=1577671361.8160.2.camel@mtksdaap41 \
    --to=ck.hu@mediatek.com \
    --cc=bibby.hsieh@mediatek.com \
    --cc=dennis-yc.hsieh@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=houlong.wei@mediatek.com \
    --cc=jassisinghbrar@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=srv_heupstream@mediatek.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;
as well as URLs for NNTP newsgroup(s).