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);