Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1414279imu; Wed, 16 Jan 2019 19:22:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN5GisEK08MzH4b9uve1EjqIF64Z3m1tlXgP0NV7VgCWqVUZ2sdA3AuHLpztHT26WxaLzVW9 X-Received: by 2002:a17:902:d697:: with SMTP id v23mr13134099ply.261.1547695358459; Wed, 16 Jan 2019 19:22:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547695358; cv=none; d=google.com; s=arc-20160816; b=ytRwblLuy6XkoOVJc+HOhAa421mr1s5D1C9VTFSu6mSKO2p6iq48howR5MxJGEhx23 6V2DoTH0Swqxck9dOOYRu3zfapFUausv/uO/3/VHKY6MA19HC8nAsenZAoTJgkM1F9B7 IxQvtIE2diJ1Bqd4zKor9VXL2BHchG6Zyo5yD6p7IamuVN3L3u8+psD7WY4YYtHsegvs W8O4PmwjY6siu+MKQiJqmj8z9FLIrIqI+hb9lChYbfy3oAMARY/Ree9L8eVJLcPlmdQC TACjB+VwrmsF39GZvUDJPKdp6hKuFCgDItV+YYP5H1ePOCIyxu0p7Tx57BeUhu+QRskF hTBQ== 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:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=Xm7lOdagTUXWoApQjAoLmUIdhJ9/+q+p1K8q4ZJihQ8=; b=xW0DSRK6CCznbBy6cA3cul2EbCkr9A4bMuwzW3tc9y7OAi4JG5+W+9n5LmRyT9laE+ i6ooLoM0MRpuMWtlWBceLzT8bWWP7adrjkmblt4WrlzZjRTo71dtEGx8TwDgD2dC+Pio pMJDZFEkQyyhaXrSWRcI4gr9KmnbuZ5S0gita1B5ztkbOlLqaSliabt4uKX1l4zWD61o bmI0AueKB6cMjAOE/aFr+jAzLnPUWs6WAZI7RYOxmLWAxpIIsoRh3kfeKmGlZTkwkySn 149SeMmYQemWIeWLdTa97c/rcKvaRlmfeEY8TiHhf1QhQCbyIK8D8ZkwYw02lsW2Ve6f ku8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=VxRliN+b; 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 37si356233pgw.590.2019.01.16.19.22.19; Wed, 16 Jan 2019 19:22:38 -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; dkim=fail header.i=@ffwll.ch header.s=google header.b=VxRliN+b; 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 S2389415AbfAPKOq (ORCPT + 99 others); Wed, 16 Jan 2019 05:14:46 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:38799 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731943AbfAPKOq (ORCPT ); Wed, 16 Jan 2019 05:14:46 -0500 Received: by mail-ed1-f65.google.com with SMTP id h50so4960049ede.5 for ; Wed, 16 Jan 2019 02:14:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:cc:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=Xm7lOdagTUXWoApQjAoLmUIdhJ9/+q+p1K8q4ZJihQ8=; b=VxRliN+b9E3BT9RqERr2ukFR4ZI4YtP/vqqB84wtUBbRdAYQuFBrf+e9UVWZt/Q+o4 0N0uG+K69dmgWuDpw3zDcN+K+1cjVMbSyplP0GTurO3HATg9MBoHOus8zTE/zqPvvjah +1zmiujDtCOtM01TqtJbkw3+CJiAZxjf6UkQU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=Xm7lOdagTUXWoApQjAoLmUIdhJ9/+q+p1K8q4ZJihQ8=; b=MfrQoeUw3waJvI9soOGbDLui8gSgEKQLnq4nsMOnzCmVkdqrNPOcgO1eW1c0K0gwf0 zOp3YnnGVfw+jGoVL0K+QVy2rRgm7QjeyKjhOH1TIo5Ydd91GXTpRvEiazdx3ym9AF8l QGWgJ+q1hWwUiEuX0BaQHMfUvYugJkL5zTsqT3tK1yhbeUAmP57huqAFtAgxbllD6+QG 927k7TwZN5xsbzq5GgakoxnXXsEfucFroq162eV0UcbJ8n1g+7pSxB6xqIsXmeXeDfvA LzL5Nohsy2cLuD/xAni3SjoCnBimDsRHDtO/I6W4lulle2Q5CwwwjT6HfCvjn3XPFbLA X6WQ== X-Gm-Message-State: AJcUukf4+5Oo93W69FZpHr9Rrtxb5GLgN61pYHR1ci1yu3hJVCAegRY2 reOF9X2vI+y0vmLl6cfvDFu6tA== X-Received: by 2002:a17:906:3712:: with SMTP id d18-v6mr6445225ejc.126.1547633683976; Wed, 16 Jan 2019 02:14:43 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id v11sm5356616edy.49.2019.01.16.02.14.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 02:14:42 -0800 (PST) Date: Wed, 16 Jan 2019 11:14:40 +0100 From: Daniel Vetter To: "Koenig, Christian" Cc: Thomas Hellstrom , "hch@lst.de" , "linux-kernel@vger.kernel.org" , "yong.zhi@intel.com" , "daniel.vetter@ffwll.ch" , "linux-rdma@vger.kernel.org" , "linux-media@vger.kernel.org" , "bingbu.cao@intel.com" , "jian.xu.zheng@intel.com" , "tian.shu.qiu@intel.com" , "shiraz.saleem@intel.com" , "sakari.ailus@linux.intel.com" , "dri-devel@lists.freedesktop.org" , "jgg@ziepe.ca" Subject: Re: [PATCH] lib/scatterlist: Provide a DMA page iterator Message-ID: <20190116101440.GR10517@phenom.ffwll.local> Mail-Followup-To: "Koenig, Christian" , Thomas Hellstrom , "hch@lst.de" , "linux-kernel@vger.kernel.org" , "yong.zhi@intel.com" , "linux-rdma@vger.kernel.org" , "linux-media@vger.kernel.org" , "bingbu.cao@intel.com" , "jian.xu.zheng@intel.com" , "tian.shu.qiu@intel.com" , "shiraz.saleem@intel.com" , "sakari.ailus@linux.intel.com" , "dri-devel@lists.freedesktop.org" , "jgg@ziepe.ca" References: <20190114094856.GB29604@lst.de> <1fb20ab4b171b281e9994b6c55734c120958530b.camel@vmware.com> <2b440a3b-ed2f-8fd6-a21e-97ca0b2f5db9@gmail.com> <20190115152029.GB2325@lst.de> <41d0616e95fb48942404fb54d82249f5700affb1.camel@vmware.com> <20190115183133.GA12350@lst.de> <20190115205801.GA15432@lst.de> <01e5522bf88549bfdaea1430fece23cb3d1a1a55.camel@vmware.com> <8aadac80-da9b-b52a-a4bf-066406127117@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8aadac80-da9b-b52a-a4bf-066406127117@amd.com> X-Operating-System: Linux phenom 4.19.0-1-amd64 User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 07:28:13AM +0000, Koenig, Christian wrote: > Am 16.01.19 um 08:09 schrieb Thomas Hellstrom: > > On Tue, 2019-01-15 at 21:58 +0100, hch@lst.de wrote: > >> On Tue, Jan 15, 2019 at 07:13:11PM +0000, Koenig, Christian wrote: > >>> Thomas is correct that the interface you propose here doesn't work > >>> at > >>> all for GPUs. > >>> > >>> The kernel driver is not informed of flush/sync, but rather just > >>> setups > >>> coherent mappings between system memory and devices. > >>> > >>> In other words you have an array of struct pages and need to map > >>> that to > >>> a specific device and so create dma_addresses for the mappings. > >> If you want a coherent mapping you need to use dma_alloc_coherent > >> and dma_mmap_coherent and you are done, that is not the problem. > >> That actually is one of the vmgfx modes, so I don't understand what > >> problem we are trying to solve if you don't actually want a non- > >> coherent mapping. > > For vmwgfx, not making dma_alloc_coherent default has a couple of > > reasons: > > 1) Memory is associated with a struct device. It has not been clear > > that it is exportable to other devices. > > 2) There seems to be restrictions in the system pages allowable. GPUs > > generally prefer highmem pages but dma_alloc_coherent returns a virtual > > address implying GFP_KERNEL? While not used by vmwgfx, TTM typically > > prefers HIGHMEM pages to facilitate caching mode switching without > > having to touch the kernel map. > > 3) Historically we had APIs to allow coherent access to user-space > > defined pages. That has gone away not but the infrastructure was built > > around it. > > > > dma_mmap_coherent isn't use because as the data moves between system > > memory, swap and VRAM, PTEs of user-space mappings are adjusted > > accordingly, meaning user-space doesn't have to unmap when an operation > > is initiated that might mean the data is moved. > > To summarize once more: We have an array of struct pages and want to > coherently map that to a device. > > If that is not possible because of whatever reason we want to get an > error code or even not load the driver from the beginning. I guess to make this work we'd also need information about how we're allowed to mmap this on the cpu side, both from the kernel (kmap or vmap) and for userspace. At least for i915 we use all kinds of combinations, e.g. cpu mmap ptes as cached w/ coherent device transactions, or cached+clflush on the cpu side, and non-coherent device transactions (the no-snoop thing), or wc mode in the cpu ptes and non-coherent device transactions- Plus some debug mode so we catch abuse, because reality is that most of the gpu driver work happens on x86, where all of this just works. Even if you do some really serious layering violations (which is why this isn't that high a priority for gpu folks). -Daniel > > > > > > >> Although last time I had that discussion with Daniel Vetter > >> I was under the impressions that GPUs really wanted non-coherent > >> mappings. > > Intel historically has done things a bit differently. And it's also > > possible that embedded platforms and ARM prefer this mode of operation, > > but I haven't caught up on that discussion. > > > >> But if you want a coherent mapping you can't go to a struct page, > >> because on many systems you can't just map arbitrary memory as > >> uncachable. It might either come from very special limited pools, > >> or might need other magic applied to it so that it is not visible > >> in the normal direct mapping, or at least not access through it. > > > > The TTM subsystem has been relied on to provide coherent memory with > > the option to switch caching mode of pages. But only on selected and > > well tested platforms. On other platforms we simply do not load, and > > that's fine for now. > > > > But as mentioned multiple times, to make GPU drivers more compliant, > > we'd really want that > > > > bool dma_streaming_is_coherent(const struct device *) > > > > API to help us decide when to load or not. > > Yes, please. > > Christian. > > > > > Thanks, > > Thomas > > > > > > > > > > > > > > > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch