From patchwork Sat Dec 14 03:26:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22482 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5051623908 for ; Sat, 14 Dec 2013 03:27:18 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id jw12sf5225732veb.7 for ; Fri, 13 Dec 2013 19:27:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=j1eA8cjDWBQ1/V7BBInAcJh6UonmwBg6fr7oPRbyHTc=; b=YbIfm79NX8itk4+/FGdt8WfTGF523owav8m8xgnMZjbwULKnYMDthp6Pdca1RauSJG Hc0eatyAZbkdRQFB8JoP/uUfuuTt5z8o23pJBnzgroupkL1jOCklKSyFp1JyJ4QD+aj0 Qhn9CTxQtX3mSwaUgdxr4OiZq+sp+VZeOOWkwK0LuYjZWGjoOtzPCNb1IyOQcY/4Z2Q2 t53NWBRuE5QHUtFEfpMdOQ6X2Pg4EasJj5q3V0Rhp6BRhoNjoL1jC/YHOnm5aaEV/1da 7ajZV0FsOpJphAYkgPIaP22VJZI0x8gFt/SHUSXV3Pc8ycrcuw8xwPSHurQVttXwhmaC AH1g== X-Gm-Message-State: ALoCoQkCZLhA+0KbXr1eiImZ4yC3FbtXr9LRAF4sY+VcZhl76Hww3gtStCA4nIx2eCb4R+qrIRWo X-Received: by 10.58.107.198 with SMTP id he6mr2144859veb.2.1386991638183; Fri, 13 Dec 2013 19:27:18 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.83.2 with SMTP id m2ls1323454qey.37.gmail; Fri, 13 Dec 2013 19:27:18 -0800 (PST) X-Received: by 10.58.208.130 with SMTP id me2mr2633274vec.13.1386991638109; Fri, 13 Dec 2013 19:27:18 -0800 (PST) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id td8si1432478vdc.1.2013.12.13.19.27.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 19:27:18 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id lf12so1865760vcb.35 for ; Fri, 13 Dec 2013 19:27:18 -0800 (PST) X-Received: by 10.58.228.231 with SMTP id sl7mr2538915vec.49.1386991638031; Fri, 13 Dec 2013 19:27:18 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp86972vcz; Fri, 13 Dec 2013 19:27:17 -0800 (PST) X-Received: by 10.66.144.102 with SMTP id sl6mr7135545pab.96.1386991637248; Fri, 13 Dec 2013 19:27:17 -0800 (PST) Received: from mail-pb0-f49.google.com (mail-pb0-f49.google.com [209.85.160.49]) by mx.google.com with ESMTPS id sw1si2984901pab.54.2013.12.13.19.27.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 19:27:17 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.49 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.49; Received: by mail-pb0-f49.google.com with SMTP id jt11so3307674pbb.8 for ; Fri, 13 Dec 2013 19:27:16 -0800 (PST) X-Received: by 10.66.142.107 with SMTP id rv11mr7261885pab.17.1386991636798; Fri, 13 Dec 2013 19:27:16 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id nw11sm11680086pab.13.2013.12.13.19.27.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 19:27:16 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , John Stultz Subject: [PATCH 112/115] ion: fix bugs in cma heap Date: Fri, 13 Dec 2013 19:26:32 -0800 Message-Id: <1386991595-6251-20-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386991595-6251-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> <1386991595-6251-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Colin Cross Implement ion_cma_unmap_kernel, ion will call it unconditionally. Use correct gfp flags when calling dma_alloc_coherent so it doesn't try to use atomic DMA memory. Check for invalid alignment when allocating. Reject cached allocations - the cpu address returned by dma_alloc_coherent is always going to be an uncached mapping, so map_kernel will not see data written by a cached userspace mapping. Signed-off-by: Colin Cross Signed-off-by: John Stultz --- drivers/staging/android/ion/ion_cma_heap.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index 3dcf9b4..f0f9889 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -69,13 +69,20 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, dev_dbg(dev, "Request buffer allocation len %ld\n", len); + if (buffer->flags & ION_FLAG_CACHED) + return -EINVAL; + + if (align > PAGE_SIZE) + return -EINVAL; + info = kzalloc(sizeof(struct ion_cma_buffer_info), GFP_KERNEL); if (!info) { dev_err(dev, "Can't allocate buffer info\n"); return ION_CMA_ALLOCATE_FAILED; } - info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle), 0); + info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle), + GFP_HIGHUSER | __GFP_ZERO); if (!info->cpu_addr) { dev_err(dev, "Fail to allocate buffer\n"); @@ -170,6 +177,11 @@ static void *ion_cma_map_kernel(struct ion_heap *heap, return info->cpu_addr; } +static void ion_cma_unmap_kernel(struct ion_heap *heap, + struct ion_buffer *buffer) +{ +} + static struct ion_heap_ops ion_cma_ops = { .allocate = ion_cma_allocate, .free = ion_cma_free, @@ -178,6 +190,7 @@ static struct ion_heap_ops ion_cma_ops = { .phys = ion_cma_phys, .map_user = ion_cma_mmap, .map_kernel = ion_cma_map_kernel, + .unmap_kernel = ion_cma_unmap_kernel, }; struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data)