Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp677000img; Thu, 21 Mar 2019 06:46:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqywoV8bHgddyADT0A8SNJtqiVDKY9poqK3qH9qH4xXiyauOm+FQlT2YR3vN+X8XMsGA3Eac X-Received: by 2002:a17:902:2903:: with SMTP id g3mr3626877plb.222.1553176018414; Thu, 21 Mar 2019 06:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553176018; cv=none; d=google.com; s=arc-20160816; b=QxJD4tbwUX84dhgpWkqfJriii+VunXYdHq5QA0IEap2+vGW6N7g2j1uHpeQfMt5KV6 jHumAIN9TV/RpI34gCtRSMWgnazgcitjk4oTl9sHg/8ehuBXQ3/piTbpUnlsgGuD/FLB EFACG/ST7BS81EFKzG0HSszqfg+O+ee5qy6doaqIHkOMOZnjgHzEBz4pQW2V6ET00lER UlK3xUJjrEDDY+vtDk7RRv7rS4yADSag2ea0hg+bwKGkVFxI+SiuWsjjCksa/Y3Ekz9T 9Z7asop1KYNsAVN3N1jPb+zHG+YbpPdXMKIPXNv8mSknurMYSjJpjFNfIEV9vQbL74SY 8m9A== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=i2Fq96/kzkzLHPA8FJ3ko9s5NVfH5SpQnfA7trhmckE=; b=uTFQ1ejvx3h8OGGRCegTw7PyyDZJjwWYpcNpAsD45sCKzqgZmflK3mRwR/uWRHIDd8 2YfljMHnleP8wgyP9+gGkVoQtYgulYoE2Fum1vrKRrb5lXzlFWihYPqL5Dte7hXyWmiR Uo3EH7tz1R0jLgvJOYvnrk33Rdws2/HHNucttHbnjryo6F4rVZr10R6Tkmp/zc6jALdb T/Pn4ABiv60ZxgwrLf688TZ2eyc13mAqrkL0KpItWOQPQ+zDh6nYEFzl2zNCDfWoFkSz RZtyBvqL7xKX09EFcdBb+wsL+FdAxSEg5rBfOQBt7BqXd6jTIqjQyfMsXGGqwnPyulKb MCXg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si3684452pfe.194.2019.03.21.06.46.43; Thu, 21 Mar 2019 06:46:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728316AbfCUNqI (ORCPT + 99 others); Thu, 21 Mar 2019 09:46:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51356 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727829AbfCUNqI (ORCPT ); Thu, 21 Mar 2019 09:46:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B454E1E308; Thu, 21 Mar 2019 13:46:07 +0000 (UTC) Received: from redhat.com (unknown [10.20.6.236]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1087C600C0; Thu, 21 Mar 2019 13:46:05 +0000 (UTC) Date: Thu, 21 Mar 2019 09:46:04 -0400 From: Jerome Glisse To: Thomas Hellstrom Cc: "dri-devel@lists.freedesktop.org" , Linux-graphics-maintainer , Andrew Morton , Matthew Wilcox , Will Deacon , Peter Zijlstra , Rik van Riel , Minchan Kim , Michal Hocko , Huang Ying , Souptick Joarder , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [RFC PATCH RESEND 0/3] mm modifications / helpers for emulated GPU coherent memory Message-ID: <20190321134603.GB2904@redhat.com> References: <20190321132140.114878-1-thellstrom@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190321132140.114878-1-thellstrom@vmware.com> User-Agent: Mutt/1.10.0 (2018-05-17) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 21 Mar 2019 13:46:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 21, 2019 at 01:22:22PM +0000, Thomas Hellstrom wrote: > Resending since last series was sent through a mis-configured SMTP server. > > Hi, > This is an early RFC to make sure I don't go too far in the wrong direction. > > Non-coherent GPUs that can't directly see contents in CPU-visible memory, > like VMWare's SVGA device, run into trouble when trying to implement > coherent memory requirements of modern graphics APIs. Examples are > Vulkan and OpenGL 4.4's ARB_buffer_storage. > > To remedy, we need to emulate coherent memory. Typically when it's detected > that a buffer object is about to be accessed by the GPU, we need to > gather the ranges that have been dirtied by the CPU since the last operation, > apply an operation to make the content visible to the GPU and clear the > the dirty tracking. > > Depending on the size of the buffer object and the access pattern there are > two major possibilities: > > 1) Use page_mkwrite() and pfn_mkwrite(). (GPU buffer objects are backed > either by PCI device memory or by driver-alloced pages). > The dirty-tracking needs to be reset by write-protecting the affected ptes > and flush tlb. This has a complexity of O(num_dirty_pages), but the > write page-fault is of course costly. > > 2) Use hardware dirty-flags in the ptes. The dirty-tracking needs to be reset > by clearing the dirty bits and flush tlb. This has a complexity of > O(num_buffer_object_pages) and dirty bits need to be scanned in full before > each gpu-access. > > So in practice the two methods need to be interleaved for best performance. > > So to facilitate this, I propose two new helpers, apply_as_wrprotect() and > apply_as_clean() ("as" stands for address-space) both inspired by > unmap_mapping_range(). Users of these helpers are in the making, but needs > some cleaning-up. To be clear this should _only be use_ for mmap of device file ? If so the API should try to enforce that as much as possible for instance by mandating the file as argument so that the function can check it is only use in that case. Also big scary comment to make sure no one just start using those outside this very limited frame. > > There's also a change to x_mkwrite() to allow dropping the mmap_sem while > waiting. This will most likely conflict with userfaultfd write protection. Maybe building your thing on top of that would be better. https://lwn.net/Articles/783571/ I will take a cursory look at the patches. Cheers, J?r?me