[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191121072910.31665-1-bibby.hsieh@mediatek.com>
Date: Thu, 21 Nov 2019 15:29:10 +0800
From: Bibby Hsieh <bibby.hsieh@...iatek.com>
To: Jassi Brar <jassisinghbrar@...il.com>,
Matthias Brugger <matthias.bgg@...il.com>,
Rob Herring <robh+dt@...nel.org>, CK HU <ck.hu@...iatek.com>
CC: <devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>,
<linux-mediatek@...ts.infradead.org>,
<srv_heupstream@...iatek.com>,
Nicolas Boichat <drinkcat@...omium.org>,
Dennis-YC Hsieh <dennis-yc.hsieh@...iatek.com>,
Houlong Wei <houlong.wei@...iatek.com>,
Bibby Hsieh <bibby.hsieh@...iatek.com>
Subject: [PATCH] soc: mediatek: cmdq: avoid racing condition with mutex
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@...iatek.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;
};
/**
--
2.18.0
Powered by blists - more mailing lists