From patchwork Thu Mar 7 15:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585846 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75F3312EBED; Thu, 7 Mar 2024 15:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824323; cv=none; b=VhEtaQyw2GW06pLuz09Qj2eam/3lYfbxHSwOAc+p69b93SuiYBXg6iPlF7Hi0jzzDfdKFcke6dYG+GI8TG+Vpl+mKPSDi4pY818ZzLWPG8Q6GJybtzk4xEWOkJpOYZ1SVNb7K1o5hKNggF7tlyYn8oJiDuQOYM7+FmGz3UUBeXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824323; c=relaxed/simple; bh=CeGGphwbZ+bq0L35X3yMxqag4sALR5PsqLC8iS3hr0U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GsgDVt7/zkjtx9kV1Da6DpDz5X+k9OG5X1iMWCQs/U9mCQCF6ikYprkDZ8fzLsqm3DaMYpuDDObKpUnZgrrBqAPEQbehuxc5kg2lf4g208kqwzazTagk239NgDx0qFdblj2d4fxxWF/e4OlvzXdBCSQxY0184b5aG9nMJDBncFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lZDGtDO+; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lZDGtDO+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=21fX9Gy5zvQsI495qmSlpVuI+exSTES9Ynq5330qoqE=; b=lZDGtDO+9RTu0cd1OXyWZO8T8n cP1/gnlzQ4B6ycpLF9bRLw350OecH8V4NIan7ZpyFwao5K4bvbI+yzXysHtQO5z4IeFT1D7bCuHVj /XD4M4d7XnVL1kSHjYrFKLJ9+UqGm58BeDd9o50XUVW8p/CFT72exRUGquG0pFoPAgruIQoPdoC7K Ns8tbPzdYwsCuse5BTx83qMGl2PX0FcKlC7ggZ3Wop8b2qlk029CCxSNqjQPXPAzeSWMDIkvOE15j h/6CXdkGjHot+Xs4S6cYBkPJSkYAo3PNZDizNAdZqXfWVYEuav8kTcpYKbP+ZZLK4p8T3pHCoDTSG 1cxBKBZA==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPd-00000005D7C-0zCe; Thu, 07 Mar 2024 15:12:01 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 01/10] block: remove the discard_granularity check in __blkdev_issue_discard Date: Thu, 7 Mar 2024 08:11:48 -0700 Message-Id: <20240307151157.466013-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html We now set a default granularity in the queue limits API, so don't bother with this extra check. Signed-off-by: Christoph Hellwig --- block/blk-lib.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index dc8e35d0a51d6d..f873eb9a886f63 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -66,13 +66,6 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, if (!bdev_max_discard_sectors(bdev)) return -EOPNOTSUPP; - /* In case the discard granularity isn't set by buggy device driver */ - if (WARN_ON_ONCE(!bdev_discard_granularity(bdev))) { - pr_err_ratelimited("%pg: Error: discard_granularity is 0.\n", - bdev); - return -EOPNOTSUPP; - } - bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; if ((sector | nr_sects) & bs_mask) return -EINVAL; From patchwork Thu Mar 7 15:11:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585847 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E24A112D754; Thu, 7 Mar 2024 15:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824324; cv=none; b=NwwSuud8lDHD1HGfnB5gB3PVJhaQ6qX3peJKyfvCcZMRyeTaVxsQQ8vyBDA86m9rDnxb7jxTnJaqiYLURPKWLsNPozX93DA9gQWlkr9Zn2qiVnNKp93u9eSsa+arZX6Ho2yy5EBkn94blrnHSVVOxgMCFOKp9A6ceqKyjswvK2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824324; c=relaxed/simple; bh=5j/8sbbwmsIGUTaid4wZisGmjeOMxRtrzYUrsaK1Cck=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VUaE9w92i4B/OYOmQXoOi8HZt19cJK6xRZczeILGsuX/dsozHK+hz3h/L4kj9x2SEUREuX0/G2v75e+RvfJ1Md6S8yfUyZYRd2w8saEQnG3XniXe7ydeScqQpedVNOOGUjzO5Ho7Js5wqIZvk5EXbkdLdKtHvD6dYd+1tEEJ9FE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=MRMaDje1; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="MRMaDje1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=4jdyG4CszBpyuc/2KWIWtUkGflIk46hmyZR40KPZHew=; b=MRMaDje10vfg8i3wtj6CHQshJx o+Bp0JaEP98NWOM0uRA5zUnllPbjVkMpZse+6r4sNljem35UrJhDf9/TGNlwSZu97fsZ6WTe1sQwP CXx+fdx2ZHHWfMroopIBE4FWPWzqBkeqIR5KFOrBGA5LJFbFxucOtZzgkc3N1YRMn5Lj38qERG48g z02qg70FUPdPVLWL00jAL0s/S9pXJ0xJYDq2CDdmz5K09n04GtXew8Xogb8ajS8bxA0pT4uTyaEnk OIcsKCS9CJcT/hJiBzhjfEAV0x0lcPqrjsQc7znZDoWo7x7SdupFIV6eVo1cberFrWQ0pEHuwYMhO C5qoAnkA==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPe-00000005D7a-0Pty; Thu, 07 Mar 2024 15:12:02 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 02/10] block: move discard checks into the ioctl handler Date: Thu, 7 Mar 2024 08:11:49 -0700 Message-Id: <20240307151157.466013-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Most bio operations get basic sanity checking in submit_bio and anything more complicated than that is done in the callers. Discards are a bit different from that in that a lot of checking is done in __blkdev_issue_discard, and the specific errnos for that are returned to userspace. Move the checks that require specific errnos to the ioctl handler instead, and just leave the basic sanity checking in submit_bio for the other handlers. This introduces two changes in behavior: 1) the logical block size alignment check of the start and len is lost for non-ioctl callers. This matches what is done for other operations including reads and writes. We should probably verify this for all bios, but for now make discards match the normal flow. 2) for non-ioctl callers all errors are reported on I/O completion now instead of synchronously. Callers in general mostly ignore or log errors so this will actually simplify the code once cleaned up Signed-off-by: Christoph Hellwig --- block/blk-lib.c | 13 ------------- block/ioctl.c | 13 +++++++++---- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index f873eb9a886f63..50923508a32466 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -59,19 +59,6 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop) { struct bio *bio = *biop; - sector_t bs_mask; - - if (bdev_read_only(bdev)) - return -EPERM; - if (!bdev_max_discard_sectors(bdev)) - return -EOPNOTSUPP; - - bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; - if ((sector | nr_sects) & bs_mask) - return -EINVAL; - - if (!nr_sects) - return -EINVAL; while (nr_sects) { sector_t req_sects = diff --git a/block/ioctl.c b/block/ioctl.c index de0cc0d215c633..1d5de0a890c5e8 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -95,6 +95,8 @@ static int compat_blkpg_ioctl(struct block_device *bdev, static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode, unsigned long arg) { + sector_t bs_mask = (bdev_logical_block_size(bdev) >> SECTOR_SHIFT) - 1; + sector_t sector, nr_sects; uint64_t range[2]; uint64_t start, len; struct inode *inode = bdev->bd_inode; @@ -105,18 +107,21 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode, if (!bdev_max_discard_sectors(bdev)) return -EOPNOTSUPP; + if (bdev_read_only(bdev)) + return -EPERM; if (copy_from_user(range, (void __user *)arg, sizeof(range))) return -EFAULT; start = range[0]; len = range[1]; + sector = start >> SECTOR_SHIFT; + nr_sects = len >> SECTOR_SHIFT; - if (start & 511) + if (!nr_sects) return -EINVAL; - if (len & 511) + if ((sector | nr_sects) & bs_mask) return -EINVAL; - if (start + len > bdev_nr_bytes(bdev)) return -EINVAL; @@ -124,7 +129,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode, err = truncate_bdev_range(bdev, mode, start, start + len - 1); if (err) goto fail; - err = blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL); + err = blkdev_issue_discard(bdev, sector, nr_sects, GFP_KERNEL); fail: filemap_invalidate_unlock(inode->i_mapping); return err; From patchwork Thu Mar 7 15:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585848 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA06512F36F; Thu, 7 Mar 2024 15:12:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824326; cv=none; b=BL7AdH6+TbdFudSsSsaX9gw4pl9D+lCVcABCMht0wXIBE0kt5FB1+u2pr5j6+FYnxLrJtp0PXBBDObqV1sFF96VSmlbteASV0sPuqVctU1j/8q68AUnFLAZT9ESj0SAf4rYfMA8BpqMGaM12areSKDQB2YIzxRcEYikt3Vfc5Nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824326; c=relaxed/simple; bh=LFzZsApGcvCLdm6zVuiq8u52+VVD4nNTQaqWvlVOnp0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ukBHVWAQdsVyghemxublVixfkxq9u13EPV8nIxj/BGTzLT8uMFFG+Tr3urdmQkWRLahR56G7oXh+OWfEMj0XjFteG3d+B916XK/z4+oeMGQOKHYm992OmHikX8XZAR5OzLKMpg/OfbztdUDewS3bCniTC3Y3pZEXwY/ZH9TUOjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=dZ8JOSgM; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dZ8JOSgM" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=pIAa/RpvHRZ8f5i+wX7BbspmDNldfs7/UxcWBp02Rkc=; b=dZ8JOSgMcu7MN3cGccf5sTRPc/ FUroHl04qi1ReLZrqfC7poA50rNdJg5vJ+HZEhLxPTktaOHXngwJ/GGiAs7LqZbPqRTC8LavDfRRh q3Q6NFhSdC/G7YEEvdIX/JOxeplMu6xcWabACsICAbVch3f2dl3i93aXZ+CiPMDyKt2VxX38FdzH2 9utGSJ1QsuxFGWzcCgrZijX7YxSmCqOXolvRDfluhZhCxAnMuP5HaUOIKGF1DYaUzLFUfuBH5pGzF qs1JscatO/BjNJH7YNZPRRDtGIOorc3drqj7/CKzhOhlPHtq3edjS0dVjocRl3qZ5x0Nc5bcjB6ku dRwEBuzw==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPe-00000005D89-3Qh7; Thu, 07 Mar 2024 15:12:03 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 03/10] block: add a blk_next_discard_bio helper Date: Thu, 7 Mar 2024 08:11:50 -0700 Message-Id: <20240307151157.466013-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html This factors the guts of __blkdev_issue_discard into a helper that can be used by callers avoid the fatal_signal_pending check and to generally simplify the bio handling. Signed-off-by: Christoph Hellwig --- block/blk-lib.c | 41 ++++++++++++++++++++++++----------------- include/linux/blkdev.h | 2 ++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 50923508a32466..4f2d52210b129c 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -55,28 +55,35 @@ static void await_bio_chain(struct bio *bio) blk_wait_io(&done); } +bool blk_next_discard_bio(struct block_device *bdev, struct bio **biop, + sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask) +{ + sector_t bio_sects = min(*nr_sects, bio_discard_limit(bdev, *sector)); + + if (!bio_sects) + return false; + + *biop = blk_next_bio(*biop, bdev, 0, REQ_OP_DISCARD, gfp_mask); + (*biop)->bi_iter.bi_sector = *sector; + (*biop)->bi_iter.bi_size = bio_sects << SECTOR_SHIFT; + *sector += bio_sects; + *nr_sects -= bio_sects; + /* + * We can loop for a long time in here if someone does full device + * discards (like mkfs). Be nice and allow us to schedule out to avoid + * softlocking if preempt is disabled. + */ + cond_resched(); + return true; +} +EXPORT_SYMBOL_GPL(blk_next_discard_bio); + int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop) { struct bio *bio = *biop; - while (nr_sects) { - sector_t req_sects = - min(nr_sects, bio_discard_limit(bdev, sector)); - - bio = blk_next_bio(bio, bdev, 0, REQ_OP_DISCARD, gfp_mask); - bio->bi_iter.bi_sector = sector; - bio->bi_iter.bi_size = req_sects << 9; - sector += req_sects; - nr_sects -= req_sects; - - /* - * We can loop for a long time in here, if someone does - * full device discards (like mkfs). Be nice and allow - * us to schedule out to avoid softlocking if preempt - * is disabled. - */ - cond_resched(); + while (blk_next_discard_bio(bdev, &bio, §or, &nr_sects, gfp_mask)) { if (fatal_signal_pending(current)) { await_bio_chain(bio); return -EINTR; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index a9a0bd6cac4aff..b87cd889008291 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1059,6 +1059,8 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask); int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop); +bool blk_next_discard_bio(struct block_device *bdev, struct bio **biop, + sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask); int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp); From patchwork Thu Mar 7 15:11:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585849 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D80F12D754; Thu, 7 Mar 2024 15:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824326; cv=none; b=IRLK2hhgwY0K2Chj0TVm1O1OaSg+5WBFfNLGjYcN049cN1BXT503BGz4HrPHoimAUM8wiCpCpfP9p013eMMXBA/pHTE7LZdCduDQd0a7eg4Dn/JtAHQ0uiqX7oaQuGNLMy+Uj6kGR2iLAVR58fiuYYr7xojsCl4LIfOeJu3X1z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824326; c=relaxed/simple; bh=34S+Vs1AXtLkKF30u7Kh5py7cvXsPdolDUs25WsCHyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KZA+LR5wNoTdGT/7pD05nSmq2dLzNMkI1F0t2626pWYahQ3FAR4cLLnJXelIv3jmFa/2gitK6lAKJFMGJuaKOxWEw6sc6CQwLOofP2G+TAA7egiuBF1nRevC92RSnj6EVPFpJNWd0HLm0pc7Hethm9IVLwpXN4e4DC/0ZrUfYgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=s84SBvaB; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="s84SBvaB" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=E17RS1gXdmfEVxJtjtbtf9HhycP12pKLgfmDFXFlsBQ=; b=s84SBvaBVgBPA8Qermc8KbFWr2 ui8KcScwvmtz3+zxPp8H6BOB/Ogrv/l4LoZXCSm+SlYjvjG25LVlGSmpN1n6/nGAfEMgLjL+94ZDb VeXURA6tiAyyeaY5O1r5yq1mZF0oPzfDe3fWnMcvfCfuNgW+em1bhZR4MHTH9ZBcnNJr+zgfw40kb w/WQ0rFNDnrb48cL7tndRT+o+Alv81PtA8qctB+23TFaGLT56wIRJlopVKWuA8gJB+Ptz43qP8g1L R4vBHnE2qS1O3Sr5IFb/mi6EdlVgMk0Efxgb5PhTAnTUhtOnrTgTpF0Ucvc3kXlDWjrWcGSASXfOe fsLdHU+g==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPf-00000005D8W-46ov; Thu, 07 Mar 2024 15:12:04 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 04/10] xfs: switch to using blk_next_discard_bio directly Date: Thu, 7 Mar 2024 08:11:51 -0700 Message-Id: <20240307151157.466013-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html This fixes fatal signals getting into the way and corrupting the bio chain and removes the need to handle synchronous errors. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_discard.c | 47 ++++++++++++++------------------------------ fs/xfs/xfs_discard.h | 2 +- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index d5787991bb5b46..6396a4e14809a2 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -102,33 +102,26 @@ xfs_discard_endio( * list. We plug and chain the bios so that we only need a single completion * call to clear all the busy extents once the discards are complete. */ -int +void xfs_discard_extents( struct xfs_mount *mp, struct xfs_busy_extents *extents) { + struct block_device *bdev = mp->m_ddev_targp->bt_bdev; struct xfs_extent_busy *busyp; struct bio *bio = NULL; struct blk_plug plug; - int error = 0; blk_start_plug(&plug); list_for_each_entry(busyp, &extents->extent_list, list) { + sector_t sector = XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno); + sector_t nr_sects = XFS_FSB_TO_BB(mp, busyp->length); + trace_xfs_discard_extent(mp, busyp->agno, busyp->bno, busyp->length); - - error = __blkdev_issue_discard(mp->m_ddev_targp->bt_bdev, - XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno), - XFS_FSB_TO_BB(mp, busyp->length), - GFP_NOFS, &bio); - if (error && error != -EOPNOTSUPP) { - xfs_info(mp, - "discard failed for extent [0x%llx,%u], error %d", - (unsigned long long)busyp->bno, - busyp->length, - error); - break; - } + while (blk_next_discard_bio(bdev, &bio, §or, &nr_sects, + GFP_NOFS)) + ; } if (bio) { @@ -139,11 +132,8 @@ xfs_discard_extents( xfs_discard_endio_work(&extents->endio_work); } blk_finish_plug(&plug); - - return error; } - static int xfs_trim_gather_extents( struct xfs_perag *pag, @@ -306,16 +296,14 @@ xfs_trim_extents( .ar_blockcount = pag->pagf_longest, .ar_startblock = NULLAGBLOCK, }; - int error = 0; do { struct xfs_busy_extents *extents; + int error; extents = kzalloc(sizeof(*extents), GFP_KERNEL); - if (!extents) { - error = -ENOMEM; - break; - } + if (!extents) + return -ENOMEM; extents->mount = pag->pag_mount; extents->owner = extents; @@ -325,7 +313,7 @@ xfs_trim_extents( &tcur, extents, blocks_trimmed); if (error) { kfree(extents); - break; + return error; } /* @@ -338,17 +326,12 @@ xfs_trim_extents( * list after this function call, as it may have been freed by * the time control returns to us. */ - error = xfs_discard_extents(pag->pag_mount, extents); - if (error) - break; - + xfs_discard_extents(pag->pag_mount, extents); if (xfs_trim_should_stop()) - break; - + return 0; } while (tcur.ar_blockcount != 0); - return error; - + return 0; } /* diff --git a/fs/xfs/xfs_discard.h b/fs/xfs/xfs_discard.h index 2b1a85223a56c6..8c5cc4af6a0787 100644 --- a/fs/xfs/xfs_discard.h +++ b/fs/xfs/xfs_discard.h @@ -6,7 +6,7 @@ struct fstrim_range; struct xfs_mount; struct xfs_busy_extents; -int xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy); +void xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy); int xfs_ioc_trim(struct xfs_mount *mp, struct fstrim_range __user *fstrim); #endif /* XFS_DISCARD_H */ From patchwork Thu Mar 7 15:11:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585850 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C613C12DD99; Thu, 7 Mar 2024 15:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824327; cv=none; b=KtziJoK0vy416xJmSTfwGjQg3PkRNR5oQWXMwaDs4fOHZYE1mjlJ4p4fbGVenRKSKhP0AZwLNDSqF4yTSPiwpxNinF+ZzmLgql0p4LwwN0QzTh/Y1wY1H08TMcSG8uAXC5Pwh1ZEuufSxJZO5LddHU3pm9nrBibg4kUAlXIT+RY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824327; c=relaxed/simple; bh=as6eEroskOLEchsef29Ei/N8XvJhpIrN4Y1Oes1eamc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=si3WMqw2VRkZp1emp75ytUF/eI8qxkWPBBXX8m/dVdj6zWZy9tbAy7zI390HCQh3M89ooXfyGT2Ph4AhJ7bNinTnJd7Lx5jW8nHjrMJN9/F5Azl30tI21qfJkC/D+EpVzEpqHyFDDB+gzkOqiHCMDZTLnvLAh4/vnZAAQcVAeSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=0dzOYaCs; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="0dzOYaCs" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=TW6U45LMqo70ibxXeynwYboB+abUkfYEFYwo0rLd1po=; b=0dzOYaCskszw2282+GkGRnddaV R3iNZrOZx2tgWUSgvUXnlAh5Kla6p89sA8t0EUgGh8ssrrxZdjjGU01y3g6lb5TfUJxSkPWuJhcGH KMHJBtXt6OK/7E3zPcH+KcXbNxTPtAnawVlTm+7jmQN5pQqniMepZJjJxszTP1ZEMXKlSuinZ9J3K kRcj1tFO2A++RyeHp3SnTuQZZ5nOe1LKovpEtUxw6k9WEaJLzjLw69Rr0z62T1vCqd5m6jDG4FXl7 bFfZ5T4zVNUHY9WcA6O5CXJSYwQd8Na1BDqHIvQ2ZOZXs2veCJrYiPbm1TelngEck5r+WGO8sRxUG selgdBqQ==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPg-00000005D9H-2yQH; Thu, 07 Mar 2024 15:12:04 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 05/10] f2fs: switch to using blk_next_discard_bio directly Date: Thu, 7 Mar 2024 08:11:52 -0700 Message-Id: <20240307151157.466013-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html This fixes fatal signals getting into the way and corrupting the bio chain and removes the need to handle synchronous errors. Signed-off-by: Christoph Hellwig --- fs/f2fs/segment.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index e1065ba7020761..c131e138d74f94 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1305,10 +1305,12 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi, if (time_to_inject(sbi, FAULT_DISCARD)) { err = -EIO; } else { - err = __blkdev_issue_discard(bdev, - SECTOR_FROM_BLOCK(start), - SECTOR_FROM_BLOCK(len), - GFP_NOFS, &bio); + sector_t sector = SECTOR_FROM_BLOCK(start); + sector_t nr_sects = SECTOR_FROM_BLOCK(len); + + while (blk_next_discard_bio(bdev, &bio, §or, + &nr_sects, GFP_NOFS)) + ; } if (err) { spin_lock_irqsave(&dc->lock, flags); From patchwork Thu Mar 7 15:11:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585851 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B9E312EBE8; Thu, 7 Mar 2024 15:12:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824327; cv=none; b=GdHElU/U5gom50BDa5XpqqxMYxFlwywvzziY9Cq90n00x/ilGNOkf+1zcxoLT9C7L86lWi8Wt7QdBdOb+MZASDsHH0U0AeQMZxAOCGDQDeauMp/if6gOGRbwdza4+YtVrCf9PjSbyt28HSkvj+O8I4OctLVP0IGR1Rqcj0RfES8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824327; c=relaxed/simple; bh=XAM+LwtEk0qr2GpYrr3g7759A/QwQZkYBngcPrPRzEM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mwNt2TX7lAWcx65N4PYSXJTGugpbLmFM45HlzdixvRGTAIQ636nnrIlGnu+4sBL/PIO88+TwGiCHlUeCosJndeAVGqUONDCezviHnidjqNZbPist3lfALl5uUQI/rwIx0sPSN2K7ZLmulfKWH5GMVDu5rUJzrLL4pCTRR2ynNqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=mZnkzLeE; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="mZnkzLeE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=pWLnUFlzUEJhnbTRDkaJ8/zvGbZPOXeOdQeHsZIHfXk=; b=mZnkzLeE+9tHuzricoH3AfKk/I JwjvFAY2rDlTMKWRjQqJijBwf3D9H5UKl1tJEH+OfBAwkmSgYlv3plwr+vrV3iylPri/kbon2ZlkH LjbhFbogqG0UBH4cbiEuNdVDA8PrZ7/WledrTqUs/PMCgRpaD2Dg8PsHgmtjYjwGOfbEPnaTDO+eK zVK0tcaUXjLjacol+JDOOOdEY/DigZBdek/N6p16dxhQERkEH63ibcA6Xg1LxcdAr/ghvHN3A0plt qhl/pwTrQPWvmBeYhyC5FcLNASBqxJ8MBg1RDnm0hLGQ73GkeU6Rezx3MXIHPL1HNxbi0LncDQfbh pReBxNZA==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPh-00000005D9c-2TVa; Thu, 07 Mar 2024 15:12:05 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 06/10] ext4: switch to using blk_next_discard_bio directly Date: Thu, 7 Mar 2024 08:11:53 -0700 Message-Id: <20240307151157.466013-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html This fixes fatal signals getting into the way and corrupting the bio chain and removes the need to handle synchronous errors. Signed-off-by: Christoph Hellwig --- fs/ext4/mballoc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index e4f7cf9d89c45a..73437510bde26c 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3840,12 +3840,16 @@ static inline int ext4_issue_discard(struct super_block *sb, trace_ext4_discard_blocks(sb, (unsigned long long) discard_block, count); if (biop) { - return __blkdev_issue_discard(sb->s_bdev, - (sector_t)discard_block << (sb->s_blocksize_bits - 9), - (sector_t)count << (sb->s_blocksize_bits - 9), - GFP_NOFS, biop); - } else - return sb_issue_discard(sb, discard_block, count, GFP_NOFS, 0); + unsigned int sshift = (sb->s_blocksize_bits - SECTOR_SHIFT); + sector_t sector = (sector_t)discard_block << sshift; + sector_t nr_sects = (sector_t)count << sshift; + + while (blk_next_discard_bio(sb->s_bdev, biop, §or, + &nr_sects, GFP_NOFS)) + ; + return 0; + } + return sb_issue_discard(sb, discard_block, count, GFP_NOFS, 0); } static void ext4_free_data_in_buddy(struct super_block *sb, From patchwork Thu Mar 7 15:11:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585852 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EC1212F388; Thu, 7 Mar 2024 15:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824328; cv=none; b=pHOH6DLdbkfVBANPqc3bUGMp0IcgrfoVsD8Hz5QjBieiMua7hLwDGq+VMYe2vc8X/g9wdWOM4vU44B0HfaYhoU39NH1PptM3UMG9HvCc4Edx4ShaX2EH/bMJ/zkReDuZGAcc7OaBSR2NwHkblVMoUeA+TGPLTLiSsk/6KJnmiUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824328; c=relaxed/simple; bh=xCe+xklm9baPXz5w5r5u0Mvfv0h4wRfFKbRMgYxRqeI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lmw6XZcDZuKf9o+E5UeMXCkvVivsxDMaviFnt1cATCl8xJPcfD3VjfKsNdnvxeYeNFtwTo91w71+KLBTCWMv/IACMPC5x7heRSt4Bo0NCgheTZzGcx/GfvUair0WQodadzCw5kdBVVq5K8HFgKATtg74iIkEeNt+0Gyzw34XdYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=rJa+Tq1L; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rJa+Tq1L" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=K6dAOpH3HfvroaSB45ET9VQSXQtJU2v4720kk0k4xZk=; b=rJa+Tq1Laip28+c966zEelI785 Qn0F6MIBM8vVn9g5s2e+7ZigMrwgXcy1C9h1PlZXWWv9XfWddnLpPLXDfP5XzFykujPrqIoVXgEUT 8bfv0rHQdJisWFZLq/6JH6glv+/biYReNfuRW20SXaZ0kYmsl1EtZqTzb+Zow0xmeDKmFOVuFAaCy zQbwp7A8fQhJcKMuaOBprBhtu3wmfm1KEm1NHiO4iCm13uk45ZM2r+/CTsWTC/N6fMIRVYguB4vQ8 ODgb8hmkIPRo+V4S9r5DgmkVRNsAw3CsDHBYZ1gyP4C8VQaPdQs/+8vySFA3PdvdgsrXBwbl9wadN rpdNWBvA==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPi-00000005DA8-0s2Q; Thu, 07 Mar 2024 15:12:06 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 07/10] nvmet: switch to using blk_next_discard_bio directly Date: Thu, 7 Mar 2024 08:11:54 -0700 Message-Id: <20240307151157.466013-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html This fixes fatal signals getting into the way and corrupting the bio chain and removes the need to handle synchronous errors. Signed-off-by: Christoph Hellwig --- drivers/nvme/target/io-cmd-bdev.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index f11400a908f269..c1345aaf837d93 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -363,17 +363,13 @@ u16 nvmet_bdev_flush(struct nvmet_req *req) static u16 nvmet_bdev_discard_range(struct nvmet_req *req, struct nvme_dsm_range *range, struct bio **bio) { - struct nvmet_ns *ns = req->ns; - int ret; + sector_t sector = nvmet_lba_to_sect(req->ns, range->slba); + sector_t nr_sects = le32_to_cpu(range->nlb) << + (req->ns->blksize_shift - SECTOR_SHIFT); - ret = __blkdev_issue_discard(ns->bdev, - nvmet_lba_to_sect(ns, range->slba), - le32_to_cpu(range->nlb) << (ns->blksize_shift - 9), - GFP_KERNEL, bio); - if (ret && ret != -EOPNOTSUPP) { - req->error_slba = le64_to_cpu(range->slba); - return errno_to_nvme_status(req, ret); - } + while (blk_next_discard_bio(req->ns->bdev, bio, §or, &nr_sects, + GFP_KERNEL)) + ; return NVME_SC_SUCCESS; } From patchwork Thu Mar 7 15:11:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585853 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEDC812F581; Thu, 7 Mar 2024 15:12:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824330; cv=none; b=oTM6i3hiullvir+v+Mg61JiyWYgps/zfT690yVfthGjPS21SgtYSjrlDXDKcvBOoNpFDqUK7k5fPlsiMLq09Bjmzne9e5VyWHxdMgw+nz4NYPhG+IbrwKEuS2GzAG2p2lHoKdyRGfPaxTNU9X7p2hIvm99etDloe+wIbym48UMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824330; c=relaxed/simple; bh=zPxsh836NPBiiy/7oPJ0S6jtnAX71dRpgwl/YopkPIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OlkSucygGNHFvJUqxBuvxf1QwapgWMbuhCV32LoUpKGQkVW5YV/bz15ubGmaR4mxcyVcLs0kpu2zVg4ii54XDhHi652VTftWPF7ir4W4/zFxbq3LwekZi2boX1rk+yOYeG9aNbuiMeokwA7m29HUjAn4uA9/mA5E0/iG8RjhdwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=BbGn5YzV; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BbGn5YzV" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=0jRMO28hlSvt3zadSNwOLNWqxW82YvXZ34Ykj2ec+Tw=; b=BbGn5YzVLKVWXIPLrCzlp84cUp I+06bpKxaQ/thKBDB3ZKn2igdrSYtfRQlztBnuURBcZuxxCTk4dFBLwd0hsWseSnN4WhpRQ8NByy1 Peg9UNEEPT8b0iCpxjhIdmTba55vx+MQplwgRUDLK8DIt/lFfNG0iUUgAkOqNUgZIU/K57YK9tOEZ +cOOYTbPgT5EJlhyuAFfXxXGpD9nfYe4x5wRs0eX384chykvV3lyH0NHkOrbuEE+7fhLZQDiWTdW7 RJbuEB6FYhstyaUqHpv9fw0tXBQOyEslSgzfteIpu/S4iRjZ9xVzoQAOm4lqj8Gx+4zXz1c6fkAi9 K3Ikbz7A==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPj-00000005DAn-1aQv; Thu, 07 Mar 2024 15:12:07 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 08/10] md: switch to using blk_next_discard_bio directly Date: Thu, 7 Mar 2024 08:11:55 -0700 Message-Id: <20240307151157.466013-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html This fixes fatal signals getting into the way and corrupting the bio chain and removes the need to handle synchronous errors. Signed-off-by: Christoph Hellwig --- drivers/md/md.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 7d7b982e369c11..5803a298dd40f9 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -8722,8 +8722,10 @@ void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev, { struct bio *discard_bio = NULL; - if (__blkdev_issue_discard(rdev->bdev, start, size, GFP_NOIO, - &discard_bio) || !discard_bio) + while (blk_next_discard_bio(rdev->bdev, &discard_bio, &start, &size, + GFP_NOIO)) + ; + if (!discard_bio) return; bio_chain(discard_bio, bio); From patchwork Thu Mar 7 15:11:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585854 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E4568526A; Thu, 7 Mar 2024 15:12:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824331; cv=none; b=Pon+tArEzOPQNIVXGldgtbN1T4eJjK8qzEXGS3q+p+elJrD5cTmModTpPT3NTbZAjMnB07GsSpG9n34B6mb3n7nveaMYMvWUL4cPyUXFuhomxchko3VTFDZ9Nt7vtB7ETNQA4RzvZUrmxtbIkvkFt7aR9g2Y7utIo1Pkqk1Ul5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824331; c=relaxed/simple; bh=JwuYAmIi5UKapQAZKgFGSV9vl5tP9gtv8VjI9JvIHIM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ovwUJb+vqDpZN377AROy0ImhvVTisfLbnpVP9g6ZQsK9rM71066+NQStyTMGPlc6WTuN2lwI/TGs+GS9EPfYLUYkHHMHOc6vzQLGZUMP4RYow4o0fvpCqG5wR96qiXB6x3ZIpJ6x4noj6zJbJ6CTiIzUxo3mvNj2LT7nSP0E/+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=S8lDtdj/; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="S8lDtdj/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Ve/vSVtU1ouGfANFy/XRVyCgEc2TdovLRI20CqB7Pzs=; b=S8lDtdj/FBMkA6isjvZR/4WZ1q qNFJNJ+s7Fy4TU7PuB63SnfKSuJ0g8E6YOHMDtlFbnoXr5y7yrRr4jNJVqZq+erDxYwZTuzDygQ+/ QCSWkJ+wA09w92Yvm//mfho01bXLLa6kIHr5fFKwQ/ZNQ3BPmeINI4ZjU4OYHXIxLccdlUYLX9HeH INYjSZTw35NkhH0eRIlUxrJ8IT3bHRHp9fcxXwXi634NDaw+GBqkAiud92TrT2hzQvHCZO/miJ0BO DwVrmmToCK5oir5n1XGEHtYL0nZskjuUfATpg1gfRWRelUWXbzs0ji+Yws9FVoc/IBecEjbKWS0rl T97FUTAA==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPk-00000005DB9-0889; Thu, 07 Mar 2024 15:12:08 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 09/10] dm-thin: switch to using blk_next_discard_bio directly Date: Thu, 7 Mar 2024 08:11:56 -0700 Message-Id: <20240307151157.466013-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html This fixes fatal signals getting into the way and corrupting the bio chain and removes the need to handle synchronous errors. Signed-off-by: Christoph Hellwig --- drivers/md/dm-thin.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index 07c7f9795b107b..becf1b66262d34 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -398,10 +398,13 @@ static void begin_discard(struct discard_op *op, struct thin_c *tc, struct bio * static int issue_discard(struct discard_op *op, dm_block_t data_b, dm_block_t data_e) { struct thin_c *tc = op->tc; + struct block_device *bdev = tc->pool_dev->bdev; sector_t s = block_to_sectors(tc->pool, data_b); sector_t len = block_to_sectors(tc->pool, data_e - data_b); - return __blkdev_issue_discard(tc->pool_dev->bdev, s, len, GFP_NOIO, &op->bio); + while (blk_next_discard_bio(bdev, &op->bio, &s, &len, GFP_NOIO)) + ; + return 0; } static void end_discard(struct discard_op *op, int r) From patchwork Thu Mar 7 15:11:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13585855 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58EBA12F58A; Thu, 7 Mar 2024 15:12:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824331; cv=none; b=JclkBJde7bg12s3lIwAfJin9fxpejv2TX6akGP6Uir3jFUDUul/ysZnWiI3hDI19vvztHzGFqw3DuByz1thFY20XA5Gw9ucowl/7bWfar2Sxp/hHlzLAcGzI/llJiqX55ayas2tNUkxanXo3cw4rbEDdClIoGlXtQuOdDrSgBEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824331; c=relaxed/simple; bh=YW6FwHf1cZyuB8pvxeE9p+PHHGc++oMFrWPwA1CA6Jo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XUvemYwkl/ainLikswujTBkw0tw3QbBE3C2neX4nnQ0wBphLeJ37ZQEEB06dmsjSlhq+baFZz2v3h1OeebfnV0f3bnP452/OWuRAFqKjRuiERuRgNFooctZReOj9g+NQjUdG7tP96OOCkGWksc+i0qzEXmOj8bCp6lABxsrSTSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Z6sNMhee; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Z6sNMhee" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=jU4QlnWtPYtUMHg2kw7ZYLYWKsDbWmqawf6KHDiM9lA=; b=Z6sNMheeJfjyD9glIjnyns+gty pAVADDD91BM4ta1R/ON8FEKfp9UXU9QfGMUtDXvPFar2iRKoKEQ17PikIDnrRXabHyGTnWawxHwK3 E96odd8qAXRxRUdewCBcgQVlqRiO8vdq1cchhQkKExU5h0I6wAf6c+7IYSlj7O2Gt/61Wlnr4ROjq nErI2lTW2bwE3W139XgwYgFhxu+bY9pHELsNsv/XImw/T1dOirZBHbtAfb9LMjewlFq7JYV9/HG/J 6AAz9JRq6hr4DzsELFrK7lGN2Levd8gQsRMcjvQsdSniIgqSMAXhxLtCNAhl1SqN1+vqru/nKCXoi yr5PtWbA==; Received: from [66.60.99.14] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1riFPk-00000005DBr-3wFH; Thu, 07 Mar 2024 15:12:09 +0000 From: Christoph Hellwig To: Jens Axboe , Chandan Babu R , Keith Busch Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org Subject: [PATCH 10/10] block: remove __blkdev_issue_discard Date: Thu, 7 Mar 2024 08:11:57 -0700 Message-Id: <20240307151157.466013-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307151157.466013-1-hch@lst.de> References: <20240307151157.466013-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Fold what is left of __blkdev_issue_discard into blkdev_issue_discard and simplify the error handling. Signed-off-by: Christoph Hellwig --- block/blk-lib.c | 29 +++++++++-------------------- include/linux/blkdev.h | 2 -- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 4f2d52210b129c..39e6e21eb2982d 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -78,23 +78,6 @@ bool blk_next_discard_bio(struct block_device *bdev, struct bio **biop, } EXPORT_SYMBOL_GPL(blk_next_discard_bio); -int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, - sector_t nr_sects, gfp_t gfp_mask, struct bio **biop) -{ - struct bio *bio = *biop; - - while (blk_next_discard_bio(bdev, &bio, §or, &nr_sects, gfp_mask)) { - if (fatal_signal_pending(current)) { - await_bio_chain(bio); - return -EINTR; - } - } - - *biop = bio; - return 0; -} -EXPORT_SYMBOL(__blkdev_issue_discard); - /** * blkdev_issue_discard - queue a discard * @bdev: blockdev to issue discard for @@ -113,16 +96,22 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, int ret; blk_start_plug(&plug); - ret = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, &bio); - if (!ret && bio) { + while (blk_next_discard_bio(bdev, &bio, §or, &nr_sects, gfp_mask)) + if (fatal_signal_pending(current)) + goto fatal_signal; + if (bio) { ret = submit_bio_wait(bio); if (ret == -EOPNOTSUPP) ret = 0; bio_put(bio); } blk_finish_plug(&plug); - return ret; + +fatal_signal: + blk_finish_plug(&plug); + await_bio_chain(bio); + return -EINTR; } EXPORT_SYMBOL(blkdev_issue_discard); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index b87cd889008291..a1e638fb90fa77 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1057,8 +1057,6 @@ extern void blk_io_schedule(void); int blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask); -int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, - sector_t nr_sects, gfp_t gfp_mask, struct bio **biop); bool blk_next_discard_bio(struct block_device *bdev, struct bio **biop, sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask); int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,