lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230510084657epcms2p69b0c426899251151a5cc7d84cedeacc7@epcms2p6>
Date:   Wed, 10 May 2023 17:46:57 +0900
From:   Jinyoung CHOI <j-young.choi@...sung.com>
To:     Jinyoung CHOI <j-young.choi@...sung.com>,
        "axboe@...nel.dk" <axboe@...nel.dk>,
        "kbusch@...nel.org" <kbusch@...nel.org>, "hch@....de" <hch@....de>,
        "sagi@...mberg.me" <sagi@...mberg.me>,
        "jejb@...ux.ibm.com" <jejb@...ux.ibm.com>,
        "martin.petersen@...cle.com" <martin.petersen@...cle.com>,
        "johannes.thumshirn@....com" <johannes.thumshirn@....com>,
        "kch@...dia.com" <kch@...dia.com>,
        "willy@...radead.org" <willy@...radead.org>,
        "linux-block@...r.kernel.org" <linux-block@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH v2 01/14] block: bio: separation to reuse a part of the
 function

__bio_try_merge_page(), which is called by the general page-add functions
and the function considering the constraints of hw, was separated.

Condition tests for general page-add functions were performed in
bio_try_merge_page(). And when the parameters of __bio_try_merge_page()
were changed, there were fewer functions affected by this.

Cc: Christoph Hellwig <hch@....de>
Cc: Martin K. Petersen <martin.petersen@...cle.com>

Signed-off-by: Jinyoung Choi <j-young.choi@...sung.com>
---
 block/bio.c | 49 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index fd11614bba4d..1be17dea603a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -926,8 +926,28 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
 	return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
 }
 
+static bool __bio_try_merge_page(struct bio *bio, struct page *page,
+				 unsigned int len, unsigned int off,
+				 bool *same_page)
+{
+	struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
+
+	if (!page_is_mergeable(bv, page, len, off, same_page))
+		return false;
+
+	if (bio->bi_iter.bi_size > UINT_MAX - len) {
+		*same_page = false;
+		return false;
+	}
+
+	bv->bv_len += len;
+	bio->bi_iter.bi_size += len;
+
+	return true;
+}
+
 /**
- * __bio_try_merge_page - try appending data to an existing bvec.
+ * bio_try_merge_page - try appending data to an existing bvec.
  * @bio: destination bio
  * @page: start page to add
  * @len: length of the data to add
@@ -942,26 +962,17 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
  *
  * Return %true on success or %false on failure.
  */
-static bool __bio_try_merge_page(struct bio *bio, struct page *page,
-		unsigned int len, unsigned int off, bool *same_page)
+static bool bio_try_merge_page(struct bio *bio, struct page *page,
+			       unsigned int len, unsigned int off,
+			       bool *same_page)
 {
 	if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
 		return false;
 
-	if (bio->bi_vcnt > 0) {
-		struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
-
-		if (page_is_mergeable(bv, page, len, off, same_page)) {
-			if (bio->bi_iter.bi_size > UINT_MAX - len) {
-				*same_page = false;
-				return false;
-			}
-			bv->bv_len += len;
-			bio->bi_iter.bi_size += len;
-			return true;
-		}
-	}
-	return false;
+	if (!bio->bi_vcnt)
+		return false;
+
+	return __bio_try_merge_page(bio, page, len, off, same_page);
 }
 
 /*
@@ -1129,7 +1140,7 @@ int bio_add_page(struct bio *bio, struct page *page,
 {
 	bool same_page = false;
 
-	if (!__bio_try_merge_page(bio, page, len, offset, &same_page)) {
+	if (!bio_try_merge_page(bio, page, len, offset, &same_page)) {
 		if (bio_full(bio, len))
 			return 0;
 		__bio_add_page(bio, page, len, offset);
@@ -1199,7 +1210,7 @@ static int bio_iov_add_page(struct bio *bio, struct page *page,
 {
 	bool same_page = false;
 
-	if (!__bio_try_merge_page(bio, page, len, offset, &same_page)) {
+	if (!bio_try_merge_page(bio, page, len, offset, &same_page)) {
 		__bio_add_page(bio, page, len, offset);
 		return 0;
 	}
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