Skip to content

Commit 3b46495

Browse files
committed
lib/scatterlist: Add SG_MITER_LOCAL and use it
JIRA: https://issues.redhat.com/browse/RHEL-116573 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit fc8d5bb Author: Herbert Xu <herbert@gondor.apana.org.au> Date: Thu Mar 13 13:14:53 2025 +0800 lib/scatterlist: Add SG_MITER_LOCAL and use it Add kmap_local support to the scatterlist iterator. Use it for all the helper functions in lib/scatterlist. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Eder Zulian <ezulian@redhat.com>
1 parent 202c6d0 commit 3b46495

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/linux/scatterlist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ sg_page_iter_dma_address(struct sg_dma_page_iter *dma_iter)
692692
#define SG_MITER_ATOMIC (1 << 0) /* use kmap_atomic */
693693
#define SG_MITER_TO_SG (1 << 1) /* flush back to phys on unmap */
694694
#define SG_MITER_FROM_SG (1 << 2) /* nop */
695+
#define SG_MITER_LOCAL (1 << 3) /* use kmap_local */
695696

696697
struct sg_mapping_iter {
697698
/* the following three fields can be accessed directly */

lib/scatterlist.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ EXPORT_SYMBOL(sg_miter_skip);
856856
* @miter->addr and @miter->length point to the current mapping.
857857
*
858858
* Context:
859-
* May sleep if !SG_MITER_ATOMIC.
859+
* May sleep if !SG_MITER_ATOMIC && !SG_MITER_LOCAL.
860860
*
861861
* Returns:
862862
* true if @miter contains the next mapping. false if end of sg
@@ -878,6 +878,8 @@ bool sg_miter_next(struct sg_mapping_iter *miter)
878878

879879
if (miter->__flags & SG_MITER_ATOMIC)
880880
miter->addr = kmap_atomic(miter->page) + miter->__offset;
881+
else if (miter->__flags & SG_MITER_LOCAL)
882+
miter->addr = kmap_local_page(miter->page) + miter->__offset;
881883
else
882884
miter->addr = kmap(miter->page) + miter->__offset;
883885

@@ -913,7 +915,9 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
913915
if (miter->__flags & SG_MITER_ATOMIC) {
914916
WARN_ON_ONCE(!pagefault_disabled());
915917
kunmap_atomic(miter->addr);
916-
} else
918+
} else if (miter->__flags & SG_MITER_LOCAL)
919+
kunmap_local(miter->addr);
920+
else
917921
kunmap(miter->page);
918922

919923
miter->page = NULL;
@@ -942,7 +946,7 @@ size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, void *buf,
942946
{
943947
unsigned int offset = 0;
944948
struct sg_mapping_iter miter;
945-
unsigned int sg_flags = SG_MITER_ATOMIC;
949+
unsigned int sg_flags = SG_MITER_LOCAL;
946950

947951
if (to_buffer)
948952
sg_flags |= SG_MITER_FROM_SG;
@@ -1057,7 +1061,7 @@ size_t sg_zero_buffer(struct scatterlist *sgl, unsigned int nents,
10571061
{
10581062
unsigned int offset = 0;
10591063
struct sg_mapping_iter miter;
1060-
unsigned int sg_flags = SG_MITER_ATOMIC | SG_MITER_TO_SG;
1064+
unsigned int sg_flags = SG_MITER_LOCAL | SG_MITER_TO_SG;
10611065

10621066
sg_miter_start(&miter, sgl, nents, sg_flags);
10631067

0 commit comments

Comments
 (0)