From patchwork Sat Dec 16 03:59:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 122161 Delivered-To: patches@linaro.org Received: by 10.140.22.227 with SMTP id 90csp299323qgn; Fri, 15 Dec 2017 19:59:52 -0800 (PST) X-Received: by 10.84.217.14 with SMTP id o14mr8713514pli.169.1513396792392; Fri, 15 Dec 2017 19:59:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513396792; cv=none; d=google.com; s=arc-20160816; b=Cb4FkKKkVqp+rbdt6ViNm4llQYiyhdMMHdv7m7oxrlac0jJHxuhWaQNP2REG82NmjC mDLINgRuX9RjqEsOLwqiQ12FqJQZDYT20QsEIkbRqOOgsung3ESSFB991kzIAOclwdhf vqxzYcbEkt2jHbh3fqueKc8zWt9H7z01LytiwguROYmng7AUJAEa810USEGVsaSsNAFd OGFApimUl9yDSw1/b0M9jnlh1aBmJgc7oXLxLcwYYBe9T4VKr1N8dEj1HEITIBX1cEvt MD1R71Mz41QRAeiVI5FgrtObgwBJKyZ2ZeS+BIdxwSQ6tndETEhl2YaWOPs5ChIxa1h2 /Etw== 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=q7kN2NBBzN6O63LDea54y6gIr1tobJSKvZvpwFHOTt4=; b=lF9Osu//piMG/6FKwHgWUcEY2ADkXrrJ7+8TJOHYKVZ6zcXVzC7kbmn39NpCldu9OQ NhPZ5xi4h83kXFuMyN4KZVRuS90315V7IGH06XMcgzLohcdsdrofsIHq17cRH81EuY7B fIrOokUHeX2MWsc7YD8ID2tTWNKYSQQ/fDSCRqEQX8tN5DvDoOF2rzH6LK/ohVVmbEZX Y5ZeZ+rE7T9H3d5liAqwCi3SJiQYSmxDVBKd9eU8jCDKhVufKAVPu4huUdTllVbFhSvO zn0ee7Yl9I9tDxRVpFbWx/MzlgyhFCx7+1g7IcDxDuu69id/xmLO77LsqHARD+Oo6EAC cxfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kwh4H0Is; 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 o125sor2224117pga.79.2017.12.15.19.59.52 for (Google Transport Security); Fri, 15 Dec 2017 19:59:52 -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=kwh4H0Is; 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=q7kN2NBBzN6O63LDea54y6gIr1tobJSKvZvpwFHOTt4=; b=kwh4H0Isu2M6uSg34LzpcCLZuT396yiFEBzYLp1v9TN6y+N8NuRikUMo5Ll+IQZDS8 QYAXZamId3kAOrUVxy68BNDJezJa4iHIU5BMZdoNIJor1V1Cl0eIQR3xxtUZjeRq+sR3 XbjnAZxTVvL8iypyGU4cSUudk/LlE/sDgG0F0= 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=q7kN2NBBzN6O63LDea54y6gIr1tobJSKvZvpwFHOTt4=; b=ZmBr4H7HWng3IVWUJPqW/VlYYANPiXuyv4dgnLQI2bRjn1ww88UrJQIEIztQNoU7Nt rf9eRrfolfkcQxwurOY+gI9ILwWC6nOIfYaC1zqpyVGA5jD8OXih8lUQtU8x+QnWdVkX Eafcecce/wySDpDdZeGAOgeVRYtW5kq9/ZYRwMh3kJhZj/GxgYhRCT6BSW7RY6klqSoy fGHPVN4OWO508QEyDJEdMO0vhsDkd4Pjs7ZqHjV+NmFZslLbe2gvup/rwGo5nm+kRNc8 tQ0oNeWGmXwAnZd5XDhPJEVho1Ob4rKsUNzZg/VkBIXmn41GlqcYXcdUpW39LvYLYEB4 Dr0Q== X-Gm-Message-State: AKGB3mI05q0R5qxYorUsOmEf2s7VF2DPJ7ybpgekvrHOkgVguFjNyHkG JaTa+dfvUK0qhkMTNtxgr64xxdN0 X-Google-Smtp-Source: ACJfBovgIZRfkSI9qED75JK6lEcmYWQ9zqJXNRxqzE9QyZMim6hVlqmk7GfwV/qeMz5/TWpA7wjgsg== X-Received: by 10.101.66.66 with SMTP id d2mr13754915pgq.244.1513396791750; Fri, 15 Dec 2017 19:59:51 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id k195sm11771473pgc.46.2017.12.15.19.59.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Dec 2017 19:59:50 -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 v3] staging: ion: Fix ion_cma_heap allocations Date: Fri, 15 Dec 2017 19:59:47 -0800 Message-Id: <1513396787-8572-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 --- v2: Fix build errors when CONFIG_CMA_ALIGNMENT isn't defined v3: Make CMA heap depend on DMA_CMA instead of just CMA to address the undefined CONFIG_CMA_ALIGNMENT issue. drivers/staging/android/ion/Kconfig | 2 +- drivers/staging/android/ion/ion_cma_heap.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig index a517b2d..8f64941 100644 --- a/drivers/staging/android/ion/Kconfig +++ b/drivers/staging/android/ion/Kconfig @@ -37,7 +37,7 @@ config ION_CHUNK_HEAP config ION_CMA_HEAP bool "Ion CMA heap support" - depends on ION && CMA + depends on ION && DMA_CMA help Choose this option to enable CMA heaps with Ion. This heap is backed by the Contiguous Memory Allocator (CMA). If your system has these 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);