From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08142C678DB for ; Fri, 24 Feb 2023 10:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbjBXKAp (ORCPT ); Fri, 24 Feb 2023 05:00:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229641AbjBXKAn (ORCPT ); Fri, 24 Feb 2023 05:00:43 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AAE065AF for ; Fri, 24 Feb 2023 02:00:42 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3470733FFB; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bQMJWpenP6OEu3AR0STwSIwzPSjq3AkhCnZCUwU4em4=; b=eOJS6frdV5UgXb66LQirAS9ZQ/sN6R7VVfUyUQO93GuJ7YDYy+gCcVKQpNK3ME6ofsbj+u qNoA75ZP+SCcWx6iNzv+kDslqOfh6KioPYBLkFW6Vm5wsP0uKlXfxMhG+f33PGKL2I+nON vlLQQ7NCxHTEb09vqsuUXAqKdYuwsts= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bQMJWpenP6OEu3AR0STwSIwzPSjq3AkhCnZCUwU4em4=; b=8uSvZSyN2Kf6MO7A0WVXIqBZpcPjWwSrokqUDvePSMNZCMXdTvp4Mz2BcsSD0D1/fRbS9I yWrCVUnAmFfSuECg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1B8B213A3C; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qEYfBsmK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:41 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 01/11] mm/mremap: fix dup_anon_vma() in vma_merge() case 4 Date: Fri, 24 Feb 2023 11:00:12 +0100 Message-Id: <20230224100022.11268-2-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In case 4, we are shrinking 'prev' (PPPP in the comment) and expanding 'mid' (NNNN). So we need to make sure 'mid' clones the anon_vma from 'prev', if it doesn't have any. After commit 0503ea8f5ba7 ("mm/mmap: remove __vma_adjust()") we can fail to do that due to wrong parameters for dup_anon_vma(). The call is a no-op because res =3D=3D next, adjust =3D= =3D mid and mid =3D=3D next. Fix it. Fixes: 0503ea8f5ba7 ("mm/mmap: remove __vma_adjust()") Signed-off-by: Vlastimil Babka --- mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index 20f21f0949dd..740b54be3ed4 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -973,7 +973,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, vma_end =3D addr; adjust =3D mid; adj_next =3D -(vma->vm_end - addr); - err =3D dup_anon_vma(res, adjust); + err =3D dup_anon_vma(adjust, prev); } else { vma =3D next; /* case 3 */ vma_start =3D addr; --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C89BC61DA3 for ; Fri, 24 Feb 2023 10:01:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbjBXKBF (ORCPT ); Fri, 24 Feb 2023 05:01:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbjBXKAp (ORCPT ); Fri, 24 Feb 2023 05:00:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94CF87281 for ; Fri, 24 Feb 2023 02:00:42 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4F92520F48; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q9S49Vc4wP4VJtPP7U3rbG14z7j2ldE6Nx08zIq8xuM=; b=Tr78MlmMX0kPXukyljCLGjQEOsVHnL+81aPOiUFNTmWYCtN1zBTbSUjhZHB9ftqgxh6RXx 1d0/JvrSAVchiVzVVqY7LrlbCuIfM7hCo7YET2cmVgKdBOi5Mit9xnCwUOptxBQxpHYzO7 lJ5n7/gPoks9SvnG4gspGm5J7AV8Jeg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q9S49Vc4wP4VJtPP7U3rbG14z7j2ldE6Nx08zIq8xuM=; b=vEOsnZ/8cVcvIWVnPLmyKr8eHtE0LGR1ZfQgvL9eEMW+pVrH2LB/t9GOljgkH4mRCNZsPk eHM11z3C2OMk8TDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 364B613246; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OMR0DMmK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:41 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 02/11] mm/mmap/vma_merge: use only primary pointers for preparing merge Date: Fri, 24 Feb 2023 11:00:13 +0100 Message-Id: <20230224100022.11268-3-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In the merging preparation part of vma_merge(), some vma pointer variables are assigned for later execution of the merge, but also read from in the block itself. The code is easier follow and check against the cases diagram in the comment if the code reads only from the "primary" vma variables prev, mid, next instead. No functional change. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 740b54be3ed4..0a8b052e3022 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -950,16 +950,16 @@ struct vm_area_struct *vma_merge(struct vma_iterator = *vmi, struct mm_struct *mm, is_mergeable_anon_vma(prev->anon_vma, next->anon_vma, NULL)) { remove =3D mid; /* case 1 */ vma_end =3D next->vm_end; - err =3D dup_anon_vma(res, remove); + err =3D dup_anon_vma(prev, mid); if (mid !=3D next) { /* case 6 */ remove2 =3D next; - if (!remove->anon_vma) - err =3D dup_anon_vma(res, remove2); + if (!mid->anon_vma) + err =3D dup_anon_vma(prev, next); } } else if (merge_prev) { err =3D 0; /* case 2 */ if (mid && end > mid->vm_start) { - err =3D dup_anon_vma(res, mid); + err =3D dup_anon_vma(prev, mid); if (end =3D=3D mid->vm_end) { /* case 7 */ remove =3D mid; } else { /* case 5 */ @@ -972,8 +972,8 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, if (prev && addr < prev->vm_end) { /* case 4 */ vma_end =3D addr; adjust =3D mid; - adj_next =3D -(vma->vm_end - addr); - err =3D dup_anon_vma(adjust, prev); + adj_next =3D -(prev->vm_end - addr); + err =3D dup_anon_vma(mid, prev); } else { vma =3D next; /* case 3 */ vma_start =3D addr; @@ -982,7 +982,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, err =3D 0; if (mid !=3D next) { /* case 8 */ remove =3D mid; - err =3D dup_anon_vma(res, remove); + err =3D dup_anon_vma(next, mid); } } } --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ACFCC64ED8 for ; Fri, 24 Feb 2023 10:00:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbjBXKAw (ORCPT ); Fri, 24 Feb 2023 05:00:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbjBXKAo (ORCPT ); Fri, 24 Feb 2023 05:00:44 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4D289015 for ; Fri, 24 Feb 2023 02:00:42 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6BBC4340DF; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y+XTfDYhuPvIRFRoJO2lR/Vb/n6vI/gDEgoJ+zMr3So=; b=xNyWzaIm8640lmbpUF9hrw5F0n2zkVBQejbHgDyQ8faqF2gyAUUwFlzi+7Bd6ugacLwJ3+ emBXxTmjLsmeEoVjEbTPGf0Gq3hjyIYGVcZ78NKc7M++yuDiV8OefuJNgyI4NaIu+2Xf68 yNJVWUT/+HlezVd9U36R1MXDRzgfmBA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y+XTfDYhuPvIRFRoJO2lR/Vb/n6vI/gDEgoJ+zMr3So=; b=x7ev2C++vaNNNQot1MtoWU4bQPeBB0xTSY2buZz9yO3ho1L1vEHbPrlWZQr+3VKXSFSvV0 YBrgBPDzmutKwiDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 50A0D13A3C; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AEwoE8mK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:41 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 03/11] mm/mmap/vma_merge: use the proper vma pointer in case 3 Date: Fri, 24 Feb 2023 11:00:14 +0100 Message-Id: <20230224100022.11268-4-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In case 3 we we use 'next' for everything but vma_pgoff. So use 'next' for that as well, instead of 'mid', for consistency. Then in case 8 we have to use 'mid' explicitly, which should also make the intent more obvious. Adjust the diagram for cases 1-3 in the comment to match the code - we are using 'next' for case 3 so mark the range with XXXX instead of NNNN. For case 2 that's a no-op as the code doesn't touch 'next' or 'mid'. For case 1 it's now wrong but that will be fixed next. No functional change. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 0a8b052e3022..1af4c9bc2c87 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -857,11 +857,11 @@ can_vma_merge_after(struct vm_area_struct *vma, unsig= ned long vm_flags, * mmap, brk or case 4 below case 5 below * mremap move: * AAAA AAAA - * PPPP NNNN PPPPNNNNXXXX + * PPPP XXXX PPPPNNNNXXXX * might become might become * PPPPPPPPPPPP 1 or PPPPPPPPPPPP 6 or - * PPPPPPPPNNNN 2 or PPPPPPPPXXXX 7 or - * PPPPNNNNNNNN 3 PPPPXXXXXXXX 8 + * PPPPPPPPXXXX 2 or PPPPPPPPXXXX 7 or + * PPPPXXXXXXXX 3 PPPPXXXXXXXX 8 * * It is important for case 8 that the vma NNNN overlapping the * region AAAA is never going to extended over XXXX. Instead XXXX must @@ -978,9 +978,10 @@ struct vm_area_struct *vma_merge(struct vma_iterator *= vmi, struct mm_struct *mm, vma =3D next; /* case 3 */ vma_start =3D addr; vma_end =3D next->vm_end; - vma_pgoff =3D mid->vm_pgoff; + vma_pgoff =3D next->vm_pgoff; err =3D 0; if (mid !=3D next) { /* case 8 */ + vma_pgoff =3D mid->vm_pgoff; remove =3D mid; err =3D dup_anon_vma(next, mid); } --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB71BC677F1 for ; Fri, 24 Feb 2023 10:01:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbjBXKBJ (ORCPT ); Fri, 24 Feb 2023 05:01:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbjBXKAp (ORCPT ); Fri, 24 Feb 2023 05:00:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 145A2902F for ; Fri, 24 Feb 2023 02:00:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BC0165C9DD; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qDnc8EEjpBsvOiKhZLRnNlYD59HvUD8m9uXQyW8ks/U=; b=3SY5VXphxPVip2cwgUzC6lOWoIxu1TXkew7APj+jPzBAf+IlC6a+bzrUBpg63peJcBGHgr cQFjIVUoPpBegCvEWaQsz64Y+C80k+5H8a8EqUuJnoxNEeuD8LnbyXtsDJb82TeOS1psl/ rgX7BNLG6B6ql4Gt/2iGE9eMUm/p2mI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qDnc8EEjpBsvOiKhZLRnNlYD59HvUD8m9uXQyW8ks/U=; b=/jIAtMOp3EUMEalc7cG90G5k2mOZB7brQnDVETi/NY6CKBucBfOljhQr8Ndj1oWYSVgzl4 VsE7Pr3tVwvZdyAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6D09F13246; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iAsMGsmK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:41 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 04/11] mm/mmap/vma_merge: use the proper vma pointers in cases 1 and 6 Date: Fri, 24 Feb 2023 11:00:15 +0100 Message-Id: <20230224100022.11268-5-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Case 1 is now shown in the comment as next vma being merged with prev, so use 'next' instead of 'mid'. In case 1 they both point to the same vma. As a consequence, in case 6, the dup_anon_vma() is now tried first on 'next' and then on 'mid', before it was the opposite order. This is not a functional change, as those two vma's cannnot have a different anon_vma, as that would have prevented the merging in the first place. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 1af4c9bc2c87..704afa278a98 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -605,7 +605,7 @@ static inline void vma_complete(struct vma_prepare *vp, =20 /* * In mprotect's case 6 (see comments on vma_merge), - * we must remove the one after next as well. + * we are removing both mid and next vma's */ if (vp->remove2) { vp->remove =3D vp->remove2; @@ -948,13 +948,14 @@ struct vm_area_struct *vma_merge(struct vma_iterator = *vmi, struct mm_struct *mm, /* Can we merge both the predecessor and the successor? */ if (merge_prev && merge_next && is_mergeable_anon_vma(prev->anon_vma, next->anon_vma, NULL)) { - remove =3D mid; /* case 1 */ + remove =3D next; /* case 1 */ vma_end =3D next->vm_end; - err =3D dup_anon_vma(prev, mid); + err =3D dup_anon_vma(prev, next); if (mid !=3D next) { /* case 6 */ + remove =3D mid; remove2 =3D next; - if (!mid->anon_vma) - err =3D dup_anon_vma(prev, next); + if (!next->anon_vma) + err =3D dup_anon_vma(prev, mid); } } else if (merge_prev) { err =3D 0; /* case 2 */ --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18152C64ED8 for ; Fri, 24 Feb 2023 10:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbjBXKA4 (ORCPT ); Fri, 24 Feb 2023 05:00:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbjBXKAp (ORCPT ); Fri, 24 Feb 2023 05:00:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4244312879 for ; Fri, 24 Feb 2023 02:00:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DAE8F5CF12; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NhRb7OEjq72gATHH+81L0Pb56Fl0vIOvf0iCMN4nYIU=; b=fYzhrj11ULyuqhA8Sagent4MDSnhNWl8R2BrOZiOHNx9yAxGii4l3b/DU9FJdKVwZb0bd0 iZoKwF2poIHgvY3Skpdlp910KuW5uXp9V7NYki4j5qv1RkOA4dGJjqXKV/gBoDa4TRbGko SzQxCkrn6JiYwn+wrf/fDRXMFA6rMNE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NhRb7OEjq72gATHH+81L0Pb56Fl0vIOvf0iCMN4nYIU=; b=pRm1v3KHo1fpox5NF177Fm9sTRwu/iI806K18nFWHsCXkfJoMqk6rxxwdLrBhH4l/+AfFj F7wKC2QJ3L4tXBDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BD04413A3C; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CIaKLcmK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:41 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 05/11] mm/mmap/vma_merge: use the proper vma pointer in case 4 Date: Fri, 24 Feb 2023 11:00:16 +0100 Message-Id: <20230224100022.11268-6-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Almost all cases now use the 'next' pointer for the vma following the merged area, and the cases diagram shows it as XXXX. Case 4 is different as it uses 'mid' and NNNN, so change it for consistency. No functional change. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 704afa278a98..1e4be7174964 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -851,9 +851,9 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigne= d long vm_flags, * vma, PPPPPP is the prev vma specified, and NNNNNN the next vma after: * * AAAA AAAA AAAA - * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPNNNNNN + * PPPPPPNNNNNN PPPPPPXXXXXX PPPPPPNNNNNN * cannot merge might become might become - * PPNNNNNNNNNN PPPPPPPPPPNN + * PPXXXXXXXXXX PPPPPPPPPPNN * mmap, brk or case 4 below case 5 below * mremap move: * AAAA AAAA @@ -972,9 +972,9 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, res =3D next; if (prev && addr < prev->vm_end) { /* case 4 */ vma_end =3D addr; - adjust =3D mid; + adjust =3D next; adj_next =3D -(prev->vm_end - addr); - err =3D dup_anon_vma(mid, prev); + err =3D dup_anon_vma(next, prev); } else { vma =3D next; /* case 3 */ vma_start =3D addr; --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0B3DC677F1 for ; Fri, 24 Feb 2023 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229895AbjBXKA7 (ORCPT ); Fri, 24 Feb 2023 05:00:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbjBXKAp (ORCPT ); Fri, 24 Feb 2023 05:00:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4402F13522 for ; Fri, 24 Feb 2023 02:00:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 00A3A5D557; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O5q8VKPwKROzkXifx9I8bCKvnOQ0g3mM/tusCr5mero=; b=FkZbX3oM6Cbh3D9vF4OTlS4FEtmkzdsoP1fdhtB+vIWGIc+CTLYRlTKX8KbFw92wHRGZPk WRX3XrvuWQ3TQDnYUjAqrVH/yf8LuYVwYmGo8G/fpZtwL8+lMKXrD+HOS1lnD/3r9bkWXe hNJNx1Uv/Wl5YHbSfNRCm14Co1q1myQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O5q8VKPwKROzkXifx9I8bCKvnOQ0g3mM/tusCr5mero=; b=D1veafK8wyctiXKNfsLpv3h/IxiFkoGpNtuFUV49wvQf76mWBKOGpHONdPSxYiiIA9MSzq 0iLisNPxtDRnFcDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DBAD713246; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iFEFNcmK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:41 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 06/11] mm/mmap/vma_merge: initialize mid and next in natural order Date: Fri, 24 Feb 2023 11:00:17 +0100 Message-Id: <20230224100022.11268-7-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It is more intuitive to go from prev to mid and then next. No functional change. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 1e4be7174964..e7d497237f44 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -912,10 +912,11 @@ struct vm_area_struct *vma_merge(struct vma_iterator = *vmi, struct mm_struct *mm, if (vm_flags & VM_SPECIAL) return NULL; =20 - next =3D find_vma(mm, prev ? prev->vm_end : 0); - mid =3D next; - if (next && next->vm_end =3D=3D end) /* cases 6, 7, 8 */ - next =3D find_vma(mm, next->vm_end); + mid =3D find_vma(mm, prev ? prev->vm_end : 0); + if (mid && mid->vm_end =3D=3D end) /* cases 6, 7, 8 */ + next =3D find_vma(mm, mid->vm_end); + else + next =3D mid; =20 /* verify some invariant that must be enforced by the caller */ VM_WARN_ON(prev && addr <=3D prev->vm_start); --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9A59C678DB for ; Fri, 24 Feb 2023 10:01:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229944AbjBXKBC (ORCPT ); Fri, 24 Feb 2023 05:01:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjBXKAp (ORCPT ); Fri, 24 Feb 2023 05:00:45 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E1D1448F for ; Fri, 24 Feb 2023 02:00:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1BA443413E; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X/29+kAqWfgwFrv7r8G7PU+eQXJAc+t/i9BDpOhdUqo=; b=GUdLjF+LpY1y3M8epywaWI0F7OGdErHQpjG3C3UJ57SxBWGh5lQqUIgyJz1ZXFz7HGul6U YdT3mNbbl5CbcI3IOjgeASIChvKtj0p2Z7t9MMVuei4ZL06tfqL5irEuQ46ZoPdTJoQ/xD 0CiYLVJ+8Cc9p6IxbllmJpCSksrJuTg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X/29+kAqWfgwFrv7r8G7PU+eQXJAc+t/i9BDpOhdUqo=; b=FPIaDwkSVcr/iQcbq6I33RPPLmtpUTezoo/59nwdZCq9QD/8WIRT2tPTl2mqxcXSrvVbqY C/fopAhRFlSI8YBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 021D113A3C; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wCRdO8mK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:41 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 07/11] mm/mmap/vma_merge: set mid to NULL if not applicable Date: Fri, 24 Feb 2023 11:00:18 +0100 Message-Id: <20230224100022.11268-8-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There are several places where we test if 'mid' is really the area NNNN in the diagram and the tests have two variants and are non-obvious to follow. Instead, set 'mid' to NULL up-front if it's not the NNNN area, and simplify the tests. Also update the description in comment accordingly. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index e7d497237f44..e05bbcaf7b61 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -848,10 +848,11 @@ can_vma_merge_after(struct vm_area_struct *vma, unsig= ned long vm_flags, * * The following mprotect cases have to be considered, where AAAA is * the area passed down from mprotect_fixup, never extending beyond one - * vma, PPPPPP is the prev vma specified, and NNNNNN the next vma after: + * vma, PPPPPP is the prev vma specified, NNNN is a vma that overlaps + * the area AAAA and XXXXXX the next vma after AAAA: * * AAAA AAAA AAAA - * PPPPPPNNNNNN PPPPPPXXXXXX PPPPPPNNNNNN + * PPPPPPXXXXXX PPPPPPXXXXXX PPPPPPNNNNNN * cannot merge might become might become * PPXXXXXXXXXX PPPPPPPPPPNN * mmap, brk or case 4 below case 5 below @@ -879,9 +880,10 @@ can_vma_merge_after(struct vm_area_struct *vma, unsign= ed long vm_flags, * * In the code below: * PPPP is represented by *prev - * NNNN is represented by *mid (and possibly equal to *next) - * XXXX is represented by *next or not represented at all. - * AAAA is not represented - it will be merged or the function will return= NULL + * NNNN is represented by *mid or not represented at all (NULL) + * XXXX is represented by *next or not represented at all (NULL) + * AAAA is not represented - it will be merged and the vma containing the + * area is returned, or the function will return NULL */ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struc= t *mm, struct vm_area_struct *prev, unsigned long addr, @@ -918,6 +920,9 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, else next =3D mid; =20 + if (mid && end <=3D mid->vm_start) + mid =3D NULL; + /* verify some invariant that must be enforced by the caller */ VM_WARN_ON(prev && addr <=3D prev->vm_start); VM_WARN_ON(mid && end > mid->vm_end); @@ -952,7 +957,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, remove =3D next; /* case 1 */ vma_end =3D next->vm_end; err =3D dup_anon_vma(prev, next); - if (mid !=3D next) { /* case 6 */ + if (mid) { /* case 6 */ remove =3D mid; remove2 =3D next; if (!next->anon_vma) @@ -960,7 +965,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, } } else if (merge_prev) { err =3D 0; /* case 2 */ - if (mid && end > mid->vm_start) { + if (mid) { err =3D dup_anon_vma(prev, mid); if (end =3D=3D mid->vm_end) { /* case 7 */ remove =3D mid; @@ -982,7 +987,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, vma_end =3D next->vm_end; vma_pgoff =3D next->vm_pgoff; err =3D 0; - if (mid !=3D next) { /* case 8 */ + if (mid) { /* case 8 */ vma_pgoff =3D mid->vm_pgoff; remove =3D mid; err =3D dup_anon_vma(next, mid); --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65A8EC64ED8 for ; Fri, 24 Feb 2023 10:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbjBXKBO (ORCPT ); Fri, 24 Feb 2023 05:01:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjBXKAp (ORCPT ); Fri, 24 Feb 2023 05:00:45 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89B1E14498 for ; Fri, 24 Feb 2023 02:00:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 359F33420D; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mjxA/DFoKz/EDUMQDrlO5jdAE8nM57iTZhngVmIGq8k=; b=voy2FpNWabIiH32uIJf9u8966WAPWARBQoSUWNaUlSJD5l5+O5hmhYUqZhVmi07hhk6s0/ QLjdt3iolSQV+mpR3WeJqGuiOkjbuUv6B7Zwt/itYCDF50XaIe8OTqsdNxDI9p68X+RXXn ursGsbz3JWzs21fSIoWdJI/c4bMeL3g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mjxA/DFoKz/EDUMQDrlO5jdAE8nM57iTZhngVmIGq8k=; b=wTXXBZ459/RZm1yILTfwpYiekgGlxCytcn5n4YtZd3HoOv3XHAqdByYTpcoq+ghkbGZ34m H3YkwoOhjIE8XpAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1C92D13246; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KChtBsqK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:42 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 08/11] mm/mmap/vma_merge: rename adj_next to adj_start Date: Fri, 24 Feb 2023 11:00:19 +0100 Message-Id: <20230224100022.11268-9-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The variable 'adj_next' holds the value by which we adjust vm_start of a vma in variable 'adjust', that's either 'next' or 'mid', so the current name is inaccurate. Rename it to 'adj_start'. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index e05bbcaf7b61..8c2bdf9e3f94 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -903,7 +903,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, bool vma_expanded =3D false; struct vma_prepare vp; unsigned long vma_end =3D end; - long adj_next =3D 0; + long adj_start =3D 0; unsigned long vma_start =3D addr; =20 validate_mm(mm); @@ -971,7 +971,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, remove =3D mid; } else { /* case 5 */ adjust =3D mid; - adj_next =3D (end - mid->vm_start); + adj_start =3D (end - mid->vm_start); } } } else if (merge_next) { @@ -979,7 +979,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, if (prev && addr < prev->vm_end) { /* case 4 */ vma_end =3D addr; adjust =3D next; - adj_next =3D -(prev->vm_end - addr); + adj_start =3D -(prev->vm_end - addr); err =3D dup_anon_vma(next, prev); } else { vma =3D next; /* case 3 */ @@ -1002,7 +1002,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator = *vmi, struct mm_struct *mm, if (vma_iter_prealloc(vmi)) return NULL; =20 - vma_adjust_trans_huge(vma, vma_start, vma_end, adj_next); + vma_adjust_trans_huge(vma, vma_start, vma_end, adj_start); init_multi_vma_prep(&vp, vma, adjust, remove, remove2); VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && vp.anon_vma !=3D adjust->anon_vma); @@ -1018,10 +1018,10 @@ struct vm_area_struct *vma_merge(struct vma_iterato= r *vmi, struct mm_struct *mm, if (vma_expanded) vma_iter_store(vmi, vma); =20 - if (adj_next) { - adjust->vm_start +=3D adj_next; - adjust->vm_pgoff +=3D adj_next >> PAGE_SHIFT; - if (adj_next < 0) { + if (adj_start) { + adjust->vm_start +=3D adj_start; + adjust->vm_pgoff +=3D adj_start >> PAGE_SHIFT; + if (adj_start < 0) { WARN_ON(vma_expanded); vma_iter_store(vmi, next); } --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98293C61DA3 for ; Fri, 24 Feb 2023 10:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbjBXKBT (ORCPT ); Fri, 24 Feb 2023 05:01:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjBXKAq (ORCPT ); Fri, 24 Feb 2023 05:00:46 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0763565AF for ; Fri, 24 Feb 2023 02:00:45 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 531353438B; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U0wR3jwDHdRrK2cxRZw/xy12wIZu3wsnwhuoBXj0MMQ=; b=KWXyMuNXAW1CBLQTUubfz3ZaB4JYVNhcclgO1jGZo5VjK6IDmNbuyTJUDOInBfy+/ZGReA Y+HFC5k0Wq59VWumMLMp6pHq3RbsWuvQGG0vn2V82+czWBpqRgGUMY2x503sc+riFul2hW 56TNM/afvXjy39C5sTvBMDTsk9V5GCo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U0wR3jwDHdRrK2cxRZw/xy12wIZu3wsnwhuoBXj0MMQ=; b=f0IpufU3BmvceE+pCst74byvq0uqDgv/mlVa6jatNSqcFHEa2tIXy68JhhykiA7j/U+YuX DMu+EH3Z7aJfuQDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3820713A3C; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eN3yDMqK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:42 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 09/11] mm/mmap/vma_merge: convert mergeability checks to return bool Date: Fri, 24 Feb 2023 11:00:20 +0100 Message-Id: <20230224100022.11268-10-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The comments already mention returning 'true' so make the code match them. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 8c2bdf9e3f94..6e439806d4ac 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -744,10 +744,10 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_ar= ea_struct *vma, * If the vma has a ->close operation then the driver probably needs to re= lease * per-vma resources, so we don't attempt to merge those. */ -static inline int is_mergeable_vma(struct vm_area_struct *vma, - struct file *file, unsigned long vm_flags, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) +static inline bool is_mergeable_vma(struct vm_area_struct *vma, + struct file *file, unsigned long vm_flags, + struct vm_userfaultfd_ctx vm_userfaultfd_ctx, + struct anon_vma_name *anon_name) { /* * VM_SOFTDIRTY should not prevent from VMA merging, if we @@ -758,21 +758,21 @@ static inline int is_mergeable_vma(struct vm_area_str= uct *vma, * extended instead. */ if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY) - return 0; + return false; if (vma->vm_file !=3D file) - return 0; + return false; if (vma->vm_ops && vma->vm_ops->close) - return 0; + return false; if (!is_mergeable_vm_userfaultfd_ctx(vma, vm_userfaultfd_ctx)) - return 0; + return false; if (!anon_vma_name_eq(anon_vma_name(vma), anon_name)) - return 0; - return 1; + return false; + return true; } =20 -static inline int is_mergeable_anon_vma(struct anon_vma *anon_vma1, - struct anon_vma *anon_vma2, - struct vm_area_struct *vma) +static inline bool is_mergeable_anon_vma(struct anon_vma *anon_vma1, + struct anon_vma *anon_vma2, + struct vm_area_struct *vma) { /* * The list_is_singular() test is to avoid merging VMA cloned from @@ -780,7 +780,7 @@ static inline int is_mergeable_anon_vma(struct anon_vma= *anon_vma1, */ if ((!anon_vma1 || !anon_vma2) && (!vma || list_is_singular(&vma->anon_vma_chain))) - return 1; + return true; return anon_vma1 =3D=3D anon_vma2; } =20 @@ -795,7 +795,7 @@ static inline int is_mergeable_anon_vma(struct anon_vma= *anon_vma1, * indices (16TB on ia32) because do_mmap() does not permit mmap's which * wrap, nor mmaps which cover the final page at index -1UL. */ -static int +static bool can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff, @@ -805,9 +805,9 @@ can_vma_merge_before(struct vm_area_struct *vma, unsign= ed long vm_flags, if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) = && is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { if (vma->vm_pgoff =3D=3D vm_pgoff) - return 1; + return true; } - return 0; + return false; } =20 /* @@ -817,7 +817,7 @@ can_vma_merge_before(struct vm_area_struct *vma, unsign= ed long vm_flags, * We cannot merge two vmas if they have differently assigned (non-NULL) * anon_vmas, nor if same anon_vma is assigned but offsets incompatible. */ -static int +static bool can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff, @@ -829,9 +829,9 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigne= d long vm_flags, pgoff_t vm_pglen; vm_pglen =3D vma_pages(vma); if (vma->vm_pgoff + vm_pglen =3D=3D vm_pgoff) - return 1; + return true; } - return 0; + return false; } =20 /* --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B13B9C61DA3 for ; Fri, 24 Feb 2023 10:01:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229972AbjBXKBQ (ORCPT ); Fri, 24 Feb 2023 05:01:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229641AbjBXKAq (ORCPT ); Fri, 24 Feb 2023 05:00:46 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04BC2525A for ; Fri, 24 Feb 2023 02:00:45 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7AF2D34432; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T637DVEgnPwS8p7L5KrNfCTDsHvOXi2P3RnjOxBPfWY=; b=zXBjdlaHJo4OPani0e7zgMaltNOkXOKjI1Vn7WQY4kdLxSIAH0M91voUErlN7tAhfYP5r+ AfesZ2Nn3ui5lM1I2fCq0a3XrC5HdGtE/UwODQutPhOXIu67II16+lo1FQxsinIDP8Yt/v aDg9Sm9wuE/lGQvXeupSfWGCQ8IbVYE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T637DVEgnPwS8p7L5KrNfCTDsHvOXi2P3RnjOxBPfWY=; b=ve/+OwGM7xKTsy5jb3bE/R482UYK814GXEMl5iQTRZyrSn+PiltVpWmaWLfmSyY0/2hjMQ ioRmMh8NT9tj3PAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 58C0F13246; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iJuVFMqK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:42 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 10/11] mm/mmap: start distinguishing if vma can be removed in mergeability test Date: Fri, 24 Feb 2023 11:00:21 +0100 Message-Id: <20230224100022.11268-11-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since pre-git times, is_mergeable_vma() returns false for a vma with vm_ops->close, so that no owner assumptions are violated in case the vma is removed as part of the merge. This check is currently very conservative and can prevent merging even situations where vma can't be removed, such as simple expansion of previous vma, as evidenced by commit d014cd7c1c35 ("mm, mremap: fix mremap() expanding for vma's with vm_ops->close()") In order to allow more merging when appropriate and simplify the code that was made more complex by commit d014cd7c1c35, start distinguishing cases where the vma can be really removed, and allow merging with vm_ops->close otherwise. As a first step, add a may_remove_vma parameter to is_mergeable_vma(). can_vma_merge_before() sets it to true, because when called from vma_merge(), a removal of the vma is possible. In can_vma_merge_after(), pass the parameter as false, because no removal can occur in each of its callers: - vma_merge() calls it on the 'prev' vma, which is never removed - mmap_region() and do_brk_flags() call it to determine if it can expand a vma, which is not removed As a result, vma's with vm_ops->close may now merge with compatible ranges in more situations than previously. We can also revert commit d014cd7c1c35 as the next step to simplify mremap code again. Signed-off-by: Vlastimil Babka --- mm/mmap.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 6e439806d4ac..21343da452e8 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -742,12 +742,14 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_ar= ea_struct *vma, =20 /* * If the vma has a ->close operation then the driver probably needs to re= lease - * per-vma resources, so we don't attempt to merge those. + * per-vma resources, so we don't attempt to merge those in case the caller + * indicates the current vma may be removed as part of the merge. */ static inline bool is_mergeable_vma(struct vm_area_struct *vma, struct file *file, unsigned long vm_flags, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) + struct anon_vma_name *anon_name, + bool may_remove_vma) { /* * VM_SOFTDIRTY should not prevent from VMA merging, if we @@ -761,7 +763,7 @@ static inline bool is_mergeable_vma(struct vm_area_stru= ct *vma, return false; if (vma->vm_file !=3D file) return false; - if (vma->vm_ops && vma->vm_ops->close) + if (may_remove_vma && vma->vm_ops && vma->vm_ops->close) return false; if (!is_mergeable_vm_userfaultfd_ctx(vma, vm_userfaultfd_ctx)) return false; @@ -794,6 +796,8 @@ static inline bool is_mergeable_anon_vma(struct anon_vm= a *anon_vma1, * We don't check here for the merged mmap wrapping around the end of page= cache * indices (16TB on ia32) because do_mmap() does not permit mmap's which * wrap, nor mmaps which cover the final page at index -1UL. + * + * We assume the vma may be removed as part of the merge. */ static bool can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, @@ -802,7 +806,7 @@ can_vma_merge_before(struct vm_area_struct *vma, unsign= ed long vm_flags, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, struct anon_vma_name *anon_name) { - if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) = && + if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name, = true) && is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { if (vma->vm_pgoff =3D=3D vm_pgoff) return true; @@ -816,6 +820,8 @@ can_vma_merge_before(struct vm_area_struct *vma, unsign= ed long vm_flags, * * We cannot merge two vmas if they have differently assigned (non-NULL) * anon_vmas, nor if same anon_vma is assigned but offsets incompatible. + * + * We assume that vma is not removed as part of the merge. */ static bool can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, @@ -824,7 +830,7 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigne= d long vm_flags, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, struct anon_vma_name *anon_name) { - if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) = && + if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name, = false) && is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { pgoff_t vm_pglen; vm_pglen =3D vma_pages(vma); --=20 2.39.2 From nobody Tue Sep 9 12:13:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41AF9C61DA3 for ; Fri, 24 Feb 2023 10:01:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbjBXKBL (ORCPT ); Fri, 24 Feb 2023 05:01:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbjBXKAq (ORCPT ); Fri, 24 Feb 2023 05:00:46 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F31FA41B53 for ; Fri, 24 Feb 2023 02:00:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9D9CB60097; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Am3Z7D3PJEF75x3/HiQBrnXvVKIlV3/Qp4c3FogRta0=; b=p3ZE5uLwEtk/cg7EnX+HE43e+C5B6rCtvsUtSKn7CxdBPlUfloNsqfqkQFJ5WiO4rEiuzB CiB36BoqS/AxKRsf+8lfBJrCPJsWYiHD17DJ2nHjh2Thr9gF1vXZgckXkVNO2twWML+bU+ lTrcHL3qGPcvWhSc4rpP5vsD4O3OOfk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Am3Z7D3PJEF75x3/HiQBrnXvVKIlV3/Qp4c3FogRta0=; b=exyNXp/OrTDQL6j9v3BOeWryfghFBfYZcF4TfoMJZypVOqnpw+z96xZJyOKkpRbJ2pT2R2 zYGobN1KuemM3LAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8010B13A3C; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8O9WHsqK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:42 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 11/11] mm/mremap: simplify vma expansion again Date: Fri, 24 Feb 2023 11:00:22 +0100 Message-Id: <20230224100022.11268-12-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224100022.11268-1-vbabka@suse.cz> References: <20230224100022.11268-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This effectively reverts d014cd7c1c35 ("mm, mremap: fix mremap() expanding for vma's with vm_ops->close()"). After the recent changes, vma_merge() is able to handle the expansion properly even when the vma being expanded has a vm_ops->close operation, so we don't need to special case it anymore. Signed-off-by: Vlastimil Babka --- mm/mremap.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 411a85682b58..65f5b545601e 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -1040,23 +1040,11 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsign= ed long, old_len, * vma (expand operation itself) and possibly also with * the next vma if it becomes adjacent to the expanded * vma and otherwise compatible. - * - * However, vma_merge() can currently fail due to - * is_mergeable_vma() check for vm_ops->close (see the - * comment there). Yet this should not prevent vma - * expanding, so perform a simple expand for such vma. - * Ideally the check for close op should be only done - * when a vma would be actually removed due to a merge. */ - if (!vma->vm_ops || !vma->vm_ops->close) { - vma =3D vma_merge(&vmi, mm, vma, extension_start, - extension_end, vma->vm_flags, vma->anon_vma, - vma->vm_file, extension_pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); - } else if (vma_expand(&vmi, vma, vma->vm_start, - addr + new_len, vma->vm_pgoff, NULL)) { - vma =3D NULL; - } + vma =3D vma_merge(&vmi, mm, vma, extension_start, + extension_end, vma->vm_flags, vma->anon_vma, + vma->vm_file, extension_pgoff, vma_policy(vma), + vma->vm_userfaultfd_ctx, anon_vma_name(vma)); if (!vma) { vm_unacct_memory(pages); ret =3D -ENOMEM; --=20 2.39.2