Commit d9df61a
scsi: ufs: core: Fix data race in CPU latency PM QoS request handling
[ Upstream commit 79dde5f ]
The cpu_latency_qos_add/remove/update_request interfaces lack internal
synchronization by design, requiring the caller to ensure thread safety.
The current implementation relies on the 'pm_qos_enabled' flag, which is
insufficient to prevent concurrent access and cannot serve as a proper
synchronization mechanism. This has led to data races and list
corruption issues.
A typical race condition call trace is:
[Thread A]
ufshcd_pm_qos_exit()
--> cpu_latency_qos_remove_request()
--> cpu_latency_qos_apply();
--> pm_qos_update_target()
--> plist_del <--(1) delete plist node
--> memset(req, 0, sizeof(*req));
--> hba->pm_qos_enabled = false;
[Thread B]
ufshcd_devfreq_target
--> ufshcd_devfreq_scale
--> ufshcd_scale_clks
--> ufshcd_pm_qos_update <--(2) pm_qos_enabled is true
--> cpu_latency_qos_update_request
--> pm_qos_update_target
--> plist_del <--(3) plist node use-after-free
Introduces a dedicated mutex to serialize PM QoS operations, preventing
data races and ensuring safe access to PM QoS resources, including sysfs
interface reads.
Fixes: 2777e73 ("scsi: ufs: core: Add CPU latency QoS support for UFS driver")
Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Huan Tang <tanghuan@vivo.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 1898631 commit d9df61a
3 files changed
+14
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
512 | 512 | | |
513 | 513 | | |
514 | 514 | | |
| 515 | + | |
| 516 | + | |
515 | 517 | | |
516 | 518 | | |
517 | 519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1045 | 1045 | | |
1046 | 1046 | | |
1047 | 1047 | | |
| 1048 | + | |
1048 | 1049 | | |
1049 | 1050 | | |
1050 | 1051 | | |
| |||
1061 | 1062 | | |
1062 | 1063 | | |
1063 | 1064 | | |
| 1065 | + | |
| 1066 | + | |
1064 | 1067 | | |
1065 | 1068 | | |
1066 | 1069 | | |
| |||
1075 | 1078 | | |
1076 | 1079 | | |
1077 | 1080 | | |
| 1081 | + | |
| 1082 | + | |
1078 | 1083 | | |
1079 | 1084 | | |
1080 | 1085 | | |
| |||
10756 | 10761 | | |
10757 | 10762 | | |
10758 | 10763 | | |
| 10764 | + | |
| 10765 | + | |
| 10766 | + | |
| 10767 | + | |
10759 | 10768 | | |
10760 | 10769 | | |
10761 | 10770 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
963 | 963 | | |
964 | 964 | | |
965 | 965 | | |
| 966 | + | |
966 | 967 | | |
967 | 968 | | |
968 | 969 | | |
| |||
1136 | 1137 | | |
1137 | 1138 | | |
1138 | 1139 | | |
| 1140 | + | |
| 1141 | + | |
1139 | 1142 | | |
1140 | 1143 | | |
1141 | 1144 | | |
| |||
0 commit comments