Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1339226imu; Sat, 15 Dec 2018 21:24:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/XFpcskODYiH5jVWly8ZyAYMEvZ/kUXB16OvPb5Y0gye58+ez7aDdha965jfVQv7ebpyyzz X-Received: by 2002:a62:868b:: with SMTP id x133mr9138772pfd.252.1544937895063; Sat, 15 Dec 2018 21:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544937895; cv=none; d=google.com; s=arc-20160816; b=WaHPdwRxhEreaQC1t1CiTPEuIfGsrTuThrBg8HOqGjjvn1PX3UYVPYchmGuimoNF9A PtlkApFk7f5bLZESfSR629S+yxHLYbsIm4kMsl9Is3joNd2LNsKXMkjAANH0oQnR3KH9 AuoaUT/6ZiD0MmAq7K9+t71W0Zh8aFhln11WSgmFI/bvqb3D8v/HBgCbWuTqoUXVZPoE OOT4hQcybkljAmkacL5K1q6buO14EZkHT3Pw6y4tuAISUhXEmH5hP2dS9jFhJa4uB5/C zBol084ScC0+xJAAmsJirdsxzzHUFygv8mZU8GmTgqGcQVhlDGtS530fGJ4WDDJLN/Ky GJtg== 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=GykOiHgq1VFQQGf6RJ28fOYGVyNpMKFhAizGvYKRREE=; b=vvmkA4cgc2rGE2rfHc5GLyuzaEbOOjaLj3/X/00rG1uF9UyI5qnR2Yd8NMjWAYdhh3 rieeNVMq0oe7wkWAhaqAei4QoMUKxH+2qD9jQtyClaZu0SVk3ioE0vdzWQAF8uscg0F1 YZzYLHRZOWbySxizdKbq88c76BBuGmxpZRwyFECGsgOhyGcKTZVoL4aMg75Oq8kodvJI 5NLmLWJT+ER/keOpSWtLV8ex7SddCc2UKSv+I2O7N+TGA/vhSQbbuu+dZL/MMjhjIQXz GsarR7quKuWvqS4RY3zRYiG/n7Pku9g6Er4lJjwc/Jx8TqlceuZfco4feUnorYkIz2o2 RMtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=eoG11qat; dkim=pass header.i=@codeaurora.org header.s=default header.b=l8I4sev0; 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 t4si8216426pgg.110.2018.12.15.21.23.54; Sat, 15 Dec 2018 21:24:55 -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=eoG11qat; dkim=pass header.i=@codeaurora.org header.s=default header.b=l8I4sev0; 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 S1729819AbeLPFUy (ORCPT + 99 others); Sun, 16 Dec 2018 00:20:54 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:51328 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729069AbeLPFUx (ORCPT ); Sun, 16 Dec 2018 00:20:53 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id E84E86071B; Sun, 16 Dec 2018 05:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1544937651; bh=c11qcR8mQ3I6Y/SpHOnVg1n86x+PqXlEnPJ/siXmdM0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=eoG11qat+2J2ikyS8pek9jGWbDvOgLeTzsqFD5YcHSNZDdOF33xPgWCieVm/BUCAe k3Yhdl2fBf/IKajEqz1H1crtlE3frs4/r5mzrTyNY4Rseq4kxh8rQl50jHwRpnzfkO rbswjQxoqxNyoqo26/YiPcJJ/fPyneedpgKABFzI= 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 7A1CB6058E; Sun, 16 Dec 2018 05:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1544937650; bh=c11qcR8mQ3I6Y/SpHOnVg1n86x+PqXlEnPJ/siXmdM0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=l8I4sev0R1//sZTQmdsrFqi8cx3aAWuZWT98IhCDa43Sc1Gasy2kxhpba955jkDpc /OFMBaRhs8uyPIb4bVk2PESK5J5tyAaU3rhgc6rWN1ybPz84YvdYDy3glkHFOWk+Wr JYNrFvxtCwE9dmzr/wd3yV1FW5ODNqDwDytFl/BQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7A1CB6058E 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: Sat, 15 Dec 2018 21:20:49 -0800 (PST) From: Liam Mark X-X-Sender: lmark@lmark-linux.qualcomm.com To: Alexey Skidanov 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: <7d836085-cd8d-300b-56be-e8db4ff37afc@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> 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 Tue, 6 Feb 2018, Alexey Skidanov wrote: > > > On 02/07/2018 01:56 AM, Laura Abbott wrote: > > On 01/31/2018 10:10 PM, Alexey Skidanov wrote: > >> > >> On 01/31/2018 03:00 PM, Greg KH wrote: > >>> On Wed, Jan 31, 2018 at 02:03:42PM +0200, Alexey Skidanov wrote: > >>>> Any driver may access shared buffers, created by ion, using > >>>> dma_buf_vmap and > >>>> dma_buf_vunmap dma-buf API that maps/unmaps previosuly allocated > >>>> buffers into > >>>> the kernel virtual address space. The implementation of these API is > >>>> missing in > >>>> the current ion implementation. > >>>> > >>>> Signed-off-by: Alexey Skidanov > >>>> --- > >>> > >>> No review from any other Intel developers? :( > >> Will add. > >>> > >>> Anyway, what in-tree driver needs access to these functions? > >> I'm not sure that there are the in-tree drivers using these functions > >> and ion as> buffer exporter because they are not implemented in ion :) > >> But there are some in-tre> drivers using these APIs (gpu drivers) with > >> other buffer exporters. > > > > It's still not clear why you need to implement these APIs. > How the importing kernel module may access the content of the buffer? :) > With the current ion implementation it's only possible by dma_buf_kmap, > mapping one page at a time. For pretty large buffers, it might have some > performance impact. > (Probably, the page by page mapping is the only way to access large > buffers on 32 bit systems, where the vmalloc range is very small. By the > way, the current ion dma_map_kmap doesn't really map only 1 page at a > time - it uses the result of vmap() that might fail on 32 bit systems.) > > > Are you planning to use Ion with GPU drivers? I'm especially > > interested in this if you have a non-Android use case. > Yes, my use case is the non-Android one. But not with GPU drivers. > > > > Thanks, > > Laura > > Thanks, > Alexey 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. Based on discussions at LPC here is what was proposed: - #1 Add support to ION for dma_buf_vmap and dma_buf_vunmap - #2 Move any existing ION clients over from using dma_buf_kmap to dma_buf_vmap - #3 Deprecate support in ION for dma_buf_kmap? - #4 Make the above performance optimization to ion_dma_buf_begin_cpu_access to remove the creation of a kernel mapping. Thoughts? Liam Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project