From patchwork Wed Apr 30 21:21:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886238 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 2ACD32BD93D; Wed, 30 Apr 2025 21:22: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=1746048128; cv=none; b=YZjXh5iTz4jczxf+FtcnUO9GP8WcIHPDuA19ei1Yw+Un2+bexzIA0+AJSk1ZRCgudPyIIyIOduu0zqIVVdXfyPhaBPAfahqtV56336w+8AIOdt8t37257UiwlDTJcHZyXuZ7m/W3EHAXqXhfoAY1HtKeudTm69KAzAw44cPzryc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048128; c=relaxed/simple; bh=sWO2f/PxHT1FPtFUalwag2d9hPPO/aR7oKxfBHK7ykw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CjBSIoVHgjCBQTOwFcojQT2DOmKg+sRgdT2nntV+FCbt6TiNysNflPSLjhYKoxJaWgWQ7gbhvNG6IoRd49WfzTy8ngsd6dmV8/Ip4BHaHwgZnVcy6Mb29esVufEvYETZfLGXuCUU6GYMv1s5+TlCPTjSu6xUUMgtjZPHmDQ9xy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=D+ofx2nx; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="D+ofx2nx" 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=R5NIVw/93J/inPIJ3/N2tOuwD8pOE89NikFOGZTqiC4=; b=D+ofx2nxOGw3yGY/8psrCG4CGg wSpsZV3SlGqkToRY30U+M8OwT2tIVU2BU9Xbo01ttwJ4qF8tp6Q2MN6Sne/d2fWpc0htF53qI/VpF pcAWkMJ4LuGnqG9MKROb8Rsp1gsJLj7kUJSWrGJ+hH2KxwFHNd9gDeDfoUHAWGaU6EVZ1P6uvNsWX oqO/GM2yKUqRza45WoEqKPbPFRO4Zkb4o+jX2nvbwqH8ZDv0rJ6SmEh3bBmT06mRi2uHRxSagHn37 9tVRNAzo1pXfMcp6c8qEY4pCmej3/P+diktB/1KYO5KeI1QdINlCnXwbUvwpLWolxUEZQc0NID/BR 0JX12Smg==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEsW-0000000E2W5-2808; Wed, 30 Apr 2025 21:22:04 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org, Hannes Reinecke , Johannes Thumshirn Subject: [PATCH 01/19] block: add a bio_add_virt_nofail helper Date: Wed, 30 Apr 2025 16:21:31 -0500 Message-ID: <20250430212159.2865803-2-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Add a helper to add a directly mapped kernel virtual address to a bio so that callers don't have to convert to pages or folios. For now only the _nofail variant is provided as that is what all the obvious callers want. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn --- block/bio.c | 16 ++++++++++++++++ include/linux/bio.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/block/bio.c b/block/bio.c index 4e6c85a33d74..c1789a58f23f 100644 --- a/block/bio.c +++ b/block/bio.c @@ -989,6 +989,22 @@ void __bio_add_page(struct bio *bio, struct page *page, } EXPORT_SYMBOL_GPL(__bio_add_page); +/** + * bio_add_virt_nofail - add data in the direct kernel mapping to a bio + * @bio: destination bio + * @vaddr: data to add + * @len: length of the data to add, may cross pages + * + * Add the data at @vaddr to @bio. The caller must have ensure a segment + * is available for the added data. No merging into an existing segment + * will be performed. + */ +void bio_add_virt_nofail(struct bio *bio, void *vaddr, unsigned len) +{ + __bio_add_page(bio, virt_to_page(vaddr), len, offset_in_page(vaddr)); +} +EXPORT_SYMBOL_GPL(bio_add_virt_nofail); + /** * bio_add_page - attempt to add page(s) to bio * @bio: destination bio diff --git a/include/linux/bio.h b/include/linux/bio.h index cafc7c215de8..acca7464080c 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -417,6 +417,8 @@ void __bio_add_page(struct bio *bio, struct page *page, unsigned int len, unsigned int off); void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len, size_t off); +void bio_add_virt_nofail(struct bio *bio, void *vaddr, unsigned len); + int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter); void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter); void __bio_release_pages(struct bio *bio, bool mark_dirty); From patchwork Wed Apr 30 21:21:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886237 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 7D6182D0ABA; Wed, 30 Apr 2025 21:22: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=1746048130; cv=none; b=NUsf9nLLOO7n1NYYjSaR+6CNRJ4dT7rjPJXSWd/h3nseG97k+Neg+zU12dcMYSe+KmCz/Yc8pSP6KNQPfQH5ue1TzdBJgvSYNGD06QdWYXYI/Jsx236XKw22NsK/0OMqPjC7h5Y1qF+6cMTjIiuwV2UJYZwNlAZqR9kRbFzJpRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048130; c=relaxed/simple; bh=KQD/7aUDcPfshCdC5wrOSoSgHOUfjW1/T4FjifhZ6r4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IPs5hes0QD/7e6nPcY5Thv9jizg/QzRRzW7/Y9ads2RrI9jh52jE3BLA9HHnMj1F55LFd3lBMm4eFRnAcFkZE/mQReFHxE9Wv4cHJs2pcMoJtQSsFdH8CzZEFl/0w2tKaK3MNvx50Qm4K1Qarkg2AGHmH0j/XOAVihYjdzJ+1r8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=tleX5N/H; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="tleX5N/H" 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=4AZ0e83YSqqAexI5BVOxX9+ELnf7u8xLP48RyNUi7l8=; b=tleX5N/H71n2VPQLiexI2uffp1 VVCcJ1IGTO8kx6Zh8C8J62/4JPNvTJfg1dc88FLlBSm61AJv+lT4BZ+kLo4X6FWftrqBU8NewpgJJ w5HBokATVRlZTOKJPsHPPCDXZOCeATp0p4ohb1aIJXWh304sdrbUXUWCt30O8jkXtQ6y2ZZQUMF49 we26MtMMuGS+KrVmrXho4EkGESBQRNpaHZAPXyCGXDtmS1L35QDMf46eW3q2dQiXMoWsPpCV3UT7b wkK/21Sv291QRSNR8RMpsA48JgZCOdSVgMu8YTrXhDvK2IcCc0h3m3MvCbJwcg/m7M1XUhWTKsjVK H0naRcNA==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEsZ-0000000E2WL-1ADo; Wed, 30 Apr 2025 21:22:07 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org, Hannes Reinecke , Johannes Thumshirn Subject: [PATCH 02/19] block: add a bdev_rw_virt helper Date: Wed, 30 Apr 2025 16:21:32 -0500 Message-ID: <20250430212159.2865803-3-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Add a helper to perform synchronous I/O on a kernel direct map range. Currently this is implemented in various places in usually not very efficient ways, so provide a generic helper instead. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn --- block/bio.c | 30 ++++++++++++++++++++++++++++++ include/linux/bio.h | 5 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index c1789a58f23f..8db2db0bba0f 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1317,6 +1317,36 @@ int submit_bio_wait(struct bio *bio) } EXPORT_SYMBOL(submit_bio_wait); +/** + * bdev_rw_virt - synchronously read into / write from kernel mapping + * @bdev: block device to access + * @sector: sector to access + * @data: data to read/write + * @len: length in byte to read/write + * @op: operation (e.g. REQ_OP_READ/REQ_OP_WRITE) + * + * Performs synchronous I/O to @bdev for @data/@len. @data must be in + * the kernel direct mapping and not a vmalloc address. + */ +int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data, + size_t len, enum req_op op) +{ + struct bio_vec bv; + struct bio bio; + int error; + + if (WARN_ON_ONCE(is_vmalloc_addr(data))) + return -EIO; + + bio_init(&bio, bdev, &bv, 1, op); + bio.bi_iter.bi_sector = sector; + bio_add_virt_nofail(&bio, data, len); + error = submit_bio_wait(&bio); + bio_uninit(&bio); + return error; +} +EXPORT_SYMBOL_GPL(bdev_rw_virt); + static void bio_wait_end_io(struct bio *bio) { complete(bio->bi_private); diff --git a/include/linux/bio.h b/include/linux/bio.h index acca7464080c..ad54e6af20dc 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -402,7 +402,6 @@ static inline int bio_iov_vecs_to_alloc(struct iov_iter *iter, int max_segs) struct request_queue; -extern int submit_bio_wait(struct bio *bio); void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table, unsigned short max_vecs, blk_opf_t opf); extern void bio_uninit(struct bio *); @@ -419,6 +418,10 @@ void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len, size_t off); void bio_add_virt_nofail(struct bio *bio, void *vaddr, unsigned len); +int submit_bio_wait(struct bio *bio); +int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data, + size_t len, enum req_op op); + int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter); void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter); void __bio_release_pages(struct bio *bio, bool mark_dirty); From patchwork Wed Apr 30 21:21:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886236 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 BDBC52D643D; Wed, 30 Apr 2025 21:22:13 +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=1746048135; cv=none; b=gXK5Zu0cQR0ce5S1bSaEh1c5AP7RIGBy32fAMaBx3zZ1V3MsaeOBJhyqdzgXJgedSFvJ1Qofy8DY50B+WhoExIm2fqt91eWvz3hslAJZamfbzaVVOBSWtV0VFIu5m6BxeruzMxSHuAA6+cPnDNmj1pJgid3Z+B6TS+g7/wk/kWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048135; c=relaxed/simple; bh=oHt7k0ATOlag8su5uID7QhFjuWncQCCw/RBdey6XSJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SObXPHWsXEHkBCB4QUzyyjk8XqHCFXopqdjYmy2j2uDAoam1THVCgGwM9rqkAva8o1tOVo7kyyk6F08MUTYDxn3bIqCg2eXUMJj2xjHMXbrde2B2r0IGOGsN3KA7iUPx9oExN5Qq1iQzZXjin9mlQ5xUma7qRYJAM/Jnvtj7ElQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=20uQwirK; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="20uQwirK" 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=BV13n3qNH9gK6w5ciD7+8l8MqTjGtb1kFaQOlROr3iw=; b=20uQwirKNl+/zR92iJKSLZkgOg l7gsiQR0G7K+4Ty7rw0WwV/tk1FoNMqzsrWo6V+XzWJk8/ohLn+ZTATcfIaNmS7HDEM/HeTYFhW3L +FBqK8Z5eKmU3QZvdErNzPNTUuSztN5TVBl9TYCa0tB1kgSPFEVgbVD2hQMsbLSOnKA80VKyeULpG d+wJhDwfgbCQ9YM1ajguIQxYZBqCXAkRXpXY4030LmxSdRox/aOaYKDg5Bzl3olkkZE19SggPZfoR GddTaRJA2UuSJRUSIgPsv5dgP7clrUE9aIsC4lsUuaNY9UVt9aQwp/KxzkrjxOC9+PfJJhAR4D6Qf xNM1gmkw==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEse-0000000E2XO-2kcJ; Wed, 30 Apr 2025 21:22:13 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 04/19] block: add a bio_add_vmalloc helpers Date: Wed, 30 Apr 2025 16:21:34 -0500 Message-ID: <20250430212159.2865803-5-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Add a helper to add a vmalloc region to a bio, abstracting away the vmalloc addresses from the underlying pages and another one wrapping it for the simple case where all data fits into a single bio. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/bio.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 3 +++ 2 files changed, 58 insertions(+) diff --git a/block/bio.c b/block/bio.c index 8db2db0bba0f..1efe63e375ae 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1074,6 +1074,61 @@ bool bio_add_folio(struct bio *bio, struct folio *folio, size_t len, } EXPORT_SYMBOL(bio_add_folio); +/** + * bio_add_vmalloc_chunk - add a vmalloc chunk to a bio + * @bio: destination bio + * @vaddr: vmalloc address to add + * @len: total length in bytes of the data to add + * + * Add data starting at @vaddr to @bio and return how many bytes were added. + * This may be less than the amount originally asked. Returns 0 if no data + * could be added to @bio. + * + * This helper calls flush_kernel_vmap_range() for the range added. For reads + * the caller still needs to manually call invalidate_kernel_vmap_range() in + * the completion handler. + */ +unsigned int bio_add_vmalloc_chunk(struct bio *bio, void *vaddr, unsigned len) +{ + unsigned int offset = offset_in_page(vaddr); + + len = min(len, PAGE_SIZE - offset); + if (bio_add_page(bio, vmalloc_to_page(vaddr), len, offset) < len) + return 0; + if (op_is_write(bio_op(bio))) + flush_kernel_vmap_range(vaddr, len); + return len; +} +EXPORT_SYMBOL_GPL(bio_add_vmalloc_chunk); + +/** + * bio_add_vmalloc - add a vmalloc region to a bio + * @bio: destination bio + * @vaddr: vmalloc address to add + * @len: total length in bytes of the data to add + * + * Add data starting at @vaddr to @bio. Return %true on success or %false if + * @bio does not have enough space for the payload. + * + * This helper calls flush_kernel_vmap_range() for the range added. For reads + * the caller still needs to manually call invalidate_kernel_vmap_range() in + * the completion handler. + */ +bool bio_add_vmalloc(struct bio *bio, void *vaddr, unsigned int len) +{ + do { + unsigned int added = bio_add_vmalloc_chunk(bio, vaddr, len); + + if (!added) + return false; + vaddr += added; + len -= added; + } while (len); + + return true; +} +EXPORT_SYMBOL_GPL(bio_add_vmalloc); + void __bio_release_pages(struct bio *bio, bool mark_dirty) { struct folio_iter fi; diff --git a/include/linux/bio.h b/include/linux/bio.h index 128b1c6ca648..5d880903bcc5 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -433,6 +433,9 @@ static inline unsigned int bio_add_max_vecs(void *kaddr, unsigned int len) return 1; } +unsigned int bio_add_vmalloc_chunk(struct bio *bio, void *vaddr, unsigned len); +bool bio_add_vmalloc(struct bio *bio, void *vaddr, unsigned int len); + int submit_bio_wait(struct bio *bio); int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data, size_t len, enum req_op op); From patchwork Wed Apr 30 21:21:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886235 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 42DA12BD93D; Wed, 30 Apr 2025 21:22:19 +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=1746048140; cv=none; b=NJpUl1ciTkAq/KtbwdzryNDN2piDdQbWOrn7fMCBD2WA6JK/niPBXoOph9vLefMHjnV4GvNfYvCQX50pSvk0mrjQZrRAhccvJdC79kMxnSKFDrp7Z7nUNackFfo83SEMpmesurSVWJMINYJFwwjxU7tCQ+yR1ecpI3ECLIuoybw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048140; c=relaxed/simple; bh=f/SCktuVLQ3i76ed/sgw4S/2ksk+BmCglPIcaaQvhko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NzTXKqXv38F4PkJWyOYG34IWJpX/ydbGDpsABR3x5sGYAOsyAQuBCmTpLfI6574dFXChl3X7ByfV3BkZDDHhV1ZxwKxK1sWyMe4QMH7fLiDVyIfQYSXK0hUAg1MFdQwwyPiNJ7wuS/ONFQ42lgGO3fhfEkiDLe1/xOZhVQYZ1IM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=ogm5d+Oa; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="ogm5d+Oa" 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=hWWdHC5y/JUq54b2u3PyEO5FfJhHi9A7bx3OXutuWMk=; b=ogm5d+OaNwwwAbG787lUCQvMkL jc99GRrS1knW++uOrAV9CiNE4R37GwofC6rShRlRLk9XXJa1yL8apLiMnYJ6eiVeP8kgISUycP+8W DcuOQ4INKIhua8fDKvnNtxq4Iq6dH12H4dp0T5t3UPxGOiB20FgGLi+LG6QwUA8rAcvkZ1zmnA8cq nIsTI2h6NTXO3A2jx6cMR15tdFa40OrGy72fBwyOXG7C64qe4kPHIb3V4dt3edAvtFQlN7uDkDrOy JO3CgNKz/7rF01YOQP7GhIEv9LQBluY+FrUFgoAtNFedJvaCzv12gYjcKJhnBVuOp7OENsZVFr+6l cCwhlvJg==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEsk-0000000E2Ym-14xO; Wed, 30 Apr 2025 21:22:18 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org, Hannes Reinecke , Johannes Thumshirn Subject: [PATCH 06/19] block: pass the operation to bio_{map,copy}_kern Date: Wed, 30 Apr 2025 16:21:36 -0500 Message-ID: <20250430212159.2865803-7-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 That way the bio can be allocated with the right operation already set and there is no need to pass the separated 'reading' argument. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn --- block/blk-map.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index 0cbceb2671c9..ca6b55ac0da1 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -321,12 +321,14 @@ static void bio_map_kern_endio(struct bio *bio) * bio_map_kern - map kernel address into bio * @data: pointer to buffer to map * @len: length in bytes + * @op: bio/request operation * @gfp_mask: allocation flags for bio allocation * * Map the kernel address into a bio suitable for io to a block * device. Returns an error pointer in case of error. */ -static struct bio *bio_map_kern(void *data, unsigned int len, gfp_t gfp_mask) +static struct bio *bio_map_kern(void *data, unsigned int len, + enum req_op op, gfp_t gfp_mask) { unsigned long kaddr = (unsigned long)data; unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; @@ -340,7 +342,7 @@ static struct bio *bio_map_kern(void *data, unsigned int len, gfp_t gfp_mask) bio = bio_kmalloc(nr_pages, gfp_mask); if (!bio) return ERR_PTR(-ENOMEM); - bio_init(bio, NULL, bio->bi_inline_vecs, nr_pages, 0); + bio_init(bio, NULL, bio->bi_inline_vecs, nr_pages, op); if (is_vmalloc) { flush_kernel_vmap_range(data, len); @@ -402,14 +404,14 @@ static void bio_copy_kern_endio_read(struct bio *bio) * bio_copy_kern - copy kernel address into bio * @data: pointer to buffer to copy * @len: length in bytes + * @op: bio/request operation * @gfp_mask: allocation flags for bio and page allocation - * @reading: data direction is READ * * copy the kernel address into a bio suitable for io to a block * device. Returns an error pointer in case of error. */ -static struct bio *bio_copy_kern(void *data, unsigned int len, gfp_t gfp_mask, - int reading) +static struct bio *bio_copy_kern(void *data, unsigned int len, enum req_op op, + gfp_t gfp_mask) { unsigned long kaddr = (unsigned long)data; unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; @@ -428,7 +430,7 @@ static struct bio *bio_copy_kern(void *data, unsigned int len, gfp_t gfp_mask, bio = bio_kmalloc(nr_pages, gfp_mask); if (!bio) return ERR_PTR(-ENOMEM); - bio_init(bio, NULL, bio->bi_inline_vecs, nr_pages, 0); + bio_init(bio, NULL, bio->bi_inline_vecs, nr_pages, op); while (len) { struct page *page; @@ -441,7 +443,7 @@ static struct bio *bio_copy_kern(void *data, unsigned int len, gfp_t gfp_mask, if (!page) goto cleanup; - if (!reading) + if (op_is_write(op)) memcpy(page_address(page), p, bytes); if (bio_add_page(bio, page, bytes, 0) < bytes) @@ -451,11 +453,11 @@ static struct bio *bio_copy_kern(void *data, unsigned int len, gfp_t gfp_mask, p += bytes; } - if (reading) { + if (op_is_write(op)) { + bio->bi_end_io = bio_copy_kern_endio; + } else { bio->bi_end_io = bio_copy_kern_endio_read; bio->bi_private = data; - } else { - bio->bi_end_io = bio_copy_kern_endio; } return bio; @@ -699,7 +701,6 @@ EXPORT_SYMBOL(blk_rq_unmap_user); int blk_rq_map_kern(struct request *rq, void *kbuf, unsigned int len, gfp_t gfp_mask) { - int reading = rq_data_dir(rq) == READ; unsigned long addr = (unsigned long) kbuf; struct bio *bio; int ret; @@ -711,16 +712,13 @@ int blk_rq_map_kern(struct request *rq, void *kbuf, unsigned int len, if (!blk_rq_aligned(rq->q, addr, len) || object_is_on_stack(kbuf) || blk_queue_may_bounce(rq->q)) - bio = bio_copy_kern(kbuf, len, gfp_mask, reading); + bio = bio_copy_kern(kbuf, len, req_op(rq), gfp_mask); else - bio = bio_map_kern(kbuf, len, gfp_mask); + bio = bio_map_kern(kbuf, len, req_op(rq), gfp_mask); if (IS_ERR(bio)) return PTR_ERR(bio); - bio->bi_opf &= ~REQ_OP_MASK; - bio->bi_opf |= req_op(rq); - ret = blk_rq_append_bio(rq, bio); if (unlikely(ret)) { bio_uninit(bio); From patchwork Wed Apr 30 21:21:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886234 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 084CA2D110F; Wed, 30 Apr 2025 21:22:24 +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=1746048146; cv=none; b=OqIpqKRV5Wu3XFk8WRSHg/V3xneVPEnIcPSmtiv+PUFoQlFlj/zmYdRY6/JjvW2uhxxgVcBDenoqo3hKdtm8Jo0fGmitii2iK1xWs8Fj1E2a/inYQ+tOEKzXCN/n4AOxlu+hWXL3brIvCDeyG0CXBW/z7EgnmDPPWr5gknQDQo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048146; c=relaxed/simple; bh=uL+BGQKI+sn+LgrFgbd7Kl5Y6Gz/UibZg1d25jUGdQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L85X9r2saeg+17fKNA9ERZFHoXsJsmg9om1aO2vBqkWCmS3LEGHYDiS6BI6sdypX2b3uD+S5Z70ChZpCDLZHvQCWWdq6/rlgc4d/5eiFVs7JrAe2ryxametzj9tujS7K+3ClFpnkd7aiQV3F5uMX5LnfuhIadqHZbUic63jDUvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=aNc8KvNU; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="aNc8KvNU" 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=vMgZ4C1bKQgx5DFySXr3zeeqwMUuRYFSx6W6DnOMpK0=; b=aNc8KvNUYxCGNkJnpU1W8fnuYo iVnZ34zlQA5cbB9JVnGXCvn9KAIBmobkp4rVRZ33mvQ9M6US68nBHrfBefXGOK07/fCVw1XOIv49s zCPd5n4f99axHvXXDlhhzDSSaljjC3q7JVumd9npO+Nvv+wXfXfagvLN8vDnYJfG3zOr/nF7ZnKB3 bFGVQL9Hdes1a7ztDFvVXNVCIyBF3KdoQbx1ZWqwpdCAjhQOI9JdmjUOiJY1OhqS3ncJ3Nzox+G+i vwj+N0fnIC00ZlKPvLSXuRvd7y4JRyz7TjCd3yqdkVOUR7spK4k7ya2mq9QcXNJlC0ml/bHy83y4b L0NC0bqQ==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEsp-0000000E2aD-3Gq1; Wed, 30 Apr 2025 21:22:24 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 08/19] bcache: use bio_add_virt_nofail Date: Wed, 30 Apr 2025 16:21:38 -0500 Message-ID: <20250430212159.2865803-9-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Convert the __bio_add_page(..., virt_to_page(), ...) pattern to the bio_add_virt_nofail helper implementing it. Signed-off-by: Christoph Hellwig Acked-by: Coly Li Reviewed-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- drivers/md/bcache/super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 813b38aec3e4..c40db9c161c1 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -293,8 +293,7 @@ static void __write_super(struct cache_sb *sb, struct cache_sb_disk *out, bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_META; bio->bi_iter.bi_sector = SB_SECTOR; - __bio_add_page(bio, virt_to_page(out), SB_SIZE, - offset_in_page(out)); + bio_add_virt_nofail(bio, out, SB_SIZE); out->offset = cpu_to_le64(sb->offset); From patchwork Wed Apr 30 21:21:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886233 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 96B802D1116; Wed, 30 Apr 2025 21:22:30 +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=1746048152; cv=none; b=goqotgAF5ViHzXW3IjXgwBtuKZ0JbfQVVPq2h0fG1mzaWsgEtYjI+mWEDFEAFAjuWPxnuVv8tsEy4tAmqdTEM8Um1x0IYYEncu6h7ZZmA18CW0SgclDpKqikw1tNEh9EorjYTlFGFodUIpdz9aKlWUs1t2/b6UknSn8COKqMJFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048152; c=relaxed/simple; bh=wiIb0dwSxihC2tC0+I4bW6s6w1Jdrr7wjX7VsYNgCCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCdxNH+I47es7XrciwGaIxq4WwE60xOJxgwIFrPj+/M6/OssDcQzUspdX1EpmD2/GlCKco4JjkUW8QdjK/uPs59aQoXOkU6V5K0aGVbz2G5KjPRZPU3VazBAvKNyPCjACD5JWtdqeQbybHi1Wza/E4Jix66MDGaag34Y2lTBhUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=srkXYIKL; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="srkXYIKL" 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=BXRwU4K0o1tFolX8zTbu/pD8mnktNKiqmpCuV5KLDco=; b=srkXYIKLE6gXpqnM5GFYVYMYNW 0Cbx1bdz23hPnCHM1OAOdB79kp+Nc6IfjWtARYYAkZSOvRL8e0ZIvP5ML6pcvpI9KdAMmgUn9fTKN x1yTyQz4iEmmOEPv/1u3ckw0ll/Z6vBouGlXAqArHMlBLJULWIEH4UcuLtku88I1lTSrPOq58Vx+q eCwzJwEI7GGd+9r1Ts1QNj8o5CURhduofr/KLSfAIiO+rDcA/b/XFYwd76zkly53uUoY+9wJqDd+K y1+yhEhAzb/gJc79vM/Pah3FAopn6H0wRth4it12PTTbqCMKXpJ+IQrfQkJvwm/kF/LjRZ93tmLQm BreujAoQ==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEsv-0000000E2bq-1sKC; Wed, 30 Apr 2025 21:22:29 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 10/19] gfs2: use bdev_rw_virt in gfs2_read_super Date: Wed, 30 Apr 2025 16:21:40 -0500 Message-ID: <20250430212159.2865803-11-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Switch gfs2_read_super to allocate the superblock buffer using kmalloc which falls back to the page allocator for PAGE_SIZE allocation but gives us a kernel virtual address and then use bdev_rw_virt to perform the synchronous read into it. Signed-off-by: Christoph Hellwig Reviewed-by: Andreas Gruenbacher Reviewed-by: Damien Le Moal --- fs/gfs2/ops_fstype.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e83d293c3614..7c1014ba7ac7 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -226,28 +226,22 @@ static void gfs2_sb_in(struct gfs2_sbd *sdp, const struct gfs2_sb *str) static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector, int silent) { - struct super_block *sb = sdp->sd_vfs; - struct page *page; - struct bio_vec bvec; - struct bio bio; + struct gfs2_sb *sb; int err; - page = alloc_page(GFP_KERNEL); - if (unlikely(!page)) + sb = kmalloc(PAGE_SIZE, GFP_KERNEL); + if (unlikely(!sb)) return -ENOMEM; - - bio_init(&bio, sb->s_bdev, &bvec, 1, REQ_OP_READ | REQ_META); - bio.bi_iter.bi_sector = sector * (sb->s_blocksize >> 9); - __bio_add_page(&bio, page, PAGE_SIZE, 0); - - err = submit_bio_wait(&bio); + err = bdev_rw_virt(sdp->sd_vfs->s_bdev, + sector * (sdp->sd_vfs->s_blocksize >> 9), sb, PAGE_SIZE, + REQ_OP_READ | REQ_META); if (err) { pr_warn("error %d reading superblock\n", err); - __free_page(page); + kfree(sb); return err; } - gfs2_sb_in(sdp, page_address(page)); - __free_page(page); + gfs2_sb_in(sdp, sb); + kfree(sb); return gfs2_check_sb(sdp, silent); } From patchwork Wed Apr 30 21:21:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886232 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 A4C192D92C4; Wed, 30 Apr 2025 21:22:35 +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=1746048157; cv=none; b=ucAx3eQ/MA1TY+SjtAYD7VELIQzh/muUiRE6+gvMvgshjp8oKxzZZLUrT4Le2OXiKj4sD7CEq4TJKrzxx0vjfCBe4CvBnaTcqsxAKW5WaG0jexy3vYj1/5DUs59fTsn53JsIVXqeCquJSpFnRPakrD0kCU+NVf4CyCZkuIp7/hk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048157; c=relaxed/simple; bh=1EkPQHeKXR7i9jybvGIPIIgc2v0MA6KU7uEhEAZ/gFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EAIUX3aGlHVJB1EmNVxLcwA/qun8xL79si07nl8Yaj0YdsYhE4pgm6gIL3lak7/Lp83l/Ohh5iNAsO0dimfXd6t5K5BkbkDUBiWod2qmsUPy/v44D/RO+/c/QIHgQMqGJ/cRzNVePsFtOhJ0Ym5qlKI8pt4ARML1KC/8A4Bf1yA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=RU1NVJYR; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="RU1NVJYR" 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=JV2b2UVsHh3t2C6xfggPa7SRCmzaZGkBoBD20kRaJZ0=; b=RU1NVJYRkPfy5TmPKgFZnwl36T inp7WnZM2NFWx/5R75mYybMPiRzcZIJngkAY+l8A4H3Q0o+2PTSOJZffSV2L0TiphW1TFWNquI61Z YmnTEUSyCa1PeIIX5aWQ+MRHSqdDrM0LRqwd2P4qkHJEEBWD/beOQUXnSLWhEEyuqe5VinU5hlczd CTX8efvRVh70zVJgJVge1MU13xPcWvEIxgcM5QQajzSGVsqbxVfuo4gLWFjsv1iTx7vv39EI6RQuO 1ny55JHDLUYW0q2rQEGcrz2PzoqZFNcziaL1YXiNyvUsNwGI5ubUkavDLgKJdymGSfgziesckFtpy J27MT1Sw==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEt0-0000000E2dJ-2xhz; Wed, 30 Apr 2025 21:22:35 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 12/19] PM: hibernate: split and simplify hib_submit_io Date: Wed, 30 Apr 2025 16:21:42 -0500 Message-ID: <20250430212159.2865803-13-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Split hib_submit_io into a sync and async version. The sync version is a small wrapper around bdev_rw_virt which implements all the logic to add a kernel direct mapping range to a bio and synchronously submits it, while the async version is slightly simplified using the bio_add_virt_nofail for adding the single range. Signed-off-by: Christoph Hellwig Acked-by: Rafael J. Wysocki Reviewed-by: Damien Le Moal --- kernel/power/swap.c | 103 +++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 58 deletions(-) diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 80ff5f933a62..ad13c461b657 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -268,35 +268,26 @@ static void hib_end_io(struct bio *bio) bio_put(bio); } -static int hib_submit_io(blk_opf_t opf, pgoff_t page_off, void *addr, +static int hib_submit_io_sync(blk_opf_t opf, pgoff_t page_off, void *addr) +{ + return bdev_rw_virt(file_bdev(hib_resume_bdev_file), + page_off * (PAGE_SIZE >> 9), addr, PAGE_SIZE, opf); +} + +static int hib_submit_io_async(blk_opf_t opf, pgoff_t page_off, void *addr, struct hib_bio_batch *hb) { - struct page *page = virt_to_page(addr); struct bio *bio; - int error = 0; bio = bio_alloc(file_bdev(hib_resume_bdev_file), 1, opf, GFP_NOIO | __GFP_HIGH); bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9); - - if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { - pr_err("Adding page to bio failed at %llu\n", - (unsigned long long)bio->bi_iter.bi_sector); - bio_put(bio); - return -EFAULT; - } - - if (hb) { - bio->bi_end_io = hib_end_io; - bio->bi_private = hb; - atomic_inc(&hb->count); - submit_bio(bio); - } else { - error = submit_bio_wait(bio); - bio_put(bio); - } - - return error; + bio_add_virt_nofail(bio, addr, PAGE_SIZE); + bio->bi_end_io = hib_end_io; + bio->bi_private = hb; + atomic_inc(&hb->count); + submit_bio(bio); + return 0; } static int hib_wait_io(struct hib_bio_batch *hb) @@ -316,7 +307,7 @@ static int mark_swapfiles(struct swap_map_handle *handle, unsigned int flags) { int error; - hib_submit_io(REQ_OP_READ, swsusp_resume_block, swsusp_header, NULL); + hib_submit_io_sync(REQ_OP_READ, swsusp_resume_block, swsusp_header); if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) || !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) { memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10); @@ -329,8 +320,8 @@ static int mark_swapfiles(struct swap_map_handle *handle, unsigned int flags) swsusp_header->flags = flags; if (flags & SF_CRC32_MODE) swsusp_header->crc32 = handle->crc32; - error = hib_submit_io(REQ_OP_WRITE | REQ_SYNC, - swsusp_resume_block, swsusp_header, NULL); + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, + swsusp_resume_block, swsusp_header); } else { pr_err("Swap header not found!\n"); error = -ENODEV; @@ -380,36 +371,30 @@ static int swsusp_swap_check(void) static int write_page(void *buf, sector_t offset, struct hib_bio_batch *hb) { + gfp_t gfp = GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY; void *src; int ret; if (!offset) return -ENOSPC; - if (hb) { - src = (void *)__get_free_page(GFP_NOIO | __GFP_NOWARN | - __GFP_NORETRY); - if (src) { - copy_page(src, buf); - } else { - ret = hib_wait_io(hb); /* Free pages */ - if (ret) - return ret; - src = (void *)__get_free_page(GFP_NOIO | - __GFP_NOWARN | - __GFP_NORETRY); - if (src) { - copy_page(src, buf); - } else { - WARN_ON_ONCE(1); - hb = NULL; /* Go synchronous */ - src = buf; - } - } - } else { - src = buf; + if (!hb) + goto sync_io; + + src = (void *)__get_free_page(gfp); + if (!src) { + ret = hib_wait_io(hb); /* Free pages */ + if (ret) + return ret; + src = (void *)__get_free_page(gfp); + if (WARN_ON_ONCE(!src)) + goto sync_io; } - return hib_submit_io(REQ_OP_WRITE | REQ_SYNC, offset, src, hb); + + copy_page(src, buf); + return hib_submit_io_async(REQ_OP_WRITE | REQ_SYNC, offset, src, hb); +sync_io: + return hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, offset, buf); } static void release_swap_writer(struct swap_map_handle *handle) @@ -1041,7 +1026,7 @@ static int get_swap_reader(struct swap_map_handle *handle, return -ENOMEM; } - error = hib_submit_io(REQ_OP_READ, offset, tmp->map, NULL); + error = hib_submit_io_sync(REQ_OP_READ, offset, tmp->map); if (error) { release_swap_reader(handle); return error; @@ -1065,7 +1050,10 @@ static int swap_read_page(struct swap_map_handle *handle, void *buf, offset = handle->cur->entries[handle->k]; if (!offset) return -EFAULT; - error = hib_submit_io(REQ_OP_READ, offset, buf, hb); + if (hb) + error = hib_submit_io_async(REQ_OP_READ, offset, buf, hb); + else + error = hib_submit_io_sync(REQ_OP_READ, offset, buf); if (error) return error; if (++handle->k >= MAP_PAGE_ENTRIES) { @@ -1590,8 +1578,8 @@ int swsusp_check(bool exclusive) BLK_OPEN_READ, holder, NULL); if (!IS_ERR(hib_resume_bdev_file)) { clear_page(swsusp_header); - error = hib_submit_io(REQ_OP_READ, swsusp_resume_block, - swsusp_header, NULL); + error = hib_submit_io_sync(REQ_OP_READ, swsusp_resume_block, + swsusp_header); if (error) goto put; @@ -1599,9 +1587,9 @@ int swsusp_check(bool exclusive) memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); swsusp_header_flags = swsusp_header->flags; /* Reset swap signature now */ - error = hib_submit_io(REQ_OP_WRITE | REQ_SYNC, + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, swsusp_resume_block, - swsusp_header, NULL); + swsusp_header); } else { error = -EINVAL; } @@ -1650,13 +1638,12 @@ int swsusp_unmark(void) { int error; - hib_submit_io(REQ_OP_READ, swsusp_resume_block, - swsusp_header, NULL); + hib_submit_io_sync(REQ_OP_READ, swsusp_resume_block, swsusp_header); if (!memcmp(HIBERNATE_SIG,swsusp_header->sig, 10)) { memcpy(swsusp_header->sig,swsusp_header->orig_sig, 10); - error = hib_submit_io(REQ_OP_WRITE | REQ_SYNC, + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, swsusp_resume_block, - swsusp_header, NULL); + swsusp_header); } else { pr_err("Cannot find swsusp signature!\n"); error = -ENODEV; From patchwork Wed Apr 30 21:21:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886231 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 A08482D113C; Wed, 30 Apr 2025 21:22:42 +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=1746048164; cv=none; b=ihK5VbV6n/a/yqqdbB+Y6p8OVi9ZLGHFa1TopK1RvpcrYbnHypgwKW/YPUwbpDyyzai2CCg1YSLJn2DDU1phefu2wIr7b0Hi88NE0VJJYaKOHsJ5g9rZhgXGYq1uh6mFyRA1jakHp2vqGUkLTARkd0WOMJ9Ysa4tn5/8jI4NemM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048164; c=relaxed/simple; bh=FXG+2y5bQ1rQOtKfMSmRnkF0ZijmjwSO0CErR4Kongc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tipWVnzNg2iA/boWhqJgMHw4spD9H17z6gBh5+mPWXVRWe5EenSx/+ILKbs04qPRnCQfl0uPU0IS1czz0Rt4eGpbo54nSPnWRNUiRcdhF0WJsdAAcTNBflc/A0bwF2RyEDrsRnbiFLCNkpEuf7LVQdpJsJrmLKhTJRsU4X2TVbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=g5CNy8co; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="g5CNy8co" 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=07wgIKRHEvblml6CuFdXwRGvEIls4LekE5NjZesY+Yk=; b=g5CNy8coJBZ8bTwCOzWtK30nz0 Px2usCKz4eoihxbnGhpSyl07VhAPyg3cA8c65jxwuX/hqgSLXU2a8DfmNYn95zVYnTgoYTIttgAyR nwNTyj5Ah/zP6h455700aFDrT2vAOnFWtcX0mta0gVYtdkyTwBgCe+tpealsZDzYQcx+RoI9bP1Kv /Yn3GpUnu22AlNZSyPXj+7P/+lNNzHxmksoXCcT9rF8qF6ix0a6zxaE7G9TZdJa/qBsz8Y/jZsTP5 r8QaYOvI4oCIPUDgqQuRjh5V+4rOnzZAiwcq59RfKZw+FgDz8DdS2GNnBoElzyqYp3oawe/b+qFGe GSyQzctg==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEt7-0000000E2f9-29r0; Wed, 30 Apr 2025 21:22:42 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 14/19] dm-integrity: use bio_add_virt_nofail Date: Wed, 30 Apr 2025 16:21:44 -0500 Message-ID: <20250430212159.2865803-15-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Convert the __bio_add_page(..., virt_to_page(), ...) pattern to the bio_add_virt_nofail helper implementing it, and do the same for the similar pattern using bio_add_page for adding the first segment after a bio allocation as that can't fail either. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- drivers/md/dm-integrity.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 2a283feb3319..9dca9dbabfaa 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -2557,14 +2557,8 @@ static void dm_integrity_inline_recheck(struct work_struct *w) char *mem; outgoing_bio = bio_alloc_bioset(ic->dev->bdev, 1, REQ_OP_READ, GFP_NOIO, &ic->recheck_bios); - - r = bio_add_page(outgoing_bio, virt_to_page(outgoing_data), ic->sectors_per_block << SECTOR_SHIFT, 0); - if (unlikely(r != (ic->sectors_per_block << SECTOR_SHIFT))) { - bio_put(outgoing_bio); - bio->bi_status = BLK_STS_RESOURCE; - bio_endio(bio); - return; - } + bio_add_virt_nofail(outgoing_bio, outgoing_data, + ic->sectors_per_block << SECTOR_SHIFT); bip = bio_integrity_alloc(outgoing_bio, GFP_NOIO, 1); if (IS_ERR(bip)) { @@ -3211,7 +3205,8 @@ static void integrity_recalc_inline(struct work_struct *w) bio = bio_alloc_bioset(ic->dev->bdev, 1, REQ_OP_READ, GFP_NOIO, &ic->recalc_bios); bio->bi_iter.bi_sector = ic->start + SB_SECTORS + range.logical_sector; - __bio_add_page(bio, virt_to_page(recalc_buffer), range.n_sectors << SECTOR_SHIFT, offset_in_page(recalc_buffer)); + bio_add_virt_nofail(bio, recalc_buffer, + range.n_sectors << SECTOR_SHIFT); r = submit_bio_wait(bio); bio_put(bio); if (unlikely(r)) { @@ -3228,7 +3223,8 @@ static void integrity_recalc_inline(struct work_struct *w) bio = bio_alloc_bioset(ic->dev->bdev, 1, REQ_OP_WRITE, GFP_NOIO, &ic->recalc_bios); bio->bi_iter.bi_sector = ic->start + SB_SECTORS + range.logical_sector; - __bio_add_page(bio, virt_to_page(recalc_buffer), range.n_sectors << SECTOR_SHIFT, offset_in_page(recalc_buffer)); + bio_add_virt_nofail(bio, recalc_buffer, + range.n_sectors << SECTOR_SHIFT); bip = bio_integrity_alloc(bio, GFP_NOIO, 1); if (unlikely(IS_ERR(bip))) { From patchwork Wed Apr 30 21:21:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886230 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 361092D112D; Wed, 30 Apr 2025 21:22:48 +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=1746048170; cv=none; b=norQKWJR6EvtLyDjyBk0EJspPkHI8KYIdjZCdfeJ/C0cDUzlLKU5gGUryLe1LABDvylW5kLNveDPcNI8ZoqIRBbWtO9xvae+bnMrP13go0oNjuZOZcM940V4/Sb6o47yus3fD9yn6UqKJarKdX19BdVF2uDFRr9c1z6dq+51OFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048170; c=relaxed/simple; bh=LtXBRUPuKXCvrQCJzuviq7k/NwRQWMn9ZEy2/gHRtSI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ux2DeJ4Nc17QbO6YJt4G+KnPr5f2xQPSxCtWIKz5UE9SUezx8EjJAtGacyEdA1Z+/VPwJzAyOeLqYxMqpOOUD0tOED1L0EaXtckMohRkRAPWG8TawZU1eY9WpLCc75+V2BG+PBUeMXbFutSenfUWoBhnDIGfxofMvrIFm819RxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=BAvqWkJX; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="BAvqWkJX" 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=v/Mboo+M2hZh4JrgqAFccQLDjODq+hl95NoNxjdgzwY=; b=BAvqWkJXwkCqAsHNnO5L9CzcXR ZgxpPvAmqK3IXC5D+a97Mu2l4rfQNth/SpF22I/FbGpurqzNILxd2hNR2yGtftrN60mnKurTIi5Sq DDwcaFkQYHiBhpHkWf3KiZNWDTYHhEwknnyOpzDNW9Eo9IdKPEuKfGELJIRXAL7JLn5Xrq/vi+R1G sNLC6O1wdEiNCi2BDZTHZWDHNon9cJb3jf5gyWxhI/Vq0sCYnkMPfF84pWLoX0+wcdVLI1+rZTTXZ Gk4uCBvfrZFbh72oLiogbWz5Ga9NgHOsI9p6OP00OrjU8kOf2Czx45AUo3C08vtI+0lsnVpdDDG3T NWYoKGxg==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEtD-0000000E2hG-3Yjh; Wed, 30 Apr 2025 21:22:48 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org, "Darrick J. Wong" Subject: [PATCH 16/19] xfs: simplify xfs_rw_bdev Date: Wed, 30 Apr 2025 16:21:46 -0500 Message-ID: <20250430212159.2865803-17-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Delegate to bdev_rw_virt when operating on non-vmalloc memory and use bio_add_vmalloc_chunk to insulate xfs from the details of adding vmalloc memory to a bio. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_bio_io.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/fs/xfs/xfs_bio_io.c b/fs/xfs/xfs_bio_io.c index fe21c76f75b8..2a736d10eafb 100644 --- a/fs/xfs/xfs_bio_io.c +++ b/fs/xfs/xfs_bio_io.c @@ -18,42 +18,36 @@ xfs_rw_bdev( enum req_op op) { - unsigned int is_vmalloc = is_vmalloc_addr(data); - unsigned int left = count; + unsigned int done = 0, added; int error; struct bio *bio; - if (is_vmalloc && op == REQ_OP_WRITE) - flush_kernel_vmap_range(data, count); + op |= REQ_META | REQ_SYNC; + if (!is_vmalloc_addr(data)) + return bdev_rw_virt(bdev, sector, data, count, op); - bio = bio_alloc(bdev, bio_max_vecs(left), op | REQ_META | REQ_SYNC, - GFP_KERNEL); + bio = bio_alloc(bdev, bio_max_vecs(count), op, GFP_KERNEL); bio->bi_iter.bi_sector = sector; do { - struct page *page = kmem_to_page(data); - unsigned int off = offset_in_page(data); - unsigned int len = min_t(unsigned, left, PAGE_SIZE - off); - - while (bio_add_page(bio, page, len, off) != len) { + added = bio_add_vmalloc_chunk(bio, data + done, count - done); + if (!added) { struct bio *prev = bio; - bio = bio_alloc(prev->bi_bdev, bio_max_vecs(left), + bio = bio_alloc(prev->bi_bdev, + bio_max_vecs(count - done), prev->bi_opf, GFP_KERNEL); bio->bi_iter.bi_sector = bio_end_sector(prev); bio_chain(prev, bio); - submit_bio(prev); } - - data += len; - left -= len; - } while (left > 0); + done += added; + } while (done < count); error = submit_bio_wait(bio); bio_put(bio); - if (is_vmalloc && op == REQ_OP_READ) + if (op == REQ_OP_READ) invalidate_kernel_vmap_range(data, count); return error; } From patchwork Wed Apr 30 21:21:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 886229 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 EDE1B2D1933; Wed, 30 Apr 2025 21:22:55 +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=1746048177; cv=none; b=aIrQPVMdjJ+W68I5rIaz4L581/aDhu1Nk1+4uCH+lMHZYnKi1CasRevGOTz00HyAROw5vM6QRssvjlyuxY8cUYROod5mN4y2AK0wMDFvQI6DuWiCeYDUGbrgp2ogcOYNoc0DRspbvZIbp9v3H+FwQPxrkVS9yyCMzFI5QonFmyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746048177; c=relaxed/simple; bh=4MSdSK68drach5d5ViWzyrbkW+nuGMgyx/gaD6bR8mo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nzgF9Mc6NdudCuhXMpsKx1tUKwRPWgFa3mOxppgWJUcrJ+M7TGVWglG+2JeSjPExajGWmHzU6WSNAfxeOyqvproZ2nhdPMsuqkgBR8EC1f40nIwbb50csApT4ODYF7S7mTv07GGOv+/wX59KcSPAf+kdjc8Ewusnhl7n2kzvmMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (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=qVPXnh3n; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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="qVPXnh3n" 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=NHhxO3wQrG8+HzurNRbsetmShFZ/Fx2USFtUoBxxpZY=; b=qVPXnh3nLUIywhqxsV8c0FTyKW CkBvJkyUVehofsbXnQBo58dDHJekYIpIHEUON7yIszqN+6JsTyhdlBbWyVyJ39by5/d2B6jaP311l TDLQpldeWu+dZFpartIglqzgOLzaz7Go8AOb2hkfYv2SzVU4EVZSm2aKLza6ivyLc3+S07r4VvPXc pME6zioBJxrOWFw0tt9LP8YV6acnpkHoYkSjy9hP99rLgm85+MUQlx9NUCnH0DGN/OB+mUwOdtOzQ ADfYfIqfOXuInGWgFOrKcHaJjmK6Dhd4tGt8/++FZy6I/r+OneoruLoRO8NrX31VER4z5ppc4+xAl Uk4LxItg==; Received: from [206.0.71.65] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAEtK-0000000E2jO-28aU; Wed, 30 Apr 2025 21:22:55 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org, "Md. Haris Iqbal" , Jack Wang , Coly Li , Kent Overstreet , Mike Snitzer , Mikulas Patocka , Chris Mason , Josef Bacik , David Sterba , Andreas Gruenbacher , Carlos Maiolino , Damien Le Moal , Naohiro Aota , Johannes Thumshirn , "Rafael J. Wysocki" , Pavel Machek , slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-btrfs@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org, Johannes Thumshirn , Qu Wenruo Subject: [PATCH 18/19] btrfs: use bdev_rw_virt in scrub_one_super Date: Wed, 30 Apr 2025 16:21:48 -0500 Message-ID: <20250430212159.2865803-19-hch@lst.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250430212159.2865803-1-hch@lst.de> References: <20250430212159.2865803-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-pm@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 Replace the code building a bio from a kernel direct map address and submitting it synchronously with the bdev_rw_virt helper. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/scrub.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 2c5edcee9450..7bdb2bc0a212 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2770,17 +2770,11 @@ static int scrub_one_super(struct scrub_ctx *sctx, struct btrfs_device *dev, struct page *page, u64 physical, u64 generation) { struct btrfs_fs_info *fs_info = sctx->fs_info; - struct bio_vec bvec; - struct bio bio; struct btrfs_super_block *sb = page_address(page); int ret; - bio_init(&bio, dev->bdev, &bvec, 1, REQ_OP_READ); - bio.bi_iter.bi_sector = physical >> SECTOR_SHIFT; - __bio_add_page(&bio, page, BTRFS_SUPER_INFO_SIZE, 0); - ret = submit_bio_wait(&bio); - bio_uninit(&bio); - + ret = bdev_rw_virt(dev->bdev, physical >> SECTOR_SHIFT, sb, + BTRFS_SUPER_INFO_SIZE, REQ_OP_READ); if (ret < 0) return ret; ret = btrfs_check_super_csum(fs_info, sb);