From patchwork Fri Sep 6 22:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13794837 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 3D889E6FE49 for ; Fri, 6 Sep 2024 22:57:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A264F6B009D; Fri, 6 Sep 2024 18:57:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D4926B009C; Fri, 6 Sep 2024 18:57:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 827E46B009D; Fri, 6 Sep 2024 18:57:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5FD806B009B for ; Fri, 6 Sep 2024 18:57:11 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D580641167 for ; Fri, 6 Sep 2024 22:57:10 +0000 (UTC) X-FDA: 82535825820.21.5A14B74 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf18.hostedemail.com (Postfix) with ESMTP id EA0921C0005 for ; Fri, 6 Sep 2024 22:57:08 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QXyvQ51B; spf=pass (imf18.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725663330; 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=jYezJHCo7v489eblMcj1bTcVFXeBrX/vk5R7qG2A1Yk=; b=SeZuAg5kt5YGd+nYnwvdCw71S91miXTCHyLrMWyQ5yM5XzhGfLUkJvYvGusLvOPhCTVyBG I6MfkYl5eE0KVqrtkoAFJjqbgTZx2sEl5igt63URSbqEX14YMXl7iiAO5z6UWrGl3Lejkj 4nkVIGpZv7y8LI2e3y5WHja65O5pDms= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725663330; a=rsa-sha256; cv=none; b=IN5cExh1RAtVtghh9E6Kq6i4+bxMPu+iHbeK4fwCvgq9+9IEbA7+O1C8ocCrRtz/WyH707 VaBz9lSv8zpyX/aYW63AR1W0ulQ0bHmFnd3VFsn2Y8RD4rwNB85qWOCHgImdwee0F+iIbz Z42kWqgsYZG2DcECYef6K0/NsxbFfpE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QXyvQ51B; spf=pass (imf18.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a8696e9bd24so326090566b.0 for ; Fri, 06 Sep 2024 15:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725663427; x=1726268227; 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=jYezJHCo7v489eblMcj1bTcVFXeBrX/vk5R7qG2A1Yk=; b=QXyvQ51BX5LcqUY9vC4wrA3UNxapiMRYjAYwY1nAopCTksLH1+H/31zrtSAL10NN+B bJ+VZu1wYcHflbxq2s7qO8bvCZzlzRbbOuhgZihQKS9VjSPK7JxKt//qSs4ztcNqzAWU cUyy8423tOPKDqujLGIn8dW7Qq/pzzokbhuias6hqOn2c9RqoORwNvf7keMNLt/2w87a Zlpb0/1F70ebobZZiBWVbMRiV4JMeVPh8TlI9vPnmIi1qWlk/BhA5ewlU/p/uKQDnjPG TiwQEOKwIDOUktNMu634o69qN8P5WmEA+JrA+rYZNIkkhemkjXmbI0VYbzEPCzYyTjyY X3SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725663427; x=1726268227; 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=jYezJHCo7v489eblMcj1bTcVFXeBrX/vk5R7qG2A1Yk=; b=XB4Q+uwtN0ov7WUitgO057pyXRetL3UltLWMeW0bIdG2HINjKwiqxcrSwRd4CIVrZD 1qvt88oA8y2xY+QZQ3fmsusEQpfLo1wsDopj8c4JREyX//HYYqvoaW0nzusxPvUX7Ln0 ezU6XlXebisJhQCiMnPkZEV5eyCd755QRxZuaXTE3XVNakiEzYRXcg98ccmt5Mei11Vh LsONLeOdRrBUMpk3lqIcd1wqadoOIxNdqWqvZxCZb1w49LosQiJHgDcNVgqce0DXIg+B 17P9IYuYd3DVvlRWNSUWeTVVR3Ph19XQph89IXI5F5K+EI7j+j9HZ46285gOMgGODr+y YhtQ== X-Forwarded-Encrypted: i=1; AJvYcCXkdNLS1IORaNztrQkcJ1Rqz3rXcvpn+5ssxdJCIHXrn/O7geYrvNjCt9T+l91Buzvd+ObDX5EweQ==@kvack.org X-Gm-Message-State: AOJu0YyGQSRzzwhlhR8S+rtOzUfjIigUuyof7eGCQ8jEX11STGfrFB1j rpadalxIb+e+/LiKQ1xVipXLO17gDaikUlJFybkhOGYNdv6aLC3S X-Google-Smtp-Source: AGHT+IE/3M7b/K3pyseCsX+NiZT9J56A5VyhoP1o7o5GWtiHew5dHLC0T6ZxFj2yq0dOHss7K5NZbA== X-Received: by 2002:a17:907:3f20:b0:a8d:caa:7fee with SMTP id a640c23a62f3a-a8d1bf75ec5mr67443566b.7.1725663427142; Fri, 06 Sep 2024 15:57:07 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.146.236]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d54978sm2679566b.199.2024.09.06.15.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 15:57:06 -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 v4 7/8] block: add nowait flag for __blkdev_issue_zero_pages Date: Fri, 6 Sep 2024 23:57:24 +0100 Message-ID: <387caa9b7a23061f19034a8afd1dfcf017d8fe35.1725621577.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-Server: rspam04 X-Rspamd-Queue-Id: EA0921C0005 X-Stat-Signature: 1akcje6rwj1419msfcikepnnfru89awb X-HE-Tag: 1725663428-879437 X-HE-Meta: U2FsdGVkX18ofkvbCVKaLsnD7d4i5tI52z9l2R1y5mWOrbJ8awyXXonj7O/D6WVVPnxvZJQ9v6ZkAVd8ZvWeecRZpUdXQt14EcHTbV3UHf3ElnpaShCg2h4bKD2JK2HN1AhdDKrhvTMZ37/9t6tk9ehYxSr9m+QWauNukDw+GCn4Q5mMm+jw8mnA8KsTd2mLgdZHK+kljTfVLL62mAL3FbPpWnYzC6twy9L+9k8z4H5n7A3VcWv6Fy3PD34Rib10j7KFyKuSqAtt7MxvWmsFfDYb9wiJawqEN9Wfp0hfmQKYCOSzr6UmAQycRpeezI10YSp/sIh7uOrJ9mRvSmta040fAIyrt6PU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XOmEZGEHdPwznsPWBq8RNwc93Gv6oEAQQG17fz/++BYmtz9B0+MYnvXS/hKewgdo1cB9ep1skEvaPHGeqzINw== 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 | 24 +++++++++++++++++++----- include/linux/bio.h | 4 ++++ include/linux/blkdev.h | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index c94c67a75f7e..0d8f1b93b4c3 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); + bio = bio_alloc(bdev, nr_vecs, opf, 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,