Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Link: https://lore.kernel.org/r/20221107121221.156274-2-nrb@linux.ibm.com
Message-Id: <20221107121221.156274-2-nrb@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

authored by

Nico Boehr and committed by
Janosch Frank
58635d66 77b53341

+8 -8
+2 -2
arch/s390/include/asm/mem_encrypt.h
··· 4 4 5 5 #ifndef __ASSEMBLY__ 6 6 7 - int set_memory_encrypted(unsigned long addr, int numpages); 8 - int set_memory_decrypted(unsigned long addr, int numpages); 7 + int set_memory_encrypted(unsigned long vaddr, int numpages); 8 + int set_memory_decrypted(unsigned long vaddr, int numpages); 9 9 10 10 #endif /* __ASSEMBLY__ */ 11 11
+6 -6
arch/s390/mm/init.c
··· 140 140 debug_checkwx(); 141 141 } 142 142 143 - int set_memory_encrypted(unsigned long addr, int numpages) 143 + int set_memory_encrypted(unsigned long vaddr, int numpages) 144 144 { 145 145 int i; 146 146 147 147 /* make specified pages unshared, (swiotlb, dma_free) */ 148 148 for (i = 0; i < numpages; ++i) { 149 - uv_remove_shared(addr); 150 - addr += PAGE_SIZE; 149 + uv_remove_shared(virt_to_phys((void *)vaddr)); 150 + vaddr += PAGE_SIZE; 151 151 } 152 152 return 0; 153 153 } 154 154 155 - int set_memory_decrypted(unsigned long addr, int numpages) 155 + int set_memory_decrypted(unsigned long vaddr, int numpages) 156 156 { 157 157 int i; 158 158 /* make specified pages shared (swiotlb, dma_alloca) */ 159 159 for (i = 0; i < numpages; ++i) { 160 - uv_set_shared(addr); 161 - addr += PAGE_SIZE; 160 + uv_set_shared(virt_to_phys((void *)vaddr)); 161 + vaddr += PAGE_SIZE; 162 162 } 163 163 return 0; 164 164 }