Commit 97e1044
block: invalidate cached plug timestamp after task switch
commit fad156c upstream.
blk_time_get_ns() caches ktime_get_ns() in current->plug->cur_ktime
and marks the task with PF_BLOCK_TS. That cache is only valid while the
task keeps running; if the task is switched out, wall-clock time
advances and the cached value must not be reused when the task runs again.
The existing invalidation covers explicit plug flushes through
__blk_flush_plug(), and the schedule() / rtmutex paths through
sched_update_worker(). It does not cover in-kernel preemption paths such
as preempt_schedule(), preempt_schedule_notrace(), and
preempt_schedule_irq(), which enter __schedule(SM_PREEMPT) directly and
return without calling sched_update_worker().
As a result, a task preempted while holding a plug with PF_BLOCK_TS set
can reuse a stale plug->cur_ktime after it is scheduled back in. blk-iocost
then consumes that stale timestamp through ioc_now(), producing stale vnow
values for throttle decisions, and through ioc_rqos_done(), inflating
on-queue time and feeding false missed-QoS samples into vrate
adjustment.
Move the schedule-side invalidation to finish_task_switch(), which runs
for the scheduled-in task after every actual context switch regardless
of which schedule entry point was used. Keep __blk_flush_plug() as the
explicit flush/finish-plug invalidation path, and remove only the
PF_BLOCK_TS handling from sched_update_worker().
Fixes: 06b23f9 ("block: update cached timestamp post schedule/preemption")
Cc: stable@vger.kernel.org
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Link: https://patch.msgid.link/20260616141604.328820-3-usama.arif@linux.dev
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent 99e6c71 commit 97e1044
2 files changed
Lines changed: 14 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1187 | 1187 | | |
1188 | 1188 | | |
1189 | 1189 | | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
| 1190 | + | |
1194 | 1191 | | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
1200 | 1196 | | |
1201 | 1197 | | |
1202 | 1198 | | |
| |||
1222 | 1218 | | |
1223 | 1219 | | |
1224 | 1220 | | |
1225 | | - | |
| 1221 | + | |
1226 | 1222 | | |
1227 | 1223 | | |
1228 | 1224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5206 | 5206 | | |
5207 | 5207 | | |
5208 | 5208 | | |
| 5209 | + | |
| 5210 | + | |
| 5211 | + | |
| 5212 | + | |
| 5213 | + | |
| 5214 | + | |
5209 | 5215 | | |
5210 | 5216 | | |
5211 | 5217 | | |
| |||
7000 | 7006 | | |
7001 | 7007 | | |
7002 | 7008 | | |
7003 | | - | |
7004 | | - | |
7005 | | - | |
| 7009 | + | |
7006 | 7010 | | |
7007 | 7011 | | |
7008 | | - | |
| 7012 | + | |
7009 | 7013 | | |
7010 | 7014 | | |
7011 | 7015 | | |
| |||
0 commit comments