Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9207253ybi; Tue, 23 Jul 2019 23:59:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJ6KYkgjyY+wWi+P2xnIJNPhT2mmg+M7CEjLSzu+MIXdtNhtmS7EEKgtCKlQlGCs0R/rYA X-Received: by 2002:a17:902:8a94:: with SMTP id p20mr84080480plo.312.1563951547945; Tue, 23 Jul 2019 23:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563951547; cv=none; d=google.com; s=arc-20160816; b=XeIbcGfr3COVJsH2z1fl6y9VYrgwlDmaAcPW8PX7MDQA1qUMgPLtWbNqZpnk8aUpgE XmMkREtZAOId3Egsf429p0lnjknxn9/r4qcC57xkYxWXAuN/cBBPw1GldFbv3ucXbzjp CWjGSheVmE1J4hXnCcOlR7AFTr0Ibti2CBhPf42ZTPc2DeOE0jiUsDmdo78mrc2BasJ6 XrJcLRolDDiIzAH3d/Adz1JfwzFcLtciPGEAYwCpvdLIpZb1j/+pDkWWbDxvzO53J53G zxC0sRTxn2+KCleWTR498tU17xO9zP2vbJQN5JRwFNYEjgFVgIdvsu2H12wrLABD93uI E2sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3X59uoIHWkle5151095EWlIhQ1uYulWqiYohiJvGIW0=; b=cpqYq5sm7RUH/JTnIo04HPro72BmUF/JqyHCcye2NnocO5dreg2DTurHTOfRzB2I+s jz8eSW//JUpPVU6WW7Ar1yoJW3YFFT//C8nsXoWGZAOdsH1JIQ+G+Skyn7GDJjK+dkCj uZQ1aF90IoRK8R0txVC7Nls+Vuupc/T3Ygopr7bOyc7S4Mbn8hbSpp56tX0EOg5Drypf Zoq7UTxyiADjCFqAs98UBRX9qfWv1s1TedcurvioYQ9JLbnZTqfG5Rlmk7x+Yp23lgjH WX0nDIQbpILdR06atEPbfDOZqvnHYGOh8H+1SMn/7RscN8Dd/ELImffSv0Ma+xrGnniA jXlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aZBHL++K; 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 a15si16931096pfg.87.2019.07.23.23.58.53; Tue, 23 Jul 2019 23:59:07 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aZBHL++K; 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 S1726240AbfGXG6P (ORCPT + 99 others); Wed, 24 Jul 2019 02:58:15 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41370 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbfGXG6P (ORCPT ); Wed, 24 Jul 2019 02:58:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=3X59uoIHWkle5151095EWlIhQ1uYulWqiYohiJvGIW0=; b=aZBHL++KElV7HejBz79l9aZpK WBi0+MfJWwUOWKC+kfJMHuYt2drkRJJ/IVSu/9T4E34Mg9lLPBX656A/Dtj3Sb3d2VaaMAdhHlRNz uCZgBsyiE3rx+f3LDhHCsXrQjn4NxUPdWaJQpa1l0QDJV/9bVb1/S6/IgNpEz9LdnlEioxXympEEX HWogf3lxQev2KnAtWlALsqZ5fsJ5YR1HnVc6I8AVM7o3ayY/RVD7tKO1eDsoOrkmIin578HoeQQVo sBzga0ZoDchy/8z6hJ5B+oSLxQNIgzOBbjsfhXnWXDKb528plA3SxBuvJB2atPh2HgVzJDS27j+Kh CexYiLXfA==; Received: from hch by bombadil.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1hqBE5-0006R9-MH; Wed, 24 Jul 2019 06:58:13 +0000 Date: Tue, 23 Jul 2019 23:58:13 -0700 From: Christoph Hellwig To: John Stultz Cc: Christoph Hellwig , lkml , Laura Abbott , Benjamin Gaignard , Sumit Semwal , Liam Mark , Pratik Patel , Brian Starkey , Vincent Donnefort , Sudipto Paul , "Andrew F . Davis" , Xu YiPing , "Chenfeng (puck)" , butao , "Xiaqing (A)" , Yudongbin , Chenbo Feng , Alistair Strachan , dri-devel , Hridya Valsaraju , Rob Clark Subject: Re: [PATCH v6 2/5] dma-buf: heaps: Add heap helpers Message-ID: <20190724065813.GB16225@infradead.org> References: <20190624194908.121273-1-john.stultz@linaro.org> <20190624194908.121273-3-john.stultz@linaro.org> <20190718100654.GA19666@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 22, 2019 at 09:09:25PM -0700, John Stultz wrote: > On Thu, Jul 18, 2019 at 3:06 AM Christoph Hellwig wrote: > > > > > +void INIT_HEAP_HELPER_BUFFER(struct heap_helper_buffer *buffer, > > > + void (*free)(struct heap_helper_buffer *)) > > > > Please use a lower case naming following the naming scheme for the > > rest of the file. > > Yes! Apologies as this was a hold-over from when the initialization > function was an inline function in the style of > INIT_WORK/INIT_LIST_HEAD. No longer appropriate that its a function. > I'll change it. > > > > +static void *dma_heap_map_kernel(struct heap_helper_buffer *buffer) > > > +{ > > > + void *vaddr; > > > + > > > + vaddr = vmap(buffer->pages, buffer->pagecount, VM_MAP, PAGE_KERNEL); > > > + if (!vaddr) > > > + return ERR_PTR(-ENOMEM); > > > + > > > + return vaddr; > > > +} > > > > Unless I'm misreading the patches this is used for the same pages that > > also might be dma mapped. In this case you need to use > > flush_kernel_vmap_range and invalidate_kernel_vmap_range in the right > > places to ensure coherency between the vmap and device view. Please > > also document the buffer ownership, as this really can get complicated. > > Forgive me I wasn't familiar with those calls, but this seems like it > would apply to all dma-buf exporters if so, and I don't see any > similar flush_kernel_vmap_range calls there (both functions are > seemingly only used by xfs, md and bio). > > We do have the dma_heap_dma_buf_begin_cpu_access()/dma_heap_dma_buf_end_cpu_access() > hooks (see more on these below) which sync the buffers for each > attachment (via dma_sync_sg_for_cpu/device), and are used around cpu > access to the buffers. Are you suggesting the > flush_kernel_vmap_range() call be added to those hooks or is the > dma_sync_sg_for_* calls sufficient there? dma_sync_sg_for_* only operates on the kernel direct mapping, that is what you get from page_address/kmap* for the page. But with vmap your create another alias in kernel virtual space, which dma_sync_sg_for_* can't know about. Now for most CPUs caches are indexed by physical addresses so this doesn't matter, but a significant minority of CPUs (parisc, some arm, some mips) index by virtual address, in which case we need non-empy flush_kernel_vmap_range and invalidate_kernel_vmap_range helper to deal with that vmap alias.