Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1674648ioo; Sun, 22 May 2022 23:57:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOBLucjpwYgSc1nRHnqcN2FWGe2nWTL/pxK2mUx+ESuuLD0/iQ/3I3xy68zua4r/h7h4Qi X-Received: by 2002:a17:902:f303:b0:161:4e12:6766 with SMTP id c3-20020a170902f30300b001614e126766mr21686206ple.39.1653289067287; Sun, 22 May 2022 23:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653289067; cv=none; d=google.com; s=arc-20160816; b=iEBKjnxvtetPEX+VTSVdUJBb6RH28gWWjzygPWcHwcsTlF8jNMveEUN9uflq4qIS2o Bh5z0/pldtfG6nqMwTsPdtdiKSmrc9H3uu3JHHDel+8MG5aBhrVJk09QBvNhSw1pOmnX IrfFcsRRxhbsrNnj5YIUS4W9fNb/G+9pDiNzcbrlubpkOrQ/D5qaQy5Tur1wp8L719N/ +V+5ZkPaGXYSwsYz7ycSL/fClCxmesAvjUz8ftcbSCZBEwdwMC/T38aCKSqYjwNXXc9v XqLub+Q6U5T3/uiS2m5qJ75IC2683iY/ThFrJTfdLWdW2Q4K/Su19Mn6Ao4X6lexMJ6C dqlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3BeEGshpUebf40S3dI2nHaMHUGbrc9YgGRUe6v3NrQI=; b=xQkZmgT0lkIrOsHlBBihgjUGNdLNrhdPTk8Q0dg7G4y6wdvih3qR2gk3EYoeFmOLKi h4ktmI0UctsXqvHd7ksMDx8fiJMh69m2HKLgfX0iWLsX2PI6ojhxWPhOkb6XCoKJhPwf Aa0m3cMSkBkMwM4fYz5t2XiHZfrFDrrKYWNf1gxWDWISeMOlGpn0XLWscFjc+OHeLWWB 2Kl37UEECmXuxVo9CezEAW/05EOrGZnsO5m/onUdmYV86Z07PmK92MtF3xh2loVT3YZD f4VXY1CzoK9XW0IIdUbu4X7XEAbSYgI5pA42K9fMWcLJFe7De7C4NqFady4Mc9bnvd/v ektQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20210112.gappssmtp.com header.s=20210112 header.b=6qt22nK9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 14-20020a63000e000000b003c6157157b1si9883587pga.144.2022.05.22.23.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 23:57:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20210112.gappssmtp.com header.s=20210112 header.b=6qt22nK9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ECBB844A00; Sun, 22 May 2022 23:23:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349891AbiETNjg (ORCPT + 99 others); Fri, 20 May 2022 09:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349096AbiETNjf (ORCPT ); Fri, 20 May 2022 09:39:35 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39482169E3B for ; Fri, 20 May 2022 06:39:34 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id p22so14353316lfo.10 for ; Fri, 20 May 2022 06:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=3BeEGshpUebf40S3dI2nHaMHUGbrc9YgGRUe6v3NrQI=; b=6qt22nK9IyDROp+1mPdWrxlvzi6NjO9eSG5Nen/b2A4439rifjlgxwQdu1H0oZvaEI zsREZJlUH9Q59JA4/xx902iUi8jdSn8cRb9yxLBKOpTVgUEBc8mktfK/Gl0D93Izd/ul Onz+P2Nvnbw9a32QqyeG9cgY4Z4J9mdF8qFpYKjfy+87PufYse2QuuIZCUVPPDlNvAKE ik5nL2LZ9Bk16e0vHts9nXx0icITt1ybjlmSAmRoFKOj9CpUtY5Q+f5Jk/vtT2A2l3gX tjGCSyXpFudAPCrNP09RJNhINqh3uz45V4pH4Lmn9DWgW4Uk7j2mupibV5+qfh9CEpti MVrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=3BeEGshpUebf40S3dI2nHaMHUGbrc9YgGRUe6v3NrQI=; b=kEBE965qPYrinNpYl6gGR4uNfDfTU2/jsBMfJwLwsNt4L2RE6GcS4ox8OLQL/T7A5H tGX1/O5Y1Nyn1PA4kklFgcdyDLDEZXa8fGxxOd/EzJPWCNDjJNsVClEbI3Rd/nns41vk 5FvBUBtzCxs21jm7gLh7CIjitBzzALgCjxVvj7mJ9QxvoYpAfyidu+DdtsoRzuTsydxU A/ICjtDcTn0zfN8Vti9pkfULuH7i9Lmy0D1MCCL1ssPno2Uvn/aFiPfInopEVfMixcgC /8XKsVaAAxWgXMhLXzybCAXQ4YM8p2Xu02sm/wJoC1uTaPvhaZmnUw5aE3HZCgzQbhNk 1rrA== X-Gm-Message-State: AOAM532d46XyKuxRSqD8w/+zO/7Ub/PfL97XybY+7LBwt3yiQ5SjHHJI 0+lwYpN0BevUgSDHF/1UJ5t/Kg== X-Received: by 2002:a19:4f04:0:b0:477:b6c7:9771 with SMTP id d4-20020a194f04000000b00477b6c79771mr6778897lfb.182.1653053972054; Fri, 20 May 2022 06:39:32 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id e7-20020a2e9847000000b0024f3d1daeacsm323659ljj.52.2022.05.20.06.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 06:39:31 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id C70E6104AAB; Fri, 20 May 2022 16:41:24 +0300 (+03) Date: Fri, 20 May 2022 16:41:24 +0300 From: "Kirill A. Shutemov" To: Jakub =?utf-8?Q?Mat=C4=9Bna?= Cc: linux-mm@kvack.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, vbabka@suse.cz, mhocko@kernel.org, mgorman@techsingularity.net, willy@infradead.org, liam.howlett@oracle.com, hughd@google.com, riel@surriel.com, rostedt@goodmis.org, peterz@infradead.org, david@redhat.com Subject: Re: [RFC PATCH v3 2/6] [PATCH 2/6] mm: add merging after mremap resize Message-ID: <20220520134124.6glbfzhrgzutfor6@box.shutemov.name> References: <20220516125405.1675-1-matenajakub@gmail.com> <20220516125405.1675-3-matenajakub@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220516125405.1675-3-matenajakub@gmail.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 16, 2022 at 02:54:01PM +0200, Jakub Matěna wrote: > When mremap call results in expansion, it might be possible to merge the > VMA with the next VMA which might become adjacent. This patch adds > vma_merge call after the expansion is done to try and merge. > > Signed-off-by: Jakub Matěna > --- > mm/mremap.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/mm/mremap.c b/mm/mremap.c > index 303d3290b938..75cda854ec58 100644 > --- a/mm/mremap.c > +++ b/mm/mremap.c > @@ -9,6 +9,7 @@ > */ > > #include > +#include > #include > #include > #include > @@ -1022,8 +1023,10 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, > } > } > > - if (vma_adjust(vma, vma->vm_start, addr + new_len, > - vma->vm_pgoff, NULL)) { > + if (!vma_merge(mm, vma, addr + old_len, addr + new_len, > + vma->vm_flags, vma->anon_vma, vma->vm_file, > + vma->vm_pgoff + (old_len >> PAGE_SHIFT), vma_policy(vma), > + vma->vm_userfaultfd_ctx, anon_vma_name(vma))) { Hm. Don't you need to update 'vma' with result of vma_merge()? 'vma' is used below the point and IIUC it can be use-after-free. -- Kirill A. Shutemov