• P
    blk-mq: attempt to fix atomic flag memory ordering · a7af0af3
    Peter Zijlstra 提交于
    Attempt to untangle the ordering in blk-mq. The patch introducing the
    single smp_mb__before_atomic() is obviously broken in that it doesn't
    clearly specify a pairing barrier and an obtained guarantee.
    
    The comment is further misleading in that it hints that the
    deadline store and the COMPLETE store also need to be ordered, but
    AFAICT there is no such dependency. However what does appear to be
    important is the clear happening _after_ the store, and that worked by
    pure accident.
    
    This clarifies blk_mq_start_request() -- we should not get there with
    STARTING set -- this simplifies the code and makes the barrier usage
    sane (the old code could be read to allow not having _any_ atomic after
    the barrier, in which case the barrier hasn't got anything to order). We
    then also introduce the missing pairing barrier for it.
    
    Also down-grade the barrier to smp_wmb(), this is cheaper for
    PowerPC/ARM and doesn't cost anything extra on x86.
    
    And it documents the STARTING vs COMPLETE ordering. Although I've not
    been entirely successful in reverse engineering the blk-mq state
    machine so there might still be more funnies around timeout vs
    requeue.
    
    If I got anything wrong, feel free to educate me by adding comments to
    clarify things ;-)
    
    Cc: Alan Stern <stern@rowland.harvard.edu>
    Cc: Will Deacon <will.deacon@arm.com>
    Cc: Ming Lei <tom.leiming@gmail.com>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Andrea Parri <parri.andrea@gmail.com>
    Cc: Boqun Feng <boqun.feng@gmail.com>
    Cc: Bart Van Assche <bart.vanassche@wdc.com>
    Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
    Fixes: 538b7534 ("blk-mq: request deadline must be visible before marking rq as started")
    Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: NJens Axboe <axboe@kernel.dk>
    a7af0af3
blk-mq.c 71.2 KB