Message ID | 20211205081815.129276-1-ltykernel@gmail.com |
---|---|
Headers | show |
Series | x86/Hyper-V: Add Hyper-V Isolation VM support(Second part) | expand |
On 12/5/2021 4:34 PM, Juergen Gross wrote: > On 05.12.21 09:18, Tianyu Lan wrote: >> From: Tianyu Lan <Tianyu.Lan@microsoft.com> >> >> hyperv 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. >> >> Hyper-V initalizes swiotlb bounce buffer and default swiotlb >> needs to be disabled. pci_swiotlb_detect_override() and >> pci_swiotlb_detect_4gb() enable the default one. To override >> the setting, hyperv_swiotlb_detect() needs to run before >> these detect functions which depends on the pci_xen_swiotlb_ >> init(). Make pci_xen_swiotlb_init() depends on the hyperv_swiotlb >> _detect() to keep the order. > > Why? Does Hyper-V plan to support Xen PV guests? If not, I don't see > the need for adding this change. > This is to keep detect function calling order that Hyper-V detect callback needs to call before pci_swiotlb_detect_override() and pci_swiotlb_detect_4gb(). This is the same for why pci_swiotlb_detect_override() needs to depend on the pci_xen_swiotlb_detect(). Hyper-V also has such request and so make xen detect callback depends on Hyper-V one.
Please spell swiotlb with a lower case s. Otherwise this look good
Acked-by: Christoph Hellwig <hch@lst.de>
Feel free to carry this in whatever tree is suitable for the rest of the
patches.
On 12/6/2021 10:09 PM, Christoph Hellwig wrote: > Please spell swiotlb with a lower case s. Otherwise this look good > > Acked-by: Christoph Hellwig <hch@lst.de> > > Feel free to carry this in whatever tree is suitable for the rest of the > patches. > Sure. Thanks for your ack and will update "swiotlb" in the next version.
On 12/5/2021 6:31 PM, Juergen Gross wrote: > On 05.12.21 09:48, Tianyu Lan wrote: >> >> >> On 12/5/2021 4:34 PM, Juergen Gross wrote: >>> On 05.12.21 09:18, Tianyu Lan wrote: >>>> From: Tianyu Lan <Tianyu.Lan@microsoft.com> >>>> >>>> hyperv 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. >>>> >>>> Hyper-V initalizes swiotlb bounce buffer and default swiotlb >>>> needs to be disabled. pci_swiotlb_detect_override() and >>>> pci_swiotlb_detect_4gb() enable the default one. To override >>>> the setting, hyperv_swiotlb_detect() needs to run before >>>> these detect functions which depends on the pci_xen_swiotlb_ >>>> init(). Make pci_xen_swiotlb_init() depends on the hyperv_swiotlb >>>> _detect() to keep the order. >>> >>> Why? Does Hyper-V plan to support Xen PV guests? If not, I don't see >>> the need for adding this change. >>> >> >> This is to keep detect function calling order that Hyper-V detect >> callback needs to call before pci_swiotlb_detect_override() and >> pci_swiotlb_detect_4gb(). This is the same for why >> pci_swiotlb_detect_override() needs to depend on the >> pci_xen_swiotlb_detect(). Hyper-V also has such request and so make >> xen detect callback depends on Hyper-V one. > > And does this even work without CONFIG_SWIOTLB_XEN, i.e. without > pci_xen_swiotlb_detect() being in the system? > Hi Juergen: Thanks for your review. This is a issue and I just sent out a v5 which decouples the dependency between xen and hyperv.
From: Tianyu Lan <Tianyu.Lan@microsoft.com> 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. 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. This patchset is to enable swiotlb bounce buffer for netvsc/storvsc in Isolation VM. This version follows Michael Kelley suggestion in the following link. https://lkml.org/lkml/2021/11/24/2044 Change since v3: * Fix boot up failure on the host with mem_encrypt=on. Move calloing of set_memory_decrypted() back from swiotlb_init_io_tlb_mem to swiotlb_late_init_with_tbl() and rmem_swiotlb_device_init(). * Change code style of checking GUEST_MEM attribute in the hyperv_cc_platform_has(). * Add comment in pci-swiotlb-xen.c to explain why add dependency between hyperv_swiotlb_detect() and pci_ xen_swiotlb_detect(). * Return directly when fails to allocate Hyper-V swiotlb buffer in the hyperv_iommu_swiotlb_init(). Change since v2: * Remove Hyper-V dma ops and dma_alloc/free_noncontiguous. Add hv_map/unmap_memory() to map/umap netvsc rx/tx ring into extra address space. * Leave mem->vaddr in swiotlb code with phys_to_virt(mem->start) when fail to remap swiotlb memory. Change since v1: * Add Hyper-V Isolation support check in the cc_platform_has() and return true for guest memory encrypt attr. * Remove hv isolation check in the sev_setup_arch() Tianyu Lan (5): Swiotlb: Add Swiotlb bounce buffer remap function for HV IVM x86/hyper-v: Add hyperv Isolation VM check in the cc_platform_has() hyperv/IOMMU: Enable swiotlb bounce buffer for Isolation VM scsi: storvsc: Add Isolation VM support for storvsc driver hv_netvsc: Add Isolation VM support for netvsc driver arch/x86/hyperv/ivm.c | 28 ++++++ arch/x86/kernel/cc_platform.c | 12 +++ arch/x86/xen/pci-swiotlb-xen.c | 12 ++- drivers/hv/hv_common.c | 11 +++ drivers/hv/vmbus_drv.c | 4 + drivers/iommu/hyperv-iommu.c | 58 +++++++++++++ drivers/net/hyperv/hyperv_net.h | 5 ++ drivers/net/hyperv/netvsc.c | 136 +++++++++++++++++++++++++++++- drivers/net/hyperv/netvsc_drv.c | 1 + drivers/net/hyperv/rndis_filter.c | 2 + drivers/scsi/storvsc_drv.c | 37 ++++---- include/asm-generic/mshyperv.h | 2 + include/linux/hyperv.h | 14 +++ include/linux/swiotlb.h | 6 ++ kernel/dma/swiotlb.c | 43 +++++++++- 15 files changed, 349 insertions(+), 22 deletions(-)