Skip to contentSkip to conversation

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

PATCH Superseded Nico Boehr 2 participants 3 messages Nov 7, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

PATCH 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/mm/init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/mm/init.c +2 -2
index 97d66a3e60fb..8b652654064e 100644
@@ -146,7 +146,7 @@ int set_memory_encrypted(unsigned long addr, int numpages)
 
 	/* make specified pages unshared, (swiotlb, dma_free) */
 	for (i = 0; i < numpages; ++i) {
-		uv_remove_shared(addr);
+		uv_remove_shared(virt_to_phys((void *)addr));
 		addr += PAGE_SIZE;
 	}
 	return 0;
@@ -157,7 +157,7 @@ int set_memory_decrypted(unsigned long addr, int numpages)
 	int i;
 	/* make specified pages shared (swiotlb, dma_alloca) */
 	for (i = 0; i < numpages; ++i) {
-		uv_set_shared(addr);
+		uv_set_shared(virt_to_phys((void *)addr));
 		addr += PAGE_SIZE;
 	}
 	return 0;
Signature · 1 line
2.37.3
reviewer Reviewed-by on v1 1/1
#1 lore raw

Am 07.11.22 um 11:58 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.

I am asking myself if we should rename addr to vaddr to make this more obvious. (Other users of these functions do use vaddr as well).

Quoted 26 lines
---
  arch/s390/mm/init.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/mm/init.c +2 -2
index 97d66a3e60fb..8b652654064e 100644
@@ -146,7 +146,7 @@ int set_memory_encrypted(unsigned long addr, int numpages)
 
  	/* make specified pages unshared, (swiotlb, dma_free) */
  	for (i = 0; i < numpages; ++i) {
-		uv_remove_shared(addr);
+		uv_remove_shared(virt_to_phys((void *)addr));
  		addr += PAGE_SIZE;
  	}
  	return 0;
@@ -157,7 +157,7 @@ int set_memory_decrypted(unsigned long addr, int numpages)
  	int i;
  	/* make specified pages shared (swiotlb, dma_alloca) */
  	for (i = 0; i < numpages; ++i) {
-		uv_set_shared(addr);
+		uv_set_shared(virt_to_phys((void *)addr));
  		addr += PAGE_SIZE;
  	}
  	return 0;
author
#2 lore raw

Quoting Christian Borntraeger (2022-11-07 12:21:58)

Quoted 8 lines

Am 07.11.22 um 11:58 schrieb Nico Boehr:

Quoted 7 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.

Quoted 7 lines
Quoted 2 lines

I am asking myself if we should rename addr to vaddr to make this more obvious. (Other users of these functions do use vaddr as well).

I had this at some point, but then changed it back because at the time I thought we don't own the prototype.

However, looking at it again, it looks like that's wrong and we do own it in arch/s390/include/asm/mem_encrypt.h.

So I think it's a good suggestion and I will pick it up for v2.