From patchwork Mon Sep 18 14:58:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 112927 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3762290qgf; Mon, 18 Sep 2017 07:59:07 -0700 (PDT) X-Received: by 10.98.153.67 with SMTP id d64mr18580543pfe.142.1505746747521; Mon, 18 Sep 2017 07:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505746747; cv=none; d=google.com; s=arc-20160816; b=NyByMYJwuY8+yE4HPfS5Pmz+ycoQSv5alt+9ekFoMd8DAtZuiWsVCgmmr2wlU/T67x Z9qCl+fn3ttUVFfKVpq7t8/14H6vJy9liuRNy8KWNPmJp+gpUHcW5iJdSffCtqyWA3uV 8YFp4JBRhIQy0vxIz5gBu4RfiI+xC9kX//vT5xUk00DitiOrutAXECTDH6o+xEK/n0C/ 9AcZdTT1NYq6+j+SPlDBjjBuF2g7RK7RnbhTtGdxoscFKeWhbPhg4BeLTDg66Stx41Yw Zi0MY1cez6rDwVM6AnmcciX168mq5QdTKmDb3w0sWYG350poap/R2iN2iOnyc5Wm/yRs 4CMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=/dhbwpUegjU9QLusVf4kFVaG4ZQjZ9P2Ktma7I3c2tE=; b=FU+TpSoFFNijpCaT0Hsl085lFy3XByBcb1jsXQ5e12bw3faANVVFtlNRixW19HwkYf MjtkyMnMcsWnP+0cSNNBh5t+rlg7oQ41c2GdHxk0A030lu4qiVVLlt+XvFqYo4FrkCKV kmooYVO+3DaXA0ADuswsuUYUVDCHnXORZF8KzJvMmNGqVbGQJrJUXfOeOrFDR390zLR/ Ojl7rUHOjk3K2pg7ACYScf48UlpPfedlbZuxmQofaMyXQ4mu0IFFSR5IJLHMV9eQvp7w CpQ6pq/f2mEOu0vyf/Igahur7LdcmgFywQ80FDR/0itowb5LZyaFkDtWSpsPGckTUumV FMMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FQvvlsw3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 90si5043796plb.565.2017.09.18.07.59.06; Mon, 18 Sep 2017 07:59:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FQvvlsw3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755851AbdIRO7E (ORCPT + 26 others); Mon, 18 Sep 2017 10:59:04 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:44495 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752979AbdIRO7D (ORCPT ); Mon, 18 Sep 2017 10:59:03 -0400 Received: by mail-wm0-f54.google.com with SMTP id 189so13750591wmh.1 for ; Mon, 18 Sep 2017 07:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=/dhbwpUegjU9QLusVf4kFVaG4ZQjZ9P2Ktma7I3c2tE=; b=FQvvlsw3IVODC/iZXVYKIM4P7e7b7QefPLBFWFDxcQ+X0Rb5r0i2EG96BVm2utefjq yRpgR9cimhUjDiL+q4x+E8EWBx/5XPk1cVJ46Ui986RzXITYsN2pppRVGziMnHksvJrB oFTJEjDwK+crIBGEWqc7r47ai9zUrrCMhSTFM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/dhbwpUegjU9QLusVf4kFVaG4ZQjZ9P2Ktma7I3c2tE=; b=c7xfIB6PPv5TrnAU1XvrrNnM+qlnUNqy21Qqa00aitsTM4eOz0LIBe9UYJaMEo0FUg ghKO5+Y5yQtpdBKx+6oHrkkWOmY/oQg4eCnIRZgdYEmsatRh3DNmtlfVJDrvzgPHvbnn iTjLMdBvMfYkaNyHVVkhmqNhCmxzHBbto/uoyGqLjG9uWyfUQzuZFstKDj2DXitagzTk 2xFlXExIb86dNSOEX9nA9BO8d0M5lIkywOKPt/NbMGWJrZIK9RtQ8D8eGr19Ou5iKj1B M3XaHuBTvJh9Lo59J4MLpgyLJZINDuJmpzrZ2peJbvs3tLIwMNLF4Oq1Ykwi9hZf1IYp VlxQ== X-Gm-Message-State: AHPjjUiNp3AzjsH1vaGOzXtOZGesqQGdApMFipf/cXwxZXudGiw3VANh Q7IpwB+8Lon7x00X1SxfGeQc1w== X-Google-Smtp-Source: AOwi7QD0YLHrilmCOgZLubUdKlwF0ppq1StVity/JJRASt2fHCwwAk+6uXNWA/p5Fy6OVumJI7RS3w== X-Received: by 10.28.88.6 with SMTP id m6mr4658105wmb.48.1505746741745; Mon, 18 Sep 2017 07:59:01 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([80.214.65.126]) by smtp.gmail.com with ESMTPSA id w5sm7789170wrg.65.2017.09.18.07.58.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Sep 2017 07:59:01 -0700 (PDT) From: Benjamin Gaignard To: labbott@redhat.com, sumit.semwal@linaro.org, gregkh@linuxfoundation.org, arve@android.com, riandrews@android.com, broonie@kernel.org Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Benjamin Gaignard Subject: [PATCH] staging: ion: create one device entry per heap Date: Mon, 18 Sep 2017 16:58:46 +0200 Message-Id: <1505746726-11443-1-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead a getting one common device "/dev/ion" for all the heaps this patch allow to create one device entry ("/dev/ionX") per heap. Getting an entry per heap could allow to set security rules per heap and global ones for all heaps. Allocation requests will be only allowed if the mask_id match with device minor. Query request could be done on any of the devices. Signed-off-by: Benjamin Gaignard --- drivers/staging/android/ion/ion-ioctl.c | 9 +++++++-- drivers/staging/android/ion/ion.c | 20 ++++++++++++++------ drivers/staging/android/ion/ion.h | 10 +++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) -- 2.7.4 diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index d9f8b14..ff06ce3 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -25,9 +25,11 @@ union ion_ioctl_arg { struct ion_heap_query query; }; -static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) +static int validate_ioctl_arg(struct file *filp, + unsigned int cmd, union ion_ioctl_arg *arg) { int ret = 0; + int mask = 1 << iminor(filp->f_inode); switch (cmd) { case ION_IOC_HEAP_QUERY: @@ -35,6 +37,9 @@ static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) ret |= arg->query.reserved1 != 0; ret |= arg->query.reserved2 != 0; break; + case ION_IOC_ALLOC: + ret = !(arg->allocation.heap_id_mask & mask); + break; default: break; } @@ -70,7 +75,7 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (copy_from_user(&data, (void __user *)arg, _IOC_SIZE(cmd))) return -EFAULT; - ret = validate_ioctl_arg(cmd, &data); + ret = validate_ioctl_arg(filp, cmd, &data); if (WARN_ON_ONCE(ret)) return ret; diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 93e2c90..5144f1a 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -40,6 +40,8 @@ #include "ion.h" +#define ION_DEV_MAX 32 + static struct ion_device *internal_dev; static int heap_id; @@ -541,11 +543,21 @@ void ion_device_add_heap(struct ion_heap *heap) { struct dentry *debug_file; struct ion_device *dev = internal_dev; + int ret; if (!heap->ops->allocate || !heap->ops->free) pr_err("%s: can not add heap with invalid ops struct.\n", __func__); + heap->ddev.devt = MKDEV(MAJOR(dev->devt), heap_id); + dev_set_name(&heap->ddev, "ion%d", heap_id); + device_initialize(&heap->ddev); + cdev_init(&heap->chrdev, &ion_fops); + heap->chrdev.owner = THIS_MODULE; + ret = cdev_device_add(&heap->chrdev, &heap->ddev); + if (ret < 0) + return; + spin_lock_init(&heap->free_lock); heap->free_list_size = 0; @@ -595,13 +607,9 @@ static int ion_device_create(void) if (!idev) return -ENOMEM; - idev->dev.minor = MISC_DYNAMIC_MINOR; - idev->dev.name = "ion"; - idev->dev.fops = &ion_fops; - idev->dev.parent = NULL; - ret = misc_register(&idev->dev); + ret = alloc_chrdev_region(&idev->devt, 0, ION_DEV_MAX, "ion"); if (ret) { - pr_err("ion: failed to register misc device.\n"); + pr_err("ion: unable to allocate major\n"); kfree(idev); return ret; } diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 621e5f7..ef51ff5 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -17,6 +17,7 @@ #ifndef _ION_H #define _ION_H +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include "../uapi/ion.h" @@ -90,13 +90,13 @@ void ion_buffer_destroy(struct ion_buffer *buffer); /** * struct ion_device - the metadata of the ion device node - * @dev: the actual misc device + * @dev: the actual device * @buffers: an rb tree of all the existing buffers * @buffer_lock: lock protecting the tree of buffers * @lock: rwsem protecting the tree of heaps and clients */ struct ion_device { - struct miscdevice dev; + dev_t devt; struct rb_root buffers; struct mutex buffer_lock; struct rw_semaphore lock; @@ -152,6 +152,8 @@ struct ion_heap_ops { * struct ion_heap - represents a heap in the system * @node: rb node to put the heap on the device's tree of heaps * @dev: back pointer to the ion_device + * @ddev: device structure + * @chrdev: associated character device * @type: type of heap * @ops: ops struct as above * @flags: flags @@ -176,6 +178,8 @@ struct ion_heap_ops { struct ion_heap { struct plist_node node; struct ion_device *dev; + struct device ddev; + struct cdev chrdev; enum ion_heap_type type; struct ion_heap_ops *ops; unsigned long flags;