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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FA91C28D13 for ; Thu, 25 Aug 2022 14:40:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7CC76B0074; Thu, 25 Aug 2022 10:40:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A04C86B0075; Thu, 25 Aug 2022 10:40:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87F32940007; Thu, 25 Aug 2022 10:40:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 728116B0074 for ; Thu, 25 Aug 2022 10:40:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3783CC0117 for ; Thu, 25 Aug 2022 14:40:28 +0000 (UTC) X-FDA: 79838375736.19.E6C2523 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 7226B40003 for ; Thu, 25 Aug 2022 14:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661438426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9gl8JtwHu2ieQqvlFlp3IZDIk+riOkODkt1dgMqEPWw=; b=UT9oLXsBQl/ExaL/wm6Yoj+3HLXvuh+YjPEPWPLQcBEd09QHyGSH3nvCVB5xO7/+jRf4BV jpWMeDHfbVocuAo4+xtpjUPj3X4xNLOQRX9mScLFamhnKWOJRAQIlInfQXHvTddzDoCZQG gBw+QhIgTlDKTgW6wJOMFKondrxtsjw= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-416-pi6mGlGrMQK-gB_HwioYUg-1; Thu, 25 Aug 2022 10:40:25 -0400 X-MC-Unique: pi6mGlGrMQK-gB_HwioYUg-1 Received: by mail-qv1-f70.google.com with SMTP id d10-20020a0cf6ca000000b00496744bc8e6so11713976qvo.2 for ; Thu, 25 Aug 2022 07:40:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=9gl8JtwHu2ieQqvlFlp3IZDIk+riOkODkt1dgMqEPWw=; b=UN7JTfbrDitkBy666NqNjULiP9ZDVQWYSAcRyCCaMbLvZrB98Lmdqkzq36Bx/RbIjq Ai1gEVht5AzUelhp+aFu9QIjq+M/RPYI9ztSE30CE8QJL5jwkZA58SP6ttNlJC7NpQYE UWK7IyTQKipQyeT3qWYHNGC+8WvK8BmdRXmrhYifcVMjiDSZYs4J5dzkB/wUYEJa+rp7 CVPP0lI+/3iu5h+//TL9Ap280Zt3CajyT5/6OsF4ORJ7+nMDFvDeF5HSZQx9aubH6DWN WTi7BbrOZVIg9RPcipllx5UnINpoAHN1Ullz+GpqZ6h6XKf5yOAqMKPm7yad7qDuxRCr Wb1A== X-Gm-Message-State: ACgBeo1U1KsuZzqYfM7nSWi+IBQz+BbOx9PK5FmJ890ZFTkbiWYdQywz NpmMckfY93oBLheLAYS3oFlTNrIVuTKr6VLdKa4toiICA9kGdoCcl5HZdN/AKNwvuXgs3ZtNhdb rEO3HMaOx6f4= X-Received: by 2002:a05:622a:170d:b0:344:646b:73e with SMTP id h13-20020a05622a170d00b00344646b073emr3753333qtk.138.1661438425286; Thu, 25 Aug 2022 07:40:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TKKJVMyGiS6bNr+tzF2JYvmP3XOGV8sOgN2jBYX27NWJFP8fCLQ0t520JEVxHIVaRHT/sEQ== X-Received: by 2002:a05:622a:170d:b0:344:646b:73e with SMTP id h13-20020a05622a170d00b00344646b073emr3753302qtk.138.1661438425022; Thu, 25 Aug 2022 07:40:25 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id j20-20020a05620a411400b006b9a24dc9d7sm17831800qko.7.2022.08.25.07.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 07:40:24 -0700 (PDT) Date: Thu, 25 Aug 2022 10:40:21 -0400 From: Peter Xu To: Alistair Popple Cc: "Huang, Ying" , Nadav Amit , huang ying , Linux MM , Andrew Morton , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org Subject: Re: [PATCH v2 1/2] mm/migrate_device.c: Copy pte dirty bit to page Message-ID: References: <87tu6bbaq7.fsf@yhuang6-desk2.ccr.corp.intel.com> <1D2FB37E-831B-445E-ADDC-C1D3FF0425C1@gmail.com> <87czcyawl6.fsf@yhuang6-desk2.ccr.corp.intel.com> <874jy9aqts.fsf@yhuang6-desk2.ccr.corp.intel.com> <87czcqiecd.fsf@nvdebian.thelocal> <87o7w9f7dp.fsf@nvdebian.thelocal> MIME-Version: 1.0 In-Reply-To: <87o7w9f7dp.fsf@nvdebian.thelocal> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661438427; a=rsa-sha256; cv=none; b=38/Pd2B+6hXeZDtEH0sx1zzCigw4LPNjs5XOyfnFvJOdW0Ny9DbGmeaoTeu/cHd/3E/dZj iwplmq/lK2KQrI5YAC+5eMbzkrMv7x6U0XTirDOm6bmZyFOutXMU94AeH7mAayxp75m8uQ UOROLUv8PQcYmnYadbFjgxFJ3BIBQmc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UT9oLXsB; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661438427; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9gl8JtwHu2ieQqvlFlp3IZDIk+riOkODkt1dgMqEPWw=; b=ZZn/rXZ5Lo75EFFJtmc6DUHi1kgir6C1FD/lC3RTa0or/DvRKhDe0lkCnNEI2uyKw3KiO4 U1q2teuF/H1cPaGrpuOROnXrmtoxN89YxQUG5mtTp7eGBWvB6cE0ORv0MZGZICy9av4Rbr UO2eUMpDmPhO2YqtkvMvt2BsTohTfck= X-Stat-Signature: uxm3ggazpwg4k4yspr5p391y9zbad3kq X-Rspamd-Queue-Id: 7226B40003 X-Rspam-User: X-Rspamd-Server: rspam06 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UT9oLXsB; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1661438427-946351 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 Thu, Aug 25, 2022 at 10:42:41AM +1000, Alistair Popple wrote: > > Peter Xu writes: > > > On Wed, Aug 24, 2022 at 04:25:44PM -0400, Peter Xu wrote: > >> On Wed, Aug 24, 2022 at 11:56:25AM +1000, Alistair Popple wrote: > >> > >> Still I don't know whether there'll be any side effect of having stall tlbs > >> > >> in !present ptes because I'm not familiar enough with the private dev swap > >> > >> migration code. But I think having them will be safe, even if redundant. > >> > > >> > What side-effect were you thinking of? I don't see any issue with not > >> > TLB flushing stale device-private TLBs prior to the migration because > >> > they're not accessible anyway and shouldn't be in any TLB. > >> > >> Sorry to be misleading, I never meant we must add them. As I said it's > >> just that I don't know the code well so I don't know whether it's safe to > >> not have it. > >> > >> IIUC it's about whether having stall system-ram stall tlb in other > >> processor would matter or not here. E.g. some none pte that this code > >> collected (boosted both "cpages" and "npages" for a none pte) could have > >> stall tlb in other cores that makes the page writable there. > > > > For this one, let me give a more detailed example. > > Thanks, I would have been completely lost about what you were talking > about without this :-) > > > It's about whether below could happen: > > > > thread 1 thread 2 thread 3 > > -------- -------- -------- > > write to page P (data=P1) > > (cached TLB writable) > > zap_pte_range() > > pgtable lock > > clear pte for page P > > pgtable unlock > > ... > > migrate_vma_collect > > pte none, npages++, cpages++ > > allocate device page > > copy data (with P1) > > map pte as device swap > > write to page P again > > (data updated from P1->P2) > > flush tlb > > > > Then at last from processor side P should have data P2 but actually from > > device memory it's P1. Data corrupt. > > In the above scenario migrate_vma_collect_pmd() will observe pte_none. > This will mark the src_pfn[] array as needing a new zero page which will > be installed by migrate_vma_pages()->migrate_vma_insert_page(). > > So there is no data to be copied hence there can't be any data > corruption. Remember these are private anonymous pages, so any > zap_pte_range() indicates the data is no longer needed (eg. > MADV_DONTNEED). My bad to have provided an example but invalid. :) So if the trylock in the function is the only way to migrate this page, then I agree stall tlb is fine. > > >> > >> When I said I'm not familiar with the code, it's majorly about one thing I > >> never figured out myself, in that migrate_vma_collect_pmd() has this > >> optimization to trylock on the page, collect if it succeeded: > >> > >> /* > >> * Optimize for the common case where page is only mapped once > >> * in one process. If we can lock the page, then we can safely > >> * set up a special migration page table entry now. > >> */ > >> if (trylock_page(page)) { > >> ... > >> } else { > >> put_page(page); > >> mpfn = 0; > >> } > >> > >> But it's kind of against a pure "optimization" in that if trylock failed, > >> we'll clear the mpfn so the src[i] will be zero at last. Then will we > >> directly give up on this page, or will we try to lock_page() again > >> somewhere? > > That comment is out dated. We used to try locking the page again but > that was removed by ab09243aa95a ("mm/migrate.c: remove > MIGRATE_PFN_LOCKED"). See > https://lkml.kernel.org/r/20211025041608.289017-1-apopple@nvidia.com > > Will post a clean-up for it. That'll help, thanks. -- Peter Xu