Skip to content

Commit 0236e75

Browse files
mhklinuxliuw
authored andcommitted
Drivers: hv: Use memremap()/memunmap() instead of ioremap_cache()/iounmap()
When running with a paravisor or in the root partition, the SynIC event and message pages are provided by the paravisor or hypervisor respectively, instead of being allocated by Linux. The provided pages are normal memory, but are outside of the physical address space seen by Linux. As such they 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 pages. 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 event and message pages. 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]/ 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 c3a6ae7 commit 0236e75

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

drivers/hv/hv.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ void hv_hyp_synic_enable_regs(unsigned int cpu)
287287
simp.simp_enabled = 1;
288288

289289
if (ms_hyperv.paravisor_present || hv_root_partition()) {
290-
/* Mask out vTOM bit. ioremap_cache() maps decrypted */
290+
/* Mask out vTOM bit and map as decrypted */
291291
u64 base = (simp.base_simp_gpa << HV_HYP_PAGE_SHIFT) &
292292
~ms_hyperv.shared_gpa_boundary;
293293
hv_cpu->hyp_synic_message_page =
294-
(void *)ioremap_cache(base, HV_HYP_PAGE_SIZE);
294+
memremap(base, HV_HYP_PAGE_SIZE, MEMREMAP_WB | MEMREMAP_DEC);
295295
if (!hv_cpu->hyp_synic_message_page)
296296
pr_err("Fail to map synic message page.\n");
297297
} else {
@@ -306,11 +306,11 @@ void hv_hyp_synic_enable_regs(unsigned int cpu)
306306
siefp.siefp_enabled = 1;
307307

308308
if (ms_hyperv.paravisor_present || hv_root_partition()) {
309-
/* Mask out vTOM bit. ioremap_cache() maps decrypted */
309+
/* Mask out vTOM bit and map as decrypted */
310310
u64 base = (siefp.base_siefp_gpa << HV_HYP_PAGE_SHIFT) &
311311
~ms_hyperv.shared_gpa_boundary;
312312
hv_cpu->hyp_synic_event_page =
313-
(void *)ioremap_cache(base, HV_HYP_PAGE_SIZE);
313+
memremap(base, HV_HYP_PAGE_SIZE, MEMREMAP_WB | MEMREMAP_DEC);
314314
if (!hv_cpu->hyp_synic_event_page)
315315
pr_err("Fail to map synic event page.\n");
316316
} else {
@@ -429,7 +429,7 @@ void hv_hyp_synic_disable_regs(unsigned int cpu)
429429
simp.simp_enabled = 0;
430430
if (ms_hyperv.paravisor_present || hv_root_partition()) {
431431
if (hv_cpu->hyp_synic_message_page) {
432-
iounmap(hv_cpu->hyp_synic_message_page);
432+
memunmap(hv_cpu->hyp_synic_message_page);
433433
hv_cpu->hyp_synic_message_page = NULL;
434434
}
435435
} else {
@@ -443,7 +443,7 @@ void hv_hyp_synic_disable_regs(unsigned int cpu)
443443

444444
if (ms_hyperv.paravisor_present || hv_root_partition()) {
445445
if (hv_cpu->hyp_synic_event_page) {
446-
iounmap(hv_cpu->hyp_synic_event_page);
446+
memunmap(hv_cpu->hyp_synic_event_page);
447447
hv_cpu->hyp_synic_event_page = NULL;
448448
}
449449
} else {

0 commit comments

Comments
 (0)