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

Merge tag 'hyperv-next-signed-20220114' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux

Pull hyperv updates from Wei Liu:

- More patches for Hyper-V isolation VM support (Tianyu Lan)

- Bug fixes and clean-up patches from various people

* tag 'hyperv-next-signed-20220114' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux:
scsi: storvsc: Fix storvsc_queuecommand() memory leak
x86/hyperv: Properly deal with empty cpumasks in hyperv_flush_tlb_multi()
Drivers: hv: vmbus: Initialize request offers message for Isolation VM
scsi: storvsc: Fix unsigned comparison to zero
swiotlb: Add CONFIG_HAS_IOMEM check around swiotlb_mem_remap()
x86/hyperv: Fix definition of hv_ghcb_pg variable
Drivers: hv: Fix definition of hypercall input & output arg variables
net: netvsc: Add Isolation VM support for netvsc driver
scsi: storvsc: Add Isolation VM support for storvsc driver
hyper-v: Enable swiotlb bounce buffer for Isolation VM
x86/hyper-v: Add hyperv Isolation VM check in the cc_platform_has()
swiotlb: Add swiotlb bounce buffer remap function for HV IVM

+328 -45
+13 -1
arch/x86/hyperv/hv_init.c
··· 28 28 #include <linux/syscore_ops.h> 29 29 #include <clocksource/hyperv_timer.h> 30 30 #include <linux/highmem.h> 31 + #include <linux/swiotlb.h> 31 32 32 33 int hyperv_init_cpuhp; 33 34 u64 hv_current_partition_id = ~0ull; ··· 37 36 void *hv_hypercall_pg; 38 37 EXPORT_SYMBOL_GPL(hv_hypercall_pg); 39 38 40 - union hv_ghcb __percpu **hv_ghcb_pg; 39 + union hv_ghcb * __percpu *hv_ghcb_pg; 41 40 42 41 /* Storage to save the hypercall page temporarily for hibernation */ 43 42 static void *hv_hypercall_pg_saved; ··· 499 498 500 499 /* Query the VMs extended capability once, so that it can be cached. */ 501 500 hv_query_ext_cap(0); 501 + 502 + #ifdef CONFIG_SWIOTLB 503 + /* 504 + * Swiotlb bounce buffer needs to be mapped in extra address 505 + * space. Map function doesn't work in the early place and so 506 + * call swiotlb_update_mem_attributes() here. 507 + */ 508 + if (hv_is_isolation_supported()) 509 + swiotlb_update_mem_attributes(); 510 + #endif 511 + 502 512 return; 503 513 504 514 clean_guest_os_id:
+28
arch/x86/hyperv/ivm.c
··· 287 287 kfree(pfn_array); 288 288 return ret; 289 289 } 290 + 291 + /* 292 + * hv_map_memory - map memory to extra space in the AMD SEV-SNP Isolation VM. 293 + */ 294 + void *hv_map_memory(void *addr, unsigned long size) 295 + { 296 + unsigned long *pfns = kcalloc(size / PAGE_SIZE, 297 + sizeof(unsigned long), GFP_KERNEL); 298 + void *vaddr; 299 + int i; 300 + 301 + if (!pfns) 302 + return NULL; 303 + 304 + for (i = 0; i < size / PAGE_SIZE; i++) 305 + pfns[i] = vmalloc_to_pfn(addr + i * PAGE_SIZE) + 306 + (ms_hyperv.shared_gpa_boundary >> PAGE_SHIFT); 307 + 308 + vaddr = vmap_pfn(pfns, size / PAGE_SIZE, PAGE_KERNEL_IO); 309 + kfree(pfns); 310 + 311 + return vaddr; 312 + } 313 + 314 + void hv_unmap_memory(void *addr) 315 + { 316 + vunmap(addr); 317 + }
+9 -10
arch/x86/hyperv/mmu.c
··· 68 68 69 69 local_irq_save(flags); 70 70 71 - /* 72 - * Only check the mask _after_ interrupt has been disabled to avoid the 73 - * mask changing under our feet. 74 - */ 75 - if (cpumask_empty(cpus)) { 76 - local_irq_restore(flags); 77 - return; 78 - } 79 - 80 71 flush_pcpu = (struct hv_tlb_flush **) 81 72 this_cpu_ptr(hyperv_pcpu_input_arg); 82 73 ··· 106 115 * must. We will also check all VP numbers when walking the 107 116 * supplied CPU set to remain correct in all cases. 108 117 */ 109 - if (hv_cpu_number_to_vp_number(cpumask_last(cpus)) >= 64) 118 + cpu = cpumask_last(cpus); 119 + 120 + if (cpu < nr_cpumask_bits && hv_cpu_number_to_vp_number(cpu) >= 64) 110 121 goto do_ex_hypercall; 111 122 112 123 for_each_cpu(cpu, cpus) { ··· 123 130 124 131 __set_bit(vcpu, (unsigned long *) 125 132 &flush->processor_mask); 133 + } 134 + 135 + /* nothing to flush if 'processor_mask' ends up being empty */ 136 + if (!flush->processor_mask) { 137 + local_irq_restore(flags); 138 + return; 126 139 } 127 140 } 128 141
+1 -1
arch/x86/include/asm/mshyperv.h
··· 30 30 31 31 extern u64 hv_current_partition_id; 32 32 33 - extern union hv_ghcb __percpu **hv_ghcb_pg; 33 + extern union hv_ghcb * __percpu *hv_ghcb_pg; 34 34 35 35 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); 36 36 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
+8
arch/x86/kernel/cc_platform.c
··· 11 11 #include <linux/cc_platform.h> 12 12 #include <linux/mem_encrypt.h> 13 13 14 + #include <asm/mshyperv.h> 14 15 #include <asm/processor.h> 15 16 16 17 static bool __maybe_unused intel_cc_platform_has(enum cc_attr attr) ··· 67 66 #endif 68 67 } 69 68 69 + static bool hyperv_cc_platform_has(enum cc_attr attr) 70 + { 71 + return attr == CC_ATTR_GUEST_MEM_ENCRYPT; 72 + } 70 73 71 74 bool cc_platform_has(enum cc_attr attr) 72 75 { 73 76 if (sme_me_mask) 74 77 return amd_cc_platform_has(attr); 78 + 79 + if (hv_is_isolation_supported()) 80 + return hyperv_cc_platform_has(attr); 75 81 76 82 return false; 77 83 }
+14 -1
arch/x86/kernel/cpu/mshyperv.c
··· 18 18 #include <linux/kexec.h> 19 19 #include <linux/i8253.h> 20 20 #include <linux/random.h> 21 + #include <linux/swiotlb.h> 21 22 #include <asm/processor.h> 22 23 #include <asm/hypervisor.h> 23 24 #include <asm/hyperv-tlfs.h> ··· 330 329 pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n", 331 330 ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); 332 331 333 - if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) 332 + if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) { 334 333 static_branch_enable(&isolation_type_snp); 334 + #ifdef CONFIG_SWIOTLB 335 + swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; 336 + #endif 337 + } 338 + 339 + #ifdef CONFIG_SWIOTLB 340 + /* 341 + * Enable swiotlb force mode in Isolation VM to 342 + * use swiotlb bounce buffer for dma transaction. 343 + */ 344 + swiotlb_force = SWIOTLB_FORCE; 345 + #endif 335 346 } 336 347 337 348 if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) {
+1 -1
drivers/hv/channel_mgmt.c
··· 1554 1554 struct vmbus_channel_msginfo *msginfo; 1555 1555 int ret; 1556 1556 1557 - msginfo = kmalloc(sizeof(*msginfo) + 1557 + msginfo = kzalloc(sizeof(*msginfo) + 1558 1558 sizeof(struct vmbus_channel_message_header), 1559 1559 GFP_KERNEL); 1560 1560 if (!msginfo)
+13 -2
drivers/hv/hv_common.c
··· 44 44 u32 hv_max_vp_index; 45 45 EXPORT_SYMBOL_GPL(hv_max_vp_index); 46 46 47 - void __percpu **hyperv_pcpu_input_arg; 47 + void * __percpu *hyperv_pcpu_input_arg; 48 48 EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); 49 49 50 - void __percpu **hyperv_pcpu_output_arg; 50 + void * __percpu *hyperv_pcpu_output_arg; 51 51 EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); 52 52 53 53 /* ··· 295 295 return HV_STATUS_INVALID_PARAMETER; 296 296 } 297 297 EXPORT_SYMBOL_GPL(hv_ghcb_hypercall); 298 + 299 + void __weak *hv_map_memory(void *addr, unsigned long size) 300 + { 301 + return NULL; 302 + } 303 + EXPORT_SYMBOL_GPL(hv_map_memory); 304 + 305 + void __weak hv_unmap_memory(void *addr) 306 + { 307 + } 308 + EXPORT_SYMBOL_GPL(hv_unmap_memory);
+4
drivers/hv/vmbus_drv.c
··· 33 33 #include <linux/random.h> 34 34 #include <linux/kernel.h> 35 35 #include <linux/syscore_ops.h> 36 + #include <linux/dma-map-ops.h> 36 37 #include <clocksource/hyperv_timer.h> 37 38 #include "hyperv_vmbus.h" 38 39 ··· 2079 2078 return child_device_obj; 2080 2079 } 2081 2080 2081 + static u64 vmbus_dma_mask = DMA_BIT_MASK(64); 2082 2082 /* 2083 2083 * vmbus_device_register - Register the child device 2084 2084 */ ··· 2120 2118 } 2121 2119 hv_debug_add_dev_dir(child_device_obj); 2122 2120 2121 + child_device_obj->device.dma_mask = &vmbus_dma_mask; 2122 + child_device_obj->device.dma_parms = &child_device_obj->dma_parms; 2123 2123 return 0; 2124 2124 2125 2125 err_kset_unregister:
+5
drivers/net/hyperv/hyperv_net.h
··· 164 164 u32 total_bytes; 165 165 u32 send_buf_index; 166 166 u32 total_data_buflen; 167 + struct hv_dma_range *dma_range; 167 168 }; 168 169 169 170 #define NETVSC_HASH_KEYLEN 40 ··· 1075 1074 1076 1075 /* Receive buffer allocated by us but manages by NetVSP */ 1077 1076 void *recv_buf; 1077 + void *recv_original_buf; 1078 1078 u32 recv_buf_size; /* allocated bytes */ 1079 1079 struct vmbus_gpadl recv_buf_gpadl_handle; 1080 1080 u32 recv_section_cnt; ··· 1084 1082 1085 1083 /* Send buffer allocated by us */ 1086 1084 void *send_buf; 1085 + void *send_original_buf; 1087 1086 u32 send_buf_size; 1088 1087 struct vmbus_gpadl send_buf_gpadl_handle; 1089 1088 u32 send_section_cnt; ··· 1734 1731 #define RETRY_US_HI 10000 1735 1732 #define RETRY_MAX 2000 /* >10 sec */ 1736 1733 1734 + void netvsc_dma_unmap(struct hv_device *hv_dev, 1735 + struct hv_netvsc_packet *packet); 1737 1736 #endif /* _HYPERV_NET_H */
+133 -3
drivers/net/hyperv/netvsc.c
··· 153 153 int i; 154 154 155 155 kfree(nvdev->extension); 156 - vfree(nvdev->recv_buf); 157 - vfree(nvdev->send_buf); 156 + 157 + if (nvdev->recv_original_buf) { 158 + hv_unmap_memory(nvdev->recv_buf); 159 + vfree(nvdev->recv_original_buf); 160 + } else { 161 + vfree(nvdev->recv_buf); 162 + } 163 + 164 + if (nvdev->send_original_buf) { 165 + hv_unmap_memory(nvdev->send_buf); 166 + vfree(nvdev->send_original_buf); 167 + } else { 168 + vfree(nvdev->send_buf); 169 + } 170 + 158 171 bitmap_free(nvdev->send_section_map); 159 172 160 173 for (i = 0; i < VRSS_CHANNEL_MAX; i++) { ··· 350 337 struct nvsp_message *init_packet; 351 338 unsigned int buf_size; 352 339 int i, ret = 0; 340 + void *vaddr; 353 341 354 342 /* Get receive buffer area. */ 355 343 buf_size = device_info->recv_sections * device_info->recv_section_size; ··· 384 370 netdev_err(ndev, 385 371 "unable to establish receive buffer's gpadl\n"); 386 372 goto cleanup; 373 + } 374 + 375 + if (hv_isolation_type_snp()) { 376 + vaddr = hv_map_memory(net_device->recv_buf, buf_size); 377 + if (!vaddr) { 378 + ret = -ENOMEM; 379 + goto cleanup; 380 + } 381 + 382 + net_device->recv_original_buf = net_device->recv_buf; 383 + net_device->recv_buf = vaddr; 387 384 } 388 385 389 386 /* Notify the NetVsp of the gpadl handle */ ··· 498 473 netdev_err(ndev, 499 474 "unable to establish send buffer's gpadl\n"); 500 475 goto cleanup; 476 + } 477 + 478 + if (hv_isolation_type_snp()) { 479 + vaddr = hv_map_memory(net_device->send_buf, buf_size); 480 + if (!vaddr) { 481 + ret = -ENOMEM; 482 + goto cleanup; 483 + } 484 + 485 + net_device->send_original_buf = net_device->send_buf; 486 + net_device->send_buf = vaddr; 501 487 } 502 488 503 489 /* Notify the NetVsp of the gpadl handle */ ··· 800 764 801 765 /* Notify the layer above us */ 802 766 if (likely(skb)) { 803 - const struct hv_netvsc_packet *packet 767 + struct hv_netvsc_packet *packet 804 768 = (struct hv_netvsc_packet *)skb->cb; 805 769 u32 send_index = packet->send_buf_index; 806 770 struct netvsc_stats *tx_stats; ··· 816 780 tx_stats->bytes += packet->total_bytes; 817 781 u64_stats_update_end(&tx_stats->syncp); 818 782 783 + netvsc_dma_unmap(ndev_ctx->device_ctx, packet); 819 784 napi_consume_skb(skb, budget); 820 785 } 821 786 ··· 981 944 memset(dest, 0, padding); 982 945 } 983 946 947 + void netvsc_dma_unmap(struct hv_device *hv_dev, 948 + struct hv_netvsc_packet *packet) 949 + { 950 + u32 page_count = packet->cp_partial ? 951 + packet->page_buf_cnt - packet->rmsg_pgcnt : 952 + packet->page_buf_cnt; 953 + int i; 954 + 955 + if (!hv_is_isolation_supported()) 956 + return; 957 + 958 + if (!packet->dma_range) 959 + return; 960 + 961 + for (i = 0; i < page_count; i++) 962 + dma_unmap_single(&hv_dev->device, packet->dma_range[i].dma, 963 + packet->dma_range[i].mapping_size, 964 + DMA_TO_DEVICE); 965 + 966 + kfree(packet->dma_range); 967 + } 968 + 969 + /* netvsc_dma_map - Map swiotlb bounce buffer with data page of 970 + * packet sent by vmbus_sendpacket_pagebuffer() in the Isolation 971 + * VM. 972 + * 973 + * In isolation VM, netvsc send buffer has been marked visible to 974 + * host and so the data copied to send buffer doesn't need to use 975 + * bounce buffer. The data pages handled by vmbus_sendpacket_pagebuffer() 976 + * may not be copied to send buffer and so these pages need to be 977 + * mapped with swiotlb bounce buffer. netvsc_dma_map() is to do 978 + * that. The pfns in the struct hv_page_buffer need to be converted 979 + * to bounce buffer's pfn. The loop here is necessary because the 980 + * entries in the page buffer array are not necessarily full 981 + * pages of data. Each entry in the array has a separate offset and 982 + * len that may be non-zero, even for entries in the middle of the 983 + * array. And the entries are not physically contiguous. So each 984 + * entry must be individually mapped rather than as a contiguous unit. 985 + * So not use dma_map_sg() here. 986 + */ 987 + static int netvsc_dma_map(struct hv_device *hv_dev, 988 + struct hv_netvsc_packet *packet, 989 + struct hv_page_buffer *pb) 990 + { 991 + u32 page_count = packet->cp_partial ? 992 + packet->page_buf_cnt - packet->rmsg_pgcnt : 993 + packet->page_buf_cnt; 994 + dma_addr_t dma; 995 + int i; 996 + 997 + if (!hv_is_isolation_supported()) 998 + return 0; 999 + 1000 + packet->dma_range = kcalloc(page_count, 1001 + sizeof(*packet->dma_range), 1002 + GFP_KERNEL); 1003 + if (!packet->dma_range) 1004 + return -ENOMEM; 1005 + 1006 + for (i = 0; i < page_count; i++) { 1007 + char *src = phys_to_virt((pb[i].pfn << HV_HYP_PAGE_SHIFT) 1008 + + pb[i].offset); 1009 + u32 len = pb[i].len; 1010 + 1011 + dma = dma_map_single(&hv_dev->device, src, len, 1012 + DMA_TO_DEVICE); 1013 + if (dma_mapping_error(&hv_dev->device, dma)) { 1014 + kfree(packet->dma_range); 1015 + return -ENOMEM; 1016 + } 1017 + 1018 + /* pb[].offset and pb[].len are not changed during dma mapping 1019 + * and so not reassign. 1020 + */ 1021 + packet->dma_range[i].dma = dma; 1022 + packet->dma_range[i].mapping_size = len; 1023 + pb[i].pfn = dma >> HV_HYP_PAGE_SHIFT; 1024 + } 1025 + 1026 + return 0; 1027 + } 1028 + 984 1029 static inline int netvsc_send_pkt( 985 1030 struct hv_device *device, 986 1031 struct hv_netvsc_packet *packet, ··· 1103 984 1104 985 trace_nvsp_send_pkt(ndev, out_channel, rpkt); 1105 986 987 + packet->dma_range = NULL; 1106 988 if (packet->page_buf_cnt) { 1107 989 if (packet->cp_partial) 1108 990 pb += packet->rmsg_pgcnt; 991 + 992 + ret = netvsc_dma_map(ndev_ctx->device_ctx, packet, pb); 993 + if (ret) { 994 + ret = -EAGAIN; 995 + goto exit; 996 + } 1109 997 1110 998 ret = vmbus_sendpacket_pagebuffer(out_channel, 1111 999 pb, packet->page_buf_cnt, 1112 1000 &nvmsg, sizeof(nvmsg), 1113 1001 req_id); 1002 + 1003 + if (ret) 1004 + netvsc_dma_unmap(ndev_ctx->device_ctx, packet); 1114 1005 } else { 1115 1006 ret = vmbus_sendpacket(out_channel, 1116 1007 &nvmsg, sizeof(nvmsg), ··· 1128 999 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 1129 1000 } 1130 1001 1002 + exit: 1131 1003 if (ret == 0) { 1132 1004 atomic_inc_return(&nvchan->queue_sends); 1133 1005
+1
drivers/net/hyperv/netvsc_drv.c
··· 2516 2516 net->netdev_ops = &device_ops; 2517 2517 net->ethtool_ops = &ethtool_ops; 2518 2518 SET_NETDEV_DEV(net, &dev->device); 2519 + dma_set_min_align_mask(&dev->device, HV_HYP_PAGE_SIZE - 1); 2519 2520 2520 2521 /* We always need headroom for rndis header */ 2521 2522 net->needed_headroom = RNDIS_AND_PPI_SIZE;
+2
drivers/net/hyperv/rndis_filter.c
··· 361 361 } 362 362 } 363 363 364 + netvsc_dma_unmap(((struct net_device_context *) 365 + netdev_priv(ndev))->device_ctx, &request->pkt); 364 366 complete(&request->wait_event); 365 367 } else { 366 368 netdev_err(ndev,
+32 -22
drivers/scsi/storvsc_drv.c
··· 21 21 #include <linux/device.h> 22 22 #include <linux/hyperv.h> 23 23 #include <linux/blkdev.h> 24 + #include <linux/dma-mapping.h> 25 + 24 26 #include <scsi/scsi.h> 25 27 #include <scsi/scsi_cmnd.h> 26 28 #include <scsi/scsi_host.h> ··· 1338 1336 continue; 1339 1337 } 1340 1338 request = (struct storvsc_cmd_request *)scsi_cmd_priv(scmnd); 1339 + scsi_dma_unmap(scmnd); 1341 1340 } 1342 1341 1343 1342 storvsc_on_receive(stor_device, packet, request); ··· 1752 1749 struct hv_host_device *host_dev = shost_priv(host); 1753 1750 struct hv_device *dev = host_dev->dev; 1754 1751 struct storvsc_cmd_request *cmd_request = scsi_cmd_priv(scmnd); 1755 - int i; 1756 1752 struct scatterlist *sgl; 1757 - unsigned int sg_count; 1758 1753 struct vmscsi_request *vm_srb; 1759 1754 struct vmbus_packet_mpb_array *payload; 1760 1755 u32 payload_sz; ··· 1825 1824 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length); 1826 1825 1827 1826 sgl = (struct scatterlist *)scsi_sglist(scmnd); 1828 - sg_count = scsi_sg_count(scmnd); 1829 1827 1830 1828 length = scsi_bufflen(scmnd); 1831 1829 payload = (struct vmbus_packet_mpb_array *)&cmd_request->mpb; 1832 1830 payload_sz = sizeof(cmd_request->mpb); 1833 1831 1834 - if (sg_count) { 1835 - unsigned int hvpgoff, hvpfns_to_add; 1832 + if (scsi_sg_count(scmnd)) { 1836 1833 unsigned long offset_in_hvpg = offset_in_hvpage(sgl->offset); 1837 1834 unsigned int hvpg_count = HVPFN_UP(offset_in_hvpg + length); 1838 - u64 hvpfn; 1835 + struct scatterlist *sg; 1836 + unsigned long hvpfn, hvpfns_to_add; 1837 + int j, i = 0, sg_count; 1839 1838 1840 1839 if (hvpg_count > MAX_PAGE_BUFFER_COUNT) { 1841 1840 ··· 1849 1848 payload->range.len = length; 1850 1849 payload->range.offset = offset_in_hvpg; 1851 1850 1851 + sg_count = scsi_dma_map(scmnd); 1852 + if (sg_count < 0) { 1853 + ret = SCSI_MLQUEUE_DEVICE_BUSY; 1854 + goto err_free_payload; 1855 + } 1852 1856 1853 - for (i = 0; sgl != NULL; sgl = sg_next(sgl)) { 1857 + for_each_sg(sgl, sg, sg_count, j) { 1854 1858 /* 1855 - * Init values for the current sgl entry. hvpgoff 1856 - * and hvpfns_to_add are in units of Hyper-V size 1857 - * pages. Handling the PAGE_SIZE != HV_HYP_PAGE_SIZE 1858 - * case also handles values of sgl->offset that are 1859 - * larger than PAGE_SIZE. Such offsets are handled 1860 - * even on other than the first sgl entry, provided 1861 - * they are a multiple of PAGE_SIZE. 1859 + * Init values for the current sgl entry. hvpfns_to_add 1860 + * is in units of Hyper-V size pages. Handling the 1861 + * PAGE_SIZE != HV_HYP_PAGE_SIZE case also handles 1862 + * values of sgl->offset that are larger than PAGE_SIZE. 1863 + * Such offsets are handled even on other than the first 1864 + * sgl entry, provided they are a multiple of PAGE_SIZE. 1862 1865 */ 1863 - hvpgoff = HVPFN_DOWN(sgl->offset); 1864 - hvpfn = page_to_hvpfn(sg_page(sgl)) + hvpgoff; 1865 - hvpfns_to_add = HVPFN_UP(sgl->offset + sgl->length) - 1866 - hvpgoff; 1866 + hvpfn = HVPFN_DOWN(sg_dma_address(sg)); 1867 + hvpfns_to_add = HVPFN_UP(sg_dma_address(sg) + 1868 + sg_dma_len(sg)) - hvpfn; 1867 1869 1868 1870 /* 1869 1871 * Fill the next portion of the PFN array with ··· 1876 1872 * the PFN array is filled. 1877 1873 */ 1878 1874 while (hvpfns_to_add--) 1879 - payload->range.pfn_array[i++] = hvpfn++; 1875 + payload->range.pfn_array[i++] = hvpfn++; 1880 1876 } 1881 1877 } 1882 1878 ··· 1888 1884 put_cpu(); 1889 1885 1890 1886 if (ret == -EAGAIN) { 1891 - if (payload_sz > sizeof(cmd_request->mpb)) 1892 - kfree(payload); 1893 1887 /* no more space */ 1894 - return SCSI_MLQUEUE_DEVICE_BUSY; 1888 + ret = SCSI_MLQUEUE_DEVICE_BUSY; 1889 + goto err_free_payload; 1895 1890 } 1896 1891 1897 1892 return 0; 1893 + 1894 + err_free_payload: 1895 + if (payload_sz > sizeof(cmd_request->mpb)) 1896 + kfree(payload); 1897 + 1898 + return ret; 1898 1899 } 1899 1900 1900 1901 static struct scsi_host_template scsi_driver = { ··· 2025 2016 stor_device->vmscsi_size_delta = sizeof(struct vmscsi_win8_extension); 2026 2017 spin_lock_init(&stor_device->lock); 2027 2018 hv_set_drvdata(device, stor_device); 2019 + dma_set_min_align_mask(&device->device, HV_HYP_PAGE_SIZE - 1); 2028 2020 2029 2021 stor_device->port_number = host->host_no; 2030 2022 ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size, is_fc);
+4 -2
include/asm-generic/mshyperv.h
··· 49 49 }; 50 50 extern struct ms_hyperv_info ms_hyperv; 51 51 52 - extern void __percpu **hyperv_pcpu_input_arg; 53 - extern void __percpu **hyperv_pcpu_output_arg; 52 + extern void * __percpu *hyperv_pcpu_input_arg; 53 + extern void * __percpu *hyperv_pcpu_output_arg; 54 54 55 55 extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr); 56 56 extern u64 hv_do_fast_hypercall8(u16 control, u64 input8); ··· 269 269 u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_size); 270 270 void hyperv_cleanup(void); 271 271 bool hv_query_ext_cap(u64 cap_query); 272 + void *hv_map_memory(void *addr, unsigned long size); 273 + void hv_unmap_memory(void *addr); 272 274 #else /* CONFIG_HYPERV */ 273 275 static inline bool hv_is_hyperv_initialized(void) { return false; } 274 276 static inline bool hv_is_hibernation_supported(void) { return false; }
+6
include/linux/hyperv.h
··· 1261 1261 1262 1262 struct vmbus_channel *channel; 1263 1263 struct kset *channels_kset; 1264 + struct device_dma_parameters dma_parms; 1264 1265 1265 1266 /* place holder to keep track of the dir for hv device in debugfs */ 1266 1267 struct dentry *debug_dir; ··· 1582 1581 guid_t data; 1583 1582 struct vmbus_channel *channel; 1584 1583 void (*callback)(void *context); 1584 + }; 1585 + 1586 + struct hv_dma_range { 1587 + dma_addr_t dma; 1588 + u32 mapping_size; 1585 1589 }; 1586 1590 1587 1591 #define MAX_SRV_VER 0x7ffffff
+6
include/linux/swiotlb.h
··· 73 73 * @end: The end address of the swiotlb memory pool. Used to do a quick 74 74 * range check to see if the memory was in fact allocated by this 75 75 * API. 76 + * @vaddr: The vaddr of the swiotlb memory pool. The swiotlb memory pool 77 + * may be remapped in the memory encrypted case and store virtual 78 + * address for bounce buffer operation. 76 79 * @nslabs: The number of IO TLB blocks (in groups of 64) between @start and 77 80 * @end. For default swiotlb, this is command line adjustable via 78 81 * setup_io_tlb_npages. ··· 95 92 struct io_tlb_mem { 96 93 phys_addr_t start; 97 94 phys_addr_t end; 95 + void *vaddr; 98 96 unsigned long nslabs; 99 97 unsigned long used; 100 98 unsigned int index; ··· 189 185 return false; 190 186 } 191 187 #endif /* CONFIG_DMA_RESTRICTED_POOL */ 188 + 189 + extern phys_addr_t swiotlb_unencrypted_base; 192 190 193 191 #endif /* __LINUX_SWIOTLB_H */
+48 -2
kernel/dma/swiotlb.c
··· 50 50 #include <asm/io.h> 51 51 #include <asm/dma.h> 52 52 53 + #include <linux/io.h> 53 54 #include <linux/init.h> 54 55 #include <linux/memblock.h> 55 56 #include <linux/iommu-helper.h> ··· 72 71 enum swiotlb_force swiotlb_force; 73 72 74 73 struct io_tlb_mem io_tlb_default_mem; 74 + 75 + phys_addr_t swiotlb_unencrypted_base; 75 76 76 77 /* 77 78 * Max segment that we can provide which (if pages are contingous) will ··· 159 156 } 160 157 161 158 /* 159 + * Remap swioltb memory in the unencrypted physical address space 160 + * when swiotlb_unencrypted_base is set. (e.g. for Hyper-V AMD SEV-SNP 161 + * Isolation VMs). 162 + */ 163 + #ifdef CONFIG_HAS_IOMEM 164 + static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) 165 + { 166 + void *vaddr = NULL; 167 + 168 + if (swiotlb_unencrypted_base) { 169 + phys_addr_t paddr = mem->start + swiotlb_unencrypted_base; 170 + 171 + vaddr = memremap(paddr, bytes, MEMREMAP_WB); 172 + if (!vaddr) 173 + pr_err("Failed to map the unencrypted memory %pa size %lx.\n", 174 + &paddr, bytes); 175 + } 176 + 177 + return vaddr; 178 + } 179 + #else 180 + static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) 181 + { 182 + return NULL; 183 + } 184 + #endif 185 + 186 + /* 162 187 * Early SWIOTLB allocation may be too early to allow an architecture to 163 188 * perform the desired operations. This function allows the architecture to 164 189 * call SWIOTLB when the operations are possible. It needs to be called ··· 203 172 vaddr = phys_to_virt(mem->start); 204 173 bytes = PAGE_ALIGN(mem->nslabs << IO_TLB_SHIFT); 205 174 set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); 206 - memset(vaddr, 0, bytes); 175 + 176 + mem->vaddr = swiotlb_mem_remap(mem, bytes); 177 + if (!mem->vaddr) 178 + mem->vaddr = vaddr; 179 + 180 + memset(mem->vaddr, 0, bytes); 207 181 } 208 182 209 183 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, ··· 232 196 mem->slots[i].orig_addr = INVALID_PHYS_ADDR; 233 197 mem->slots[i].alloc_size = 0; 234 198 } 199 + 200 + /* 201 + * If swiotlb_unencrypted_base is set, the bounce buffer memory will 202 + * be remapped and cleared in swiotlb_update_mem_attributes. 203 + */ 204 + if (swiotlb_unencrypted_base) 205 + return; 206 + 235 207 memset(vaddr, 0, bytes); 208 + mem->vaddr = vaddr; 209 + return; 236 210 } 237 211 238 212 int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) ··· 417 371 phys_addr_t orig_addr = mem->slots[index].orig_addr; 418 372 size_t alloc_size = mem->slots[index].alloc_size; 419 373 unsigned long pfn = PFN_DOWN(orig_addr); 420 - unsigned char *vaddr = phys_to_virt(tlb_addr); 374 + unsigned char *vaddr = mem->vaddr + tlb_addr - mem->start; 421 375 unsigned int tlb_offset, orig_addr_offset; 422 376 423 377 if (orig_addr == INVALID_PHYS_ADDR)