Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1680087ybt; Thu, 25 Jun 2020 11:28:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWJ3KMspwnlKtDi4bindqBTqwk1phXidAMsKmjaYeZGwX2xIeQuvwOlu0d324PGFFPYw9l X-Received: by 2002:a17:906:d8db:: with SMTP id re27mr12959194ejb.554.1593109734266; Thu, 25 Jun 2020 11:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593109734; cv=none; d=google.com; s=arc-20160816; b=LUKl2d36WdHMA1N33j2jiqoKjA0mRFHp3zspTXsN2GJjmUOkvgRCod7iTrWY9KWycA HT9RIDhEo4XF2Sjvj2P7ZkYW6c185w3rZSfW63iZy0pudXKQP+ohqH29E56mwHxsL9B6 NzwQtFbwrJjcONG0NTCYIGt/S8nKaHNvFyErb8iFhEtpYxIHjvPjTz38u1gSV6/SWxpP Ytei6ZiY2Xn13QAsNtx7z9kzXzpE/3cr1bhOjuYsS84YHzpCcCnIKqW/2xfmPfA24I2D DPB0IU6FxDB7Ns6J1h1TDx9nAMyFOfZvvk8Db9Rt2x3nxQ2nbASiS5SkbS3nDPHO8vRq PHMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=uYfK6rsz5+ealU9/4gfA5Q+t0zfXrSyYkvAq9Mm4eGo=; b=UwBfdgzWdtk45OnoMGPn2k6aev2isjf03Ua7k+SMw7KKK38LN5Hl2+5mv67D5/XxqF xb5SFyJiF7SQDcA34lnhAQBTssHB0oIjlDrqVa0EKyhClEM9u/cwugwoGQIVxOKbGIw3 2LJ7JoliUA6X+Tv4xD95MO3NXwfdu+n1rOxjRE5wP1zb5ff7edxNRnkFyr2yM8wrzue/ MlkNwG7a/nOXHrO/irdwE4beaHaB7cZhh7iL36XjxTPK8mnr52nVhUPMFdg+IjIBrneN 45lS10dIa8T2vLi0hV7Rg7dPs7VbU81T8uUHhM9eo0KbpGjVzfSFLPP2gz0OD80tfnGZ 4+gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=XRF2xro5; 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 r22si1658062edq.411.2020.06.25.11.28.31; Thu, 25 Jun 2020 11:28:54 -0700 (PDT) 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=XRF2xro5; 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 S2404596AbgFYRZu (ORCPT + 99 others); Thu, 25 Jun 2020 13:25:50 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:9156 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404342AbgFYRZu (ORCPT ); Thu, 25 Jun 2020 13:25:50 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 25 Jun 2020 10:24:15 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 25 Jun 2020 10:25:49 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 25 Jun 2020 10:25:49 -0700 Received: from rcampbell-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 25 Jun 2020 17:25:39 +0000 Subject: Re: [RESEND PATCH 2/3] nouveau: fix mixed normal and device private page migration From: Ralph Campbell To: Christoph Hellwig CC: , , "Jerome Glisse" , John Hubbard , "Jason Gunthorpe" , Ben Skeggs , Andrew Morton , , Bharata B Rao References: <20200622233854.10889-1-rcampbell@nvidia.com> <20200622233854.10889-3-rcampbell@nvidia.com> <20200624072355.GB18609@lst.de> <330f6a82-d01d-db97-1dec-69346f41e707@nvidia.com> X-Nvconfidentiality: public Message-ID: Date: Thu, 25 Jun 2020 10:25:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <330f6a82-d01d-db97-1dec-69346f41e707@nvidia.com> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1593105855; bh=uYfK6rsz5+ealU9/4gfA5Q+t0zfXrSyYkvAq9Mm4eGo=; h=X-PGP-Universal:Subject:From:To:CC:References:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=XRF2xro5q/8nFW0qjYwB2C4HyBRCQPyCPqDcMZofasBrICeXUutwqnsZyPduCtLpq /ggcpTLFzaRb8MUCEsmqC8yYPn/2pY+ZgjZwdi3UDopmO98V/URpD7d9BSuxWKPA+G 2nWK0ffA0twlTJi0w2nlPSyqlw9LesqC01C2zXdacZOl5IX+OEzPnbN5JxKfO+3mNq oLvpus8nOYzAdTC4mzG5HtY6eVcuvTk4GK+8EAbum/RRJFnP5wOzkH//3bk+0krJvj HKpTZHcZhZjtaWE+Kb3QksgDgj0vokNgKMFr+K5B2UagSY1t9LsD44MzthqGXgXuBU T0TO8BMY5JjBg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Making sure to include linux-mm and Bharata B Rao for IBM's use of migrate_vma*(). On 6/24/20 11:10 AM, Ralph Campbell wrote: >=20 > On 6/24/20 12:23 AM, Christoph Hellwig wrote: >> On Mon, Jun 22, 2020 at 04:38:53PM -0700, Ralph Campbell wrote: >>> The OpenCL function clEnqueueSVMMigrateMem(), without any flags, will >>> migrate memory in the given address range to device private memory. The >>> source pages might already have been migrated to device private memory. >>> In that case, the source struct page is not checked to see if it is >>> a device private page and incorrectly computes the GPU's physical >>> address of local memory leading to data corruption. >>> Fix this by checking the source struct page and computing the correct >>> physical address. >> >> I'm really worried about all this delicate code to fix the mixed >> ranges.=C2=A0 Can't we make it clear at the migrate_vma_* level if we wa= nt >> to migrate from or two device private memory, and then skip all the work >> for regions of memory that already are in the right place?=C2=A0 This mi= ght be >> a little more work initially, but I think it leads to a much better >> API. >> >=20 > The current code does encode the direction with src_owner !=3D NULL meani= ng > device private to system memory and src_owner =3D=3D NULL meaning system > memory to device private memory. This patch would obviously defeat that > so perhaps a flag could be added to the struct migrate_vma to indicate th= e > direction but I'm unclear how that makes things less delicate. > Can you expand on what you are worried about? >=20 > The issue with invalidations might be better addressed by letting the dev= ice > driver handle device private page TLB invalidations when migrating to > system memory and changing migrate_vma_setup() to only invalidate CPU > TLB entries for normal pages being migrated to device private memory. > If a page isn't migrating, it seems inefficient to invalidate those TLB > entries. >=20 > Any other suggestions? After a night's sleep, I think this might work. What do others think? 1) Add a new MMU_NOTIFY_MIGRATE enum to mmu_notifier_event. 2) Change migrate_vma_collect() to use the new MMU_NOTIFY_MIGRATE event typ= e. 3) Modify nouveau_svmm_invalidate_range_start() to simply return (no invali= dations) for MMU_NOTIFY_MIGRATE mmu notifier callbacks. 4) Leave the src_owner check in migrate_vma_collect_pmd() for normal pages = so if the device driver is migrating normal pages to device private memory, the drive= r would set src_owner =3D NULL and already migrated device private pages would be s= kipped. Since the mmu notifier callback did nothing, the device private entries rem= ain valid in the device's MMU. migrate_vma_collect_pmd() would still invalidate the C= PU page tables for migrated normal pages. If the driver is migrating device private pages to system memory, it would = set src_owner !=3D NULL, normal pages would be skipped, but now the device driv= er has to invalidate device MMU mappings in the "alloc and copy" before doing the cop= y. This would be after migrate_vma_setup() returns so the list of migrating de= vice pages is known to the driver. The rest of the migrate_vma_pages() and migrate_vma_finalize() remain the s= ame.