Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1114602rwd; Thu, 18 May 2023 08:08:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5N8OMgzIrBtQfLdR0hvcyKF0wVp/GKB1Ppn7v+hwWQvVFDwfEZMQm6+qG3onC+CZ7u739G X-Received: by 2002:a05:6a21:6d8e:b0:100:fe72:0 with SMTP id wl14-20020a056a216d8e00b00100fe720000mr3035421pzb.43.1684422499836; Thu, 18 May 2023 08:08:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684422499; cv=none; d=google.com; s=arc-20160816; b=0O9c6EOzl8MYQrCPuEt+Obp7efecFH4y197KAIsOrovPWUBM+FT376i4LNqtodsYO3 NmCStoKcbpCh6nNJ/Z3ZUW+Pwx+2x37GWpLCig/RhDppzrkDFnPXm4tYfyw5ixnLh01J BD8RHmq7HoVlxnnFo7WuAf3Py8cC70Bjb1D6WMwI/vf7gL5XcrQMJjuv9WF+7DwRDUsy gSHw+6SIRHlu281wvRKDbyQhm1GbVdx/WsvrVSzk3pG5ylsIJd05MSnU5GNy+71T5tTD y+Kzow96bDqYtvYU9+Rjmr+Hq1KMsj7iuMGHSMEdBfEfL+wEJgH8rQ6PcA+d2qYLMvGH Skuw== 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=obhgUzt9f6O2yq2OScYiSLzmPyBEa1gRm2MaMRKe5ow=; b=lFEsIRbf6pyWYBkJ+4O6EOXZpgAHWxPre1qx3fI95SNSo4kWeRn81FMCzbgsIhrD0C XZdTR82sjACF9qan9HfJMOac9sK6a0/KkVbuJ1nouwgNE8++Tjoub7Rh2fZDfBV7jx0y Cj8nmt+SBO4rTLyAxvHkmcX+tm9Xf6cJGHCccfpXdL7Rykel0l7R+H7Ji4HwJMTRDCL2 XtvNVxQeA8KbHPFTFdcfD0ITkYPrZXX50H/SHmOkNsR3J3LhsMwTw3/dQ2gGETfb4kRK CNKPKYxxybkkdWhftKnXQ8CysCnFvAZ23XcHt9aG/roipOGqe+rk51AKTSOGhS8l5fp2 vHjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Xhj0iznq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020a63b10f000000b0050f89421524si1636203pgf.319.2023.05.18.08.08.05; Thu, 18 May 2023 08:08:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Xhj0iznq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231720AbjEROop (ORCPT + 99 others); Thu, 18 May 2023 10:44:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbjEROon (ORCPT ); Thu, 18 May 2023 10:44:43 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52811E1 for ; Thu, 18 May 2023 07:44:42 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-3f4f47336bcso11132421cf.3 for ; Thu, 18 May 2023 07:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1684421081; x=1687013081; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=obhgUzt9f6O2yq2OScYiSLzmPyBEa1gRm2MaMRKe5ow=; b=Xhj0iznqnM9003UxxM6XKADJGQU/zEHYZmW3Aa8pXsAuPHpfiPqC0/mDD8QQPG6ZqN 0Y7LTj1fvE63plVXwi6gAVcWC520Y0rnqcYRtXQ/i3CqBeJo/Vpfp2LahF65MVyBrlZr PIDybiXdTvDRLOLmztgSUkqooX6wim0hVkbQU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684421081; x=1687013081; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=obhgUzt9f6O2yq2OScYiSLzmPyBEa1gRm2MaMRKe5ow=; b=I7xQ96NKPpkx0OS+TrwKV0y01YXvZQbUleiZO5cygk3pmcJcqhKG39HfCBRedwK5P8 E/XCl3igruokymcC+XFqiiLdGnEYJi0+4yD2wDVfnTXw24s9TR57xv+gAP+dnKt6Ki0z RPZTwSW65IDlaPb2P3QiJ/OUX1w10t8EuwqGNsvD83qwyzwbkE38JWCupGO/zRXGDJsf jPF63DbZGfcPNX6QCo4ZDlwrQZTekEvNGu7WZE129BAPEstTEfSiyiVlN8JYwtrYVCR5 5FgCNLVNFCeVKXev7aFUfTNkDypixEVlLM+DFovlFBloC1b0piAy34s9wKdh9xTmYSC3 /fRg== X-Gm-Message-State: AC+VfDzZwtPtOSU233kMSUJYUVmFMhPFNBPX4sA884Xi71kkloGIrD6u 114zg36BKpGSXZWstY9elW3XFw== X-Received: by 2002:ac8:5b88:0:b0:3f5:37eb:1fba with SMTP id a8-20020ac85b88000000b003f537eb1fbamr5443748qta.23.1684421081388; Thu, 18 May 2023 07:44:41 -0700 (PDT) Received: from localhost (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id b28-20020a05620a127c00b0075941df3365sm436934qkl.52.2023.05.18.07.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 07:44:40 -0700 (PDT) Date: Thu, 18 May 2023 14:44:40 +0000 From: Joel Fernandes To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" Subject: Re: [PATCH RFC 1/4] mm/mremap: Optimize the start addresses in move_page_tables() Message-ID: <20230518144440.GA813364@google.com> References: <20230518021825.712742-1-joel@joelfernandes.org> <20230518021825.712742-2-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLACK 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 Wed, May 17, 2023 at 09:12:07PM -0700, Linus Torvalds wrote: > On Wed, May 17, 2023 at 7:18 PM Joel Fernandes (Google) > wrote: > > > > This warning will only trigger when there is mutual alignment in the > > move operation. A solution, as suggested by Linus Torvalds [2], is to > > initiate the copy process at the PMD level whenever such alignment is > > present. > > So this patch is actually simpler than I thought it would be. > > But I'm a bit nervous about it. In particular, it ends doing > > old_end = old_addr + len; > ... expand old_addr/new_addr down to the pmd boundary .. > return len + old_addr - old_end; /* how much done */ > > doesn't that return value end up being nonsensical now? Aargh, Sorry to miss that. Yes, it ends up being bogus in the case where the loop broke out early due to failure (but only on the first PMD move failure AFAICS). In the success case (or failures after the first PMD move), it does not matter because old_addr is updated to what it was without the optimization. > In particular, I think it can return a *negative* value, because of > how old_addr was moved down, and the "now much done" might indeed be > "negative" in the sense that it failed the move even "before" the > original starting point. > > And that negative value then ends up being a large positive one as an > "unsigned long", of course. > > So I get the feeling that it wants something like > > if (old_addr + len < old_end) > return 0; I think that will fix it (thanks!). The main thing I think is to not mess up the second call to move_page_tables() in mremap where it tries to move the half-moved stuff back: move_page_tables(new_vma, new_addr, vma, old_addr, moved_len, true); There moved_len comes from the return value of the first call to move_page_tables(). If we realigned, and then the first PMD alloc failed, moved_len might be negative as you pointed. If the first PMD move passed, then there is no issue as I mentioned above. I will fix this in the next revision and also add a test case for this, I am wondering how to test it without some kind of error-injection to make the first PMD copy fail. In any case, I will try to hack my local kernel to test that. thanks, - Joel > there at the end. > > But maybe there is something in there that guarantees that that case > never happens. I didn't think too deeply about it, I just felt this > looked odd. > > Linus