Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp251902ybz; Wed, 15 Apr 2020 08:07:22 -0700 (PDT) X-Google-Smtp-Source: APiQypKlUXebhz7fHwwAPSLVPXPO2HMuGLd8o42sQ/M5b5HNI7y8PPeN3fSpi6gPZtPglQa2Me1Z X-Received: by 2002:a50:8e4b:: with SMTP id 11mr10816143edx.329.1586963242210; Wed, 15 Apr 2020 08:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586963242; cv=none; d=google.com; s=arc-20160816; b=QPJPD/nLmB9fc9oCM98phAnyYYsHUlEdsczgciyosama0oZwmwomkdpny/HqXjuC1W ZyVGfdPn40UaEi6nwDzJDLPRoc/BDms6Ip9UxBgO6YruUeBUaagEUoInttYjna6iS2BN XogCgDyoU50NrSYM0lGdMRS0Mdvb1ccgBOlxsWERFtZs5lWTIATJlsLsQ551qvbAZoxN w1mli4RZtbpvN84kcfkSXVXm6a766BfibFhkiUadJEqmzUQX0LHo9A14PmPI5c9fqBMm AuLbQsxBB9zAmSwNHrihVTnhM5ovqF25INIQ5jBq3i5nB2jEKgdhr2XJzQF1mpsJJGFh 5r4A== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=yuNggtIe2GcnI6FuGYRCP7sxE6PadkqmBj6CF6tR/Gs=; b=w64dsMDP9N/Ha6Q1Nq1BYDDHTm2kj4cjDNrOkdV9SpA2bkz7DJnt8XsXNJVWiVbfhe WadkP79u34g0aKnWQ9PT8da3RqHoAMMlalGQTZSZ/iXNKOxAZXu1+2OX4bQBH2Zqdo3g oPsqF4xBRv/uk5z6aCsjE7z/ScqXFMSULdhTGGUePsqYxIhA2RUub7cNkQV3s2DcaSBv WHzPrM29OFdi5sXfRFJLMhMJj5Zfbf+H4k8L972qZm+hiY32qHxlDtklvmcGDf+RTwt+ Ai5pyXIsAg5wMr3xU4TRJ1DokuMSqMD5mVpjcDpl8l8elVV70Ohm/7IxHQtveMQcNmOC gdkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OTB3RfMy; spf=pass (google.com: best guess record for 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 bs10si651392edb.429.2020.04.15.08.06.42; Wed, 15 Apr 2020 08:07:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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=OTB3RfMy; spf=pass (google.com: best guess record for 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 S2388223AbgDOElr (ORCPT + 99 others); Wed, 15 Apr 2020 00:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388490AbgDOElp (ORCPT ); Wed, 15 Apr 2020 00:41:45 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3EF2C061A0E for ; Tue, 14 Apr 2020 21:41:43 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id l21so2126934otd.9 for ; Tue, 14 Apr 2020 21:41:43 -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:content-transfer-encoding; bh=yuNggtIe2GcnI6FuGYRCP7sxE6PadkqmBj6CF6tR/Gs=; b=OTB3RfMyrdVJ7ygI0eAB6m89DfyK7Br1DSBVEoq2OJ7g7XFVWBZQPhOzgDy4S2LXTG AJMMYR4R29njK35OPsxHnQWrI4xuOC6YfmkFBSL5Y+FgN3f+0KpEoFSNwgomtJqP6l+t 67AkaK6noIU47090e/BLlc5lXsENljKM6uNHv5jQ8a5ZPyksi5DuPEmiD3YDvILPQnSd FAtwGQFURFCCkodWA0D/g9A/wdDKxcAfw2dFzbvHNG6sP3CPa2rfBd08PS+4c+nmxokI DSYZFItuasCmP6x1Ah64Othz0RVdteA6jakPuTPC+ob5HEcxFBDDGgFT1q6KPNyyuJGY xFJg== 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:content-transfer-encoding; bh=yuNggtIe2GcnI6FuGYRCP7sxE6PadkqmBj6CF6tR/Gs=; b=fgSru8pc8W4QtndMXURu9LnJsumwiL18WnJrh7q6qbOzV5lUAbeaUKmowv3KBSlMIx SVJo7yuQ8zGVYk1GZBNSc1XJ7sKSDUJoikwv9gIPdm6/Pri0/U6FNyOU/HF87oFdEpZo ZAR4I1sENvy82lg0wmvw3ePQ+qzL7ya9WvFvXmXJYcoyeDxV8RuveFRLxaFY2QrK1ct7 fobUtgNnBEYmGkDvMyDnnaZoUFZTfmEOIuXKk4Tj+Fufv6fAnin1E1uUt2o6+mfW+6bw hTkGC+AfFyki+CbEdEZ2OxtDUY/f5EzqXkOtIzyQnRua8xIJWG/7i5MCd+PpSs7mDX4k ZX8Q== X-Gm-Message-State: AGi0PuaNTzH/L/5gamtf03eC+j/UeBw0/Iqe2lY/lcKxfnGpLnwy6gfD Sp+lZ4FJ5j01H2UAFmRHj6IpcJWcZbGKsM2DdqS2+A== X-Received: by 2002:a05:6830:20c3:: with SMTP id z3mr15050625otq.102.1586925703073; Tue, 14 Apr 2020 21:41:43 -0700 (PDT) MIME-Version: 1.0 References: <20200414134629.54567-1-orjan.eide@arm.com> <20200414141849.55654-1-orjan.eide@arm.com> <20200414142810.GA958163@kroah.com> In-Reply-To: <20200414142810.GA958163@kroah.com> From: John Stultz Date: Tue, 14 Apr 2020 21:41:31 -0700 Message-ID: Subject: Re: [PATCH] staging: android: ion: Skip sync if not mapped To: Greg Kroah-Hartman Cc: =?UTF-8?Q?=C3=98rjan_Eide?= , nd , Anders Pedersen , Laura Abbott , Sumit Semwal , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Daniel Vetter , "Darren Hart (VMware)" , Lecopzer Chen , Arnd Bergmann , driverdevel , dri-devel , "moderated list:DMA BUFFER SHARING FRAMEWORK" , lkml , linux-media@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 14, 2020 at 7:28 AM Greg Kroah-Hartman wrote: > > On Tue, Apr 14, 2020 at 04:18:47PM +0200, =C3=98rjan Eide wrote: > > Only sync the sg-list of an Ion dma-buf attachment when the attachment > > is actually mapped on the device. > > > > dma-bufs may be synced at any time. It can be reached from user space > > via DMA_BUF_IOCTL_SYNC, so there are no guarantees from callers on when > > syncs may be attempted, and dma_buf_end_cpu_access() and > > dma_buf_begin_cpu_access() may not be paired. > > > > Since the sg_list's dma_address isn't set up until the buffer is used > > on the device, and dma_map_sg() is called on it, the dma_address will b= e > > NULL if sync is attempted on the dma-buf before it's mapped on a device= . > > > > Before v5.0 (commit 55897af63091 ("dma-direct: merge swiotlb_dma_ops > > into the dma_direct code")) this was a problem as the dma-api (at least > > the swiotlb_dma_ops on arm64) would use the potentially invalid > > dma_address. How that failed depended on how the device handled physica= l > > address 0. If 0 was a valid address to physical ram, that page would ge= t > > flushed a lot, while the actual pages in the buffer would not get synce= d > > correctly. While if 0 is an invalid physical address it may cause a > > fault and trigger a crash. > > > > In v5.0 this was incidentally fixed by commit 55897af63091 ("dma-direct= : > > merge swiotlb_dma_ops into the dma_direct code"), as this moved the > > dma-api to use the page pointer in the sg_list, and (for Ion buffers at > > least) this will always be valid if the sg_list exists at all. > > > > But, this issue is re-introduced in v5.3 with > > commit 449fa54d6815 ("dma-direct: correct the physical addr in > > dma_direct_sync_sg_for_cpu/device") moves the dma-api back to the old > > behaviour and picks the dma_address that may be invalid. > > > > dma-buf core doesn't ensure that the buffer is mapped on the device, an= d > > thus have a valid sg_list, before calling the exporter's > > begin_cpu_access. > > > > Signed-off-by: =C3=98rjan Eide > > --- > > drivers/staging/android/ion/ion.c | 12 ++++++++++++ > > 1 file changed, 12 insertions(+) > > > > Resubmit without disclaimer, sorry about that. > > > > This seems to be part of a bigger issue where dma-buf exporters assume > > that their dma-buf begin_cpu_access and end_cpu_access callbacks have a > > certain guaranteed behavior, which isn't ensured by dma-buf core. > > > > This patch fixes this in ion only, but it also needs to be fixed for > > other exporters, either handled like this in each exporter, or in > > dma-buf core before calling into the exporters. > > > > diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/androi= d/ion/ion.c > > index 38b51eace4f9..7b752ba0cb6d 100644 > > --- a/drivers/staging/android/ion/ion.c > > +++ b/drivers/staging/android/ion/ion.c > > Now that we have the dma-buff stuff in the tree, do we even need the > ion code in the kernel anymore? Can't we delete it now? > I agree that we shouldn't be taking further (non-security/cleanup) patches to the ION code. I'd like to give developers a little bit of a transition period (I was thinking a year, but really just one LTS release that has both would do) where they can move their ION heaps over to dmabuf heaps and test both against the same tree. But I do think we can mark it as deprecated and let folks know that around the end of the year it will be deleted. That sound ok? thanks -john