Re: [BUG REPORT] General protection fault while discarding extents on XFS on next-20240305

Keith Busch
2024-03-06T14:36:46Z

On Wed, Mar 06, 2024 at 04:35:09AM -0800, Christoph Hellwig wrote:
> On Wed, Mar 06, 2024 at 12:49:29PM +0530, Chandan Babu R wrote:
> > The above *probably* occured because __blkdev_issue_discard() noticed a pending
> > signal, processed the bio, freed the bio and returned a non-NULL bio pointer
> > to the caller (i.e. xfs_discard_extents()).
> >
> > xfs_discard_extents() then tries to process the freed bio once again.
>
> Yes, __blkdev_issue_discard really needs to clear *biop to NULL for
> this case, i.e.:
>
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index dc8e35d0a51d6d..26850d4895cdaf 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -99,6 +99,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
> cond_resched();
> if (fatal_signal_pending(current)) {
> await_bio_chain(bio);
> + *biop = NULL;
> return -EINTR;
> }
> }

But everyone who calls this already sets their local bio to NULL by
default, and __blkdev_issue_discard updates *biop only on success, so
'*biop' should already be NULL here. ?