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

hv_netvsc: Remove second mapping of send and recv buffers

With changes to how Hyper-V guest VMs flip memory between private
(encrypted) and shared (decrypted), creating a second kernel virtual
mapping for shared memory is no longer necessary. Everything needed
for the transition to shared is handled by set_memory_decrypted().

As such, remove the code to create and manage the second
mapping for the pre-allocated send and recv buffers. This mapping
is the last user of hv_map_memory()/hv_unmap_memory(), so delete
these functions as well. Finally, hv_map_memory() is the last
user of vmap_pfn() in Hyper-V guest code, so remove the Kconfig
selection of VMAP_PFN.

Signed-off-by: Michael Kelley <mikelley@microsoft.com>
Reviewed-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
Link: https://lore.kernel.org/r/1679838727-87310-11-git-send-email-mikelley@microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Michael Kelley and committed by
Wei Liu
25727aae bb862397

+2 -90
-28
arch/x86/hyperv/ivm.c
··· 376 376 377 377 #endif /* CONFIG_AMD_MEM_ENCRYPT */ 378 378 379 - /* 380 - * hv_map_memory - map memory to extra space in the AMD SEV-SNP Isolation VM. 381 - */ 382 - void *hv_map_memory(void *addr, unsigned long size) 383 - { 384 - unsigned long *pfns = kcalloc(size / PAGE_SIZE, 385 - sizeof(unsigned long), GFP_KERNEL); 386 - void *vaddr; 387 - int i; 388 - 389 - if (!pfns) 390 - return NULL; 391 - 392 - for (i = 0; i < size / PAGE_SIZE; i++) 393 - pfns[i] = vmalloc_to_pfn(addr + i * PAGE_SIZE) + 394 - (ms_hyperv.shared_gpa_boundary >> PAGE_SHIFT); 395 - 396 - vaddr = vmap_pfn(pfns, size / PAGE_SIZE, pgprot_decrypted(PAGE_KERNEL)); 397 - kfree(pfns); 398 - 399 - return vaddr; 400 - } 401 - 402 - void hv_unmap_memory(void *addr) 403 - { 404 - vunmap(addr); 405 - } 406 - 407 379 enum hv_isolation_type hv_get_isolation_type(void) 408 380 { 409 381 if (!(ms_hyperv.priv_high & HV_ISOLATION))
-1
drivers/hv/Kconfig
··· 8 8 || (ACPI && ARM64 && !CPU_BIG_ENDIAN) 9 9 select PARAVIRT 10 10 select X86_HV_CALLBACK_VECTOR if X86 11 - select VMAP_PFN 12 11 select OF_EARLY_FLATTREE if OF 13 12 help 14 13 Select this option to run Linux as a Hyper-V client operating
-11
drivers/hv/hv_common.c
··· 311 311 return HV_STATUS_INVALID_PARAMETER; 312 312 } 313 313 EXPORT_SYMBOL_GPL(hv_ghcb_hypercall); 314 - 315 - void __weak *hv_map_memory(void *addr, unsigned long size) 316 - { 317 - return NULL; 318 - } 319 - EXPORT_SYMBOL_GPL(hv_map_memory); 320 - 321 - void __weak hv_unmap_memory(void *addr) 322 - { 323 - } 324 - EXPORT_SYMBOL_GPL(hv_unmap_memory);
-2
drivers/net/hyperv/hyperv_net.h
··· 1139 1139 1140 1140 /* Receive buffer allocated by us but manages by NetVSP */ 1141 1141 void *recv_buf; 1142 - void *recv_original_buf; 1143 1142 u32 recv_buf_size; /* allocated bytes */ 1144 1143 struct vmbus_gpadl recv_buf_gpadl_handle; 1145 1144 u32 recv_section_cnt; ··· 1147 1148 1148 1149 /* Send buffer allocated by us */ 1149 1150 void *send_buf; 1150 - void *send_original_buf; 1151 1151 u32 send_buf_size; 1152 1152 struct vmbus_gpadl send_buf_gpadl_handle; 1153 1153 u32 send_section_cnt;
+2 -46
drivers/net/hyperv/netvsc.c
··· 154 154 int i; 155 155 156 156 kfree(nvdev->extension); 157 - 158 - if (nvdev->recv_original_buf) 159 - vfree(nvdev->recv_original_buf); 160 - else 161 - vfree(nvdev->recv_buf); 162 - 163 - if (nvdev->send_original_buf) 164 - vfree(nvdev->send_original_buf); 165 - else 166 - vfree(nvdev->send_buf); 167 - 157 + vfree(nvdev->recv_buf); 158 + vfree(nvdev->send_buf); 168 159 bitmap_free(nvdev->send_section_map); 169 160 170 161 for (i = 0; i < VRSS_CHANNEL_MAX; i++) { ··· 338 347 struct nvsp_message *init_packet; 339 348 unsigned int buf_size; 340 349 int i, ret = 0; 341 - void *vaddr; 342 350 343 351 /* Get receive buffer area. */ 344 352 buf_size = device_info->recv_sections * device_info->recv_section_size; ··· 371 381 netdev_err(ndev, 372 382 "unable to establish receive buffer's gpadl\n"); 373 383 goto cleanup; 374 - } 375 - 376 - if (hv_isolation_type_snp()) { 377 - vaddr = hv_map_memory(net_device->recv_buf, buf_size); 378 - if (!vaddr) { 379 - ret = -ENOMEM; 380 - goto cleanup; 381 - } 382 - 383 - net_device->recv_original_buf = net_device->recv_buf; 384 - net_device->recv_buf = vaddr; 385 384 } 386 385 387 386 /* Notify the NetVsp of the gpadl handle */ ··· 474 495 netdev_err(ndev, 475 496 "unable to establish send buffer's gpadl\n"); 476 497 goto cleanup; 477 - } 478 - 479 - if (hv_isolation_type_snp()) { 480 - vaddr = hv_map_memory(net_device->send_buf, buf_size); 481 - if (!vaddr) { 482 - ret = -ENOMEM; 483 - goto cleanup; 484 - } 485 - 486 - net_device->send_original_buf = net_device->send_buf; 487 - net_device->send_buf = vaddr; 488 498 } 489 499 490 500 /* Notify the NetVsp of the gpadl handle */ ··· 729 761 netvsc_teardown_recv_gpadl(device, net_device, ndev); 730 762 netvsc_teardown_send_gpadl(device, net_device, ndev); 731 763 } 732 - 733 - if (net_device->recv_original_buf) 734 - hv_unmap_memory(net_device->recv_buf); 735 - 736 - if (net_device->send_original_buf) 737 - hv_unmap_memory(net_device->send_buf); 738 764 739 765 /* Release all resources */ 740 766 free_netvsc_device_rcu(net_device); ··· 1806 1844 netif_napi_del(&net_device->chan_table[0].napi); 1807 1845 1808 1846 cleanup2: 1809 - if (net_device->recv_original_buf) 1810 - hv_unmap_memory(net_device->recv_buf); 1811 - 1812 - if (net_device->send_original_buf) 1813 - hv_unmap_memory(net_device->send_buf); 1814 - 1815 1847 free_netvsc_device(&net_device->rcu); 1816 1848 1817 1849 return ERR_PTR(ret);
-2
include/asm-generic/mshyperv.h
··· 271 271 void hyperv_cleanup(void); 272 272 bool hv_query_ext_cap(u64 cap_query); 273 273 void hv_setup_dma_ops(struct device *dev, bool coherent); 274 - void *hv_map_memory(void *addr, unsigned long size); 275 - void hv_unmap_memory(void *addr); 276 274 #else /* CONFIG_HYPERV */ 277 275 static inline bool hv_is_hyperv_initialized(void) { return false; } 278 276 static inline bool hv_is_hibernation_supported(void) { return false; }