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]) From patchwork Tue Mar 26 23:01:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872297 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 9B8A317E0 for ; Tue, 26 Mar 2019 23:02:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8159028D92 for ; Tue, 26 Mar 2019 23:02:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75C4028DA0; Tue, 26 Mar 2019 23:02:24 +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 1C8E228D92 for ; Tue, 26 Mar 2019 23:02:24 +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=asKRfXJ8a2nh76vN7Je+9hkMKDaa+7fohJbHmnvthgE=; b=iig1pfkgjYrAasHL5+Xbf4GSH0 7crdcMnoofGSUXkSbQ5Sotx/nxHkNEPQCTxXieGaH1/IRH1fgu5G6XX/AFzYf44lbrNb62WzEJ7Q/ /DwBIxRwGxSmAkqr0JUOKXUnBdn4i7qa3HFT3Ewmr4Bq7J1Ao4xKlOvkpC3HZs5FC/8Z0GrD5UCMb 9J+MrDe/kA3tMqOoIf1qpmK3QXkJgrT8kuKX17gmWt3F65fBptZ41S+eWCBW+Nos6h8t+me7XseTh +Hp6G5xQ04nvav16kk7DsBTC8tzP3oQyf/ZtkSYX8OqHfApqC8sIxhOqT/S9Voqi6+9ggxWq0FFWm mcQoCvIA==; 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 1h8v5G-0001xi-4r; Tue, 26 Mar 2019 23:02:18 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8v4h-0001Ko-LN for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 23:01:45 +0000 Received: by mail-pl1-x644.google.com with SMTP id b11so2327105plr.7 for ; Tue, 26 Mar 2019 16:01:41 -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=YwwzX2Ckb5IfO36KXFpoRn0bgcwJZJMjsrMm/Tj5wmQ=; b=Nn9q3ZFaAD/c1+ZSBu573k//eegbkL8oLW4s44qOduajMYZ21kIvPvakhZ0S5rv4QB tJnGB7JqGFkcFhJ4Xcnl1T94Uzhdg5SUmHGXHq9IzLJ4oa+vRIGN0MF8fznY7AjLo161 M4mwwCYDcNkdNq/I0W4PRkG597A/r+FLTt94H8HrzDzqFQ8roUk3SO3mZbUG3AHgV45w VW7bgYKIeZ9LKh5xsktkTHnYZ5svDQ+6FdZYNk2Qv7cGP0YkZDTuNHNP5emgFZpMqqwr e9G3wJbgWu2utDgh+a5fXLTaKac2Je2evrrANpmaSszlhOrX6XujofGDF+rELW4LogUS ghMQ== 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=YwwzX2Ckb5IfO36KXFpoRn0bgcwJZJMjsrMm/Tj5wmQ=; b=kSYX7mdlPEctFY2Eagxj1I0/mGr2mnOq6Sg5P82nnnNAf8ojzm/HGfA4Wo6oSL4Q1J wLuMic5Zsg04QjnwlJsNyQMvZg2J8qbgFFdyl/Cc1gJ5r0hL9nRFulD/mkQ3MRH1tex+ JhWYsh6jMpgCxaOAck7mpnbdl1AQOXiP5JZezx4xqedNeY3GHy65Xvevv+nBaLZTTupi ykVS8mvADOqUUVvYJpANahOWm16xcdkvd4YNHJpndnLric6ryjUnuSpoO/yNqiNXHaJ9 cc7ABeR7rDGWgSz3tQEPEiTsSxyayuKPG5kxBlmjsDHBjQo7KZopQ9ASAWzId8vn2v21 JUuw== X-Gm-Message-State: APjAAAVf3JUJ6xusaCwADNNJ+VokZWQyh5g3O1p3FlmEyy93zrO5b1Fs xVnKbJ1t6gJRIA2MoxIj0nI= X-Google-Smtp-Source: APXvYqwos9GlWk8aPE/h4lNoYQAEJzJM0q9VFoHFIolVkeadZjxjBGqN/o6Xk9M/LFnA64Pau6O61g== X-Received: by 2002:a17:902:8643:: with SMTP id y3mr33347145plt.195.1553641300615; Tue, 26 Mar 2019 16:01:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 16:01:40 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH v2 RFC/RFT 2/5] dma-remap: Run alloc_pages() on failure Date: Tue, 26 Mar 2019 16:01:28 -0700 Message-Id: <20190326230131.16275-3-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_160143_844703_579DFB93 X-CRM114-Status: GOOD ( 12.12 ) 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 moves the alloc_pages() call to the fallback routines. Signed-off-by: Nicolin Chen --- Changlog v1->v2: * PATCH-2: Initialized page pointer to NULL kernel/dma/remap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index 2b750f13bc8f..c2076c6d6c17 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -109,14 +109,14 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) { unsigned int pool_size_order = get_order(atomic_pool_size); unsigned long nr_pages = atomic_pool_size >> PAGE_SHIFT; - struct page *page; + struct page *page = NULL; void *addr; int ret; if (dev_get_cma_area(NULL)) page = dma_alloc_from_contiguous(NULL, nr_pages, pool_size_order, false); - else + if (!page) page = alloc_pages(gfp, pool_size_order); if (!page) goto out; From patchwork Tue Mar 26 23:01:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872295 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 EDA52139A for ; Tue, 26 Mar 2019 23:02:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D959D28D92 for ; Tue, 26 Mar 2019 23:02:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C91F428DA0; Tue, 26 Mar 2019 23:02:23 +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 45F1328D92 for ; Tue, 26 Mar 2019 23:02:23 +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=+0Vt6Dbkm2jC4sCULzH4TeTeDsmgUNh0IVOX/+w6sgY=; b=eAVOZJhWYznyxhDDRAZHSsXqVQ 5texd6UH5oyKthtbZtanLp7g+x4EMtlh3m3lZJhX6Q0iaU9QJSPyHsVXi+5PkN3f952rRaxcRjTVv KR7ZPEmhK9yZHmCdd5IeazTaEhaz4n4Iy7GYXTbKnUOp/uyL5uy6MzAMhNjFTl2X8d0LGugsrcgac oh9hZZ/HBthiH5z3CaNlZ7HnRrKcoBTy/LNNAOpipcnR9/WoXe6V/Ozoe3rFc97zeuAU97oZYwvt5 3TELRtFLGG0avTITxBY8mHpNlTFRPA4x2Ttt40SkAHVG1tAN6dIdxRFWO7PBlhkJnK1CBmgtxe2qn gCqw7FNA==; 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 1h8v5B-0001sL-7C; Tue, 26 Mar 2019 23:02:13 +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 1h8v4g-0001L1-H7 for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 23:01:44 +0000 Received: by mail-pf1-x444.google.com with SMTP id c207so8762700pfc.7 for ; Tue, 26 Mar 2019 16:01:42 -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=Pbdwi/63Agi4s6Tt6RAM0FtL+bzJWgpn5Dncpfelpvo=; b=VEl0Z5RabQr/GpMe+VeLFsQb1j8S9dkjTJrD73RCdjoxt/+64vqdmHwA3oCGAU3Rao muG6Fg1gGNy4yTM2ISm6Gf3H5J7n1jKEiVHPSGMKodZ0bbiuQWDa8gw1fkXV8HsU5ery mpeAb6v/5rSdYG4hg+7ZETItqEadoofzRSDWxISNsQUrrUVE7NPHPampAmcd89uvOBnV ILhZtuXSENh2o4CATQZwLUHukCRjgN4ODRK3DJXp21AKe0LehF7+/VJaueNzwuYtNAkD OQ53fK3oOGDrCaQw0Syk2v6ZUm+nJiznA+UTVRMM49uxpitTBcIJ45aavdT9RDkG7MNG OkxA== 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=Pbdwi/63Agi4s6Tt6RAM0FtL+bzJWgpn5Dncpfelpvo=; b=dMqeTrXXnE9eZIVgScmm7zkFo+uTIUXUrma9mC0f9Fk7fWLiEFmZaZk9f+d+igdt4C B3K1zXsxIXJj3+c6cb5dv1H3eOdma/Jp7KItJ+YETDGQ48KPpxvBTGHIwqsPKXMfYf5s bvWAm0SZe4c7aA5okg5oQ4A4LnMhK6D1XFWgi4oKoGClV4RjSU8/zVHBhjqo+Ock4qf5 OtMhzNnnS5MCVvRVO4Xgl6G0UGV3gL6/rZuIy4UB7KifjSCz9YBDTHqfpqFonV4fHhjQ r2rSh3TttimPrAZWQUsiuDyQZ1QzXPv70j6JCHl4LYMfuR50/QflGAu7qZZyc1pJY8Kn 63jA== X-Gm-Message-State: APjAAAU5DLzQww3uMadouYVqGkvzLosL3Fv3sqv14ZglxRWVQkg78IgJ q7qESZh8dw7kOSFhjRHqBX0= X-Google-Smtp-Source: APXvYqzI4KLCbPz8UxICZ051Zm3uWTFPxOlGhyODzocBuOSnWTYCxGRTIeA0rPSHp3VHcl/fsSnMcw== X-Received: by 2002:a62:388d:: with SMTP id f135mr17894178pfa.103.1553641301996; Tue, 26 Mar 2019 16:01:41 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 16:01:41 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH v2 RFC/RFT 3/5] iommu: amd_iommu: Add fallback normal page allocations Date: Tue, 26 Mar 2019 16:01:29 -0700 Message-Id: <20190326230131.16275-4-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_160142_808404_77B2F821 X-CRM114-Status: GOOD ( 12.27 ) 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. Note: amd_iommu driver uses dma_alloc_from_contiguous() as a fallback allocation and uses alloc_pages() as its first round allocation. This's in reverse order than other callers. So the alloc_pages() added by this change becomes a second fallback, though it likely won't succeed since the alloc_pages() has failed once. Signed-off-by: Nicolin Chen --- drivers/iommu/amd_iommu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 21cb088d6687..2aa4818f5249 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2701,6 +2701,9 @@ static void *alloc_coherent(struct device *dev, size_t size, page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, get_order(size), flag & __GFP_NOWARN); + if (!page) + page = alloc_pages(flag | __GFP_NOWARN, + get_order(size)); if (!page) return NULL; } 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); From patchwork Tue Mar 26 23:01:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872303 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 1865314DE for ; Tue, 26 Mar 2019 23:02:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07FEB28D92 for ; Tue, 26 Mar 2019 23:02:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F034028DA0; Tue, 26 Mar 2019 23:02:44 +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 5C65528D92 for ; Tue, 26 Mar 2019 23:02:44 +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=bVYjpiKTpsKqb1AkUnToKy8iAzxSdJkCto6TAZ0Fs/M=; b=GptpbGU12GpPxKFk1CXhNVKfb7 qe7q1lOFMATdvVggxYV8DTb6nwTeRJDKZLKQ2VCOrwnu50o0y9e8U05RVzwq1paw6i5mAMabRuLNq sQHJoxZF/UeBaXm7RDtrE1K6ADAL11s0AZbPlCfNNGgYB6Bni8+itPY9DBKBiAhp87ZVO+VNm5AKL 2oSKy3hbcFwOOATJVQ0YFZcTCwuRgGtBBS+EnMfpm7OY0v6VuXIT0llclDzP2wraNg0QEeFM8xCDP 86QGuuxGKZoF1hStHP87V5xo6kquVVdI2NZmt6tsp0w478WL2dCbNQwJoRRS17fY9t2PTzXR4flUl Snx/I2Xg==; 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 1h8v5c-0002Pm-BW; Tue, 26 Mar 2019 23:02:40 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8v4m-0001NK-Dz for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 23:01:57 +0000 Received: by mail-pl1-x641.google.com with SMTP id b11so2327184plr.7 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=xR2fAcbi08dJ1U/q08SNwZuhqDiyYfroDhLUIQLycmU=; b=ZRq94w4D00wfNmDhagQEuvIFMFs73QFUr4is3xAUxVycvb9Y4QfKSVGYSVqHIdt4yQ /Dg3bO579AdlV+OYj3yo9UWqEhUG2d+MERdzs6xApqiar8ax+iAaWGF9YKpAa3lW053O 95zfD6T0qswCMW8aetPrWFBPj7IIIsQf2CKRNfVE4t3uNWR2KpDHEYIO2ysR2EOtCGc2 TzgVe7Wuk2KHilHsftLjOXWwSIo9M+PyvGBVkgrAl4ZUEhwjELhGmgNoCaXHM4jJkgXK 6duRfiQPShZOqYsMlFVck0R1vog0+PP8ldK6Sl3xRJj6ucVg5hMr82WuURjijkU8PFyZ ClEQ== 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=xR2fAcbi08dJ1U/q08SNwZuhqDiyYfroDhLUIQLycmU=; b=MNqDX2X9n7Q3uC3jEmGcTX+jZMTuTMQkjnP/a8/Z8GLEI1AbDh7tZEJNc3fMrloNvL v4o5mFaqI6HXQcTbgxZz0qB1du84E2c1BkVKIeevpY+mXGNbLIzkLzBnHYGhZzFCuu5d 7IV1gEAuFX5uryHRbnbMbf2d30ToRo8dG3V8heWgWcjSUtsO+T2HiINIRmWx8TuqoYou DZaiRItm+1ZSCGoRjqWMFRAF20Vrt6nrvQKT+/FJNfZdys6mdOTea19Ak7bynUnxrh4j JYiMj6V0Sx3HOywibP2ahFgMDINHAfuy86bStg1PqNzTwdgsTlqxZdXMkax6GtKRVOQz g5vA== X-Gm-Message-State: APjAAAXa49UMoW9zTpp8lD7C6tqcdemMf6E9SvBgKRsBu2zejTHdiZX6 5JU5Cd2g9nxgj6Xwhq9CN7M= X-Google-Smtp-Source: APXvYqw95qvrcdsbOKMlAJtssFXpn2KopvmCCHiGiW9jB5JdCv75GEFUp4aJ6ghruPJ0/CYlo+WAZA== X-Received: by 2002:a17:902:be04:: with SMTP id r4mr20181970pls.218.1553641304557; Tue, 26 Mar 2019 16:01:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 16:01:44 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH v2 RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Date: Tue, 26 Mar 2019 16:01:31 -0700 Message-Id: <20190326230131.16275-6-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_160148_901879_A9DF22B4 X-CRM114-Status: GOOD ( 14.79 ) 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 addresses within a single page are always contiguous, so it's not so necessary to always allocate one single page from CMA area. Since the CMA area has a limited predefined size of space, it may run out of space in heavy use cases, where there might be quite a lot CMA pages being allocated for single pages. However, there is also a concern that a device might care where a page comes from -- it might expect the page from CMA area and act differently if the page doesn't. This patch tries to skip of one-page size allocations and returns NULL so as to let callers allocate normal pages unless the device has its own CMA area. This would save resources from the CMA area for more CMA allocations. And it'd also reduce CMA fragmentations resulted from trivial allocations. Signed-off-by: Nicolin Chen --- kernel/dma/contiguous.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index b2a87905846d..09074bd04793 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -186,16 +186,32 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, * * This function allocates memory buffer for specified device. It uses * device specific contiguous memory area if available or the default - * global one. Requires architecture specific dev_get_cma_area() helper - * function. + * global one. + * + * However, it skips one-page size of allocations from the global area. + * As the addresses within one page are always contiguous, so there is + * no need to waste CMA pages for that kind; it also helps reduce the + * fragmentations in the CMA area. So a caller should be the rebounder + * in such case to allocate a normal page upon NULL return value. + * + * Requires architecture specific dev_get_cma_area() helper function. */ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, unsigned int align, bool no_warn) { + struct cma *cma; + if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; - return cma_alloc(dev_get_cma_area(dev), count, align, no_warn); + if (dev && dev->cma_area) + cma = dev->cma_area; + else if (count > 1) + cma = dma_contiguous_default_area; + else + return NULL; + + return cma_alloc(cma, count, align, no_warn); } /**