public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mailbox: txdone_method shouldn't always be reset
@ 2017-11-16  5:31 Bjorn Andersson
  2017-11-16 16:51 ` Jassi Brar
  0 siblings, 1 reply; 8+ messages in thread
From: Bjorn Andersson @ 2017-11-16  5:31 UTC (permalink / raw)
  To: Jassi Brar, Sudeep Holla; +Cc: linux-kernel, Alexey Klimov

A client that knows how to drive txdone would temporarily "upgrade" the
method to TXDONE_BY_ACK. But with the introduction of commit 33cd7123ac0ba
("mailbox: reset txdone_method TXDONE_BY_POLL if client knows_txdone")
there is no longer a distinction between a channel in "upgraded" state
or a channel for a controller that only supports TXDONE_BY_ACK. So upon
freeing the channel it will be "downgraded" to TXDONE_BY_POLL.

But a channel that operates with the txdone method of TXDONE_BY_POLL
requires that the controller implements the last_tx_done callback and
that the associated hrtimer was initialized when the controller was
registered.

So the core now relies on the fact that subsequent calls to
mbox_request_channel() "upgrades" the channel to TXDONE_BY_ACK or it
will dereference the non-initialized hrtimer.

The intention of commit 33cd7123ac0ba ("mailbox: reset txdone_method
TXDONE_BY_POLL if client knows_txdone") is to not restart the hrtimer
when the channel is in an "upgraded" state. So this patch reverts the
commit, in order to never leave the channel is a invalid state, and
instead only start the timer when we're in the "non-upgraded" POLL
state.

Fixes: 33cd7123ac0ba ("mailbox: reset txdone_method TXDONE_BY_POLL if client knows_txdone")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 drivers/mailbox/mailbox.c | 6 +++---
 drivers/mailbox/pcc.c     | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 674b35f402f5..da8d666a8c56 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -85,7 +85,7 @@ static void msg_submit(struct mbox_chan *chan)
 exit:
 	spin_unlock_irqrestore(&chan->lock, flags);
 
-	if (!err && (chan->txdone_method & TXDONE_BY_POLL))
+	if (!err && chan->txdone_method == TXDONE_BY_POLL)
 		/* kick start the timer immediately to avoid delays */
 		hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL);
 }
@@ -351,7 +351,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
 	init_completion(&chan->tx_complete);
 
 	if (chan->txdone_method	== TXDONE_BY_POLL && cl->knows_txdone)
-		chan->txdone_method = TXDONE_BY_ACK;
+		chan->txdone_method |= TXDONE_BY_ACK;
 
 	spin_unlock_irqrestore(&chan->lock, flags);
 
@@ -418,7 +418,7 @@ void mbox_free_channel(struct mbox_chan *chan)
 	spin_lock_irqsave(&chan->lock, flags);
 	chan->cl = NULL;
 	chan->active_req = NULL;
-	if (chan->txdone_method == TXDONE_BY_ACK)
+	if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK))
 		chan->txdone_method = TXDONE_BY_POLL;
 
 	module_put(chan->mbox->dev->driver->owner);
diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
index 3ef7f036ceea..e5a69679cfa2 100644
--- a/drivers/mailbox/pcc.c
+++ b/drivers/mailbox/pcc.c
@@ -265,7 +265,7 @@ struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl,
 	init_completion(&chan->tx_complete);
 
 	if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone)
-		chan->txdone_method = TXDONE_BY_ACK;
+		chan->txdone_method |= TXDONE_BY_ACK;
 
 	spin_unlock_irqrestore(&chan->lock, flags);
 
@@ -311,7 +311,7 @@ void pcc_mbox_free_channel(struct mbox_chan *chan)
 	spin_lock_irqsave(&chan->lock, flags);
 	chan->cl = NULL;
 	chan->active_req = NULL;
-	if (chan->txdone_method == TXDONE_BY_ACK)
+	if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK))
 		chan->txdone_method = TXDONE_BY_POLL;
 
 	spin_unlock_irqrestore(&chan->lock, flags);
-- 
2.15.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-11-17 12:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-16  5:31 [PATCH] mailbox: txdone_method shouldn't always be reset Bjorn Andersson
2017-11-16 16:51 ` Jassi Brar
2017-11-16 17:06   ` Jassi Brar
2017-11-16 17:42     ` Bjorn Andersson
     [not found]       ` <CABb+yY0cwDCG=zKBT1ckoLSi+cHnmxcNbi2BXz2EstVTAo169w@mail.gmail.com>
     [not found]         ` <CABb+yY0SmdLyo7g46VqznHZravBv7qUTZcuQ5o4v+4QGMw-pyQ@mail.gmail.com>
     [not found]           ` <CABb+yY0EkKUMfLrQs4OjHkVPKghKND6hChfzmjS60asTrAcYyg@mail.gmail.com>
     [not found]             ` <CABb+yY0GkRpPgAgAFOMxLJ_7qh4wV7R5At8VFOxepuEN76K1QQ@mail.gmail.com>
     [not found]               ` <CABb+yY0nSnkYQtL28UwsqRCRkaZHSU2O-RM9r=50n0n7Owkf+A@mail.gmail.com>
2017-11-17  7:04                 ` Bjorn Andersson
2017-11-17  9:51                   ` Sudeep Holla
2017-11-17 12:40                   ` Jassi Brar
2017-11-16 17:24   ` Sudeep Holla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox