Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4007050pxb; Tue, 25 Jan 2022 01:12:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8cwvP8p6HyNQDoE93Wpt2mw3Lc04Bw5xG86vIKU+SP/Xg+ueD9w48SeywePwDZjTm/kSN X-Received: by 2002:a17:902:8509:b0:14b:7484:9ce6 with SMTP id bj9-20020a170902850900b0014b74849ce6mr2212726plb.19.1643101943572; Tue, 25 Jan 2022 01:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643101943; cv=none; d=google.com; s=arc-20160816; b=K3gRnm4ab23+iUqD68cLbq/GRcAie8hbmzWkmxdpWFUKrVE8yU3xbL19v/XDY1udyb za7QIzYIQgBc+VFULZxRYLqGwhhrIFa1UQYRoivNuXeJ2WrnGKTf0OOD1n33nN+guegx K3ATnipmCmHOP8/nme6EJpin+8TpHF2h+sdOhCOji/Fgb9puFFJviFp1AlHhNjnJrK1A 8BaC9W3GkLI4PKj8S9poBxxCYOnG+aWRFBs3zvejIXNTQr4mKr7vgJRn/rvMwp6OUEZ8 KqEP1xpjwWuLBDD4awcYCNpNEpGsBSFepyizXaqsvWx6Wb0owgjaTDnC5G6RDHfZsZqQ GeIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dME7WGjycfCPYxmjYIqrFH1YXeqs+InmpqysLjTPlzM=; b=RiSexaLRzO8RuKr8MdQHUiaETyhpH7uyd3fqDDmIE3fj6OV2kud4ZLQHU6FuPW3uUs Hp6q7HCWlGnOECPeqGT/359sptH0sGa1HgX8hac1N8VTh8Bq8KLqgosCqEUKtJxE1tol v9vVZrjEGcgmRK7pZqS8O1McxKC1RPm6PoSfaJ0qnBLBdQ9GnpGr8MYTdjdMk1WpxtAs 2oN4Er/+TN4UM4nvq9VFPiBw+9K9EPnAFrFTtEwiilXPfO2DCIoAPSccpGmCjuuxmByU ja7j59th77yoSM6AqjsOQusBay+WUDUwspavVmN5cm3HBcxhO2rWX301AznhrZAypaxQ atmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=amYBEOB2; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si513790pfh.105.2022.01.25.01.12.11; Tue, 25 Jan 2022 01:12:23 -0800 (PST) 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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=amYBEOB2; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442948AbiAYHM2 (ORCPT + 99 others); Tue, 25 Jan 2022 02:12:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442568AbiAYHJV (ORCPT ); Tue, 25 Jan 2022 02:09:21 -0500 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0860C0619C4 for ; Mon, 24 Jan 2022 22:02:35 -0800 (PST) Received: by mail-yb1-xb36.google.com with SMTP id k17so3274050ybk.6 for ; Mon, 24 Jan 2022 22:02:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=dME7WGjycfCPYxmjYIqrFH1YXeqs+InmpqysLjTPlzM=; b=amYBEOB2sMOECjGPhfMEQ/UEOLKvNfub12ZZk6Kgde8UISLhPq4P1tKSS/hAze0p9j nQK8P40wup1JaOHr9cpNR8PdlxRSiqyf6zbqlpbP8jTRjj+5Zxjq5qC1BYhFd6XGobq1 wvuQK1Y6HWvKRFS7JckDgPpQ/KCUvYBDwejHVepaDsKNPpdRwME7gDaIlm1ibJY4Uv71 EucJgwOtoNl1GoJUoH5SWV70wr2EDE9STpBxi2NGfryDM7a3IXoulow8sGajQVJoYgzD CZbXO6nmX+RyjSa3++7xyC348NY/OUAYAfSdoUbPmrUMNKmTpbpA9sBTihbzEsH+87xS KtDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=dME7WGjycfCPYxmjYIqrFH1YXeqs+InmpqysLjTPlzM=; b=7rC4WMHRWf5DrVmtYH1GpLarE3SltRJkx0Ow32zfJvaFHvuDk8PgfognNsVTkOpnG4 jlD4lKwaDT/2zyQqrr41as83b+IHIuYWTXZ74kZvFDIckVLH0iJXtzbJlxZ7Oc0h807j p4JmNbP8K+9E/o2S32CxGUdgocsTPQ0FrY67/rtd0flEGBdEmRvfpH5qaqh6NVU/m9oy Atf/DYegvMInJSmcdhkEWVTytmAMlJpunZc/12ikLEApqmPY/dHjSdXRxMxO3CfTAGFk HgLtFPx5r4L+v3rdCOm2tjV9dk4ULcm0UN96WmIT6rda1SBw2r5Um0hRo8DxYTao7ZwY H7Rg== X-Gm-Message-State: AOAM530WPECWn4pEl3sHa2+whjdBD+1W9kVpgNJaVjzTpSr4F0KtlONw RAOwbBgNAea86dbSoV4cC+5KfwOKV+K0sgZGFemOhw== X-Received: by 2002:a05:6902:100c:: with SMTP id w12mr12601077ybt.317.1643090555052; Mon, 24 Jan 2022 22:02:35 -0800 (PST) MIME-Version: 1.0 References: <20220124051752.83281-1-songmuchun@bytedance.com> <20220124051752.83281-2-songmuchun@bytedance.com> <4d5044e7-cac9-b6e6-1467-59ea6010b0f5@google.com> <5D9B52E1-A74B-4964-AACF-ADB91536C4C0@nvidia.com> <7D7EB27F-DEA7-41AA-B24E-B61A2A1A5F07@nvidia.com> In-Reply-To: <7D7EB27F-DEA7-41AA-B24E-B61A2A1A5F07@nvidia.com> From: Muchun Song Date: Tue, 25 Jan 2022 14:01:59 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] mm: fix missing cache flush for all tail pages of THP To: Zi Yan Cc: David Rientjes , Andrew Morton , "Kirill A. Shutemov" , Linux Memory Management List , LKML , Xiongchun duan , Lars Persson , Mike Kravetz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 25, 2022 at 10:42 AM Zi Yan wrote: > > On 24 Jan 2022, at 20:55, Muchun Song wrote: > > > On Tue, Jan 25, 2022 at 3:22 AM Zi Yan wrote: > >> > >> On 24 Jan 2022, at 13:11, David Rientjes wrote: > >> > >>> On Mon, 24 Jan 2022, Muchun Song wrote: > >>> > >>>> The D-cache maintenance inside move_to_new_page() only consider one = page, > >>>> there is still D-cache maintenance issue for tail pages of THP. Fix = this > >>>> by not using flush_dcache_folio() since it is not backportable. > >>>> > >>> > >>> The mention of being backportable suggests that we should backport th= is, > >>> likely to 4.14+. So should it be marked as stable? > >> > >> Hmm, after more digging, I am not sure if the bug exists. For THP migr= ation, > >> flush_cache_range() is used in remove_migration_pmd(). The flush_dcach= e_page() > >> was added by Lars Persson (cc=E2=80=99d) to solve the data corruption = on MIPS[1], > >> but THP migration is only enabled on x86_64, PPC_BOOK3S_64, and ARM64. > > > > I only mention the THP case. After some more thinking, I think the Huge= TLB > > should also be considered, Right? The HugeTLB is enabled on arm, arm64, > > mips, parisc, powerpc, riscv, s390 and sh. > > > > +Mike for HugeTLB > > If HugeTLB page migration also misses flush_dcache_page() on its tail pag= es, > you will need a different patch for the commit introducing hugetlb page m= igration. Agree. I think arm (see the following commit) has handled this issue, while= most others do not. commit 0b19f93351dd ("ARM: mm: Add support for flushing HugeTLB pages.") But I do not have any real devices to test if this issue exists on other ar= chs. In theory, it exists. > > >> > >> To make code more consistent, I guess flush_cache_range() in remove_mi= gration_pmd() > >> can be removed, since it is superseded by the flush_dcache_page() belo= w. > > > > From my point of view, flush_cache_range() in remove_migration_pmd() is > > a wrong usage, which cannot replace flush_dcache_page(). I think the co= mmit > > c2cc499c5bcf ("mm compaction: fix of improper cache flush in migration = code") > > , which is similar to the situation here, can offer more infos. > > > > Thanks for the information. That helps. But remove_migration_pmd() did no= t cause > any issue at the commit pointed by Fixes but at the commit which enabled = THP > migration on IBM and ARM64, whichever came first. > > IIUC, there will be different versions of the fix targeting different sta= ble > trees: > > 1. pre-4.14, THP migration did not exist: you will need to fix the use of > flush_dcache_page() at that time for HugeTLB page migration. Both flushin= g > dcache page for all subpages and moving flush_dcache_page from > remove_migration_pte() to move_to_new_page(). 4.9 and 4.4 are affected. > But EOL of 4.4 is next month, so you might skip it. > > 2. 4.14 to before device public page is removed: your current fix will no= t > apply directly, but the for loop works. flush_cache_range() in > remove_migration_pmd() should be removed, since it is dead code based on > the commit you mentioned. It might not be worth the effort to find when > IBM and ARM64 enable THP migration. > > 3. after device public page is removed: your current fix will apply clean= ly > and the removal of flush_cache_range() in remove_migration_pmd() should > be added. > > Let me know if it makes sense. Make sense. Thanks.