A later patch will store the data lifetime in the bio->bi_ioprio member before bio_set_ioprio() is called. Make sure that bio_set_ioprio() doesn't clear more bits than necessary. Cc: Damien Le Moal <dlemoal@xxxxxxxxxx> Cc: Niklas Cassel <niklas.cassel@xxxxxxx> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx> --- block/blk-mq.c | 3 ++- include/linux/ioprio.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index e2d11183f62e..bc086660ffd3 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2926,7 +2926,8 @@ static void bio_set_ioprio(struct bio *bio) { /* Nobody set ioprio so far? Initialize it based on task's nice value */ if (IOPRIO_PRIO_CLASS(bio->bi_ioprio) == IOPRIO_CLASS_NONE) - bio->bi_ioprio = get_current_ioprio(); + ioprio_set_class_and_level(&bio->bi_ioprio, + get_current_ioprio()); blkcg_set_ioprio(bio); } diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h index 7578d4f6a969..f2e768ab4b35 100644 --- a/include/linux/ioprio.h +++ b/include/linux/ioprio.h @@ -71,4 +71,14 @@ static inline int ioprio_check_cap(int ioprio) } #endif /* CONFIG_BLOCK */ +#define IOPRIO_CLASS_LEVEL_MASK ((IOPRIO_CLASS_MASK << IOPRIO_CLASS_SHIFT) | \ + (IOPRIO_LEVEL_MASK << 0)) + +static inline void ioprio_set_class_and_level(u16 *prio, u16 class_level) +{ + WARN_ON_ONCE(class_level & ~IOPRIO_CLASS_LEVEL_MASK); + *prio &= ~IOPRIO_CLASS_LEVEL_MASK; + *prio |= class_level; +} + #endif