From patchwork Tue Mar 26 23:01:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872293 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 2F299139A for ; Tue, 26 Mar 2019 23:01:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E8C128D92 for ; Tue, 26 Mar 2019 23:01:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 128FD28DA0; Tue, 26 Mar 2019 23:01:53 +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 91DB428D92 for ; Tue, 26 Mar 2019 23:01:52 +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=u7fRuAiYozOL4LxCezkBLhvCN6 dpSsg0U9w3YEnRDlaJ01xEK0z9beH0l7ePBnHFagiEeK7M7h9SKwvmQ3XprUCnuqf/JG5DXmWjc3b KH16K6LYpnIC1DXcUjcOUIcSYUAebIEdbRsiU4sHMLPVuuIiMPo4A7NNCJvBmpT5p+VGSP/TPlxKH RhbiInSr3YocGelVTQGqP2HlY70rmQlOzuYsI0upKEGvndvnhoGvUHkvbCDT8sFGsYDZMCcUw61bo oAF9Ft6jgvILBKL4e8cqxTCLGxZXSfkNa9fmrgp/pcy7eNfERm2+Dp5u1UsjBDj2EhKp6/0c92Cz3 +BOV9k4A==; 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 1h8v4n-0001Rq-Mb; Tue, 26 Mar 2019 23:01:49 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8v4d-0001KO-Vz for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 23:01:41 +0000 Received: by mail-pf1-x444.google.com with SMTP id r15so8744575pfn.9 for ; Tue, 26 Mar 2019 16:01:39 -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=YXEW98J6zg2ngpdsbfxr6LvjKJrW33mB3hLFn3NjZUDubpqWmop2dMdcSWSvyphals 7TiS+I8S0EO+f/8xgAKAa8RjMCdMxQMzFhh61XaYuVBMgclCGd0KIg+qAs6zK7YSCqtg uRPGdvIAycukBJ7HDxvb5wMH0fGXj5XEVIcBC+RewLu9Jnf6dCW1uhxu4WPJBADSR5Yc KGoiXFYQSdq11wARhbBhf22DLSqyjOSwrlOckPYB557DntfUEWvq2x4TybL6EYePmDyl PUacipS6FZTxJLVOprM6mCFCSxE2kXPH7GxaJBbz7p8lmHGMPjYoCfGy1JNVPGQm78WK oKBQ== 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=QJTsNBtFCGo1xi2xgnYMdvytk7Iw1dcHZIYMT77FrOv0DfO0lVKFadDLtTfU2Do9yx 4AvfsaAXvK86/t0IGvHsvTw1FqKLIfIU7D8wf9e9g+ecmoSHKDcV7ka+O6jH8X4PpVN+ G6aWmlCAEz6NA54sbeKqXwrHvh0xEscJfMIx19ddoyXatO5AMTQhS0yvrZvpZojw4HlD 5PfaK3mJlnY5iMGX4Tiil4Yy4OnBE1QbEPwCiXhQbhc2w8u0t44ohGNc63br1+HJVbO1 wcgfxzPm2zjrwhbVJZ2SF8KtykgJUeoySp6/S2DD4YRja4cqk/bVfcOHUcBajwP7MUvD MxUg== X-Gm-Message-State: APjAAAUTJjk+b5aCUxQGz4ALXtSUhCNfLT9ngriqULc8+fr9iFxbpx/v 9lL3x4XaJOQGd479QUr9HYc= X-Google-Smtp-Source: APXvYqzklxAL3HA3sAuQe2qJFq1XDkOl77Jl/JduYVAUyv9Beg8otfrvCX8qukeM8dQKVBZmt8Bt8A== X-Received: by 2002:a62:1b03:: with SMTP id b3mr28362977pfb.150.1553641299192; Tue, 26 Mar 2019 16:01:39 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 16:01:38 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH v2 RFC/RFT 1/5] ARM: dma-mapping: Add fallback normal page allocations Date: Tue, 26 Mar 2019 16:01:27 -0700 Message-Id: <20190326230131.16275-2-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_160140_030788_660BB958 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])