public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: Christoph Hellwig <hch@infradead.org>,
	Stephan Wurm <stephan.wurm@a-eberle.de>,
	Richard Weinberger <richard@nod.at>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Oliver Neukum <oliver@neukum.org>, Ali Akcaagac <aliakc@web.de>,
	Jamie Lenehan <lenehan@twibble.org>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: [PATCH 6/7] ubi: block: Switch to kmap_sg
Date: Thu, 10 Aug 2023 18:00:17 +0200	[thread overview]
Message-ID: <20230810160019.16977-7-richard@nod.at> (raw)
In-Reply-To: <20230810160019.16977-1-richard@nod.at>

Remove our copy of scsi_kmap_atomic_sg() and use the new helper
kmap_sg(). Since it is based on kmap_local() we can remove the
bounce buffer and perform IO while we hold the mapping.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/eba.c | 59 +++++--------------------------------------
 1 file changed, 6 insertions(+), 53 deletions(-)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 82c54bf7c2067..650eacab27f03 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -731,44 +731,6 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
 	return err;
 }
 
-/*
- * Basically a copy of scsi_kmap_atomic_sg().
- * As long scsi_kmap_atomic_sg() is not part of lib/scatterlist.c have
- * our own version to avoid a dependency on CONFIG_SCSI.
- */
-static void *ubi_kmap_atomic_sg(struct scatterlist *sgl, int sg_count,
-			  size_t *offset, size_t *len)
-{
-	int i;
-	size_t sg_len = 0, len_complete = 0;
-	struct scatterlist *sg;
-	struct page *page;
-
-	for_each_sg(sgl, sg, sg_count, i) {
-		len_complete = sg_len; /* Complete sg-entries */
-		sg_len += sg->length;
-		if (sg_len > *offset)
-			break;
-	}
-
-	if (WARN_ON_ONCE(i == sg_count))
-		return NULL;
-
-	/* Offset starting from the beginning of first page in this sg-entry */
-	*offset = *offset - len_complete + sg->offset;
-
-	/* Assumption: contiguous pages can be accessed as "page + i" */
-	page = nth_page(sg_page(sg), (*offset >> PAGE_SHIFT));
-	*offset &= ~PAGE_MASK;
-
-	/* Bytes in this sg-entry from *offset to the end of the page */
-	sg_len = PAGE_SIZE - *offset;
-	if (*len > sg_len)
-		*len = sg_len;
-
-	return kmap_atomic(page);
-}
-
 /**
  * ubi_eba_read_leb_sg - read data into a scatter gather list.
  * @ubi: UBI device description object
@@ -789,17 +751,6 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol,
 {
 	size_t map_len, map_offset, cur_offset;
 	int ret, to_read = len;
-	char *bounce_buf;
-
-	bounce_buf = kvmalloc(to_read, GFP_KERNEL);
-	if (!bounce_buf) {
-		ret = -ENOMEM;
-		goto out;
-	}
-
-	ret = ubi_eba_read_leb(ubi, vol, lnum, bounce_buf, offset, to_read, check);
-	if (ret < 0)
-		goto out;
 
 	cur_offset = 0;
 	while (to_read > 0) {
@@ -808,9 +759,12 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol,
 		map_len = to_read;
 		map_offset = cur_offset + sgl->tot_offset;
 
-		dst = ubi_kmap_atomic_sg(sgl->sg, sgl->len, &map_offset, &map_len);
-		memcpy(dst + map_offset, bounce_buf + cur_offset, map_len);
-		kunmap_atomic(dst);
+		dst = kmap_sg(sgl->sg, sgl->len, &map_offset, &map_len);
+		ret = ubi_eba_read_leb(ubi, vol, lnum, dst + map_offset, offset + cur_offset,
+				       map_len, check);
+		if (ret < 0)
+			goto out;
+		kunmap_sg(dst);
 
 		cur_offset += map_len;
 		to_read -= map_len;
@@ -818,7 +772,6 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol,
 
 	ret = 0;
 out:
-	kvfree(bounce_buf);
 	return ret;
 }
 
-- 
2.35.3


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2023-08-10 16:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-10 16:00 [PATCH 0/7] Fix UBI Block wrt. highmem Richard Weinberger
2023-08-10 16:00 ` [PATCH 1/7] ubi: block: Refactor sg list processing for highmem Richard Weinberger
2023-08-10 16:06   ` Christoph Hellwig
2023-08-10 16:15     ` Richard Weinberger
2023-08-10 16:21       ` Christoph Hellwig
2023-08-10 19:54         ` Richard Weinberger
2023-08-11  8:12           ` Christoph Hellwig
2023-08-11  8:34             ` Richard Weinberger
2023-08-11  8:36               ` Christoph Hellwig
2023-08-10 16:00 ` [PATCH 2/7] scatterlist: Add kmap helpers Richard Weinberger
2023-08-10 16:00 ` [PATCH 3/7] scsi: dc395x: Switch to kmap_sg Richard Weinberger
2023-08-10 16:00 ` [PATCH 4/7] scsi: esp_scsi: " Richard Weinberger
2023-08-10 16:00 ` [PATCH 5/7] scsi: fdomain: " Richard Weinberger
2023-08-10 16:00 ` Richard Weinberger [this message]
2023-08-10 16:00 ` [PATCH 7/7] scsi: core: Remove scsi_kmap_atomic_sg() Richard Weinberger
2023-08-11  5:52 ` [PATCH 0/7] Fix UBI Block wrt. highmem Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230810160019.16977-7-richard@nod.at \
    --to=richard@nod.at \
    --cc=aliakc@web.de \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=hch@infradead.org \
    --cc=jejb@linux.ibm.com \
    --cc=lenehan@twibble.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=oliver@neukum.org \
    --cc=stephan.wurm@a-eberle.de \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox