x86/Hyper-V: Add Hyper-V Isolation VM support
Subsystems (11)
v3 cover x86/Hyper-V: Add Hyper-V Isolation VM support
From: Tianyu Lan <[email protected]>
Hyper-V provides two kinds of Isolation VMs. VBS(Virtualization-based security) and AMD SEV-SNP unenlightened Isolation VMs. This patchset is to add support for these Isolation VM support in Linux.
The memory of these vms are encrypted and host can't access guest memory directly. Hyper-V provides new host visibility hvcall and the guest needs to call new hvcall to mark memory visible to host before sharing memory with host. For security, all network/storage stack memory should not be shared with host and so there is bounce buffer requests.
Vmbus channel ring buffer already plays bounce buffer role because all data from/to host needs to copy from/to between the ring buffer and IO stack memory. So mark vmbus channel ring buffer visible.
There are two exceptions - packets sent by vmbus_sendpacket_ pagebuffer() and vmbus_sendpacket_mpb_desc(). These packets contains IO stack memory address and host will access these memory. So add allocation bounce buffer support in vmbus for these packets.
For SNP isolation VM, guest needs to access the shared memory via extra address space which is specified by Hyper-V CPUID HYPERV_CPUID_ ISOLATION_CONFIG. The access physical address of the shared memory should be bounce buffer memory GPA plus with shared_gpa_boundary reported by CPUID.
Change since v2:
- Remove not UIO driver in Isolation VM patch
- Use vmap_pfn() to replace ioremap_page_range function in order to avoid exposing symbol ioremap_page_range() and ioremap_page_range()
- Call hv set mem host visibility hvcall in set_memory_encrypted/decrypted()
- Enable swiotlb force mode instead of adding Hyper-V dma map/unmap hook
- Fix code style
Tianyu Lan (11):
x86/HV: Initialize GHCB page in Isolation VM
x86/HV: Initialize shared memory boundary in the Isolation VM. x86/Hyper-V: Add new hvcall guest address host visibility support
HV: Add Write/Read MSR registers via ghcb
HV: Add ghcb hvcall support for SNP VM
HV/Vmbus: Add SNP support for VMbus channel initiate message HV/Vmbus: Initialize VMbus ring buffer for Isolation VM
swiotlb: Add bounce buffer remap address setting function HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM HV/Netvsc: Add Isolation VM support for netvsc driver HV/Storvsc: Add Isolation VM support for storvsc driver
arch/x86/hyperv/Makefile | 2 +- arch/x86/hyperv/hv_init.c | 70 +++++-- arch/x86/hyperv/ivm.c | 300 +++++++++++++++++++++++++++++ arch/x86/include/asm/hyperv-tlfs.h | 24 +++ arch/x86/include/asm/mshyperv.h | 85 +++++++- arch/x86/kernel/cpu/mshyperv.c | 5 + arch/x86/mm/pat/set_memory.c | 10 +- arch/x86/xen/pci-swiotlb-xen.c | 3 +- drivers/hv/Kconfig | 1 + drivers/hv/channel.c | 48 ++++- drivers/hv/connection.c | 68 ++++++- drivers/hv/hv.c | 122 ++++++++---- drivers/hv/hyperv_vmbus.h | 3 + drivers/hv/ring_buffer.c | 84 ++++++-- drivers/hv/vmbus_drv.c | 3 + drivers/iommu/hyperv-iommu.c | 81 ++++++++ drivers/net/hyperv/hyperv_net.h | 6 + drivers/net/hyperv/netvsc.c | 125 +++++++++++- drivers/net/hyperv/rndis_filter.c | 3 + drivers/scsi/storvsc_drv.c | 63 +++++- include/asm-generic/hyperv-tlfs.h | 1 + include/asm-generic/mshyperv.h | 18 +- include/linux/hyperv.h | 16 ++ include/linux/swiotlb.h | 5 + kernel/dma/swiotlb.c | 14 +- 25 files changed, 1062 insertions(+), 98 deletions(-) create mode 100644 arch/x86/hyperv/ivm.c
Signature · 1 line
2.25.1
RFC PATCH v3 1/11 x86/HV: Initialize GHCB page in Isolation VM
From: Tianyu Lan <[email protected]>
Hyper-V exposes GHCB page via SEV ES GHCB MSR for SNP guest to communicate with hypervisor. Map GHCB page for all cpus to read/write MSR register and submit hvcall request via GHCB.
--- arch/x86/hyperv/hv_init.c | 60 ++++++++++++++++++++++++++++++--- arch/x86/include/asm/mshyperv.h | 2 ++ include/asm-generic/mshyperv.h | 2 ++ 3 files changed, 60 insertions(+), 4 deletions(-)
arch/x86/hyperv/hv_init.c +56 -4
@@ -60,6 +60,9 @@ static int hv_cpu_init(unsigned int cpu)struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id ()];void **input_arg;struct page *pg; +u64 ghcb_gpa; +void *ghcb_va; +void **ghcb_base;/* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ pg =alloc_pages (irqs_disabled () ?GFP_ATOMIC :GFP_KERNEL , hv_root_partition ?1 :0 );
@@ -106,6 +109,17 @@ static int hv_cpu_init(unsigned int cpu)wrmsrl (HV_X64_MSR_VP_ASSIST_PAGE , val); } +if (ms_hyperv.ghcb_base) { +rdmsrl (MSR_AMD64_SEV_ES_GHCB , ghcb_gpa); + + ghcb_va =ioremap_cache (ghcb_gpa,HV_HYP_PAGE_SIZE ); +if (!ghcb_va) +return -ENOMEM ; + + ghcb_base = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); + *ghcb_base = ghcb_va; + } +return 0 ; }
@@ -201,6 +215,7 @@ static int hv_cpu_die(unsigned int cpu)unsigned long flags;void **input_arg;void *pg; +void **ghcb_va =NULL ;local_irq_save (flags); input_arg = (void **)this_cpu_ptr (hyperv_pcpu_input_arg);
@@ -214,6 +229,13 @@ static int hv_cpu_die(unsigned int cpu) *output_arg =NULL ; } +if (ms_hyperv.ghcb_base) { + ghcb_va = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); +if (*ghcb_va) +iounmap (*ghcb_va); + *ghcb_va =NULL ; + } +local_irq_restore (flags);free_pages ((unsigned long )pg, hv_root_partition ?1 :0 );
@@ -369,6 +391,9 @@ void __init hyperv_init(void)u64 guest_id, required_msrs;union hv_x64_msr_hypercall_contents hypercall_msr;int cpuhp, i; +u64 ghcb_gpa; +void *ghcb_va; +void **ghcb_base;if (x86_hyper_type !=X86_HYPER_MS_HYPERV )return ;
@@ -429,9 +454,24 @@ void __init hyperv_init(void)VMALLOC_END ,GFP_KERNEL ,PAGE_KERNEL_ROX ,VM_FLUSH_RESET_PERMS ,NUMA_NO_NODE , __builtin_return_address(0)); -if (hv_hypercall_pg ==NULL ) { -wrmsrl (HV_X64_MSR_GUEST_OS_ID ,0 ); - goto remove_cpuhp_state; +if (hv_hypercall_pg ==NULL ) + goto clean_guest_os_id; + +if (hv_isolation_type_snp ()) { + ms_hyperv.ghcb_base = alloc_percpu(void *); +if (!ms_hyperv.ghcb_base) + goto clean_guest_os_id; + +rdmsrl (MSR_AMD64_SEV_ES_GHCB , ghcb_gpa); + ghcb_va =ioremap_cache (ghcb_gpa,HV_HYP_PAGE_SIZE ); +if (!ghcb_va) { +free_percpu (ms_hyperv.ghcb_base); + ms_hyperv.ghcb_base =NULL ; + goto clean_guest_os_id; + } + + ghcb_base = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); + *ghcb_base = ghcb_va; }rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64);
@@ -502,7 +542,8 @@ void __init hyperv_init(void)hv_query_ext_cap (0 );return ; -remove_cpuhp_state: +clean_guest_os_id: +wrmsrl (HV_X64_MSR_GUEST_OS_ID ,0 );cpuhp_remove_state (cpuhp); free_vp_assist_page:kfree (hv_vp_assist_page);
@@ -531,6 +572,9 @@ void hyperv_cleanup(void)*/ hv_hypercall_pg =NULL ; +if (ms_hyperv.ghcb_base) +free_percpu (ms_hyperv.ghcb_base); +/* Reset the hypercall page */ hypercall_msr.as_uint64 =0 ;wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64);
@@ -615,6 +659,14 @@ bool hv_is_isolation_supported(void) }EXPORT_SYMBOL_GPL (hv_is_isolation_supported); +DEFINE_STATIC_KEY_FALSE (isolation_type_snp); + +bool hv_isolation_type_snp (void ) +{ +return static_branch_unlikely (&isolation_type_snp); +} +EXPORT_SYMBOL_GPL (hv_isolation_type_snp); +/* Bit mask of the extended capability to query: see HV_EXT_CAPABILITY_xxx */ bool hv_query_ext_cap (u64 cap_query) {
arch/x86/include/asm/mshyperv.h +2 -0
@@ -11,6 +11,8 @@#include <asm/paravirt.h> #include <asm/mshyperv.h> +DECLARE_STATIC_KEY_FALSE (isolation_type_snp); +typedef int (*hyperv_fill_flush_list_func )(struct hv_guest_mapping_flush_list *flush,void *data);
include/asm-generic/mshyperv.h +2 -0
@@ -35,6 +35,7 @@ struct ms_hyperv_info {u32 max_lp_index;u32 isolation_config_a;u32 isolation_config_b; +void __percpu **ghcb_base; };extern struct ms_hyperv_info ms_hyperv;
@@ -224,6 +225,7 @@ bool hv_is_hyperv_initialized(void);bool hv_is_hibernation_supported (void );enum hv_isolation_type hv_get_isolation_type (void );bool hv_is_isolation_supported (void ); +bool hv_isolation_type_snp (void );void hyperv_cleanup (void );bool hv_query_ext_cap (u64 cap_query);#else /* CONFIG_HYPERV */
Signature · 1 line
2.25.1
Re: [RFC PATCH V3 01/11] x86/HV: Initialize GHCB page in Isolation VM
arch/x86/hyperv/hv_init.c static int hv_cpu_init(unsigned int cpu) · line 117
Quoted 6 lines · Tianyu Lan
arch/x86/hyperv/hv_init.c +6
-0+if (ms_hyperv.ghcb_base) { +rdmsrl (MSR_AMD64_SEV_ES_GHCB , ghcb_gpa); + + ghcb_va =ioremap_cache (ghcb_gpa,HV_HYP_PAGE_SIZE ); +if (!ghcb_va) +return -ENOMEM ;
Can you explain this a bit more? We've very much deprecated ioremap_cache in favor of memremap. Why yo you need a __iomem address here? Why do we need the remap here at all?
Does the data structure at this address not have any types that we could use a struct for?
arch/x86/hyperv/hv_init.c void __init hyperv_init(void) · line 467
Quoted 4 lines
arch/x86/hyperv/hv_init.c +4
-0+ +rdmsrl (MSR_AMD64_SEV_ES_GHCB , ghcb_gpa); + ghcb_va =ioremap_cache (ghcb_gpa,HV_HYP_PAGE_SIZE ); +if (!ghcb_va) {
This seems to duplicate the above code.
arch/x86/hyperv/hv_init.c bool hv_is_isolation_supported(void) · line 668
Quoted 5 lines
arch/x86/hyperv/hv_init.c +5
-0+bool hv_isolation_type_snp (void ) +{ +return static_branch_unlikely (&isolation_type_snp); +} +EXPORT_SYMBOL_GPL (hv_isolation_type_snp);
This probably wants a kerneldoc explaining when it should be used.
Re: [RFC PATCH V3 01/11] x86/HV: Initialize GHCB page in Isolation VM
Hi Christoph:
Thanks for your review.
Quoted 11 lines · Christoph Hellwig
arch/x86/hyperv/hv_init.c static int hv_cpu_init(unsigned int cpu) · line 117
Quoted 6 lines · Tianyu Lan
arch/x86/hyperv/hv_init.c +6
-0+if (ms_hyperv.ghcb_base) { +rdmsrl (MSR_AMD64_SEV_ES_GHCB , ghcb_gpa); + + ghcb_va =ioremap_cache (ghcb_gpa,HV_HYP_PAGE_SIZE ); +if (!ghcb_va) +return -ENOMEM ;Can you explain this a bit more? We've very much deprecated
ioremap_cachein favor of memremap. Why yo you need a__iomemaddress here? Why do we need the remap here at all? >
GHCB physical address is an address in extra address space which is above shared gpa boundary reported by Hyper-V CPUID. The addresses below
shared gpa boundary treated as encrypted and the one above is treated as decrypted. System memory is remapped in the extra address space and it starts from the boundary. The shared memory with host needs to use address in the extra address(pa + shared_gpa_boundary) in Linux guest.
Here is to map ghcb page for the communication operations with Hypervisor(e.g, hypercall and read/write MSR) via GHCB page.
memremap() will go through iomem_resource list and the address in extra address space will not be in the list. So I used ioremap_cache(). I will memremap() instead of ioremap() here.
Quoted 2 lines
Does the data structure at this address not have any types that we could use a struct for?
The struct will be added in the following patch. I will refresh the following patch and use the struct hv_ghcb for the mapped point.
Quoted 7 lines
arch/x86/hyperv/hv_init.c void __init hyperv_init(void) · line 467
Quoted 5 lines
arch/x86/hyperv/hv_init.c +4
-0+ +rdmsrl (MSR_AMD64_SEV_ES_GHCB , ghcb_gpa); + ghcb_va =ioremap_cache (ghcb_gpa,HV_HYP_PAGE_SIZE ); +if (!ghcb_va) {This seems to duplicate the above code.
The above is to map ghcb for BSP and here does the same thing for APs Will add a new function to avoid the duplication.
Quoted 8 lines
arch/x86/hyperv/hv_init.c bool hv_is_isolation_supported(void) · line 668
Quoted 6 lines
arch/x86/hyperv/hv_init.c +5
-0+bool hv_isolation_type_snp (void ) +{ +return static_branch_unlikely (&isolation_type_snp); +} +EXPORT_SYMBOL_GPL (hv_isolation_type_snp);This probably wants a kerneldoc explaining when it should be used. >
OK. I will add.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [RFC PATCH V3 01/11] x86/HV: Initialize GHCB page in Isolation VM
In reply to Tianyu LanQuoted 19 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
Hyper-V exposes GHCB page via SEV ES GHCB MSR for SNP guest to communicate with hypervisor. Map GHCB page for all cpus to read/write MSR register and submit hvcall request via GHCB.
Signed-off-by Tianyu Lan <[email protected]>--- arch/x86/hyperv/hv_init.c | 60 ++++++++++++++++++++++++++++++--- arch/x86/include/asm/mshyperv.h | 2 ++ include/asm-generic/mshyperv.h | 2 ++ 3 files changed, 60 insertions(+), 4 deletions(-)arch/x86/hyperv/hv_init.c +0
-0
arch/x86/hyperv/hv_init.c static int hv_cpu_init(unsigned int cpu) · line 65
Quoted 6 lines
arch/x86/hyperv/hv_init.c +3
-0@@ -60,6 +60,9 @@ static int hv_cpu_init(unsigned int cpu)struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id ()];void **input_arg;struct page *pg; +u64 ghcb_gpa; +void *ghcb_va; +void **ghcb_base;
Any reason you can't reuse the SEV-ES support code in the Linux kernel? It already has code to setup GHCBs for all vCPUs.
I see that you don't need #VC handling in your SNP VMs because of the paravisor running underneath it, but just re-using the GHCB setup code shouldn't be too hard.
Regards,
Joerg
Re: [RFC PATCH V3 01/11] x86/HV: Initialize GHCB page in Isolation VM
Hi Joerg:
Thanks for your review.
Quoted 30 lines · Joerg Roedel
Quoted 19 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
Hyper-V exposes GHCB page via SEV ES GHCB MSR for SNP guest to communicate with hypervisor. Map GHCB page for all cpus to read/write MSR register and submit hvcall request via GHCB.
Signed-off-by Tianyu Lan <[email protected]>--- arch/x86/hyperv/hv_init.c | 60 ++++++++++++++++++++++++++++++--- arch/x86/include/asm/mshyperv.h | 2 ++ include/asm-generic/mshyperv.h | 2 ++ 3 files changed, 60 insertions(+), 4 deletions(-)arch/x86/hyperv/hv_init.c +0
-0arch/x86/hyperv/hv_init.c static int hv_cpu_init(unsigned int cpu) · line 65
Quoted 6 lines
arch/x86/hyperv/hv_init.c +3
-0@@ -60,6 +60,9 @@ static int hv_cpu_init(unsigned int cpu)struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id ()];void **input_arg;struct page *pg; +u64 ghcb_gpa; +void *ghcb_va; +void **ghcb_base;Any reason you can't reuse the SEV-ES support code in the Linux kernel? It already has code to setup GHCBs for all vCPUs.
Quoted 4 lines
I see that you don't need #VC handling in your SNP VMs because of the paravisor running underneath it, but just re-using the GHCB setup code shouldn't be too hard.
Thanks for your suggestion. I will have a try to use SEV-ES code.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
RFC PATCH v3 2/11 x86/HV: Initialize shared memory boundary in the Isolation VM.
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
Hyper-V also exposes shared memory boundary via cpuid HYPERV_CPUID_ISOLATION_CONFIG and store it in the shared_gpa_boundary of ms_hyperv struct. This prepares to share memory with host for SNP guest.
--- arch/x86/kernel/cpu/mshyperv.c | 2 ++ include/asm-generic/mshyperv.h | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mshyperv.c +2 -0
@@ -320,6 +320,8 @@ static void __init ms_hyperv_init_platform(void)if (ms_hyperv.priv_high &HV_ISOLATION ) { ms_hyperv.isolation_config_a =cpuid_eax (HYPERV_CPUID_ISOLATION_CONFIG ); ms_hyperv.isolation_config_b =cpuid_ebx (HYPERV_CPUID_ISOLATION_CONFIG ); + ms_hyperv.shared_gpa_boundary = + (u64 )1 << ms_hyperv.shared_gpa_boundary_bits;pr_info ("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n" , ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
include/asm-generic/mshyperv.h +11 -1
@@ -34,8 +34,18 @@ struct ms_hyperv_info {u32 max_vp_index;u32 max_lp_index;u32 isolation_config_a; -u32 isolation_config_b; +union { +u32 isolation_config_b; +struct { +u32 cvm_type :4 ; +u32 Reserved11 :1 ; +u32 shared_gpa_boundary_active :1 ; +u32 shared_gpa_boundary_bits :6 ; +u32 Reserved12 :20 ; + }; + };void __percpu **ghcb_base; +u64 shared_gpa_boundary; };extern struct ms_hyperv_info ms_hyperv;
Signature · 1 line
2.25.1
RFC PATCH v3 3/11 x86/Hyper-V: Add new hvcall guest address host visibility support
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
Add new hvcall guest address host visibility support. Mark vmbus ring buffer visible to host when create gpadl buffer and mark back to not visible when tear down gpadl buffer.
--- arch/x86/hyperv/Makefile | 2 +- arch/x86/hyperv/ivm.c | 106 +++++++++++++++++++++++++++++ arch/x86/include/asm/hyperv-tlfs.h | 24 +++++++ arch/x86/include/asm/mshyperv.h | 4 +- arch/x86/mm/pat/set_memory.c | 10 ++- drivers/hv/channel.c | 38 ++++++++++- include/asm-generic/hyperv-tlfs.h | 1 + include/linux/hyperv.h | 10 +++ 8 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 arch/x86/hyperv/ivm.c
arch/x86/hyperv/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y := hv_init.o mmu.o nested.o irqdomain.o +obj-y := hv_init.o mmu.o nested.o irqdomain.o ivm.o obj-$(CONFIG_X86_64) += hv_apic.o hv_proc.o ifdef CONFIG_X86_64
arch/x86/hyperv/ivm.c new file +106 -0
106 lines not on this page · raw message
arch/x86/include/asm/hyperv-tlfs.h +24 -0
@@ -262,6 +262,17 @@ enum hv_isolation_type {#define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT#define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC +/* Hyper-V GPA map flags */ +#define HV_MAP_GPA_PERMISSIONS_NONE 0x0 +#define HV_MAP_GPA_READABLE 0x1 +#define HV_MAP_GPA_WRITABLE 0x2 + +enum vmbus_page_visibility { +VMBUS_PAGE_NOT_VISIBLE =0 , +VMBUS_PAGE_VISIBLE_READ_ONLY =1 , +VMBUS_PAGE_VISIBLE_READ_WRITE =3 +}; +/* * Declare the MSR used to setup pages used to communicate with the hypervisor. */
@@ -561,4 +572,17 @@ enum hv_interrupt_type {#include <asm-generic/hyperv-tlfs.h> +/* All input parameters should be in single page. */ +#define HV_MAX_MODIFY_GPA_REP_COUNT \ + ((PAGE_SIZE / sizeof(u64)) - 2) + +/* HvCallModifySparseGpaPageHostVisibility hypercall */ +struct hv_gpa_range_for_visibility { +u64 partition_id; +u32 host_visibility:2 ; +u32 reserved0:30 ; +u32 reserved1; +u64 gpa_page_list[HV_MAX_MODIFY_GPA_REP_COUNT ]; +} __packed; +#endif
arch/x86/include/asm/mshyperv.h +3 -1
@@ -194,7 +194,9 @@ struct irq_domain *hv_create_pci_msi_domain(void);int hv_map_ioapic_interrupt (int ioapic_id,bool level,int vcpu,int vector,struct hv_interrupt_entry *entry);int hv_unmap_ioapic_interrupt (int ioapic_id,struct hv_interrupt_entry *entry); - +int hv_mark_gpa_visibility (u16 count,const u64 pfn[],u32 visibility); +int hv_set_mem_host_visibility (void *kbuffer,size_t size, +enum vmbus_page_visibility visibility);#else /* CONFIG_HYPERV */ static inline void hyperv_init (void ) {}static inline void hyperv_setup_mmu_ops (void ) {}
arch/x86/mm/pat/set_memory.c +9 -1
@@ -29,6 +29,8 @@#include <asm/proto.h> #include <asm/memtype.h> #include <asm/set_memory.h> +#include <asm/hyperv-tlfs.h> +#include <asm/mshyperv.h> #include "../mm_internal.h"
@@ -1986,8 +1988,14 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)int ret;/* Nothing to do if memory encryption is not active */ -if (!mem_encrypt_active ()) +if (hv_is_isolation_supported ()) { +return hv_set_mem_host_visibility ((void *)addr, + numpages *HV_HYP_PAGE_SIZE , + enc ?VMBUS_PAGE_NOT_VISIBLE + :VMBUS_PAGE_VISIBLE_READ_WRITE ); + }else if (!mem_encrypt_active ()) {return 0 ; + }/* Should not be working on unaligned addresses */ if (WARN_ONCE (addr & ~PAGE_MASK ,"misaligned address: %#lx\n" , addr))
drivers/hv/channel.c +36 -2
@@ -17,6 +17,7 @@#include <linux/hyperv.h> #include <linux/uio.h> #include <linux/interrupt.h> +#include <linux/set_memory.h> #include <asm/page.h> #include <asm/mshyperv.h>
@@ -465,7 +466,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,struct list_head *curr;u32 next_gpadl_handle;unsigned long flags; -int ret =0 ; +int ret =0 , index; next_gpadl_handle = (atomic_inc_return (&vmbus_connection.next_gpadl_handle) -1 );
@@ -474,6 +475,13 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,if (ret)return ret; + ret =set_memory_decrypted ((unsigned long )kbuffer, +HVPFN_UP (size)); +if (ret) { +pr_warn ("Failed to set host visibility.\n" ); +return ret; + } +init_completion (&msginfo->waitevent); msginfo->waiting_channel = channel;
@@ -539,6 +547,15 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,/* At this point, we received the gpadl created msg */ *gpadl_handle = gpadlmsg->gpadl; +if (type ==HV_GPADL_BUFFER ) + index =0 ; +else + index = channel->gpadl_range[1 ].gpadlhandle ?2 :1 ; + + channel->gpadl_range[index].size = size; + channel->gpadl_range[index].buffer = kbuffer; + channel->gpadl_range[index].gpadlhandle = *gpadl_handle; + cleanup:spin_lock_irqsave (&vmbus_connection.channelmsg_lock, flags);list_del (&msginfo->msglistentry);
@@ -549,6 +566,11 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, }kfree (msginfo); + +if (ret) +set_memory_encrypted ((unsigned long )kbuffer, +HVPFN_UP (size)); +return ret; }
@@ -811,7 +833,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)struct vmbus_channel_gpadl_teardown *msg;struct vmbus_channel_msginfo *info;unsigned long flags; -int ret; +int ret, i; info =kzalloc (sizeof (*info) +sizeof (struct vmbus_channel_gpadl_teardown ),GFP_KERNEL );
@@ -859,6 +881,18 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)spin_unlock_irqrestore (&vmbus_connection.channelmsg_lock, flags);kfree (info); + +/* Find gpadl buffer virtual address and size. */ +for (i =0 ; i <VMBUS_GPADL_RANGE_COUNT ; i++) +if (channel->gpadl_range[i].gpadlhandle == gpadl_handle) +break ; + +if (set_memory_encrypted ((unsigned long )channel->gpadl_range[i].buffer, +HVPFN_UP (channel->gpadl_range[i].size))) +pr_warn ("Fail to set mem host visibility.\n" ); + + channel->gpadl_range[i].gpadlhandle =0 ; +return ret; }EXPORT_SYMBOL_GPL (vmbus_teardown_gpadl);
include/asm-generic/hyperv-tlfs.h +1 -0
@@ -158,6 +158,7 @@ struct ms_hyperv_tsc_page {#define HVCALL_RETARGET_INTERRUPT 0x007e#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 +#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db/* Extended hypercalls */ #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001
include/linux/hyperv.h +10 -0
@@ -809,6 +809,14 @@ struct vmbus_device {#define VMBUS_DEFAULT_MAX_PKT_SIZE 4096 +struct vmbus_gpadl_range { +u32 gpadlhandle; +u32 size; +void *buffer; +}; + +#define VMBUS_GPADL_RANGE_COUNT 3 +struct vmbus_channel {struct list_head listentry;
@@ -829,6 +837,8 @@ struct vmbus_channel {struct completion rescind_event;u32 ringbuffer_gpadlhandle; +/* GPADL_RING and Send/Receive GPADL_BUFFER. */ +struct vmbus_gpadl_range gpadl_range[VMBUS_GPADL_RANGE_COUNT ];/* Allocated memory for ring buffer */ struct page *ringbuffer_page;
Signature · 1 line
2.25.1
Borislav Petkov
maintainerRe: [RFC PATCH V3 03/11] x86/Hyper-V: Add new hvcall guest address host visibility support
Quoted 14 lines · Tianyu Lan
arch/x86/mm/pat/set_memory.c +2
-0@@ -29,6 +29,8 @@#include <asm/proto.h> #include <asm/memtype.h> #include <asm/set_memory.h> +#include <asm/hyperv-tlfs.h> +#include <asm/mshyperv.h> #include "../mm_internal.h"
arch/x86/mm/pat/set_memory.c static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) · line 1995
Quoted 9 lines
arch/x86/mm/pat/set_memory.c +5
-1@@ -1986,8 +1988,14 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)int ret;/* Nothing to do if memory encryption is not active */ -if (!mem_encrypt_active ()) +if (hv_is_isolation_supported ()) { +return hv_set_mem_host_visibility ((void *)addr, + numpages *HV_HYP_PAGE_SIZE , + enc ?VMBUS_PAGE_NOT_VISIBLE + :VMBUS_PAGE_VISIBLE_READ_WRITE );
Put all this gunk in a hv-specific function somewhere in hv-land which you only call from here. This way you probably won't even need to export hv_set_mem_host_visibility() and so on...
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [RFC PATCH V3 03/11] x86/Hyper-V: Add new hvcall guest address host visibility support
Hi Borislav:
Thanks for your review.
Quoted 17 lines · Borislav Petkov
Quoted 16 lines · Tianyu Lan
arch/x86/mm/pat/set_memory.c +2
-0@@ -29,6 +29,8 @@#include <asm/proto.h> #include <asm/memtype.h> #include <asm/set_memory.h> +#include <asm/hyperv-tlfs.h> +#include <asm/mshyperv.h> #include "../mm_internal.h" @@ -1986,8 +1988,14 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)int ret;
Quoted 12 lines
arch/x86/mm/pat/set_memory.c static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) · line 1995
Quoted 7 lines
arch/x86/mm/pat/set_memory.c +5
-1/* Nothing to do if memory encryption is not active */ -if (!mem_encrypt_active ()) +if (hv_is_isolation_supported ()) { +return hv_set_mem_host_visibility ((void *)addr, + numpages *HV_HYP_PAGE_SIZE , + enc ?VMBUS_PAGE_NOT_VISIBLE + :VMBUS_PAGE_VISIBLE_READ_WRITE );Put all this gunk in a hv-specific function somewhere in hv-land which you only call from here. This way you probably won't even need to export
hv_set_mem_host_visibility()and so on...
Good idea. Will update. Thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 03/11] x86/Hyper-V: Add new hvcall guest address host visibility support
In reply to Tianyu LanQuoted 152 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
Add new hvcall guest address host visibility support. Mark vmbus ring buffer visible to host when create gpadl buffer and mark back to not visible when tear down gpadl buffer.
Co-developed-by Sunil Muthuswamy <[email protected]>Signed-off-by Tianyu Lan <[email protected]>--- arch/x86/hyperv/Makefile | 2 +- arch/x86/hyperv/ivm.c | 106 +++++++++++++++++++++++++++++ arch/x86/include/asm/hyperv-tlfs.h | 24 +++++++ arch/x86/include/asm/mshyperv.h | 4 +- arch/x86/mm/pat/set_memory.c | 10 ++- drivers/hv/channel.c | 38 ++++++++++- include/asm-generic/hyperv-tlfs.h | 1 + include/linux/hyperv.h | 10 +++ 8 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 arch/x86/hyperv/ivm.carch/x86/hyperv/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y := hv_init.o mmu.o nested.o irqdomain.o +obj-y := hv_init.o mmu.o nested.o irqdomain.o ivm.o obj-$(CONFIG_X86_64) += hv_apic.o hv_proc.o ifdef CONFIG_X86_64arch/x86/hyperv/ivm.c new file +106
-0@@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Hyper-V Isolation VM interface with paravisor and hypervisor +* +* Author: +* Tianyu Lan <[email protected]> +*/ + +#include <linux/hyperv.h> +#include <linux/types.h> +#include <linux/bitfield.h> +#include <asm/io.h> +#include <asm/mshyperv.h> + +/* +* hv_mark_gpa_visibility - Set pages visible to host via hvcall. +* +* In Isolation VM, all guest memory is encripted from host and guest +* needs to set memory visible to host via hvcall before sharing memory +* with host. +*/ +int hv_mark_gpa_visibility (u16 count,const u64 pfn[],u32 visibility) +{ +struct hv_gpa_range_for_visibility **input_pcpu, *input; +u16 pages_processed; +u64 hv_status; +unsigned long flags; + +/* no-op if partition isolation is not enabled */ +if (!hv_is_isolation_supported ()) +return 0 ; + +if (count >HV_MAX_MODIFY_GPA_REP_COUNT ) { +pr_err ("Hyper-V: GPA count:%d exceeds supported:%lu\n" , count, +HV_MAX_MODIFY_GPA_REP_COUNT ); +return -EINVAL ; + } + +local_irq_save (flags); + input_pcpu = (struct hv_gpa_range_for_visibility **) +this_cpu_ptr (hyperv_pcpu_input_arg); + input = *input_pcpu; +if (unlikely (!input)) { +local_irq_restore (flags); +return -EINVAL ; + } + + input->partition_id =HV_PARTITION_ID_SELF ; + input->host_visibility = visibility; + input->reserved0 =0 ; + input->reserved1 =0 ; +memcpy ((void *)input->gpa_page_list, pfn, count *sizeof (*pfn)); + hv_status =hv_do_rep_hypercall ( +HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY , count, +0 , input, &pages_processed); +local_irq_restore (flags); + +if (!(hv_status &HV_HYPERCALL_RESULT_MASK )) +return 0 ; + +return hv_status &HV_HYPERCALL_RESULT_MASK ; +} +EXPORT_SYMBOL (hv_mark_gpa_visibility); + +/* +* hv_set_mem_host_visibility - Set specified memory visible to host. +* +* In Isolation VM, all guest memory is encrypted from host and guest +* needs to set memory visible to host via hvcall before sharing memory +* with host. This function works as wrap of hv_mark_gpa_visibility() +* with memory base and size. +*/ +int hv_set_mem_host_visibility (void *kbuffer,size_t size, +enum vmbus_page_visibility visibility) +{ +int pagecount = size >>HV_HYP_PAGE_SHIFT ; +u64 *pfn_array; +int ret =0 ; +int i, pfn; + +if (!hv_is_isolation_supported ()) +return 0 ; + + pfn_array =vzalloc (HV_HYP_PAGE_SIZE ); +if (!pfn_array) +return -ENOMEM ; + +for (i =0 , pfn =0 ; i < pagecount; i++) { + pfn_array[pfn] =virt_to_hvpfn (kbuffer + i *HV_HYP_PAGE_SIZE ); + pfn++; + +if (pfn ==HV_MAX_MODIFY_GPA_REP_COUNT || i == pagecount -1 ) { + ret |=hv_mark_gpa_visibility (pfn, pfn_array, visibility); + pfn =0 ; + +if (ret) + goto err_free_pfn_array; + } + } + + err_free_pfn_array: +vfree (pfn_array); +return ret; +} +EXPORT_SYMBOL_GPL (hv_set_mem_host_visibility); +arch/x86/include/asm/hyperv-tlfs.h +1
-0@@ -262,6 +262,17 @@ enum hv_isolation_type {#define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT#define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC +/* Hyper-V GPA map flags */
arch/x86/include/asm/hyperv-tlfs.h enum hv_isolation_type { · line 275
Quoted 10 lines
arch/x86/include/asm/hyperv-tlfs.h +10
-0+#define HV_MAP_GPA_PERMISSIONS_NONE 0x0 +#define HV_MAP_GPA_READABLE 0x1 +#define HV_MAP_GPA_WRITABLE 0x2 + +enum vmbus_page_visibility { +VMBUS_PAGE_NOT_VISIBLE =0 , +VMBUS_PAGE_VISIBLE_READ_ONLY =1 , +VMBUS_PAGE_VISIBLE_READ_WRITE =3 +}; +
Why do we need both flags and the enum? I don't see HV_MAP_GPA_* being used anywhere and VMBUS_PAGE_VISIBLE_READ_WRITE looks like HV_MAP_GPA_READABLE | HV_MAP_GPA_WRITABLE.
As this is used to communicate with the host, I'd suggest to avoid using enum and just use flags everywhere.
Quoted 196 lines
arch/x86/include/asm/hyperv-tlfs.h +13
-0/* * Declare the MSR used to setup pages used to communicate with the hypervisor. */ @@ -561,4 +572,17 @@ enum hv_interrupt_type {#include <asm-generic/hyperv-tlfs.h> +/* All input parameters should be in single page. */ +#define HV_MAX_MODIFY_GPA_REP_COUNT \ + ((PAGE_SIZE / sizeof(u64)) - 2) + +/* HvCallModifySparseGpaPageHostVisibility hypercall */ +struct hv_gpa_range_for_visibility { +u64 partition_id; +u32 host_visibility:2 ; +u32 reserved0:30 ; +u32 reserved1; +u64 gpa_page_list[HV_MAX_MODIFY_GPA_REP_COUNT ]; +} __packed; +#endif arch/x86/include/asm/mshyperv.h +3
-1@@ -194,7 +194,9 @@ struct irq_domain *hv_create_pci_msi_domain(void);int hv_map_ioapic_interrupt (int ioapic_id,bool level,int vcpu,int vector,struct hv_interrupt_entry *entry);int hv_unmap_ioapic_interrupt (int ioapic_id,struct hv_interrupt_entry *entry); - +int hv_mark_gpa_visibility (u16 count,const u64 pfn[],u32 visibility); +int hv_set_mem_host_visibility (void *kbuffer,size_t size, +enum vmbus_page_visibility visibility);#else /* CONFIG_HYPERV */ static inline void hyperv_init (void ) {}static inline void hyperv_setup_mmu_ops (void ) {}arch/x86/mm/pat/set_memory.c +9
-1@@ -29,6 +29,8 @@#include <asm/proto.h> #include <asm/memtype.h> #include <asm/set_memory.h> +#include <asm/hyperv-tlfs.h> +#include <asm/mshyperv.h> #include "../mm_internal.h" @@ -1986,8 +1988,14 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)int ret;/* Nothing to do if memory encryption is not active */ -if (!mem_encrypt_active ()) +if (hv_is_isolation_supported ()) { +return hv_set_mem_host_visibility ((void *)addr, + numpages *HV_HYP_PAGE_SIZE , + enc ?VMBUS_PAGE_NOT_VISIBLE + :VMBUS_PAGE_VISIBLE_READ_WRITE ); + }else if (!mem_encrypt_active ()) {return 0 ; + }/* Should not be working on unaligned addresses */ if (WARN_ONCE (addr & ~PAGE_MASK ,"misaligned address: %#lx\n" , addr))drivers/hv/channel.c +36
-2@@ -17,6 +17,7 @@#include <linux/hyperv.h> #include <linux/uio.h> #include <linux/interrupt.h> +#include <linux/set_memory.h> #include <asm/page.h> #include <asm/mshyperv.h> @@ -465,7 +466,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,struct list_head *curr;u32 next_gpadl_handle;unsigned long flags; -int ret =0 ; +int ret =0 , index; next_gpadl_handle = (atomic_inc_return (&vmbus_connection.next_gpadl_handle) -1 );@@ -474,6 +475,13 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,if (ret)return ret; + ret =set_memory_decrypted ((unsigned long )kbuffer, +HVPFN_UP (size)); +if (ret) { +pr_warn ("Failed to set host visibility.\n" ); +return ret; + } +init_completion (&msginfo->waitevent); msginfo->waiting_channel = channel;@@ -539,6 +547,15 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,/* At this point, we received the gpadl created msg */ *gpadl_handle = gpadlmsg->gpadl; +if (type ==HV_GPADL_BUFFER ) + index =0 ; +else + index = channel->gpadl_range[1 ].gpadlhandle ?2 :1 ; + + channel->gpadl_range[index].size = size; + channel->gpadl_range[index].buffer = kbuffer; + channel->gpadl_range[index].gpadlhandle = *gpadl_handle; + cleanup:spin_lock_irqsave (&vmbus_connection.channelmsg_lock, flags);list_del (&msginfo->msglistentry);@@ -549,6 +566,11 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, }kfree (msginfo); + +if (ret) +set_memory_encrypted ((unsigned long )kbuffer, +HVPFN_UP (size)); +return ret; }@@ -811,7 +833,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)struct vmbus_channel_gpadl_teardown *msg;struct vmbus_channel_msginfo *info;unsigned long flags; -int ret; +int ret, i; info =kzalloc (sizeof (*info) +sizeof (struct vmbus_channel_gpadl_teardown ),GFP_KERNEL );@@ -859,6 +881,18 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)spin_unlock_irqrestore (&vmbus_connection.channelmsg_lock, flags);kfree (info); + +/* Find gpadl buffer virtual address and size. */ +for (i =0 ; i <VMBUS_GPADL_RANGE_COUNT ; i++) +if (channel->gpadl_range[i].gpadlhandle == gpadl_handle) +break ; + +if (set_memory_encrypted ((unsigned long )channel->gpadl_range[i].buffer, +HVPFN_UP (channel->gpadl_range[i].size))) +pr_warn ("Fail to set mem host visibility.\n" ); + + channel->gpadl_range[i].gpadlhandle =0 ; +return ret; }EXPORT_SYMBOL_GPL (vmbus_teardown_gpadl);include/asm-generic/hyperv-tlfs.h +1
-0@@ -158,6 +158,7 @@ struct ms_hyperv_tsc_page {#define HVCALL_RETARGET_INTERRUPT 0x007e#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 +#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db/* Extended hypercalls */ #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001include/linux/hyperv.h +10
-0@@ -809,6 +809,14 @@ struct vmbus_device {#define VMBUS_DEFAULT_MAX_PKT_SIZE 4096 +struct vmbus_gpadl_range { +u32 gpadlhandle; +u32 size; +void *buffer; +}; + +#define VMBUS_GPADL_RANGE_COUNT 3 +struct vmbus_channel {struct list_head listentry;@@ -829,6 +837,8 @@ struct vmbus_channel {struct completion rescind_event;u32 ringbuffer_gpadlhandle; +/* GPADL_RING and Send/Receive GPADL_BUFFER. */ +struct vmbus_gpadl_range gpadl_range[VMBUS_GPADL_RANGE_COUNT ];/* Allocated memory for ring buffer */ struct page *ringbuffer_page;
Signature · 6 lines
Vitaly _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 03/11] x86/Hyper-V: Add new hvcall guest address host visibility support
Hi Vitaly:
Thanks for your review.
Quoted 23 lines · Vitaly Kuznetsov
Quoted 9 lines
arch/x86/include/asm/hyperv-tlfs.h +1
-0@@ -262,6 +262,17 @@ enum hv_isolation_type {#define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT#define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC +/* Hyper-V GPA map flags */ arch/x86/include/asm/hyperv-tlfs.h enum hv_isolation_type { · line 275
Quoted 10 lines
arch/x86/include/asm/hyperv-tlfs.h +10
-0+#define HV_MAP_GPA_PERMISSIONS_NONE 0x0 +#define HV_MAP_GPA_READABLE 0x1 +#define HV_MAP_GPA_WRITABLE 0x2 + +enum vmbus_page_visibility { +VMBUS_PAGE_NOT_VISIBLE =0 , +VMBUS_PAGE_VISIBLE_READ_ONLY =1 , +VMBUS_PAGE_VISIBLE_READ_WRITE =3 +}; +Why do we need both flags and the enum? I don't see HV_MAP_GPA_* being used anywhere and
VMBUS_PAGE_VISIBLE_READ_WRITElooks likeHV_MAP_GPA_READABLE|HV_MAP_GPA_WRITABLE.
Quoted 3 lines
As this is used to communicate with the host, I'd suggest to avoid using enum and just use flags everywhere.
Nice catch. Will update in the next version.
Thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
RFC PATCH v3 4/11 HV: Add Write/Read MSR registers via ghcb
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
Hyper-V provides GHCB protocol to write Synthetic Interrupt Controller MSR registers and these registers are emulated by Hypervisor rather than paravisor in VMPL0.
Hyper-V requests to write SINTx MSR registers twice(once via GHCB and once via wrmsr instruction emulated by paravisor including the proxy bit 21). Guest OS ID MSR also needs to be set via GHCB.
--- arch/x86/hyperv/hv_init.c | 26 +------ arch/x86/hyperv/ivm.c | 125 ++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 78 +++++++++++++++++++- arch/x86/kernel/cpu/mshyperv.c | 3 + drivers/hv/hv.c | 114 +++++++++++++++++++---------- include/asm-generic/mshyperv.h | 4 +- 6 files changed, 287 insertions(+), 63 deletions(-)
arch/x86/hyperv/hv_init.c +4 -22
@@ -472,6 +472,9 @@ void __init hyperv_init(void) ghcb_base = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); *ghcb_base = ghcb_va; + +/* Hyper-V requires to write guest os id via ghcb in SNP IVM. */ +hv_ghcb_msr_write (HV_X64_MSR_GUEST_OS_ID , guest_id); }rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64);
@@ -564,6 +567,7 @@ void hyperv_cleanup(void)/* Reset our OS id */ wrmsrl (HV_X64_MSR_GUEST_OS_ID ,0 ); +hv_ghcb_msr_write (HV_X64_MSR_GUEST_OS_ID ,0 );/* * Reset hypercall page reference before reset the page,
@@ -645,28 +649,6 @@ bool hv_is_hibernation_supported(void) }EXPORT_SYMBOL_GPL (hv_is_hibernation_supported); -enum hv_isolation_type hv_get_isolation_type (void ) -{ -if (!(ms_hyperv.priv_high &HV_ISOLATION )) -return HV_ISOLATION_TYPE_NONE ; -return FIELD_GET (HV_ISOLATION_TYPE , ms_hyperv.isolation_config_b); -} -EXPORT_SYMBOL_GPL (hv_get_isolation_type); - -bool hv_is_isolation_supported (void ) -{ -return hv_get_isolation_type () !=HV_ISOLATION_TYPE_NONE ; -} -EXPORT_SYMBOL_GPL (hv_is_isolation_supported); - -DEFINE_STATIC_KEY_FALSE (isolation_type_snp); - -bool hv_isolation_type_snp (void ) -{ -return static_branch_unlikely (&isolation_type_snp); -} -EXPORT_SYMBOL_GPL (hv_isolation_type_snp); -/* Bit mask of the extended capability to query: see HV_EXT_CAPABILITY_xxx */ bool hv_query_ext_cap (u64 cap_query) {
arch/x86/hyperv/ivm.c +125 -0
137 lines not on this page · raw message
arch/x86/include/asm/mshyperv.h +77 -1
98 lines not on this page · raw message
arch/x86/kernel/cpu/mshyperv.c +3 -0
@@ -325,6 +325,9 @@ static void __init ms_hyperv_init_platform(void)pr_info ("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n" , ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); + +if (hv_get_isolation_type () ==HV_ISOLATION_TYPE_SNP ) +static_branch_enable (&isolation_type_snp); }if (ms_hyperv.hints &HV_X64_ENLIGHTENED_VMCS_RECOMMENDED ) {
drivers/hv/hv.c +75 -39
174 lines not on this page · raw message
include/asm-generic/mshyperv.h +3 -1
@@ -23,6 +23,7 @@#include <linux/bitops.h> #include <linux/cpumask.h> #include <asm/ptrace.h> +#include <asm/mshyperv.h> #include <asm/hyperv-tlfs.h> struct ms_hyperv_info {
@@ -51,6 +52,7 @@ extern struct ms_hyperv_info ms_hyperv;extern u64 hv_do_hypercall (u64 control,void *inputaddr,void *outputaddr);extern u64 hv_do_fast_hypercall8 (u16 control,u64 input8); +extern bool hv_isolation_type_snp (void );/* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */ static inline int hv_result (u64 status)
@@ -145,7 +147,7 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)* possibly deliver another msg from the * hypervisor */ -hv_set_register (HV_REGISTER_EOM ,0 ); +hv_signal_eom (); } }
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [RFC PATCH V3 04/11] HV: Add Write/Read MSR registers via ghcb
Quoted 20 lines · Tianyu Lan
arch/x86/hyperv/ivm.c +20
-0+void hv_ghcb_msr_write (u64 msr,u64 value) +{ +union hv_ghcb *hv_ghcb; +void **ghcb_base; +unsigned long flags; + +if (!ms_hyperv.ghcb_base) +return ; + +local_irq_save (flags); + ghcb_base = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); + hv_ghcb = (union hv_ghcb *)*ghcb_base; +if (!hv_ghcb) { +local_irq_restore (flags); +return ; + } + +memset (hv_ghcb,0x00 ,HV_HYP_PAGE_SIZE ); + + hv_ghcb->ghcb.protocol_version =1 ;
arch/x86/hyperv/ivm.c line 52
Quoted 10 lines
arch/x86/hyperv/ivm.c +10
-0+ hv_ghcb->ghcb.ghcb_usage =0 ; + +ghcb_set_sw_exit_code (&hv_ghcb->ghcb,SVM_EXIT_MSR ); +ghcb_set_rcx (&hv_ghcb->ghcb, msr); +ghcb_set_rax (&hv_ghcb->ghcb,lower_32_bits (value)); +ghcb_set_rdx (&hv_ghcb->ghcb, value >>32 ); +ghcb_set_sw_exit_info_1 (&hv_ghcb->ghcb,1 ); +ghcb_set_sw_exit_info_2 (&hv_ghcb->ghcb,0 ); + +VMGEXIT ();
This is not safe to use from NMI context. You need at least some checking or WARN_ON/assertion/whatever to catch cases where this is violated. Otherwise it will result in some hard to debug bug reports.
Regards,
Joerg
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 04/11] HV: Add Write/Read MSR registers via ghcb
Quoted 27 lines · Joerg Roedel
Quoted 26 lines · Tianyu Lan
arch/x86/hyperv/ivm.c +26
-0+void hv_ghcb_msr_write (u64 msr,u64 value) +{ +union hv_ghcb *hv_ghcb; +void **ghcb_base; +unsigned long flags; + +if (!ms_hyperv.ghcb_base) +return ; + +local_irq_save (flags); + ghcb_base = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); + hv_ghcb = (union hv_ghcb *)*ghcb_base; +if (!hv_ghcb) { +local_irq_restore (flags); +return ; + } + +memset (hv_ghcb,0x00 ,HV_HYP_PAGE_SIZE ); + + hv_ghcb->ghcb.protocol_version =1 ; + hv_ghcb->ghcb.ghcb_usage =0 ; + +ghcb_set_sw_exit_code (&hv_ghcb->ghcb,SVM_EXIT_MSR ); +ghcb_set_rcx (&hv_ghcb->ghcb, msr); +ghcb_set_rax (&hv_ghcb->ghcb,lower_32_bits (value)); +ghcb_set_rdx (&hv_ghcb->ghcb, value >>32 );
Quoted 9 lines
arch/x86/hyperv/ivm.c line 52
Quoted 4 lines
arch/x86/hyperv/ivm.c +4
-0+ghcb_set_sw_exit_info_1 (&hv_ghcb->ghcb,1 ); +ghcb_set_sw_exit_info_2 (&hv_ghcb->ghcb,0 ); + +VMGEXIT ();This is not safe to use from NMI context. You need at least some checking or WARN_ON/assertion/whatever to catch cases where this is violated. Otherwise it will result in some hard to debug bug reports.
Nice catch. Will update in the next version.
Thanks.
RFC PATCH v3 5/11 HV: Add ghcb hvcall support for SNP VM
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
Hyper-V provides ghcb hvcall to handle VMBusHVCALL_SIGNAL_EVENT and HVCALL_POST_MESSAGE
msg in SNP Isolation VM. Add such support.
--- arch/x86/hyperv/ivm.c | 69 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/connection.c | 6 ++- drivers/hv/hv.c | 8 +++- 4 files changed, 82 insertions(+), 2 deletions(-)
arch/x86/hyperv/ivm.c +69 -0
@@ -18,8 +18,77 @@union hv_ghcb {struct ghcb ghcb; +struct { +u64 hypercalldata[509 ]; +u64 outputgpa; +union { +union { +struct { +u32 callcode :16 ; +u32 isfast :1 ; +u32 reserved1 :14 ; +u32 isnested :1 ; +u32 countofelements :12 ; +u32 reserved2 :4 ; +u32 repstartindex :12 ; +u32 reserved3 :4 ; + }; +u64 asuint64; + } hypercallinput; +union { +struct { +u16 callstatus; +u16 reserved1; +u32 elementsprocessed :12 ; +u32 reserved2 :20 ; + }; +u64 asunit64; + } hypercalloutput; + }; +u64 reserved2; + } hypercall; } __packed__aligned(PAGE_SIZE) ; +u64 hv_ghcb_hypercall (u64 control,void *input,void *output,u32 input_size) +{ +union hv_ghcb *hv_ghcb; +void **ghcb_base; +unsigned long flags; + +if (!ms_hyperv.ghcb_base) +return -EFAULT ; + +local_irq_save (flags); + ghcb_base = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); + hv_ghcb = (union hv_ghcb *)*ghcb_base; +if (!hv_ghcb) { +local_irq_restore (flags); +return -EFAULT ; + } + +memset (hv_ghcb,0x00 ,HV_HYP_PAGE_SIZE ); + hv_ghcb->ghcb.protocol_version =1 ; + hv_ghcb->ghcb.ghcb_usage =1 ; + + hv_ghcb->hypercall.outputgpa = (u64 )output; + hv_ghcb->hypercall.hypercallinput.asuint64 =0 ; + hv_ghcb->hypercall.hypercallinput.callcode = control; + +if (input_size) +memcpy (hv_ghcb->hypercall.hypercalldata, input, input_size); + +VMGEXIT (); + + hv_ghcb->ghcb.ghcb_usage =0xffffffff ; +memset (hv_ghcb->ghcb.save.valid_bitmap,0 , +sizeof (hv_ghcb->ghcb.save.valid_bitmap)); + +local_irq_restore (flags); + +return hv_ghcb->hypercall.hypercalloutput.callstatus; +} +EXPORT_SYMBOL_GPL (hv_ghcb_hypercall); +void hv_ghcb_msr_write (u64 msr,u64 value) {union hv_ghcb *hv_ghcb;
arch/x86/include/asm/mshyperv.h +1 -0
@@ -259,6 +259,7 @@ void hv_sint_rdmsrl_ghcb(u64 msr, u64 *value);void hv_signal_eom_ghcb (void );void hv_ghcb_msr_write (u64 msr,u64 value);void hv_ghcb_msr_read (u64 msr,u64 *value); +u64 hv_ghcb_hypercall (u64 control,void *input,void *output,u32 input_size);#define hv_get_synint_state_ghcb (int_num, val) \ hv_sint_rdmsrl_ghcb(HV_X64_MSR_SINT0 + int_num, val)
drivers/hv/connection.c +5 -1
@@ -445,6 +445,10 @@ void vmbus_set_event(struct vmbus_channel *channel) ++channel->sig_events; -hv_do_fast_hypercall8 (HVCALL_SIGNAL_EVENT , channel->sig_event); +if (hv_isolation_type_snp ()) +hv_ghcb_hypercall (HVCALL_SIGNAL_EVENT , &channel->sig_event, +NULL ,sizeof (u64)); +else +hv_do_fast_hypercall8 (HVCALL_SIGNAL_EVENT , channel->sig_event); }EXPORT_SYMBOL_GPL (vmbus_set_event);
drivers/hv/hv.c +7 -1
@@ -97,7 +97,13 @@ int hv_post_message(union hv_connection_id connection_id, aligned_msg->payload_size = payload_size;memcpy ((void *)aligned_msg->payload, payload, payload_size); - status =hv_do_hypercall (HVCALL_POST_MESSAGE , aligned_msg,NULL ); +if (hv_isolation_type_snp ()) + status =hv_ghcb_hypercall (HVCALL_POST_MESSAGE , + (void *)aligned_msg,NULL , +sizeof (struct hv_input_post_message )); +else + status =hv_do_hypercall (HVCALL_POST_MESSAGE , + aligned_msg,NULL );/* Preemption must remain disabled until after the hypercall * so some other thread can't get scheduled onto this cpu and
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [RFC PATCH V3 05/11] HV: Add ghcb hvcall support for SNP VM
Quoted 19 lines · Tianyu Lan
arch/x86/hyperv/ivm.c +19
-0+u64 hv_ghcb_hypercall (u64 control,void *input,void *output,u32 input_size) +{ +union hv_ghcb *hv_ghcb; +void **ghcb_base; +unsigned long flags; + +if (!ms_hyperv.ghcb_base) +return -EFAULT ; + +local_irq_save (flags); + ghcb_base = (void **)this_cpu_ptr (ms_hyperv.ghcb_base); + hv_ghcb = (union hv_ghcb *)*ghcb_base; +if (!hv_ghcb) { +local_irq_restore (flags); +return -EFAULT ; + } + +memset (hv_ghcb,0x00 ,HV_HYP_PAGE_SIZE ); + hv_ghcb->ghcb.protocol_version =1 ;
arch/x86/hyperv/ivm.c line 80
Quoted 10 lines
arch/x86/hyperv/ivm.c +10
-0+ hv_ghcb->ghcb.ghcb_usage =1 ; + + hv_ghcb->hypercall.outputgpa = (u64 )output; + hv_ghcb->hypercall.hypercallinput.asuint64 =0 ; + hv_ghcb->hypercall.hypercallinput.callcode = control; + +if (input_size) +memcpy (hv_ghcb->hypercall.hypercalldata, input, input_size); + +VMGEXIT ();
Also not NMI-safe. When you re-use the existing GHCB setup code from from SEV-ES code, you can also use sev_es_get/put_ghcb() which takes care of re-using a GHCB already in use.
Regards,
Joerg
RFC PATCH v3 6/11 HV/Vmbus: Add SNP support for VMbus channel initiate message
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
The monitor pages in the CHANNELMSG_INITIATE_CONTACT are shared with host and so it's necessary to use hvcall to set them visible to host. In Isolation VM with AMD SEV SNP, the access address should be in the extra space which is above shared gpa boundary. So remap these pages into the extra address(pa + shared_gpa_boundary).
--- drivers/hv/connection.c | 62 +++++++++++++++++++++++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 1 + 2 files changed, 63 insertions(+)
drivers/hv/connection.c +62 -0
@@ -104,6 +104,12 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) msg->monitor_page1 =virt_to_phys (vmbus_connection.monitor_pages[0 ]); msg->monitor_page2 =virt_to_phys (vmbus_connection.monitor_pages[1 ]); + +if (hv_is_isolation_supported ()) { + msg->monitor_page1 += ms_hyperv.shared_gpa_boundary; + msg->monitor_page2 += ms_hyperv.shared_gpa_boundary; + } + msg->target_vcpu =hv_cpu_number_to_vp_number (VMBUS_CONNECT_CPU );/*
@@ -148,6 +154,29 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)return -ECONNREFUSED ; } +if (hv_is_isolation_supported ()) { + vmbus_connection.monitor_pages_va[0 ] + = vmbus_connection.monitor_pages[0 ]; + vmbus_connection.monitor_pages[0 ] + =ioremap_cache (msg->monitor_page1,HV_HYP_PAGE_SIZE ); +if (!vmbus_connection.monitor_pages[0 ]) +return -ENOMEM ; + + vmbus_connection.monitor_pages_va[1 ] + = vmbus_connection.monitor_pages[1 ]; + vmbus_connection.monitor_pages[1 ] + =ioremap_cache (msg->monitor_page2,HV_HYP_PAGE_SIZE ); +if (!vmbus_connection.monitor_pages[1 ]) { +vunmap (vmbus_connection.monitor_pages[0 ]); +return -ENOMEM ; + } + +memset (vmbus_connection.monitor_pages[0 ],0x00 , +HV_HYP_PAGE_SIZE ); +memset (vmbus_connection.monitor_pages[1 ],0x00 , +HV_HYP_PAGE_SIZE ); + } +return ret; }
@@ -159,6 +188,7 @@ int vmbus_connect(void)struct vmbus_channel_msginfo *msginfo =NULL ;int i, ret =0 ;__u32 version; +u64 pfn[2 ];/* Initialize the vmbus connection */ vmbus_connection.conn_state =CONNECTING ;
@@ -216,6 +246,16 @@ int vmbus_connect(void) goto cleanup; } +if (hv_is_isolation_supported ()) { + pfn[0 ] =virt_to_hvpfn (vmbus_connection.monitor_pages[0 ]); + pfn[1 ] =virt_to_hvpfn (vmbus_connection.monitor_pages[1 ]); +if (hv_mark_gpa_visibility (2 , pfn, +VMBUS_PAGE_VISIBLE_READ_WRITE )) { + ret = -EFAULT ; + goto cleanup; + } + } + msginfo =kzalloc (sizeof (*msginfo) +sizeof (struct vmbus_channel_initiate_contact ),GFP_KERNEL );
@@ -282,6 +322,8 @@ int vmbus_connect(void)void vmbus_disconnect (void ) { +u64 pfn[2 ]; +/* * First send the unload request to the host. */
@@ -301,6 +343,26 @@ void vmbus_disconnect(void) vmbus_connection.int_page =NULL ; } +if (hv_is_isolation_supported ()) { +if (vmbus_connection.monitor_pages_va[0 ]) { +vunmap (vmbus_connection.monitor_pages[0 ]); + vmbus_connection.monitor_pages[0 ] + = vmbus_connection.monitor_pages_va[0 ]; + vmbus_connection.monitor_pages_va[0 ] =NULL ; + } + +if (vmbus_connection.monitor_pages_va[1 ]) { +vunmap (vmbus_connection.monitor_pages[1 ]); + vmbus_connection.monitor_pages[1 ] + = vmbus_connection.monitor_pages_va[1 ]; + vmbus_connection.monitor_pages_va[1 ] =NULL ; + } + + pfn[0 ] =virt_to_hvpfn (vmbus_connection.monitor_pages[0 ]); + pfn[1 ] =virt_to_hvpfn (vmbus_connection.monitor_pages[1 ]); +hv_mark_gpa_visibility (2 , pfn,VMBUS_PAGE_NOT_VISIBLE ); + } +hv_free_hyperv_page ((unsigned long )vmbus_connection.monitor_pages[0 ]);hv_free_hyperv_page ((unsigned long )vmbus_connection.monitor_pages[1 ]); vmbus_connection.monitor_pages[0 ] =NULL ;
drivers/hv/hyperv_vmbus.h +1 -0
@@ -240,6 +240,7 @@ struct vmbus_connection {* is child->parent notification */ struct hv_monitor_page *monitor_pages[2 ]; +void *monitor_pages_va[2 ];struct list_head chn_msg_list;spinlock_t channelmsg_lock;
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
RFC PATCH v3 7/11 HV/Vmbus: Initialize VMbus ring buffer for Isolation VM
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
VMbus ring buffer are shared with host and it's need to be accessed via extra address space of Isolation VM with SNP support. This patch is to map the ring buffer address in extra address space via ioremap(). HV host visibility hvcall smears data in the ring buffer and so reset the ring buffer memory to zero after calling visibility hvcall.
--- drivers/hv/Kconfig | 1 + drivers/hv/channel.c | 10 +++++ drivers/hv/hyperv_vmbus.h | 2 + drivers/hv/ring_buffer.c | 84 ++++++++++++++++++++++++++++++--------- 4 files changed, 79 insertions(+), 18 deletions(-)
drivers/hv/Kconfig +1 -0
@@ -7,6 +7,7 @@ config HYPERV depends on X86 && ACPI && X86_LOCAL_APIC && HYPERVISOR_GUEST select PARAVIRT select X86_HV_CALLBACK_VECTOR + select VMAP_PFN help Select this option to run Linux as a Hyper-V client operating system.
drivers/hv/channel.c +10 -0
@@ -707,6 +707,16 @@ static int __vmbus_open(struct vmbus_channel *newchannel,if (err) goto error_clean_ring; + err =hv_ringbuffer_post_init (&newchannel->outbound, + page, send_pages); +if (err) + goto error_free_gpadl; + + err =hv_ringbuffer_post_init (&newchannel->inbound, + &page[send_pages], recv_pages); +if (err) + goto error_free_gpadl; +/* Create and init the channel open message */ open_info = kzalloc(sizeof(*open_info) + sizeof(struct vmbus_channel_open_channel),
drivers/hv/hyperv_vmbus.h +2 -0
@@ -172,6 +172,8 @@ extern int hv_synic_cleanup(unsigned int cpu);/* Interface */ void hv_ringbuffer_pre_init (struct vmbus_channel *channel); +int hv_ringbuffer_post_init (struct hv_ring_buffer_info *ring_info, +struct page *pages,u32 page_cnt);int hv_ringbuffer_init (struct hv_ring_buffer_info *ring_info,struct page *pages,u32 pagecnt,u32 max_pkt_size);
drivers/hv/ring_buffer.c +66 -18
115 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
RFC PATCH v3 8/11 swiotlb: Add bounce buffer remap address setting function
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
For Hyper-V isolation VM with AMD SEV SNP, the bounce buffer(shared memory) needs to be accessed via extra address space(e.g address above bit39). Hyper-V code may remap extra address space outside of swiotlb. swiotlb_ bounce() needs to use remap virtual address to copy data from/to bounce buffer. Add new interface swiotlb_set_bounce_remap() to do that.
--- include/linux/swiotlb.h | 5 +++++ kernel/dma/swiotlb.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-)
include/linux/swiotlb.h +5 -0
@@ -113,8 +113,13 @@ unsigned int swiotlb_max_segment(void);size_t swiotlb_max_mapping_size (struct device *dev);bool is_swiotlb_active (void );void __init swiotlb_adjust_size (unsigned long size); +void swiotlb_set_bounce_remap (unsigned char *vaddr);#else #define swiotlb_force SWIOTLB_NO_FORCE +static inline void swiotlb_set_bounce_remap (unsigned char *vaddr) +{ +} +static inline bool is_swiotlb_buffer (phys_addr_t paddr) {return false;
kernel/dma/swiotlb.c +13 -1
@@ -70,6 +70,7 @@ struct io_tlb_mem *io_tlb_default_mem;* not be bounced (unless SWIOTLB_FORCE is set). */ static unsigned int max_segment; +static unsigned char *swiotlb_bounce_remap_addr;static unsigned long default_nslabs =IO_TLB_DEFAULT_SIZE >>IO_TLB_SHIFT ;
@@ -334,6 +335,11 @@ void __init swiotlb_exit(void) io_tlb_default_mem =NULL ; } +void swiotlb_set_bounce_remap (unsigned char *vaddr) +{ + swiotlb_bounce_remap_addr = vaddr; +} +/* * Bounce: copy the swiotlb buffer from or back to the original dma location */
@@ -345,7 +351,13 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t sizephys_addr_t orig_addr = mem->slots[index].orig_addr;size_t alloc_size = mem->slots[index].alloc_size;unsigned long pfn =PFN_DOWN (orig_addr); -unsigned char *vaddr =phys_to_virt (tlb_addr); +unsigned char *vaddr; + +if (swiotlb_bounce_remap_addr) + vaddr = swiotlb_bounce_remap_addr + tlb_addr - + io_tlb_default_mem->start; +else + vaddr =phys_to_virt (tlb_addr);if (orig_addr ==INVALID_PHYS_ADDR )return ;
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Quoted 7 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
For Hyper-V isolation VM with AMD SEV SNP, the bounce buffer(shared memory) needs to be accessed via extra address space(e.g address above bit39). Hyper-V code may remap extra address space outside of swiotlb.
swiotlb_bounce()needs to use remap virtual address to copy data from/to bounce buffer. Add new interfaceswiotlb_set_bounce_remap()to do that.
Why can't you use the bus_dma_region ranges to remap to your preferred address?
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Quoted 12 lines · Christoph Hellwig
Quoted 7 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
For Hyper-V isolation VM with AMD SEV SNP, the bounce buffer(shared memory) needs to be accessed via extra address space(e.g address above bit39). Hyper-V code may remap extra address space outside of swiotlb.
swiotlb_bounce()needs to use remap virtual address to copy data from/to bounce buffer. Add new interfaceswiotlb_set_bounce_remap()to do that.Why can't you use the
bus_dma_regionranges to remap to your preferred address?
Thanks for your suggestion.
These addresses in extra address space works as system memory mirror. The shared memory with host in Isolation VM needs to be accessed via extra address space which is above shared gpa boundary. During initializing swiotlb bounce buffer pool, only address bellow shared gpa boundary can be accepted by swiotlb API because it is treated as system memory and managed by memory management. This is why Hyper-V swiotlb bounce buffer pool needs to be allocated in Hyper-V code and map associated physical address in extra address space. The patch target is
to add the new interface to set start virtual address of bounce buffer
pool and let swiotlb boucne buffer copy function to use right virtual address for extra address space.
bus_dma_region is to translate cpu physical address to dma address. It can't modify the virtual address of bounce buffer pool and let swiotlb code to copy data with right address. If some thing missed, please correct me.
Thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Quoted 22 lines · Tianyu Lan
Quoted 12 lines · Christoph Hellwig
Quoted 7 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
For Hyper-V isolation VM with AMD SEV SNP, the bounce buffer(shared memory) needs to be accessed via extra address space(e.g address above bit39). Hyper-V code may remap extra address space outside of swiotlb.
swiotlb_bounce()needs to use remap virtual address to copy data from/to bounce buffer. Add new interfaceswiotlb_set_bounce_remap()to do that.Why can't you use the
bus_dma_regionranges to remap to your preferred address?Thanks for your suggestion.
These addresses in extra address space works as system memory mirror. The shared memory with host in Isolation VM needs to be accessed via extra address space which is above shared gpa boundary. During initializing swiotlb bounce buffer pool, only address bellow shared gpa boundary can be accepted by swiotlb API because it is treated as system memory and managed by memory management. This is why Hyper-V swiotlb bounce buffer pool needs to be allocated in Hyper-V code and map associated physical address in extra address space. The patch target is
to add the new interface to set start virtual address of bounce buffer
pool and let swiotlb boucne buffer copy function to use right virtual address for extra address space.
Quoted 5 lines
bus_dma_regionis to translate cpu physical address to dma address. It can't modify the virtual address of bounce buffer pool and let swiotlb code to copy data with right address. If some thing missed, please correct me.
Hi Christoph:
Sorry to bother you. Could you have a look at my previous reply?
I try figuring out the right way.
Thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
In reply to Tianyu LanQuoted 3 lines · Tianyu Lan
These addresses in extra address space works as system memory mirror. The shared memory with host in Isolation VM needs to be accessed via extra address space which is above shared gpa boundary.
Why?
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Tianyu Lan
These addresses in extra address space works as system memory mirror. The shared memory with host in Isolation VM needs to be accessed via extra address space which is above shared gpa boundary.
Why?
IIUC, this is using the vTOM feature of SEV-SNP. When this feature is enabled for a VMPL level, any physical memory addresses below vTOM are considered private/encrypted and any physical memory addresses above vTOM are considered shared/unencrypted. With this option, you don't need a fully enlightened guest that sets and clears page table encryption bits. You just need the DMA buffers to be allocated in the proper range above vTOM.
See the section on "Virtual Machine Privilege Levels" in
https://www.amd.com/system/files/TechDocs/SEV-SNP-strengthening-vm-isolation-with-integrity-protection-and-more.pdf.
Thanks,
Tom
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Quoted 3 lines · Tianyu Lan
These addresses in extra address space works as system memory mirror. The shared memory with host in Isolation VM needs to be accessed via extra address space which is above shared gpa boundary.
Why?
The shared_gpa_boundary in the AMD SEV SNP spec is called virtual top of memory(vTOM). Memory addresses below vTOM are automatically treated as private while memory above vTOM is treated as shared. Using vTOM to separate memory in this way avoids the need to augment the standard x86 page tables with C-bit markings, simplifying guest OS software.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Quoted 8 lines · Tianyu Lan
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Tianyu Lan
These addresses in extra address space works as system memory mirror. The shared memory with host in Isolation VM needs to be accessed via extra address space which is above shared gpa boundary.
Quoted 8 lines
Quoted 2 lines
Why?
The
shared_gpa_boundaryin the AMD SEV SNP spec is called virtual top of memory(vTOM). Memory addresses below vTOM are automatically treated as private while memory above vTOM is treated as shared. Using vTOM to separate memory in this way avoids the need to augment the standard x86 page tables with C-bit markings, simplifying guest OS software.
Here is the spec link and vTOM description is in the page 14.
https://www.amd.com/system/files/TechDocs/SEV-SNP-strengthening-vm-isolation-with-integrity-protection-and-more.pdf
Thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Robin Murphy
reviewerRe: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
In reply to Christoph HellwigQuoted 11 lines · Christoph Hellwig
Quoted 7 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
For Hyper-V isolation VM with AMD SEV SNP, the bounce buffer(shared memory) needs to be accessed via extra address space(e.g address above bit39). Hyper-V code may remap extra address space outside of swiotlb.
swiotlb_bounce()needs to use remap virtual address to copy data from/to bounce buffer. Add new interfaceswiotlb_set_bounce_remap()to do that.Why can't you use the
bus_dma_regionranges to remap to your preferred address?
FWIW, I think a better generalisation for this would be allowing set_memory_decrypted() to return an address rather than implicitly operating in-place, and hide all the various hypervisor hooks behind that.
Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Quoted 3 lines · Robin Murphy
FWIW, I think a better generalisation for this would be allowing
set_memory_decrypted()to return an address rather than implicitly operating in-place, and hide all the various hypervisor hooks behind that.
Yes, something like that would be a good idea. As-is set_memory_decrypted is a pretty horribly API anyway due to passing the address as void, and taking a size parameter while it works in units of pages. So I'd very much welcome a major overhaul of this API.
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Robin Murphy
FWIW, I think a better generalisation for this would be allowing
set_memory_decrypted()to return an address rather than implicitly operating in-place, and hide all the various hypervisor hooks behind that.Yes, something like that would be a good idea. As-is
set_memory_decryptedis a pretty horribly API anyway due to passing the address as void, and taking a size parameter while it works in units of pages. So I'd very much welcome a major overhaul of this API.
Hi Christoph and Robin:
Thanks for your suggestion. I will try this idea in the next version.
Besides make the address translation into set_memory_decrypted() and return address, do you want to make other changes to the API in order to make it more reasonable(e.g size parameter)?
Thanks
Re: [RFC PATCH V3 08/11] swiotlb: Add bounce buffer remap address setting function
Hi Christoph and Robin:
I introduced new interface set_memory_decrypted_map() to hide all
the hypervisor code behind it in the latest version. In current generic
code, only swiotlb bounce buffer needs to be decrypted and remapped in the same time and so keep set_memory_decrypted(). If there were more requests of set_memory_decrypted_map() for other platform, we may replace set_memory_decrypted() step by step. Please have a look.
https://lkml.org/lkml/2021/7/7/570
Thanks.
Quoted 12 lines · Tianyu Lan
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Robin Murphy
FWIW, I think a better generalisation for this would be allowing
set_memory_decrypted()to return an address rather than implicitly operating in-place, and hide all the various hypervisor hooks behind that.Yes, something like that would be a good idea. As-is
set_memory_decryptedis a pretty horribly API anyway due to passing the address as void, and taking a size parameter while it works in units of pages. So I'd very much welcome a major overhaul of this API.
Quoted 6 lines
Hi Christoph and Robin:
Thanks for your suggestion. I will try this idea in the next
version. Besides make the address translation intoset_memory_decrypted()and return address, do you want to make other changes to the API in order to make it more reasonable(e.g size parameter)?Thanks
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
RFC PATCH v3 9/11 HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
Hyper-V Isolation VM requires bounce buffer support to copy data from/to encrypted memory and so enable swiotlb force mode to use swiotlb bounce buffer for DMA transaction.
In Isolation VM with AMD SEV, the bounce buffer needs to be accessed via extra address space which is above shared_gpa_boundary (E.G 39 bit address line) reported by Hyper-V CPUID ISOLATION_CONFIG. The access physical address will be original physical address + shared_gpa_boundary. The shared_gpa_boundary in the AMD SEV SNP spec is called virtual top of memory(vTOM). Memory addresses below vTOM are automatically treated as private while memory above vTOM is treated as shared.
ioremap_cache() can't use in the hyperv_iommu_swiotlb_init() which is too early place and remap bounce buffer in the hyperv_iommu_swiotlb_ later_init().
--- arch/x86/xen/pci-swiotlb-xen.c | 3 +- drivers/hv/vmbus_drv.c | 3 ++ drivers/iommu/hyperv-iommu.c | 81 ++++++++++++++++++++++++++++++++++ include/linux/hyperv.h | 1 + 4 files changed, 87 insertions(+), 1 deletion(-)
arch/x86/xen/pci-swiotlb-xen.c +2 -1
@@ -4,6 +4,7 @@#include <linux/dma-map-ops.h> #include <linux/pci.h> +#include <linux/hyperv.h> #include <xen/swiotlb-xen.h> #include <asm/xen/hypervisor.h>
@@ -91,6 +92,6 @@ int pci_xen_swiotlb_init_late(void)EXPORT_SYMBOL_GPL (pci_xen_swiotlb_init_late);IOMMU_INIT_FINISH (pci_xen_swiotlb_detect, -NULL , + hyperv_swiotlb_detect, pci_xen_swiotlb_init,NULL );
drivers/hv/vmbus_drv.c +3 -0
@@ -23,6 +23,7 @@#include <linux/cpu.h> #include <linux/sched/task_stack.h> +#include <linux/dma-map-ops.h> #include <linux/delay.h> #include <linux/notifier.h> #include <linux/ptrace.h>
@@ -2080,6 +2081,7 @@ struct hv_device *vmbus_device_create(const guid_t *type,return child_device_obj; } +static u64 vmbus_dma_mask =DMA_BIT_MASK (64 );/* * vmbus_device_register - Register the child device */
@@ -2120,6 +2122,7 @@ int vmbus_device_register(struct hv_device *child_device_obj) }hv_debug_add_dev_dir (child_device_obj); + child_device_obj->device.dma_mask = &vmbus_dma_mask;return 0 ; err_kset_unregister:
drivers/iommu/hyperv-iommu.c +81 -0
105 lines not on this page · raw message
include/linux/hyperv.h +1 -0
@@ -1759,6 +1759,7 @@ int hyperv_write_cfg_blk(struct pci_dev *dev, void *buf, unsigned int len,int hyperv_reg_block_invalidate (struct pci_dev *dev,void *context,void (*block_invalidate)(void *context,u64 block_mask)); +int __init hyperv_swiotlb_detect (void );struct hyperv_pci_block_ops { int (*read_block)(struct pci_dev *dev, void *buf, unsigned int buf_len,
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Boris Ostrovsky
reviewerRe: [RFC PATCH V3 09/11] HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM
arch/x86/xen/pci-swiotlb-xen.c int pci_xen_swiotlb_init_late(void) · line 97
Quoted 8 lines · Tianyu Lan
arch/x86/xen/pci-swiotlb-xen.c +1
-1@@ -91,6 +92,6 @@ int pci_xen_swiotlb_init_late(void)EXPORT_SYMBOL_GPL (pci_xen_swiotlb_init_late);IOMMU_INIT_FINISH (2 , -NULL , + hyperv_swiotlb_detect, pci_xen_swiotlb_init,NULL );
Could you explain this change?
-boris
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 09/11] HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM
Hi Boris:
Thanks for your review.
Quoted 5 lines · Boris Ostrovsky
Quoted 3 lines · Tianyu Lan
arch/x86/xen/pci-swiotlb-xen.c +0
-0@@ -91,6 +92,6 @@ int pci_xen_swiotlb_init_late(void)EXPORT_SYMBOL_GPL (pci_xen_swiotlb_init_late);
Quoted 8 lines
arch/x86/xen/pci-swiotlb-xen.c int pci_xen_swiotlb_init_late(void) · line 97
Quoted 5 lines
arch/x86/xen/pci-swiotlb-xen.c +1
-1IOMMU_INIT_FINISH (2 , -NULL , + hyperv_swiotlb_detect, pci_xen_swiotlb_init,NULL );Could you explain this change?
Hyper-V allocates its own swiotlb bounce buffer and the default
swiotlb buffer should not be allocated. swiotlb_init() in pci_swiotlb_init() is to allocate default swiotlb buffer.
To achieve this, put hyperv_swiotlb_detect() as the first entry in the iommu_table_entry list. The detect loop in the pci_iommu_alloc() will exit once hyperv_swiotlb_detect() is called in Hyper-V VM and other iommu_table_entry callback will not be called.
Boris Ostrovsky
reviewerRe: [RFC PATCH V3 09/11] HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM
Quoted 17 lines · Tianyu Lan
Hi Boris:
Thanks for your review.Quoted 12 lines · Boris Ostrovsky
arch/x86/xen/pci-swiotlb-xen.c int pci_xen_swiotlb_init_late(void) · line 96
Quoted 7 lines · Tianyu Lan
arch/x86/xen/pci-swiotlb-xen.c +1
-1@@ -91,6 +92,6 @@ int pci_xen_swiotlb_init_late(void) EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late); IOMMU_INIT_FINISH(2, - NULL, + hyperv_swiotlb_detect, pci_xen_swiotlb_init, NULL);Could you explain this change?
Quoted 3 lines
Hyper-V allocates its own swiotlb bounce buffer and the default
swiotlb buffer should not be allocated.swiotlb_init()inpci_swiotlb_init()is to allocate default swiotlb buffer.
To achieve this, puthyperv_swiotlb_detect()as the first entry in theiommu_table_entrylist. The detect loop in thepci_iommu_alloc()will exit oncehyperv_swiotlb_detect()is called in Hyper-V VM and otheriommu_table_entrycallback will not be called.
Right. But pci_xen_swiotlb_detect() will only do something for Xen PV guests, and those guests don't run on hyperV. It's either xen_pv_domain() (i.e. hypervisor_is_type(X86_HYPER_XEN_PV)) or hypervisor_is_type(X86_HYPER_MS_HYPERV) but never both. So I don't think there needs to be a dependency between the two callbacks.
-boris
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 09/11] HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM
Quoted 19 lines · Boris Ostrovsky
Quoted 17 lines · Tianyu Lan
Hi Boris:
Thanks for your review.Quoted 12 lines · Boris Ostrovsky
arch/x86/xen/pci-swiotlb-xen.c int pci_xen_swiotlb_init_late(void) · line 96
Quoted 7 lines · Tianyu Lan
arch/x86/xen/pci-swiotlb-xen.c +1
-1@@ -91,6 +92,6 @@ int pci_xen_swiotlb_init_late(void) EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late); IOMMU_INIT_FINISH(2, - NULL, + hyperv_swiotlb_detect, pci_xen_swiotlb_init, NULL);Could you explain this change?
Quoted 7 lines
Quoted 3 lines
Hyper-V allocates its own swiotlb bounce buffer and the default
swiotlb buffer should not be allocated.swiotlb_init()inpci_swiotlb_init()is to allocate default swiotlb buffer.
To achieve this, puthyperv_swiotlb_detect()as the first entry in theiommu_table_entrylist. The detect loop in thepci_iommu_alloc()will exit oncehyperv_swiotlb_detect()is called in Hyper-V VM and otheriommu_table_entrycallback will not be called.Right. But
pci_xen_swiotlb_detect()will only do something for Xen PV guests, and those guests don't run on hyperV. It's eitherxen_pv_domain()(i.e.hypervisor_is_type(X86_HYPER_XEN_PV)) orhypervisor_is_type(X86_HYPER_MS_HYPERV)but never both. So I don't think there needs to be a dependency between the two callbacks.
Yes, the dependency is between hyperv_swiotlb_detect() and
pci_swiotlb_detect_override()/pci_swiotlb_detect_4gb(). Nowpci_swiotlb_detect_override() and pci_swiotlb_detect_4gb() depends onpci_xen_swiotlb_detect(). To keep dependency betweenhyperv_swiotlb_detect() and pci_swiotlb_detect_override/4gb(), make pci_xen_swiotlb_detect() depends on hyperv_swiotlb_detect() and just to keep order in the IOMMU table. Current iommu_table_entry only has one
depend callback and this is why I put xen depends on hyperv detect function.
Thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Boris Ostrovsky
reviewerRe: [RFC PATCH V3 09/11] HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM
Quoted 9 lines · Tianyu Lan
Yes, the dependency is between
hyperv_swiotlb_detect()and
pci_swiotlb_detect_override()/pci_swiotlb_detect_4gb(). Nowpci_swiotlb_detect_override()andpci_swiotlb_detect_4gb()depends onpci_xen_swiotlb_detect(). To keep dependency betweenhyperv_swiotlb_detect()and pci_swiotlb_detect_override/4gb(), makepci_xen_swiotlb_detect()depends onhyperv_swiotlb_detect()and just to keep order in the IOMMU table. Currentiommu_table_entryonly has one
depend callback and this is why I put xen depends on hyperv detect function.
Ah, ok. Thanks.
-boris
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 09/11] HV/IOMMU: Enable swiotlb bounce buffer for Isolation VM
Honestly, we really need to do away with the concept of hypervisor- specific swiotlb allocations and just add a hypervisor hook to remap the "main" buffer. That should remove a lot of code and confusion not just for Xen but also any future addition like hyperv.
RFC PATCH v3 10/11 HV/Netvsc: Add Isolation VM support for netvsc driver
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
In Isolation VM, all shared memory with host needs to mark visible to host via hvcall. vmbus_establish_gpadl() has already done it for netvsc rx/tx ring buffer. The page buffer used by vmbus_sendpacket_ pagebuffer() still need to handle. Use DMA API to map/umap these memory during sending/receiving packet and Hyper-V DMA ops callback will use swiotlb function to allocate bounce buffer and copy data from/to bounce buffer.
--- drivers/net/hyperv/hyperv_net.h | 6 ++ drivers/net/hyperv/netvsc.c | 125 ++++++++++++++++++++++++++++-- drivers/net/hyperv/rndis_filter.c | 3 + include/linux/hyperv.h | 5 ++ 4 files changed, 133 insertions(+), 6 deletions(-)
drivers/net/hyperv/hyperv_net.h +6 -0
@@ -164,6 +164,7 @@ struct hv_netvsc_packet {u32 total_bytes;u32 send_buf_index;u32 total_data_buflen; +struct hv_dma_range *dma_range; };#define NETVSC_HASH_KEYLEN 40
@@ -1074,6 +1075,7 @@ struct netvsc_device {/* Receive buffer allocated by us but manages by NetVSP */ void *recv_buf; +void *recv_original_buf;u32 recv_buf_size;/* allocated bytes */ u32 recv_buf_gpadl_handle;u32 recv_section_cnt;
@@ -1082,6 +1084,8 @@ struct netvsc_device {/* Send buffer allocated by us */ void *send_buf; +void *send_original_buf; +u32 send_buf_size;u32 send_buf_gpadl_handle;u32 send_section_cnt;u32 send_section_size;
@@ -1729,4 +1733,6 @@ struct rndis_message {#define RETRY_US_HI 10000#define RETRY_MAX 2000/* >10 sec */ +void netvsc_dma_unmap (struct hv_device *hv_dev, +struct hv_netvsc_packet *packet);#endif /* _HYPERV_NET_H */
drivers/net/hyperv/netvsc.c +119 -6
180 lines not on this page · raw message
drivers/net/hyperv/rndis_filter.c +3 -0
@@ -293,6 +293,8 @@ static void rndis_filter_receive_response(struct net_device *ndev,u32 *req_id = &resp->msg.init_complete.req_id;struct rndis_device *dev = nvdev->extension;struct rndis_request *request =NULL ; +struct hv_device *hv_dev = ((struct net_device_context *) +netdev_priv (ndev))->device_ctx;bool found = false;unsigned long flags;
@@ -361,6 +363,7 @@ static void rndis_filter_receive_response(struct net_device *ndev, } } +netvsc_dma_unmap (hv_dev, &request->pkt);complete (&request->wait_event); }else { netdev_err(ndev,
include/linux/hyperv.h +5 -0
@@ -1616,6 +1616,11 @@ struct hyperv_service_callback {void (*callback)(void *context); }; +struct hv_dma_range { +dma_addr_t dma; +u32 mapping_size; +}; +#define MAX_SRV_VER 0x7ffffff extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf, u32 buflen, const int *fw_version, int fw_vercnt,
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 10/11] HV/Netvsc: Add Isolation VM support for netvsc driver
Quoted 4 lines · Tianyu Lan
drivers/net/hyperv/netvsc.c +4
-0+if (hv_isolation_type_snp ()) { + pfns =kcalloc (buf_size /HV_HYP_PAGE_SIZE ,sizeof (unsigned long ), +GFP_KERNEL ); +for (i =0 ; i < buf_size /HV_HYP_PAGE_SIZE ; i++)
drivers/net/hyperv/netvsc.c static int netvsc_init_buf(struct hv_device *device, · line 406
Quoted 10 lines
drivers/net/hyperv/netvsc.c +10
-0+ pfns[i] =virt_to_hvpfn (net_device->recv_buf + i *HV_HYP_PAGE_SIZE ) + + (ms_hyperv.shared_gpa_boundary >>HV_HYP_PAGE_SHIFT ); + + vaddr =vmap_pfn (pfns, buf_size /HV_HYP_PAGE_SIZE ,PAGE_KERNEL_IO ); +kfree (pfns); +if (!vaddr) + goto cleanup; + net_device->recv_original_buf = net_device->recv_buf; + net_device->recv_buf = vaddr; + }
This probably wnats a helper to make the thing more readable. But who came up with this fucked up communication protocol where the host needs to map random pfns into a contigous range? Sometime I really have to wonder what crack the hyper-v people take when comparing this to the relatively sane approach others take.
drivers/net/hyperv/netvsc.c static void netvsc_copy_to_send_buf(struct netvsc_device *net_device, · line 1014
Quoted 6 lines
drivers/net/hyperv/netvsc.c +6
-0+for (i =0 ; i < page_count; i++) +dma_unmap_single (&hv_dev->device, packet->dma_range[i].dma, + packet->dma_range[i].mapping_size, +DMA_TO_DEVICE ); + +kfree (packet->dma_range);
Any reason this isn't simply using a struct scatterlist?
drivers/net/hyperv/netvsc.c static void netvsc_copy_to_send_buf(struct netvsc_device *net_device, · line 1039
Quoted 7 lines
drivers/net/hyperv/netvsc.c +7
-0+for (i =0 ; i < page_count; i++) { +char *src =phys_to_virt ((pb[i].pfn <<HV_HYP_PAGE_SHIFT ) + + pb[i].offset); +u32 len = pb[i].len; + + dma =dma_map_single (&hv_dev->device, src, len, +DMA_TO_DEVICE );
dma_map_single can only be used on page baked memory, and if this is using page backed memory you wouldn't need to do thee phys_to_virt tricks. Can someone explain the mess here in more detail?
drivers/net/hyperv/rndis_filter.c static void rndis_filter_receive_response(struct net_device *ndev, · line 297
Quoted 4 lines
drivers/net/hyperv/rndis_filter.c +2
-0struct rndis_device *dev = nvdev->extension;struct rndis_request *request =NULL ; +struct hv_device *hv_dev = ((struct net_device_context *) +netdev_priv (ndev))->device_ctx;
Why not use a net_device_context local variable instead of this cast galore?
Re: [RFC PATCH V3 10/11] HV/Netvsc: Add Isolation VM support for netvsc driver
Quoted 13 lines · Christoph Hellwig
Quoted 12 lines · Tianyu Lan
drivers/net/hyperv/netvsc.c +12
-0+if (hv_isolation_type_snp ()) { + pfns =kcalloc (buf_size /HV_HYP_PAGE_SIZE ,sizeof (unsigned long ), +GFP_KERNEL ); +for (i =0 ; i < buf_size /HV_HYP_PAGE_SIZE ; i++) + pfns[i] =virt_to_hvpfn (net_device->recv_buf + i *HV_HYP_PAGE_SIZE ) + + (ms_hyperv.shared_gpa_boundary >>HV_HYP_PAGE_SHIFT ); + + vaddr =vmap_pfn (pfns, buf_size /HV_HYP_PAGE_SIZE ,PAGE_KERNEL_IO ); +kfree (pfns); +if (!vaddr) + goto cleanup; + net_device->recv_original_buf = net_device->recv_buf;
Quoted 8 lines
drivers/net/hyperv/netvsc.c static int netvsc_init_buf(struct hv_device *device, · line 406
Quoted 2 lines
drivers/net/hyperv/netvsc.c +2
-0+ net_device->recv_buf = vaddr; + }This probably wnats a helper to make the thing more readable. But who came up with this fucked up communication protocol where the host needs to map random pfns into a contigous range? Sometime I really have to wonder what crack the hyper-v people take when comparing this to the relatively sane approach others take.
Agree. Will add a helper function.
Quoted 9 lines
drivers/net/hyperv/netvsc.c static void netvsc_copy_to_send_buf(struct netvsc_device *net_device, · line 1014
Quoted 7 lines
drivers/net/hyperv/netvsc.c +6
-0+for (i =0 ; i < page_count; i++) +dma_unmap_single (&hv_dev->device, packet->dma_range[i].dma, + packet->dma_range[i].mapping_size, +DMA_TO_DEVICE ); + +kfree (packet->dma_range);Any reason this isn't simply using a struct scatterlist?
I will have a look. Thanks to reminder scatterlist.
Quoted 12 lines
drivers/net/hyperv/netvsc.c static void netvsc_copy_to_send_buf(struct netvsc_device *net_device, · line 1039
Quoted 8 lines
drivers/net/hyperv/netvsc.c +7
-0+for (i =0 ; i < page_count; i++) { +char *src =phys_to_virt ((pb[i].pfn <<HV_HYP_PAGE_SHIFT ) + + pb[i].offset); +u32 len = pb[i].len; + + dma =dma_map_single (&hv_dev->device, src, len, +DMA_TO_DEVICE );
dma_map_singlecan only be used on page baked memory, and if this is using page backed memory you wouldn't need to do theephys_to_virttricks. Can someone explain the mess here in more detail?
Sorry. Could you elaborate the issue? These pages in the pb array are not allocated by DMA API and using dma_map_single() here is to map these pages' address to bounce buffer physical address.
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c static void rndis_filter_receive_response(struct net_device *ndev, · line 297
Quoted 5 lines
struct rndis_device *dev = nvdev->extension; struct rndis_request *request = NULL;drivers/net/hyperv/rndis_filter.c +2
-0+struct hv_device *hv_dev = ((struct net_device_context *) +netdev_priv (ndev))->device_ctx;Why not use a
net_device_contextlocal variable instead of this cast galore?
OK. I will update.
Thanks.
Re: [RFC PATCH V3 10/11] HV/Netvsc: Add Isolation VM support for netvsc driver
Quoted 7 lines · Tianyu Lan
Quoted 3 lines
dma_map_singlecan only be used on page baked memory, and if this is using page backed memory you wouldn't need to do theephys_to_virttricks. Can someone explain the mess here in more detail?Sorry. Could you elaborate the issue? These pages in the pb array are not allocated by DMA API and using
dma_map_single()here is to map these pages' address to bounce buffer physical address.
dma_map_single just calls dma_map_page using virt_to_page. So this can't work on addresses not in the kernel linear mapping.
Re: [RFC PATCH V3 10/11] HV/Netvsc: Add Isolation VM support for netvsc driver
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Tianyu Lan
Quoted 3 lines
dma_map_singlecan only be used on page baked memory, and if this is using page backed memory you wouldn't need to do theephys_to_virttricks. Can someone explain the mess here in more detail?
Quoted 7 lines
Quoted 3 lines
Sorry. Could you elaborate the issue? These pages in the pb array are not allocated by DMA API and using
dma_map_single()here is to map these pages' address to bounce buffer physical address.
dma_map_singlejust callsdma_map_pageusingvirt_to_page. So this can't work on addresses not in the kernel linear mapping.
The pages in the hv_page_buffer array here are in the kernel linear mapping. The packet sent to host will contain an array which contains transaction data. In the isolation VM, data in the these pages needs to be copied to bounce buffer and so call dma_map_single() here to map these data pages with bounce buffer. The vmbus has ring buffer where the send/receive packets are copied to/from. The ring buffer has been remapped to the extra space above shared gpa boundary/vTom during probing Netvsc driver and so not call dma map function for vmbus ring buffer.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 10/11] HV/Netvsc: Add Isolation VM support for netvsc driver
Quoted 9 lines · Tianyu Lan
The pages in the
hv_page_bufferarray here are in the kernel linear mapping. The packet sent to host will contain an array which contains transaction data. In the isolation VM, data in the these pages needs to be copied to bounce buffer and so calldma_map_single()here to map these data pages with bounce buffer. The vmbus has ring buffer where the send/receive packets are copied to/from. The ring buffer has been remapped to the extra space above shared gpa boundary/vTom during probing Netvsc driver and so not call dma map function for vmbus ring
buffer.
So why do we have all that PFN magic instead of using struct page or the usual kernel I/O buffers that contain a page pointer?
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 10/11] HV/Netvsc: Add Isolation VM support for netvsc driver
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Tianyu Lan
The pages in the
hv_page_bufferarray here are in the kernel linear mapping. The packet sent to host will contain an array which contains transaction data. In the isolation VM, data in the these pages needs to be copied to bounce buffer and so calldma_map_single()here to map these data pages with bounce buffer. The vmbus has ring buffer where the send/receive packets are copied to/from. The ring buffer has been remapped to the extra space above shared gpa boundary/vTom during probing Netvsc driver and so not call dma map function for vmbus ring
buffer.
Quoted 3 lines
So why do we have all that PFN magic instead of using struct page or the usual kernel I/O buffers that contain a page pointer?
These PFNs originally is part of Hyper-V protocol data and will be sent
to host. Host accepts these GFN and copy data from/to guest memory. The translation from va to pa is done by caller that populates the hv_page_buffer array. I will try calling dma map function before populating struct hv_page_buffer and this can avoid redundant translation between PA and VA.
Re: [RFC PATCH V3 10/11] HV/Netvsc: Add Isolation VM support for netvsc driver
In reply to Tianyu LanQuoted 230 lines · Tianyu Lan
From: Tianyu Lan <[email protected]>
In Isolation VM, all shared memory with host needs to mark visible to host via hvcall.
vmbus_establish_gpadl()has already done it for netvsc rx/tx ring buffer. The page buffer used byvmbus_sendpacket_pagebuffer()still need to handle. Use DMA API to map/umap these memory during sending/receiving packet and Hyper-V DMA ops callback will use swiotlb function to allocate bounce buffer and copy data from/to bounce buffer.Signed-off-by Tianyu Lan <[email protected]>--- drivers/net/hyperv/hyperv_net.h | 6 ++ drivers/net/hyperv/netvsc.c | 125 ++++++++++++++++++++++++++++-- drivers/net/hyperv/rndis_filter.c | 3 + include/linux/hyperv.h | 5 ++ 4 files changed, 133 insertions(+), 6 deletions(-)drivers/net/hyperv/hyperv_net.h +6
-0@@ -164,6 +164,7 @@ struct hv_netvsc_packet {u32 total_bytes;u32 send_buf_index;u32 total_data_buflen; +struct hv_dma_range *dma_range; };#define NETVSC_HASH_KEYLEN 40@@ -1074,6 +1075,7 @@ struct netvsc_device {/* Receive buffer allocated by us but manages by NetVSP */ void *recv_buf; +void *recv_original_buf;u32 recv_buf_size;/* allocated bytes */ u32 recv_buf_gpadl_handle;u32 recv_section_cnt;@@ -1082,6 +1084,8 @@ struct netvsc_device {/* Send buffer allocated by us */ void *send_buf; +void *send_original_buf; +u32 send_buf_size;u32 send_buf_gpadl_handle;u32 send_section_cnt;u32 send_section_size;@@ -1729,4 +1733,6 @@ struct rndis_message {#define RETRY_US_HI 10000#define RETRY_MAX 2000/* >10 sec */ +void netvsc_dma_unmap (struct hv_device *hv_dev, +struct hv_netvsc_packet *packet);#endif /* _HYPERV_NET_H */ drivers/net/hyperv/netvsc.c +110
-3@@ -153,8 +153,21 @@ static void free_netvsc_device(struct rcu_head *head)int i;kfree (nvdev->extension); -vfree (nvdev->recv_buf); -vfree (nvdev->send_buf); + +if (nvdev->recv_original_buf) { +vunmap (nvdev->recv_buf); +vfree (nvdev->recv_original_buf); + }else { +vfree (nvdev->recv_buf); + } + +if (nvdev->send_original_buf) { +vunmap (nvdev->send_buf); +vfree (nvdev->send_original_buf); + }else { +vfree (nvdev->send_buf); + } +kfree (nvdev->send_section_map);for (i =0 ; i <VRSS_CHANNEL_MAX ; i++) {@@ -338,8 +351,10 @@ static int netvsc_init_buf(struct hv_device *device,struct net_device *ndev =hv_get_drvdata (device);struct nvsp_message *init_packet;unsigned int buf_size; +unsigned long *pfns;size_t map_words;int i, ret =0 ; +void *vaddr;/* Get receive buffer area. */ buf_size = device_info->recv_sections * device_info->recv_section_size;@@ -375,6 +390,21 @@ static int netvsc_init_buf(struct hv_device *device, goto cleanup; } +if (hv_isolation_type_snp ()) { + pfns =kcalloc (buf_size /HV_HYP_PAGE_SIZE ,sizeof (unsigned long ), +GFP_KERNEL ); +for (i =0 ; i < buf_size /HV_HYP_PAGE_SIZE ; i++) + pfns[i] =virt_to_hvpfn (net_device->recv_buf + i *HV_HYP_PAGE_SIZE ) + + (ms_hyperv.shared_gpa_boundary >>HV_HYP_PAGE_SHIFT ); + + vaddr =vmap_pfn (pfns, buf_size /HV_HYP_PAGE_SIZE ,PAGE_KERNEL_IO ); +kfree (pfns); +if (!vaddr) + goto cleanup; + net_device->recv_original_buf = net_device->recv_buf; + net_device->recv_buf = vaddr; + } +/* Notify the NetVsp of the gpadl handle */ init_packet = &net_device->channel_init_pkt;memset (init_packet,0 ,sizeof (struct nvsp_message ));@@ -477,6 +507,23 @@ static int netvsc_init_buf(struct hv_device *device, goto cleanup; } +if (hv_isolation_type_snp ()) { + pfns =kcalloc (buf_size /HV_HYP_PAGE_SIZE ,sizeof (unsigned long ), +GFP_KERNEL ); + +for (i =0 ; i < buf_size /HV_HYP_PAGE_SIZE ; i++) + pfns[i] =virt_to_hvpfn (net_device->send_buf + i *HV_HYP_PAGE_SIZE ) + + (ms_hyperv.shared_gpa_boundary >>HV_HYP_PAGE_SHIFT ); + + vaddr =vmap_pfn (pfns, buf_size /HV_HYP_PAGE_SIZE ,PAGE_KERNEL_IO ); +kfree (pfns); +if (!vaddr) + goto cleanup; + + net_device->send_original_buf = net_device->send_buf; + net_device->send_buf = vaddr; + } +/* Notify the NetVsp of the gpadl handle */ init_packet = &net_device->channel_init_pkt;memset (init_packet,0 ,sizeof (struct nvsp_message ));@@ -767,7 +814,7 @@ static void netvsc_send_tx_complete(struct net_device *ndev,/* Notify the layer above us */ if (likely (skb)) { -const struct hv_netvsc_packet *packet +struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)skb->cb;u32 send_index = packet->send_buf_index;struct netvsc_stats *tx_stats;@@ -783,6 +830,7 @@ static void netvsc_send_tx_complete(struct net_device *ndev, tx_stats->bytes += packet->total_bytes;u64_stats_update_end (&tx_stats->syncp); +netvsc_dma_unmap (ndev_ctx->device_ctx, packet);napi_consume_skb (skb, budget); }@@ -947,6 +995,63 @@ static void netvsc_copy_to_send_buf(struct netvsc_device *net_device,memset (dest,0 , padding); } +void netvsc_dma_unmap (struct hv_device *hv_dev, +struct hv_netvsc_packet *packet) +{ +u32 page_count = packet->cp_partial ? + packet->page_buf_cnt - packet->rmsg_pgcnt : + packet->page_buf_cnt; +int i; + +if (!packet->dma_range) +return ; + +for (i =0 ; i < page_count; i++) +dma_unmap_single (&hv_dev->device, packet->dma_range[i].dma, + packet->dma_range[i].mapping_size, +DMA_TO_DEVICE ); + +kfree (packet->dma_range); +} + +int netvsc_dma_map (struct hv_device *hv_dev, +struct hv_netvsc_packet *packet, +struct hv_page_buffer *pb) +{ +u32 page_count = packet->cp_partial ? + packet->page_buf_cnt - packet->rmsg_pgcnt : + packet->page_buf_cnt; +dma_addr_t dma; +int i; + + packet->dma_range =kcalloc (page_count, +sizeof (*packet->dma_range), +GFP_KERNEL ); +if (!packet->dma_range) +return -ENOMEM ; + +for (i =0 ; i < page_count; i++) { +char *src =phys_to_virt ((pb[i].pfn <<HV_HYP_PAGE_SHIFT ) + + pb[i].offset); +u32 len = pb[i].len; + + dma =dma_map_single (&hv_dev->device, src, len, +DMA_TO_DEVICE ); +if (dma_mapping_error (&hv_dev->device, dma)) { +kfree (packet->dma_range); +return -ENOMEM ; + } + + packet->dma_range[i].dma = dma; + packet->dma_range[i].mapping_size = len; + pb[i].pfn = dma >>HV_HYP_PAGE_SHIFT ; + pb[i].offset =offset_in_hvpage (dma); + pb[i].len = len; + } + +return 0 ; +} + static inline int netvsc_send_pkt( struct hv_device *device, struct hv_netvsc_packet *packet,@@ -987,14 +1092,22 @@ static inline int netvsc_send_pkt(trace_nvsp_send_pkt (ndev, out_channel, rpkt); + packet->dma_range =NULL ;if (packet->page_buf_cnt) {if (packet->cp_partial) pb += packet->rmsg_pgcnt; + ret =netvsc_dma_map (ndev_ctx->device_ctx, packet, pb);
drivers/net/hyperv/netvsc.c static inline int netvsc_send_pkt( · line 1107
Quoted 10 lines
drivers/net/hyperv/netvsc.c +6
-3+if (ret) +return ret; + ret =vmbus_sendpacket_pagebuffer (out_channel, - pb, packet->page_buf_cnt, - &nvmsg,sizeof (nvmsg), - req_id); + pb, packet->page_buf_cnt, + &nvmsg,sizeof (nvmsg), + req_id);
Nitpick: stray change?
Quoted 43 lines
drivers/net/hyperv/netvsc.c +3
-0+ +if (ret) +netvsc_dma_unmap (ndev_ctx->device_ctx, packet); }else { ret = vmbus_sendpacket(out_channel, &nvmsg, sizeof(nvmsg),drivers/net/hyperv/rndis_filter.c +3
-0@@ -293,6 +293,8 @@ static void rndis_filter_receive_response(struct net_device *ndev,u32 *req_id = &resp->msg.init_complete.req_id;struct rndis_device *dev = nvdev->extension;struct rndis_request *request =NULL ; +struct hv_device *hv_dev = ((struct net_device_context *) +netdev_priv (ndev))->device_ctx;bool found = false;unsigned long flags;@@ -361,6 +363,7 @@ static void rndis_filter_receive_response(struct net_device *ndev, } } +netvsc_dma_unmap (hv_dev, &request->pkt);complete (&request->wait_event); }else { netdev_err(ndev,include/linux/hyperv.h +5
-0@@ -1616,6 +1616,11 @@ struct hyperv_service_callback {void (*callback)(void *context); }; +struct hv_dma_range { +dma_addr_t dma; +u32 mapping_size; +}; +#define MAX_SRV_VER 0x7ffffff extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf, u32 buflen, const int *fw_version, int fw_vercnt,
Signature · 1 line
Vitaly
RFC PATCH v3 11/11 HV/Storvsc: Add Isolation VM support for storvsc driver
In reply to Tianyu LanFrom: Tianyu Lan <[email protected]>
In Isolation VM, all shared memory with host needs to mark visible to host via hvcall. vmbus_establish_gpadl() has already done it for storvsc rx/tx ring buffer. The page buffer used by vmbus_sendpacket_ mpb_desc() still need to handle. Use DMA API to map/umap these memory during sending/receiving packet and Hyper-V DMA ops callback will use swiotlb function to allocate bounce buffer and copy data from/to bounce buffer.
--- drivers/scsi/storvsc_drv.c | 63 +++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 5 deletions(-)
drivers/scsi/storvsc_drv.c +58 -5
@@ -21,6 +21,8 @@#include <linux/device.h> #include <linux/hyperv.h> #include <linux/blkdev.h> +#include <linux/io.h> +#include <linux/dma-mapping.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_host.h>
@@ -427,6 +429,8 @@ struct storvsc_cmd_request {u32 payload_sz;struct vstor_packet vstor_packet; +u32 hvpg_count; +struct hv_dma_range *dma_range; };
@@ -1267,6 +1271,7 @@ static void storvsc_on_channel_callback(void *context)struct hv_device *device;struct storvsc_device *stor_device;struct Scsi_Host *shost; +int i;if (channel->primary_channel !=NULL ) device = channel->primary_channel->device_obj;
@@ -1321,6 +1326,17 @@ static void storvsc_on_channel_callback(void *context) request = (struct storvsc_cmd_request *)scsi_cmd_priv (scmnd); } +if (request->dma_range) { +for (i =0 ; i < request->hvpg_count; i++) +dma_unmap_page (&device->device, + request->dma_range[i].dma, + request->dma_range[i].mapping_size, + request->vstor_packet.vm_srb.data_in + ==READ_TYPE ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); +kfree (request->dma_range); + } +storvsc_on_receive (stor_device, packet, request);continue ; }
@@ -1817,7 +1833,9 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)unsigned int hvpgoff, hvpfns_to_add;unsigned long offset_in_hvpg =offset_in_hvpage (sgl->offset);unsigned int hvpg_count =HVPFN_UP (offset_in_hvpg + length); +dma_addr_t dma;u64 hvpfn; +u32 size;if (hvpg_count >MAX_PAGE_BUFFER_COUNT ) {
@@ -1831,6 +1849,13 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) payload->range.len = length; payload->range.offset = offset_in_hvpg; + cmd_request->dma_range =kcalloc (hvpg_count, +sizeof (*cmd_request->dma_range), +GFP_ATOMIC ); +if (!cmd_request->dma_range) { + ret = -ENOMEM ; + goto free_payload; + }for (i =0 ; sgl !=NULL ; sgl =sg_next (sgl)) {/*
@@ -1854,9 +1879,30 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)* last sgl should be reached at the same time that * the PFN array is filled. */ -while (hvpfns_to_add--) - payload->range.pfn_array[i++] = hvpfn++; +while (hvpfns_to_add--) { + size =min (HV_HYP_PAGE_SIZE - offset_in_hvpg, + (unsigned long )length); + dma =dma_map_page (&dev->device, +pfn_to_page (hvpfn++), + offset_in_hvpg, size, + scmnd->sc_data_direction); +if (dma_mapping_error (&dev->device, dma)) { + ret = -ENOMEM ; + goto free_dma_range; + } + +if (offset_in_hvpg) { + payload->range.offset = dma & ~HV_HYP_PAGE_MASK ; + offset_in_hvpg =0 ; + } + + cmd_request->dma_range[i].dma = dma; + cmd_request->dma_range[i].mapping_size = size; + payload->range.pfn_array[i++] = dma >>HV_HYP_PAGE_SHIFT ; + length -= size; + } } + cmd_request->hvpg_count = hvpg_count; } cmd_request->payload = payload;
@@ -1867,13 +1913,20 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)put_cpu ();if (ret == -EAGAIN ) { -if (payload_sz >sizeof (cmd_request->mpb)) -kfree (payload);/* no more space */ -return SCSI_MLQUEUE_DEVICE_BUSY ; + ret =SCSI_MLQUEUE_DEVICE_BUSY ; + goto free_dma_range; }return 0 ; + +free_dma_range: +kfree (cmd_request->dma_range); + +free_payload: +if (payload_sz >sizeof (cmd_request->mpb)) +kfree (payload); +return ret; }static struct scsi_host_template scsi_driver = {
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RFC PATCH V3 11/11] HV/Storvsc: Add Isolation VM support for storvsc driver
drivers/scsi/storvsc_drv.c static void storvsc_on_channel_callback(void *context) · line 1337
Quoted 8 lines · Tianyu Lan
drivers/scsi/storvsc_drv.c +8
-0+for (i =0 ; i < request->hvpg_count; i++) +dma_unmap_page (&device->device, + request->dma_range[i].dma, + request->dma_range[i].mapping_size, + request->vstor_packet.vm_srb.data_in + ==READ_TYPE ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); +kfree (request->dma_range);
Unreadably long lines. You probably want to factor the quoted code into a little readable helper and do the same for the map side.
Re: [RFC PATCH V3 11/11] HV/Storvsc: Add Isolation VM support for storvsc driver
Quoted 12 lines · Christoph Hellwig
drivers/scsi/storvsc_drv.c static void storvsc_on_channel_callback(void *context) · line 1337
Quoted 8 lines · Tianyu Lan
drivers/scsi/storvsc_drv.c +8
-0+for (i =0 ; i < request->hvpg_count; i++) +dma_unmap_page (&device->device, + request->dma_range[i].dma, + request->dma_range[i].mapping_size, + request->vstor_packet.vm_srb.data_in + ==READ_TYPE ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); +kfree (request->dma_range);Unreadably long lines. You probably want to factor the quoted code into a little readable helper and do the same for the map side.
Good suggestion. Will update.
Thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu