linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Sahitya Tummala <stummala@codeaurora.org>,
	Subhash Jadavani <subhashj@codeaurora.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Amit Pundir <amit.pundir@linaro.org>
Subject: [PATCH 4.4 75/86] scsi: ufs: fix race between clock gating and devfreq scaling work
Date: Thu, 29 Nov 2018 15:12:40 +0100	[thread overview]
Message-ID: <20181129140115.951351091@linuxfoundation.org> (raw)
In-Reply-To: <20181129140109.832117862@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Subhash Jadavani <subhashj@codeaurora.org>

commit 30fc33f1ef475480dc5bea4fe1bda84b003b992c upstream.

UFS devfreq clock scaling work may require clocks to be ON if it need to
execute some UFS commands hence it may request for clock hold before
issuing the command. But if UFS clock gating work is already running in
parallel, ungate work would end up waiting for the clock gating work to
finish and as clock gating work would also wait for the clock scaling
work to finish, we would enter in deadlock state. Here is the call trace
during this deadlock state:

Workqueue: devfreq_wq devfreq_monitor
	__switch_to
	__schedule
	schedule
	schedule_timeout
	wait_for_common
	wait_for_completion
	flush_work
	ufshcd_hold
	ufshcd_send_uic_cmd
	ufshcd_dme_get_attr
	ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div
	ufs_qcom_clk_scale_notify
	ufshcd_scale_clks
	ufshcd_devfreq_target
	update_devfreq
	devfreq_monitor
	process_one_work
	worker_thread
	kthread
	ret_from_fork

Workqueue: events ufshcd_gate_work
	__switch_to
	__schedule
	schedule
	schedule_preempt_disabled
	__mutex_lock_slowpath
	mutex_lock
	devfreq_monitor_suspend
	devfreq_simple_ondemand_handler
	devfreq_suspend_device
	ufshcd_gate_work
	process_one_work
	worker_thread
	kthread
	ret_from_fork

Workqueue: events ufshcd_ungate_work
	__switch_to
	__schedule
	schedule
	schedule_timeout
	wait_for_common
	wait_for_completion
	flush_work
	__cancel_work_timer
	cancel_delayed_work_sync
	ufshcd_ungate_work
	process_one_work
	worker_thread
	kthread
	ret_from_fork

This change fixes this deadlock by doing this in devfreq work (devfreq_wq):
Try cancelling clock gating work. If we are able to cancel gating work
or it wasn't scheduled, hold the clock reference count until scaling is
in progress. If gate work is already running in parallel, let's skip
the frequecy scaling at this time and it will be retried once next scaling
window expires.

