From patchwork Tue Mar 26 23:01:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F2B5139A for ; Tue, 26 Mar 2019 23:02:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B72628D92 for ; Tue, 26 Mar 2019 23:02:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F18C28DA1; Tue, 26 Mar 2019 23:02:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E60FF28D92 for ; Tue, 26 Mar 2019 23:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Ns2nvF0fqeWlPhOWZctIRDI/E8m3mjlLBwjRr0X1DSE=; b=R+lGKKIex3rf+39Tt1XIuBO/zl Lbeedy39OWYGqscL+g7tanRgZFNqns3u50Kd9veAWo8GWRwHLE2U1BdxR8uIyL+TDapVJH61dtO0Z WDZoLW5OvEL0VzTXfDprS/8jQU1vB9PqSPHW1eNJ0zmOu8vV1q/ouA866/ycO0MprSXKMPorNK0HU OwbBIAlYH2uRQO29RNhOkKLJo3k8YQs6VuoeFzkHk0pC45qCoiB73jx+qrJAPeJ4S0j+gEGJspyFM Lmvp601duQHgUh7Gh27pn2SHjID3V7keFbvbC4NRZJv5XuAidcDuO3yCqMfu3TihG2Mk2tJ3E0lqs oPAbq97Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8v5S-0002D2-MI; Tue, 26 Mar 2019 23:02:30 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8v4j-0001N3-Dj for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 23:01:49 +0000 Received: by mail-pl1-x643.google.com with SMTP id bg8so2326356plb.0 for ; Tue, 26 Mar 2019 16:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mVhTNoDORVJm41U/dvmFkCkktZV91K1+FNoU6GFbQHw=; b=HsR0qgSYordfKl2jHrx5zqJbtouhHI4pyU3627J8Xuo70x35da5R5nIyaLmo3shlAL mlGdpHjesbvXjNJakIwR8NxAiE+SB5HdR8pPKoSJPqq7zbhNnAX7YxgYxsjqOZRH8ejL /8hzsQopu3FXi7tiGZLpeusdTKfY1xj0R3qYnY8dToqDZ/o4lv1CSpJhThbJb21hRvC0 BibsSmWSMgOn3qJHysfkKIkvlkf3Tcgv056cAPgLmDXSkVBaVAhuyocpTXbmFKRY/v/Z bUTDvBKzyZUUIayeIQN4ndiJltczqB7bUA9KoIKAJhxuyqaWSdCaCCTliu32NT+/9X29 jh6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mVhTNoDORVJm41U/dvmFkCkktZV91K1+FNoU6GFbQHw=; b=O/3xPOD7Kgw09QRwWUJCNsPCPnqeRvv4jXQppdF+ptD52TNg4iJhM2D5CzPavqS+/q TQK/Ss7O7SmtsC87YF1jL3Ynjo1nrYpZXX870AgjG8k6GGqNnvEzCCt4DGfMBrInzqEH qQppK5YNaDMSUFybmjsq17yYXwU+DfIDBHmLP8Z99akkjPgvEgs6ElXTDQQ3gHKuxMuO H12uHY8zgswxdCR4X8HTPWG4W0f5NyGrdiInTYv3Ac2K/P42ozPaysg4fj4JFoCbnY8M cylwYmGFa9h1G/+gePuUlVfa6XyWTqoUL4RUlhZLPIvARNMH7iga+COAnG5JXyNRfdjT kHiQ== X-Gm-Message-State: APjAAAXSByVF4bJuPwavm+ZiTAKUGFY+9GyRhItGapF+kVx3Y650eJBQ APyWYhK0A4uCt+5f0FDCwJU= X-Google-Smtp-Source: APXvYqxUYbOG0HP6pL1n1gl+MBlw4kIQsbSZwC9tPcLPEhkpNkYXVFIayVuF4UUGx/Zz7cgQGLcjNg== X-Received: by 2002:a17:902:7d81:: with SMTP id a1mr25950343plm.202.1553641303304; Tue, 26 Mar 2019 16:01:43 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id n24sm43832587pfi.123.2019.03.26.16.01.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 16:01:42 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH v2 RFC/RFT 4/5] arm64: dma-mapping: Add fallback normal page allocations Date: Tue, 26 Mar 2019 16:01:30 -0700 Message-Id: <20190326230131.16275-5-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190326230131.16275-1-nicoleotsuka@gmail.com> References: <20190326230131.16275-1-nicoleotsuka@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_160145_791466_984FE30F X-CRM114-Status: GOOD ( 12.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tony@atomide.com, catalin.marinas@arm.com, joro@8bytes.org, will.deacon@arm.com, linux@armlinux.org.uk, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The cma allocation will skip allocations of single pages to save CMA resource. This requires its callers to rebound those page allocations from normal area. So this patch adds fallback routines. Signed-off-by: Nicolin Chen --- arch/arm64/mm/dma-mapping.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 78c0a72f822c..be2302533334 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -156,17 +156,20 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size, } } else if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { pgprot_t prot = arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs); + unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; struct page *page; - page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, - get_order(size), gfp & __GFP_NOWARN); + page = dma_alloc_from_contiguous(dev, count, get_order(size), + gfp & __GFP_NOWARN); + if (!page) + page = alloc_pages(gfp, get_order(size)); if (!page) return NULL; *handle = iommu_dma_map_page(dev, page, 0, iosize, ioprot); if (*handle == DMA_MAPPING_ERROR) { - dma_release_from_contiguous(dev, page, - size >> PAGE_SHIFT); + if (!dma_release_from_contiguous(dev, page, count)) + __free_pages(page, get_order(size)); return NULL; } addr = dma_common_contiguous_remap(page, size, VM_USERMAP, @@ -178,8 +181,8 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size, memset(addr, 0, size); } else { iommu_dma_unmap_page(dev, *handle, iosize, 0, attrs); - dma_release_from_contiguous(dev, page, - size >> PAGE_SHIFT); + if (!dma_release_from_contiguous(dev, page, count)) + __free_pages(page, get_order(size)); } } else { pgprot_t prot = arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs); @@ -201,6 +204,7 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size, static void __iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle, unsigned long attrs) { + unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; size_t iosize = size; size = PAGE_ALIGN(size); @@ -222,7 +226,8 @@ static void __iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr, struct page *page = vmalloc_to_page(cpu_addr); iommu_dma_unmap_page(dev, handle, iosize, 0, attrs); - dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT); + if (!dma_release_from_contiguous(dev, page, count)) + __free_pages(page, get_order(size)); dma_common_free_remap(cpu_addr, size, VM_USERMAP); } else if (is_vmalloc_addr(cpu_addr)){ struct vm_struct *area = find_vm_area(cpu_addr);