From patchwork Thu Mar 21 13:22:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10863523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE8401669 for ; Thu, 21 Mar 2019 13:22:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B29B22A1E4 for ; Thu, 21 Mar 2019 13:22:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6B482A1E5; Thu, 21 Mar 2019 13:22:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5627E2A1D6 for ; Thu, 21 Mar 2019 13:22:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 091E68935B; Thu, 21 Mar 2019 13:22:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-eopbgr770088.outbound.protection.outlook.com [40.107.77.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 949348935B for ; Thu, 21 Mar 2019 13:22:28 +0000 (UTC) Received: from MN2PR05MB6141.namprd05.prod.outlook.com (20.178.241.217) by MN2PR05MB6095.namprd05.prod.outlook.com (20.178.243.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.15; Thu, 21 Mar 2019 13:22:23 +0000 Received: from MN2PR05MB6141.namprd05.prod.outlook.com ([fe80::91e:292d:e304:78ad]) by MN2PR05MB6141.namprd05.prod.outlook.com ([fe80::91e:292d:e304:78ad%6]) with mapi id 15.20.1750.010; Thu, 21 Mar 2019 13:22:23 +0000 From: Thomas Hellstrom To: "dri-devel@lists.freedesktop.org" , Linux-graphics-maintainer Subject: [RFC PATCH RESEND 0/3] mm modifications / helpers for emulated GPU coherent memory Thread-Topic: [RFC PATCH RESEND 0/3] mm modifications / helpers for emulated GPU coherent memory Thread-Index: AQHU3+ke+3ZNutXb50uqrjfFd5pvKw== Date: Thu, 21 Mar 2019 13:22:22 +0000 Message-ID: <20190321132140.114878-1-thellstrom@vmware.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR01CA0039.prod.exchangelabs.com (2603:10b6:a03:94::16) To MN2PR05MB6141.namprd05.prod.outlook.com (2603:10b6:208:c7::25) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.0.rc1 x-originating-ip: [208.91.2.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9225d3f4-1a5d-476f-02a5-08d6ae004020 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:MN2PR05MB6095; x-ms-traffictypediagnostic: MN2PR05MB6095: x-ld-processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr x-microsoft-antispam-prvs: x-forefront-prvs: 0983EAD6B2 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(366004)(376002)(346002)(396003)(189003)(199004)(186003)(66574012)(86362001)(1076003)(71200400001)(68736007)(66066001)(71190400001)(26005)(476003)(2616005)(6506007)(386003)(97736004)(486006)(256004)(110136005)(25786009)(7416002)(54906003)(14444005)(102836004)(305945005)(316002)(6436002)(7736002)(2906002)(36756003)(52116002)(6486002)(14454004)(6636002)(3846002)(6116002)(105586002)(6512007)(106356001)(50226002)(5660300002)(53936002)(99286004)(8676002)(8936002)(4326008)(81156014)(2501003)(81166006)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR05MB6095; H:MN2PR05MB6141.namprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: b335V57y7dj2mCBh57Ya5Dkbaz2AVnlLnP9e12Mqc7N0pMH88E3YsrCT+0f4trHfA1V/trKLkz/jTUfB+nQSF88ZKgF6byuu53eoBSxw4q59iKayq8xgyQOfv7p8vm7XtggXavL6TAxdwgiM/A1GwwggvqijTCVZArDFQgm8muCCx2QaUf006q6eBgICFV43uG0JHveExk0Y8CwXLBeO7csKtsAZjeruRnmOQHsXwUydIhuTBgCKzBlJu5r99YgKLBgvsY8dQu5Hw5lJClYTtjxCu+lwQ8zej92Wgr5wKFrv8GQz/v9W6X4X+Yv7/S99dH03/hnAFUywaghCFJ/RvoN+t/Ddjl+QCvXzyiteeMh6m0O9BZYRINWyj9XICz36gigGpwj1sDbwp7aaVeiEkplPfyuyttAcB/tHp0AhwTQ= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9225d3f4-1a5d-476f-02a5-08d6ae004020 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 13:22:23.3787 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR05MB6095 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ci1JgvY53IsFjqkrEJnhDAyV3m6wF2/lrA5nX6tnXEk=; b=aOprZdwQWzbGgcPruJi1iGHv7b42+pyy/alhI7NUNTD0HAOT8AMjnLzTaERl95m8nH4votnS0+Fq12l0F5cqt24SK9pzXGuS9daRrsUkTl3daOo8/OejW4U1De4KCKI4TgvD4hX14jq53TgyIaq8O0D+7XKEi+PsL3PA4nqA5do= X-Mailman-Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=thellstrom@vmware.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstrom , Michal Hocko , Rik van Riel , Peter Zijlstra , Will Deacon , "linux-kernel@vger.kernel.org" , Matthew Wilcox , "linux-mm@kvack.org" , Minchan Kim , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Souptick Joarder , Huang Ying , Andrew Morton Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Cc: Andrew Morton Cc: Matthew Wilcox Cc: Will Deacon Cc: Peter Zijlstra Cc: Rik van Riel Cc: Minchan Kim Cc: Michal Hocko Cc: Huang Ying Cc: Souptick Joarder Cc: "Jérôme Glisse" Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org 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. There's also a change to x_mkwrite() to allow dropping the mmap_sem while waiting. Any comments or suggestions appreciated. Thanks, Thomas