Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1681431ybt; Thu, 25 Jun 2020 11:30:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxszzOqrwplxid1rhk3A7NAhWeW09o0hbpQ5WGyLzuYtHkWu1MU6MsME74+LjtdqsnlwY5t X-Received: by 2002:a17:906:168b:: with SMTP id s11mr15443200ejd.444.1593109840845; Thu, 25 Jun 2020 11:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593109840; cv=none; d=google.com; s=arc-20160816; b=jl7uh+8bhVjoeB1HqTpufbbFUp+uPDoJ4sbqbcnJEHEKVLkjNL5QayXh7++Htnow8r B2ZOPGXln2jOBHH7zutzhoSmVebwKvjH7Ep8KFBVMidwLJLK8DyNyi6VgUEd/rDiecfx vHSIuS+eHUWzdtcbgeJ4DF1lMTQAGbsvH6q67JD6s1WDcps2Q2NZKjIb5cMDET96pGBW hd7Y0O0DvoKeFfqrsoeuNJ1Pvud2+1obX48JUTQ8bKCiclUucqYsFnv3q6CwxPMjYhrZ Ay0fasKG6M4XN2m7HQQq9N7CzUIWWG1628mIv/6pR3g4jmA+ng+Awmm5EP8YR1GhtNr0 qJTQ== 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:from:references:cc:to:subject; bh=dVDtjOJNekdnS7jMIhDZrkR7SUVoPtPB26y7vdiQ8rc=; b=Zq6HwWsPYfgQLPCriewPE/YFwhYPR03FCJaOURd0maTpxG8fdvGn0tbvMEJA1KG00a hqlsocA7Hkd8CNa1u4nHxA51lA0HtCn4BqyojTAB0NLiRc9ZFZzFKwCQ3yO+dgH9CEwK Iek73ls+Z9FBrDgBhdowUnvSmSYCriZR5d2QdLUysAe6By52TwPBCCpVjSlDjLcQmguF jOU5pyaGWRizd/ebt0Oew5OG6qbyqDSJpnX5SOdsKFi5QiTRuoh3Iw3akQ12gcNsKbyS YEQzRJbe5RsfSWZ784BGORGuNUc/vuaSYGXs3WzCeA80EZ7+EPfFp4v4FSzRlxpXbXnV b2WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=C79NzfYI; 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 w22si35941ejb.729.2020.06.25.11.30.17; Thu, 25 Jun 2020 11:30:40 -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=C79NzfYI; 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 S2405492AbgFYRmZ (ORCPT + 99 others); Thu, 25 Jun 2020 13:42:25 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:10680 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405282AbgFYRmZ (ORCPT ); Thu, 25 Jun 2020 13:42:25 -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:40:50 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 25 Jun 2020 10:42:24 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 25 Jun 2020 10:42:24 -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:42:24 +0000 Subject: Re: [RESEND PATCH 2/3] nouveau: fix mixed normal and device private page migration To: Jason Gunthorpe CC: Christoph Hellwig , , , Jerome Glisse , "John Hubbard" , 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> <20200625173144.GT6578@ziepe.ca> From: Ralph Campbell X-Nvconfidentiality: public Message-ID: <412b3a51-619a-4f94-da96-f4596e5eb510@nvidia.com> Date: Thu, 25 Jun 2020 10:42:24 -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: <20200625173144.GT6578@ziepe.ca> 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=1593106851; bh=dVDtjOJNekdnS7jMIhDZrkR7SUVoPtPB26y7vdiQ8rc=; h=X-PGP-Universal:Subject:To:CC:References:From: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=C79NzfYIZ/4/7K07xyDkDyWF09cLOtFqcAGWDpgLD6fZQTPfIVTxfx1KX73YbBEX5 /lPoACQODhbk+hYa01hbXni4W78wr6AcXvVIyzAG0zdQlx2FtFg1fMjGGCHQ9GA8iu ZhYBp+2pngMltPsi9YG3jJwCKSJmCqJAqoXHEQLTZGDGuSNkde/g66HChAung88sMa Yn/fIm7hckavMnJq1E5saPfA+7u/Qkh3aGkER+w3SF8PIYoGYjuHKncp7/+hLfUWWo VokvfaTAX8aR6ZKyk9Guo7o3WeVENV12wbZ5ShgD2PtP+fkIq1KpbhHNNwmfFDGww0 OSCwcLhSmr9Vg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/25/20 10:31 AM, Jason Gunthorpe wrote: > On Thu, Jun 25, 2020 at 10:25:38AM -0700, Ralph Campbell wrote: >> 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: >>> >>> 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. T= he >>>>> source pages might already have been migrated to device private memor= y. >>>>> 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 = want >>>> to migrate from or two device private memory, and then skip all the wo= rk >>>> for regions of memory that already are in the right place?=C2=A0 This = might be >>>> a little more work initially, but I think it leads to a much better >>>> API. >>>> >>> >>> The current code does encode the direction with src_owner !=3D NULL mea= ning >>> device private to system memory and src_owner =3D=3D NULL meaning syste= m >>> 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 = the >>> direction but I'm unclear how that makes things less delicate. >>> Can you expand on what you are worried about? >>> >>> The issue with invalidations might be better addressed by letting the d= evice >>> 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. >>> >>> 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 = type. >> >> 3) Modify nouveau_svmm_invalidate_range_start() to simply return (no inv= alidations) >> for MMU_NOTIFY_MIGRATE mmu notifier callbacks. >=20 > Isn't it a bit of an assumption that migrate_vma_collect() is only > used by nouveau itself? >=20 > What if some other devices' device_private pages are being migrated? >=20 > Jason >=20 Good point. The driver needs a way of knowing the callback is due its call to migrate_vma_setup() and not some other migration invalidation. How about adding a void pointer to struct mmu_notifier_range which migrate_vma_collect() can set to src_owner. If the event is MMU_NOTIFY_MIGRATE and the src_owner matches the void pointer, then the callback should be the one the driver initiated.