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: 1574361 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7FEED3FE36 for ; Wed, 10 Oct 2012 15:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932307Ab2JJPCF (ORCPT ); Wed, 10 Oct 2012 11:02:05 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:45637 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932229Ab2JJPCD (ORCPT ); Wed, 10 Oct 2012 11:02:03 -0400 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 linux-media@vger.kernel.org; Thu, 11 Oct 2012 00:02:02 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-50-50758dea78a2 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id A6.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 linux-media@vger.kernel.org; Thu, 11 Oct 2012 00:02:02 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: airlied@redhat.com, m.szyprowski@samsung.com, t.stanislaws@samsung.com, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, sumit.semwal@ti.com, daeinki@gmail.com, daniel.vetter@ffwll.ch, robdclark@gmail.com, pawel@osciak.com, linaro-mm-sig@lists.linaro.org, hverkuil@xs4all.nl, remi@remlab.net, subashrp@gmail.com, mchehab@redhat.com, zhangfei.gao@gmail.com, s.nawrocki@samsung.com, k.debski@samsung.com Subject: [PATCHv10 22/26] v4l: vb2-dma-contig: fail if user ptr buffer is not correctly aligned 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+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jAd1XvaUBBjP2SVv0bNjK6sDo8XmT XABjFJdNSmpOZllqkb5dAlfG3/5NbAWfuSrunZ/L3MA4hbOLkZNDQsBEYu395WwQtpjEhXvr gWwuDiGBRYwSx3Y/YYRwVjFJ3F7zlhGkig2o49iSz2C2iICDxOm7s5hBipgF1jBLvFh5A2yU sECixLdbv1lBbBYBVYmzz56ygNi8Ap4S26Z1s0Osk5d4er8PrJ4TKH5h3nRmEFtIwEPi//rN TBMYeRcwMqxiFE0tSC4oTkrPNdQrTswtLs1L10vOz93ECPb6M6kdjCsbLA4xCnAwKvHwZkSV BAixJpYVV+YeYpTgYFYS4TX1KQ0Q4k1JrKxKLcqPLyrNSS0+xCjNwaIkztvskRIgJJCeWJKa nZpakFoEk2Xi4JRqYHTdNWNRJ3f8VrGtMSoaIZkHrjMrZSzUmsu0eVVQrc1/h+etaS0CvcEL 6n80drvM/ZB75VfWFJeVP0N5V5zh8NZbVRhsKf7rm0pL/BRNq/9f/5xReMK41feyX+nfJWX3 S/d8DtZUvCkeXWc41XhRVprs5TV+Dimz9nIER3+/8Ir51qn8GtM175RYijMSDbWYi4oTAZ/x tFH2AQAA Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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)