Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1377298imu; Sat, 15 Dec 2018 22:35:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/WZ82h+P9EeanDqevn5DrUZbXcETgDj83D4xn0+M6ScQ3LTEyfL5grnRHU3Mb349S7K3ssR X-Received: by 2002:a63:65c7:: with SMTP id z190mr8282579pgb.249.1544942117342; Sat, 15 Dec 2018 22:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544942117; cv=none; d=google.com; s=arc-20160816; b=CZVfecSUYg20z98nROzE10YofsUKGWPGtyjfsCk3FzI3mTBYjV6r/a/I+gC+rGwdRo /kHRGsMEZFyrwXiDlDEhm3a6Czm/IV1XThvyh6aEyeHmhXxEd+VZO3XFkurKqXVHi1bE 2j1USBIehMAVdy/M/dm6Nw+mDsLgkAGHJrcDFaU5t0qd/RnaPq8j1VKwHRAG3/KTOes+ TXI8tg7GpI/3WkSKh5llcoCxDkoDNy9wSXb5hTfPBCxF6q8qf8KE8aIhc9YZK2LuhNEw 7TLUWNQhhUNjOtGJ0h2HgUp9iI0NKopP9r7OAHnIb+dGnxiuoeWJFUATEdJJxsD2VZI3 Cwmw== 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=8Ggv8ii+HOxZ+iy6qKFs/1hMouIQsL8y4DNPJVML5c8=; b=D1Mz2aHfbAPxXQiJCdNHysYIwxwaJjb503evZg2HGVkzr/MBu5jhCaOUD2d1pg/Fzb 3mwf4FYVKa4YkkYovfVWA1Ur8qOycKlDgm2c90Nr3ZtKo7PKWOuQAN74W/6Zfyb9mlkQ HKIMgY+K4/6r5oyesuHt5/+FlPRZIyY26UHPFinNf7cmAcvspaHDwoX4aTcw9dg7kDKT 9Z6JKz2pjF5xOnTbGLW7f/QJdbQkYRPUsQf9dYFqfawKEWwUuq5yURMvX27SDimWNAdf +XW/hxdFeuVAA4fnoTe01jCfPMhRD3+W2mO2h2569++KBrTtyJX41tgQULqW8uKQXnlF AeQA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si7780583pll.221.2018.12.15.22.34.59; Sat, 15 Dec 2018 22:35:17 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729842AbeLPGeF (ORCPT + 99 others); Sun, 16 Dec 2018 01:34:05 -0500 Received: from mga18.intel.com ([134.134.136.126]:36885 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729758AbeLPGeF (ORCPT ); Sun, 16 Dec 2018 01:34:05 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Dec 2018 22:34:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,360,1539673200"; d="scan'208";a="101877302" Received: from kohsamui.iil.intel.com (HELO [10.236.193.12]) ([10.236.193.12]) by orsmga008.jf.intel.com with ESMTP; 15 Dec 2018 22:33:58 -0800 Subject: Re: [PATCH v3] staging: android: ion: Add implementation of dma_buf_vmap and dma_buf_vunmap To: Liam Mark 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 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> From: Alexey Skidanov Message-ID: <67f288db-d9ea-2d45-ddcf-a15dbff316f5@intel.com> Date: Sun, 16 Dec 2018 08:35:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 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 12/16/18 7:20 AM, Liam Mark wrote: > 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. 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 would suggest to fix the contract and to keep the dma_buf_kmap() support in ION. > > 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 > Thanks, Alexey