Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5256461imu; Tue, 29 Jan 2019 15:58:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN4Tm7sGpb9PwkbnwN19f0btox3yo8UCXGnRe74dd8rAPzlZm7GCBQPDdmKqOzOnKn1wusvF X-Received: by 2002:a63:6704:: with SMTP id b4mr25639860pgc.100.1548806292553; Tue, 29 Jan 2019 15:58:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548806292; cv=none; d=google.com; s=arc-20160816; b=1EJivXMAhfchbFIu6Fa5TOobiTHDtG/uusdAFdGlOoG6xIxUaW81xObbsKkPbC5u6K 8jJsUOuQuw6t2l2vxfD1+2TyHXAyUvFDI+7jNo1wqELcsQ+K50k4W16JvRbElS7jU1tM CyC3OMXkt56kgyf+xMgRhfxEZ9zuWFpFg67vY1UbxYVR5KFBsowzaDmFvE8ybu4FSI67 3eNaakmVmyRSRFDx98uZDHfkFUmsppoYzaSuGX0GgbbC6Ffrk9CpUqd2nv+888aOgxjT qAWpVY6VXtCp2nQtAPmSgpb1dUBfQWOEiaqixmPy1e5B9j8WfxMx8X/r4BB5bGiuAFL6 4S8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dmarc-filter :dkim-signature:dkim-signature; bh=gsrHbJvcE+QUeTSEFFGUd9m36FxapiJwa1bZLq0q10Y=; b=YlczflwuTMSSvHytsum7xcmDgvNzF1AC5m3lI0H1JAUXglGYKSPHiRso+HSsx/PzZ0 ipkiS9/XOESKflkJRn4YKbKX3nJYnzECqWB6zSH12o6Oqae3zhuTJBxU44bCevtDy4Tz aPMqFaiDUZHqKRBfDQB1pNJKhgP7uX7U1l/WlQmymSu/aSOMP54KY5gSlnrlOyJUAxGG /ymbgoA8TMrTDkPj5sjpJFZqCZfi3S9+SLVKDV7/HNfVux1fRfqtHxr//12W4J0nMugK m+mogSuAdcuJUrkgQfjBjwJQtnKJejqaTcwmw1rlnh+DTvcBakUnWCjMx8ZLCNcxpd+W 8c+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=NVv8tivW; dkim=pass header.i=@codeaurora.org header.s=default header.b="eqouPe/3"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h68si3322466plb.375.2019.01.29.15.57.56; Tue, 29 Jan 2019 15:58:12 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=NVv8tivW; dkim=pass header.i=@codeaurora.org header.s=default header.b="eqouPe/3"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727646AbfA2X4O (ORCPT + 99 others); Tue, 29 Jan 2019 18:56:14 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:36382 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726890AbfA2X4N (ORCPT ); Tue, 29 Jan 2019 18:56:13 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6D61C6083E; Tue, 29 Jan 2019 23:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1548806172; bh=3E39rNK8WQfnmWhN+okT8Vvmmb/HXZD26rZ/X0hdh0Q=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=NVv8tivW6iafeEDULqf0ovpXUh08RAEBK/lUO/ihnbybt2qEC8pkocuGGR2AOPjSq gKXxLZz0wUb5pbJJ8AILZ662s7DSuj0IbOQEwpeb/cc8cBgHuXSRRKlD6x7BZefD2P zT+I0rP4nb/+g4vKZfbWy1W9kBWa15J+9IPKMO+E= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from lmark-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lmark@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id A6D87604BE; Tue, 29 Jan 2019 23:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1548806171; bh=3E39rNK8WQfnmWhN+okT8Vvmmb/HXZD26rZ/X0hdh0Q=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=eqouPe/3rjVU1uFf653gYATT6UXa43w/iOopbJUYEmY4FIPK09z2VzvXbZRE+IXoZ kSn8Y1NDK5DE4vM/HXWiIz3j06nQxTNkYWIhXuIKhZ2nWBeuKmwVvyrrDowFxfwEBI 9o93jfpyLKeN/vA5c652D/gi2wJmRe1pbZwGdfQc= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A6D87604BE Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=lmark@codeaurora.org Date: Tue, 29 Jan 2019 15:56:10 -0800 (PST) From: Liam Mark X-X-Sender: lmark@lmark-linux.qualcomm.com To: "Skidanov, Alexey" cc: Laura Abbott , Greg KH , "devel@driverdev.osuosl.org" , "tkjos@android.com" , "rve@android.com" , "linux-kernel@vger.kernel.org" , "maco@android.com" , "sumit.semwal@linaro.org" Subject: RE: [PATCH v3] staging: android: ion: Add implementation of dma_buf_vmap and dma_buf_vunmap In-Reply-To: <040863540BC4D141BEB177532350882876A5692E@hasmsx108.ger.corp.intel.com> Message-ID: References: <1517400222-2854-1-git-send-email-alexey.skidanov@intel.com> <20180131130047.GA22917@kroah.com> <89be45dd-ac0e-4efb-2b21-e6c07b0cd66e@intel.com> <7d836085-cd8d-300b-56be-e8db4ff37afc@intel.com> <67f288db-d9ea-2d45-ddcf-a15dbff316f5@intel.com> <3740948f-02be-cf7a-bc41-54b4fd195103@intel.com> <040863540BC4D141BEB177532350882876A5692E@hasmsx108.ger.corp.intel.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 4 Jan 2019, Skidanov, Alexey wrote: > > > > -----Original Message----- > > From: Liam Mark [mailto:lmark@codeaurora.org] > > Sent: Friday, January 04, 2019 19:42 > > To: Skidanov, Alexey > > Cc: Laura Abbott ; Greg KH ; > > devel@driverdev.osuosl.org; tkjos@android.com; rve@android.com; linux- > > kernel@vger.kernel.org; maco@android.com; sumit.semwal@linaro.org > > Subject: Re: [PATCH v3] staging: android: ion: Add implementation of dma_buf_vmap and > > dma_buf_vunmap > > > > On Tue, 18 Dec 2018, Alexey Skidanov wrote: > > > > > >>> I was wondering if we could re-open the discussion on adding support to > > > >>> ION for dma_buf_vmap. > > > >>> It seems like the patch was not taken as the reviewers wanted more > > > >>> evidence of an upstream use case. > > > >>> > > > >>> Here would be my upstream usage argument for including dma_buf_vmap > > > >>> support in ION. > > > >>> > > > >>> Currently all calls to ion_dma_buf_begin_cpu_access result in the creation > > > >>> of a kernel mapping for the buffer, unfortunately the resulting call to > > > >>> alloc_vmap_area can be quite expensive and this has caused a performance > > > >>> regression for certain clients when they have moved to the new version of > > > >>> ION. > > > >>> > > > >>> The kernel mapping is not actually needed in ion_dma_buf_begin_cpu_access, > > > >>> and generally isn't needed by clients. So if we remove the creation of the > > > >>> kernel mapping in ion_dma_buf_begin_cpu_access and only create it when > > > >>> needed we can speed up the calls to ion_dma_buf_begin_cpu_access. > > > >>> > > > >>> An additional benefit of removing the creation of kernel mappings from > > > >>> ion_dma_buf_begin_cpu_access is that it makes the ION code more secure. > > > >>> Currently a malicious client could call the DMA_BUF_IOCTL_SYNC IOCTL with > > > >>> flags DMA_BUF_SYNC_END multiple times to cause the ION buffer kmap_cnt to > > > >>> go negative which could lead to undesired behavior. > > > >>> > > > >>> One disadvantage of the above change is that a kernel mapping is not > > > >>> already created when a client calls dma_buf_kmap. So the following > > > >>> dma_buf_kmap contract can't be satisfied. > > > >>> > > > >>> /** > > > >>> * dma_buf_kmap - Map a page of the buffer object into kernel address > > > >>> space. The > > > >>> * same restrictions as for kmap and friends apply. > > > >>> * @dmabuf: [in] buffer to map page from. > > > >>> * @page_num: [in] page in PAGE_SIZE units to map. > > > >>> * > > > >>> * This call must always succeed, any necessary preparations that might > > > >>> fail > > > >>> * need to be done in begin_cpu_access. > > > >>> */ > > > >>> > > > >>> But hopefully we can work around this by moving clients to dma_buf_vmap. > > > >> I think the problem is with the contract. We can't ensure that the call > > > >> is always succeeds regardless the implementation - any mapping might > > > >> fail. Probably this is why *all* clients of dma_buf_kmap() check the > > > >> return value (so it's safe to return NULL in case of failure). > > > >> > > > > > > > > I think currently the call to dma_buf_kmap will always succeed since the > > > > DMA-Buf contract requires that the client first successfully call > > > > dma_buf_begin_cpu_access(), and if dma_buf_begin_cpu_access() succeeds > > > > then dma_buf_kmap will succeed. > > > > > > > >> I would suggest to fix the contract and to keep the dma_buf_kmap() > > > >> support in ION. > > > > > > > > I will leave it to the DMA-Buf maintainers as to whether they want to > > > > change their contract. > > > > > > > > Liam > > > > > > > > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, > > > > a Linux Foundation Collaborative Project > > > > > > > > > > Ok. We need the list of the clients using the ION in the mainline tree. > > > > > > > Looks to me like the only functions which might be calling > > dma_buf_kmap/dma_buf_kunmap on ION buffers are > > tegra_bo_kmap/tegra_bo_kunmap, I assume Tegra is used in some Android > > automotive products. > > > > Looks like these functions could be moved over to using > > dma_buf_vmap/dma_buf_vunmap but it wouldn't be very clean and would add a > > performance hit. > > > > Liam > > > > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, > > a Linux Foundation Collaborative Project > > I'm a little bit confused. Why making the buffer accessible by CPU (mapping the buffer) > and making the content of the buffer valid (coherent) are so tightly coupled in DMA-BUF? > Hi Sumit, Hope you are feeling better. I was wondering if you would be open to changes to to the DMA-BUF contract so that we can remove the creation of kernel mappings in begin_cpu_access. This would have the benefit of improving the performance of begin_cpu_access and removing the ability for userspace to add and remove kernel mappings. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project