From patchwork Wed Jul 15 12:35:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "kirill.shutemov@linux.intel.com" X-Patchwork-Id: 11665219 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F6A813A4 for ; Wed, 15 Jul 2020 12:35:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0641320658 for ; Wed, 15 Jul 2020 12:35:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0641320658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0ABDC6B0002; Wed, 15 Jul 2020 08:35:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 05BFC6B0003; Wed, 15 Jul 2020 08:35:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8D286B0005; Wed, 15 Jul 2020 08:35:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id CEA336B0002 for ; Wed, 15 Jul 2020 08:35:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 505CD181AC9B6 for ; Wed, 15 Jul 2020 12:35:20 +0000 (UTC) X-FDA: 77040255600.28.pail75_5c0312226ef9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 20C456D62 for ; Wed, 15 Jul 2020 12:35:20 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,kirill.shutemov@linux.intel.com,,RULES_HIT:30054:30064:30070,0,RBL:192.55.52.88:@linux.intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95;04y84zc8hd7ifojxodas8tn9iu4i1oph8xhn1dxc6187ymd4exh5cq1xww3bqiq.dicwuxguoyfeqr7c8h63setye8xkwpghikx199qw1afdzho36afap1367kp4tot.e-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: pail75_5c0312226ef9 X-Filterd-Recvd-Size: 4090 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jul 2020 12:35:19 +0000 (UTC) IronPort-SDR: +dEf8iUlyKV7biXBTiXKA/Zg4QCE4+4DPIoOAVE/V+WH3mUwumnBqvuF7q92l+HjCRPMQ2B6+U R2QX4ZOP66AA== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="167252930" X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="167252930" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2020 05:35:17 -0700 IronPort-SDR: GFVku8FxPuBhbJwckGG+97wqo1oklR5rxjArhU0zj/kScG7/CZXpWNSSdIK5U+PaP39ZUjSj5Y qUMlHCtEVM+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="268943784" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 15 Jul 2020 05:35:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id D95A2190; Wed, 15 Jul 2020 15:35:14 +0300 (EEST) From: "Kirill A. Shutemov" To: Andrew Morton Cc: Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Naresh Kamboju , Joel Fernandes , William Kucharski Subject: [PATCH] mm: Fix warning in move_normal_pmd() Date: Wed, 15 Jul 2020 15:35:13 +0300 Message-Id: <20200715123513.42240-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 20C456D62 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: mremap(2) does not allow source and destination regions to overlap, but shift_arg_pages() calls move_page_tables() directly and in this case the source and destination overlap often. It confuses move_normal_pmd(): WARNING: CPU: 3 PID: 27091 at mm/mremap.c:211 move_page_tables+0x6ef/0x720 move_normal_pmd() expects the destination PMD to be empty, but when ranges overlap nobody removes PTE page tables on source side. move_ptes() only removes PTE entries, leaving tables behind. When the source PMD becomes destination and alignment/size is right we step onto the warning. The warning is harmless: kernel correctly fallbacks to handle entries on per-entry basis. The fix is to avoid move_normal_pmd() if we see that source and destination ranges overlap. Signed-off-by: Kirill A. Shutemov Reported-and-tested-by: Naresh Kamboju Fixes: 2c91bd4a4e2e ("mm: speed up mremap by 20x on large regions") Cc: Joel Fernandes Cc: William Kucharski Reviewed-by: Joel Fernandes (Google) --- mm/mremap.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 5dd572d57ca9..e33fcee541fe 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -245,6 +245,18 @@ unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long extent, next, old_end; struct mmu_notifier_range range; pmd_t *old_pmd, *new_pmd; + bool overlaps; + + /* + * shift_arg_pages() can call move_page_tables() on overlapping ranges. + * In this case we cannot use move_normal_pmd() because destination pmd + * might be established page table: move_ptes() doesn't free page + * table. + */ + if (old_addr > new_addr) + overlaps = old_addr - new_addr < len; + else + overlaps = new_addr - old_addr < len; old_end = old_addr + len; flush_cache_range(vma, old_addr, old_end); @@ -282,7 +294,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma, split_huge_pmd(vma, old_pmd, old_addr); if (pmd_trans_unstable(old_pmd)) continue; - } else if (extent == PMD_SIZE) { + } else if (!overlaps && extent == PMD_SIZE) { #ifdef CONFIG_HAVE_MOVE_PMD /* * If the extent is PMD-sized, try to speed the move by