Skip to content

Commit 5ed8cbc

Browse files
mhklinuxliuw
authored andcommitted
x86/hyperv: Use memremap()/memunmap() instead of ioremap_cache()/iounmap()
When running with a paravisor and SEV-SNP, the GHCB page is provided by the paravisor instead of being allocated by Linux. The provided page is normal memory, but is outside of the physical address space seen by Linux. As such it cannot be accessed via the kernel's direct map, and must be explicitly mapped to a kernel virtual address. Current code uses ioremap_cache() and iounmap() to map and unmap the page. These functions are for use on I/O address space that may not behave as normal memory, so they generate or expect addresses with the __iomem attribute. For normal memory, the preferred functions are memremap() and memunmap(), which operate similarly but without __iomem. At the time of the original work on CoCo VMs on Hyper-V, memremap() did not support creating a decrypted mapping, so ioremap_cache() was used instead, since I/O address space is always mapped decrypted. memremap() has since been enhanced to allow decrypted mappings, so replace ioremap_cache() with memremap() when mapping the GHCB page. Similarly, replace iounmap() with memunmap(). As a side benefit, the replacement cleans up 'sparse' warnings about __iomem mismatches. The replacement is done to use the correct functions as long-term goodness and to clean up the sparse warnings. No runtime bugs are fixed. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Michael Kelley <[email protected]> Signed-off-by: Wei Liu <[email protected]>
1 parent 0236e75 commit 5ed8cbc

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/x86/hyperv/hv_init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ static int hyperv_init_ghcb(void)
103103
*/
104104
rdmsrq(MSR_AMD64_SEV_ES_GHCB, ghcb_gpa);
105105

106-
/* Mask out vTOM bit. ioremap_cache() maps decrypted */
106+
/* Mask out vTOM bit and map as decrypted */
107107
ghcb_gpa &= ~ms_hyperv.shared_gpa_boundary;
108-
ghcb_va = (void *)ioremap_cache(ghcb_gpa, HV_HYP_PAGE_SIZE);
108+
ghcb_va = memremap(ghcb_gpa, HV_HYP_PAGE_SIZE, MEMREMAP_WB | MEMREMAP_DEC);
109109
if (!ghcb_va)
110110
return -ENOMEM;
111111

@@ -277,7 +277,7 @@ static int hv_cpu_die(unsigned int cpu)
277277
if (hv_ghcb_pg) {
278278
ghcb_va = (void **)this_cpu_ptr(hv_ghcb_pg);
279279
if (*ghcb_va)
280-
iounmap(*ghcb_va);
280+
memunmap(*ghcb_va);
281281
*ghcb_va = NULL;
282282
}
283283

0 commit comments

Comments
 (0)