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,URIBL_BLOCKED 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 AEED0C433EA for ; Thu, 16 Jul 2020 07:23:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6D1D72067D for ; Thu, 16 Jul 2020 07:23:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="V83W9JPe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D1D72067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E95106B0022; Thu, 16 Jul 2020 03:23:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E457E6B0024; Thu, 16 Jul 2020 03:23:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D35AC8D0001; Thu, 16 Jul 2020 03:23:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id BD09F6B0022 for ; Thu, 16 Jul 2020 03:23:38 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2D6AA1EE6 for ; Thu, 16 Jul 2020 07:23:38 +0000 (UTC) X-FDA: 77043098916.05.jewel58_0007c9d26f00 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id ED184180142F8 for ; Thu, 16 Jul 2020 07:23:37 +0000 (UTC) X-HE-Tag: jewel58_0007c9d26f00 X-Filterd-Recvd-Size: 8016 Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Jul 2020 07:23:37 +0000 (UTC) Received: by mail-lj1-f194.google.com with SMTP id f5so5952370ljj.10 for ; Thu, 16 Jul 2020 00:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CMfq9IrRotghhONHBzEQ7VPqPzHVuJEy3x1AP8iTmRU=; b=V83W9JPe/G9CHrgopNuB/d5bRkNFKdOlMAmC5tThj3DS+uDWgV0HDsLkoheHvsSKyp Sr+JASOLA/ukU/xXADuoY10L3qNc9wTmpsHB7zNrfRaGD7MtVG/axzdCKXQXdspuw9Ra De74rZ7R6EgIzv6v5cZ/l8IKdlYrdqUVTQVgLxXJ6wXXo/b8TXdJyKM4vT8WoapzcIHN Lavov63WdNyrISXKE/gaOMEEjlZwKAA9Z94ng1lWPGpxBeiFXX9bejYOHGzc88nbwVlb Fl6PxUPp68mVMfIvVRmgFHN0/5NgY4TCHtOb/GxPXIHwXsGzAwnsiikCortLcauml4jv LFRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CMfq9IrRotghhONHBzEQ7VPqPzHVuJEy3x1AP8iTmRU=; b=bj4nt9OhFsQhyWTQJR3OCpHwv0hpa0Eb1j/kIpWSaDXmpmYh08Ozp6pTU/i+l3u8qt KMiQv9t5KP+0ODb/YJ+erXzAPdnIgkh/VUXRQVWljH2xLsQH/pk8QFJQP1eJju3Dw9Pq qMaMXxq/Hri4xP16Vhm27VyylSeHGCj8f3Odt7tmtdN/f81ouAM5ZQHK2xZ40t3BKXky sFQBkmEFBb+MiAs7Sr46i8S1ZU7ae7ttu8OR0Q4tUVYXwLJZr2k/I5aDFpgeu8RvI9gx Vg/GRCHM3CMOSYiH/yDn8GCYzYbjt5aePfRJiytY6meZFgH3Q9X0FYtsINYXBoxcBSTT 0DRg== X-Gm-Message-State: AOAM531Be7bjCAGoBDZwGoL5N4ju6hzpSJ+eUHNeWc4cL5lyAnQth8CT uECKotEzNC+GlyTpmqjcDEuHuzyOwirXWh7tyIenkbcA6bJABA== X-Google-Smtp-Source: ABdhPJzGsDMZLoStikfh66vE054+v0Q3o3xaW/g4KhQ/UoV69B8PFvAniTkP+YdnV+4mot2nvsg5xP/izSv6raHPgkU= X-Received: by 2002:a2e:9089:: with SMTP id l9mr1331358ljg.431.1594884215665; Thu, 16 Jul 2020 00:23:35 -0700 (PDT) MIME-Version: 1.0 References: <20200715135011.42743-1-kirill.shutemov@linux.intel.com> <20200715205428.GA201569@google.com> <20200715222228.jf2pv5u2wyhtc5o5@box> In-Reply-To: From: Naresh Kamboju Date: Thu, 16 Jul 2020 12:53:23 +0530 Message-ID: Subject: Re: [PATCHv2] mm: Fix warning in move_normal_pmd() To: Linus Torvalds Cc: "Kirill A. Shutemov" , Joel Fernandes , "Kirill A. Shutemov" , Andrew Morton , Linux-MM , Linux Kernel Mailing List , William Kucharski Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: ED184180142F8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 Thu, 16 Jul 2020 at 12:07, Naresh Kamboju wrote: > > On Thu, 16 Jul 2020 at 04:49, Linus Torvalds > wrote: > > > > On Wed, Jul 15, 2020 at 4:04 PM Linus Torvalds > > wrote: > > > > > > It *might* be as simple as this incremental thing on top > > > > No, it needs to be > > > > + if (*old_addr + *len < old->vm_end) > > + return; > > > > in try_to_align_end(), of course. > > > > Now I'm going for a lie-down, because this cross-eyed thing isn't working. > > > Just want to double check. > Here is the diff after those two patches applied. Please correct me if > it is wrong. > This patch applied on top of Linus mainline master branch. > I am starting my test cycles. Sorry this patch (the below pasted ) did not solve the reported problem. I still notice warning [ 760.004318] ------------[ cut here ]------------ [ 760.009039] WARNING: CPU: 3 PID: 461 at mm/mremap.c:230 move_page_tables+0x818/0x840 [ 760.016848] Modules linked in: x86_pkg_temp_thermal fuse [ 760.022220] CPU: 3 PID: 461 Comm: true Not tainted 5.8.0-rc5 #1 [ 760.028198] Hardware name: Supermicro SYS-5019S-ML/X11SSH-F, BIOS 2.2 05/23/2018 [ 760.035651] EIP: move_page_tables+0x818/0x840 ref: https://lkft.validation.linaro.org/scheduler/job/1574277#L12221 > > --- > mm/mremap.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 73 insertions(+) > > diff --git a/mm/mremap.c b/mm/mremap.c > index 6b153dc05fe4..4961c18d2008 100644 > --- a/mm/mremap.c > +++ b/mm/mremap.c > @@ -254,6 +254,77 @@ static bool move_normal_pmd(struct vm_area_struct > *vma, unsigned long old_addr, > > return true; > } > + > +#define ADDR_BEFORE_PREV(addr, vma) \ > + ((vma)->vm_prev && (addr) < (vma)->vm_prev->vm_end) > + > +static inline void try_to_align_start(unsigned long *len, > + struct vm_area_struct *old, unsigned long *old_addr, > + struct vm_area_struct *new, unsigned long *new_addr) > +{ > + if (*old_addr > old->vm_start) > + return; > + > + if (ADDR_BEFORE_PREV(*old_addr & PMD_MASK, old)) > + return; > + > + if (ADDR_BEFORE_PREV(*new_addr & PMD_MASK, new)) > + return; > + > + /* Bingo! */ > + *len += *new_addr & ~PMD_MASK; > + *old_addr &= PMD_MASK; > + *new_addr &= PMD_MASK; > +} > + > +/* > + * When aligning the end, avoid ALIGN() (which can overflow > + * if the user space is the full address space, and overshoot > + * the vm_start of the next vma). > + * > + * Align the upper limit down instead, and check that it's not > + * in the same PMD as the end. > + */ > +#define ADDR_AFTER_NEXT(addr, vma) \ > + ((vma)->vm_next && (addr) > (PMD_MASK & (vma)->vm_next->vm_start)) > + > +static inline void try_to_align_end(unsigned long *len, > + struct vm_area_struct *old, unsigned long *old_addr, > + struct vm_area_struct *new, unsigned long *new_addr) > +{ > + if (*old_addr < old->vm_end) > + return; > + > + if (ADDR_AFTER_NEXT(*old_addr + *len, old)) > + return; > + > + if (ADDR_AFTER_NEXT(*new_addr + *len, new)) > + return; > + > + /* Mutual alignment means this is same for new/old addr */ > + *len = ALIGN(*new_addr + *len, PMD_SIZE) - *new_addr; > +} > + > +/* > + * The PMD move case is much more efficient, so if we have the > + * mutually aligned case, try to see if we can extend the > + * beginning and end to be aligned too. > + * > + * The pointer dereferences look bad, but with inlining, the > + * compiler will sort it out. > + */ > +static inline void try_to_align_range(unsigned long *len, > + struct vm_area_struct *old, unsigned long *old_addr, > + struct vm_area_struct *new, unsigned long *new_addr) > +{ > + if ((*old_addr ^ *new_addr) & ~PMD_MASK) > + return; > + > + try_to_align_start(len, old, old_addr, new, new_addr); > + try_to_align_end(len, old, old_addr, new, new_addr); > +} > +#else > +#define try_to_align_range(len,old,olda,new,newa) do { } while(0); > #endif > > unsigned long move_page_tables(struct vm_area_struct *vma, > @@ -272,6 +343,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma, > old_addr, old_end); > mmu_notifier_invalidate_range_start(&range); > > + try_to_align_range(&len, vma, &old_addr, new_vma, &new_addr); > + > for (; old_addr < old_end; old_addr += extent, new_addr += extent) { > cond_resched(); > next = (old_addr + PMD_SIZE) & PMD_MASK; > -- > 2.27.0 > > > > > Linus > > - Naresh