Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1479524pxu; Fri, 16 Oct 2020 13:05:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo7t8BoL0CVayLSKF+u2so0UhSVsG90n/xrJbJAvq4hdhyXM51UoLfXDVSxJytpVs/0++h X-Received: by 2002:a17:906:3cc:: with SMTP id c12mr5064086eja.210.1602878744310; Fri, 16 Oct 2020 13:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602878744; cv=none; d=google.com; s=arc-20160816; b=KzSBe9rKnkhcrSHOLqL9FA2CZT1IeMQ2XdH4YqDOb2rnTAfnu2mnPzfyneteltvBF3 Pnb3f1yciDPESb3vZM0r66K77fcwelQAViRuEe6gwoVVaJaTAoSemVFiEW1NwBgJ+x2o AWNGosv0jaqW1DdV/rZ7wY1nJqOuRt6YHrqJ0IyWRxUTRhCDnsSM9s6w1jBp3qt8v0UZ jItGMIXbFhH9qkzZWZFCjqNIRDtQtRHiNWq86GczqFLGuRaf4DDtz9T9jNB7cSThRyB5 SqMXxSnBYizFPtn9lJYyAzUHWjQDFr3Bv2XsN0pV+rlr8R6/g8s78C+W/KiiPmuUmICR 3TcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=IDGiTqL122cqbXZ5gmkVRBP3kDwxXwWxYEu+99pwLt8=; b=Wd9vGw91z/r/apIEoQVl8pjdk7wFC/c9qKuEEIFRMFK2THbsChNRGp8Mvs+GQLSjIQ QRKsbLKyfPTB1eElCksmzitY6a3zIEzl/U0wK+a/0Yr5mh3NPUiTelVkIX1CdsRWWXH0 ZsbyksgBgRnytigT543UZY23FD0H7wNGJSVaVv+rHGMQMNaw9az7xGQboRBeaNhlYYpX xNVbkom0fi7KabVi9yiK88lUccYSUS4UQxFIpWBWU1RHVeleO4v5JrvAlzQ9DFY+Hzhf bj91eyYkrxkJmNeJp4RGGefFa+AWCtJIwGmIn9NFLmoo8klrdJGKgcu85YN2pe1OeBHi kjDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vu3mPMHF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id l13si2456571eja.131.2020.10.16.13.05.21; Fri, 16 Oct 2020 13:05:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vu3mPMHF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2409796AbgJPTEH (ORCPT + 99 others); Fri, 16 Oct 2020 15:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407907AbgJPTEG (ORCPT ); Fri, 16 Oct 2020 15:04:06 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54D61C061755 for ; Fri, 16 Oct 2020 12:04:05 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id m128so3583413oig.7 for ; Fri, 16 Oct 2020 12:04:05 -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=IDGiTqL122cqbXZ5gmkVRBP3kDwxXwWxYEu+99pwLt8=; b=Vu3mPMHF4DBQL4kRlIWhIl9ji8RQex+xp7zFTvbtx9Zh3wWBCGFoYeL/7r0Hwx7EEm ek/hS1ud5mnmbehUUkObdzbIdX1ck0whwPXMxyA+pc4U2Po7VQFjq76x7YeoaqZ4xAFJ mwF4zceOwX+zbQMCOYexMBUOltu9uBPnMBcKiz318natkpmKGrWTqxNZ5Kkiu5RJurMu G/iH5A/kDsU0spCOTx5TFbopILA7+8QBYCiLHYfxxrGaW08UxWy4D6M49AWqht3kleGc lWN6yRRg3N3kw1bDIyIRC8GWZYDYuXhfaMzjmSt5arM4Ogx55jg+MJ5wQfQvit3Fy1Q6 4vbA== 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=IDGiTqL122cqbXZ5gmkVRBP3kDwxXwWxYEu+99pwLt8=; b=muPaRCx/63www7WlH0dmAwMAfJGVQvQZQOcEKLC7ZtOv95ebASXos2WtszVSfpOVXa VwCSxZNjZFRBXrj36mZvjDSU22sxZszEAwh5EdL3GvQjjB/wioM9R6PKegm1OnchGhfo 7CLPIHc+soN8MoBdGiLhGFFb+TYSiBunH8SwM+HcML2g5GYt0vCCfARJFfh4IYxrCgXA ie95vfO7cvOM2pRyHJwqJg+NaYwV9bRWFenEwhJGvAjfC87O2EbxV9vABJEehTgTNFiq GnoLOZTKARc2e7BCFfW/oOO5RiGnOus+1mKJz1MnSeJV+XtigfuCk8uUZN2rXV2MPF2S HoVg== X-Gm-Message-State: AOAM5333kBGJT7/bSIubu09e/SX32HLi4VVkDtpFxkjQNpp6wnibms3r a/eV0lT/dbADC4OGjI8TQZoFrbR+Wf8bU2QN+XbnGw== X-Received: by 2002:aca:3341:: with SMTP id z62mr3245667oiz.169.1602875044682; Fri, 16 Oct 2020 12:04:04 -0700 (PDT) MIME-Version: 1.0 References: <20201003040257.62768-1-john.stultz@linaro.org> <20201003040257.62768-8-john.stultz@linaro.org> <20201008115101.4qi6wh3hhkb6krg5@DESKTOP-E1NTVVP.localdomain> In-Reply-To: <20201008115101.4qi6wh3hhkb6krg5@DESKTOP-E1NTVVP.localdomain> From: John Stultz Date: Fri, 16 Oct 2020 12:03:52 -0700 Message-ID: Subject: Re: [PATCH v3 7/7] dma-buf: system_heap: Add a system-uncached heap re-using the system heap To: Brian Starkey Cc: lkml , Sumit Semwal , Liam Mark , Laura Abbott , Hridya Valsaraju , Suren Baghdasaryan , Sandeep Patil , Daniel Mentz , Chris Goldsworthy , =?UTF-8?Q?=C3=98rjan_Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media , dri-devel , nd Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 8, 2020 at 4:51 AM Brian Starkey wrote: > On Sat, Oct 03, 2020 at 04:02:57AM +0000, John Stultz wrote: > > @@ -215,8 +236,12 @@ static void *system_heap_do_vmap(struct system_heap_buffer *buffer) > > struct page **pages = vmalloc(sizeof(struct page *) * npages); > > struct page **tmp = pages; > > struct sg_page_iter piter; > > + pgprot_t pgprot = PAGE_KERNEL; > > void *vaddr; > > > > + if (buffer->uncached) > > + pgprot = pgprot_writecombine(PAGE_KERNEL); > > I think this should go after the 'if (!pages)' check. Best to get the > allocation failure check as close to the allocation as possible IMO. Sounds good. Changed in my tree. > > @@ -393,6 +424,16 @@ static int system_heap_allocate(struct dma_heap *heap, > > /* just return, as put will call release and that will free */ > > return ret; > > } > > + > > + /* > > + * For uncached buffers, we need to initially flush cpu cache, since > > + * the __GFP_ZERO on the allocation means the zeroing was done by the > > + * cpu and thus it is likely cached. Map (and implicitly flush) it out > > + * now so we don't get corruption later on. > > + */ > > + if (buffer->uncached) > > + dma_map_sgtable(dma_heap_get_dev(heap), table, DMA_BIDIRECTIONAL, 0); > > Do we have to keep this mapping around for the entire lifetime of the > buffer? Yea, I guess we can just map and unmap it right there. It will look a little absurd, but that sort of aligns with your next point. > Also, this problem (and solution) keeps lingering around. It really > feels like there should be a better way to solve "clean the linear > mapping all the way to DRAM", but I don't know what that should be. Yea, something better here would be nice... > > @@ -426,6 +487,16 @@ static int system_heap_create(void) > > if (IS_ERR(sys_heap)) > > return PTR_ERR(sys_heap); > > > > + exp_info.name = "system-uncached"; > > + exp_info.ops = &system_uncached_heap_ops; > > + exp_info.priv = NULL; > > + > > + sys_uncached_heap = dma_heap_add(&exp_info); > > + if (IS_ERR(sys_uncached_heap)) > > + return PTR_ERR(sys_heap); > > + > > In principle, there's a race here between the heap getting registered > to sysfs and the dma_mask getting updated. > > I don't think it would cause a problem in practice, but with the API > as it is, there's no way to avoid it - so I wonder if the > dma_heap_get_dev() accessor isn't the right API design. Hrm. I guess to address your concern we would need split dma_heap_add() into something like: dma_heap_create() dma_heap_add() Which breaks the creation of the heap with the registering it to the subsystem, so some attributes can be tweaked inbetween? I'll see about taking a stab at this, but I'll probably submit my updated series sooner with this un-addressed so I can get some further review. thanks -john