From patchwork Sat Dec 9 01:11:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 121252 Delivered-To: patches@linaro.org Received: by 10.140.22.227 with SMTP id 90csp179719qgn; Fri, 8 Dec 2017 17:11:19 -0800 (PST) X-Received: by 10.84.178.37 with SMTP id y34mr32468995plb.260.1512781879382; Fri, 08 Dec 2017 17:11:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512781879; cv=none; d=google.com; s=arc-20160816; b=m9qgC2eTUgpQaJrqvawP9VHiYjMwpqEUg9yj/cOKFVsg/HkCT0/3Cvq2uA8p782o+q Dm/h5/PskpXetuMoWTcdwAW6YHRo8GcuHmsM6cVmUcljuOAUmhidenrVB0hlagn6Rk/V Uzv7mXn+4e52HE+GtzWCN07+UTZK0PyzAGB6eJPeNzNG4xs0kFQ4MeXWHqJLo+ltkAzV 5rWaxRv3LrqIhxxy8RZK/rxuRSP3Mf9AExwKXaZ+jlvAO43KSKej5jt69TkYfR/4+iws IwcHzDgam4BrBmRiXN/+MaeW/gkeZVPHGQM4bbxoFiE5BRKvhVz9cFEQw4Jzmf4qdWhS jRmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=5JuzN24PqWYMHeIajXxukHZ7HFA0LPglUuxOgvVRZcU=; b=O9mE6nQTwZAqSv74O4GP5aB1edlF341m7nfIm84SvZu/62gfofvmMIyUi7nzax4dBN 0hYBCKU3G6z+GRRARMhVPijo1JK4k++Bw3oSaB8R+Wnw9UbcMCndNkx9FvkZo6LJTbAm pWfqcq+IFCruRHJxLxt/DC7T8OR+OVhlLpCqCfW9bfjowRyPZGRyo7Bjn6mqN4LMIaM6 3j7uUi/2XMmadOZPntYSfP2f06CeKsGvacTjLe4V0kGr86goFMaTAttjeMw/aXZoIXVA OLZKmZY2pTnOkDPEe4XUqf+M6w1cpJnXL6NuWdS/L0K12jMGxIJbj8l12usSNAAeVeKM Nqtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ON+dxs4l; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i7sor3842074plt.42.2017.12.08.17.11.19 for (Google Transport Security); Fri, 08 Dec 2017 17:11:19 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ON+dxs4l; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=5JuzN24PqWYMHeIajXxukHZ7HFA0LPglUuxOgvVRZcU=; b=ON+dxs4lwDB5G8spBqzA98mRO0Kt78r0NFvv94LXs4rsP8Xn9JPxivVFCE3XbK4RHu 1JU/fEO/ATBeg9iC/q8xg5tEOoGryvEgka4ALiDAG7MwrW97U3mZWH0WkgfeyQRJVRz9 qRLZzchjWFUQFgvHsvGEO4nGJ1xelco7RDph0= 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; bh=5JuzN24PqWYMHeIajXxukHZ7HFA0LPglUuxOgvVRZcU=; b=W40zxJfGt70zv0/QORGTuU4UNrtNLUJA/8TcrSGVHuM5WO0CCCQYVVsG3KNwJdIODE vbGiZY0Xu4J1eCAfD/E8mz+43pcXUY6yCMmEOnmi7f+ISSfAnRx105So7lzDp4RZCg6F hvGB/K1EatKafPE4CqN98jAStacQxzwmwsKBNskFSqPxITCLD20HmOuHRNsPmfH4QsaL eS2HZ0tnWSJsHQiYDylg7TMxdnGs0VcbW3e6lSeZawcEEhNrL8tPqPK1s2g51zCN+wFL LurPLA8+lF3+t+gF7QLyc+kEP3aRbDOvxZIc4i5iKssiOqh53Lf/VqJ/kY6hi0G6QI+3 qaGA== X-Gm-Message-State: AJaThX4qXn8KisnYKHITpJAmzSp6OHgcK0RwyQVUU7LqvafnNpFwwLj6 xsgdANslAil4xvGWm8pL/ENigDfd X-Google-Smtp-Source: AGs4zMZYeW7mvBZHPDgaAgD3uySNjaUjHyHxji3vxwl8S1LuAsfYk/0eFu67/gA7ak/F72BSKj+gsw== X-Received: by 10.84.128.197 with SMTP id a63mr31931443pla.212.1512781878583; Fri, 08 Dec 2017 17:11:18 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id x21sm15580138pfi.174.2017.12.08.17.11.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Dec 2017 17:11:16 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Laura Abbott , Sumit Semwal , Benjamin Gaignard , Archit Taneja , Greg KH , Daniel Vetter , Dmitry Shmidt , Todd Kjos , Amit Pundir Subject: [PATCH] staging: ion: Fix ion_cma_heap allocations Date: Fri, 8 Dec 2017 17:11:12 -0800 Message-Id: <1512781872-4071-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In trying to add support for drm_hwcomposer to HiKey, I've needed to utilize the ION CMA heap, and I've noticed problems with allocations on newer kernels failing. It seems back with 204f672255c2 ("ion: Use CMA APIs directly"), the ion_cma_heap code was modified to use the CMA API, but kept the arguments as buffer lengths rather then number of pages. This results in errors as we don't have enough pages in CMA to satisfy the exaggerated requests. This patch converts the ion_cma_heap CMA API usage to properly request pages. It also fixes a minor issue in the allocation where in the error path, the cma_release is called with the buffer->size value which hasn't yet been set. Cc: Laura Abbott Cc: Sumit Semwal Cc: Benjamin Gaignard Cc: Archit Taneja Cc: Greg KH Cc: Daniel Vetter Cc: Dmitry Shmidt Cc: Todd Kjos Cc: Amit Pundir Fixes: 204f672255c2 ("staging: android: ion: Use CMA APIs directly") Acked-by: Laura Abbott Signed-off-by: John Stultz --- drivers/staging/android/ion/ion_cma_heap.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index dd5545d..86196ff 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -39,9 +39,15 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, struct ion_cma_heap *cma_heap = to_cma_heap(heap); struct sg_table *table; struct page *pages; + unsigned long size = PAGE_ALIGN(len); + unsigned long nr_pages = size >> PAGE_SHIFT; + unsigned long align = get_order(size); int ret; - pages = cma_alloc(cma_heap->cma, len, 0, GFP_KERNEL); + if (align > CONFIG_CMA_ALIGNMENT) + align = CONFIG_CMA_ALIGNMENT; + + pages = cma_alloc(cma_heap->cma, nr_pages, align, GFP_KERNEL); if (!pages) return -ENOMEM; @@ -53,7 +59,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, if (ret) goto free_mem; - sg_set_page(table->sgl, pages, len, 0); + sg_set_page(table->sgl, pages, size, 0); buffer->priv_virt = pages; buffer->sg_table = table; @@ -62,7 +68,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, free_mem: kfree(table); err: - cma_release(cma_heap->cma, pages, buffer->size); + cma_release(cma_heap->cma, pages, nr_pages); return -ENOMEM; } @@ -70,9 +76,10 @@ static void ion_cma_free(struct ion_buffer *buffer) { struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap); struct page *pages = buffer->priv_virt; + unsigned long nr_pages = PAGE_ALIGN(buffer->size) >> PAGE_SHIFT; /* release memory */ - cma_release(cma_heap->cma, pages, buffer->size); + cma_release(cma_heap->cma, pages, nr_pages); /* release sg table */ sg_free_table(buffer->sg_table); kfree(buffer->sg_table);