All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: "Darrick J. Wong" <djwong@kernel.org>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/2] xfs: hold buffer across unpin and potential shutdown processing
Date: Wed, 12 May 2021 10:29:41 -0400	[thread overview]
Message-ID: <YJvmVUZpSmP9EzTV@bfoster> (raw)
In-Reply-To: <YJvImeri0qEQtPJ1@infradead.org>

On Wed, May 12, 2021 at 01:22:49PM +0100, Christoph Hellwig wrote:
> On Tue, May 11, 2021 at 06:52:44PM -0700, Darrick J. Wong wrote:
> > > is unpinned if the associated item has been aborted and will require
> > > a simulated I/O failure. The hold is already required for the
> > > simulated I/O failure, so the ordering simply guarantees the unpin
> > > handler access to the buffer before it is unpinned and thus
> > > processed by the AIL. This particular ordering is required so long
> > > as the AIL does not acquire a reference on the bli, which is the
> > > long term solution to this problem.
> > 
> > Are you working on that too, or are we just going to let that lie for
> > the time being? :)
> 
> Wouldn't that be as simple as something like the untested patch below?
> 

I actually think this is moderately less simple than the RFC I started
with (see the cover letter for a reference) because there's really no
need for a buffer hold per pin. I moved away from the RFC approach to
this to 1. isolate the hold/rele cycle to the scenario where it's
actually necessary (unpin abort) and 2. document the design flaw that
Dave had pointed out that contributes to this problem.

So point #1 means the explicit hold basically fills the gap that the bli
reference count fails to cover to preserve buffer access by (AIL
resident) log item processing code, and no more, whereas the RFC and the
patch below are a bit more convoluted (even though the code might look
simpler) in that they obscure that context.

Brian

> 
> diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
> index fb69879e4b2b..07e08713ecd4 100644
> --- a/fs/xfs/xfs_buf_item.c
> +++ b/fs/xfs/xfs_buf_item.c
> @@ -471,6 +471,7 @@ xfs_buf_item_pin(
>  	trace_xfs_buf_item_pin(bip);
>  
>  	atomic_inc(&bip->bli_refcount);
> +	xfs_buf_hold(bip->bli_buf);
>  	atomic_inc(&bip->bli_buf->b_pin_count);
>  }
>  
> @@ -552,14 +553,15 @@ xfs_buf_item_unpin(
>  		xfs_buf_relse(bp);
>  	} else if (freed && remove) {
>  		/*
> -		 * The buffer must be locked and held by the caller to simulate
> -		 * an async I/O failure.
> +		 * The buffer must be locked to simulate an async I/O failure.
> +		 * xfs_buf_ioend_fail will drop our buffer reference.
>  		 */
>  		xfs_buf_lock(bp);
> -		xfs_buf_hold(bp);
>  		bp->b_flags |= XBF_ASYNC;
>  		xfs_buf_ioend_fail(bp);
> +		return;
>  	}
> +	xfs_buf_rele(bp);
>  }
>  
>  STATIC uint
> 


  reply	other threads:[~2021-05-12 14:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 13:52 [PATCH 0/2] xfs: fix buffer use after free on unpin abort Brian Foster
2021-05-11 13:52 ` [PATCH 1/2] xfs: hold buffer across unpin and potential shutdown processing Brian Foster
2021-05-12  1:52   ` Darrick J. Wong
2021-05-12 12:22     ` Christoph Hellwig
2021-05-12 14:29       ` Brian Foster [this message]
2021-05-12 14:28     ` Brian Foster
2021-05-11 13:52 ` [PATCH 2/2] xfs: remove dead stale buf unpin handling code Brian Foster
2021-05-12  1:55   ` Darrick J. Wong
2021-05-12 12:00   ` Christoph Hellwig
2021-05-12 14:29     ` Brian Foster
2021-05-12 14:30   ` [PATCH v1.1 " Brian Foster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YJvmVUZpSmP9EzTV@bfoster \
    --to=bfoster@redhat.com \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.