Skip to contentSkip to conversation

bus: mhi: core: Disable pre-emption for data events tasklet processing

PATCH Superseded Bhaumik Bhatt 3 participants 3 messages Jun 18, 2021 – Jun 21, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus: mhi: core: Disable pre-emption for data events tasklet processing

With spin_lock_bh(), it is possible that a tasklet processing data events gets scheduled out if another higher priority tasklet is ready to run. While the tasklet is sleeping, it can hold the event ring spinlock and block another tasklet, for example, one processing an M0 state change event, from acquiring it. This can starve the core which blocks in an attempt to acquire the spinlock until it gets released. Fix this issue by disabling pre-emption on the core processing data events and allow it to run to completion such that other tasklets do not block for long periods.

Fixes 1d3173a3bae7 ("bus: mhi: core: Add support for processing events from client device")
---
 drivers/bus/mhi/core/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/bus/mhi/core/main.c +3 -2
index 3775c77..02c8c09 100644
@@ -1036,11 +1036,12 @@ void mhi_ev_task(unsigned long data)
 {
 	struct mhi_event *mhi_event = (struct mhi_event *)data;
 	struct mhi_controller *mhi_cntrl = mhi_event->mhi_cntrl;
+	unsigned long flags;
 
 	/* process all pending events */
-	spin_lock_bh(&mhi_event->lock);
+	spin_lock_irqsave(&mhi_event->lock, flags);
 	mhi_event->process_event(mhi_cntrl, mhi_event, U32_MAX);
-	spin_unlock_bh(&mhi_event->lock);
+	spin_unlock_irqrestore(&mhi_event->lock, flags);
 }
 
 void mhi_ctrl_ev_task(unsigned long data)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 10 lines · Bhaumik Bhatt

With spin_lock_bh(), it is possible that a tasklet processing data events gets scheduled out if another higher priority tasklet is ready to run. While the tasklet is sleeping, it can hold the event ring spinlock and block another tasklet, for example, one processing an M0 state change event, from acquiring it. This can starve the core which blocks in an attempt to acquire the spinlock until it gets released. Fix this issue by disabling pre-emption on the core processing data events and allow it to run to completion such that other tasklets do not block for long periods.

Are you sure?

IIUC, the tasklets priority is only used while trying to schedule the next pending tasklet. But I don't think a high priority tasklet can preempt the low priority one.

Please correct me if I'm wrong.

Thanks,
Mani

Quoted 29 lines
Fixes 1d3173a3bae7 ("bus: mhi: core: Add support for processing events from client device")
---
 drivers/bus/mhi/core/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/bus/mhi/core/main.c +3 -2
index 3775c77..02c8c09 100644
@@ -1036,11 +1036,12 @@ void mhi_ev_task(unsigned long data)
 {
 	struct mhi_event *mhi_event = (struct mhi_event *)data;
 	struct mhi_controller *mhi_cntrl = mhi_event->mhi_cntrl;
+	unsigned long flags;
 
 	/* process all pending events */
-	spin_lock_bh(&mhi_event->lock);
+	spin_lock_irqsave(&mhi_event->lock, flags);
 	mhi_event->process_event(mhi_cntrl, mhi_event, U32_MAX);
-	spin_unlock_bh(&mhi_event->lock);
+	spin_unlock_irqrestore(&mhi_event->lock, flags);
 }
 
 void mhi_ctrl_ev_task(unsigned long data)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw
Quoted 4 lines · Manivannan Sadhasivam
Quoted 3 lines · Bhaumik Bhatt

With spin_lock_bh(), it is possible that a tasklet processing data events gets scheduled out if another higher priority tasklet is

Needs some re-wording. What we observed was threded irq storms and in the past we observed some RT tasks preempting MHI tasklet for long time.

Quoted 1 line
Quoted 1 line

ready to run. While the tasklet is sleeping, it can hold the event

Not allowed to sleep in tasklet context.

Quoted 19 lines
Quoted 8 lines

ring spinlock and block another tasklet, for example, one processing
an M0 state change event, from acquiring it. This can starve the core which blocks in an attempt to acquire the spinlock until it gets released. Fix this issue by disabling pre-emption on the core processing data events and allow it to run to completion such that other tasklets do not block for long periods.

Are you sure?

IIUC, the tasklets priority is only used while trying to schedule the next pending tasklet. But I don't think a high priority tasklet can preempt the low priority one.

Please correct me if I'm wrong.

Thanks,
Mani

[..]

Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project