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]) From patchwork Tue Mar 26 22:49:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872279 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 4451315AC for ; Tue, 26 Mar 2019 22:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C33F28CA6 for ; Tue, 26 Mar 2019 22:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2038128D6F; Tue, 26 Mar 2019 22:50:37 +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 5F22D28CA6 for ; Tue, 26 Mar 2019 22:50:36 +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=rImlM4d6yYD050/Nqn/p3Zd4JI8dQnJVItg6F8OtbRw=; b=lyciafjmmnRxE5dtIER6/LKuKC 88OlucnAhgy739gcGTYKb2WApW4f6MJ3KbLlkQFiF8qwcOU5g9wKqmo4TULIBu6riS81yvFKYZDV8 7RmhMvFHyTfbzb7/baJcaQdDBvV371oCQ0rfChIpviS7D5Xbp9EN4RpSV48WQ/LALPpc23xmQQUSs E+8hLnKHMUWyU3lCowZKkXINKHk25BkwTKnZ+lhSWP6biF7lJmt8OlMP9aK//p50KuAQLzaQaZzcq CxrriHoe3AKOpdqR+s/JIE0nr7gzL+XqCjFFMoAYxDiBw2c9DAt3UeNhkbFiuzAom+62oKyGQt71e CPHhR26g==; 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 1h8utr-0005KG-Va; Tue, 26 Mar 2019 22:50:31 +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 1h8utV-0004wn-W9 for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 22:50:16 +0000 Received: by mail-pl1-x644.google.com with SMTP id q6so2318236pll.4 for ; Tue, 26 Mar 2019 15:50:09 -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=nSqLKLQoUDGkS6WO6/0mqXSeMgP/CMmbaNUycpN9yEE=; b=ZVveUJyfJtWMiRM4wzAvSqvIrGb5Uc4l2fO8VFBJijcJW7PWGpQb8oVHdGr0AoCgDE 3A6CC9+a+wrgLm2xlITj6BH4POxgy856dcYoulSSjYKNcRXv/P/8Pdps5oSzikhA3+KD Nr6ybuvCcvEAfUO4Aj/nP6wiVfwmPGk5vp1NMOYeKrE1mfER2xMRG891B1EcnUjv+0QL 1PV0iOoeyf52M2f3f3oe//dlwFLXILaoVIDLaEM5YS83vmVbGZXfpHZhknITyT400jI9 Bo+MqtKKdeKLLchEHs8DWIbTTI4kTFMoX5odJYfHaP53mgCJyyhjufaKI+yUrmlmcpm6 naiA== 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=nSqLKLQoUDGkS6WO6/0mqXSeMgP/CMmbaNUycpN9yEE=; b=oaLzO0oq5p3C5Y8y5FAs7ze4/XCLgUnxC3K9d0vqgiRFXNwu03PYgbN9BFJkarJaCm ZWks7LXP0aoutcSimZBcoZX3BTGvcyNShmJiTSFxUl1RJ7h1d2xR1KIPSVvZ1s1Z4Kq7 hb2Y3e7t02vfgPDs7QIgZtt0aIKjyx8LKGGrATIdJHsjimuPV3FltXgIXvKpPui+uQfx GZ5Pev8c/QnsPZ9QQBDJTBSU9SvqLiTWCf/GE3YtC7lfcC3I77vTi+JpzOXXX9lDN+3o Hsu6eSnpFMOFOXzSeAK/ub2YA0s2tfWgGgWRM9u/xSk7bNVPn0K5K38+V7iQIGPtZ7me ntAg== X-Gm-Message-State: APjAAAX3/c7Px5pPHI4PzA0hK4IQ/ADjwg6gxydd4d+aHdJD9VWA+/a4 qD7X66dNZckQmS6ii4rd+O0= X-Google-Smtp-Source: APXvYqwmClTzI7FvtAmxZGjK3gY6Chb0F1x05w8JRFZiw+0qSexX6YaMke6VFqQXamPljAAhWjWM2A== X-Received: by 2002:a17:902:846:: with SMTP id 64mr33494874plk.266.1553640609222; Tue, 26 Mar 2019 15:50:09 -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.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 15:50:08 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH RFC/RFT 2/5] dma-remap: Run alloc_pages() on failure Date: Tue, 26 Mar 2019 15:49:56 -0700 Message-Id: <20190326224959.9656-3-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_155010_030111_0A9C2805 X-CRM114-Status: GOOD ( 12.24 ) 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 --- kernel/dma/remap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index 2b750f13bc8f..daab2f3186a2 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -116,7 +116,7 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) 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 22:49:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872283 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 C407F14DE for ; Tue, 26 Mar 2019 22:50:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC5CC28D6A for ; Tue, 26 Mar 2019 22:50:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A01A828D8A; Tue, 26 Mar 2019 22:50:54 +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 564DE28D6A for ; Tue, 26 Mar 2019 22:50:54 +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=Qy+BqyG+A9NQ/s9em1qZXNR4LQ Dzb9pOEpv042LNSmyUDfV0mn04qguRj+iiBaCwWBl7T+2Rk09vMJ8MpoWR18PB3CCrchF17PVplha tw+hn8myxQaSUrajm3Xi/BVS1QEe6BnQW6A9enl7rLYnCQo9E5ttBa6GmnKHXt9+tOJOvAUikXu4M ePcS+D7wha4QW3pJYN5ovuNGN7xbLBgk7Pag/wf45BwpJs12xsmZr5wZMzSNU4VCAPIk82NYvH80m KJXp51SBM//bj3lAHp8MaHkOpqcYLYntrfQrBtZENqdTGsexCXzxd5ORvsScVY6+YVTd6luxhNue0 /rndmpNw==; 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 1h8uu2-0005c8-II; Tue, 26 Mar 2019 22:50:42 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8utX-0004xE-LH for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 22:50:18 +0000 Received: by mail-pg1-x541.google.com with SMTP id p6so8943033pgh.9 for ; Tue, 26 Mar 2019 15:50:11 -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=d8d9SI6Uzq+6pA3O9Jx8nnoiwqY60LZWCoNccnt0K7MvApqO2DcuOeGIS12uMabsmD AVNmdPvCM7YIMEcl2cUEIm2v9GWUIyfQq9VG+d5LIXDM4dW0NLdPhncvUSknr3U/9kFv NDLoqxOvdImnulMbZg6hbB3W4gLKeKa1F8iu6zS2HhLmr/NnNhgeNlY7fledAXgxev9y TUKEYIvrbQeYpqZ0jx6tqnDs+MD2mKsVgClr2Ru08YK55y7RZffVEdSLFwTeeI0kGzpF Dkf3kQo7NldEVDFowISnKphyjF7fLk1CnVMtcNyC6K65TDNcCjNEW7qeXDngWOVlHObv /sJg== 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=L3wkGUyEYRdXJyOM2Fs2uj3NALmxvGoM1q+6tiJwpq767wZGmp5mCW/0Z2mkfBrPL8 NEMgQlkfCQGaFXVGfvtGwNPSf+8Rb3pCw9IvIo3Th0oskYW+PeGvfrLH3NzahfqLWXDS 1nOh4BxWocpukhNOMntDuRajHz3U4fNhSWfyZ6WX3ZFtVeWTZDLLDCfEZTpar7BDpxkS 8ZTeuDLDbJ/inp/0Ck516ylacHynVmUmpXjJZ8ayOuYjjpDR/n3uTIppvtCIADGizgfJ OSE6gnumJeHSP0BrCJLLM0qWKE0/1MCkMDndlQukZuzggymzgiZh3Ohmp7brrsZU3aH7 ECoQ== X-Gm-Message-State: APjAAAWn349/d4sPdLSKDbBW+yFc3vyvMjt07SLhY+YfH/YrlcY7OAjh CcR+m7zmaM7C7Ai7XkOwbZI= X-Google-Smtp-Source: APXvYqxjrn23ApvCQzafM7tMebJ15yXX6D1flXgkxPRKN9E+zV3h/+BemsDAd4R1MIaYDAjaf6LTwg== X-Received: by 2002:a63:4620:: with SMTP id t32mr29273831pga.363.1553640610294; Tue, 26 Mar 2019 15:50:10 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 15:50:09 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH RFC/RFT 3/5] iommu: amd_iommu: Add fallback normal page allocations Date: Tue, 26 Mar 2019 15:49:57 -0700 Message-Id: <20190326224959.9656-4-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_155011_700153_A43F7F0F X-CRM114-Status: GOOD ( 12.05 ) 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 22:49:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872285 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 4A42A15AC for ; Tue, 26 Mar 2019 22:51:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B01128D6A for ; Tue, 26 Mar 2019 22:51:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F16428D8A; Tue, 26 Mar 2019 22:51:19 +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 B1F4F28D6A for ; Tue, 26 Mar 2019 22:51:18 +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=m97yhibb350wrAIPNQ/o9iuXBo QY2lsNimsanjVjQ5RULwwueDTHFu/k3mzu6G+1016WTYWfC5Zp79asA6+CQaiQw9UF8PYjgV5Fm+M aphW1aLm6Y2Amv7yzk8VDwiCXEQoLqTwuuf+VoV6m4lbvTKr29xpcCEkIYEf+pQ8oczZv1gRdz/8u 1J2LTrO1653esRbhoImCSPdvG5EJE5mPSizSfJyqSFld+mdP085gqhzBvHPpf28F3ECQn5ruvmFkK iZBu4mg9FqvK91jEiZ4JHJreiUK8YcD9hQGoPeH+99wDtXN5WUMGG+fdeHGqX0Lsxdbos1dsHk7tM xVvoT4xg==; 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 1h8uuU-0005zq-9G; Tue, 26 Mar 2019 22:51:10 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8uta-0004yZ-1x for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 22:50:21 +0000 Received: by mail-pg1-x543.google.com with SMTP id i2so8930183pgj.11 for ; Tue, 26 Mar 2019 15:50:13 -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=cFqJQuV6FmmN/f2qOE6O3FagCTd8eyCZsCSf/bXbOIxVMBIxsfByjEuqUdT0yPlczZ qKE5Y0QUWVtnc+sLX5v+2NF3AjjUkXAJ7fF+50t1hDwLW5GE1bxFca/kNEkumdyC13HN zAEzlZroDh7TUyO06rLhbvFTBw10lv4dhsdlQ2lnsM7CNQw3UxDymby1giPnWC7h/b5S Lr3G4bPqrl5KMS+wh4aU4rZihb4Yg+O0x2z3frjLpHF3tT+5wXQXccuHdyiPg+Ge1WB2 AsGfHAAbInBda09PKb4duUmNhFQ2rVzzv/vbCtEsCOrZQylqHqvLcpnqjCKB9mWLFOb4 DsOw== 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=tnOSFNWK4Xeu/QfQ8RgwgTyXUVLDSwHzErUPhJCwmNPoep3YLc0z4X+Z57/cvaMAzz WmPDDQCIb0fyEvWtqEIJi215WZsVumxVK903FhyxKTZ5R2FejGppuIoveBdD8TOSsM7Y BsK7e4uN2bxFOUVxDW5PJdij339pokH4SUt4ES4qvC7YjKeqOd7fWjXPB8i7WJinGTGY MTHLH48d0XyhI2PUEYBwSF6cf0KQO9d4BHRrpezWu0g21j005AS4PFVELH1JHCJspuZU pNddmU3xjQC5pIzvfOpb240LfMTUoX2XUKT9Z1sRKMNT9TXBrcEHV50xjB+ATEiGw1/6 CP/g== X-Gm-Message-State: APjAAAUn3Afs6diUZHnAoa2+q6u6VSUMD+CS6eaaYjsCsrVKUJ9OQUhT ncUe/XM+AgSPgvO1gIU1/j4= X-Google-Smtp-Source: APXvYqwThCSYyhpxpNvxFwMCUg5Eb+Cf0vqe6uTZOwvb8aCx2itCgLKEQC5TFVuZ4K/fEtk6lUt/HA== X-Received: by 2002:a63:7d03:: with SMTP id y3mr18841321pgc.8.1553640612009; Tue, 26 Mar 2019 15:50:12 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 15:50:10 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH RFC/RFT 4/5] arm64: dma-mapping: Add fallback normal page allocations Date: Tue, 26 Mar 2019 15:49:58 -0700 Message-Id: <20190326224959.9656-5-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_155014_254377_9AF50119 X-CRM114-Status: GOOD ( 12.26 ) 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 22:49:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872289 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 3706F14DE for ; Tue, 26 Mar 2019 22:52:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FC0528BB9 for ; Tue, 26 Mar 2019 22:52:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 135FC28D6A; Tue, 26 Mar 2019 22:52:12 +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 AD66028BB9 for ; Tue, 26 Mar 2019 22:52:11 +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=TPlrNg3ElWKKq1KPIBbGSk3QbG FzRWnmRWW4zVrhelzAd310Pl15XbvmtLjJSvDtGZY/LIKKvSRmN4ZtR5MDV4+5bLG6YdynbVlq9PW uFFYMDYUwhWyvUJ4bBtLSUuDa2f4i3AKlx4BfGHuO+bkRRc8T+0TxhKNTf+ToQieQYyWJ9faBz7zQ AP8j9gTTCVBEeZMjxRinecSnugp4Jl08cj8SbP4ix5PQ83if1Ie8za5FGfGL3FIzMBEy9xkypLsT2 8hC1LQzs5HhLKcDeuu0S8tM8c3wja08UU5R0D4vzz/CXANrtYtdUHIRbASF5+HClJf120mQP9a0zX PXsVOLwg==; 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 1h8uvM-0006Li-BX; Tue, 26 Mar 2019 22:52:04 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8uta-00050Q-NY for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 22:50:19 +0000 Received: by mail-pg1-x541.google.com with SMTP id y3so8930038pgk.12 for ; Tue, 26 Mar 2019 15:50:14 -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=msqo3md2sAcMz6GQ64ybELtPm5q20Ot5oUTlPMh0Oebc+foeYulBl+nKNO+5O8wfNN vW16df9fGdyuriIUKnQzh2QYAeA2NtXWiMTYY+q48kxmviKbNHreRXftpGksrMXG7iZL xrgiynkXN3R9uy2J7m5IzKws0dim0cKbybsejXhNsybr6ijdzXzF6gN/iQa6uWoB8Hs0 RSfkbCu4hjBD+mwvaLcyn34KRjI2U61I3efqFXgsrueWydJ7PlRtBsC0AGC7+Sq+vU99 ZBAHmbX4usg6pB4SNPZaDPE3cFZrd7DNIvHLDkiH3zhnypGs9A64vtHDD1RUuKZRLnvw U9Vg== 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=nJ4ojTIW/33YhB4uanN5lG/qtEFCoXdkHaolK8MxU/X8Kc0RutWgElYDrKpVx7uXZG cfzgHseWaghCy7nWGrcKA1Oa4zibNnZpZaT7otN8SMpi6Ex7KNqiNxaoAvOp1j2tve9b //MpWuZ77EPRRJZB5mkzZpEbBWAVrIGpSKoxjBLXtHZox14mfU0dJEiRdb19CxNc5x7V +LcdDKO9cvxBmmZGns4pu+qm/HmDzPeCNq+yhcawH1XOTXEj+g/Grm37o8l4XHBKVsir jSMxX2lElAHk5hDKtyZGAk/V6GA3LugnwHRUmx3pchqtGOTlB02vuXpT2EwmtHcUY0Er OS3g== X-Gm-Message-State: APjAAAVirCgj+i670gydsRrGEPsBprOFHV2q3f90q7qwkF4HLY4PWLmZ JAy9WvjxrIhehUhIsH9WZAM= X-Google-Smtp-Source: APXvYqxZpKGQj6dfGYHbCUIDZUHCWq8Wq5nlbTjsOZ9r7c3obGfooVatp/mh5wpzMEIihl6DSdIuGw== X-Received: by 2002:a63:6949:: with SMTP id e70mr31096833pgc.89.1553640613149; Tue, 26 Mar 2019 15:50:13 -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.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 15:50:12 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Date: Tue, 26 Mar 2019 15:49:59 -0700 Message-Id: <20190326224959.9656-6-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_155015_063762_2CC91811 X-CRM114-Status: GOOD ( 14.47 ) 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); } /**