mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drivers/nvdimm: Use local kmaps
@ 2025-11-28 21:23 Davidlohr Bueso
  2025-12-04 15:32 ` Dave Jiang
  2026-01-12 23:10 ` Ira Weiny
  0 siblings, 2 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2025-11-28 21:23 UTC (permalink / raw)
  To: vishal.l.verma, dan.j.williams, dave.jiang, ira.weiny
  Cc: nvdimm, linux-kernel, Davidlohr Bueso

Replace the now deprecated kmap_atomic() with kmap_local_page().

Optimizing nvdimm/pmem for highmem makes no sense as this is always
64bit, and the mapped regions for both btt and pmem do not require
disabling preemption and pagefaults. Specifically, kmap does not care
about the caller's atomic context (such as reads holding the btt arena
spinlock) or NVDIMM_IO_ATOMIC semantics to avoid error handling when
accessing the btt arena in general. Same for the memcpy cases. kmap
local temporary mappings will hold valid across any context switches.

Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
 drivers/nvdimm/btt.c  | 12 ++++++------
 drivers/nvdimm/pmem.c |  8 ++++----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index a933db961ed7..237edfa1c624 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -1104,10 +1104,10 @@ static int btt_data_read(struct arena_info *arena, struct page *page,
 {
 	int ret;
 	u64 nsoff = to_namespace_offset(arena, lba);
-	void *mem = kmap_atomic(page);
+	void *mem = kmap_local_page(page);
 
 	ret = arena_read_bytes(arena, nsoff, mem + off, len, NVDIMM_IO_ATOMIC);
-	kunmap_atomic(mem);
+	kunmap_local(mem);
 
 	return ret;
 }
@@ -1117,20 +1117,20 @@ static int btt_data_write(struct arena_info *arena, u32 lba,
 {
 	int ret;
 	u64 nsoff = to_namespace_offset(arena, lba);
-	void *mem = kmap_atomic(page);
+	void *mem = kmap_local_page(page);
 
 	ret = arena_write_bytes(arena, nsoff, mem + off, len, NVDIMM_IO_ATOMIC);
-	kunmap_atomic(mem);
+	kunmap_local(mem);
 
 	return ret;
 }
 
 static void zero_fill_data(struct page *page, unsigned int off, u32 len)
 {
-	void *mem = kmap_atomic(page);
+	void *mem = kmap_local_page(page);
 
 	memset(mem + off, 0, len);
-	kunmap_atomic(mem);
+	kunmap_local(mem);
 }
 
 #ifdef CONFIG_BLK_DEV_INTEGRITY
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 05785ff21a8b..92c67fbbc1c8 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -128,10 +128,10 @@ static void write_pmem(void *pmem_addr, struct page *page,
 	void *mem;
 
 	while (len) {
-		mem = kmap_atomic(page);
+		mem = kmap_local_page(page);
 		chunk = min_t(unsigned int, len, PAGE_SIZE - off);
 		memcpy_flushcache(pmem_addr, mem + off, chunk);
-		kunmap_atomic(mem);
+		kunmap_local(mem);
 		len -= chunk;
 		off = 0;
 		page++;
@@ -147,10 +147,10 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
 	void *mem;
 
 	while (len) {
-		mem = kmap_atomic(page);
+		mem = kmap_local_page(page);
 		chunk = min_t(unsigned int, len, PAGE_SIZE - off);
 		rem = copy_mc_to_kernel(mem + off, pmem_addr, chunk);
-		kunmap_atomic(mem);
+		kunmap_local(mem);
 		if (rem)
 			return BLK_STS_IOERR;
 		len -= chunk;
-- 
2.39.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/nvdimm: Use local kmaps
  2025-11-28 21:23 [PATCH] drivers/nvdimm: Use local kmaps Davidlohr Bueso
@ 2025-12-04 15:32 ` Dave Jiang
  2026-01-12 23:10 ` Ira Weiny
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Jiang @ 2025-12-04 15:32 UTC (permalink / raw)
  To: Davidlohr Bueso, vishal.l.verma, dan.j.williams, ira.weiny
  Cc: nvdimm, linux-kernel



On 11/28/25 2:23 PM, Davidlohr Bueso wrote:
> Replace the now deprecated kmap_atomic() with kmap_local_page().
> 
> Optimizing nvdimm/pmem for highmem makes no sense as this is always
> 64bit, and the mapped regions for both btt and pmem do not require
> disabling preemption and pagefaults. Specifically, kmap does not care
> about the caller's atomic context (such as reads holding the btt arena
> spinlock) or NVDIMM_IO_ATOMIC semantics to avoid error handling when
> accessing the btt arena in general. Same for the memcpy cases. kmap
> local temporary mappings will hold valid across any context switches.
> 
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>> ---
>  drivers/nvdimm/btt.c  | 12 ++++++------
>  drivers/nvdimm/pmem.c |  8 ++++----
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
> index a933db961ed7..237edfa1c624 100644
> --- a/drivers/nvdimm/btt.c
> +++ b/drivers/nvdimm/btt.c
> @@ -1104,10 +1104,10 @@ static int btt_data_read(struct arena_info *arena, struct page *page,
>  {
>  	int ret;
>  	u64 nsoff = to_namespace_offset(arena, lba);
> -	void *mem = kmap_atomic(page);
> +	void *mem = kmap_local_page(page);
>  
>  	ret = arena_read_bytes(arena, nsoff, mem + off, len, NVDIMM_IO_ATOMIC);
> -	kunmap_atomic(mem);
> +	kunmap_local(mem);
>  
>  	return ret;
>  }
> @@ -1117,20 +1117,20 @@ static int btt_data_write(struct arena_info *arena, u32 lba,
>  {
>  	int ret;
>  	u64 nsoff = to_namespace_offset(arena, lba);
> -	void *mem = kmap_atomic(page);
> +	void *mem = kmap_local_page(page);
>  
>  	ret = arena_write_bytes(arena, nsoff, mem + off, len, NVDIMM_IO_ATOMIC);
> -	kunmap_atomic(mem);
> +	kunmap_local(mem);
>  
>  	return ret;
>  }
>  
>  static void zero_fill_data(struct page *page, unsigned int off, u32 len)
>  {
> -	void *mem = kmap_atomic(page);
> +	void *mem = kmap_local_page(page);
>  
>  	memset(mem + off, 0, len);
> -	kunmap_atomic(mem);
> +	kunmap_local(mem);
>  }
>  
>  #ifdef CONFIG_BLK_DEV_INTEGRITY
> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> index 05785ff21a8b..92c67fbbc1c8 100644
> --- a/drivers/nvdimm/pmem.c
> +++ b/drivers/nvdimm/pmem.c
> @@ -128,10 +128,10 @@ static void write_pmem(void *pmem_addr, struct page *page,
>  	void *mem;
>  
>  	while (len) {
> -		mem = kmap_atomic(page);
> +		mem = kmap_local_page(page);
>  		chunk = min_t(unsigned int, len, PAGE_SIZE - off);
>  		memcpy_flushcache(pmem_addr, mem + off, chunk);
> -		kunmap_atomic(mem);
> +		kunmap_local(mem);
>  		len -= chunk;
>  		off = 0;
>  		page++;
> @@ -147,10 +147,10 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
>  	void *mem;
>  
>  	while (len) {
> -		mem = kmap_atomic(page);
> +		mem = kmap_local_page(page);
>  		chunk = min_t(unsigned int, len, PAGE_SIZE - off);
>  		rem = copy_mc_to_kernel(mem + off, pmem_addr, chunk);
> -		kunmap_atomic(mem);
> +		kunmap_local(mem);
>  		if (rem)
>  			return BLK_STS_IOERR;
>  		len -= chunk;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/nvdimm: Use local kmaps
  2025-11-28 21:23 [PATCH] drivers/nvdimm: Use local kmaps Davidlohr Bueso
  2025-12-04 15:32 ` Dave Jiang
@ 2026-01-12 23:10 ` Ira Weiny
  1 sibling, 0 replies; 3+ messages in thread
From: Ira Weiny @ 2026-01-12 23:10 UTC (permalink / raw)
  To: Davidlohr Bueso, vishal.l.verma, dan.j.williams, dave.jiang, ira.weiny
  Cc: nvdimm, linux-kernel, Davidlohr Bueso

Davidlohr Bueso wrote:
> Replace the now deprecated kmap_atomic() with kmap_local_page().
> 
> Optimizing nvdimm/pmem for highmem makes no sense as this is always
> 64bit, and the mapped regions for both btt and pmem do not require
> disabling preemption and pagefaults. Specifically, kmap does not care
> about the caller's atomic context (such as reads holding the btt arena
> spinlock) or NVDIMM_IO_ATOMIC semantics to avoid error handling when
> accessing the btt arena in general. Same for the memcpy cases. kmap
> local temporary mappings will hold valid across any context switches.
> 
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>

Queue'd for 7.0

Thanks!
Ira Weiny

> ---
>  drivers/nvdimm/btt.c  | 12 ++++++------
>  drivers/nvdimm/pmem.c |  8 ++++----
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
> index a933db961ed7..237edfa1c624 100644
> --- a/drivers/nvdimm/btt.c
> +++ b/drivers/nvdimm/btt.c
> @@ -1104,10 +1104,10 @@ static int btt_data_read(struct arena_info *arena, struct page *page,
>  {
>  	int ret;
>  	u64 nsoff = to_namespace_offset(arena, lba);
> -	void *mem = kmap_atomic(page);
> +	void *mem = kmap_local_page(page);
>  
>  	ret = arena_read_bytes(arena, nsoff, mem + off, len, NVDIMM_IO_ATOMIC);
> -	kunmap_atomic(mem);
> +	kunmap_local(mem);
>  
>  	return ret;
>  }
> @@ -1117,20 +1117,20 @@ static int btt_data_write(struct arena_info *arena, u32 lba,
>  {
>  	int ret;
>  	u64 nsoff = to_namespace_offset(arena, lba);
> -	void *mem = kmap_atomic(page);
> +	void *mem = kmap_local_page(page);
>  
>  	ret = arena_write_bytes(arena, nsoff, mem + off, len, NVDIMM_IO_ATOMIC);
> -	kunmap_atomic(mem);
> +	kunmap_local(mem);
>  
>  	return ret;
>  }
>  
>  static void zero_fill_data(struct page *page, unsigned int off, u32 len)
>  {
> -	void *mem = kmap_atomic(page);
> +	void *mem = kmap_local_page(page);
>  
>  	memset(mem + off, 0, len);
> -	kunmap_atomic(mem);
> +	kunmap_local(mem);
>  }
>  
>  #ifdef CONFIG_BLK_DEV_INTEGRITY
> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> index 05785ff21a8b..92c67fbbc1c8 100644
> --- a/drivers/nvdimm/pmem.c
> +++ b/drivers/nvdimm/pmem.c
> @@ -128,10 +128,10 @@ static void write_pmem(void *pmem_addr, struct page *page,
>  	void *mem;
>  
>  	while (len) {
> -		mem = kmap_atomic(page);
> +		mem = kmap_local_page(page);
>  		chunk = min_t(unsigned int, len, PAGE_SIZE - off);
>  		memcpy_flushcache(pmem_addr, mem + off, chunk);
> -		kunmap_atomic(mem);
> +		kunmap_local(mem);
>  		len -= chunk;
>  		off = 0;
>  		page++;
> @@ -147,10 +147,10 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
>  	void *mem;
>  
>  	while (len) {
> -		mem = kmap_atomic(page);
> +		mem = kmap_local_page(page);
>  		chunk = min_t(unsigned int, len, PAGE_SIZE - off);
>  		rem = copy_mc_to_kernel(mem + off, pmem_addr, chunk);
> -		kunmap_atomic(mem);
> +		kunmap_local(mem);
>  		if (rem)
>  			return BLK_STS_IOERR;
>  		len -= chunk;
> -- 
> 2.39.5
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-12 23:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-28 21:23 [PATCH] drivers/nvdimm: Use local kmaps Davidlohr Bueso
2025-12-04 15:32 ` Dave Jiang
2026-01-12 23:10 ` Ira Weiny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®