From nobody Mon Jun 8 14:36:13 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 1B1964028CC; Thu, 28 May 2026 17:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779991157; cv=none; b=HOdX1xVH6NBSwzfa+H0oQVQNz3n0wp5WglwVN2qm7O04aY33pm/szATmZ2X3fctsidLsaQRTLVJ0gkhwY33IIgxFRIiIbDPNcqfjr49tIdWWXV33WJ2WFD2Qil0VbEBhh3sEm3W2gC2TZ2tcLhcV44zTJEmke+3It3rwXCIWpiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779991157; c=relaxed/simple; bh=HWnwdvN+wH0BNDOr5PiWKCj6j16psryRcs0rHbe8jV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FtoTu4seZieGxV+B01lac9c/4ZEB7YUYHLevDJGf+kV13a9CZnpbkzRDOTIGZaLqOv2/y7/vekfOiuMFLoC3/8q1BwNPfqUCtFq6BJhDjcvYbxwlLqYyzWRu5A+ymA/sUonmYrnT8CS03e7v1wycuiSstMrmaYMCSVnaFdc98pQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=LxLOs6Ov; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LxLOs6Ov" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=00eqepaCtdAWu+DT6W6K8Woolj1q8dfZ4GLsgZojTfU=; b=LxLOs6Ov5lZ1U5Xru94afj9U9t PJL/TdKDYOWmG/W183u33w3lX2ScLoLLWmYvgRywVOH7ba+BYVC/K3wV4aME5maSdLI3puQCo0n/u npWsniY14pov3dOUQuhEU+7dEY8RgL+hTxmseN4qNOsjMfY4ZiHEQr4dSYi2kcbE2DbamsS88ptkZ HJOAw+ReE+LcCye1BMN2T5ZYVqsTsftZ6EMmMdcSRrYJHoC8PPlylMxT9wgT2qOtV1Z9S6i72ds+s 1zm4CaNYV9URu7imarFFRFQPtyWp5DXpz71Ueb5+ERrYUkuaEX4q/QzHJnpC6nwo34LWrWlHbmfW8 SAkN2pDg==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wSf0d-00000004clb-2Ub7; Thu, 28 May 2026 17:59:07 +0000 From: "Matthew Wilcox (Oracle)" To: Jens Axboe Cc: "Matthew Wilcox (Oracle)" , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, linux-mm@kvack.org, Leon Romanovsky , Christoph Hellwig Subject: [PATCH v2 1/2] block: Add bvec_folio() Date: Thu, 28 May 2026 18:59:03 +0100 Message-ID: <20260528175905.1102280-2-willy@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260528175905.1102280-1-willy@infradead.org> References: <20260528175905.1102280-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is a simple helper which replaces page_folio(bvec->bv_page). Minor improvement in readability, but the real motivation is to reduce the number of references to bvec->bv_page so that it can be changed with less work. Signed-off-by: Matthew Wilcox (Oracle) Cc: Leon Romanovsky Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Reviewed-by: William Kucharski --- block/bio.c | 6 +++--- include/linux/bio.h | 2 +- include/linux/bvec.h | 15 +++++++++++++++ io_uring/rsrc.c | 2 +- mm/page_io.c | 4 ++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/block/bio.c b/block/bio.c index 5f10900b3f42..85aab3140909 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1300,7 +1300,7 @@ static void bio_free_folios(struct bio *bio) int i; =20 bio_for_each_bvec_all(bv, bio, i) { - struct folio *folio =3D page_folio(bv->bv_page); + struct folio *folio =3D bvec_folio(bv); =20 if (!is_zero_folio(folio)) folio_put(folio); @@ -1409,7 +1409,7 @@ int bio_iov_iter_bounce(struct bio *bio, struct iov_i= ter *iter, size_t maxlen, =20 static void bvec_unpin(struct bio_vec *bv, bool mark_dirty) { - struct folio *folio =3D page_folio(bv->bv_page); + struct folio *folio =3D bvec_folio(bv); size_t nr_pages =3D (bv->bv_offset + bv->bv_len - 1) / PAGE_SIZE - bv->bv_offset / PAGE_SIZE + 1; =20 @@ -1443,7 +1443,7 @@ static void bio_iov_iter_unbounce_read(struct bio *bi= o, bool is_error, bvec_unpin(&bio->bi_io_vec[1 + i], mark_dirty); } =20 - folio_put(page_folio(bio->bi_io_vec[0].bv_page)); + folio_put(bvec_folio(&bio->bi_io_vec[0])); } =20 /** diff --git a/include/linux/bio.h b/include/linux/bio.h index dc17780d6c1e..6613ab4519bd 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -283,7 +283,7 @@ static inline void bio_first_folio(struct folio_iter *f= i, struct bio *bio, return; } =20 - fi->folio =3D page_folio(bvec->bv_page); + fi->folio =3D bvec_folio(bvec); fi->offset =3D bvec->bv_offset + PAGE_SIZE * folio_page_idx(fi->folio, bvec->bv_page); fi->_seg_count =3D bvec->bv_len; diff --git a/include/linux/bvec.h b/include/linux/bvec.h index d36dd476feda..27ac3fcc6d9e 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -74,6 +74,21 @@ static inline void bvec_set_virt(struct bio_vec *bv, voi= d *vaddr, bvec_set_page(bv, virt_to_page(vaddr), len, offset_in_page(vaddr)); } =20 +/** + * bvec_folio - Return the first folio referenced by this bvec + * @bv: bvec to access + * + * A bvec can contain non-folio memory, so this should only be called by + * the creator of the bvec; drivers have no business looking at the owner + * of the memory. It may not even be the right interface for the caller + * to use as a bvec can span multiple folios. You may be better off using + * something like bio_for_each_folio_all() which iterates over all folios. + */ +static inline struct folio *bvec_folio(const struct bio_vec *bv) +{ + return page_folio(bv->bv_page); +} + struct bvec_iter { /* * Current device address in 512 byte sectors. Only updated by the bio diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index 650303626be6..5d792f70ec1e 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -102,7 +102,7 @@ static void io_release_ubuf(void *priv) unsigned int i; =20 for (i =3D 0; i < imu->nr_bvecs; i++) { - struct folio *folio =3D page_folio(imu->bvec[i].bv_page); + struct folio *folio =3D bvec_folio(&imu->bvec[i]); =20 unpin_user_folio(folio, 1); } diff --git a/mm/page_io.c b/mm/page_io.c index 70cea9e24d2f..a59b73f8bdd9 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -490,7 +490,7 @@ static void sio_read_complete(struct kiocb *iocb, long = ret) =20 if (ret =3D=3D sio->len) { for (p =3D 0; p < sio->pages; p++) { - struct folio *folio =3D page_folio(sio->bvec[p].bv_page); + struct folio *folio =3D bvec_folio(&sio->bvec[p]); =20 count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN); count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio)); @@ -500,7 +500,7 @@ static void sio_read_complete(struct kiocb *iocb, long = ret) count_vm_events(PSWPIN, sio->len >> PAGE_SHIFT); } else { for (p =3D 0; p < sio->pages; p++) { - struct folio *folio =3D page_folio(sio->bvec[p].bv_page); + struct folio *folio =3D bvec_folio(&sio->bvec[p]); =20 folio_unlock(folio); } --=20 2.47.3 From nobody Mon Jun 8 14:36:13 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 1BCA43FFAAA; Thu, 28 May 2026 17:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779991154; cv=none; b=f4AcKau5ph5PR8Ap7/b0fnB5en2Q8mpA+fyRyu5dkVHsJuGuAsX/x8FvXJTrtrSSirrR/MN/29pS6S9wsn9FXpSGV4BhgJNSlmc9TcxdgK3RM4mB+qTzjH3YBn145QHt/UI2pR8CT+4pUCw3dtgNCpL1+wvm5J1WplXJZU4CuEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779991154; c=relaxed/simple; bh=B5+iiubFY2WySZ4DjiX1w5VwrGkgnT9zl5grrfROc+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GQWboiltZiaMPY1ey8yqu9u0YNmzx6EMpJjafUnVtMe3v0TlR2ICYQQnh6YOcOjX9LgRkCpOZnrhND5TX3TfWNwyfb1JXyTNPX5FqGpBluNsQjReQcloncNns8/gEf4TmQ+tLsm1BcdSphKzkO4mEW5v+al/nhtLTMEDtwfUg4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=FYkUfT7g; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FYkUfT7g" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=EGVmzaNcu/49E2fMbgScKw5kBNsfavLbAhlmVlLSNus=; b=FYkUfT7g4UMygsRy00AFaFX47s kjEQozDyEE80XVE63jF3gPUMIHTC/IJYHb9NkibfKWXnGXdHHCyDOGrJXjaOtTHtFWY6pR3foOPdn 3PP/4eEbtWxBZqtRXs8JRP5jzg6YnLf50adQ11TjweGHEbwbAX1NogA6502huvXX/OtuCKOFWEyjr i3gdFQtlXf4WkiYlKaae0B+J8CL0lqITx3OQ6LJepVLv5sJjEhV8VkqWyweHUslKDAtNMhkAkyOEe XmNphA6bjaJPlXirk5sCqqWhFyqWXVpjl5iDRtAbuhvGaR5RN+L96WdJuwJeBRwZc4EWqIX/+PIRf U5AcLsiw==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wSf0d-00000004cld-2uYw; Thu, 28 May 2026 17:59:07 +0000 From: "Matthew Wilcox (Oracle)" To: Jens Axboe Cc: "Matthew Wilcox (Oracle)" , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, linux-mm@kvack.org, Leon Romanovsky , Christoph Hellwig Subject: [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs Date: Thu, 28 May 2026 18:59:04 +0100 Message-ID: <20260528175905.1102280-3-willy@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260528175905.1102280-1-willy@infradead.org> References: <20260528175905.1102280-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" People have gone to the trouble of writing this kernel-doc; the least we can do is publish it. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Reviewed-by: William Kucharski --- Documentation/core-api/kernel-api.rst | 1 + include/linux/bvec.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api= /kernel-api.rst index e8211c4ca662..4c4a57c1c094 100644 --- a/Documentation/core-api/kernel-api.rst +++ b/Documentation/core-api/kernel-api.rst @@ -307,6 +307,7 @@ Accounting Framework Block Devices =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +.. kernel-doc:: include/linux/bvec.h .. kernel-doc:: include/linux/bio.h .. kernel-doc:: block/blk-core.c :export: diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 27ac3fcc6d9e..09d6bb76919e 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -262,6 +262,7 @@ static inline void *bvec_kmap_local(struct bio_vec *bve= c) =20 /** * memcpy_from_bvec - copy data from a bvec + * @to: Kernel virtual address to copy to. * @bvec: bvec to copy from * * Must be called on single-page bvecs only. @@ -274,6 +275,7 @@ static inline void memcpy_from_bvec(char *to, struct bi= o_vec *bvec) /** * memcpy_to_bvec - copy data to a bvec * @bvec: bvec to copy to + * @from: Kernel virtual address to copy from. * * Must be called on single-page bvecs only. */ --=20 2.47.3