From patchwork Thu Feb 10 12:30:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741872 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4383DC433F5 for ; Thu, 10 Feb 2022 12:37:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB9306B0074; Thu, 10 Feb 2022 07:37:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B3EC16B0075; Thu, 10 Feb 2022 07:37:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DFAB6B007B; Thu, 10 Feb 2022 07:37:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 9161F6B0074 for ; Thu, 10 Feb 2022 07:37:26 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 6A97F1214D4 for ; Thu, 10 Feb 2022 12:37:26 +0000 (UTC) X-FDA: 79126820892.01.33F7818 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf10.hostedemail.com (Postfix) with ESMTP id 13EBFC0004 for ; Thu, 10 Feb 2022 12:37:25 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id m7so5073987pjk.0 for ; Thu, 10 Feb 2022 04:37: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=gKFpQhrIc0qg1OGn2vjlbFux2cfH4pwiDVgfg/+s2Gk=; b=JjFFmiBFFspTkoWluz4Y/2OhOC+2cDtbHwUi6Z8G3s5O6jLaI4K+hCvdUcs90RTnTb VZzbBD0KpisBRj8k0XTR/DImFMEN6lbYnM9WDekRGuOQXnKm5v/KFFCA1wP7yp5PeI0v C+DYAamNxNXL8z4lSF6NDBsFbDFTsDn5cWDibf8rPJgyTMdpR/aegPTr3LScOIw320ZH sqJSZSjApl195zpCodCKCZUZ3KK2Il7lDKn9IX13DkmKxsDDQPAnQ+a9yOjE2qFn5wCo RCS7uBuIFUpHMKaPGF2+nbn7Z+voZtzaqSo80Xtu69Fr9csc3qXRTPKMyfc2amzuhODn LyZA== 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=lwZtCgpwySgy6Pnj0CjCqDu7XgtUJGKnBSEFl4GiwhkgM/jk1XS/zOGJ8Nc0RuSzvN W5eh92VVPHI2njbv0v8KU6xV5i/aEyJ4jWPuODQnuQ4kCqLs7OPmcijJ0DZiyxEVmUyI ba3TFTRl4OT0SOE101yhHB+lOFmn8CqJH6ip26RAkHxXVoIunfIGrNGBhW8wXVGDT7i0 z5SzWJOQzaF8RsaGqvPVYa9BCdVL3UDXIumtKmF3WwLvarAfjKRs85gFhbEXKgvFwel0 gfL4+I2EkhnHNVE642wX8hK3XFvkcscxzHcLQW9nG6cTf0Fu7vSDWq7M90bY0iNghYRO NoIw== X-Gm-Message-State: AOAM530sJsbS0ZSMXbMIHEgcbgpNpeb5Xp/VF2/fLzTH0f6pDFk2A571 ztXwz+IbNaNyDOge84+WUA2fOw== X-Google-Smtp-Source: ABdhPJzv8qdSlKpXUXZEnltPAAV/8T3YIxP2tHLDjv5DmIpbC3EC8oCGfwcWkp6oBYuakLpHJH3riQ== X-Received: by 2002:a17:902:cf0c:: with SMTP id i12mr7387028plg.64.1644496645014; Thu, 10 Feb 2022 04:37:25 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37: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, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v5 1/7] mm: thp: fix wrong cache flush in remove_migration_pmd() Date: Thu, 10 Feb 2022 20:30:52 +0800 Message-Id: <20220210123058.79206-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=JjFFmiBF; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf10.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: 66t96amxujh4wpp9cntenj8oc7suypi4 X-Rspamd-Queue-Id: 13EBFC0004 X-HE-Tag: 1644496645-363382 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 = pmd_wrprotect(pmd_mkuffd_wp(pmde)); - 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 From patchwork Thu Feb 10 12:30:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741873 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 381B8C433EF for ; Thu, 10 Feb 2022 12:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E1516B0075; Thu, 10 Feb 2022 07:37:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 990826B007B; Thu, 10 Feb 2022 07:37:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88BC56B007D; Thu, 10 Feb 2022 07:37:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id 7A4806B0075 for ; Thu, 10 Feb 2022 07:37:31 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 33A14181F6CB5 for ; Thu, 10 Feb 2022 12:37:31 +0000 (UTC) X-FDA: 79126821102.29.2268B59 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf04.hostedemail.com (Postfix) with ESMTP id D141340007 for ; Thu, 10 Feb 2022 12:37:30 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id x15so7546377pfr.5 for ; Thu, 10 Feb 2022 04:37:30 -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=vH5ZsS3PT2z/Kj1kRUC91t3vQ/3r4wzvj9kOFOgiv2XuirXjyqCONSJ/51PQ+9kRrK me7yzHej8KCOSngIj9caZ8TYmD6yjv+OipS0Zh++ztGJnNTQv16Q7RRYXhTYPGAmroqD 8m5j3krUJ5T7ngC61kzmUoO7LQUaIz2LEx+1pTMuFaVjauZ+az7YgVOMXYNt/EgUzglJ CeNzs5L0I0SGoqAREdYhRiJAtewRFVJhmU7qPU751vHJEyUnYbv9HmWNYc2VVD/9t+9P RXlLPEDx6qiWtpgfwcD3oePkZ1C9Ng9PvZ1jiTdIVXdZgfWlIljgvFq369BTQ+OK00/n CUjg== 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=qqUYhIaGKGop7sbqId+sIYSjP7oK0pWU57pqUkABgqsd64WRDY5Kp0ZrPeUTvAAw0r L6ukfjT68o4uzg6yq74W9JQeYi1MsEn61phQbRrMVxWQj+xD/eBa/asin9fqAJEljuUf KTtyVI88FlblK61DuV2qMqg0PadU3QPK9sXULWWTtzHyhi8MJ7uQm9iYRB1e3ovLSeUv 24RXfSf24wdY+JzTpUTFhzbWjSp0t0ME5dtYugfGARKkbht38aIPnlE4n/jRqEStnlpO I1rxgUDFD2hznxgfktw4Ub/nCIo0ThagBXVTP2H9R4hJ4cU1sr6wSJ0j9u6WIB0wPAKE 6q8g== X-Gm-Message-State: AOAM530WtYhTGoK3StVjVmVelq9ClUIfYxn4bJ0A98F+EjLM2ejM2UxE K/KCBbHePar4L40spa88vQkTRJ6oADVWlggg X-Google-Smtp-Source: ABdhPJwl1X1ncYwB3dcpyVNk3GZyIIA7yD1CzabbhXJpnxAOqkc97+qhRQDMOf2nz7oIH9laIqf+NA== X-Received: by 2002:a65:681a:: with SMTP id l26mr5933154pgt.365.1644496649737; Thu, 10 Feb 2022 04:37:29 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:29 -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 v5 2/7] mm: fix missing cache flush for all tail pages of compound page Date: Thu, 10 Feb 2022 20:30:53 +0800 Message-Id: <20220210123058.79206-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=vH5ZsS3P; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspam-User: X-Rspamd-Queue-Id: D141340007 X-Stat-Signature: zpt8wgzp5tq5ycqfja4oxyac41d3tztm X-Rspamd-Server: rspam07 X-HE-Tag: 1644496650-279582 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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, struct page *page, if (!PageMappingFlags(page)) page->mapping = NULL; - if (likely(!is_zone_device_page(newpage))) - flush_dcache_page(newpage); + if (likely(!is_zone_device_page(newpage))) { + int i, nr = compound_nr(newpage); + for (i = 0; i < nr; i++) + flush_dcache_page(newpage + i); + } } out: return rc; From patchwork Thu Feb 10 12:30:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741874 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82CF2C433EF for ; Thu, 10 Feb 2022 12:37:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F11FF6B007B; Thu, 10 Feb 2022 07:37:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC1796B007D; Thu, 10 Feb 2022 07:37:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8B746B007E; Thu, 10 Feb 2022 07:37:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id C985E6B007B for ; Thu, 10 Feb 2022 07:37:35 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 872ED1BFF42 for ; Thu, 10 Feb 2022 12:37:35 +0000 (UTC) X-FDA: 79126821270.24.5443057 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf28.hostedemail.com (Postfix) with ESMTP id 27CCAC0003 for ; Thu, 10 Feb 2022 12:37:35 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id c5-20020a17090a1d0500b001b904a7046dso6824770pjd.1 for ; Thu, 10 Feb 2022 04:37:34 -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=kCvGgcRI4BCb4bo+PLBmo+rPOq2UtF9zlalPG6igjOk=; b=nk3w1/O8ruce/KxIcFhyUO1pVaNj82bb2o0RtC+Eqn+gFpTDRTDEEO+SUjkKii+bMA 6/XUIHV6zMhbdvk0KD8AaMfYxOjdrDE/7BPf2Z1eS3SWvotZrlr+0FHt9//kPbH5xExr QBMsk7iVC+lbtURShOMph5ee0edzKKy8tr0ltF1A0FHWFQrbjSd6iU3q6WGP9e8BVY17 9SsD6HPxj3Z6fmn3OcjrV8uLz3kbddDZFxPxIcLS9FKpC8iZfZiXhVY5IdjLNbA2qjSP kyJe8qybWut+rnxiXLz/UUmADHvH367cikWiEbu+7LMtZO3nb/X5hv0TeKzr6J8tdMIc UEdA== 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=kCvGgcRI4BCb4bo+PLBmo+rPOq2UtF9zlalPG6igjOk=; b=QwrO2+1rgU+j9rOHjfzkS9OZOp7hVXFMh9zDpyzb0wEnaOKfKTQtXO09+LR5oedFE1 Dy2XxILhF++ZuEbZ/B/37ubNZJ0s7kcZVp0xsnd7hR4H5Ov2HBm0rQJidJo5uC2DssAi 0a7NVlsM+qMxyxhcW37Iu7oKudAopGx0ZU4hkEtkN0aFtZq139sNHbfZH6PJlzIcP+HM MpkSRkoqXmlnWo+ck5y6kX9XQS65ZUkcWBuqgIesYQF4BeV4SgTxqbILuuo8wUEcZpT1 /LLbRSJPZt5C/TAXUj6hz9eNGXnAWQ82VlFefzrX6Fga4UfJJrsjN5lbgJnJ5XUdYTnO 4u/g== X-Gm-Message-State: AOAM531BJxP8QU+7zCeMTDMtWajG95GTdClyAeCxo6oJavFkGhHU5xRC uzOrIaRfC2LfSCDXmR/Rt8HRsA== X-Google-Smtp-Source: ABdhPJydgYDL68pV4tg6C9n6s9P9xqUtx6BfUfSjlx18xcMF5d9QufoEkJRRr1Q5wwnwW+Wqm5H7Zw== X-Received: by 2002:a17:902:e743:: with SMTP id p3mr1888043plf.152.1644496654350; Thu, 10 Feb 2022 04:37:34 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:34 -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 v5 3/7] mm: hugetlb: fix missing cache flush in copy_huge_page_from_user() Date: Thu, 10 Feb 2022 20:30:54 +0800 Message-Id: <20220210123058.79206-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="nk3w1/O8"; spf=pass (imf28.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Stat-Signature: i88m8aibxfnof8aqaxzh885un6upqur8 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 27CCAC0003 X-Rspam-User: X-HE-Tag: 1644496655-967714 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Mike Kravetz --- 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; + flush_dcache_page(subpage); + cond_resched(); } return ret_val; From patchwork Thu Feb 10 12:30:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741875 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50452C433F5 for ; Thu, 10 Feb 2022 12:37:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3C9A6B007D; Thu, 10 Feb 2022 07:37:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEC2D6B007E; Thu, 10 Feb 2022 07:37:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8D068D0001; Thu, 10 Feb 2022 07:37:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id AB4606B007D for ; Thu, 10 Feb 2022 07:37:40 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5EACF84B33A3 for ; Thu, 10 Feb 2022 12:37:40 +0000 (UTC) X-FDA: 79126821480.23.1636FDC Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf11.hostedemail.com (Postfix) with ESMTP id EACAD40003 for ; Thu, 10 Feb 2022 12:37:39 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id x4so1707665plb.4 for ; Thu, 10 Feb 2022 04:37:39 -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=kILCWGYQN4aCmOVzGkGgpbDqf3vflThkp2WsD9ah7ls=; b=fG95xjXcp5pb/4AZm3qvm7w7s5VMHbtcG0Lx0tYYXqTPxFq3Uc9uBYT7LAv2r+KKbS O4ERCsf/+TVyMN0TI/YJ5AQEXti7JI7zzwU0mLvt4C3cBqleBqOzGfuRZcC1OF+y8qK2 vSoUE7Hf9EA/yx8S3k+43lmfcwEiQw/pT+Qqytcy93VzMeV9T5V1d8vGtrZWnnkTZ83m gsLyBS9KN5r5acorSo3QXiEsgVjacHClEVUDMD4sG3kLdlBslDcPD75Vy3XQBiXZPJMa t7zXdHWqMkokITwK0wwNIOyWHuSRyTfwh6IqmbAlxzQ9Gwc1zYBjlhUYgd302H5unjo9 UwFg== 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=kILCWGYQN4aCmOVzGkGgpbDqf3vflThkp2WsD9ah7ls=; b=fl4BVx0o9Qvl2XymMtqgnq9wM24DkgD8CXQfDq5cDzlaJaDeXqgr/FCyZYVXHum5ta 565mOs7h19BXKkzYQae5195RmvDZDxGjRuJvl/p2N7DI0IDcuLNHWIMqzTV4k6Ss+1Cv 50CASFjGdniRnVRu7iE89mGWQAwmiJhs/2BGiSHXINNZY/bcOAIRmpQIwIuRQFZP9hiu XwEKjziY2q4cFtAzWxTBTBrHdUcBU3AFFP3UZjGwXcfOPtph1XxLf+IfNz+eAR+cyOzL iaS+JDvo7+2V+xpZfZbDGY5ul9fJe4KZIPyFqldxc3KSGEOjRcb/rJUch3nvR028gA2e 5ZQg== X-Gm-Message-State: AOAM532HFIAGSZ/qwFzbTRfGcXRfJu0QooEhCX/JS9DAeLq2V7fur/SX 0UaAR66Oyz9xRn96PXIOT3Chpg== X-Google-Smtp-Source: ABdhPJxXO3PdREGl7iYGtPoZwu9ZnEuV9DWQ2+VdIf1bDfCvRiQrzRC1gMtC9rR0cVrUjm5h5t4w8g== X-Received: by 2002:a17:903:1211:: with SMTP id l17mr7635562plh.11.1644496658991; Thu, 10 Feb 2022 04:37:38 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:38 -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 v5 4/7] mm: hugetlb: fix missing cache flush in hugetlb_mcopy_atomic_pte() Date: Thu, 10 Feb 2022 20:30:55 +0800 Message-Id: <20220210123058.79206-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=fG95xjXc; spf=pass (imf11.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Stat-Signature: 51m1gbjui9cdrruzkky5hksosnskdawb X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EACAD40003 X-Rspam-User: X-HE-Tag: 1644496659-303241 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. It is also make backports easier. Fixes: 8cc5fcbb5be8 ("mm, hugetlb: fix racy resv_huge_pages underflow on UFFDIO_COPY") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- 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 = 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 = NULL; } From patchwork Thu Feb 10 12:30:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741876 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF14CC433EF for ; Thu, 10 Feb 2022 12:37:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 352D96B007E; Thu, 10 Feb 2022 07:37:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DA818D0001; Thu, 10 Feb 2022 07:37:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17AB56B0081; Thu, 10 Feb 2022 07:37:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id 094886B007E for ; Thu, 10 Feb 2022 07:37:45 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B688C1D1661 for ; Thu, 10 Feb 2022 12:37:44 +0000 (UTC) X-FDA: 79126821648.28.9C68116 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf15.hostedemail.com (Postfix) with ESMTP id 4D123A0011 for ; Thu, 10 Feb 2022 12:37:44 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id x4so1707810plb.4 for ; Thu, 10 Feb 2022 04:37:44 -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=tKpVSiHHtaj87FMK/TeB9fab8FVNXtwv8Xc4GuIj/Kg=; b=fQy8vfqpU9cS9VF0UkKIV2NNCg0tQEdPXZgAQyveKt+IqZMhPhSLL2L91pt18Zg06N vNvRvBopSQe6m1BOl262fpfSHiT8PTxbkyLfR2s8UUCSsGqv6jhJr5tF046QxWGKPvQ4 j1luq5AgDAl2iOiKPsSWugj44vi8gpSPdoJjaafW25tBKv8lpwq+uDQF3SBoV0mX0uWh oeE64v4w2/BhLSM2qEBvn2JtkZhtGWhP1r03BRWqGEilJv2WHtsOlbBI0BeMeSkYlft6 BtL8Es/U26EonkHfhoxdHnW89rwm0do83Rj77+xgClJ16smYtj669p2PtIeIaa0K/Otd MINg== 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=tKpVSiHHtaj87FMK/TeB9fab8FVNXtwv8Xc4GuIj/Kg=; b=rWSZYYiEK7wWjDkxZGNhCR0XScr0GECMFqM0AUcS4SGrHpif1wqqbJIE5bcccFwozm Nokz6pw64obTB+LXzbFg4xfFVWyUiVZqkWyI9FZsTS28htK+MBSl76woPS4W66Vuo6Ok +ADroNQYwMb2v4NRUmCzoVmqlmCiI+gBBn+Spab0CP0rrjurQaqcNEZzfKLsE8hp43Q1 +/fCjTlcm+VQpytBu3d4isYcK8cGpwkG6NbFVk3UsOAe6nH6SOzh6DaY1uzmmcPTwQdf zWoMoGRAG5mlOKw0fX/t7c6fP+b0ATEbuCr63AJf2eDqaW9gaZMsEQGrExgE99BT8Eaf SgwQ== X-Gm-Message-State: AOAM530TTXMkVOB85c1wbCLqy+C3r9zsnx0dX59kyh/Wk7sjteo+4dpu 872G3ce+c4P6oddPlJQ5spGt5w== X-Google-Smtp-Source: ABdhPJyGp2GsZvSDMqpR5iLkDxZjE53dEk3dm5rB0VkaJA74+KantoyMJ9LJ6pDdNdp3d3NZ3dXk6A== X-Received: by 2002:a17:90b:1c0e:: with SMTP id oc14mr2638965pjb.2.1644496663463; Thu, 10 Feb 2022 04:37:43 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:43 -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 v5 5/7] mm: shmem: fix missing cache flush in shmem_mfill_atomic_pte() Date: Thu, 10 Feb 2022 20:30:56 +0800 Message-Id: <20220210123058.79206-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4D123A0011 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=fQy8vfqp; spf=pass (imf15.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Stat-Signature: yqinfwjkyqs1qc4xyurdsi1pe4jdbjxf X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1644496664-666816 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The userfaultfd calls shmem_mfill_atomic_pte() 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. Insert flush_dcache_page() in non-zero-page case. And replace clear_highpage() with clear_user_highpage() which already considers the cache maintenance. Fixes: 8d1039634206 ("userfaultfd: shmem: add shmem_mfill_zeropage_pte for userfaultfd support") Fixes: 4c27fe4c4c84 ("userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- mm/shmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index eb0fd9001130..2e17ec9231a2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2371,8 +2371,10 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, /* don't free the page */ goto out_unacct_blocks; } + + flush_dcache_page(page); } else { /* ZEROPAGE */ - clear_highpage(page); + clear_user_highpage(page, dst_addr); } } else { page = *pagep; From patchwork Thu Feb 10 12:30:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741877 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71314C433EF for ; Thu, 10 Feb 2022 12:37:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 107818D0001; Thu, 10 Feb 2022 07:37:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B6D66B0081; Thu, 10 Feb 2022 07:37:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC12A8D0001; Thu, 10 Feb 2022 07:37:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id DD0266B0080 for ; Thu, 10 Feb 2022 07:37:49 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8A657183BB2BB for ; Thu, 10 Feb 2022 12:37:49 +0000 (UTC) X-FDA: 79126821858.14.81E8853 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf27.hostedemail.com (Postfix) with ESMTP id 33F3740002 for ; Thu, 10 Feb 2022 12:37:49 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id d187so9944898pfa.10 for ; Thu, 10 Feb 2022 04:37:48 -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=kGvpK6UTEMeGdDCg9a68QTimGRB3Wg5V4hLO/H8ovOk=; b=8R2KQc0VHwfvgfFLuPp0xcs/i0bFi3ZpoOvzA4bg66nMtTPqQzqxTX+Hj1tWbZt+HU 01u5lq16jDHas70gMpnZO5BBiMuTF+W5pva0r6kivMj+a2RM3QWGQAUXznhUqBxpKPkf Vv/Tu1P5u0Zi/cQioKebx7XyAGlUXUXMibP1SqIBSj3UGsVQaJUelPy5p4+rwTHdnNhy imoRrsXIOlM97bvi9gNvPrSM9JSeP4ZkPvsAYpxNIA9hXjYHh50pMLoZIGcA0ttGpuMA Y/Xsnao5EZKEuqby/5+bnXTVOdcLa1PFjq8mBuhVnryqOZu7iQRstCzev9b3DNb+X1dy uUqA== 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=kGvpK6UTEMeGdDCg9a68QTimGRB3Wg5V4hLO/H8ovOk=; b=BitNn2SRNMbN1iefxDv3cJ2eC5ZEFGHKJnxJEmcnAqUQaaKL/zVaqhKEUNbVQIJHF3 Qvd4stsyTMUWqj9uZZyEo2S0gtqN6DONQVBqQM9opmBdrXJtoEY7h1mvwV1iKByyshNF hRjaY9mmkoHPi/EEe5esCr+i7Lhvmdh705vMhdl2ZxLJ4aI1getoEmKpF7u4f9tYFJ9G hamKFS4Zhn0WFnJrPOZTHuF8WZAtp8hSHRyM4Jw2q08GtQ5/GhD88cNW3NYhwJ//29to 2LA9QWrpDalJtq3jq+eJZ0hbTfcrvVPeRfanjKHsNVLMnoNME8YTdlPAgKM4ErJtYpHI Bujw== X-Gm-Message-State: AOAM531wixQDPVwBOz3Nl7wXMFAyea1ug9kyDcDi6otvRVPcyGLWap0T v6KTxypnOYEJIK/wEU/zhaTHvg== X-Google-Smtp-Source: ABdhPJxuA+mcAk8N3GxFOFt4YcmS2sQMINZgJ8h6aEo3yg4idUSXIkOyJ07Dtpti42YAT/Z5DU8wrQ== X-Received: by 2002:a63:4e0e:: with SMTP id c14mr6120150pgb.490.1644496668324; Thu, 10 Feb 2022 04:37:48 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:48 -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 v5 6/7] mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic() Date: Thu, 10 Feb 2022 20:30:57 +0800 Message-Id: <20220210123058.79206-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: fghenxs7fiy6ihs3us6yipjubx4h56xt Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=8R2KQc0V; spf=pass (imf27.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 33F3740002 X-HE-Tag: 1644496669-993869 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The userfaultfd calls mcopy_atomic_pte() and __mcopy_atomic() which do 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 by insert flush_dcache_page() after copy_from_user() succeeds. Fixes: b6ebaedb4cb1 ("userfaultfd: avoid mmap_sem read recursion in mcopy_atomic") Fixes: c1a4de99fada ("userfaultfd: mcopy_atomic|mfill_zeropage: UFFDIO_COPY|UFFDIO_ZEROPAGE preparation") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- mm/userfaultfd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 0780c2a57ff1..6ccc534d1c1c 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -150,6 +150,8 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, /* don't free the page */ goto out; } + + flush_dcache_page(page); } else { page = *pagep; *pagep = NULL; @@ -625,6 +627,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, err = -EFAULT; goto out; } + flush_dcache_page(page); goto retry; } else BUG_ON(page); From patchwork Thu Feb 10 12:30:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741878 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26950C4332F for ; Thu, 10 Feb 2022 12:37:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2FE26B0080; Thu, 10 Feb 2022 07:37:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B81D6B0081; Thu, 10 Feb 2022 07:37:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 880946B0082; Thu, 10 Feb 2022 07:37:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id 7B5B76B0080 for ; Thu, 10 Feb 2022 07:37:54 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3660581049EC for ; Thu, 10 Feb 2022 12:37:54 +0000 (UTC) X-FDA: 79126822068.19.31447BD Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf02.hostedemail.com (Postfix) with ESMTP id CDBAE80003 for ; Thu, 10 Feb 2022 12:37:53 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id h7-20020a17090a648700b001b927560c2bso4223449pjj.1 for ; Thu, 10 Feb 2022 04:37:53 -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=oDahdnw06IsGwB/7M26luCqPUnRrkijqY+ZjOYkno4A=; b=tpGNdIY2hwVGwRhbVAEv6E5VyLyH6hl7LUw7SLZyLIw8PMoLNcP/DUGn0A+TA43MA3 DAp3ueB1y4QZ01hqgxcV1mb3FD1UWVfLo9aGY6MkmnYv1rOx2LYVOFu5ECBqxxAlZ6h7 +fYloX/Dkjb81uKdqULv2aHbXuLal3uHsATiys2WgJE7mplGe4YGnpxk3Z0z9gm5fdvJ Fvl59LuYztWU/omTw0zQNUWaMxPJB3cNt2Hzp19Bnjfm+NtW+p+D6/+bjn6Ikjry2ySE 7IJqRMvlWxRjZy4PkrIHOFY8qSvSNocEuSXW3CRF3ibl5YTyGYBL49XvaPC+KX6yN7Yk TAAA== 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=oDahdnw06IsGwB/7M26luCqPUnRrkijqY+ZjOYkno4A=; b=TaiOLCpcKF9o4I3YruCEnWNnAMXmnMHpgckIqjzy3Zd3s2GAyY8xYZyNrqftDhE3Aw yh4jzfTMPft/tPmV5bhCUQTxYcD+tug3sA6qUssab4jegSJaLvPc9vBFnR+akN0t0i3C 9RJD3iCg80FhwhsgajHjymlEL/b3v4kDtNxBcmOz1qY4iA0zne4vdMvcnkZ/jP/5EUBS m2gX5X0zl29agw4k2wqf75c5mDp9/tKaoFuHx7r8E9S1SWQwHpR0k7ia4+8ggaOCsZ2R aQhMUkNHbi9DPUuT5TcY74ZomeWyFJtsOdBK8lMlPdJRF8czBSLThSsNIJrdqlCYTB11 +JJA== X-Gm-Message-State: AOAM532+aOsiotCTGbMIFBxT0wYORdI40mZRlb9fqsCS5eYi74zYBHYM 6vhh9ADaI4hSu0Fu4KJNzCGr9Q== X-Google-Smtp-Source: ABdhPJzn0l92vEIhPNZDK6wnPCBAAD+wPaRAZsukzdXyxqRwg+i/PIhMukVTcN6WwYR8rEu1ZtzJfQ== X-Received: by 2002:a17:90a:fe15:: with SMTP id ck21mr2602609pjb.95.1644496673004; Thu, 10 Feb 2022 04:37:53 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:52 -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 v5 7/7] mm: replace multiple dcache flush with flush_dcache_folio() Date: Thu, 10 Feb 2022 20:30:58 +0800 Message-Id: <20220210123058.79206-8-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: 51uiigym3fpb3s7fqdoj74htdes5mqek X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=tpGNdIY2; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CDBAE80003 X-HE-Tag: 1644496673-768834 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000499, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Simplify the code by using flush_dcache_folio(). Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- 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, struct page *page, if (!PageMappingFlags(page)) page->mapping = NULL; - if (likely(!is_zone_device_page(newpage))) { - int i, nr = compound_nr(newpage); - - for (i = 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;