Skip to contentSkip to conversation

s390/mm: fix virtual-physical address confusion for swiotlb

PATCH In review Nico Boehr 3 participants 4 messages Nov 7, 2022

Subsystems (3)
lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

v2 cover s390/mm: fix virtual-physical address confusion for swiotlb

v1->v2:
---
* rename addr to vaddr (thanks Christian)

Nico Boehr (1):
s390/mm: fix virtual-physical address confusion for swiotlb

 arch/s390/include/asm/mem_encrypt.h |  4 ++--
 arch/s390/mm/init.c                 | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)
Signature · 1 line
2.37.3
author
#1 lore raw

PATCH v2 1/1 s390/mm: fix virtual-physical address confusion for swiotlb

swiotlb passes virtual addresses to set_memory_encrypted() and set_memory_decrypted(), but uv_remove_shared() and uv_set_shared() expect physical addresses. This currently works, because virtual and physical addresses are the same.

Add virt_to_phys() to resolve the virtual-physical confusion.

---
 arch/s390/include/asm/mem_encrypt.h |  4 ++--
 arch/s390/mm/init.c                 | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)
arch/s390/include/asm/mem_encrypt.h +2 -2
index 08a8b96606d7..b85e13505a0f 100644
@@ -4,8 +4,8 @@
 
 #ifndef __ASSEMBLY__
 
-int set_memory_encrypted(unsigned long addr, int numpages);
-int set_memory_decrypted(unsigned long addr, int numpages);
+int set_memory_encrypted(unsigned long vaddr, int numpages);
+int set_memory_decrypted(unsigned long vaddr, int numpages);
 
 #endif	/* __ASSEMBLY__ */
 
arch/s390/mm/init.c +6 -6
index 97d66a3e60fb..d509656c67d7 100644
@@ -140,25 +140,25 @@ void mark_rodata_ro(void)
 	debug_checkwx();
 }
 
-int set_memory_encrypted(unsigned long addr, int numpages)
+int set_memory_encrypted(unsigned long vaddr, int numpages)
 {
 	int i;
 
 	/* make specified pages unshared, (swiotlb, dma_free) */
 	for (i = 0; i < numpages; ++i) {
-		uv_remove_shared(addr);
-		addr += PAGE_SIZE;
+		uv_remove_shared(virt_to_phys((void *)vaddr));
+		vaddr += PAGE_SIZE;
 	}
 	return 0;
 }
 
-int set_memory_decrypted(unsigned long addr, int numpages)
+int set_memory_decrypted(unsigned long vaddr, int numpages)
 {
 	int i;
 	/* make specified pages shared (swiotlb, dma_alloca) */
 	for (i = 0; i < numpages; ++i) {
-		uv_set_shared(addr);
-		addr += PAGE_SIZE;
+		uv_set_shared(virt_to_phys((void *)vaddr));
+		vaddr += PAGE_SIZE;
 	}
 	return 0;
 }
Signature · 1 line
2.37.3
reviewer Reviewed-by on v2 1/1
#2 lore raw

Am 07.11.22 um 13:12 schrieb Nico Boehr:

Quoted 9 lines

swiotlb passes virtual addresses to set_memory_encrypted() and set_memory_decrypted(), but uv_remove_shared() and uv_set_shared() expect physical addresses. This currently works, because virtual and physical addresses are the same.

Add virt_to_phys() to resolve the virtual-physical confusion.

You can keep my RB:

Quoted 56 lines
---
  arch/s390/include/asm/mem_encrypt.h |  4 ++--
  arch/s390/mm/init.c                 | 12 ++++++------
  2 files changed, 8 insertions(+), 8 deletions(-)
arch/s390/include/asm/mem_encrypt.h +2 -2
index 08a8b96606d7..b85e13505a0f 100644
@@ -4,8 +4,8 @@
 
  #ifndef __ASSEMBLY__
 
