Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp357994imu; Thu, 3 Jan 2019 22:05:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN5orlLhzcKuD6d+sEOux+9cnceV2y82vO4ozE34iOSOucefVsqzrDD3udwPp82doTOnX5mU X-Received: by 2002:a63:fb15:: with SMTP id o21mr546634pgh.211.1546581910895; Thu, 03 Jan 2019 22:05:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546581910; cv=none; d=google.com; s=arc-20160816; b=Lr/NTPriGIuPRF/2ehzzXVo+DwNz56pTPJihBx3L5YNL2L11TAav2oXBzxb4OjGQ/L RvDb+6qC6DiM0tLd3BZjM9Zc4k3jvhQZxxF2bnlr3dVq90ic6IhRumPFWkz7TxliUSXH NNwRtCd9frjnjwVyOv7LMn5w23MOlYG+6BmG1vFZiViw4TvE1FXi+/p4e+dZMJv+N0q0 O7e4+qF23mcyOUAXt6Ft/AI68dPepP1IVdat27X3P7l7nA1zaAZEi8yNTmJZhLtu6Bbq Nagi99g5GDNUei7GRd4UFYN/AQNQmM3KdtrH6fbBb9JIeJaVteMfoFF3MqidlGvE+1zU NhQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=zSadeRyo8ZWieUhJ4H9kk44LLYxK9xtQ50kWRQi9Muw=; b=U0AwUwpHgLBFy6rauuoiJiX6mGrx3hSYJ+2bO1rgc4WpL5CG8EPsS//LPg0KtT/N1a KXqL6JdAM2lGas/wDE4RwMgePac26v52tivxF9xtExXw+c2RWVSXZAqI6RCp88ugupPR YtbQgJVfsxSa/gBHgC6gShUIek9mlJt0Y8rez0y6K8PGkHkZNQ4e69lcI+hlmOJSTNcg DJ/Nyd8Flb2CS9cwANiP6n/Y9Z+Gd6XUENi+xrZ4x4YRG5460ehDtoz0Z/MYsbjNIkDB 0+KcXdngSVqPVONgUYlKLHs+jfqSUNbQGRgnI19wwExt02PnvF/vBtwfgbTik9xDOmw9 fUtg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 63si54048490pla.65.2019.01.03.22.04.41; Thu, 03 Jan 2019 22:05:10 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726137AbfADBxD (ORCPT + 99 others); Thu, 3 Jan 2019 20:53:03 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:39111 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725879AbfADBxC (ORCPT ); Thu, 3 Jan 2019 20:53:02 -0500 Received: by mail-qt1-f193.google.com with SMTP id u47so34387767qtj.6 for ; Thu, 03 Jan 2019 17:53:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zSadeRyo8ZWieUhJ4H9kk44LLYxK9xtQ50kWRQi9Muw=; b=qLzV6YCORM97adJn3oY3PsL/fPuoZlJWqjQITkxLrgVMxwvWp54zKlG5eHuObKl1T7 5bpSFhkNKMVHPmQB6rPjduyMG+134F6x53UtdPsDYh6wNRqA5CSI26mE1lCiD12p0p58 QJkYFuV2OOA8zKLgGX/E4ur/NEifZhQYOqNjk+dV8XyIDbIYorYOpYneMkXiDEYdY6j4 99AHSBMnXuImzKjvjQYjo/dLG8VJlfjmA7ye5FerdNnbZJVcjuSg7tjCITeb0LScRofS jeo8x8HeOKSfSrFFRLf/LUZRlnXFJAyRaSV9pZjfhCU48ssJ0SbdIdI9rvUG538/g+Mu 5AxQ== X-Gm-Message-State: AJcUukeEV4Dw2eZUuXSNNk+dFaWvJnY18fzPGL434hiCZMJ8JnZa7L85 xFr+l6adkIlEjpQu0hgcpNB6hozqmtk= X-Received: by 2002:aed:31a3:: with SMTP id 32mr46086650qth.234.1546566779841; Thu, 03 Jan 2019 17:52:59 -0800 (PST) Received: from ?IPv6:2601:602:9800:dae6::814b? ([2601:602:9800:dae6::814b]) by smtp.gmail.com with ESMTPSA id o34sm24634085qte.4.2019.01.03.17.52.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 17:52:59 -0800 (PST) Subject: Re: [PATCH] staging: android: ion: add buffer flag update ioctl To: "Zengtao (B)" , "sumit.semwal@linaro.org" Cc: Greg Kroah-Hartman , =?UTF-8?Q?Arve_Hj=c3=b8nnev=c3=a5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , "devel@driverdev.osuosl.org" , "dri-devel@lists.freedesktop.org" , "linaro-mm-sig@lists.linaro.org" , "linux-kernel@vger.kernel.org" References: <1545239943-15414-1-git-send-email-prime.zeng@hisilicon.com> <678F3D1BB717D949B966B68EAEB446ED24E2926A@dggemm526-mbx.china.huawei.com> <786ad55f-4651-56ce-cd5c-ca02f7ac4093@redhat.com> <678F3D1BB717D949B966B68EAEB446ED24E2B495@dggemm526-mbx.china.huawei.com> <58278bab-413c-ef5e-3074-5afbcc1b86de@redhat.com> <678F3D1BB717D949B966B68EAEB446ED24E31270@dggemm526-mbx.china.huawei.com> From: Laura Abbott Message-ID: Date: Thu, 3 Jan 2019 17:52:57 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <678F3D1BB717D949B966B68EAEB446ED24E31270@dggemm526-mbx.china.huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/3/19 5:42 PM, Zengtao (B) wrote: >> -----Original Message----- >> From: Laura Abbott [mailto:labbott@redhat.com] >> Sent: Thursday, January 03, 2019 6:31 AM >> To: Zengtao (B) ; sumit.semwal@linaro.org >> Cc: Greg Kroah-Hartman ; Arve Hjønnevåg >> ; Todd Kjos ; Martijn Coenen >> ; Joel Fernandes ; >> devel@driverdev.osuosl.org; dri-devel@lists.freedesktop.org; >> linaro-mm-sig@lists.linaro.org; linux-kernel@vger.kernel.org >> Subject: Re: [PATCH] staging: android: ion: add buffer flag update ioctl >> >> On 12/23/18 6:47 PM, Zengtao (B) wrote: >>> Hi laura: >>> >>>> -----Original Message----- >>>> From: Laura Abbott [mailto:labbott@redhat.com] >>>> Sent: Friday, December 21, 2018 4:50 AM >>>> To: Zengtao (B) ; >> sumit.semwal@linaro.org >>>> Cc: Greg Kroah-Hartman ; Arve >> Hjønnevåg >>>> ; Todd Kjos ; Martijn >> Coenen >>>> ; Joel Fernandes ; >>>> devel@driverdev.osuosl.org; dri-devel@lists.freedesktop.org; >>>> linaro-mm-sig@lists.linaro.org; linux-kernel@vger.kernel.org >>>> Subject: Re: [PATCH] staging: android: ion: add buffer flag update >>>> ioctl >>>> >>>> On 12/19/18 5:39 PM, Zengtao (B) wrote: >>>>> Hi laura: >>>>> >>>>>> -----Original Message----- >>>>>> From: Laura Abbott [mailto:labbott@redhat.com] >>>>>> Sent: Thursday, December 20, 2018 2:10 AM >>>>>> To: Zengtao (B) ; >>>> sumit.semwal@linaro.org >>>>>> Cc: Greg Kroah-Hartman ; Arve >>>> Hjønnevåg >>>>>> ; Todd Kjos ; Martijn >>>> Coenen >>>>>> ; Joel Fernandes ; >>>>>> devel@driverdev.osuosl.org; dri-devel@lists.freedesktop.org; >>>>>> linaro-mm-sig@lists.linaro.org; linux-kernel@vger.kernel.org >>>>>> Subject: Re: [PATCH] staging: android: ion: add buffer flag update >>>>>> ioctl >>>>>> >>>>>> On 12/19/18 9:19 AM, Zeng Tao wrote: >>>>>>> In some usecases, the buffer cached attribute is not determined at >>>>>>> allocation time, it's determined just before the real cpu mapping. >>>>>>> And from the memory view of point, a buffer should not have the >>>>>> cached >>>>>>> attribute util is really mapped by the cpu. So in this patch, we >>>>>>> introduced the new ioctl command to target the requirement. >>>>>>> >>>>>> >>>>>> This is racy and error prone. Can you explain more what problem >> you >>>>>> are trying to solve? >>>>> >>>>> My use case is like this: >>>>> 1. There are two process A and B, A takes case of ion buffer >>>>> allocation, >>>> and >>>>> pass the buffer fd to B, then B maps and uses it. >>>>> 2. Process B need to map the buffer with different cached attribute >>>>> for different use case, for example, if the buffer is used for pure >>>>> software algorithm, then we need to map it as cached, otherwise >>>>> non-cached, and B needs to deal with both cases. >>>>> And unfortunately the mmap syscall takes no cached flags and we >>>>> can't decide the cache attribute when we are doing the mmap, so I >>>>> introduce new the ioctl even though I think the solution is not as >> good. >>>>> >>>>> >>>> >>>> Thanks for the explanation, this was about the use case I expected. >>>> I'm pretty sure I had this exact problem once upon a time and we >>>> didn't come up with a solution. I'd still like to get rid of uncached >>>> buffers in general and just use cached buffers (see >>>> http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/201 >>>> 8-N >>>> ovember/128842.html) >>>> What's your usecase for uncached buffers? >>> >>> Some buffers are only used by HW, in this case, we tend to use >> uncached buffers. >>> But sometimes the SW need to read few buffer contents for debug >>> purpose and no synchronization is needed. >>> >> >> If this is primarily for debug, that's not really a compelling reason to >> support uncached buffers. It's incredibly difficult to do uncached buffers >> correctly I'd rather spend effort on making the cached use cases work >> better. >> > No, not only for debug, I meant if the buffers are uncached, the SW will only mmap > them for debug or even don't need to mmap them. > So for the two kinds of buffers: > 1. uncached: only the HW need to access it, the SW don't need to mmap it or just for debug. > 2. cached: both the HW and the SW need to access it. > The ION is designed as a generalized memory manager, I think we should cover as many > requirements as we can in the ION design, so I 'd rather that we keep the uncached support. > And I don’t quite understand the difficulty you mentioned to support the uncached buffers, would > you explain a little more about it. > We end up with aliasing problems. Each kernel page still has a cached mapping so it's very difficult to keep the two mappings in sync. https://lore.kernel.org/lkml/20181120164636.jcw7li2uaa3cmwc3@DESKTOP-E1NTVVP.localdomain/ This thread does a better job of explaining the problem and the objections to uncached buffers. And if the software never touches the buffer, why does it matter if the buffer is uncached? Laura > Thanks > Zengtao > >> >>>> >>>>>> >>>>>>> Signed-off-by: Zeng Tao >>>>>>> --- >>>>>>> drivers/staging/android/ion/ion-ioctl.c | 4 ++++ >>>>>>> drivers/staging/android/ion/ion.c | 17 >>>> +++++++++++++++++ >>>>>>> drivers/staging/android/ion/ion.h | 1 + >>>>>>> drivers/staging/android/uapi/ion.h | 22 >>>>>> ++++++++++++++++++++++ >>>>>>> 4 files changed, 44 insertions(+) >>>>>>> >>>>>>> diff --git a/drivers/staging/android/ion/ion-ioctl.c >>>>>>> b/drivers/staging/android/ion/ion-ioctl.c >>>>>>> index a8d3cc4..60bb702 100644 >>>>>>> --- a/drivers/staging/android/ion/ion-ioctl.c >>>>>>> +++ b/drivers/staging/android/ion/ion-ioctl.c >>>>>>> @@ -12,6 +12,7 @@ >>>>>>> >>>>>>> union ion_ioctl_arg { >>>>>>> struct ion_allocation_data allocation; >>>>>>> + struct ion_buffer_flag_data update; >>>>>>> struct ion_heap_query query; >>>>>>> }; >>>>>>> >>>>>>> @@ -83,6 +84,9 @@ long ion_ioctl(struct file *filp, unsigned int >>>>>>> cmd, unsigned long arg) >>>>>>> >>>>>>> break; >>>>>>> } >>>>>>> + case ION_IOC_BUFFER_UPDATE: >>>>>>> + ret = ion_buffer_update(data.update.fd, data.update.flags); >>>>>>> + break; >>>>>>> case ION_IOC_HEAP_QUERY: >>>>>>> ret = ion_query_heaps(&data.query); >>>>>>> break; >>>>>>> diff --git a/drivers/staging/android/ion/ion.c >>>>>>> b/drivers/staging/android/ion/ion.c >>>>>>> index 9907332..f1404dc 100644 >>>>>>> --- a/drivers/staging/android/ion/ion.c >>>>>>> +++ b/drivers/staging/android/ion/ion.c >>>>>>> @@ -436,6 +436,23 @@ int ion_alloc(size_t len, unsigned int >>>>>> heap_id_mask, unsigned int flags) >>>>>>> return fd; >>>>>>> } >>>>>>> >>>>>>> +int ion_buffer_update(unsigned int fd, unsigned int flags) { >>>>>>> + struct dma_buf *dmabuf; >>>>>>> + struct ion_buffer *buffer; >>>>>>> + >>>>>>> + dmabuf = dma_buf_get(fd); >>>>>>> + >>>>>>> + if (!dmabuf) >>>>>>> + return -EINVAL; >>>>>>> + >>>>>>> + buffer = dmabuf->priv; >>>>>>> + buffer->flags = flags; >>>>>>> + dma_buf_put(dmabuf); >>>>>>> + >>>>>>> + return 0; >>>>>>> +} >>>>>>> + >>>>>>> int ion_query_heaps(struct ion_heap_query *query) >>>>>>> { >>>>>>> struct ion_device *dev = internal_dev; diff --git >>>>>>> a/drivers/staging/android/ion/ion.h >>>>>>> b/drivers/staging/android/ion/ion.h >>>>>>> index c006fc1..99bf9ab 100644 >>>>>>> --- a/drivers/staging/android/ion/ion.h >>>>>>> +++ b/drivers/staging/android/ion/ion.h >>>>>>> @@ -199,6 +199,7 @@ int ion_heap_pages_zero(struct page >> *page, >>>>>> size_t size, pgprot_t pgprot); >>>>>>> int ion_alloc(size_t len, >>>>>>> unsigned int heap_id_mask, >>>>>>> unsigned int flags); >>>>>>> +int ion_buffer_update(unsigned int fd, unsigned int flags); >>>>>>> >>>>>>> /** >>>>>>> * ion_heap_init_shrinker >>>>>>> diff --git a/drivers/staging/android/uapi/ion.h >>>>>>> b/drivers/staging/android/uapi/ion.h >>>>>>> index 5d70098..99753fc 100644 >>>>>>> --- a/drivers/staging/android/uapi/ion.h >>>>>>> +++ b/drivers/staging/android/uapi/ion.h >>>>>>> @@ -74,6 +74,20 @@ struct ion_allocation_data { >>>>>>> __u32 unused; >>>>>>> }; >>>>>>> >>>>>>> +/** >>>>>>> + * struct ion_buffer_flag_data - metadata passed from userspace >>>>>>> +for update >>>>>>> + * buffer flags >>>>>>> + * @fd: file descriptor of the buffer >>>>>>> + * @flags: flags passed to the buffer >>>>>>> + * >>>>>>> + * Provided by userspace as an argument to the ioctl */ >>>>>>> + >>>>>>> +struct ion_buffer_flag_data { >>>>>>> + __u32 fd; >>>>>>> + __u32 flags; >>>>>>> +} >>>>>>> + >>>>>>> #define MAX_HEAP_NAME 32 >>>>>>> >>>>>>> /** >>>>>>> @@ -116,6 +130,14 @@ struct ion_heap_query { >>>>>>> struct ion_allocation_data) >>>>>>> >>>>>>> /** >>>>>>> + * DOC: ION_IOC_BUFFER_UPDATE - update the specified ion >> buffer >>>>>> flags >>>>>>> + * >>>>>>> + * Takes an ion_buffer_flag_data structure and returns the result >>>>>>> +of the >>>>>>> + * buffer flag update operation. >>>>>>> + */ >>>>>>> +#define ION_IOC_BUFFER_UPDATE _IOWR(ION_IOC_MAGIC, 1, \ >>>>>>> + struct ion_buffer_flag_data) >>>>>>> +/** >>>>>>> * DOC: ION_IOC_HEAP_QUERY - information about available >>>> heaps >>>>>>> * >>>>>>> * Takes an ion_heap_query structure and populates >> information >>>>>> about >>>>>>> >>>>> >>> >