Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1059918rwe; Wed, 24 Aug 2022 14:11:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR5/4n4rooIAMgiRChE7niikfgjkpZhEJiaVvPs8Crrn8c+lcrBxeU5BQ3ReLc25mf2k31+u X-Received: by 2002:a05:6402:248f:b0:440:9bb3:5936 with SMTP id q15-20020a056402248f00b004409bb35936mr721475eda.178.1661375479767; Wed, 24 Aug 2022 14:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661375479; cv=none; d=google.com; s=arc-20160816; b=Q09nTV/PUm+KGK32/Hooy9vN9C2crFb4LCdCrr+RtXRSfGp+AVYrdsNjD6uFH6pZS/ bl6lX6kYj/VbY/UhMGjbMW7l+4Ko8LfmUt/AQ7pd/7WS1ECO/w1ZclYaCWpGE4+U3NqC X7KkrZy7qeeMXDzg+G4oUFfgWYSSYelrlypOr4uXTPozHQrsNqt3Mog/2lRGJqgbs3eL pokdU4SmOS3Ji5TP+oB606igB92oLbdQkciU4qntjM7Mv1UK/M+SGVc5CmC7UDt70Gus FWfO3zpFG0mJCCEQrzKVA+HaZYLfVS3TUZGy9MJq4x/uPta/K3P030PmTbzgbJvJgwYj f1rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/rRnDONf/MIAcvQvaU+OL/iys5bxrMY05ODAN/aEOnI=; b=iPhcvK10nZ51cH7dJKWN29//HwG+yXroqGxYjyFkuIs0j8kbwEgaWrtXoMaEaa/1UR c00U9eyZdweVpIfCl4Ep7iMrZA5ofMfRImoKfGA84nJGxV0im3NAPL4Pcc1kKTgH9F7D KwAeWAZ2uXwtqvs1RHdaqDG3f64zS3q2rF9+s1ILjA4tLSbgLADRhbxL6YJ25psDf9C9 2LNo3HAyUFFoyU8C3teHzy5exjdFHUOWl0asZnAhgs0c7grDt2YHVXyee9WSxq4mDa4V EUBpsQBnqI4aXbXcDJ/lXbV2wcmYXNmVLGrwfg0Ed71NEXRE3SeMa0tuV1EgmhQvLZ1B DU+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aj/+ET2U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w1-20020a17090652c100b0072a6d845d91si2317415ejn.159.2022.08.24.14.10.54; Wed, 24 Aug 2022 14:11:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aj/+ET2U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240502AbiHXUsr (ORCPT + 99 others); Wed, 24 Aug 2022 16:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240492AbiHXUsp (ORCPT ); Wed, 24 Aug 2022 16:48:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0160C786C9 for ; Wed, 24 Aug 2022 13:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661374123; 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=/rRnDONf/MIAcvQvaU+OL/iys5bxrMY05ODAN/aEOnI=; b=aj/+ET2UnjpBLdj4Z8sxjtg36aqNF85XMtJ6JREFtjObE2EctYcMtdHYVXrsKzTP2orppa pHIwK90PoLNe+1XTWX6XU5UcREmVmLv7BiZRQyXom6GqT1DO7NxRJDFvvHR7iAKArigtU8 MS5VMR6NRj21Dqp1Mt2986CqLAdUbPs= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-225-8-2xqIANN2eg0SV0V9-69A-1; Wed, 24 Aug 2022 16:48:42 -0400 X-MC-Unique: 8-2xqIANN2eg0SV0V9-69A-1 Received: by mail-qt1-f198.google.com with SMTP id s2-20020ac85cc2000000b00342f8ad1f40so13688017qta.12 for ; Wed, 24 Aug 2022 13:48:41 -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=/rRnDONf/MIAcvQvaU+OL/iys5bxrMY05ODAN/aEOnI=; b=6ZPxaY323pxhgsHh/aAm2Cm98n6If6QleAE07CtZBNUtm7ako/6S451HTsGIRLIyAJ Aa0leZ2FFm5bt/dU1Q4TFtnKujZOFCV8OHcjA9fEzhkkNnGGbHrv2VP+S21NmMPixXbH qpVf6bTMlFg86B9v5/NzTjkabKDo921bKimPLuh8yN5GV0cW7EPYT8gDUpV2Ycph2CEd 9x28Yf2KZojF2vwdadDicosM5oaJAePaiFsRyFQdNr4f642OqX1Rp5PMFZ17e5pimS9s BcvHnSntaBQg5ILqFxhrJy+MM2Tpm/qQCXWbMELsxoZMzE8nOq3+oMZWIISe9BO8lj6C 0SXA== X-Gm-Message-State: ACgBeo3CSvrxOExfkkEsnRDtmMiE7FfYlpCQTH/0zd++Lfp4qQg0wvrx bJEQ2mtcKtUGtkglvzCwCwaWzqoPmlV/+gk9Io7/Q4q3QFnAzOIpJnC2rd8kDT+gnB7CYeKVKdj LyXebf++lVMw/ytTIOGR4+WYd X-Received: by 2002:ad4:4eaf:0:b0:496:ac46:2d9c with SMTP id ed15-20020ad44eaf000000b00496ac462d9cmr868924qvb.82.1661374121416; Wed, 24 Aug 2022 13:48:41 -0700 (PDT) X-Received: by 2002:ad4:4eaf:0:b0:496:ac46:2d9c with SMTP id ed15-20020ad44eaf000000b00496ac462d9cmr868905qvb.82.1661374121119; Wed, 24 Aug 2022 13:48:41 -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 g9-20020ac85809000000b00344576bcfefsm13976258qtg.70.2022.08.24.13.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 13:48:40 -0700 (PDT) Date: Wed, 24 Aug 2022 16:48:38 -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: <87o7wjtn2g.fsf@nvdebian.thelocal> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. > > 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? > > The future unmap op is also based on this "cpages", not "npages": > > if (args->cpages) > migrate_vma_unmap(args); > > So I never figured out how this code really works. It'll be great if you > could shed some light to it. > > Thanks, > > -- > Peter Xu -- Peter Xu