-int set_memory_encrypted(unsigned long addr, int numpages);
-int set_memory_decrypted(unsigned long addr, int numpages);
+int set_memory_encrypted(unsigned long vaddr, int numpages);
+int set_memory_decrypted(unsigned long vaddr, int numpages);
 
  #endif	/* __ASSEMBLY__ */
 
arch/s390/mm/init.c +6 -6
index 97d66a3e60fb..d509656c67d7 100644
@@ -140,25 +140,25 @@ void mark_rodata_ro(void)
  	debug_checkwx();
  }
 
-int set_memory_encrypted(unsigned long addr, int numpages)
+int set_memory_encrypted(unsigned long vaddr, int numpages)
  {
  	int i;
 
  	/* make specified pages unshared, (swiotlb, dma_free) */
  	for (i = 0; i < numpages; ++i) {
-		uv_remove_shared(addr);
-		addr += PAGE_SIZE;
+		uv_remove_shared(virt_to_phys((void *)vaddr));
+		vaddr += PAGE_SIZE;
  	}
  	return 0;
  }
 
-int set_memory_decrypted(unsigned long addr, int numpages)
+int set_memory_decrypted(unsigned long vaddr, int numpages)
  {
  	int i;
  	/* make specified pages shared (swiotlb, dma_alloca) */
  	for (i = 0; i < numpages; ++i) {
-		uv_set_shared(addr);
-		addr += PAGE_SIZE;
+		uv_set_shared(virt_to_phys((void *)vaddr));
+		vaddr += PAGE_SIZE;
  	}
  	return 0;
  }
Reviewed-by on v2 1/1
#3 lore raw
In reply to Nico Boehr
Quoted 9 lines · On Mon, 7 Nov 2022 13:12:21 +0100 Nico Boehr <[email protected]> wrote:

swiotlb passes virtual addresses to set_memory_encrypted() and set_memory_decrypted(), but uv_remove_shared() and uv_set_shared() expect physical addresses. This currently works, because virtual and physical addresses are the same.

Add virt_to_phys() to resolve the virtual-physical confusion.

Quoted 56 lines
---
 arch/s390/include/asm/mem_encrypt.h |  4 ++--
 arch/s390/mm/init.c                 | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)
arch/s390/include/asm/mem_encrypt.h +2 -2
index 08a8b96606d7..b85e13505a0f 100644
@@ -4,8 +4,8 @@
 
 #ifndef __ASSEMBLY__
 
-int set_memory_encrypted(unsigned long addr, int numpages);
-int set_memory_decrypted(unsigned long addr, int numpages);
+int set_memory_encrypted(unsigned long vaddr, int numpages);
+int set_memory_decrypted(unsigned long vaddr, int numpages);
 
 #endif	/* __ASSEMBLY__ */
 
arch/s390/mm/init.c +6 -6
index 97d66a3e60fb..d509656c67d7 100644
@@ -140,25 +140,25 @@ void mark_rodata_ro(void)
 	debug_checkwx();
 }
 
-int set_memory_encrypted(unsigned long addr, int numpages)
+int set_memory_encrypted(unsigned long vaddr, int numpages)
 {
 	int i;
 
 	/* make specified pages unshared, (swiotlb, dma_free) */
 	for (i = 0; i < numpages; ++i) {
-		uv_remove_shared(addr);
-		addr += PAGE_SIZE;
+		uv_remove_shared(virt_to_phys((void *)vaddr));
+		vaddr += PAGE_SIZE;
 	}
 	return 0;
 }
 
-int set_memory_decrypted(unsigned long addr, int numpages)
+int set_memory_decrypted(unsigned long vaddr, int numpages)
 {
 	int i;
 	/* make specified pages shared (swiotlb, dma_alloca) */
 	for (i = 0; i < numpages; ++i) {
-		uv_set_shared(addr);
-		addr += PAGE_SIZE;
+		uv_set_shared(virt_to_phys((void *)vaddr));
+		vaddr += PAGE_SIZE;
 	}
 	return 0;
 }