From patchwork Wed Sep 11 16:34:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13800883 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 62CFEEE57C2 for ; Wed, 11 Sep 2024 16:34:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 667DA94006A; Wed, 11 Sep 2024 12:34:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E8DB940066; Wed, 11 Sep 2024 12:34:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 413A094006A; Wed, 11 Sep 2024 12:34:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0DF2E940066 for ; Wed, 11 Sep 2024 12:34:33 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B5B24161997 for ; Wed, 11 Sep 2024 16:34:32 +0000 (UTC) X-FDA: 82553005584.17.DC5466F Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf02.hostedemail.com (Postfix) with ESMTP id DF61680011 for ; Wed, 11 Sep 2024 16:34:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OnJ2vqNf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726072394; a=rsa-sha256; cv=none; b=bfAjCdZilMC7ZXycp6ug3P6DC9dL3bxojxjSo5+IM4CyLXbCV5Z5htePZNdabkwOsUy99s kSHY7ccqJ3QhHZr+/qJGjhjHED2+Pav4/tLzDEiEgHhk49VDi7fZvc1gtAgg5oZCYfJFSo RhFW714r6nmwxPvvg1xHf0tIV3DsLik= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OnJ2vqNf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.52 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=1726072394; 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=Jv/xRgK93eDswhXa+H3bNlv587Pzbd+1FrWwfpAcjww=; b=4nvCNylF+b6qAHvANIzK3J1iHXpyvflfshfKDBbsDD7LThzXDOlupjExFpYVUiFHfVdEdj ZKZNCMRG0ww201fRfjFq++TtsBdFh4SfrHZx6aaVY33zu8DwPUsegrV4/tQpEgmxSDxKo9 txouM/qFcRDw4Ci7nUh4U5RpOAzh9ZE= Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a8a7cdfdd80so7192966b.0 for ; Wed, 11 Sep 2024 09:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726072469; x=1726677269; 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=Jv/xRgK93eDswhXa+H3bNlv587Pzbd+1FrWwfpAcjww=; b=OnJ2vqNfqa8AW2WRd1NrwCRj4LM8Tzl/L1MfrnfPcAD5MqaMZousMPXC+W1ytLYzhv kiRRwT8CnycIRwxWTpZ8PBo+XWzEUVJ9LpFw2juR2HJzkJehXRWq/pnNr/VUC0e39m2p M7ZFzbDyEu5FsWZhX4jsZ4SiMgz80DlkJcDDlNzcV/ZmVgB3keCWDbMYDYhGuZRJJ+wx yOd46RomEZJsf1QdI1+EdM1jlKl88inZeNNRiOUHPPHYp9/G8ASRB9tLJwBlWRkwG4fy Nzypi0TuTmGgevpZCmfqpoOpAgsS7zlAseVseAySrsek0EC5b2e7GYsQQOVvl0k/SpK5 VoZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726072469; x=1726677269; 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=Jv/xRgK93eDswhXa+H3bNlv587Pzbd+1FrWwfpAcjww=; b=Vf8WaL72vmfe7BsehjuNw4eOGaFlc0tz1mcGyO8lVfz3mTaxAclPtxzRdCYVHsSphe FPrw6qek8BWUjs9aXUXP3k/6lPChzdAYfbDQ4g3Xg1mrsGdiq873kZL6m3cWPFEYXKOv /Umz1B/v6tvaAOj5WpSjkYUwPOR+5PnMuvJmkN8kfSostj3OYt5xfrWUPbVXO5FU0wf2 p5Dl8Gvd+7R/DqPNK7DkHP+4Bq9vKcwtX0t6j64jXoiQ9ZA53In4vF+T+ukEYbC+iJ4q NBGuBKh+nWCvcBD3sZnVH/+wVGIx8TcCZIcUy5XYpaS2Fy/HzC5bd7ON/VA/S8PDf4GN q/PQ== X-Forwarded-Encrypted: i=1; AJvYcCVEBirHoRHfwCEby6hlLQ/rwIe0R0j2HOXPzklUlOYlbQAhxDBS72ZWPhs+WKdgg7BxoPTsQk+h/w==@kvack.org X-Gm-Message-State: AOJu0YzpVJHEnj1dkM4zePnbKhT293vgHgTvfQ8mBxamuw7r8s4WWmP+ WjVAzOZNZFR0CEr6kTW1ajcr/MWpCT2fyxOAGe5FtqxUC3uWpPhs X-Google-Smtp-Source: AGHT+IGuiTLA2mNX0YCzkTRNyEFx9mbWso8US7cNHDcH1lN98BWCM89d0c663QhibBxvnr/nZH5TzQ== X-Received: by 2002:a17:907:f186:b0:a86:f960:411d with SMTP id a640c23a62f3a-a9029409aedmr9838766b.2.1726072469422; Wed, 11 Sep 2024 09:34:29 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72ed3sm631820866b.135.2024.09.11.09.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 09:34:28 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, linux-block@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: [PATCH v5 7/8] block: add nowait flag for __blkdev_issue_zero_pages Date: Wed, 11 Sep 2024 17:34:43 +0100 Message-ID: <0a4e17bf70d5fa035329664b25a780bf4f53e38f.1726072086.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: DF61680011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ou9cruspuwuqbgcgosrxhb13tgtiaz7e X-HE-Tag: 1726072470-84347 X-HE-Meta: U2FsdGVkX1/CTwPt6l+aYNIWSFVvD7EknxAO4qBAqPVxN2GfwC2LMtEKPOeKF14Kw5nV0P0SEy4Nr+QabZKFUloZwYqd0yacOMyOKzNPNfA+BO698YpjSb6SFeuXKBYAUit9V1dyxkdmvVerdbNMItSqTNquKj3ufMlJTm+2cFB4AA+DaEPSX3JBknmwsufBUibMFKBKo7W05B74v84+1+XCSP7t9KiCVMl6RAdQkC9Px/S+UgZ57QkN2S0iLUiL5yPstX60W0UMkgoDSlqqzFvtkVeaSTlMhKl59psIP2FTWyehcNjTgZ6UmFqcYIlsTqSimnz3rKh96aZ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QopTbPSUb+DkE1UhaFveDSQPLqtFahOCfYFggT4ib1F79PcgUA9Om8LXw6aNe4BI8WGSGX0gjKgr4ZNLe/LosAcagpad/ZJYuyezZkbNfl3FXuYhneJw01yMK/pUVZibHC1gv594tWItJiby8F202ysk/hg5 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 83eb7761c2bf..40bb59f583ee 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -192,20 +192,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; @@ -222,6 +234,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, @@ -235,7 +249,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)) { @@ -285,7 +299,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 faceadb040f9..e4e495a4a95b 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -684,4 +684,8 @@ struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new); struct bio *blk_alloc_discard_bio(struct block_device *bdev, sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask); +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,