Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4324157rwb; Tue, 16 Aug 2022 20:00:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4zHNmEIMahqidCV+yeCIFI2yhJeSWGqBD1bbzFlvHMzXKHV4zAtG2KBEbTsUKG/pL0PKO/ X-Received: by 2002:a17:90b:3e8b:b0:1f5:8706:18a1 with SMTP id rj11-20020a17090b3e8b00b001f5870618a1mr1691549pjb.112.1660705234539; Tue, 16 Aug 2022 20:00:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660705234; cv=none; d=google.com; s=arc-20160816; b=QwkfCcwk70CI69lbXJBYMWzg++GXIrSKyXBA4BOZWmlJSg5xSUFaNRYuF7D4fcoabh LZMPvNX5NSvNg3IgRkf2fXINqgEH5H8AN39BDzd96iq26ZGHDXWbngpF6805ia2Yxdct fOtTLc6bUnPapbL7xLymAKCL5kTvwR8RaX7JfFf+TEDD4+fDZlS7egs9uLjJKFQ++9hV 6tBJpb+GN/pKso8umatuiLLMCdt5MIaLrubx8oYtKYs6zgXwI+co4Qszy1N3H/IXLGeh LE2YrTipSsIFZZohpE5eMcToCkrVs69LrYChXptHT2g8hZNau6agH5c9d0khHyzpIPIV 6oow== 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=sFFVgLR/Ut+q9B0hkN4LXK9LXiRNRRxKcE0ZSUfZXQc=; b=tDtjznH4jyWeotGponmDqwbEL6Qo5VnTkltWplVgb+Ac378lGtbSdLC2v2S73enXM0 QpJrwCmUKOWxWxU/uTwKCEwHCZHZ6nnolU1u03lN3JE7QDjbdfHaUku2ERVYjgrPxnoM 2f5FQo8lgIMM9gNfpByGLy7p5IUw7fDwMqhGtgvmjV4qEtnZH+e2FqFHJkvFP14qQHjl vW6uvvVAL4DFW4Psf7gWwlhwNFf7qDgIqmbeYOx5fvaC2U2Y+5+duht8w+TytSTQhimO e0t8QvDGAgEA6InyKa2Cw2FOOZCOJ6YHew0FTMSbWisLcxMqL1VfrFzeajXptWeOj8Uq 11xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=igBR8u9I; 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 me10-20020a17090b17ca00b001f2332335c2si770747pjb.133.2022.08.16.20.00.23; Tue, 16 Aug 2022 20:00:34 -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=igBR8u9I; 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 S238303AbiHQCpp (ORCPT + 99 others); Tue, 16 Aug 2022 22:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238272AbiHQCpo (ORCPT ); Tue, 16 Aug 2022 22:45:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CFF376440 for ; Tue, 16 Aug 2022 19:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660704341; 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=sFFVgLR/Ut+q9B0hkN4LXK9LXiRNRRxKcE0ZSUfZXQc=; b=igBR8u9IhUYcHwo5l1rjuJfd2rcU5ceZRs3Qp1ncSYfPTyixtv34Ch0k2xoMln+3l+R28N D31pbiAHOaXoKgMS3UVUbxJ42LFMZALnE2ySckpRILTsKugI8yMHPTxFrEEVQzt8jaVMeU WjvsMmQ/UqDcpZKSSQWEMcbOeqz+Vqk= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-442-8qdMojSqPE6ScwMvFI54Ew-1; Tue, 16 Aug 2022 22:45:40 -0400 X-MC-Unique: 8qdMojSqPE6ScwMvFI54Ew-1 Received: by mail-qv1-f72.google.com with SMTP id d10-20020a0cf6ca000000b00496744bc8e6so777387qvo.2 for ; Tue, 16 Aug 2022 19:45:40 -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=sFFVgLR/Ut+q9B0hkN4LXK9LXiRNRRxKcE0ZSUfZXQc=; b=0kzIKMTHGRzABnPfwoxZ4PaIi2FooU/rQiaihS8rzAjvSHd6F+7YWUE6Fv6BT4JXi0 yzH9xVdA4+EhMuu5Y+7vmDJMXGDWO0QtJsftYC1zi8aKhiZZR21V5IvjSPQyzO5Q0fT/ afQqjwyB4NvNdTIsfFKP5r6U1b9iVaa6b1EHimAV0sF3MX5WtGO1EVYqT5BAcL6eb3L3 eouJOrP31kA34kaWdEcaUY04XvFVyosFeIxZaI7PC/PRB6rCfYvS82Zu15iQGBgEJX7i 7qH0//p8xUG/ZGOt+WvJk922gjZAz+sSIIwZ3RLhR8bClnJYZDyyh3hsDx/urUmvjy3i 5A9Q== X-Gm-Message-State: ACgBeo3WQpnImlMdNvlppGBI/9JCSCkAqsDQNU45AWPFKn/m+GM8RQoY nx7RJA8hkfdLwDiJIaKLCN8Mb5hZJqWlDUxW5lc0vTldiyJNfT4KR2oCwKvX7I5GRmzA/IVDJty zyFQfJbVWeSQFP4uwXdZZ7uIU X-Received: by 2002:a37:64c3:0:b0:6ba:f404:8ff2 with SMTP id y186-20020a3764c3000000b006baf4048ff2mr12451570qkb.397.1660704339576; Tue, 16 Aug 2022 19:45:39 -0700 (PDT) X-Received: by 2002:a37:64c3:0:b0:6ba:f404:8ff2 with SMTP id y186-20020a3764c3000000b006baf4048ff2mr12451556qkb.397.1660704339333; Tue, 16 Aug 2022 19:45:39 -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 w17-20020a05620a0e9100b006bb568016easm4148710qkm.116.2022.08.16.19.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 19:45:38 -0700 (PDT) Date: Tue, 16 Aug 2022 22:45:37 -0400 From: Peter Xu To: Alistair Popple Cc: huang ying , linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "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, Huang Ying , stable@vger.kernel.org Subject: Re: [PATCH v2 1/2] mm/migrate_device.c: Copy pte dirty bit to page Message-ID: References: <6e77914685ede036c419fa65b6adc27f25a6c3e9.1660635033.git-series.apopple@nvidia.com> <871qtfvdlw.fsf@nvdebian.thelocal> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <871qtfvdlw.fsf@nvdebian.thelocal> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 17, 2022 at 11:49:03AM +1000, Alistair Popple wrote: > > Peter Xu writes: > > > On Tue, Aug 16, 2022 at 04:10:29PM +0800, huang ying wrote: > >> > @@ -193,11 +194,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, > >> > bool anon_exclusive; > >> > pte_t swp_pte; > >> > > >> > + flush_cache_page(vma, addr, pte_pfn(*ptep)); > >> > + pte = ptep_clear_flush(vma, addr, ptep); > >> > >> Although I think it's possible to batch the TLB flushing just before > >> unlocking PTL. The current code looks correct. > > > > If we're with unconditionally ptep_clear_flush(), does it mean we should > > probably drop the "unmapped" and the last flush_tlb_range() already since > > they'll be redundant? > > This patch does that, unless I missed something? Yes it does. Somehow I didn't read into the real v2 patch, sorry! > > > If that'll need to be dropped, it looks indeed better to still keep the > > batch to me but just move it earlier (before unlock iiuc then it'll be > > safe), then we can keep using ptep_get_and_clear() afaiu but keep "pte" > > updated. > > I think we would also need to check should_defer_flush(). Looking at > try_to_unmap_one() there is this comment: > > if (should_defer_flush(mm, flags) && !anon_exclusive) { > /* > * We clear the PTE but do not flush so potentially > * a remote CPU could still be writing to the folio. > * If the entry was previously clean then the > * architecture must guarantee that a clear->dirty > * transition on a cached TLB entry is written through > * and traps if the PTE is unmapped. > */ > > And as I understand it we'd need the same guarantee here. Given > try_to_migrate_one() doesn't do batched TLB flushes either I'd rather > keep the code as consistent as possible between > migrate_vma_collect_pmd() and try_to_migrate_one(). I could look at > introducing TLB flushing for both in some future patch series. should_defer_flush() is TTU-specific code? IIUC the caller sets TTU_BATCH_FLUSH showing that tlb can be omitted since the caller will be responsible for doing it. In migrate_vma_collect_pmd() iiuc we don't need that hint because it'll be flushed within the same function but just only after the loop of modifying the ptes. Also it'll be with the pgtable lock held. Indeed try_to_migrate_one() doesn't do batching either, but IMHO it's just harder to do due to using the vma walker (e.g., the lock is released in not_found() implicitly so iiuc it's hard to do tlb flush batching safely in the loop of page_vma_mapped_walk). Also that's less a concern since the loop will only operate upon >1 ptes only if it's a thp page mapped in ptes. OTOH migrate_vma_collect_pmd() operates on all ptes on a pmd always. No strong opinion anyway, it's just a bit of a pity because fundamentally this patch is removing the batching tlb flush. I also don't know whether there'll be observe-able perf degrade for migrate_vma_collect_pmd(), especially on large machines. Thanks, -- Peter Xu