From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 429B2C433E0 for ; Fri, 31 Jul 2020 19:31:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0E3C8208E4 for ; Fri, 31 Jul 2020 19:31:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="Jrvy3o8X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E3C8208E4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 81EF68D0056; Fri, 31 Jul 2020 15:31:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A8438D000B; Fri, 31 Jul 2020 15:31:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 697918D0056; Fri, 31 Jul 2020 15:31:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 522CD8D000B for ; Fri, 31 Jul 2020 15:31:27 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C95D8180AD802 for ; Fri, 31 Jul 2020 19:31:26 +0000 (UTC) X-FDA: 77099364972.11.ants62_041271b26f86 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 86F3D180F8B86 for ; Fri, 31 Jul 2020 19:31:26 +0000 (UTC) X-HE-Tag: ants62_041271b26f86 X-Filterd-Recvd-Size: 6641 Received: from hqnvemgate24.nvidia.com (hqnvemgate24.nvidia.com [216.228.121.143]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Fri, 31 Jul 2020 19:31:25 +0000 (UTC) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 31 Jul 2020 12:29:50 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 31 Jul 2020 12:31:24 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 31 Jul 2020 12:31: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; Fri, 31 Jul 2020 19:31:23 +0000 Subject: Re: [PATCH v4 6/6] mm/migrate: remove range invalidation in migrate_vma_pages() To: Jason Gunthorpe CC: , , , , , , "Jerome Glisse" , John Hubbard , "Christoph Hellwig" , Andrew Morton , Shuah Khan , Ben Skeggs , Bharata B Rao References: <20200723223004.9586-1-rcampbell@nvidia.com> <20200723223004.9586-7-rcampbell@nvidia.com> <20200728191940.GB159104@nvidia.com> <7f947311-0034-9148-1dca-fb9b9a10abc4@nvidia.com> <20200731191543.GJ24045@ziepe.ca> X-Nvconfidentiality: public From: Ralph Campbell Message-ID: Date: Fri, 31 Jul 2020 12:31:23 -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: <20200731191543.GJ24045@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: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1596223790; bh=MF4Np6kSGoTk93XreGGnpf8Lflbk/aQSd9CdXlm3gxg=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=Jrvy3o8XJ2rY3h6bMQqWanvXTXrCvZz2LWHdo1X7SNs+nmekjNPqnyIhs7UtxJkuW FMnHvtBQj8zr9jesv11SxggwiWhDu6842G9JagwXSjMizmbF/C+x2Ml8s6IOQs08nq 2n8TQS51oUHkTQcN2FCe7qo70Q8VKNVlgQ4qLtBkSQ9+ib1yW6Nc70SFp/jQcRjyxh WxtFmZ16kXYh+Hq3mhLNHf/Y0PI4F+dahDYQaKaTitPTDBPbVjT0OVveLaQMuLEI/Z pIPJrtAiTRbfiY7Pb5dn/ns2bCBOZa3fWf9TQyI6WuLHb8Jv/Fs6eww3WhAufsO/x5 njIu1bRlWI0iw== X-Rspamd-Queue-Id: 86F3D180F8B86 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 7/31/20 12:15 PM, Jason Gunthorpe wrote: > On Tue, Jul 28, 2020 at 03:04:07PM -0700, Ralph Campbell wrote: >> >> On 7/28/20 12:19 PM, Jason Gunthorpe wrote: >>> On Thu, Jul 23, 2020 at 03:30:04PM -0700, Ralph Campbell wrote: >>>> When migrating the special zero page, migrate_vma_pages() calls >>>> mmu_notifier_invalidate_range_start() before replacing the zero page >>>> PFN in the CPU page tables. This is unnecessary since the range was >>>> invalidated in migrate_vma_setup() and the page table entry is checked >>>> to be sure it hasn't changed between migrate_vma_setup() and >>>> migrate_vma_pages(). Therefore, remove the redundant invalidation. >>> >>> I don't follow this logic, the purpose of the invalidation is also to >>> clear out anything that may be mirroring this VA, and "the page hasn't >>> changed" doesn't seem to rule out that case? >>> >>> I'm also not sure I follow where the zero page came from? >> >> The zero page comes from an anonymous private VMA that is read-only >> and the user level CPU process tries to read the page data (or any >> other read page fault). >> >>> Jason >>> >> >> The overall migration process is: >> >> mmap_read_lock() >> >> migrate_vma_setup() >> // invalidates range, locks/isolates pages, puts migration entry in page table >> >> >> >> migrate_vma_pages() >> // moves source struct page info to destination struct page info. >> // clears migration flag for pages that can't be migrated. >> >> >> >> migrate_vma_finalize() >> // replaces migration page table entry with destination page PFN. >> >> mmap_read_unlock() >> >> Since the address range is invalidated in the migrate_vma_setup() stage, >> and the page is isolated from the LRU cache, locked, unmapped, and the page table >> holds a migration entry (so the page can't be faulted and the CPU page table set >> valid again), and there are no extra page references (pins), the page >> "should not be modified". > > That is the physical page though, it doesn't prove nobody else is > reading the PTE. > >> For pte_none()/is_zero_pfn() entries, migrate_vma_setup() leaves the >> pte_none()/is_zero_pfn() entry in place but does still call >> mmu_notifier_invalidate_range_start() for the whole range being migrated. > > Ok.. > >> In the migrate_vma_pages() step, the pte page table is locked and the >> pte entry checked to be sure it is still pte_none/is_zero_pfn(). If not, >> the new page isn't inserted. If it is still none/zero, the new device private >> struct page is inserted into the page table, replacing the pte_none()/is_zero_pfn() >> page table entry. The secondary MMUs were already invalidated in the migrate_vma_setup() >> step and a pte_none() or zero page can't be modified so the only invalidation needed >> is the CPU TLB(s) for clearing the special zero page PTE entry. > > No, the secondary MMU was invalidated but the invalidation start/end > range was exited. That means a secondary MMU is immeidately able to > reload the zero page into its MMU cache. > > When this code replaces the PTE that has a zero page it also has to > invalidate again so that secondary MMU's are guaranteed to pick up the > new PTE value. > > So, I still don't understand how this is safe? > > Jason Oops, you are right of course. I was only thinking of the device doing the migration and forgetting about a second device faulting on the same page. You can drop patch from the series.