From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53819C433E4 for ; Wed, 15 Jul 2020 13:42:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 10E7E2064B for ; Wed, 15 Jul 2020 13:42:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="JZLurGrN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10E7E2064B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E6C76B0006; Wed, 15 Jul 2020 09:42:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 797DD8D0001; Wed, 15 Jul 2020 09:42:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 686296B0008; Wed, 15 Jul 2020 09:42:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 52B706B0006 for ; Wed, 15 Jul 2020 09:42:13 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DB6402DFD for ; Wed, 15 Jul 2020 13:42:12 +0000 (UTC) X-FDA: 77040424104.18.vest19_5709e1226efa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 94C16100EDBD9 for ; Wed, 15 Jul 2020 13:42:12 +0000 (UTC) X-HE-Tag: vest19_5709e1226efa X-Filterd-Recvd-Size: 6480 Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jul 2020 13:42:12 +0000 (UTC) Received: by mail-lf1-f67.google.com with SMTP id u12so1091552lff.2 for ; Wed, 15 Jul 2020 06:42:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=SxxB4qbhw2tWNEvr88Pqt9cvKqwZuyme5Sh3lfJhB5Y=; b=JZLurGrNoBYQxciEUm87cgGqTsV5W49DaQV7e35/aDoZH6eIxdJu8vyg9dyV320WYl FJpzd9gZU+cOHEpGW0kGqZkz422JyA1uH1U/Q/Adb/jupijKqtOB8t91/s69FfCG+AvD tLJ1Xk/K4wreOJfXKFqZ425hRmW58P7f+iFDoUyVrt1bqwbfNacRpzRRexLSwXbVtNEs LN7b5lYzKIyDOwS4InTTTePYGOwsE3UXTlRlroYPA8t5p5v3S1oUm1SgPCS/vMZ40HYZ k1iVl2msTW8xyEHBJXlQMAL4dV96v9NFDM96Tmtwys39vZdyZtMcGtIc/1tu1C2rxpTy 9Z8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=SxxB4qbhw2tWNEvr88Pqt9cvKqwZuyme5Sh3lfJhB5Y=; b=H244W+fnNaZELNl4FarSyA/IyaDmxcBQ4jImcnV7Gq22dbZ9GQsoZkq6/gYl2eEXQc dEjoSVwb1fqC5w9+XYL8Tcks4KHQ7AHbz8tgPt/Nvj3vTbYM5IVap4B1M0+FkjIfcSwZ a3aN83ZtNk1dqAtHnS+DCuavdwF8sNRJmKAYagGG9eREa5rJ765PwX9OVDze3aZ4RTwm l/QH5tEJAysjHenc6UsDnJ/lQb235JSLlhU6DJjNcAAMXN/bkYbil/0dqWPssABH4/b+ Ofz7kzt/AhWnyy7VYvtMU0oCR/xLQqdx2H0uAMLBb3CrF9xTDiy9uO6pgPss3fz/xuOK IImA== X-Gm-Message-State: AOAM533pwD8APoP5Db7JNZd8PahLKG8+yaIMbhpzQAW9JYR3m4u3snY/ IIMSO/AskVOhHyMATgFNz0VV0g== X-Google-Smtp-Source: ABdhPJwFrBfWYTK+Q3wN2zFu2P8FuaHH7sb7oZGfLhfgtGrJScnlsn11reIleDOy2JwazRE6wYYnHQ== X-Received: by 2002:a19:6b16:: with SMTP id d22mr4810925lfa.111.1594820530434; Wed, 15 Jul 2020 06:42:10 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id j2sm461147lji.115.2020.07.15.06.42.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2020 06:42:09 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 5B0EB10209F; Wed, 15 Jul 2020 16:42:14 +0300 (+03) Date: Wed, 15 Jul 2020 16:42:14 +0300 From: "Kirill A. Shutemov" To: Joel Fernandes Cc: "Kirill A. Shutemov" , Andrew Morton , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Naresh Kamboju , William Kucharski Subject: Re: [PATCH] mm: Fix warning in move_normal_pmd() Message-ID: <20200715134214.qzkuxnfjszgty2oj@box> References: <20200715123513.42240-1-kirill.shutemov@linux.intel.com> <20200715131451.GA2971370@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200715131451.GA2971370@google.com> X-Rspamd-Queue-Id: 94C16100EDBD9 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: On Wed, Jul 15, 2020 at 09:14:51AM -0400, Joel Fernandes wrote: > On Wed, Jul 15, 2020 at 03:35:13PM +0300, Kirill A. Shutemov wrote: > > 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. > > A link to the debugging effort could be added to the change log: > https://lore.kernel.org/lkml/20200713025354.GB3644504@google.com/ > > > The fix is to avoid move_normal_pmd() if we see that source and > > destination ranges overlap. > > Reviewed-by: Joel Fernandes (Google) Thanks. > And one thing that bothers me: > > > 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; > > Does the code really work properly if old_addr < new_addr and overlaps == > true ? If not, then we should add a warning here in the else IMHO: > > if (old_addr >= new_addr) { > overlaps = old_addr - new_addr < len; > } else { > overlaps = new_addr - old_addr < len; > WARN_ON(overlaps); > } > > (More so, since you have added code that detects overlaps for such a case). Right, I'll update. But we should warn for old_addr == new_addr too. Nobody should do this. > > thanks, > > - Joel > > > > > 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 > > -- > > 2.26.2 > > > > > -- Kirill A. Shutemov