From patchwork Tue Oct 11 23:50:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruchi Kandoi X-Patchwork-Id: 9371875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9893160865 for ; Tue, 11 Oct 2016 23:51:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8711C28643 for ; Tue, 11 Oct 2016 23:51:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B63529125; Tue, 11 Oct 2016 23:51:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20B5228931 for ; Tue, 11 Oct 2016 23:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753449AbcJKXvB (ORCPT ); Tue, 11 Oct 2016 19:51:01 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:35854 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753259AbcJKXut (ORCPT ); Tue, 11 Oct 2016 19:50:49 -0400 Received: by mail-pf0-f173.google.com with SMTP id e6so9245714pfk.3 for ; Tue, 11 Oct 2016 16:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=+rkvOaz1PnfYCxKvqeohoq0s4Wi3ry0L6k67WbobMMI=; b=XhcQarud56Ea5qlHKB9FFPkjIJizm0oCsd+l5keCJsD59Y87luFDTjSvHDtRNSpCLi uaKOkG1i8LU2sOaJXJLV8RJAtoCIUDjkJHZkqVvcoz2o5U2nOytqB29jNr2cB/bb0xuC u8wMLOkIDrTx4RV266SNsM4kPpoGlWVnnB2Sm5jpNBMKEVRi/ol9LgX2Y8pE5eicy7O9 u5bP0ho6nYaxXEVkzeJzGSLG2yF3AWfTf7O7KCrqm14PL1zb61PR7guI+hZUHvKmohiW IuOkVvTvF7kNHCaTCbb71M7LEzp8pqz3fiJN4jpYVrzI/m1QyxkfoqgnIqLfVDrsR0Ov TjpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+rkvOaz1PnfYCxKvqeohoq0s4Wi3ry0L6k67WbobMMI=; b=Rg+MihtArSh+AzzxCSGvmNaapLd8fwrftHyl8ly4BuxcbRLbacCbHeZSKyxsDFV05P EU8C06ECuIJPONouWsjV0EL4r6RRbJ7o15pjZ6Pp+7TOMjgEDi3eRHjqETAXWlb6lclm +tI/edbwwnXfBUWqxOlqUxwMDeAHg4Go7GGnbIb563sN2wAH/shqO/RJaW9jaMi58crd iIwiCA8gzPMm9Vjbk6XXN+PUqYJ6FbBKMCZid/szLDaDNTc6h8a+mrwr85v9bkCFpSzT AwDUEYzMacFT7/tFYEzxEqOAX1gmCpp9vT3V2hD85K79cXdgObCumlK5XeRo+aHHvAoY XXTw== X-Gm-Message-State: AA6/9RnrSmfpZ/QjeYslGWfxPdGH8b4r3KlenL0X00kDFI4H0qXCmsV/LEbmIDO5F+soxesd X-Received: by 10.98.36.219 with SMTP id k88mr812877pfk.88.1476229848401; Tue, 11 Oct 2016 16:50:48 -0700 (PDT) Received: from kandoiruchi.mtv.corp.google.com ([100.98.120.59]) by smtp.gmail.com with ESMTPSA id i8sm6922381paw.25.2016.10.11.16.50.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Oct 2016 16:50:47 -0700 (PDT) From: Ruchi Kandoi To: kandoiruchi@google.com, gregkh@linuxfoundation.org, arve@android.com, riandrews@android.com, sumit.semwal@linaro.org, arnd@arndb.de, labbott@redhat.com, viro@zeniv.linux.org.uk, jlayton@poochiereds.net, bfields@fieldses.org, mingo@redhat.com, peterz@infradead.org, akpm@linux-foundation.org, keescook@chromium.org, mhocko@suse.com, oleg@redhat.com, john.stultz@linaro.org, mguzik@redhat.com, jdanis@google.com, adobriyan@gmail.com, ghackmann@google.com, kirill.shutemov@linux.intel.com, vbabka@suse.cz, dave.hansen@linux.intel.com, dan.j.williams@intel.com, hannes@cmpxchg.org, iamjoonsoo.kim@lge.com, luto@kernel.org, tj@kernel.org, vdavydov.dev@gmail.com, ebiederm@xmission.com, linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC 6/6] drivers: staging: ion: add ION_IOC_TAG ioctl Date: Tue, 11 Oct 2016 16:50:10 -0700 Message-Id: <1476229810-26570-7-git-send-email-kandoiruchi@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1476229810-26570-1-git-send-email-kandoiruchi@google.com> References: <1476229810-26570-1-git-send-email-kandoiruchi@google.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Greg Hackmann ION_IOC_TAG provides a userspace interface for tagging buffers with their memtrack usage after allocation. Signed-off-by: Ruchi Kandoi --- drivers/staging/android/ion/ion-ioctl.c | 17 +++++++++++++++++ drivers/staging/android/uapi/ion.h | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index 7e7431d..8745a85 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -28,6 +28,7 @@ union ion_ioctl_arg { struct ion_handle_data handle; struct ion_custom_data custom; struct ion_heap_query query; + struct ion_tag_data tag; }; static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) @@ -162,6 +163,22 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case ION_IOC_HEAP_QUERY: ret = ion_query_heaps(client, &data.query); break; + case ION_IOC_TAG: + { +#ifdef CONFIG_MEMTRACK + struct ion_handle *handle; + + handle = ion_handle_get_by_id(client, data.tag.handle); + if (IS_ERR(handle)) + return PTR_ERR(handle); + data.tag.tag[sizeof(data.tag.tag) - 1] = 0; + memtrack_buffer_set_tag(&handle->buffer->memtrack_buffer, + data.tag.tag); +#else + ret = -ENOTTY; +#endif + break; + } default: return -ENOTTY; } diff --git a/drivers/staging/android/uapi/ion.h b/drivers/staging/android/uapi/ion.h index 14cd873..4c26196 100644 --- a/drivers/staging/android/uapi/ion.h +++ b/drivers/staging/android/uapi/ion.h @@ -115,6 +115,22 @@ struct ion_handle_data { ion_user_handle_t handle; }; +#define ION_MAX_TAG_LEN 32 + +/** + * struct ion_fd_data - metadata passed from userspace for a handle + * @handle: a handle + * @tag: a string describing the buffer + * + * For ION_IOC_TAG userspace populates the handle field with + * the handle returned from ion alloc and type contains the memtrack_type which + * accurately describes the usage for the memory. + */ +struct ion_tag_data { + ion_user_handle_t handle; + char tag[ION_MAX_TAG_LEN]; +}; + /** * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl * @cmd: the custom ioctl function to call @@ -217,6 +233,15 @@ struct ion_heap_query { #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) /** + * DOC: ION_IOC_TAG - adds a memtrack descriptor tag to memory + * + * Takes an ion_tag_data struct with the type field populated with a + * memtrack_type and handle populated with a valid opaque handle. The + * memtrack_type should accurately define the usage for the memory. + */ +#define ION_IOC_TAG _IOWR(ION_IOC_MAGIC, 8, struct ion_tag_data) + +/** * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl * * Takes the argument of the architecture specific ioctl to call and