Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8085508ybi; Tue, 23 Jul 2019 02:36:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmCk7qKJ8auuZ8Vp8yBsdZkSHZiyNJ2uRnMtvxudCROzXIz7WsXbun7K6aTJhjUfJbhqL/ X-Received: by 2002:a63:9e43:: with SMTP id r3mr51069283pgo.148.1563874569178; Tue, 23 Jul 2019 02:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563874569; cv=none; d=google.com; s=arc-20160816; b=b6Dzk4b5Ab13+KkRiWdYY2cYOrIHAMmGAr1rAB1CVSOrCbRrnmytPFHrFQ6rr4ALry 2yuNUO/uoikLIvAHABz/3jiI8/Mbi1MPMT2GOC0Lusx/5BLzpY20xtwZQc0++9FDvSDx ZMcZ3F5im5mU0E6DS1q15Tz5du00pJ/8H+B7Pju7XK/TZQfePSFZ96WBnjdw7RuDO08K L5MEgdHYKfHaF7jiGrFJYYbg8LC5lIvP3ebBz07en7cnFHnhSpsxM/fFuQQ2M4nBb2DF fER2QlIm5XXFaWHzt3ESkJSwLFtv2BWQrHW7xqhf8KliIynNkbrY60LjA4g19Vk/GTiz MqdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+AEy0A1U3bDIt426sx3FptCy+IyQIvQzzikjslkeuhc=; b=Z+EU5ER1ic+lqvq6yLUIPsy2JZdubRsGqj7TgOTV0fDSHx8YBHHJ1qi0/GOk9P39KE OENmRu43ja8vwxFhjk1laNthvBTSU0vbdLmpfk36oV2Z7g/Yu4rlWltR06XPp8jqj3AX niMe11ozNigz9QzeveKoP76WL0+3LjmtenPHoOBK/IqONiJ9ErZEEZ5wi6HOXDfEXaFy f9UmG+3PwW5Esbaob10M/8/SODmr9O3gmU89pMkaSkC0Aqp2PrzglR6uFBJJCf9OW9mK 7PDuciAkPt+rLbrLsXejJfWNwg2GWsvbdOiljOax2H/a4mPx0ZUnyl1G5AzFKUlCUcAS JxJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E311kO1p; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22si10434139plr.120.2019.07.23.02.35.53; Tue, 23 Jul 2019 02:36:09 -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=pass header.i=@linaro.org header.s=google header.b=E311kO1p; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbfGWEJl (ORCPT + 99 others); Tue, 23 Jul 2019 00:09:41 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38962 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725865AbfGWEJk (ORCPT ); Tue, 23 Jul 2019 00:09:40 -0400 Received: by mail-wm1-f65.google.com with SMTP id u25so26778883wmc.4 for ; Mon, 22 Jul 2019 21:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+AEy0A1U3bDIt426sx3FptCy+IyQIvQzzikjslkeuhc=; b=E311kO1pCEwMLgLW8p32jUkqQOjQ9ZoxegskYz6+JpTLlAudw1HLUYbCumdlFFhvlN kknZAMeF/KHxiSf9QsA6fQbR+l+hHeS1KJrxuFayMjWeUjRw/vRMm1JeHS+yFatZIVtD iBjLtMlVQU2dN2EOMpK58+tFiAC2ZYilQAZ70uh+1pz3Ryqb91hawquXEbV//jqi+a8v PetHF5ohrQ4BFuL1d4cQtT3tqa0gkhsy6nSts16PwfrMnLXOBgp+f87TyuCUbmR9CLsB 8vUkxyOvq5Wjxf8LYsqRq78Lbadeg2mgJu1/x+x87LVeyafSxluHqsAfIBCFQm3FL0P0 uyKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+AEy0A1U3bDIt426sx3FptCy+IyQIvQzzikjslkeuhc=; b=TgDftPAFT25MQQHcjN0C34phwnbbgrSO/8yrhFyOAQa479sgCAzroQCpX1jt4Mslce WtJxyPEW4LHQ9QxpjHR3tH+YBPaR5rJFT12IpYjCP4t2vnn72dl/1/8/qNtYhudvwCd8 9h+7kkC02rYDyQOhYHHoHLdE8jRL2yZ7UO0SVBqQ0ZHPWK1CVPUGMQ9byNCodPB61Qa0 dLi003yUr09x6gpIl/w42EC3ODdIr1qo/bcr6iingimwFMQABxi4pMK/gBlA50eHUx32 pixA9vRj/8kE3XbNkZUF2GNyndWDv5c/9yjyarQUOGqob4XvVrO96WEcrPr4RSmb/RNG u2Dg== X-Gm-Message-State: APjAAAUrqo0d6qA8f5bOPmaAjLMWXRFty7CnemUf5QVX37+fkA0/Ji8/ kVNKRgpRJtDbsPR3KMSDPstH1p1PAqfj8WhxktCOng== X-Received: by 2002:a1c:dc07:: with SMTP id t7mr69039790wmg.164.1563854978031; Mon, 22 Jul 2019 21:09:38 -0700 (PDT) MIME-Version: 1.0 References: <20190624194908.121273-1-john.stultz@linaro.org> <20190624194908.121273-3-john.stultz@linaro.org> <20190718100654.GA19666@infradead.org> In-Reply-To: <20190718100654.GA19666@infradead.org> From: John Stultz Date: Mon, 22 Jul 2019 21:09:25 -0700 Message-ID: Subject: Re: [PATCH v6 2/5] dma-buf: heaps: Add heap helpers To: Christoph Hellwig Cc: 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > > +static vm_fault_t dma_heap_vm_fault(struct vm_fault *vmf) > > +{ > > + struct vm_area_struct *vma = vmf->vma; > > + struct heap_helper_buffer *buffer = vma->vm_private_data; > > + > > + vmf->page = buffer->pages[vmf->pgoff]; > > + get_page(vmf->page); > > + > > + return 0; > > +} > > Is there any exlusion between mmap / vmap and the device accessing > the data? Without that you are going to run into a lot of coherency > problems. This has actually been a concern of mine recently, but at the higher dma-buf core level. Conceptually, there is the dma_buf_map_attachment() and dma_buf_unmap_attachment() calls drivers use to map the buffer to an attached device, and there are the dma_buf_begin_cpu_access() and dma_buf_end_cpu_access() calls which are to be done when touching the cpu mapped pages. These look like serializing functions, but actually don't seem to have any enforcement mechanism to exclude parallel access. To me it seems like adding the exclusion between those operations should be done at the dmabuf core level, and would actually be helpful for optimizing some of the cache maintenance rules w/ dmabuf. Does this sound like something closer to what your suggesting, or am I misunderstanding your point? Again, I really appreciate the review and feedback! Thanks so much! -john