block/blk-iocost: annotate ioc_pd_stat reads with data_race()

ioc_pd_stat() reads ioc->enabled, ioc->vtime_base_rate, and
iocg->last_stat without holding ioc->lock, which trips KCSAN since
ioc_adjust_base_vrate() and iocg_flush_stat_upward() write those
fields under ioc->lock.

Commit 35198e3230 fixed the same issue in ioc_qos_prfill() and
ioc_cost_model_prfill() by adding spin_lock_irq(&ioc->lock).  However,
those functions read configuration parameters (qos/model) that need
synchronized reads.  In contrast, ioc_pd_stat() only reads stat
values (vrate, usage) where stale reads are harmless, so data_race()
is more appropriate — it silences the KCSAN warning without adding
lock contention during high-frequency stat reads.

Signed-off-by: Tao Cui <cuitao@kylinos.cn>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://patch.msgid.link/20260804054120.161933-1-cui.tao@linux.dev
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Tao Cui
2026-08-04 13:41:20 +08:00
committed by Jens Axboe
parent 3bf9a21e7b
commit 4d73bf0ca4

View File

@@ -3093,23 +3093,23 @@ static void ioc_pd_stat(struct blkg_policy_data *pd, struct seq_file *s)
struct ioc_gq *iocg = pd_to_iocg(pd);
struct ioc *ioc = iocg->ioc;
if (!ioc->enabled)
if (!data_race(ioc->enabled))
return;
if (iocg->level == 0) {
unsigned vp10k = DIV64_U64_ROUND_CLOSEST(
ioc->vtime_base_rate * 10000,
data_race(ioc->vtime_base_rate) * 10000,
VTIME_PER_USEC);
seq_printf(s, " cost.vrate=%u.%02u", vp10k / 100, vp10k % 100);
}
seq_printf(s, " cost.usage=%llu", iocg->last_stat.usage_us);
seq_printf(s, " cost.usage=%llu", data_race(iocg->last_stat.usage_us));
if (blkcg_debug_stats)
seq_printf(s, " cost.wait=%llu cost.indebt=%llu cost.indelay=%llu",
iocg->last_stat.wait_us,
iocg->last_stat.indebt_us,
iocg->last_stat.indelay_us);
data_race(iocg->last_stat.wait_us),
data_race(iocg->last_stat.indebt_us),
data_race(iocg->last_stat.indelay_us));
}
static u64 ioc_weight_prfill(struct seq_file *sf, struct blkg_policy_data *pd,