Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1534069ybb; Fri, 29 Mar 2019 06:28:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUDxMEjxpVk3bZr5xEbtI70j26FbwBzuOl6p7LqzBGudFCbBjvJVXdiNv6939CPlSystWF X-Received: by 2002:a62:5185:: with SMTP id f127mr6624023pfb.199.1553866113243; Fri, 29 Mar 2019 06:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553866113; cv=none; d=google.com; s=arc-20160816; b=tSQvS4tqwxkcyPlKDxLBw5TlurTCOuCyI9UbWu14VmwQ0bR+112nzzDgB6fCHE8EID X3L2tqxXgiEs0gKjMNU7Z/ABuCHKXBor/fYD55UyxNDtfujPiePphIUgkkDTqeCHa50k ewjrPZcR1tGCqJ1pmSSMp71rJhYJvFxh8Y6Dcbj1gCJ+lXBWzgnKzfl3NSEj7UN5plVb 13NOTiMfovx2YiHr9375Qz9QWfmwadU2jZrwoca+7rNm4kdZ72lyg7I9DxGbbc4+G6kP m6zWguHbokWVc65z8qx7cgRXd/fv86XaAGlwm8ktIUtr2AA5PA74X8glcMgLTCapGdZt 5z4A== 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=7e5Q9Ti8TiacMjqfNeYCqFACxYIKO5gcweQdTSalm/Q=; b=o0q4fEKMYNSbtesq4Vjs9rDu5F/+U9/BfPxni52hkW2RumJa0PSo0GwCoTY+hNUcim xn+sevRpoZCeCDhGXzNWa1T8cn1WZGun5ILVa+iC3XdByv1TC4jYJCUj71XZQj6J3Vtp gFpzb98QdEMDftW3sLoi2HJFwGFX4qCeaFvpGOx8BkxI4C0iDDPSBavoWFwrHp2WkzFM mQXNC2gQVe/kUqhsN4SxAXEcEjvJqrRsD9A4YznYIDxwr5kTfXWwdKoLiV1xOIN0991C o4Hqy87TcmTdYAyDLmx15zsoVwoPscmCZ/J3e3F44igt5Bo2IoksWdMztkpNDsAmZCy8 ZSZw== 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 e10si1822956pgo.404.2019.03.29.06.28.16; Fri, 29 Mar 2019 06:28:33 -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; 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 S1729643AbfC2N1X (ORCPT + 99 others); Fri, 29 Mar 2019 09:27:23 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:37590 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729477AbfC2N1W (ORCPT ); Fri, 29 Mar 2019 09:27:22 -0400 Received: by mail-qk1-f195.google.com with SMTP id c1so1331565qkk.4 for ; Fri, 29 Mar 2019 06:27:22 -0700 (PDT) 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=7e5Q9Ti8TiacMjqfNeYCqFACxYIKO5gcweQdTSalm/Q=; b=dkFOLW5x0DTALZZDAAqKw1dh5PCUX6wN561mWPnH12Modd8rLufWqts40prI9K3/Vy XdhLFKTU1o+N9Oq8yFFpHXRHliehCPq/pEzAVqAwNBWAoBE7M3piAcbtxW5Xr70ISvi1 9AyPZx9ZVrixTbh2LOM8X45v+I1xlQeo46TLSVpMQWuZHc8YMBkfVVbHXJnybjpR5VGS TqHDik259IAPJNQV9tp65jHBMqAHRRIZRUV+L9eH/ZmkqW/4OMOLWbzfw/eOzyjCodwr mFORZl9lZjhf41Ru2x2K0KANZvCyNBP8yMl3anjJdirRwvJoOJDzpoQ6SMI6ahHrbE6q OVSw== X-Gm-Message-State: APjAAAVhCYOVJ37wmhaEmPq4ugULOycvQQMON2vvlhZDP4Pj8opR68/y hTP+Y8wWta8MrduJ2XT+7cvPhEhJ+Lk= X-Received: by 2002:a05:620a:14bc:: with SMTP id x28mr4365478qkj.221.1553866041182; Fri, 29 Mar 2019 06:27:21 -0700 (PDT) Received: from ?IPv6:2601:602:9800:dae6::fa4a? ([2601:602:9800:dae6::fa4a]) by smtp.gmail.com with ESMTPSA id y18sm1288365qty.78.2019.03.29.06.27.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 06:27:20 -0700 (PDT) Subject: Re: [PATCH] staging: android: ion: refactory ion_alloc for kernel driver use To: Zeng Tao , sumit.semwal@linaro.org Cc: Greg Kroah-Hartman , =?UTF-8?Q?Arve_Hj=c3=b8nnev=c3=a5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , devel@driverdev.osuosl.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org References: <1553884816-37850-1-git-send-email-prime.zeng@hisilicon.com> From: Laura Abbott Message-ID: Date: Fri, 29 Mar 2019 06:27:17 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.0 MIME-Version: 1.0 In-Reply-To: <1553884816-37850-1-git-send-email-prime.zeng@hisilicon.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/29/19 11:40 AM, Zeng Tao wrote: > There are two reasons for this patch: > 1. There are some potential requirements for ion_alloc in kernel space, > some media drivers need to allocate media buffers from ion instead of > buddy or dma framework, this is more convient and clean very for media > drivers. And In that case, ion is the only media buffer provider, it's > more easier to maintain. > 2. Fd is only needed by user processes, not the kernel space, so dma_buf > should be returned instead of fd for kernel space, and dma_buf_fd should > be called only for userspace api. > I really want to just NAK this because it doesn't seem like something that's necessary. The purpose of Ion is to provide buffers to userspace because there's no other way for userspace to get access to the memory. The kernel already has other APIs to access the memory. This also complicates the re-work that's been happening where the requirement is only userspace. Can you be more detailed about which media drivers you are referring to and why they can't just use other APIs? > Signed-off-by: Zeng Tao > --- > drivers/staging/android/ion/ion.c | 32 +++++++++++++++++--------------- > 1 file changed, 17 insertions(+), 15 deletions(-) > > diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c > index 92c2914..e93fb49 100644 > --- a/drivers/staging/android/ion/ion.c > +++ b/drivers/staging/android/ion/ion.c > @@ -387,13 +387,13 @@ static const struct dma_buf_ops dma_buf_ops = { > .unmap = ion_dma_buf_kunmap, > }; > > -static int ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags) > +struct dma_buf *ion_alloc(size_t len, unsigned int heap_id_mask, > + unsigned int flags) > { > struct ion_device *dev = internal_dev; > struct ion_buffer *buffer = NULL; > struct ion_heap *heap; > DEFINE_DMA_BUF_EXPORT_INFO(exp_info); > - int fd; > struct dma_buf *dmabuf; > > pr_debug("%s: len %zu heap_id_mask %u flags %x\n", __func__, > @@ -407,7 +407,7 @@ static int ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags) > len = PAGE_ALIGN(len); > > if (!len) > - return -EINVAL; > + return ERR_PTR(-EINVAL); > > down_read(&dev->lock); > plist_for_each_entry(heap, &dev->heaps, node) { > @@ -421,10 +421,10 @@ static int ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags) > up_read(&dev->lock); > > if (!buffer) > - return -ENODEV; > + return ERR_PTR(-ENODEV); > > if (IS_ERR(buffer)) > - return PTR_ERR(buffer); > + return ERR_PTR(PTR_ERR(buffer)); > > exp_info.ops = &dma_buf_ops; > exp_info.size = buffer->size; > @@ -432,17 +432,12 @@ static int ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags) > exp_info.priv = buffer; > > dmabuf = dma_buf_export(&exp_info); > - if (IS_ERR(dmabuf)) { > + if (IS_ERR(dmabuf)) > _ion_buffer_destroy(buffer); > - return PTR_ERR(dmabuf); > - } > > - fd = dma_buf_fd(dmabuf, O_CLOEXEC); > - if (fd < 0) > - dma_buf_put(dmabuf); > - > - return fd; > + return dmabuf; > } > +EXPORT_SYMBOL(ion_alloc); > > static int ion_query_heaps(struct ion_heap_query *query) > { > @@ -539,12 +534,19 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > case ION_IOC_ALLOC: > { > int fd; > + struct dma_buf *dmabuf; > > - fd = ion_alloc(data.allocation.len, > + dmabuf = ion_alloc(data.allocation.len, > data.allocation.heap_id_mask, > data.allocation.flags); > - if (fd < 0) > + if (IS_ERR(dmabuf)) > + return PTR_ERR(dmabuf); > + > + fd = dma_buf_fd(dmabuf, O_CLOEXEC); > + if (fd < 0) { > + dma_buf_put(dmabuf); > return fd; > + } > > data.allocation.fd = fd; > >