From nobody Mon Jun 29 23:08:12 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 9F343C433EF for ; Mon, 31 Jan 2022 16:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380000AbiAaQEM (ORCPT ); Mon, 31 Jan 2022 11:04:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379998AbiAaQEG (ORCPT ); Mon, 31 Jan 2022 11:04:06 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 600ABC061714 for ; Mon, 31 Jan 2022 08:04:06 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id h12so14432566pjq.3 for ; Mon, 31 Jan 2022 08:04:06 -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=3P2GhQ/A4jZ2vY4MofmwB/at+DQmKpJSp18e9dRfwe4=; b=5URQXSWgeqQ7mckfU4C9lY/dFwxZNhRwVpHK8PF66Zds0N3U5nsrMNbagre+kYdnct +7o8S/vRwiYT6Zw3piBgSLEXOeagAuCSSDt5bYZ8PiiQ1WiJOzuLDBf9kGZ2xrU0DFCI Bj4Qz09SgZvWc8iA9F5vFDGmETHPkYnDxkCsLa8nhEgbbBi5icdAE1eLXYLBh8ZXnLJ1 MjO8vyzTyf6I6AAfmVEXkPHMyN5hET/0/8R3vtzopEPjnTYAD6MjTm+ZVCnuHucvkzT9 R2JPwM4NUEFLkb5Pavb8ubGKAM7YnFbERMPEt5PE/HE28UvrKKlT8px8uUdqmOm8J+sK zXFA== 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=3P2GhQ/A4jZ2vY4MofmwB/at+DQmKpJSp18e9dRfwe4=; b=bTsy8EGok8mo+EWYw1qsDBl26IQqjl1NPgJQ+LaoRs2j5omTD+MTpT0xhXXtqlsqF4 4jqW/BuMclquTGAoIuSuCl9rPnTbkyWLvzkPcUYCrKI9DVmnrrGQAi5Ji5NLE1Y29NXT 2b6A0YCV0O7+/GbZ5k/fO053zu2m7DSutjUP/4gUnd7I2BAD3i2v7q+/Wmx1PaNJndGu y2rL/U44Kzu4Y6pOmbsGL1PQtLmNa5B4Jn5c/XNH5zbY2CXguIL5brUW8+FS91npI4OU DLrHBjAPo+W1LG19BpZxOSKk4jKXPviUGQpzpYMmRQXUyogMhfjU0pJYbaLDbaqDWVgw Be7w== X-Gm-Message-State: AOAM531WtnAm4bNHecTCFrx9/fQmEHzUPVYosPT0b8rlvm1yTCyzcoao tIJVF9cctK19I8qOnpCACPUCUQ== X-Google-Smtp-Source: ABdhPJx+s3Ymv7b02lJg4vX/CGJvKlKxbU1nqbdkqUMa4X7q/ZoBsG0DOzq5OgBQhaDtJj5SKTVUgQ== X-Received: by 2002:a17:902:ea06:: with SMTP id s6mr20895751plg.161.1643645045966; Mon, 31 Jan 2022 08:04:05 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id n42sm17940716pfv.29.2022.01.31.08.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 08:04:05 -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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, Muchun Song , Zi Yan Subject: [PATCH v3 1/5] mm: thp: fix wrong cache flush in remove_migration_pmd() Date: Tue, 1 Feb 2022 00:02:50 +0800 Message-Id: <20220131160254.43211-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220131160254.43211-1-songmuchun@bytedance.com> References: <20220131160254.43211-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_page() is supposed to be justified only if the page is already placed in process page table, and that is done right after flush_cache_page(). 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 23:08:12 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 A1345C433FE for ; Mon, 31 Jan 2022 16:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380007AbiAaQEN (ORCPT ); Mon, 31 Jan 2022 11:04:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380002AbiAaQEL (ORCPT ); Mon, 31 Jan 2022 11:04:11 -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 7AD61C06173E for ; Mon, 31 Jan 2022 08:04:11 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id oa14-20020a17090b1bce00b001b61aed4a03so12959145pjb.5 for ; Mon, 31 Jan 2022 08:04:11 -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=iQH5onptg6s877J45y8Fks8F6bmcOMzezi8xj98jFE4=; b=EastST5ZIcLSESMsp5gzxuTqcCSNgh5+VOlWEXH6hIDH/Y+6Yi35lcJ+cnIcbEKd7m ys4Lc9gV7R1lfGNhqxJc+0ZWjEjrfRAh03XbwNQJ53zVIlzmP/zQztsQ3zILrR4XJDYD rdDAzYkP/5wsiH5bx7EUldm57nS/S/pVfNhfrTxu0WxmmGgw9Ah3xuHFcL6fj+0NqSGV ZkvPlQ/0AC4dX++DpJqmn/6luHcfdGPKTHwysX/OSTavRqfsce1g9gsT8z2fFQGeXmvM CrHvh4ovORh0oE2mshQS/a7a4kDp+bt1wsKPtyuevVZy/noM5LRw2Sk8WpFt2yMPhny8 JFnQ== 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=iQH5onptg6s877J45y8Fks8F6bmcOMzezi8xj98jFE4=; b=5nBzFdGIklv+1uAaoEpDMPP452gIdO5lWOunxh5G7SajaHj0/qnSh5nL7HTfgkROOo L+SiTYCug7suo/Dh3ysEErUo6b5CxCXcWqNPN2EcgRIKCSy9la8vg1k8k21mwT6jJlt+ jCZUZnrlbo5AtpuPOPspEKHw7RGoVzSxtSa+w9nIF6IEHLaTyuBlr3d5fD2o4eeY1ekY uSUKm84ziV+waqluvk8iqQBX4OPTra3eLm0uJ9p3yGgn6R+UfpD6rRwDkN825UFjK5c4 B+R6RMG70C0DNxMlSvlu4ELqwWRNIqoup0uPiORTO8edTYBb5J+FteXb0/u6zR6BYGuD ul6g== X-Gm-Message-State: AOAM530nGiVnlu5GkQBURvNlLd/nHn0iLHwwtQaJYDx789Jac4LqzmwG 7s6wN6EagPratD33YNVuaD+NOg== X-Google-Smtp-Source: ABdhPJyKqjzk6JU+7cZI+lIZKz8qJV0tOrsdnXMJaAquGWsMKIiUnglaRbBHuWSf5yL2XPDGOcbabQ== X-Received: by 2002:a17:90b:1952:: with SMTP id nk18mr34913304pjb.101.1643645051035; Mon, 31 Jan 2022 08:04:11 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id n42sm17940716pfv.29.2022.01.31.08.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 08:04:10 -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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, Muchun Song , Zi Yan Subject: [PATCH v3 2/5] mm: fix missing cache flush for all tail pages of compound page Date: Tue, 1 Feb 2022 00:02:51 +0800 Message-Id: <20220131160254.43211-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220131160254.43211-1-songmuchun@bytedance.com> References: <20220131160254.43211-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. In theory, the issue can be found on arm64 and powerpc. 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: 616b8371539a ("mm: thp: enable thp migration in generic path") 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 23:08:12 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 2F947C433EF for ; Mon, 31 Jan 2022 16:04:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380041AbiAaQEY (ORCPT ); Mon, 31 Jan 2022 11:04:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380022AbiAaQEQ (ORCPT ); Mon, 31 Jan 2022 11:04:16 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61AFAC06173D for ; Mon, 31 Jan 2022 08:04:16 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id b1-20020a17090a990100b001b14bd47532so14329326pjp.0 for ; Mon, 31 Jan 2022 08:04:16 -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=kqcwDry5uO65hxuBb6yCzUOH/a1vV6vXhHnghWYmZE0wFwKVg4sDSVN/IFdkti1vxa gH7qY1qLoeC+cKiFHLrznIF/YZZj/5AhGagvceyAcyEcWWJMLsMqThARBDdu+bmGE+PX x6nXbH2i4BHnV1zU3rPxoNPPkey5wfOwbpO2l++PZiNesvMkQiFad2sph+apeltel7aQ Ls1SJTkFiJ4YqR9pdlN4r7l0tC31BgRrY8AyIlvoJPiUU/g7awJtPbivAom+ouD7h5rh 4fLe2DLqgbdp4M3crNsgRcakjECmczJ67k4TbCKpIhxWYZao52P3BXYCUZuUbN4s2YZS rVFQ== 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=fezs+C/vgRqwUAku6nRDBAmYFsbng5TxQz5PuaWDPYO2JSswCN4498K5j1pSKy9ei8 SUkAE/ghsKMBL2UcnfcF6iF2CqbUYeSRK+R8K5L1RYdJjFSIqeC42QNPsFEFZK+gzYJG DE1ra8Plt4qgIqWaE6/bvihjd5so8qBSUPz7DK3uDCEP+TQo395zFmOOP7BJrmsEO2Jx 8jMPL5PqTFohIoBJ2ld5KOhcKAqkAXg7rXpFv5WM3mG/f+H8TTC06CZP44wc2m4SrToc pI713wBgmj3K5LktJt2LxFzCy5TL/4IebyOGYQLJYzIMydgTcBZ4kdfkHJuX7nEmRo0R QQgw== X-Gm-Message-State: AOAM533+A4vnwfGGTPzXl9aGBvl9KoHXnPP4TeP0rn7XcfKfgV5AH9Pg 7/SIj3lCQPqxoTah5Cc4xhwtIw== X-Google-Smtp-Source: ABdhPJxZJ+tEgViLwu3F1PuG3ikPoO/2NiO4jJZJUhCFbhH2t+GN/XLwxc/o0L5yrU9nizfHfRLOTw== X-Received: by 2002:a17:902:e788:: with SMTP id cp8mr21004336plb.172.1643645055966; Mon, 31 Jan 2022 08:04:15 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id n42sm17940716pfv.29.2022.01.31.08.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 08:04:15 -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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, Muchun Song Subject: [PATCH v3 3/5] mm: hugetlb: fix missing cache flush in copy_huge_page_from_user() Date: Tue, 1 Feb 2022 00:02:52 +0800 Message-Id: <20220131160254.43211-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220131160254.43211-1-songmuchun@bytedance.com> References: <20220131160254.43211-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 23:08:12 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 92C6BC433EF for ; Mon, 31 Jan 2022 16:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380027AbiAaQEa (ORCPT ); Mon, 31 Jan 2022 11:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380010AbiAaQEU (ORCPT ); Mon, 31 Jan 2022 11:04:20 -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 B8E65C061714 for ; Mon, 31 Jan 2022 08:04:20 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id oa14-20020a17090b1bce00b001b61aed4a03so12959735pjb.5 for ; Mon, 31 Jan 2022 08:04:20 -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=pht+u875/nHbiyfmnh2sHRDlYx7sxAKFTWEwLAeL/xQ=; b=asLzFLOtnhAt1wJ9MkFxljPA6I+O9Q3lLsoNk3YTh57vC01yj731U/WEvoQVHChNPv YmPjjWrQVJpd+K5pDqdHk7/Ga+moURiIO0F5YaZp2iEYDbWl0QhBcftDlCDJhERdof// PW6WNKKdyMCNG87pMWXQV+Aj5f9tKti/Uvg/D9Wcjem4fI1UyGOCMPBdSppQhkr2Ans4 8DD/GaoXJkl+gHf4awk75ojdsvXeezRplz7byycXAAk4SvhrjmCccOlB4PEkINoxtgCS pcbaOJ6CDCAdwhYM/2vh/kAdKvw3Di51GKUxoUc0E6zOEe5QRkyjCHdmC4Ro5wuy+yXh 4Bhw== 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=pht+u875/nHbiyfmnh2sHRDlYx7sxAKFTWEwLAeL/xQ=; b=xvlrhjE2LSNMUwi20triwBDxotMT9CJ920lPMiMz3XCGvUNHFwk0vv/La54xwP5Skm YTJRuF7UuVmxRFZzPGibuUFCqz/heFzTFHC6UiUZlL0jQD0LMmJcp1/0Epu7R7YNjT5z zZamfk3Z2zGoVlqpZKjgig2SoQHTa3qHcXETUfCrrFH7pAfCdvCqRE93/82kfQ+1Dtlp sJ2VsRc4O1MX6xFOHyU+3DQuBJXRXw0bElMoP2IzcfkUdaSYBzBB3vKxAsf9aqlUCcuk PPIWFR/IFDiEJxZmwNCHxfcU7LX4Rt33CN8qRJD61C44ecwA7o1cGWgE2PpILmwqjaXa n5/Q== X-Gm-Message-State: AOAM533SMAHjrywNVzEIjyEOQHUYJnMakBkNomO2zeY0ec7IjRTHGPsK W3+TsEzNmYEznvqG7jQzEhwJyg== X-Google-Smtp-Source: ABdhPJxtq4AiRBDI6E+iaufhjEeklExYl8CNg78gPPyn/nVhJ3VlwPpiHVau25255hprz6v62IPy1w== X-Received: by 2002:a17:902:8213:: with SMTP id x19mr18163640pln.150.1643645060156; Mon, 31 Jan 2022 08:04:20 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id n42sm17940716pfv.29.2022.01.31.08.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 08:04:19 -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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, Muchun Song Subject: [PATCH v3 4/5] mm: hugetlb: fix missing cache flush in hugetlb_mcopy_atomic_pte() Date: Tue, 1 Feb 2022 00:02:53 +0800 Message-Id: <20220131160254.43211-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220131160254.43211-1-songmuchun@bytedance.com> References: <20220131160254.43211-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. Fix this issue by flushing dcache but not use flush_dcache_folio() since it is not backportable. Fixes: 8cc5fcbb5be8 ("mm, hugetlb: fix racy resv_huge_pages underflow on UF= FDIO_COPY") Signed-off-by: Muchun Song --- mm/hugetlb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a1baa198519a..f1f1ab31dc8a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5804,6 +5804,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, goto out; } } else { + int i, nr; + if (vm_shared && hugetlbfs_pagecache_present(h, dst_vma, dst_addr)) { put_page(*pagep); @@ -5819,6 +5821,9 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, goto out; } folio_copy(page_folio(page), page_folio(*pagep)); + nr =3D compound_nr(page); + for (i =3D 0; i < nr; i++) + flush_dcache_page(page + i); put_page(*pagep); *pagep =3D NULL; } --=20 2.11.0 From nobody Mon Jun 29 23:08:12 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 6220BC433F5 for ; Mon, 31 Jan 2022 16:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380075AbiAaQEe (ORCPT ); Mon, 31 Jan 2022 11:04:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380052AbiAaQEZ (ORCPT ); Mon, 31 Jan 2022 11:04:25 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75DB4C061741 for ; Mon, 31 Jan 2022 08:04:25 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id o16-20020a17090aac1000b001b62f629953so11323274pjq.3 for ; Mon, 31 Jan 2022 08:04:25 -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=gisX+SmHlGPaod6BmlULNl1QqGpeThEpw2gv3Ed6fPs=; b=5Kju0dWpSHwXhYEWvUiml8KB/0ZMWI8SxY+Qz6NYPYq89/Rcn6kjtmlsEGtAmVwJoV 7UHjH692hPcUl3swiilP52F9+cY+ioBqdsilrfv8fyAr3nyRomOfaJ0DgIobtvOYXmHa xLVYYwa1pYNhqIDLyrj0GVbQc089q2E3TI/YbhKZr3Nuv66N5mnCSnrH1ZEbKxM/KuF/ 8m3792ODuO8Q2a+VlrTtC4n0FkTsRVP7BJ8Fy1Xj7Z0KimoGrsiJHh9CIAD4fClr/mi0 a7ZMNNBfQr2jcIC63VZUkaEmE2I8HeG3ec7oLHCYwwu/Srwvs59VWyFub+A/ec54/yny 4qxw== 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=gisX+SmHlGPaod6BmlULNl1QqGpeThEpw2gv3Ed6fPs=; b=o2bESRfUjcuOoP6CwkbfuIQ0czEQcD2XU4Na0cyAQS/UTkZlM7hlH4ySa1rQCIFwPT CvYW1GsIbH0RW6ovyyOTtIVn/MSo8M23ZJZQhf89PgaN9eTXcRLePAeu2Is5vZ3h+khf caMDXnieEZ0F4fVm/H0mJ7jsToxjUBjTJywOvOOf6bSrGYZY+2Hnvvc9ygpGKDr7ei3n SCJNiWTZPxGhykWE+M5o1V/tYQzNrj+arbcEBf44vKFGYC8B5onBxxPGNznEHMXAHr0J OyKuGZdBF6PhDXA1mPd4LEoKopW19/lzX3+WS0k4Am52TiFJ6/km05lJzC1AkT613CM1 6nIA== X-Gm-Message-State: AOAM532ClVQ71Pf0LQHtorYoWtiqI9qBNoBl+73TIxQCgk6949GQfhWF mGtko9+4O/Pomt9NpTj18NR6aw== X-Google-Smtp-Source: ABdhPJwnOHSIH/tVeMiDIsL5x0suj1BcB23ljOBPvIUrK1xrla1SShg+QsGbaZcLU6k68TnfcGxnWQ== X-Received: by 2002:a17:902:d2cf:: with SMTP id n15mr20697725plc.33.1643645065059; Mon, 31 Jan 2022 08:04:25 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id n42sm17940716pfv.29.2022.01.31.08.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 08:04:24 -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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, Muchun Song Subject: [PATCH v3 5/5] mm: replace multiple dcache flush with flush_dcache_folio() Date: Tue, 1 Feb 2022 00:02:54 +0800 Message-Id: <20220131160254.43211-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220131160254.43211-1-songmuchun@bytedance.com> References: <20220131160254.43211-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/hugetlb.c | 6 +----- mm/migrate.c | 8 ++------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f1f1ab31dc8a..828240aee3f9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5804,8 +5804,6 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, goto out; } } else { - int i, nr; - if (vm_shared && hugetlbfs_pagecache_present(h, dst_vma, dst_addr)) { put_page(*pagep); @@ -5821,9 +5819,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, goto out; } folio_copy(page_folio(page), page_folio(*pagep)); - nr =3D compound_nr(page); - for (i =3D 0; i < nr; i++) - flush_dcache_page(page + i); + flush_dcache_folio(page_folio(page)); put_page(*pagep); *pagep =3D NULL; } 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