Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp443515ybh; Wed, 15 Jul 2020 06:16:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVzNObsohBZT15CT1VAmwH2RkPrshfoQF/fRiveu5/N9XvrYF4wtULqd/WeWLJXRmRRsAa X-Received: by 2002:a17:907:2163:: with SMTP id rl3mr8905281ejb.409.1594818988455; Wed, 15 Jul 2020 06:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594818988; cv=none; d=google.com; s=arc-20160816; b=MjWQ7g4k5emclM6aBhKAFeD8v31X8Ut3wPO6YOAQLzWbbqK+WGgI29v8T5XJeVFBzs UvYL7NcEi10DDN6nuI0KctdUiUs0569bdcx1+/E8bCM30iRnh+vNQAXL2tGLKLUpQOBR OmPWK/QhtXSU9NuHQRLQXFw8vMmvRfYZ1YgbvEAP2TLoEwppj8Qbu0TwErd5i6L/zpXh X6tBlYjVP1WMWg83YAwabJurcQ3/gf9fgEim3iX7YUgc05gkhwzssqFoOKz7qSvkeb8b LoiPSiSv8XtbKLlt5qkxHn1/6yoqgfL3gfDbGY1WciR5p7rQPio3AXJFPuW6+aFxTAHA Ynow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=36xFMqA7jKBKS65g8wY6rmZnlfX7TIQ/b5ZfvSdEJW8=; b=JxIoL3HdxlWykEzA1qxvcH6dTuCajdbFTG70RwFztIPmcIoNwNM1W03lcFgO2pkM4g H2/EBag52eWSKKa9rbI5tpaXTx3nENVDxa0ViDUMqihV1OrI3FARc+DVUgeR1WtTr8eC M071XER0GJKHGCu9rErwokGg+Qnc3FZXqejwSDr5Yt3p33U374a9Hv2W13T+3J3eKRBL GAYSGVDU+vALNbKDMB2K/4nvoGR5/9+bB0j1tl6RZQTZ4jAkOU0K7EkV2XHpi8u60z6p 5Rg32PNNq1wDMbdHwUBBpGidiKp9wRREGzMACz2A2jOxjyxTiyDSp5qYEyhT9XTftfLq wcbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="YL/nqL8t"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t8si1203353edi.534.2020.07.15.06.15.29; Wed, 15 Jul 2020 06:16:28 -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; dkim=pass header.i=@joelfernandes.org header.s=google header.b="YL/nqL8t"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731508AbgGONOy (ORCPT + 99 others); Wed, 15 Jul 2020 09:14:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731457AbgGONOx (ORCPT ); Wed, 15 Jul 2020 09:14:53 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DFB8C061755 for ; Wed, 15 Jul 2020 06:14:53 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id e13so1685364qkg.5 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=RBoe5Q6z/JXyK2hLbnPvZqaG9hhCowEoRJVQUKJWgBsncj6Oy1TMLW1ADZ6M/hp9KL y1VMwLltO5jJkcxqq8W3xUcuwXgCwLsPPJX4oqm23iehzVUPpbeXCPjT4B3E8Z+EaC76 QDPIuEQRhNdnpUvot2KdyXRdT7tekfyoCpaUdsaUnKUI4yPbkajQnXwpXbSVYktklX3Y kOBzmXNFZSQCDX1p2ZKVeHdug3fFyoB2rWPDLKgTJWPyQGhsHtHnWmDfmaSaCLHxGhO8 lreNw/XVelRxwKn64s7EMGis99t2CZmoHeldQXVyrFYJ/9aVfl50uM29u8ti06ykBrDH +1lg== X-Gm-Message-State: AOAM5315oYevHYuLlbJX1q5Ky5yuvGdQblHHvdZ5Jmp5clrgSA0vLy+5 1V3AUiNFeRj9qIGWP7u9YkDl4A== 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > >