From patchwork Wed Sep 4 14:18:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13790937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4C23CD484A for ; Wed, 4 Sep 2024 14:18:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B6136B00CF; Wed, 4 Sep 2024 10:17:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 363926B00D2; Wed, 4 Sep 2024 10:17:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B5C16B00D6; Wed, 4 Sep 2024 10:17:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EBDA36B00CF for ; Wed, 4 Sep 2024 10:17:56 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7122AC1342 for ; Wed, 4 Sep 2024 14:17:56 +0000 (UTC) X-FDA: 82527259752.11.1F1C338 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by imf18.hostedemail.com (Postfix) with ESMTP id 805231C0027 for ; Wed, 4 Sep 2024 14:17:54 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Xca3ZfHJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725459450; a=rsa-sha256; cv=none; b=cVoiVTJBesTGOmPa3N52MpkUZIyPFdKBH58y4JsxHVtHxlwjbXz72S6gpdRV1Smx6qmOMP p7+y1w9oQmlwBQQpyVJYGzLZjwdhajETlzobawcAjYy4BPbJEg75RdG2AJaLegYSu+Sn+O v+S5zU/SYpFuGqyjyom3fNOsGhKk+Do= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Xca3ZfHJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725459450; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/3weTv0JDO1olCzxF1klLqGqviZ0xpQPSzNHS+GA/qM=; b=IoW4gdhvRxa0rk8y6IDzpI3zpXxqDYTSiF7HrV+C7pPAX23hec9MLCzJJ+CailOPU0Laco Cx5+OcqbX67Jv11gY5D21Hn9rypED5WUF0IvKdp6H5abe0PmphadEeUjWd8WfzWJ3QwVki j/rAOjfTKqmvjoGlNiZ9ct/cg42OAuk= Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-533de5a88f8so6869809e87.3 for ; Wed, 04 Sep 2024 07:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725459472; x=1726064272; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/3weTv0JDO1olCzxF1klLqGqviZ0xpQPSzNHS+GA/qM=; b=Xca3ZfHJyap+EADU7jX2ISPugr2YcZqWZTb0YLvbpKc8ltHumbczAextV6cxtRZKWz aOsaGBBJJZEDyCDRrfta0VmYop/uulOP0H/VaxI3OzRHWt93zGc4tvbV6FMOqdV0aTIv fuM7IaBEU3gKGML/roQpyVAf/2wOvxEf74TjBjA6eb2sWLUlB35QwejBMsnMTzikLvwY Fl0MGM8MgtMJ3fxDsZz5dzeGWHBcDpz9SmhGUkt6+8FH/wevMMHIewU6F5e4zFmP+349 xarqRKlW2NFHYsQtnQqPi9DYWfXLpjZbHTKIRZ4+1XHcUvu+lUl4O4vcyJYXLBOXKWIH 85Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725459472; x=1726064272; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/3weTv0JDO1olCzxF1klLqGqviZ0xpQPSzNHS+GA/qM=; b=NEao5pT0YvuhpKET8ol9ShzY94mfsg73KbuckoKG7WOKX+NVY5Wl7P21Lq7eRDePqm 8oeqkvawrZHt+3ArnMVDeOdWw+Cq1RiprXNLrJuqDfiPWTLTR6R/f3T0jheYdwwhWKN6 tQg3jUWYzxkNKCGrnP6UXNDlu9hl7Aaz4IaONrXuRE6n6X7raf4cKkzB5VRfqW+BQDk5 gsQqx6z1n9mk7av+AJxPYMmIgQTDsigTcy1FGZWOdldgRcMdHU14j3ev7aWPpSnx15tb v3EBWn69ZAG2ljyad688pB6JJXYZ77kc8rhY0zySF3i5K+ZJwnWjsyh7y+q2/bDHltLe 074Q== X-Forwarded-Encrypted: i=1; AJvYcCWAViwsGPoZRu2/r3GCV5lggNU2AGvi/SEPZ2XzXUs7pipwlzY0IPRvZhSvffocxxt2q1G35MSdXg==@kvack.org X-Gm-Message-State: AOJu0YxNqrQj1UcR8Dk3tWh9PvcETkhGUgUF8U0e5ZgzEndlXlwZYn0Q xRU3UKmO5vBsbSIvK8Is65nMx+NLJ0hfuGGKqEwBrB2G6lRZbHYL X-Google-Smtp-Source: AGHT+IHXEXHSZq9e6Nc/W/109+8Kx4Ik97uxMWG+wzLcTtKwZnA/1xjIlHHukneB6BfUKC9IqvzHsA== X-Received: by 2002:ac2:4c4f:0:b0:533:42ae:c985 with SMTP id 2adb3069b0e04-53546b2df7emr12335403e87.25.1725459472360; Wed, 04 Sep 2024 07:17:52 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989196c88sm811160766b.102.2024.09.04.07.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 07:17:51 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: [PATCH v3 7/8] block: add nowait flag for __blkdev_issue_zero_pages Date: Wed, 4 Sep 2024 15:18:06 +0100 Message-ID: <292fa1c611adb064efe16ab741aad65c2128ada8.1725459175.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 805231C0027 X-Rspamd-Server: rspam01 X-Stat-Signature: rddkfwwdgfzmt1tgqnkfimgnyj8g1ix3 X-HE-Tag: 1725459474-877005 X-HE-Meta: U2FsdGVkX19e1bDuCJSmZI6uH5rHKSr3ITgRsXLj6VjRPDBHE/uBllbzXvx3IMLiD+R9ARBsoX/obrlMXRIPp97kf1E5ObB2DGz35l0Qul6EXNr0gf4xtGp30jJraXYUqutpppqgjLqLqpwThVSGHVicGWdPl9YZvHwMmbrYBOpvoxMPD0WtfLaQa/4OiIgJgI1ynLCyySAzYjXWZgM2k+gUHuJgW5srMfya/9nwS12c6C310coGZx760pUQ9CuRwjh1xHuxHxcntMMvwJrj3ev6S5E6ChvhAKVOE30rETe9gfmDOm3j65g9i+SC+y66Y/Ih6+eXA+XfFc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OU52aixzW5NrhaqratRYAAJGKV+1tZQ7hDlv+WCaGxo2NGIcb1lRXKl7BkRgtHnxfPYMsbQlfHi0djB7FEp4RJWd1+p3wy8RUTnZGxoODWTL4Lxm7A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: To reuse __blkdev_issue_zero_pages() in the following patch, we need to make it work with non-blocking requests. Add a new nowait flag we can pass inside. Return errors if something went wrong, and check bio_alloc() for failures, which wasn't supposed to happen before because of what gfp flags the callers are passing. Note that there might be a bio passed back even when the function returned an error. To limit the scope of the patch, don't add return code handling to callers, that can be deferred to a follow up. Signed-off-by: Pavel Begunkov --- block/blk-lib.c | 22 ++++++++++++++++++---- include/linux/bio.h | 4 ++++ include/linux/blkdev.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index c94c67a75f7e..a16b7c7965e8 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -193,20 +193,32 @@ static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects) return min(pages, (sector_t)BIO_MAX_VECS); } -static void __blkdev_issue_zero_pages(struct block_device *bdev, +int blkdev_issue_zero_pages_bio(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, unsigned int flags) { + blk_opf_t opf = REQ_OP_WRITE; + + if (flags & BLKDEV_ZERO_PAGES_NOWAIT) { + sector_t max_bio_sectors = BIO_MAX_VECS << PAGE_SECTORS_SHIFT; + + if (nr_sects > max_bio_sectors) + return -EAGAIN; + opf |= REQ_NOWAIT; + } + while (nr_sects) { unsigned int nr_vecs = __blkdev_sectors_to_bio_pages(nr_sects); struct bio *bio; bio = bio_alloc(bdev, nr_vecs, REQ_OP_WRITE, gfp_mask); + if (!bio) + return -ENOMEM; bio->bi_iter.bi_sector = sector; if ((flags & BLKDEV_ZERO_KILLABLE) && fatal_signal_pending(current)) - break; + return -EINTR; do { unsigned int len, added; @@ -223,6 +235,8 @@ static void __blkdev_issue_zero_pages(struct block_device *bdev, *biop = bio_chain_and_submit(*biop, bio); cond_resched(); } + + return 0; } static int blkdev_issue_zero_pages(struct block_device *bdev, sector_t sector, @@ -236,7 +250,7 @@ static int blkdev_issue_zero_pages(struct block_device *bdev, sector_t sector, return -EOPNOTSUPP; blk_start_plug(&plug); - __blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp, &bio, flags); + blkdev_issue_zero_pages_bio(bdev, sector, nr_sects, gfp, &bio, flags); if (bio) { if ((flags & BLKDEV_ZERO_KILLABLE) && fatal_signal_pending(current)) { @@ -286,7 +300,7 @@ int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, } else { if (flags & BLKDEV_ZERO_NOFALLBACK) return -EOPNOTSUPP; - __blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp_mask, + blkdev_issue_zero_pages_bio(bdev, sector, nr_sects, gfp_mask, biop, flags); } return 0; diff --git a/include/linux/bio.h b/include/linux/bio.h index 78ead424484c..87d85b326e1e 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -686,4 +686,8 @@ struct bio *blk_alloc_discard_bio(struct block_device *bdev, sector_t bio_discard_limit(struct block_device *bdev, sector_t sector); +int blkdev_issue_zero_pages_bio(struct block_device *bdev, + sector_t sector, sector_t nr_sects, gfp_t gfp_mask, + struct bio **biop, unsigned int flags); + #endif /* __LINUX_BIO_H */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 643c9020a35a..bf1aa951fda2 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1098,6 +1098,7 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ #define BLKDEV_ZERO_KILLABLE (1 << 2) /* interruptible by fatal signals */ +#define BLKDEV_ZERO_PAGES_NOWAIT (1 << 3) /* non-blocking submission */ extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop,