From patchwork Tue Oct 2 14:27:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1537601 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id B6E7CDFFAD for ; Tue, 2 Oct 2012 14:49:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 899B09F6BA for ; Tue, 2 Oct 2012 07:49:14 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by gabe.freedesktop.org (Postfix) with ESMTP id 6CDF69EB31 for ; Tue, 2 Oct 2012 07:30:29 -0700 (PDT) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MB900EV3SA0IC00@mailout4.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 02 Oct 2012 23:30:28 +0900 (KST) X-AuditID: cbfee61b-b7f2b6d000000f14-cf-506afa846379 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 1D.B1.03860.48AFA605; Tue, 02 Oct 2012 23:30:28 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MB9005A7S65K790@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 02 Oct 2012 23:30:28 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCHv9 22/25] v4l: vb2-dma-contig: fail if user ptr buffer is not correctly aligned Date: Tue, 02 Oct 2012 16:27:33 +0200 Message-id: <1349188056-4886-23-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> References: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jQd2WX1kBBs/3GVpc+fqezYHR4373 caYAxigum5TUnMyy1CJ9uwSujM7lqxgLLnJW/D29jqmBsZuji5GTQ0LARGLrgyVsELaYxIV7 64FsLg4hgemMEuf/72eGcNYxSfz+upIJpIoNqOPYks+MILaIgIPE6buzwIqYBdYwS7xYeQNs lLBAgsSB7vtARRwcLAKqEqdmxoOEeQU8JG6vaGSE2CYv8fR+H1g5J1D855MLLCC2kIC7xJ7l TWwTGHkXMDKsYhRNLUguKE5KzzXSK07MLS7NS9dLzs/dxAj2+jPpHYyrGiwOMQpwMCrx8O46 mRkgxJpYVlyZe4hRgoNZSYTX+n5WgBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHeZo+UACGB9MSS 1OzU1ILUIpgsEwenVAPj2oXX915pLl50pM+WK3O6ue4++87+F/uuPFv0gf/Gl9oX17j3HWLa wMgjUP/Wo0tB6I556v9iTZmy34+cdESPLLTNic62YDlZ8mjPxLAVPWt10j/uPW9T/mqq06Ic w2t6J8w2LHjad6ZWLla60DK95h9nYIvRBV22rKaLoUz1uxotn5/yVotTYinOSDTUYi4qTgQA BK4jLfYBAAA= Cc: t.stanislaws@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, mchehab@redhat.com, daniel.vetter@ffwll.ch, subashrp@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, zhangfei.gao@gmail.com, airlied@redhat.com, remi@remlab.net, m.szyprowski@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.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 --- drivers/media/video/videobuf2-dma-contig.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index b4d287a..55f8c80 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/videobuf2-dma-contig.c @@ -494,6 +494,13 @@ 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_err("user data must be aligned to %lu bytes\n", dma_align); + return ERR_PTR(-EINVAL); + } buf = kzalloc(sizeof *buf, GFP_KERNEL); if (!buf)