Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp520881ybh; Wed, 15 Jul 2020 08:09:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOuFxaiHtuU2WvV4LPduDwAVfs5lSA88+/FjzGzGGsfQhHEZrlG9seDQ20ZvvIh6xt5HPD X-Received: by 2002:a50:a45d:: with SMTP id v29mr80535edb.284.1594825777549; Wed, 15 Jul 2020 08:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594825777; cv=none; d=google.com; s=arc-20160816; b=q/Yx1o2QG/jivH5D9kezWHi7449KBnr+zGJ0MvTcGi/R4et42zEr7V5pc/7CVf4H0C LJTMUZkTP5lqdkNB15OjntFxBPcUp/gpvioXb95p944GfHg0vYvOlQQevwa8Oz2n4dRq dWKQRdJtROPnBYTLAeOPsVHyGNC9FVBU1+PTjv69fsfjc/WYKIyiqKaIrZ0a5hsq+f5x Q2biFJ6H0t8B/6RIHjbBmsxdTVyRYQ57s8jd8LaKKbfG759T7nbsqcacHopsfQwPX/ql dadQpodTSESyy/F+7vLLqWpx65f0pGt9+bdoeB0ygHNSGaQxyXa9Q8DA5VY0UP/bCCEe IzjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=YpASIW2XP7FOEh6qxm30JAMgTxEMrUD5oTuqeiyS6v0=; b=e/ifTa6TKzak6YhtPahQSY60hQdCVbgRskulB+CmUVOo+Ej22A+2hgnZ2HlJUclsnE bRCxm7aIyp3e4aPAcDNIefzSNQ47mprpbUEDgauCg861/ZIXjUTK9W4bTS8clEjvsPh/ 76AtAoTceZAZxJVoSGAYaU4pLSHviB0uQUUcxrEdV1LqTpOUazI/XJz9vJ/+N/l3+zIr UGdPL4z9TuZLfKswEAEMssuCzrby/45TWNw3jbO5toIM7htfLKewq+Rb7DoHbhYkaFaQ cz0k0fUNednqoB+w2QlULbMmlgXOoAy8ose84P1LwhJS3TNs69RXwWzivweLLVxFM51c HVLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si1487482ejj.516.2020.07.15.08.09.09; Wed, 15 Jul 2020 08:09:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731802AbgGONuR (ORCPT + 99 others); Wed, 15 Jul 2020 09:50:17 -0400 Received: from mga09.intel.com ([134.134.136.24]:36587 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729086AbgGONuQ (ORCPT ); Wed, 15 Jul 2020 09:50:16 -0400 IronPort-SDR: Mw6I9VVgcTZ0j0ub+FXnw+O/JfIYU+xh9Vc45w926/ncjloNNvuxiV1n3Izc85Pl8U6xlTOmsg UjAvHRVM2XSg== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="150556596" X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="150556596" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2020 06:50:15 -0700 IronPort-SDR: HGWwevdqxTxDRDHxu6Loac2IHFbvALH+N778mrEpxGQOVurNvv8tjElWvYNleM189heoRQy4oy DriO0I4yhElA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="282095027" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 15 Jul 2020 06:50:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id EA8C476; Wed, 15 Jul 2020 16:50:12 +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: [PATCHv2] mm: Fix warning in move_normal_pmd() Date: Wed, 15 Jul 2020 16:50:11 +0300 Message-Id: <20200715135011.42743-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Fixes: 2c91bd4a4e2e ("mm: speed up mremap by 20x on large regions") Link: https://lore.kernel.org/lkml/20200713025354.GB3644504@google.com/ Reported-and-tested-by: Naresh Kamboju Reviewed-by: Joel Fernandes (Google) Cc: William Kucharski --- mm/mremap.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 5dd572d57ca9..340a96a29cbb 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -245,6 +245,26 @@ 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; + + /* + * We are interating over ranges forward. It means we cannot + * handle overlapping ranges with new_addr > old_addr without + * risking data corruption. Don't do this. + */ + WARN_ON(overlaps); + } old_end = old_addr + len; flush_cache_range(vma, old_addr, old_end); @@ -282,7 +302,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 -- 2.26.2