• Shin'ichiro Kawasaki's avatar
    null_blk: Fix handling of submit_queues and poll_queues attributes · 15dfc662
    Shin'ichiro Kawasaki authored
    Commit 0a593fbb ("null_blk: poll queue support") introduced the poll
    queue feature to null_blk. After this change, null_blk device has both
    submit queues and poll queues, and null_map_queues() callback maps the
    both queues for corresponding hardware contexts. The commit also added
    the device configuration attribute 'poll_queues' in same manner as the
    existing attribute 'submit_queues'. These attributes allow to modify the
    numbers of queues. However, when the new values are stored to these
    attributes, the values are just handled only for the corresponding
    queue. When number of submit_queue is updated, number of poll_queue is
    not counted, or vice versa.  This caused inconsistent number of queues
    and queue mapping and resulted in null-ptr-dereference. This failure was
    observed in blktests block/029 and block/030.
    
    To avoid the inconsistency, fix the attribute updates to care both
    submit_queues and poll_queues. Introduce the helper function
    nullb_update_nr_hw_queues() to handle stores to the both two attributes.
    Add poll_queues field to the struct nullb_device to track the number in
    same manner as submit_queues. Add two more fields prev_submit_queues and
    prev_poll_queues to keep the previous values before change. In case the
    block layer failed to update the nr_hw_queues, refer the previous values
    in null_map_queues() to map queues in same manner as before change.
    
    Also add poll_queues value checks in nullb_update_nr_hw_queues() and
    null_validate_conf(). They ensure the poll_queues value of each device
    is within the range from 1 to module parameter value of poll_queues.
    
    Fixes: 0a593fbb ("null_blk: poll queue support")
    Reported-by: default avatarYi Zhang <yi.zhang@redhat.com>
    Signed-off-by: default avatarShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
    Link: https://lore.kernel.org/r/20211029103926.845635-1-shinichiro.kawasaki@wdc.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
    15dfc662
null_blk.h 5.25 KB