Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp116930pxb; Mon, 8 Feb 2021 17:11:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJybjkqyy+TZkxcE0rj+Mxj+5qyx/rlJnPdhGmG/qgurnCCVWpg/OPqPa9CJ5twBNQu0WDGT X-Received: by 2002:a50:9d4d:: with SMTP id j13mr19701263edk.83.1612833079887; Mon, 08 Feb 2021 17:11:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612833079; cv=none; d=google.com; s=arc-20160816; b=s5/FDfErseMZVCUrHXHUQQTKOfcvi4mWBy78QW+bwm4gGOMMk9GUuSZ44e94LAwiSs vldluaKvkpHBAkAwja+znhBA3MJfTwS4Q0frgy2RriQyCIMa35JOmj/lFGoL5mpcqQbp H0cEw36i6cFkDeS/zdyn0Pe+4lIbAugHn91NSljj6Ctsj8J1TvqkFUsEG//ztBxHa4px xpYcl8YkquaLB/lehg/Y6Sdr95VUgYhPyjL2FXu6sU1HgVxYVmiWo1SIwgMrE6J8nk7J 4zuszpz9xO0Bc/xfR1uZ4r61IAn+j2DcgqkmYOgzpfaWxKFnJLoSczf/kTGYOZgaGlfy vyIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=fHzIrA6EUkcvyYZOzc2r5U/q2OlDx68NlFICQTs7dQ8=; b=H4AocWURdk9j5gRVgDDONosWrPk+1gzM+sPbaenhUea8GFtMdU4cA98vd7bIcBoCKs boU3WIXBOa+1Q0orQiwk4Kb2lqVzOtJVKt/ZGUEoF6A/oVvOlODcx63c07WZdPoxKd4C lnCmF17Bd69DX0ufj1k/OpYxYSi+xGf9sJhTAncmi8RyMng37mWz0TYA3pYJv+mEdfBU gnTcf/+MbCXhFINb9rZiHlDetOZq/B/1/B9StQpiWhCTH4JDdt4YH9v9nnBXNwG3d1VY 1k7vB+WJ35r0B4gRZpXw25eEH7yny57YBb+NOljLM75zBnHRsUpex+dq7RtF5qaxOV1q VJGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=JLn42Im7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id br5si12599624ejb.608.2021.02.08.17.10.57; Mon, 08 Feb 2021 17:11:19 -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=@nvidia.com header.s=n1 header.b=JLn42Im7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbhBIBKD (ORCPT + 99 others); Mon, 8 Feb 2021 20:10:03 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:6565 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbhBIBKC (ORCPT ); Mon, 8 Feb 2021 20:10:02 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Mon, 08 Feb 2021 17:09:21 -0800 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 9 Feb 2021 01:09:21 +0000 Received: from localhost (172.20.145.6) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 9 Feb 2021 01:09:20 +0000 From: Alistair Popple To: , , , CC: , , , , , , , "Alistair Popple" Subject: [PATCH 0/9] Add support for SVM atomics in Nouveau Date: Tue, 9 Feb 2021 12:07:13 +1100 Message-ID: <20210209010722.13839-1-apopple@nvidia.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To DRHQMAIL107.nvidia.com (10.27.9.16) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612832961; bh=fHzIrA6EUkcvyYZOzc2r5U/q2OlDx68NlFICQTs7dQ8=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; b=JLn42Im7IWDEnuTDb+HAfmg21WCbnWEbIR0KYAxMkB56Xg+hXwpVMRWJJRpoQRHJa huf1OdR0WZ/xbBkkJUUvfEpMrTL1a5eUkJvtZpjNYotNPcpHubOEIwYsPQWQwTlOxO jybuOYXvAGRV+8LewjvSBZSReyU0Uwa0ZRMllU/kW0/RgIx1LjmT0zt3MKIYYamXOK pB30alYCHMQ0EXloW6/GydUcrRRaxaCIdqaauza/x+VFBXw1WCAhGJL+cD9g6rHI7u K2FsmBZ+Lca4vpaXoQR0qV/i4FwObqrVWHlQXKPTDH/AljdLXGbV8p9MZ6wUzY0KkI TsL/93w80i8dw== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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(-) --=20 2.20.1