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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC62EC71153 for ; Mon, 28 Aug 2023 18:32:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB5D28E002B; Mon, 28 Aug 2023 14:32:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A65AE8E0029; Mon, 28 Aug 2023 14:32:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92E188E002B; Mon, 28 Aug 2023 14:32:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 814DB8E0029 for ; Mon, 28 Aug 2023 14:32:45 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E115B1605A7 for ; Mon, 28 Aug 2023 18:32:44 +0000 (UTC) X-FDA: 81174359448.13.8244DC9 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) by imf20.hostedemail.com (Postfix) with ESMTP id 1F8661C0020 for ; Mon, 28 Aug 2023 18:32:42 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=joelfernandes.org header.s=google header.b=nFrb0GNP; spf=pass (imf20.hostedemail.com: domain of joel@joelfernandes.org designates 209.85.166.47 as permitted sender) smtp.mailfrom=joel@joelfernandes.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693247563; a=rsa-sha256; cv=none; b=tEhSwmHSghAvHJxXCwhJ8Qi1u+MX4cVBuFm8gkJ4KCBVYNtV+9NkqsQ+sR1XPN7+CaEvUd /NrxW74e608Cz4HFK/fvgymflFRf2r0AeL02E+aqUz3ZWBq2T86Kpu1Oy8N5Pu9HtWXR1D vBN5P7E04Rd0TsRQDAdXXz4G+2odxto= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=joelfernandes.org header.s=google header.b=nFrb0GNP; spf=pass (imf20.hostedemail.com: domain of joel@joelfernandes.org designates 209.85.166.47 as permitted sender) smtp.mailfrom=joel@joelfernandes.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693247563; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vlH1F433gTQcUsEtLxKZUpHNUAMNhRhkYP0DbGmnz0M=; b=xqEzqs21rzuN7Ta8Fs1Xg/N52qljwCIw6TxQFfrTjSOiHWabTzxQi+n3IilNV0/51FNiZz adFZQGsPw8inaNe4uXJIS2jWrdYt8xE7HDEawPB3eqM+ltJG7gqiGocIlLSMsRIQ7PVCG1 ea21fnQCP2QHuif5q34ZDSD6N9V9RF4= Received: by mail-io1-f47.google.com with SMTP id ca18e2360f4ac-792726d3aeeso121539439f.0 for ; Mon, 28 Aug 2023 11:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1693247562; x=1693852362; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=vlH1F433gTQcUsEtLxKZUpHNUAMNhRhkYP0DbGmnz0M=; b=nFrb0GNPs/wTaQ8nE94D2sT5zOH75np79gen6grO8f06qzDww14rcelBIZ8AryJmtx ykbAJyUCuQOhz4qfjy3SCSQ6Zk7nW9JNYgSZn4AUNdQ4WCSRwZ8/RtnIKDm68XSqo3Zh jcaqMY9hihGchweqJvZBajTMOa2WtIolhXueg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693247562; x=1693852362; h=in-reply-to: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=vlH1F433gTQcUsEtLxKZUpHNUAMNhRhkYP0DbGmnz0M=; b=cuMfODCyYW/I/2V609b7mKOTHGxt4i1wSTdbcBQxvTusAx1tjaorRVoCWmGCTvlPxn VzTqRhWou/KKg/d4yD2IBYMzbugkUWsL0qasv8wvV+NgNQTX7FGYWD0vEiubGaYzpGlz bLQOudP7ObF9htAWRoGpciC0QJCnjrPm2acdXOVvYnN0N+Nxu1ZLfEdG7/eNEfXI0WNY 7vjmkllRdO6BD0fS2kzyr2gHRTsUPfeNI5c68SQfNbonkXRjQ9x0NoGQtpi22Aaf/c0O +NMvlyy8Xf6VElhy34v9/Qku4geXj+M/XHNahbGL4jAPa+pVLueXLnBAUgRIB+ngbTf2 AmYg== X-Gm-Message-State: AOJu0YxELeSXZANRyMAabailmuil2kJOczHSMb3ItptCdi1KD+7AVAkM BZZJzR5SSDV6PuuICz/dpDzsVQ== X-Google-Smtp-Source: AGHT+IFBKaZS5q2OBtEoOJhIJR2uV7Jev+fXXzpRuiK0lkyhalyR6TxJ2IhnOS+W5HHEfqZbHItCdg== X-Received: by 2002:a5d:9718:0:b0:786:f47b:c063 with SMTP id h24-20020a5d9718000000b00786f47bc063mr17281322iol.21.1693247562178; Mon, 28 Aug 2023 11:32:42 -0700 (PDT) Received: from localhost (156.190.123.34.bc.googleusercontent.com. [34.123.190.156]) by smtp.gmail.com with ESMTPSA id f7-20020a6bdd07000000b007922dc27aa6sm2677118ioc.24.2023.08.28.11.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 11:32:41 -0700 (PDT) Date: Mon, 28 Aug 2023 18:32:40 +0000 From: Joel Fernandes To: Lorenzo Stoakes Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Linus Torvalds , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra Subject: Re: [PATCH v5 2/7] mm/mremap: Allow moves within the same VMA Message-ID: <20230828183240.GA1621761@google.com> References: <20230822015501.791637-1-joel@joelfernandes.org> <20230822015501.791637-3-joel@joelfernandes.org> <46196ba1-c54d-4c1d-954f-a0006602af99@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46196ba1-c54d-4c1d-954f-a0006602af99@lucifer.local> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1F8661C0020 X-Stat-Signature: 614zhnui958r4ybefm1b3aadp66snca6 X-Rspam-User: X-HE-Tag: 1693247562-437620 X-HE-Meta: U2FsdGVkX19qB7ru6jONeFO0XOCOdMAQvHUPg/qLoFhWGu6Dg4lq1qMguXfE55Pr4eAaZm9xKE2IFv9jUHfLIGGhrI1Ycae1zF08XFcxHVmIx/Gg1AtHKKQGRSW6WnhCz528xxCkya/j65xuTFsvds8yfjVtVONj518cFCifUYKK8kzwZN9oltYyIO8Euft59FwRR+y8o2mFrrds02TMvsjHnC1XTRpOA1/g97Zo4yObqnx7n/WT5/nQyTk3IoI9H0LuChXzP90IAmIC+bT9NgZ4MxYlRZ35H/jwIiB0Kfa06xtNGGqodKVorZ3ST90f8sUK3caIaKsuYvcsF1Pg9cSHtR+XA98zpgM1UWe+V97TMfy7Ub/6nifI/Pq77ZMi8891rEz0CamTNysObUg/nA9mVJnep80TwJcuuUaY9P/5HxBHo33y19oOpWNChb006jMZIXxY/vBoeEoaPFtvdiMFlonEzlYRYDDXVURAtEXBxHZ/eCqNu7ztX2EeHUuy5dbYtjnPFnJZ+lZl1v7i10v4l51HxIm68JncyG/UQwBboGNVAcyp0v99Fc/7Vbqixl9NsbMLyaPGC2HKA92IaKUpo1Qjeb17X+G6+iW06NgaJ0njFHm1D0uVUidoWtAqxMX7fu0Srpy1pMVhUckj+63rwUG9zwBTgL8DPQ0chNuYsNVnPyItEV1RrDoVtahp7hd0nfOG69pkIwTaOuw36lcmCOqQhs0vDHzMW/k2ZjClCvrisc74/Px6ylunQiFPoNiUg77oNSuGNaooATy5MfzwXyaoAXA9dPcU1es287qB3+nP1nR2LRC69zjBzgZerNoVXMCOZOeNDMdV6m4u6emNXPBP7OTbWmayJ1Kfqv4AxY8YxCj2O8+P2G5VqlY+HgdFD42Clq0E7G5cZPUr+76tdPCthLc1X2COxwypWJvxV6qXpHTSiXh1Q22aCoo2NOmAklZSNJas+clPDco 7j8QhTMt i8HkQHYqqcg9najVZRAL5CWcZsTI0XKOM9NBCIWW0CZes2hVQQpRdf6kPSv0Vkx3Lr3h1EzlL4O5TTJTfZxeH+lUfXc445CJuD81M4+5YfCvy6AAlbLVONZ6k4rpWRdsOJRjEBHK/JcPrwK6XbElYRcBvPDowuIXjsWUxehDLp+FSSyKhM5NLV03is9RH7t57thXz0e3/sa7uZRibpaYOQ+Tl7LW5PIxbnVLhOHQ0XGkQCZN0UAu3sTeAYcpXZQR0Y9vGn1QaBi5CfdFI0myx22JD2ydhi2oqvQb0Quxplo/3nROteSMwHCUUxueRWZ1zcOaJ 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 Sun, Aug 27, 2023 at 10:21:14AM +0100, Lorenzo Stoakes wrote: [..] > > > > /* > > * Flags used by change_protection(). For now we make it a bitmap so > > diff --git a/mm/mremap.c b/mm/mremap.c > > index 035fbf542a8f..06baa13bd2c8 100644 > > --- a/mm/mremap.c > > +++ b/mm/mremap.c > > @@ -490,12 +490,13 @@ static bool move_pgt_entry(enum pgt_entry entry, struct vm_area_struct *vma, > > } > > > > /* > > - * A helper to check if a previous mapping exists. Required for > > - * move_page_tables() and realign_addr() to determine if a previous mapping > > - * exists before we can do realignment optimizations. > > + * A helper to check if aligning down is OK. The aligned address should fall > > + * on *no mapping*. For the stack moving down, that's a special move within > > + * the VMA that is created to span the source and destination of the move, > > + * so we make an exception for it. > > */ > > static bool can_align_down(struct vm_area_struct *vma, unsigned long addr_to_align, > > - unsigned long mask) > > + unsigned long mask, bool for_stack) > > { > > unsigned long addr_masked = addr_to_align & mask; > > > > @@ -504,7 +505,7 @@ static bool can_align_down(struct vm_area_struct *vma, unsigned long addr_to_ali > > * of the corresponding VMA, we can't align down or we will destroy part > > * of the current mapping. > > */ > > - if (vma->vm_start != addr_to_align) > > + if (!for_stack && vma->vm_start != addr_to_align) > > return false; > > I'm a little confused by this exception, is it very specifically for the > shift_arg_pages() case where can assume we are safe to just discard the > lower portion of the stack? > > Wouldn't the find_vma_intersection() line below fail in this case? I may be > missing something here :) I think you are right. In v4, this was not an issue as we did this: + if (!for_stack && vma->vm_start != addr_to_align) + return false; + + cur = find_vma_prev(vma->vm_mm, vma->vm_start, &prev); + if (WARN_ON_ONCE(cur != vma)) + return false; Which essentially means this patch is a NOOP in v5 for the stack case. So what we really want is the VMA previous to @vma and whether than subsumes the masked address. Should I just change it back to the v4 version then as above for both patch 1 and 2 and carry your review tags? This is also hard to test as it requires triggering the execve stack move case. Though it is not a bug (as it is essentially a NOOP), it still would be nice to test it. This is complicated by also the fact that mremap(2) itself does not allow overlapping moves. I could try to hardcode the unfavorable situation as I have done in the past to force that mremap warning. thanks, - Joel