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.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 B30C0C433E2 for ; Wed, 15 Jul 2020 13:14:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 77661206E9 for ; Wed, 15 Jul 2020 13:14:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="YL/nqL8t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 77661206E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E0B2F6B0005; Wed, 15 Jul 2020 09:14:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBB636B0006; Wed, 15 Jul 2020 09:14:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAAC56B0007; Wed, 15 Jul 2020 09:14:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id B13006B0005 for ; Wed, 15 Jul 2020 09:14:54 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1F605181AC9CB for ; Wed, 15 Jul 2020 13:14:54 +0000 (UTC) X-FDA: 77040355308.20.leg23_040fa0226ef9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id EC490180C0611 for ; Wed, 15 Jul 2020 13:14:53 +0000 (UTC) X-HE-Tag: leg23_040fa0226ef9 X-Filterd-Recvd-Size: 5726 Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jul 2020 13:14:53 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id c30so1659852qka.10 for ; Wed, 15 Jul 2020 06:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=36xFMqA7jKBKS65g8wY6rmZnlfX7TIQ/b5ZfvSdEJW8=; b=YL/nqL8tRBuXuNQQaYLOrwV6/rXJobd2XN8BqippDR1hJ6Jyw7DGfbxOkStgeYsAKP 4XB11f5ZP4U1OmyLH1dGWLHv/p4TTQD+mylxG1uLG2UpkLcYf070VsQ7NxwkHlwe/SA9 W+on5iAZrkThieSg5SB5tT66cFRWTzdeWyuFs= 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=36xFMqA7jKBKS65g8wY6rmZnlfX7TIQ/b5ZfvSdEJW8=; b=dvrbqunKhybvz912aA8283CbJORx9zyBPpp0sqEK+R0gh3cvvlMOR20KVLJYOmdhuI QkJNayq4jH1Q3XAIvIqF0P73sIbLPBSJ26cEoqaTgl+UpiFkyAfjtklqodHf8IJBG/9r 2mHnzhn6ppZvfy2wfrMJxjIIBJh915dwbI+nMEK/Z4+otPVSokAsTgdARWpyIbeEiICf Gl6YgeD29WKk67TX8upS7UQJ+qxiHWBp7mFC3vor6kZ9iD8iQatZfE5VZ6Pk2tNsYsVt GeqnzOC3V/J+2gcZfP+mhwYFHBeXSfjmKFJYJSTaucpmGCgiZRI2E6dRHRf75yMsJYz9 vpBw== X-Gm-Message-State: AOAM532qvfr/CTXJfksTZw03H43c9Wa8YaKOR/eJbzwioWsLnAEIeZ26 iAiKjddJOv3OVAc7rk9pHmiOvw== X-Google-Smtp-Source: ABdhPJxaafHoFn6d7qIo70bj00//MqfDVz+UywkULGl6GMdlvmjAJbPYgRUr/IKvgTxibmGYIseguw== X-Received: by 2002:ae9:e517:: with SMTP id w23mr9340433qkf.159.1594818892647; Wed, 15 Jul 2020 06:14:52 -0700 (PDT) Received: from localhost ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id j18sm2824425qko.95.2020.07.15.06.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2020 06:14:52 -0700 (PDT) Date: Wed, 15 Jul 2020 09:14:51 -0400 From: Joel Fernandes To: "Kirill A. Shutemov" Cc: 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: <20200715131451.GA2971370@google.com> References: <20200715123513.42240-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200715123513.42240-1-kirill.shutemov@linux.intel.com> X-Rspamd-Queue-Id: EC490180C0611 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 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) 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). 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 > >