On 9/15/2021 11:42 PM, Michael Kelley wrote:
@@ -196,13 +199,34 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem 
*mem, phys_addr_t start,
                mem->slots[i].orig_addr = INVALID_PHYS_ADDR;
                mem->slots[i].alloc_size = 0;
        }
+
+       if (set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT))
+               return -EFAULT;
+
+       /*
+        * Map memory in the unencrypted physical address space when requested
+        * (e.g. for Hyper-V AMD SEV-SNP Isolation VMs).
+        */
+       if (swiotlb_unencrypted_base) {
+               phys_addr_t paddr = __pa(vaddr) + swiotlb_unencrypted_base;
Nit:  Use "start" instead of "__pa(vaddr)" since "start" is already the needed
physical address.


Yes, "start" should be used here.


@@ -304,7 +332,7 @@ int
  swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
  {
        struct io_tlb_mem *mem = &io_tlb_default_mem;
-       unsigned long bytes = nslabs << IO_TLB_SHIFT;
+       int ret;

        if (swiotlb_force == SWIOTLB_NO_FORCE)
                return 0;
@@ -318,8 +346,9 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
        if (!mem->slots)
                return -ENOMEM;

-       set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
-       swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+       ret = swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+       if (ret)
Before returning the error, free the pages obtained from the earlier call
to __get_free_pages()?


Yes, will fix.

Thanks.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to