From patchwork Mon Aug 5 06:22:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher James Halse Rogers X-Patchwork-Id: 18766 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F0EB5246D0 for ; Mon, 5 Aug 2013 08:14:52 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id z20sf4250991yhz.11 for ; Mon, 05 Aug 2013 01:14:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-beenthere:x-forwarded-to:x-forwarded-for:delivered-to:from:to :date:message-id:x-mailer:x-mailman-approved-at:cc:subject :x-beenthere:x-mailman-version:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-gm-message-state:x-removed-original-auth :x-original-sender:x-original-authentication-results:mailing-list :x-google-group-id:content-type:content-transfer-encoding; bh=Cvo9Z0SiyrxtsJLcCo2qER9kQljGxclXU87+GUgf/6E=; b=jbXNu+4ooMfisdsk9XJTa+10dOw9DyXkOFeM7/VsuvuY68CEDRxf841lXAnu9HoGAw +QDkltahMlY0419AHQ53X6TroWub82gba29oqcAUxvH1Y+jyfmJALQxS5l4i6OYYF7ci k9einMb/NMI5bGTAZ7IxbEUFC18yaZqJhAEw+y4w8ZnScD20PBgE1vGQS2Kea/rsM/we AJ0NdO8SfLfp5hXTfGwhtbooUnVOE/ZVZKpG0hwd9YjGOTzAd4FiK8+lBgWwCvaRbn/f Xu55V/3bYUtkqcbxLSzmtKzhnvgAF1/ynuyeClNByYjZ5zI6hiEXxx0FD4Dzb8DtB03w BMkA== X-Received: by 10.236.148.33 with SMTP id u21mr7315712yhj.37.1375690492290; Mon, 05 Aug 2013 01:14:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.1.227 with SMTP id 3ls2672754qep.5.gmail; Mon, 05 Aug 2013 01:14:52 -0700 (PDT) X-Received: by 10.59.0.131 with SMTP id ay3mr5276811ved.78.1375690492183; Mon, 05 Aug 2013 01:14:52 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id gr9si4742735vec.73.2013.08.05.01.14.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Aug 2013 01:14:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.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.128.176; Received: by mail-ve0-f176.google.com with SMTP id b10so2712452vea.21 for ; Mon, 05 Aug 2013 01:14:52 -0700 (PDT) X-Received: by 10.58.128.71 with SMTP id nm7mr5444789veb.51.1375690492057; Mon, 05 Aug 2013 01:14:52 -0700 (PDT) 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.221.11.8 with SMTP id pc8csp75179vcb; Mon, 5 Aug 2013 01:14:51 -0700 (PDT) X-Received: by 10.15.42.129 with SMTP id u1mr15891286eev.116.1375690490819; Mon, 05 Aug 2013 01:14:50 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id u9si15371994eeg.261.2013.08.05.01.14.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 05 Aug 2013 01:14:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1V6Fw3-0002Gx-4u; Mon, 05 Aug 2013 08:14:35 +0000 Received: from li226-30.members.linode.com ([173.255.216.30] helo=mail.cooperteam.net) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1V6EB6-0001fu-OR for linaro-mm-sig@lists.linaro.org; Mon, 05 Aug 2013 06:22:00 +0000 Received: from Bebop.fritz.box (ppp105-211.static.internode.on.net [150.101.105.211]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: chris) by mail.cooperteam.net (Postfix) with ESMTPSA id 1D9B0104B29; Mon, 5 Aug 2013 06:22:09 +0000 (UTC) From: Christopher James Halse Rogers To: linux-kernel@vger.kernel.org Date: Mon, 5 Aug 2013 16:22:00 +1000 Message-Id: <1375683720-4748-1-git-send-email-christopher.halse.rogers@canonical.com> X-Mailer: git-send-email 1.8.3.2 X-Mailman-Approved-At: Mon, 05 Aug 2013 08:14:33 +0000 Cc: linux-arch@vger.kernel.org, Christopher James Halse Rogers , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, robclark@gmail.com, maarten.lankhorst@canonical.com, linux-media@vger.kernel.org Subject: [Linaro-mm-sig] [PATCH] dma-buf: Expose buffer size to userspace X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkZdbYlLUPEDRNhoG8WuBoodaeAU2q9QnDYrG/LrS+G5xs7jKLCpyTUnwu49HEIdMUS8Cum X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christopher.halse.rogers@canonical.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Each dma-buf has an associated size and it's reasonable for userspace to want to know what it is. Since userspace already has an fd, expose the size using the size = lseek(fd, SEEK_END, 0); lseek(fd, SEEK_CUR, 0); idiom. Signed-off-by: Christopher James Halse Rogers --- I've run into a point in the radeon DRM userspace where I need the size of a dma-buf. I could add a radeon-specific mechanism to get that, but this seems like something that would be more generally useful. I'm not entirely sure about supporting both SEEK_END and SEEK_CUR; this is somewhat of an abuse of lseek, as seeking obviously doesn't make sense. It's the obivous idiom for getting the size of what's on the other end of a file descriptor, though. I didn't notice anywhere to document this; Documentation/dma-buf-api didn't seem like the right place. Is there somewhere I've overlooked? drivers/base/dma-buf.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 6687ba7..c33a857 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -77,9 +77,36 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) return dmabuf->ops->mmap(dmabuf, vma); } +static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence) +{ + struct dma_buf *dmabuf; + loff_t base; + + if (!is_dma_buf_file(file)) + return -EBADF; + + dmabuf = file->private_data; + + /* only support discovering the end of the buffer, + but also allow SEEK_SET to maintain the idiomatic + SEEK_END(0), SEEK_CUR(0) pattern */ + if (whence == SEEK_END) + base = dmabuf->size; + else if (whence == SEEK_SET) + base = 0; + else + return -EINVAL; + + if (offset != 0) + return -EINVAL; + + return base + offset; +} + static const struct file_operations dma_buf_fops = { .release = dma_buf_release, .mmap = dma_buf_mmap_internal, + .llseek = dma_buf_llseek, }; /* @@ -133,6 +160,7 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, dmabuf->exp_name = exp_name; file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags); + file->f_mode |= FMODE_LSEEK; dmabuf->file = file;