mailbox: avoid timer start from callback

If the txdone is done by polling, it is possible for msg_submit() to start
the timer while txdone_hrtimer() callback is running. If the timer needs
recheduling, it could already be enqueued by the time hrtimer_forward_now()
is called, leading hrtimer to loudly complain.

WARNING: CPU: 3 PID: 74 at kernel/time/hrtimer.c:932 hrtimer_forward+0xc4/0x110
CPU: 3 PID: 74 Comm: kworker/u8:1 Not tainted 5.9.0-rc2-00236-gd3520067d01c-dirty #5
Hardware name: Libre Computer AML-S805X-AC (DT)
Workqueue: events_freezable_power_ thermal_zone_device_check
pstate: 20000085 (nzCv daIf -PAN -UAO BTYPE=--)
pc : hrtimer_forward+0xc4/0x110
lr : txdone_hrtimer+0xf8/0x118
[...]

This can be fixed by not starting the timer from the callback path. Which
requires the timer reloading as long as any message is queued on the
channel, and not just when current tx is not done yet.

Fixes: 0cc67945ea59 ("mailbox: switch to hrtimer for tx_complete polling")
Reported-by: Da Xue <da@libre.computer>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Jerome Brunet <jbrunet@baylibre.com>
Tested-by: Jerome Brunet <jbrunet@baylibre.com>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>

+7 -5
+7 -5
drivers/mailbox/mailbox.c
··· 82 82 exit: 83 83 spin_unlock_irqrestore(&chan->lock, flags); 84 84 85 - if (!err && (chan->txdone_method & TXDONE_BY_POLL)) 86 - /* kick start the timer immediately to avoid delays */ 87 - hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); 85 + /* kick start the timer immediately to avoid delays */ 86 + if (!err && (chan->txdone_method & TXDONE_BY_POLL)) { 87 + /* but only if not already active */ 88 + if (!hrtimer_active(&chan->mbox->poll_hrt)) 89 + hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); 90 + } 88 91 } 89 92 90 93 static void tx_tick(struct mbox_chan *chan, int r) ··· 125 122 struct mbox_chan *chan = &mbox->chans[i]; 126 123 127 124 if (chan->active_req && chan->cl) { 125 + resched = true; 128 126 txdone = chan->mbox->ops->last_tx_done(chan); 129 127 if (txdone) 130 128 tx_tick(chan, 0); 131 - else 132 - resched = true; 133 129 } 134 130 } 135 131