From patchwork Tue Sep 19 10:25:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 112978 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4729809qgf; Tue, 19 Sep 2017 03:26:09 -0700 (PDT) X-Received: by 10.159.247.202 with SMTP id v10mr834303plz.321.1505816769339; Tue, 19 Sep 2017 03:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505816769; cv=none; d=google.com; s=arc-20160816; b=LoNWp+e9jYr3I2nA8CSKN+iB91agl3Q8gAfR9bjuOYE3i1eSbGgWMz/rvETAPMZ20Y oSkNU2YesH4n7ZrG85O8ncu0VBSErT8KypevBzEksZ8MT/BKeaE5Z22Kr97Wftr1Yd5v Smr9w8a8CXt/kg+Xu6kvpN35mbXFKOiIMTDy3eTF058c3WO9I/8YUinX62JabgaeJAu9 cuQJyfBvYzW2oU3xeS658B0BkjgV3JLY6wNOqxFOSz02kcqqLh0XqUHxYtI3qlJXjhMi Z2JLLtXKStBGdngRSMd6xgEOhs/ds/LvKG/uASXVvq8vE6YEbzxZrUpRSI1G+lTNYjXf ZFGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=E3q4+DnoJTevrgOB3IhP71fBhH7C18Z06tfGTavzLvI=; b=imJiFXKe4z2OrjgVu3CNyXRORmWvEV5xv5GMrfakX7SCPBIfBJS5GoyZrsjZ5BEZ/P xlQ8hU4rU4dlT3epZcXW9ZevL6hd2WrLp8cr2ne3ZBEU8BIKR8nPs8mTOvpKPoVUNNaZ a+u3X+QScdAd3kJK4zCwm/Nt/HcxbnKN2RaHskswrdeZ/TCCH6lu0LZODIP6k01idNNu R8QiHE2HCTtbuHcwWMVVvAwNEBONWCgZzXLU8nSzExI7BbVx4AZhOsBu//4arBXMN5Ze IjVthfPvgOgznot55/RN6uPUYFb08RqDqWUUzUmbLZZvlAovjqgGQYFsqTBjyzzH0ksg 8rkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kkHYgEmV; 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 g8si1156930pgr.309.2017.09.19.03.26.09; Tue, 19 Sep 2017 03:26:09 -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=kkHYgEmV; 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 S1751466AbdISK0G (ORCPT + 26 others); Tue, 19 Sep 2017 06:26:06 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:50703 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750974AbdISK0D (ORCPT ); Tue, 19 Sep 2017 06:26:03 -0400 Received: by mail-wm0-f49.google.com with SMTP id v142so3805166wmv.5 for ; Tue, 19 Sep 2017 03:26: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:in-reply-to:references; bh=E3q4+DnoJTevrgOB3IhP71fBhH7C18Z06tfGTavzLvI=; b=kkHYgEmVJKj1m9aqQbAiTIrprSgww1J5HvRC8u6ky9gkiJx8Q1xPYa1mfQsC5r/9AK JUHXTAeGr1Nlh97FbghqkUhuFhsLcFQZM09CtZRH1aGXM5SBa0FjIOAlzsaQn3sT7348 0pqi80PSb9cmT86zLEFPk9wshPw4tPfkETn+4= 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:in-reply-to :references; bh=E3q4+DnoJTevrgOB3IhP71fBhH7C18Z06tfGTavzLvI=; b=Us/Obag6je5e4+c1W1gv/sW7Sl9qov9VgLh4buyIJNT7iojnysanzG19soYEcynhMw 7Gz4q5OoCIu+JSnwjNGgFU5VZD+6gHTwTM50Lcjh+avag1UEE0f131IRJGILxf8Euf2o tJ3Qso4J5md9rq2QusojYgLbNHSbJaw65446vXzl2kiD+bezQRw1hDgU7+18HsJp5JRJ NH+tR6C57YgAiezEJxttqXKFJVXmdhjvcYDQ4YtAugIKp/FsU20L9DiozYZLLjr76aGb EwcTUDbIDz3/sXymGwPi9HAq2yRkT67BvUeE96BnBVoh0iu5B8j9GhvwT0VqeMTkjBwG /5+w== X-Gm-Message-State: AHPjjUjiF+gEGiMPHDljl1hhTk4qO3hkf2qECr/hwPrCJhldR23o1m0Q Cs4icqXWxjohvXsJIr8SYUcPFQ== X-Google-Smtp-Source: AOwi7QBvbqmhXj5yyyGfNBs7vNRPCgphF1ooDrvqUw6ye5WRSdYwYZrtSmzkQwiQLVif5zP/8udiZQ== X-Received: by 10.28.97.135 with SMTP id v129mr670591wmb.98.1505816761767; Tue, 19 Sep 2017 03:26:01 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([80.215.227.50]) by smtp.gmail.com with ESMTPSA id 56sm9039451wrx.2.2017.09.19.03.25.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Sep 2017 03:26: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, dan.carpenter@oracle.com Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Benjamin Gaignard Subject: [PATCH v2 1/2] staging: ion: simplify ioctl args checking function Date: Tue, 19 Sep 2017 12:25:37 +0200 Message-Id: <1505816738-30017-2-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505816738-30017-1-git-send-email-benjamin.gaignard@linaro.org> References: <1505816738-30017-1-git-send-email-benjamin.gaignard@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make arguments checking more easy to read. Signed-off-by: Benjamin Gaignard --- drivers/staging/android/ion/ion-ioctl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index d9f8b14..e26b786 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -27,19 +27,18 @@ union ion_ioctl_arg { static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) { - int ret = 0; - switch (cmd) { case ION_IOC_HEAP_QUERY: - ret = arg->query.reserved0 != 0; - ret |= arg->query.reserved1 != 0; - ret |= arg->query.reserved2 != 0; + if (arg->query.reserved0 || + arg->query.reserved1 || + arg->query.reserved2 ) + return -EINVAL; break; default: break; } - return ret ? -EINVAL : 0; + return 0; } /* fix up the cases where the ioctl direction bits are incorrect */ From patchwork Tue Sep 19 10:25:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 112979 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4729848qgf; Tue, 19 Sep 2017 03:26:12 -0700 (PDT) X-Received: by 10.99.105.196 with SMTP id e187mr855487pgc.360.1505816772397; Tue, 19 Sep 2017 03:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505816772; cv=none; d=google.com; s=arc-20160816; b=aNyrgb+tOoq2XdaFC+dUbOhi2rlUvpOAWK049vYjVFofrXFmwGt3I8TuDlRtr9mvk2 6v2JvRlw1UcQXBAlkF+rdxdhVAzAsdSWxNJc6Sqc2uQiNtJeoDPwfu5kDzij0BgE+ddP RC+KrDhhfzdie8mzgHYECSIPVutKieZIjzo0ELjh6QhmsYMkWeqddr1QsrLuMEijjlof J82ZV0EjAUGLCfsTbIz168m5U71Yaa5kcU2OMVztfnGPJXSfH/kcsaZPHT/z0aAB0FPb w3Z49i475HGO5rib8EgJNNlL39+/Ikp9SueXA2sFoU6oJAn5CPaCCM/BywuTMUTJVVS3 b4RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uWZTMSgPvCMJ4c6hvL7kQC2377tDMWsHmKfHUvhSPtM=; b=0qldjGrMpkHvRsqfacSjvuSMI7jQm9HXYmX9hU19jj1hgq6LxcE3joIWKNxL70Z2u4 930pOdesRwa+dNEBV4DmGhVEXu7/lez5IMUPZSQwjr7tBXPfXb+9NzRwYg1I90Vi1fvw 0ds2+LxTsYEzITHp2gLoi05N2SXkGUo2F1uFnxGCVa6rzSp3JYPH4Q3MhjaTt7M5Oyb3 T1FVd81t2Gkc9vA7fN6Xz8VEhoN3o2o07tjjyuQGNUAH1GE+gapwjkstGtfKrLf/wAYx s9uTSO0HXyBVF/YbHbMCFs/m6z1Gkly9HtHL1psT7AKlTOmdgzjPtxBYy3Jz3yLuEdMo Byog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hQ3vRCdQ; 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 c8si1087406pfm.118.2017.09.19.03.26.12; Tue, 19 Sep 2017 03:26:12 -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=hQ3vRCdQ; 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 S1751517AbdISK0J (ORCPT + 26 others); Tue, 19 Sep 2017 06:26:09 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:51659 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751445AbdISK0G (ORCPT ); Tue, 19 Sep 2017 06:26:06 -0400 Received: by mail-wr0-f181.google.com with SMTP id z39so2652616wrb.8 for ; Tue, 19 Sep 2017 03:26:05 -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:in-reply-to:references; bh=uWZTMSgPvCMJ4c6hvL7kQC2377tDMWsHmKfHUvhSPtM=; b=hQ3vRCdQNpxrAqw/Y+yqCYserJdaBR3XH1RhZJrwZ6uBd56sSXiPDIDE8hbms7c5YB vn6xwAVsEE6kNFR3Odr4QZgki2yp4cBpw1ZktVrlwxAZedyu/0dsX+m4VzMaxOH0rXNU ty5jPxfIarQGa379azw5GZyI587nBdpYReD4s= 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:in-reply-to :references; bh=uWZTMSgPvCMJ4c6hvL7kQC2377tDMWsHmKfHUvhSPtM=; b=GbsexZQKVdYnW04p74LAYqUvbr4BVVKEYSXk3VR54dyU2JIkn4oYX3gtZCym+j7V7N Vw49ann1qioUdDVZYbCQ/hLuzRuwdEOEOvt0iMasLKPawnawXFHsBSkjczsXCPyKj7ud HoGPaMrNAeqXaCYveZnTpBsNH+rWPw1QeWtx85rwwfS0vkZyl+sMBqnTlzJzCWlGr/2f iOzFdabIZvmyzNua0JsaV3B3ueqM3prjg4CrVRdWvmIXDRTx8W4K15WYL6pk7wJscMPp CwlSCoOz2OAQU4YE2hFImj5oosqZ79/G/fLRuws708AS7GUSPWKYA/oc31Wcs+Tth59p alkA== X-Gm-Message-State: AHPjjUgO1X1j3BBqCQLp8qg0ezAMGwQ3BUc4XWUCiWTYBMLec0q46S2/ szuYoDX/A6xFMf8UXuOp5gfaDw== X-Google-Smtp-Source: AOwi7QDZuNfiZJHBcpXaBQotKyyjebokD8x9zVUACXyuyuuNAXkFU0qiHlNFGoHxYm9BqhrjrKrpbw== X-Received: by 10.223.151.55 with SMTP id r52mr1011744wrb.69.1505816764994; Tue, 19 Sep 2017 03:26:04 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([80.215.227.50]) by smtp.gmail.com with ESMTPSA id 56sm9039451wrx.2.2017.09.19.03.26.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Sep 2017 03:26:04 -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, dan.carpenter@oracle.com Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Benjamin Gaignard Subject: [PATCH v2 2/2] staging: ion: create one device entry per heap Date: Tue, 19 Sep 2017 12:25:38 +0200 Message-Id: <1505816738-30017-3-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505816738-30017-1-git-send-email-benjamin.gaignard@linaro.org> References: <1505816738-30017-1-git-send-email-benjamin.gaignard@linaro.org> 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 | 11 +++++++++-- drivers/staging/android/ion/ion.c | 23 +++++++++++++++++------ drivers/staging/android/ion/ion.h | 10 +++++++--- 3 files changed, 33 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 e26b786..c8c906c 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -25,8 +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 mask = 1 << iminor(filp->f_inode); + switch (cmd) { case ION_IOC_HEAP_QUERY: if (arg->query.reserved0 || @@ -34,6 +37,10 @@ static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) arg->query.reserved2 ) return -EINVAL; break; + case ION_IOC_ALLOC: + if (!(arg->allocation.heap_id_mask & mask)) + return -EINVAL; + break; default: break; } @@ -69,7 +76,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..3f8b595 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,24 @@ 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__); + if (heap_id >= ION_DEV_MAX) + return -EBUSY; + + 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 +610,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;