block: limit block time caching to in_task() context
authorJens Axboe <axboe@kernel.dk>
Tue, 12 Mar 2024 21:58:41 +0000 (15:58 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 13 Mar 2024 20:12:53 +0000 (14:12 -0600)
We should not have any callers of this from non-task context, but Jakub
ran [1] into one from blk-iocost. Rather than risk running into others,
or future ones, just limit blk_time_get_ns() to when it is called from
a task. Any other usage is invalid.

[1] https://lore.kernel.org/lkml/CAHk-=wiOaBLqarS2uFhM1YdwOvCX4CZaWkeyNDY1zONpbYw2ig@mail.gmail.com/

Fixes: da4c8c3d0975 ("block: cache current nsec time in struct blk_plug")
Reported-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk.h

index a19b7b42e6503cd5ca5e03aba41b894a891929b8..5cac4e29ae1744fe4dd370e05290df0f31f3f4ba 100644 (file)
@@ -534,7 +534,7 @@ static inline u64 blk_time_get_ns(void)
 {
        struct blk_plug *plug = current->plug;
 
-       if (!plug)
+       if (!plug || !in_task())
                return ktime_get_ns();
 
        /*