From patchwork Wed Oct 10 14:46:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 12131 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 27C0F23EFB for ; Wed, 10 Oct 2012 15:02:09 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id AD599A18502 for ; Wed, 10 Oct 2012 15:02:08 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so1023889iej.11 for ; Wed, 10 Oct 2012 08:02:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=0LUaZtkiSsDJtRmVgnIS3Z6YMOJpFdChw1i9QM4XyFQ=; b=Bd+fdK/EBp52j1uY+uE3edsy6mnqH8DD9l2ZszOmQVrbXAOiuRrr7tchiyhEx3llWh lKmaIfbcw3TPI1e3fnw73UMcrGEJmOFx2vlF8q5xZhFBUulFILzXbZXbHV8Ib9gurS4M S3c0qvmVoJ4A0yvRGWPQCmfXzKCuSzrbZ2IgZutj9/K3K8pE0nVt4hL2QI1+nJghLahL Y0+tJ/EfLIvhWE1jIdWket+clcpRje+N1XipwivVxtPCL9vZJuHthUHOe87hzJ5LCoTh Di1a4ze0c6638KTDB9X99Mfs/pObzIspevZeysT9C1uOKcyWJIGC2knnjSLsMCz4E98w LCXA== Received: by 10.42.57.10 with SMTP id b10mr14346332ich.54.1349881327951; Wed, 10 Oct 2012 08:02:07 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp237362igt; Wed, 10 Oct 2012 08:02:07 -0700 (PDT) Received: by 10.14.223.199 with SMTP id v47mr6774572eep.45.1349881326356; Wed, 10 Oct 2012 08:02:06 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id u6si1103364eep.71.2012.10.10.08.02.05; Wed, 10 Oct 2012 08:02:06 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxnQ-0002xx-6n; Wed, 10 Oct 2012 15:02:04 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxnP-0002xs-DY for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 15:02:03 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO006NNN3EQC11@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 11 Oct 2012 00:02:02 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-4d-50758dea2f13 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 26.1B.03783.AED85705; Thu, 11 Oct 2012 00:02:02 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MBO002YDME0EC70@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 11 Oct 2012 00:02:02 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Wed, 10 Oct 2012 16:46:41 +0200 Message-id: <1349880405-26049-23-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> References: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCJMWRmVeSWpSXmKPExsVy+t9jAd1XvaUBBjt6xSy+XHnI5MDocfvf Y+YAxigum5TUnMyy1CJ9uwSujL/9m9gKPnNV3Ds/l7mBcQpnFyMnh4SAicT8u/dYIWwxiQv3 1rN1MXJxCAksYpR4c/wrM4SzlkniUedJRpAqNqCOY0s+g9kiAg4Sp+/OAitiFljDLPFi5Q02 kISwQKLEt1u/wcayCKhKnH32lAXE5hXwlNg2rZsdYp28xNP7fWD1nEDxC/OmM4PYQgIeEv/X b2aawMi7gJFhFaNoakFyQXFSeq6hXnFibnFpXrpecn7uJkaw359J7WBc2WBxiFGAg1GJhzcj qiRAiDWxrLgy9xCjBAezkgivqU9pgBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHeZo+UACGB9MSS 1OzU1ILUIpgsEwenVANjl/zUOQJixRkbntt9qPoto2BuoF3BuXnxsYUR2060+JRbfmDnOH4m SGvTu9m9vNWPWec2PlrO9Oie5Q1N4d2V/+s6tkeX9+54Yc19ReaZ7CY2nowDT1bLFuQkSAp+ 6ma9OLHVIHvH/H+uc7cn2r6OvP+jP/e+7HN2h5VXJROXR+jyxLmdmLlHiaU4I9FQi7moOBEA ztyq8fcBAAA= Cc: k.debski@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, sumit.semwal@ti.com, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, airlied@redhat.com, remi@remlab.net Subject: [Linaro-mm-sig] [PATCHv10 22/26] v4l: vb2-dma-contig: fail if user ptr buffer is not correctly aligned X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQknmyYrIzweAcDd8TEaCyBFnqJ07VbOn2UbUPLwdW6oklLK+Mo3K0xQl0YgL63VkuLFAyVr From: Marek Szyprowski The DMA transfer must be aligned to a specific value. If userptr is not aligned to DMA requirements then unexpected corruptions of the memory may occur before or after a buffer. To prevent such situations, all unligned userptr buffers are rejected at VIDIOC_QBUF. Signed-off-by: Marek Szyprowski Acked-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 2d661fd..571a919 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -493,6 +493,18 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr, struct vm_area_struct *vma; struct sg_table *sgt; unsigned long contig_size; + unsigned long dma_align = dma_get_cache_alignment(); + + /* Only cache aligned DMA transfers are reliable */ + if (!IS_ALIGNED(vaddr | size, dma_align)) { + pr_debug("user data must be aligned to %lu bytes\n", dma_align); + return ERR_PTR(-EINVAL); + } + + if (!size) { + pr_debug("size is zero\n"); + return ERR_PTR(-EINVAL); + } buf = kzalloc(sizeof *buf, GFP_KERNEL); if (!buf)