From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754113AbcIBUlz (ORCPT ); Fri, 2 Sep 2016 16:41:55 -0400 Received: from mail-it0-f51.google.com ([209.85.214.51]:37130 "EHLO mail-it0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752847AbcIBUlx (ORCPT ); Fri, 2 Sep 2016 16:41:53 -0400 Subject: Re: [PATCHv2 4/4] staging: android: ion: Add ioctl to query available heaps To: Greg Kroah-Hartman References: <1472769644-11039-1-git-send-email-labbott@redhat.com> <1472769644-11039-5-git-send-email-labbott@redhat.com> <20160902061410.GC13294@kroah.com> Cc: Sumit Semwal , John Stultz , =?UTF-8?Q?Arve_Hj=c3=b8nnev=c3=a5g?= , Riley Andrews , Daniel Vetter , linaro-mm-sig@lists.linaro.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Eun Taik Lee , Liviu Dudau , Jon Medhurst , Mitchel Humpherys , Jeremy Gebben , Bryan Huntsman , Android Kernel Team , Chen Feng , Brian Starkey From: Laura Abbott Message-ID: <6e6578da-45c0-00e4-cd99-09b6931abe22@redhat.com> Date: Fri, 2 Sep 2016 13:41:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160902061410.GC13294@kroah.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/01/2016 11:14 PM, Greg Kroah-Hartman wrote: > On Thu, Sep 01, 2016 at 03:40:44PM -0700, Laura Abbott wrote: >> >> Ion clients currently lack a good method to determine what >> heaps are available and what ids they map to. This leads >> to tight coupling between user and kernel space and headaches. >> Add a query ioctl to let userspace know the availability of >> heaps. >> >> Signed-off-by: Laura Abbott >> --- >> drivers/staging/android/ion/ion-ioctl.c | 11 +++++++++ >> drivers/staging/android/ion/ion.c | 44 +++++++++++++++++++++++++++++++++ >> drivers/staging/android/ion/ion_priv.h | 3 +++ >> drivers/staging/android/uapi/ion.h | 39 +++++++++++++++++++++++++++++ >> 4 files changed, 97 insertions(+) >> >> diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c >> index 53b9520..e76d517 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_abi_version abi_version; >> + struct ion_heap_query query; >> }; >> >> static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) >> @@ -38,6 +39,11 @@ static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) >> case ION_IOC_ABI_VERSION: >> ret = arg->abi_version.reserved != 0; >> break; >> + case ION_IOC_HEAP_QUERY: >> + ret = arg->query.reserved0 != 0; >> + ret |= arg->query.reserved1 != 0; >> + ret |= arg->query.reserved2 != 0; >> + break; >> default: >> break; >> } >> @@ -162,6 +168,11 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) >> data.abi_version.abi_version = ION_ABI_VERSION; >> break; >> } >> + case ION_IOC_HEAP_QUERY: >> + { >> + ret = ion_query_heaps(client, &data.query); >> + break; >> + } > > Minor nit, the { } aren't needed here. Yeah, I know the other cases > have them, but they aren't all needed there either, no need to keep > copying bad code style :) > Huh, might deserve a checkpatch addition then. Never heard that one before. > > >> default: >> return -ENOTTY; >> } >> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c >> index 975b48f..91b765c 100644 >> --- a/drivers/staging/android/ion/ion.c >> +++ b/drivers/staging/android/ion/ion.c >> @@ -1174,6 +1174,49 @@ int ion_sync_for_device(struct ion_client *client, int fd) >> return 0; >> } >> >> +int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query) >> +{ >> + struct ion_device *dev = client->dev; >> + struct ion_heap_data __user *buffer = >> + (struct ion_heap_data __user *)query->heaps; > > Shouldn't query be marked as __user instead of having this cast? > No, the query structure itself is copied into the kernel in ion_ioctl. The sub field query->heaps is a user pointer which is marked as _u64 for compatability ala botching-ioctls.txt hence the cast. >> + int ret = -EINVAL, cnt = 0, max_cnt; >> + struct ion_heap *heap; >> + struct ion_heap_data hdata; >> + >> + memset(&hdata, 0, sizeof(hdata)); >> + >> + down_read(&dev->lock); >> + if (!buffer) { >> + query->cnt = dev->heap_cnt; > > Wait, query is __user? > > I think the mixing of user/kernel pointers here isn't quite right, or I > just really can't figure it out... > > And kbuild didn't seem to like this patch either :( > > But your first 2 patches are great, I'll queue them up later today. > > thanks, > > greg k-h >