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: 11943 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 97BD91A52FC for ; Tue, 2 Oct 2012 14:30:39 +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 43E4DA18672 for ; Tue, 2 Oct 2012 14:30:39 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so14258231iej.11 for ; Tue, 02 Oct 2012 07:30:39 -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=rOUF6te5V42nSjC9Bx6X0yG5rzHZMcKyZLV6ojsvU3s=; b=hB55lIDaPn+KSFKDMvjqfht+VSUXOLo2KI9p1sunD6s09riLwKy+X/vO5fGSFuNSpy fk26y7GzrTsrUpSBhH68KrfAIm6QNkU/wE6GiNNuhvFKNIByWez7dGRQf+GhY8qdEOJp 8lRUcfHq+ecRLcr5f8JiSucLiMeHS7tr5am+p3E0oexr6KgLZ+a9P2FPUFiYOIb7MlaP QLLAGdbN4efqxjm8IVErnNxlyUwG/FdQSP4eE/3DJC5zIBkpWx47rUM2LRlDNT3C5Y4g gkUC7q68UV02BAMSJpWanZN2L1TL8Wq0IlpM/N2PrfaWj6j138tMJt5dBp+VxKXX/pxk 2MoA== Received: by 10.50.150.198 with SMTP id uk6mr8951642igb.43.1349188239043; Tue, 02 Oct 2012 07:30:39 -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.184.232 with SMTP id ex8csp85062igc; Tue, 2 Oct 2012 07:30:38 -0700 (PDT) Received: by 10.180.81.38 with SMTP id w6mr22321820wix.10.1349188237746; Tue, 02 Oct 2012 07:30:37 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id z24si1363893wep.49.2012.10.02.07.30.36; Tue, 02 Oct 2012 07:30:37 -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 1TJ3UW-0005H4-52; Tue, 02 Oct 2012 14:30:35 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TJ3UU-0005GU-7n for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 14:30:30 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MB9006YXSAS9XL0@mailout1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:30:28 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-fe-506afa847207 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 2A.BE.03783.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 linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:30:28 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org 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+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jQd2WX1kBBuuuGVl8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGZ3LVzEWXOSs+Ht6HVMDYzdHFyMnh4SAicTkOfuZIWwxiQv3 1rOB2EIC0xklWi64dDFyAdlrmST2f1wEVsQG1HBsyWdGEFtEwEHi9N1ZzCBFzAJrmCVerLwB 1i0skCBxoPs+UBEHB4uAqsSpmfEgYV4BD4nbKxoZIZbJSzy93wdWzgkU//nkAgvEYneJPcub 2CYw8i5gZFjFKJpakFxQnJSea6hXnJhbXJqXrpecn7uJEezzZ1I7GFc2WBxiFOBgVOLh3Xky M0CINbGsuDL3EKMEB7OSCK/1/awAId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rzNHikBQgLpiSWp 2ampBalFMFkmDk6pBsaWQDnNRMbbSwxVFvNNXbqyd8LsjrfLSu24zWfJ8RlrPVtkWxySP+He ZotVO+O2pBg0VKcXTVbu4/jc/Ppnt3Z22Wz1jI6qpjSG7IhrLSWO3z6Juf1PS5sacKUo3z6z 6qPxsnMH1l5oMJts6yY1eXdoRavf2n8i72/++fHn5O2p8tavjt7zmK7EUpyRaKjFXFScCADx DkOs9QEAAA== 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] [PATCHv9 22/25] 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: ALoCoQlOfSX0xZPBwmP/Zb21jnnJVS9vkKU8++afvHSTsY1wIq8sNbuEA1ak41kVFtptmC4J79nr 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)