| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
 Re: [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl
 
To: Christoph Hellwig <hch@xxxxxx>, iommu@xxxxxxxxxxxxxxxxxxxxxxxxxxFrom: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>Date: Mon, 14 Mar 2022 19:11:55 -0400Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=noneArc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3MuYOLTOkylaHJzU8Tl5QA/7wYuewROYqN/cIfLF+8A=; b=fFqf1COeKM460F7stQVFHzX1oMZicnWpgRGzk3+CD7j/cjXwzVxhntGHO9wMCF/tY0RExb+zjzJ0pHC7WKVajxZviZ5Ft8ovgmkh/qace9hblVTRg65NSqatCedb5jfYpYhLlOlV4ORbXkkxDITIPn2aCBLvNCZYj81W8keYyYjkRY6QcgpCe3k0Qm1FEulBmlSx2BfqZBAV2oiXDA5Ixd1yLBXR4m863gMxDd/k2eLFpGjpAe4/U53bTFDibHK6DuGyysQg6a9bOl/iqyNbLWPEjW38/VG9nVy6I6z32pk7uH/IGBQq71FdKzuwt+IeRUBlts3XlonXD6ZCHzICjA==Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aKaTad3FPHeZAPyJave5/Te4e/R8bfgkZ6OENMhHOkz1cB9XTEoBWAqZcKpxruc8bdQpIw9/TnU4GuHpWp9sSfSQr9cigVrIlPvEfL9i8Pp9JzEGSr1Qr/ttp4IOl8ztfGoySqL2Qs8OO7ZUTDYarcddPQU5gTHSecwRfCxQ0kNtOp+qKSrGrf01RVsmRMeaZhqnRqnkJW+uCqym1RzibotPqfqe3NcNpk3GrYKsTCBhxyA1h8X15OhOtr1UtvXIMOuzgscV8LRb6TPUZ3drODl4aUPXKpwL16frkqxpmNhuSUDEYIwz/O7PxYykb8zploF7Y1WFJzokiJNgnyCsjw==Cc: x86@xxxxxxxxxx, Anshuman Khandual <anshuman.khandual@xxxxxxx>,        Tom Lendacky <thomas.lendacky@xxxxxxx>,        Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>,        Stefano Stabellini <sstabellini@xxxxxxxxxx>,        Juergen Gross <jgross@xxxxxxxx>, Joerg Roedel <joro@xxxxxxxxxx>,        David Woodhouse <dwmw2@xxxxxxxxxxxxx>,        Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>,        Robin Murphy <robin.murphy@xxxxxxx>,        linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx,        linux-ia64@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx,        linuxppc-dev@xxxxxxxxxxxxxxxx, linux-riscv@xxxxxxxxxxxxxxxxxxx,        linux-s390@xxxxxxxxxxxxxxx, linux-hyperv@xxxxxxxxxxxxxxx,        tboot-devel@xxxxxxxxxxxxxxxxxxxxx, linux-pci@xxxxxxxxxxxxxxxDelivery-date: Mon, 14 Mar 2022 23:13:12 +0000List-id: Xen developer discussion <xen-devel.lists.xenproject.org> 
 
On 3/14/22 3:31 AM, Christoph Hellwig wrote:
 
@@ -314,6 +293,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned 
int flags)
  int swiotlb_init_late(size_t size, gfp_t gfp_mask,
                int (*remap)(void *tlb, unsigned long nslabs))
  {
+       struct io_tlb_mem *mem = &io_tlb_default_mem;
        unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
        unsigned long bytes;
        unsigned char *vstart = NULL;
@@ -355,33 +335,28 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
                        (PAGE_SIZE << order) >> 20);
                nslabs = SLABS_PER_PAGE << order;
        }
-       rc = swiotlb_late_init_with_tbl(vstart, nslabs);
-       if (rc)
-               free_pages((unsigned long)vstart, order);
-
-       return rc;
-}
-
-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;
-	if (swiotlb_force_disable)
-               return 0;
+       if (remap)
+               rc = remap(vstart, nslabs);
+       if (rc) {
+               free_pages((unsigned long)vstart, order);
-	/* protect against double initialization */
-       if (WARN_ON_ONCE(mem->nslabs))
-               return -ENOMEM;
+               /* Min is 2MB */
+               if (nslabs <= 1024)
+                       return rc;
+               nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
+               goto retry;
+       }
 
We now end up with two attempts to remap. I think this second one is what we 
want since it solves the problem I pointed in previous patch.
-boris
 
 |