Re: [PATCH] xen/blkback: Prevent missed completion when draining I/O

Jan Beulich <[email protected]> Thu, 30 Jul 2026 10:43:43 +0200
Newsgroups gmane.comp.emulators.xen.devel,gmane.linux.block,gmane.linux.kernel
Message-ID <[email protected]>
On 30.07.2026 10:40, Gui-Dong Han wrote:
> --- a/drivers/block/xen-blkback/blkback.c
> +++ b/drivers/block/xen-blkback/blkback.c
> @@ -1021,6 +1021,13 @@ static void xen_blk_drain_io(struct xen_blkif_ring *ring)
>  	struct xen_blkif *blkif = ring->blkif;
>  
>  	atomic_set(&blkif->drain, 1);
> +	/*
> +	 * Publish drain before checking inflight. Otherwise,
> +	 * xen_blkbk_unmap_and_respond_callback() can decrement inflight with
> +	 * atomic_dec_and_test() and still see drain == 0 after this path saw
> +	 * inflight > 0, missing the completion.
> +	 */
> +	smp_mb();
>  	do {
>  		if (atomic_read(&ring->inflight) == 0)
>  			break;

Yet then don't we also need a barrier in xen_blkbk_unmap_and_respond_callback()'s
check? Barriers almost always come in pairs, after all.

Jan