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

From: Gui-Dong Han

Date: Thu Jul 30 2026 - 05:57:40 EST


On Thu, Jul 30, 2026 at 4:43 PM Jan Beulich <jbeulich@xxxxxxxx> wrote:
>
> 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.

The matching barrier is already provided by atomic_dec_and_test(), which
is fully ordered. It orders the inflight decrement before the following
drain read.

Thus, an additional barrier in
xen_blkbk_unmap_and_respond_callback() would be redundant.

Thanks.