Inter-revision diff: patch 9

Comparing v3 (message) to v4 (message)

--- v3
+++ v4
@@ -13,17 +13,29 @@
 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().
+Swiotlb bounce buffer code calls set_memory_decrypted_map()
+to mark bounce buffer visible to host and map it in extra
+address space.
+
+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.
+
+The map function vmap_pfn() can't work in the early place
+hyperv_iommu_swiotlb_init() and so initialize swiotlb bounce
+buffer in the hyperv_iommu_swiotlb_later_init().
 
 Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
 ---
  arch/x86/xen/pci-swiotlb-xen.c |  3 +-
  drivers/hv/vmbus_drv.c         |  3 ++
- drivers/iommu/hyperv-iommu.c   | 81 ++++++++++++++++++++++++++++++++++
+ drivers/iommu/hyperv-iommu.c   | 62 ++++++++++++++++++++++++++++++++++
  include/linux/hyperv.h         |  1 +
- 4 files changed, 87 insertions(+), 1 deletion(-)
+ 4 files changed, 68 insertions(+), 1 deletion(-)
 
 diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
 index 54f9aa7e8457..43bd031aa332 100644
@@ -74,7 +86,7 @@
  
  err_kset_unregister:
 diff --git a/drivers/iommu/hyperv-iommu.c b/drivers/iommu/hyperv-iommu.c
-index e285a220c913..2604619c6fa3 100644
+index e285a220c913..d7ea8e05b991 100644
 --- a/drivers/iommu/hyperv-iommu.c
 +++ b/drivers/iommu/hyperv-iommu.c
 @@ -13,14 +13,22 @@
@@ -109,35 +121,27 @@
  static int hyperv_ir_set_affinity(struct irq_data *data,
  		const struct cpumask *mask, bool force)
  {
-@@ -337,4 +347,75 @@ static const struct irq_domain_ops hyperv_root_ir_domain_ops = {
+@@ -337,4 +347,56 @@ static const struct irq_domain_ops hyperv_root_ir_domain_ops = {
  	.free = hyperv_root_irq_remapping_free,
  };
  
 +void __init hyperv_iommu_swiotlb_init(void)
 +{
-+	unsigned long bytes, io_tlb_nslabs;
++	unsigned long bytes;
 +	void *vstart;
 +
-+	/* Allocate Hyper-V swiotlb  */
-+	bytes = 200 * 1024 * 1024;
-+	vstart = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE);
-+	io_tlb_nslabs = bytes >> IO_TLB_SHIFT;
-+	hyperv_io_tlb_size = bytes;
++	/*
++	 * Allocate Hyper-V swiotlb bounce buffer at early place
++	 * to reserve large contiguous memory.
++	 */
++	hyperv_io_tlb_size = 200 * 1024 * 1024;
++	hyperv_io_tlb_start = memblock_alloc_low(PAGE_ALIGN(hyperv_io_tlb_size),
++						 HV_HYP_PAGE_SIZE);
 +
-+	if (!vstart) {
-+		pr_warn("Fail to allocate swiotlb.\n");
++	if (!hyperv_io_tlb_start) {
++		pr_warn("Fail to allocate Hyper-V swiotlb buffer.\n");
 +		return;
 +	}
-+
-+	hyperv_io_tlb_start = virt_to_phys(vstart);
-+	if (!hyperv_io_tlb_start)
-+		panic("%s: Failed to allocate %lu bytes align=0x%lx.\n",
-+		      __func__, PAGE_ALIGN(bytes), PAGE_SIZE);
-+
-+	if (swiotlb_init_with_tbl(vstart, io_tlb_nslabs, 1))
-+		panic("%s: Cannot allocate SWIOTLB buffer.\n", __func__);
-+
-+	swiotlb_set_max_segment(HV_HYP_PAGE_SIZE);
 +}
 +
 +int __init hyperv_swiotlb_detect(void)
@@ -160,24 +164,13 @@
 +	void *hyperv_io_tlb_remap;
 +	int ret;
 +
-+	/* Mask bounce buffer visible to host and remap extra address. */
-+	if (hv_isolation_type_snp()) {
-+		ret = set_memory_decrypted((unsigned long)
-+				phys_to_virt(hyperv_io_tlb_start),
-+				HVPFN_UP(hyperv_io_tlb_size));
-+		if (ret)
-+			panic("%s: Fail to mark Hyper-v swiotlb buffer visible to host. err=%d\n",
-+			      __func__, ret);
-+
-+		hyperv_io_tlb_remap = ioremap_cache(hyperv_io_tlb_start
-+				+ ms_hyperv.shared_gpa_boundary,
-+				hyperv_io_tlb_size);
-+		if (!hyperv_io_tlb_remap)
-+			panic("Fail to remap io tlb.\n");
-+
-+		memset(hyperv_io_tlb_remap, 0x00, hyperv_io_tlb_size);
-+		swiotlb_set_bounce_remap(hyperv_io_tlb_remap);
-+	}
++	/*
++	 * Swiotlb bounce buffer needs to be mapped in extra address
++	 * space. Map function doesn't work in the early place and so
++	 * call swiotlb_late_init_with_tbl() here.
++	 */
++	swiotlb_late_init_with_tbl(hyperv_io_tlb_start,
++				   hyperv_io_tlb_size >> IO_TLB_SHIFT);
 +}
 +
 +IOMMU_INIT_FINISH(hyperv_swiotlb_detect,
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help