Reviewed-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/scsi/ufs/ufshcd.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -5511,15 +5511,47 @@ static int ufshcd_devfreq_target(struct
 {
 	int err = 0;
 	struct ufs_hba *hba = dev_get_drvdata(dev);
+	bool release_clk_hold = false;
+	unsigned long irq_flags;
 
 	if (!ufshcd_is_clkscaling_enabled(hba))
 		return -EINVAL;
 
+	spin_lock_irqsave(hba->host->host_lock, irq_flags);
+	if (ufshcd_eh_in_progress(hba)) {
+		spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
+		return 0;
+	}
+
+	if (ufshcd_is_clkgating_allowed(hba) &&
+	    (hba->clk_gating.state != CLKS_ON)) {
+		if (cancel_delayed_work(&hba->clk_gating.gate_work)) {
+			/* hold the vote until the scaling work is completed */
+			hba->clk_gating.active_reqs++;
+			release_clk_hold = true;
+			hba->clk_gating.state = CLKS_ON;
+		} else {
+			/*
+			 * Clock gating work seems to be running in parallel
+			 * hence skip scaling work to avoid deadlock between
+			 * current scaling work and gating work.
+			 */
+			spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
+			return 0;
+		}
+	}
+	spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
+
 	if (*freq == UINT_MAX)
 		err = ufshcd_scale_clks(hba, true);
 	else if (*freq == 0)
 		err = ufshcd_scale_clks(hba, false);
 
+	spin_lock_irqsave(hba->host->host_lock, irq_flags);
+	if (release_clk_hold)
+		__ufshcd_release(hba);
+	spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
+
 	return err;
 }
 



  parent reply	other threads:[~2018-11-29 14:20 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 14:11 [PATCH 4.4 00/86] 4.4.166-stable review Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 01/86] usb: core: Fix hub port connection events lost Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 02/86] usb: xhci: fix timeout for transition from RExit to U0 Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 03/86] MAINTAINERS: Add Sasha as a stable branch maintainer Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 04/86] iwlwifi: mvm: support sta_statistics() even on older firmware Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 05/86] v9fs_dir_readdir: fix double-free on p9stat_read error Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 06/86] bfs: add sanity check at bfs_fill_super() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 07/86] sctp: clear the transport of some out_chunk_list chunks in sctp_assoc_rm_peer Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 08/86] gfs2: Dont leave s_fs_info pointing to freed memory in init_sbd Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 09/86] llc: do not use sk_eat_skb() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 10/86] drm/ast: change resolution may cause screen blurred Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 11/86] drm/ast: fixed cursor may disappear sometimes Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 12/86] can: dev: can_get_echo_skb(): factor out non sending code to __can_get_echo_skb() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 13/86] can: dev: __can_get_echo_skb(): replace struct can_frame by canfd_frame to access frame length Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 14/86] can: dev: __can_get_echo_skb(): Dont crash the kernel if can_priv::echo_skb is accessed out of bounds Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 15/86] can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 16/86] ACPICA: AML interpreter: add region addresses in global list during initialization Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 17/86] usb: xhci: Prevent bus suspend if a port connect change or polling state is detected Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 18/86] KVM: PPC: Move and undef TRACE_INCLUDE_PATH/FILE Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 19/86] cpufreq: imx6q: add return value check for voltage scale Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 20/86] ARM: make lookup_processor_type() non-__init Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 21/86] SUNRPC: Fix a bogus get/put in generic_key_to_expire() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 22/86] kdb: Use strscpy with destination buffer size Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 23/86] powerpc/numa: Suppress "VPHN is not supported" messages Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 24/86] tmpfs: make lseek(SEEK_DATA/SEK_HOLE) return ENXIO with a negative offset Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 25/86] of: add helper to lookup compatible child node Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 26/86] NFC: nfcmrvl_uart: fix OF child-node lookup Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 27/86] net: bcmgenet: " Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 28/86] x86/entry: spell EBX register correctly in documentation Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 29/86] x86/entry/64: Remove %ebx handling from error_entry/exit Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 30/86] arm64: remove no-op -p linker flag Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 31/86] ath10k: fix kernel panic due to race in accessing arvif list Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 32/86] Input: xpad - remove spurious events of wireless xpad 360 controller Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 33/86] Input: xpad - handle "present" and "gone" correctly Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 34/86] Input: xpad - update Xbox One Force Feedback Support Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 35/86] Input: xpad - workaround dead irq_out after suspend/ resume Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 36/86] Input: xpad - use LED API when identifying wireless controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 37/86] Input: xpad - correct xbox one pad device name Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 38/86] Input: xpad - remove unused function Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 39/86] Input: xpad - add Mad Catz FightStick TE 2 VID/PID Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 40/86] Input: xpad - prevent spurious input from wired Xbox 360 controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 41/86] Input: xpad - add more third-party controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 42/86] Input: xpad - xbox one elite controller support Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 43/86] Input: xpad - fix rumble on Xbox One controllers with 2015 firmware Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 44/86] Input: xpad - power off wireless 360 controllers on suspend Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 45/86] Input: xpad - add product ID for Xbox One S pad Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 46/86] Input: xpad - fix Xbox One rumble stopping after 2.5 secs Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 47/86] Input: xpad - correctly sort vendor ids Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 48/86] Input: xpad - move reporting xbox one home button to common function Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 49/86] Input: xpad - simplify error condition in init_output Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 50/86] Input: xpad - dont depend on endpoint order Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 51/86] Input: xpad - fix stuck mode button on Xbox One S pad Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 52/86] Input: xpad - restore LED state after device resume Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 53/86] Input: xpad - support some quirky Xbox One pads Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 54/86] Input: xpad - sort supported devices by USB ID Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 55/86] Input: xpad - sync supported devices with xboxdrv Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 56/86] Input: xpad - add USB IDs for Mad Catz Brawlstick and Razer Sabertooth Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 57/86] Input: xpad - sync supported devices with 360Controller Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 58/86] Input: xpad - sync supported devices with XBCD Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 59/86] Input: xpad - constify usb_device_id Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 60/86] Input: xpad - fix PowerA init quirk for some gamepad models Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 61/86] Input: xpad - validate USB endpoint type during probe Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 62/86] Input: xpad - add support for PDP Xbox One controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 63/86] Input: xpad - add PDP device id 0x02a4 Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 64/86] Input: xpad - fix some coding style issues Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 65/86] Input: xpad - avoid using __set_bit() for capabilities Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 66/86] Input: xpad - add GPD Win 2 Controller USB IDs Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 67/86] Input: xpad - fix GPD Win 2 controller name Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 68/86] Input: xpad - add support for Xbox1 PDP Camo series gamepad Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 69/86] cw1200: Dont leak memory if krealloc failes Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 70/86] mwifiex: Fix NULL pointer dereference in skb_dequeue() Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 71/86] mwifiex: fix p2p device doesnt find in scan problem Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 72/86] netfilter: nf_tables: fix oops when inserting an element into a verdict map Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 73/86] scsi: ufs: fix bugs related to null pointer access and array size Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 74/86] scsi: ufshcd: Fix race between clk scaling and ungate work Greg Kroah-Hartman
2018-11-29 14:12 ` Greg Kroah-Hartman [this message]
2018-11-29 14:12 ` [PATCH 4.4 76/86] scsi: ufshcd: release resources if probe fails Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 77/86] scsi: qla2xxx: do not queue commands when unloading Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 78/86] iwlwifi: mvm: fix regulatory domain update when the firmware starts Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 79/86] tty: wipe buffer Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 80/86] tty: wipe buffer if not echoing data Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 81/86] usb: xhci: fix uninitialized completion when USB3 port got wrong status Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 82/86] btrfs: Ensure btrfs_trim_fs can trim the whole filesystem Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 83/86] sched/core: Allow __sched_setscheduler() in interrupts when PI is not used Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 84/86] namei: allow restricted O_CREAT of FIFOs and regular files Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 85/86] s390/mm: Check for valid vma before zapping in gmap_discard Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 86/86] drm/ast: Remove existing framebuffers before loading driver Greg Kroah-Hartman
2018-11-29 19:51 ` [PATCH 4.4 00/86] 4.4.166-stable review kernelci.org bot
2018-11-29 20:26 ` shuah
2018-11-29 21:49 ` Harsh Shandilya
2018-11-30  9:00 ` Naresh Kamboju
2018-11-30 22:27 ` Guenter Roeck

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=20181129140115.951351091@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=amit.pundir@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=stummala@codeaurora.org \
    --cc=subhashj@codeaurora.org \
    /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).