block: fix that iostat can show huge wait time
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I57S8D CVE: NA -------------------------------- There might be a problem that iostat can read less 'nsecs' than the last time. 1) io is started after 'hd->stat_time' is set. 2) following concurrent scenario: t1 t2 blk_mq_end_request time1 -> before hd->stat_time blk_account_io_done part_get_stat_info part_set_stat_time hd->stat_time = time2 -> time1 < time2 blk_mq_in_flight_with_stat blk_mq_check_inflight_with_stat cmpxchg64() -> set stat_time_ns to time2 cmpxchg64() -> set stat_time to time1 duation = time1 - time2; -> time1 < time2 part_stat_add(xx, nsecs, duation) -> problematic 3) Similar concurrent scenario the other way around. Fix the problem by don't add 'duation' if the calculation might underflow. Signed-off-by: NYu Kuai <yukuai3@huawei.com> Reviewed-by: NJason Yan <yanaijie@huawei.com> Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Showing
想要评论请 注册 或 登录