From patchwork Tue Mar 26 22:49:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872277 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 09DB417E6 for ; Tue, 26 Mar 2019 22:50:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7C0A28843 for ; Tue, 26 Mar 2019 22:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB12528D6F; Tue, 26 Mar 2019 22:50:30 +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 831A328843 for ; Tue, 26 Mar 2019 22:50:30 +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=/G4N0QRw9NBilgxPssR3sCEVpGgilJNqbMEMsxlKBn4=; b=HMxA4KDUqsb4jS17Zs9KNuqHeJ uV3HkG5HW4+WtEKymi+i11JOsvq597lHzFKbR8DbnvQT+zAuxGVGhnXgtcTQ1ugbi93hxxQ1Eerje +Iv4vltSygEMmY+NMH4Ttn6aSGV01LHz30394LFmzoszFX/guRyCRzBXqrD5Mo0FeBKk6hG3biBd4 /7yGxxIrGRENkJdBEEZZavBruEuR3LJqhyxDoE6coNxbLZjg5LkixuqPISKVV2kebL4KNsgIJgG/6 6QbfqWGhlfx+ka5WXjzailp2ralFj0M+C0kD1bt7ZXlh6P/zeYHYAtIr9bnTf7YzyP/8Z0EyvOMRg A+MEwfhA==; 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 1h8uti-00058I-LQ; Tue, 26 Mar 2019 22:50:22 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8utV-0004wL-8G for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 22:50:12 +0000 Received: by mail-pf1-x442.google.com with SMTP id i19so114450pfd.0 for ; Tue, 26 Mar 2019 15:50:08 -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=uADFbodtyi76mzTIX2Xhd3f7QgEY+mxRgH7JdFV0yy0=; b=EvDsmFx9nuzUTBrHdOWJWjUIPzIu41Xn0U30foyGliVRBJqfitnwfk2hJS3G6tGuxS uYtVVjCfNOdxq7QhC5Qpr4yhe+VjhWKvgo+jPL5My6eVGqAI8PkUplK8khP+3cp967do 2GpK5aU5QFUjL1HJvWkOW7CAm+EU8wDn3hHg5XehJEnmqekDrBzcqVw9yky9syLoz8Rx pUkDYjqGlaCH5WNy/KEu9PES1s6fqgT45QnsJc6S3/2KgGnDwK8VKxsHKWBl7qsRlP7g bOcrzH72lC6JSE91zxuttQVhRZKQTaas5w1E9i+uaNnIGztd96CEAI58OzRLVYmRTAD2 vjPQ== 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=uADFbodtyi76mzTIX2Xhd3f7QgEY+mxRgH7JdFV0yy0=; b=o7MN3hNTnBWyOGePmkXudPABsDzIzg2l8SxvpKddUsqFBBQy/ia961vHBFL0jdIPpA 3E9D+sy8vpPgOIkVVKtkUo3EbvEuvXfAX7b/PutvDLj+YJGSSJBUelzlAO3hHdGpl2iO MkIKmHCTJZd1pSvaN8Wg7uGjGRW8SnpjtxvIRZbJXP0oBeC565vw3ujoDkYuqpn3wSp+ HcrS7pLefc1dCsS95MkP5Y+7rqP1A012fBsG9WWDuG0UhAIO0bBRZUjnFVQ6ndZ9YIW2 NWkzJ9htQJwGjiirGYAlXAefA+TQKztt07cC8HmpQy415Wehnibx4FPqR0PB6z4HwggE bFNg== X-Gm-Message-State: APjAAAWGxSmufXTDknvHm9j2gCVEqlRIwb112u7zGSZ/0mTiVS6nI1L1 4NRmpmpXxQr+RmPcUVyOG5s= X-Google-Smtp-Source: APXvYqxXIqzjWYVrB3+n7+8C14DJI/QFIHAGZaOed/jWzUdScSQW52wDYo5nXaVGZn24F+emSmeXEw== X-Received: by 2002:aa7:8a87:: with SMTP id a7mr33152903pfc.252.1553640607850; Tue, 26 Mar 2019 15:50:07 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id 8sm56937368pfs.50.2019.03.26.15.50.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 15:50:07 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH RFC/RFT 1/5] ARM: dma-mapping: Add fallback normal page allocations Date: Tue, 26 Mar 2019 15:49:55 -0700 Message-Id: <20190326224959.9656-2-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190326224959.9656-1-nicoleotsuka@gmail.com> References: <20190326224959.9656-1-nicoleotsuka@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_155009_299220_8D3F88E8 X-CRM114-Status: GOOD ( 13.92 ) 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/arm/mm/dma-mapping.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 8a90f298af96..febaf637a25b 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -589,6 +589,8 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size, void *ptr = NULL; page = dma_alloc_from_contiguous(dev, count, order, gfp & __GFP_NOWARN); + if (!page) + page = alloc_pages(gfp, order); if (!page) return NULL; @@ -600,7 +602,8 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size, if (PageHighMem(page)) { ptr = __dma_alloc_remap(page, size, GFP_KERNEL, prot, caller); if (!ptr) { - dma_release_from_contiguous(dev, page, count); + if (!dma_release_from_contiguous(dev, page, count)) + __free_pages(page, get_order(size)); return NULL; } } else { @@ -622,7 +625,8 @@ static void __free_from_contiguous(struct device *dev, struct page *page, else __dma_remap(page, size, PAGE_KERNEL); } - dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT); + if (!dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT)) + __free_pages(page, get_order(size)); } static inline pgprot_t __get_dma_pgprot(unsigned long attrs, pgprot_t prot) @@ -1295,6 +1299,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, page = dma_alloc_from_contiguous(dev, count, order, gfp & __GFP_NOWARN); + if (!page) + page = alloc_pages(gfp, order); if (!page) goto error; @@ -1369,7 +1375,8 @@ static int __iommu_free_buffer(struct device *dev, struct page **pages, int i; if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { - dma_release_from_contiguous(dev, pages[0], count); + if (!dma_release_from_contiguous(dev, pages[0], count)) + __free_pages(page[0], get_order(size)); } else { for (i = 0; i < count; i++) if (pages[i])