Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp373037pxb; Tue, 9 Feb 2021 02:35:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZpxnA47IGzM31nLdZDO52UQI6W5Lp/KqCiDIzRtM+qAjS8iz2ybLlXPSV69b6O9RVcPw0 X-Received: by 2002:a17:906:2bd7:: with SMTP id n23mr21605004ejg.502.1612866951512; Tue, 09 Feb 2021 02:35:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612866951; cv=none; d=google.com; s=arc-20160816; b=hkciNyIRliVBMfih2neGuUOGzl+HD4svd9qsXBEbSxxZy3OJYrXyzuAUnXw5YMXTOl /de3FYzXdAjXCcPatyXcfTTwS7iXV4zrDyNdyNOVMrG5w/bxaqDQmv4RAxUynrG6YlgK 3ZkRHMGOnlbktnr/n95cmTqlRIw4EOhNLi15HQURFIwW0wGQw+A9Dv5kjU9cpDynP9rF WJohQTbSa5602imps4LEwJqGk1cKifs7+EINbrM09WXqZrGC8VDDpW7m5qwWE8z9/+yt QAlq19m1dT1Oov8upplTtXPwZ3qvDD6KTlFsbO9pFqi3ZLVixkJINW4i4BFGCP7Ft5pq 9qmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=IuPwe6UnW2D70azMPi7ooQm/qzJFfsCFKJ5pbRf3Rag=; b=Pv26hUVFzoAD6cllUZTVbbsU5p4qC2nbtYOd5NxNR+CVZF1XsbnqnhKZMrnIvTm9vf ejK2CU9LkPtYCcHTc+65iUeyXlXzX2e+wKQkRe8lnZeDcw7xrM0MQQ1h7+MqJSreo65W gJ92bWnYmwNEzWWCe8Cnd1ySrvA5HsSxkGENPOEBOkGxPAFeZZ4PNb77FUjXMbpfy5KV gaNJdB5HL9uKE8uhZLjiyOXNd3rgy7WbrKMPZvO3wlnR/eLnzI2j6AgcfXJEqFZEhoIi 1oSjPLxzYiRsGiWsJcesIXzqXWzzw7wyhoHA0JxlGvHASB44FWNi9zs1AVyCcoPlnaOi mY4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=fjNiIqJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr3si4312714ejb.514.2021.02.09.02.35.28; Tue, 09 Feb 2021 02:35:51 -0800 (PST) Received-SPF: pass (google.com: 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=@ffwll.ch header.s=google header.b=fjNiIqJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231972AbhBIKdL (ORCPT + 99 others); Tue, 9 Feb 2021 05:33:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231856AbhBIK16 (ORCPT ); Tue, 9 Feb 2021 05:27:58 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61DD6C06178C for ; Tue, 9 Feb 2021 02:27:18 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id r75so5265967oie.11 for ; Tue, 09 Feb 2021 02:27:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IuPwe6UnW2D70azMPi7ooQm/qzJFfsCFKJ5pbRf3Rag=; b=fjNiIqJN11AmOAs1Pa1q8noSSurhramxPWrN+UmCUCz19mWIDz3e7u/5LlRSNHdThF 3SEZ7MSpAtz9+pzxH2o0Dx3sbAmj0oYCQwbWPReA/QOLUf+HZ5ccnMsn7DBtkieJMPzL BA++OnfY3vQP93lMntxdlYu6pI2Pqm/Q0zTQA= 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; bh=IuPwe6UnW2D70azMPi7ooQm/qzJFfsCFKJ5pbRf3Rag=; b=YQlhS33qwltPurZ9WK8FVnotFODRz3bH4jK6o2yyEy5Jfo+osEUb3hox7G79kiqotf dTt6Ml3XrLMmBkq5sup8ag2IF4cbDKul40FZMitrkb4YLcQVkJpuJXF9+gPns8KoOe25 OmzfIKRMEqbLLcaIBgFYNH68fcomSsw4V31f72dWgJaiMvKFLMosWudeWvS82IL/v8G7 tBcp+rfIMLYvowp7cFbqeJXBeWWi5J7rIP27EGmBAmNE2dintjPoka/c/yyFEq0LXDr7 PXJOabI0BXBNxq1g980Ft4+vhs6ac7TUACs5jjHz/uvVSs4GXIN+LD8v+aem0kVAE6n9 gjnw== X-Gm-Message-State: AOAM533tyhFyDbwQKgT6lnrQtW0H0ENHeH8KEFqgJdZmy6btaQLvMcfm aIzXFj83SbRAdtE/W4BnftV2B6IbnzoF+e4r3txNxg== X-Received: by 2002:aca:1906:: with SMTP id l6mr1967569oii.101.1612866437717; Tue, 09 Feb 2021 02:27:17 -0800 (PST) MIME-Version: 1.0 References: <20210209010722.13839-1-apopple@nvidia.com> In-Reply-To: <20210209010722.13839-1-apopple@nvidia.com> From: Daniel Vetter Date: Tue, 9 Feb 2021 11:27:05 +0100 Message-ID: Subject: Re: [PATCH 0/9] Add support for SVM atomics in Nouveau To: Alistair Popple Cc: Linux MM , Nouveau Dev , Ben Skeggs , Andrew Morton , Linux Doc Mailing List , Linux Kernel Mailing List , kvm-ppc@vger.kernel.org, dri-devel , John Hubbard , Ralph Campbell , Jerome Glisse , Jason Gunthorpe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 09, 2021 at 12:07:13PM +1100, Alistair Popple wrote: > This series adds support to Nouveau for atomic memory operations on OpenCL > shared virtual memory (SVM). This is achieved using the atomic PTE bits on > the GPU to only permit atomic operations to system memory when a page is > not mapped in userspace on the CPU. > > This is implemented by adding a mode to migrate_vma_pages() which unmaps > and isolates existing pages from the CPU and pins them. The original > userspace page table entries are migrated to point to device private pages > allocated by the driver. This allows the driver to enable GPU atomic access > to the page as it will receive a callback when CPU userspace needs to > access it. > > In response to this callback the driver revokes the atomic access > permission from the GPU and migrates entries to point back to the original > page. The original page is unpinned as part of the migration operation > which also returns it to the LRU. > > Patch 3 contains the bulk of the memory management changes to implement > unmap and pin. > > Patches 6-9 extend Nouveau to use the new mode to allow system wide atomics > for OpenCL SVM to be implemented on Nouveau. > > This has been tested using the latest upstream Mesa userspace with a simple > OpenCL test program which checks the results of atomic GPU operations on a > buffer whilst also writing to the same buffer from the CPU. > > Problems yet to be addressed: > > Recent changes to pin_user_pages() prevent the creation of pinned pages in > ZONE_MOVABLE. This series allows pinned pages to be created in ZONE_MOVABLE > as attempts to migrate may fail which would be fatal to userspace. > > In this case migration of the pinned page is unnecessary as the page can be > unpinned at anytime by having the driver revoke atomic permission as it > does for the migrate_to_ram() callback. However a method of calling this > when memory needs to be moved has yet to be resolved so any discussion is > welcome. Why do we need to pin for gpu atomics? You still have the callback for cpu faults, so you can move the page as needed, and hence a long-term pin sounds like the wrong approach. That would avoid all the hacking around long term pin constraints, because for real unmoveable long term pinned memory we really want to have all these checks. So I think we might be missing some other callbacks to be able to move these pages, instead of abusing longterm pins for lack of better tools. Cheers, Daniel > > Alistair Popple (9): > mm/migrate.c: Always allow device private pages to migrate > mm/migrate.c: Allow pfn flags to be passed to migrate_vma_setup() > mm/migrate: Add a unmap and pin migration mode > Documentation: Add unmap and pin to HMM > hmm-tests: Add test for unmap and pin > nouveau/dmem: Only map migrating pages > nouveau/svm: Refactor nouveau_range_fault > nouveau/dmem: Add support for multiple page types > nouveau/svm: Implement atomic SVM access > > Documentation/vm/hmm.rst | 22 +- > arch/powerpc/kvm/book3s_hv_uvmem.c | 4 +- > drivers/gpu/drm/nouveau/include/nvif/if000c.h | 1 + > drivers/gpu/drm/nouveau/nouveau_dmem.c | 190 +++++++++++++++--- > drivers/gpu/drm/nouveau/nouveau_dmem.h | 9 + > drivers/gpu/drm/nouveau/nouveau_svm.c | 148 +++++++++++--- > drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.h | 1 + > .../drm/nouveau/nvkm/subdev/mmu/vmmgp100.c | 6 + > include/linux/migrate.h | 2 + > include/linux/migrate_mode.h | 1 + > lib/test_hmm.c | 109 ++++++++-- > lib/test_hmm_uapi.h | 1 + > mm/migrate.c | 82 +++++--- > tools/testing/selftests/vm/hmm-tests.c | 49 +++++ > 14 files changed, 524 insertions(+), 101 deletions(-) > > -- > 2.20.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch