Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp75070ybl; Thu, 15 Aug 2019 12:59:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqygBXrL+fmwXb7NqNkjrzyHdVfPJTExX96Ho/3pCFl4Qeb6xfIYu8szhbLL2N4rXniEB3sM X-Received: by 2002:a17:902:46a:: with SMTP id 97mr5967087ple.322.1565899163874; Thu, 15 Aug 2019 12:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565899163; cv=none; d=google.com; s=arc-20160816; b=FZBIvD5f2UT+1LxMYvMruoEyUve9g54k9TFk2FQfE+ypB18zIQfWrC78/27389DBjP 8d5knleM3gnl9yHsPmhIVoHBKQ3YBw6taCF7gkEr+VyQeeR+vWtCZLfBtBuaNg4t+PPN DfXs9xUuR0Ur7gNNiS0Q+umDZ/9mJPZVXSbj4Et0Fp+5Xf33LbBoLj3gL2IkXDsalKfJ w1RsXqm5FgCG5uaRWvd2wpHx8hzlnUQBMHHSzYTUKtRpkrhYIaLai6uMCTtC1QkZEiDx ioYNuupyMX9KyY0Sp1D4dWMAAQeN8qWYM+0d1pqDkluhIGa0u9tcaQFN+rP/sHeggLur gg9g== 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=BnI8+uYTBZJKnMRavU1hA2TnI4rNr0e2aXC8LBXC9rk=; b=BOmen6zVFjaCpD7bRDWjAEizf90silhhcF7OrfzgMB7hcPJUZj0+zaXhOvqvvn0pU2 E0MfvjujX6PovrP0yixQMt90L+j7O7YbMMICHyG5vM/j44wsE42G/TqptTVUN8+pgqwi ZMn/P/UFvB6HPzAJv03ZaOr/7UBk8L8/qgK9cVbBJY4x99U+/RYiGydTYazcW9rm57Dz w7XSEZZjXxl9c+fA8+3eqk2wIFiOUlvp9Oy253+hyqkm/yj3j4R+CK28xc91cSLVanxf wp48gTh0ze1kD7jzsD0QdWJaKn1m00/+WXs/Gz7uUec9XsyD3q1HMiANW28jmxhV6jE8 WLiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=BGaLtEn0; 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 124si2380277pgd.142.2019.08.15.12.59.07; Thu, 15 Aug 2019 12:59:23 -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=@ziepe.ca header.s=google header.b=BGaLtEn0; 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 S1731707AbfHOSCC (ORCPT + 99 others); Thu, 15 Aug 2019 14:02:02 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:45116 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731524AbfHOSCC (ORCPT ); Thu, 15 Aug 2019 14:02:02 -0400 Received: by mail-qk1-f196.google.com with SMTP id m2so2499947qki.12 for ; Thu, 15 Aug 2019 11:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=BnI8+uYTBZJKnMRavU1hA2TnI4rNr0e2aXC8LBXC9rk=; b=BGaLtEn0xYdBTNlc96MSvc0pra1wpogvEbh9GdU2lucZLzHp357V0Gu4O4fnG6AOf2 BybrSFZaeZEzYMjh/IoUujmDgJd5IpCUR3tMstVXWjLAycVo9JtMa+b7MtCAS3YLD4Pd dgFmBtsLGh7Dhx4A4xWk9JocKdxSNpTPeGr8QLfny4yWKeB/twiqSr+/O8137DgtxKMx Jl9VLmWm8wQswZBqORI5f4rKt93iNPd/i6wk0e2H0oUug4hUvei5Afb61IF1snBw6wXa nsMBUVu57cjgGfgQB8mcQJtzDfAZ+xarKGUIbjN5S3r8JHADl8l+z4uWQ7PDRLewWs2y zxrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=BnI8+uYTBZJKnMRavU1hA2TnI4rNr0e2aXC8LBXC9rk=; b=TGJDBU4QdbN7oQPFvRjlL9oC9VKSAAi4+ILbr7LD/SXd9XpZYx0lz2Yn1m+jEj8Iz2 A3mYf6zVhq8CTmS8MSxqEF83WJVkv0/7PbZSnsz+qJVaALbCujR+OmdRiZ9faoxrJoZv jLvBYE1UvwRUUVXmRUqAGocV9IwnJgB/ICLQLOR4pILjCJT+fNMUV5a9zk3sBaSJkHYA svlagp3v/JmC99rcteE82KGqLIY2SxQyUDdoDBGg5vGxIaBei8ts6PfEZ2IdWLM919ko FdjSBC/yaunRNrrvYtRiwDgudpAmZffQl3uB5Y5k0LQQp0Kk/cuDRCiEyvfXvLQ9b25g sisQ== X-Gm-Message-State: APjAAAWNS9+de6Du5EM/G0x/uRl29RjLl7wcUUxQ9WHOYmy5SgIAqg95 1hJxxkNs9JKHB/Y/1x8G6BNsJQ== X-Received: by 2002:a37:311:: with SMTP id 17mr4904431qkd.466.1565892120753; Thu, 15 Aug 2019 11:02:00 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-55-100.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.55.100]) by smtp.gmail.com with ESMTPSA id p126sm2042871qkc.84.2019.08.15.11.02.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Aug 2019 11:02:00 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1hyK4V-0007BP-Uc; Thu, 15 Aug 2019 15:01:59 -0300 Date: Thu, 15 Aug 2019 15:01:59 -0300 From: Jason Gunthorpe To: Jerome Glisse Cc: Daniel Vetter , Michal Hocko , Andrew Morton , LKML , Linux MM , DRI Development , Intel Graphics Development , Peter Zijlstra , Ingo Molnar , David Rientjes , Christian =?utf-8?B?S8O2bmln?= , Masahiro Yamada , Wei Wang , Andy Shevchenko , Thomas Gleixner , Jann Horn , Feng Tang , Kees Cook , Randy Dunlap , Daniel Vetter Subject: Re: [PATCH 2/5] kernel.h: Add non_block_start/end() Message-ID: <20190815180159.GO21596@ziepe.ca> References: <20190814134558.fe659b1a9a169c0150c3e57c@linux-foundation.org> <20190815084429.GE9477@dhcp22.suse.cz> <20190815130415.GD21596@ziepe.ca> <20190815143759.GG21596@ziepe.ca> <20190815151028.GJ21596@ziepe.ca> <20190815173557.GN21596@ziepe.ca> <20190815173922.GH30916@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190815173922.GH30916@redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 15, 2019 at 01:39:22PM -0400, Jerome Glisse wrote: > On Thu, Aug 15, 2019 at 02:35:57PM -0300, Jason Gunthorpe wrote: > > On Thu, Aug 15, 2019 at 06:25:16PM +0200, Daniel Vetter wrote: > > > > > I'm not really well versed in the details of our userptr, but both > > > amdgpu and i915 wait for the gpu to complete from > > > invalidate_range_start. Jerome has at least looked a lot at the amdgpu > > > one, so maybe he can explain what exactly it is we're doing ... > > > > amdgpu is (wrongly) using hmm for something, I can't really tell what > > it is trying to do. The calls to dma_fence under the > > invalidate_range_start do not give me a good feeling. > > > > However, i915 shows all the signs of trying to follow the registration > > cache model, it even has a nice comment in > > i915_gem_userptr_get_pages() explaining that the races it has don't > > matter because it is a user space bug to change the VA mapping in the > > first place. That just screams registration cache to me. > > > > So it is fine to run HW that way, but if you do, there is no reason to > > fence inside the invalidate_range end. Just orphan the DMA buffer and > > clean it up & release the page pins when all DMA buffer refs go to > > zero. The next access to that VA should get a new DMA buffer with the > > right mapping. > > > > In other words the invalidation should be very simple without > > complicated locking, or wait_event's. Look at hfi1 for example. > > This would break the today usage model of uptr and it will > break userspace expectation ie if GPU is writting to that > memory and that memory then the userspace want to make sure > that it will see what the GPU write. How exactly? This is holding the page pin, so the only way the VA mapping can be changed is via explicit user action. ie: gpu_write_something(va, size) mmap(.., va, size, MMAP_FIXED); gpu_wait_done() This is racy and indeterminate with both models. Based on the comment in i915 it appears to be going on the model that changes to the mmap by userspace when the GPU is working on it is a programming bug. This is reasonable, lots of systems use this kind of consistency model. Since the driver seems to rely on a dma_fence to block DMA access, it looks to me like the kernel has full visibility to the 'gpu_write_something()' and 'gpu_wait_done()' markers. I think trying to use hmm_range_fault on HW that can't do HW page faulting and HW 'TLB shootdown' is a very, very bad idea. I fear that is what amd gpu is trying to do. I haven't yet seen anything that looks like 'TLB shootdown' in i915?? Jason