From nobody Mon Jun 29 16:00:24 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB9F1C433F5 for ; Tue, 8 Feb 2022 07:36:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348310AbiBHHgl (ORCPT ); Tue, 8 Feb 2022 02:36:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348287AbiBHHgi (ORCPT ); Tue, 8 Feb 2022 02:36:38 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05141C0401F6 for ; Mon, 7 Feb 2022 23:36:38 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id h14-20020a17090a130e00b001b88991a305so1330180pja.3 for ; Mon, 07 Feb 2022 23:36:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gKFpQhrIc0qg1OGn2vjlbFux2cfH4pwiDVgfg/+s2Gk=; b=aesHRx4mkuJbzEXODBVC2NuJ3XIEly0uKuZ0fmmOCkbIBaQTKzJFrpHLliZ6LydIDC ZC6nmHSeL7VuMK9rDPMrgXApR4hnw1zY9zkx3KRUddNG14JwZrOt0HceyD46+rolqZSx 5HGsRA4wl3xJql/bNDiaoEcP5SL7tVmEM7fgqxVDJXJ0tBSkiUrnWmm8pAaDWr0inTKH A1TNo7Qo7cAjAJwTEXN/9nx4/YP86wP+m5YLCsjmA9PDo8Zwq+CGiG7a8HGwA1yRkFLt ziW2W/YhD7crzFt9s/t23pfDkgrlu90mkwCSBpAoO68ukfznQJvW2mLcsjBEhGGXcioK 9Gsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gKFpQhrIc0qg1OGn2vjlbFux2cfH4pwiDVgfg/+s2Gk=; b=0pTnWYbbFWfENbH3YyyoPrdG/274BJko2GRHkMb8igfnW+59a+SFE35nxet6ABp8/l LaCFDfOTWVF+kmp15iwM3mhCJmFNWanj22Fx2zUCBp6Eqyr7zkapdGTxegNoJazu7Mhq q/EdCFQHAFpNO6q+gQNyb0lqIE8CzepezOzOqFcK7lQB4JnhfiyurD8FP9aBjUwZgB4V TaMwOWiqF6tqWY7ZkTDVevuf1umPcUh5jLITFrSPdeRQHDVRUWdO851tFKJ8kQ5s3fp9 Bm7jJjxN92rlDuiD7A/1ACfqOvVQJT785MRqHvib4fX1kFvHEBWda6k+B5IXzugzYp2r npMA== X-Gm-Message-State: AOAM533RbWlGouCDymYJQN8irSSiOd5jJeTQ1xuhZsvm9ko282QnX7d8 WrusSnR8am2Naovo2QbgJ9aakg== X-Google-Smtp-Source: ABdhPJzEt4E48DQEs4fdQH9qP/j0O1H1fFoyW4x9658/zRKEKEvOfX+7jWzf6rShGjw7nmSjy1Bt3w== X-Received: by 2002:a17:90a:8904:: with SMTP id u4mr2969489pjn.137.1644305797603; Mon, 07 Feb 2022 23:36:37 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id gx10sm1621017pjb.7.2022.02.07.23.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 23:36:37 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, zi.yan@cs.rutgers.edu, kirill.shutemov@linux.intel.com, rientjes@google.com, lars.persson@axis.com, mike.kravetz@oracle.com, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v4 1/5] mm: thp: fix wrong cache flush in remove_migration_pmd() Date: Tue, 8 Feb 2022 15:36:13 +0800 Message-Id: <20220208073617.70342-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220208073617.70342-1-songmuchun@bytedance.com> References: <20220208073617.70342-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The flush_cache_range() is supposed to be justified only if the page is already placed in process page table, and that is done right after flush_cache_range(). So using this interface is wrong. And there is no need to invalite cache since it was non-present before in remove_migration_pmd(). So just to remove it. Signed-off-by: Muchun Song Reviewed-by: Zi Yan --- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f58524394dc1..45ede45b11f5 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3207,7 +3207,6 @@ void remove_migration_pmd(struct page_vma_mapped_walk= *pvmw, struct page *new) if (pmd_swp_uffd_wp(*pvmw->pmd)) pmde =3D pmd_wrprotect(pmd_mkuffd_wp(pmde)); =20 - flush_cache_range(vma, mmun_start, mmun_start + HPAGE_PMD_SIZE); if (PageAnon(new)) page_add_anon_rmap(new, vma, mmun_start, true); else @@ -3215,6 +3214,8 @@ void remove_migration_pmd(struct page_vma_mapped_walk= *pvmw, struct page *new) set_pmd_at(mm, mmun_start, pvmw->pmd, pmde); if ((vma->vm_flags & VM_LOCKED) && !PageDoubleMap(new)) mlock_vma_page(new); + + /* No need to invalidate - it was non-present before */ update_mmu_cache_pmd(vma, address, pvmw->pmd); } #endif --=20 2.11.0 From nobody Mon Jun 29 16:00:24 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E55A2C433FE for ; Tue, 8 Feb 2022 07:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348320AbiBHHgs (ORCPT ); Tue, 8 Feb 2022 02:36:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348298AbiBHHgn (ORCPT ); Tue, 8 Feb 2022 02:36:43 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B024CC0401F1 for ; Mon, 7 Feb 2022 23:36:42 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id w20so3900756plq.12 for ; Mon, 07 Feb 2022 23:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I/ARb1Au1FcGhHT5OSe5P8uQ767qWIf49sbqK0ZF8no=; b=hIUCyUYTQeWIyj0y3xa/lyJzJfBL9YeIpDkgIOVfa9Clb0wtstmPR610H1IH10cyNC IG+zGUOO/ZeEVHE8BfrdZHeMAPXZJrhPIZ5Fm2Tamk5Xsyp2QOnEPsMIAJkaPCHR1gfa U32l7A+wL1flsdi7qlpHY+HbrTGtygA2afkAodp9Xx4VKZDhbKB5Md2FpFPw1lKz1Us7 lJvwf8JjE0koHnrQ1fNx3hwWEWzZMKQl0hl921uE1+/CB+qidA3V6kqFUA7qx1owiBSo ZKfSFuUUUODfiZlV0CGELceZ3dOxNuZQUzREfn5T/pI5Po6WOrr2dQ3HwuByV8LbMakC SBYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I/ARb1Au1FcGhHT5OSe5P8uQ767qWIf49sbqK0ZF8no=; b=wLFjKP6b304Yl8MRJ0IFGMav8hhbYD5Ql/9zl1GcrE4h2jxhvTRtK7Dmx9vZ92uiXb DPGqOZDAWugGlPfFYIAl+L0tKmQjmAp32Gmkwq89z7Y9JHumN8g/YQ1y2DEKuMmmU+zB B1u0Ae1dEAmNUqvMP4ZOKV24EriN//fhOXyVvX2B9UmnNqI8DWBWPE9ukPyJ01WKi1Am fV9tHclk2fN/An7O3kLsOvIY9XxG16qr7kL7Bc8TWdBjKDNrXCQ16gxN9oYCjPL8A0qK vWi4XtLDiPZN8ArBzpBw4UA07D/ZSkQhhjztjG6vb6LU0WDFdoRLrgj7tDCaOsuuWYT0 Fp+A== X-Gm-Message-State: AOAM532ecybxGDuKs5nZelCI2/ZNyAl9AXxqELBtBDnWKOy7s/AVext6 FWXhDx09R6BglYRjdjZHnJbAyA== X-Google-Smtp-Source: ABdhPJwsZdtiU96OKE7UAsec4IC2Z4kjKKWlUx3J30L+vHnc5YKdB/6S38QvVd5szKB7Y7RVjoAr2w== X-Received: by 2002:a17:902:bf4a:: with SMTP id u10mr3025261pls.113.1644305802222; Mon, 07 Feb 2022 23:36:42 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id gx10sm1621017pjb.7.2022.02.07.23.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 23:36:41 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, zi.yan@cs.rutgers.edu, kirill.shutemov@linux.intel.com, rientjes@google.com, lars.persson@axis.com, mike.kravetz@oracle.com, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v4 2/5] mm: fix missing cache flush for all tail pages of compound page Date: Tue, 8 Feb 2022 15:36:14 +0800 Message-Id: <20220208073617.70342-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220208073617.70342-1-songmuchun@bytedance.com> References: <20220208073617.70342-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The D-cache maintenance inside move_to_new_page() only consider one page, there is still D-cache maintenance issue for tail pages of compound page (e.g. THP or HugeTLB). THP migration is only enabled on x86_64, ARM64 and powerpc, while powerpc and arm64 need to maintain the consistency between I-Cache and D-Cache, which depends on flush_dcache_page() to maintain the consistency between I-Cache and D-Cache. But there is no issues on arm64 and powerpc since they already considers the compound page cache flushing in their icache flush function. HugeTLB migration is enabled on arm, arm64, mips, parisc, powerpc, riscv, s390 and sh, while arm has handled the compound page cache flush in flush_dcache_page(), but most others do not. In theory, the issue exists on many architectures. Fix this by not using flush_dcache_folio() since it is not backportable. Fixes: 290408d4a250 ("hugetlb: hugepage migration core") Signed-off-by: Muchun Song Reviewed-by: Zi Yan --- mm/migrate.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index c9296d63878d..c418e8d92b9c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -933,9 +933,12 @@ static int move_to_new_page(struct page *newpage, stru= ct page *page, if (!PageMappingFlags(page)) page->mapping =3D NULL; =20 - if (likely(!is_zone_device_page(newpage))) - flush_dcache_page(newpage); + if (likely(!is_zone_device_page(newpage))) { + int i, nr =3D compound_nr(newpage); =20 + for (i =3D 0; i < nr; i++) + flush_dcache_page(newpage + i); + } } out: return rc; --=20 2.11.0 From nobody Mon Jun 29 16:00:24 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA84EC433EF for ; Tue, 8 Feb 2022 07:36:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348345AbiBHHgv (ORCPT ); Tue, 8 Feb 2022 02:36:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348336AbiBHHgs (ORCPT ); Tue, 8 Feb 2022 02:36:48 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D318C0401F5 for ; Mon, 7 Feb 2022 23:36:47 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id a11-20020a17090a740b00b001b8b506c42fso1433514pjg.0 for ; Mon, 07 Feb 2022 23:36:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cll0HiNGaOM9yDWI60AkgZZ8Vcgf+tRA3oZc4UBL7nk=; b=y0jpOk6gAkKem1qpuxCydTJQeI0RYuJhd3oYTOoGI39XA5VyoB+ep0jJ6o+P/dV+6o mlwuzoo+SR5YLg3y2a/BC+MJRoaSWHaJ+qAJZb5Y5tHw3Dvyj2R7bsDTORVKf+0aoy9q Jn9P8oSuy9WMEeo5jqDcltiB2MAuJdmewps+UxFLCGBfsHbB4Nz8BgoO7bfS4ookfhRt fJVNLLDP8w7JHk+3AsBSjsnnR7LoF4EmZz1NN9NARpNJUzV4ELzDvSQGQOwb5dl3rKMT pSdNUaU72b0vAJoGUIJ5R22jT7AVOdSonWMx6C0mW3i1zT2otqX9O90SuABNbMer7Tl8 XOnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cll0HiNGaOM9yDWI60AkgZZ8Vcgf+tRA3oZc4UBL7nk=; b=EMmI4hSeQhgLS7yHQ54ESa4ENYmPL7+a5J4MtxJ/fQuud9JqVB5Fk83djHQH9QQe7s GET8/cRI3GT26AkNLOASyn/89Eu5C7WkDqRUA3G/mnRybrU1dOZJRofT5myZAM5ihu5X S83VEyPWp0Juv6NpI5XvFd8t4Fyw7tgZ3O4068unHtsCZfUWQthpHURFoxyesmgEz2Bt k0doIYWh5T4t+Sdh5NCSJ+3gFWbmffg2dJtMdJuAQXwvJXgecGf2X77hO6qa2Wnsav5G IOGI20a3E77hWRRERcBdU0OWE2h8JxNNFN0IUBYqsmn0LhhqrjA8Ic0XVy3kiiKrOZyl Y9bQ== X-Gm-Message-State: AOAM5322HnN/PRPhHTRr89E87sYTunpOzOjuy9+TmPURLNOnYJpFCsj8 u1UV6y2kAtKmjmTUhnHie5h5dA== X-Google-Smtp-Source: ABdhPJzvsh4kBT5/wdRGyGAAQcGNW7TSFAisLlWR6Pe1OtowTbWhv0vQtaLjIv9HxR4IbxCYWBl48w== X-Received: by 2002:a17:902:b90a:: with SMTP id bf10mr3230897plb.36.1644305806765; Mon, 07 Feb 2022 23:36:46 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id gx10sm1621017pjb.7.2022.02.07.23.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 23:36:46 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, zi.yan@cs.rutgers.edu, kirill.shutemov@linux.intel.com, rientjes@google.com, lars.persson@axis.com, mike.kravetz@oracle.com, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v4 3/5] mm: hugetlb: fix missing cache flush in copy_huge_page_from_user() Date: Tue, 8 Feb 2022 15:36:15 +0800 Message-Id: <20220208073617.70342-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220208073617.70342-1-songmuchun@bytedance.com> References: <20220208073617.70342-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The userfaultfd calls copy_huge_page_from_user() which does not do any cache flushing for the target page. Then the target page will be mapped to the user space with a different address (user address), which might have an alias issue with the kernel address used to copy the data from the user to. Fix this issue by flushing dcache in copy_huge_page_from_user(). Fixes: fa4d75c1de13 ("userfaultfd: hugetlbfs: add copy_huge_page_from_user = for hugetlb userfaultfd support") Signed-off-by: Muchun Song --- mm/memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index e8ce066be5f2..eb027da68aa7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5405,6 +5405,8 @@ long copy_huge_page_from_user(struct page *dst_page, if (rc) break; =20 + flush_dcache_page(subpage); + cond_resched(); } return ret_val; --=20 2.11.0 From nobody Mon Jun 29 16:00:24 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0C8EC433F5 for ; Tue, 8 Feb 2022 07:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348351AbiBHHg6 (ORCPT ); Tue, 8 Feb 2022 02:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348333AbiBHHgw (ORCPT ); Tue, 8 Feb 2022 02:36:52 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB365C0401F1 for ; Mon, 7 Feb 2022 23:36:51 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id n32so17430505pfv.11 for ; Mon, 07 Feb 2022 23:36:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/rv2PEt6IIiPLW9lZEeUjxxgQpIiSoXGPYPSbKMenEs=; b=mWirpXFETjjymQb9FwJYTXT9RWcZSQSLT5Nsh/1DBOfuh2Biuy/KM+f9R5CeJIlYYC GDwg8fBYZTDlssF3zNfvwJnkHHLbN9g9hR/k68bwOWP4LlYKrolMPPGjF06x1diK+Vpg Oeq7EOUsr9mUAe81PFskxE4Owu3enMTWXolrKTdSt0ZY2vd98WKWzyNREyikVcUun4xE SyrT606wjX2rhlV21mzXjz0B6XCMwG0ldcYNkSV1MewRFtJ3CeKOt8uPKd04zxFdx6ft e8aAg8sn9SGEQdDo3KLTRL2+fX4oI1DR15XPBg91kF7l+/phcejECxxqPkHZHbrWx/sK 7lKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/rv2PEt6IIiPLW9lZEeUjxxgQpIiSoXGPYPSbKMenEs=; b=Sz6wIAjKTllQtKMOlGo/Z/qmeCGGGCs4DOqmcWuQhYoEksutlioJXZgsx/0fw1m9Zj bmbAwoCa37sLJa0Irz3dXicRuKVZttarzy0uHvGt4WE9ClBUPKytwcqCk9NfjpMQO7Pg gDIb3e/Kwm2u7S7EaGXBZS0L95IC1no0t1Ay9PiFDEDwVbP+RIKuyBBM6ibTeUlxS9eb LzxSAx/ll9GwsDBRXtc24Ut+4TxMxW6gi29D9308tDokt9U2BPVgi+L6kJHKWGaiv6NO 1wyfVsN33hwr6TYHvnpnB+1IQCc5xQln+QjNBWHc7fh/tagpMQISK98exxRd31diUmXx /e9Q== X-Gm-Message-State: AOAM532du9Dhd8RE4VHJaNPGP85CMAN0ijwW9Nbb/1wbKGlixvdP4Gf/ gG11/b8eFvHVI5noMHrlfARhyw== X-Google-Smtp-Source: ABdhPJx5wI1WRTMKEZCVCDQaBQBLj00V8f1A43/kPGwa6KwBioaxK5T2yS6JmK55WW3Uw7U4O59aTA== X-Received: by 2002:a05:6a00:1253:: with SMTP id u19mr3314465pfi.8.1644305811236; Mon, 07 Feb 2022 23:36:51 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id gx10sm1621017pjb.7.2022.02.07.23.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 23:36:50 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, zi.yan@cs.rutgers.edu, kirill.shutemov@linux.intel.com, rientjes@google.com, lars.persson@axis.com, mike.kravetz@oracle.com, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v4 4/5] mm: hugetlb: fix missing cache flush in hugetlb_mcopy_atomic_pte() Date: Tue, 8 Feb 2022 15:36:16 +0800 Message-Id: <20220208073617.70342-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220208073617.70342-1-songmuchun@bytedance.com> References: <20220208073617.70342-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" folio_copy() will copy the data from one page to the target page, then the target page will be mapped to the user space address, which might have an alias issue with the kernel address used to copy the data from the page to. There are 2 ways to fix this issue. 1) insert flush_dcache_page() after folio_copy(). 2) replace folio_copy() with copy_user_huge_page() which already considers the cache maintenance. We chose 2) way to fix the issue since architectures can optimize this situation. Fixes: 8cc5fcbb5be8 ("mm, hugetlb: fix racy resv_huge_pages underflow on UF= FDIO_COPY") Signed-off-by: Muchun Song --- mm/hugetlb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a1baa198519a..eba7681d15d0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5818,7 +5818,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, *pagep =3D NULL; goto out; } - folio_copy(page_folio(page), page_folio(*pagep)); + copy_user_huge_page(page, *pagep, dst_addr, dst_vma, + pages_per_huge_page(h)); put_page(*pagep); *pagep =3D NULL; } --=20 2.11.0 From nobody Mon Jun 29 16:00:24 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 166CBC433F5 for ; Tue, 8 Feb 2022 07:37:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348391AbiBHHhF (ORCPT ); Tue, 8 Feb 2022 02:37:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348375AbiBHHhC (ORCPT ); Tue, 8 Feb 2022 02:37:02 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E66C03FECA for ; Mon, 7 Feb 2022 23:36:59 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id k17so13205244plk.0 for ; Mon, 07 Feb 2022 23:36:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ppq4XlgFUv42e60ZLq/R/m9c3uPkEPmuzaFcdHPRBnk=; b=xVoHJj/4zyPvyg7fneG+v1w0Ib0159bkGEZFF8GmxqGz1GIqJQvjHPPWQUUBQVBWSi yR2SPqfsbh97O8Bk0wkaV2DY7IDHGcuTgyVWO/W/8a0okGQfamKHXNVAIF4if1wm6/w5 iiwk1B4JgZBA4eWoYz+PU1VYZ55CZdIYVNH4J5zSrekqulSmRsmD2G0K+Pf8fVKb53hx t4ihL4kylEoaMDcmJaTJcAiXjkdVmkC43SCUedvI61iLAerc6p8houdOghfe1doOVpQa oubwmMrsU31yjFg4iMICpMtw3IcU5yLSUYRvgyulqzAWcjvp0pMZyUz3r23mxXP1tv2z smFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ppq4XlgFUv42e60ZLq/R/m9c3uPkEPmuzaFcdHPRBnk=; b=SxPdFYuARS+Y/u+Ff++Hpl6LNeRD4WJ6BY8pC4jNohcXVwQ/GXl3RUJ0n3csE0/cy8 w0AmI//Bi480yAoPlZFJOUIkAaYo+AsNqFVDlkAwKhDte2I4Rp9XzVI5uR0rRY0E6hHa a2NdElFv5E/3OBFSlenZfHLrb/5UKogIG9fgZZoR9UtAgGV6MtkEwDcablV7Q0nW8UVg hxON+SqNql07ysst8+AKbeyOwWNFnprxpdRSugvt+6K5ecEJlxjO1cTdbMt9SyrWQaRO XubUHnZQ5/UmHv4BHu3RvzFt/Cdp61Nqz189fN4oHAASlYwxjAWBPjJZKkl7z4PsGcA8 phIw== X-Gm-Message-State: AOAM533ssRfA1kyrIWo+wITw3HSewLVBVI85ZftLK1ACtp80TQ5y8x1S 37THrmuHxSgaZ8PbcH83165goQ== X-Google-Smtp-Source: ABdhPJzNE1tP0FCmJnNbT+MwdBxWiom5QGlNn45IpoyK3Oqddhm8dX950DKcNeuV59Q8o0qQlea8fA== X-Received: by 2002:a17:902:ab06:: with SMTP id ik6mr3065211plb.162.1644305818957; Mon, 07 Feb 2022 23:36:58 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id gx10sm1621017pjb.7.2022.02.07.23.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 23:36:58 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, zi.yan@cs.rutgers.edu, kirill.shutemov@linux.intel.com, rientjes@google.com, lars.persson@axis.com, mike.kravetz@oracle.com, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v4 5/5] mm: replace multiple dcache flush with flush_dcache_folio() Date: Tue, 8 Feb 2022 15:36:17 +0800 Message-Id: <20220208073617.70342-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220208073617.70342-1-songmuchun@bytedance.com> References: <20220208073617.70342-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Simplify the code by using flush_dcache_folio(). Signed-off-by: Muchun Song --- mm/migrate.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index c418e8d92b9c..daf2b3508670 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -933,12 +933,8 @@ static int move_to_new_page(struct page *newpage, stru= ct page *page, if (!PageMappingFlags(page)) page->mapping =3D NULL; =20 - if (likely(!is_zone_device_page(newpage))) { - int i, nr =3D compound_nr(newpage); - - for (i =3D 0; i < nr; i++) - flush_dcache_page(newpage + i); - } + if (likely(!is_zone_device_page(newpage))) + flush_dcache_folio(page_folio(newpage)); } out: return rc; --=20 2.11.0