From patchwork Thu Mar 9 11:12:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167263 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 435AEC61DA4 for ; Thu, 9 Mar 2023 11:13:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6D026B0075; Thu, 9 Mar 2023 06:13:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD18A6B007D; Thu, 9 Mar 2023 06:13:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 700AD280003; Thu, 9 Mar 2023 06:13:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4149B6B0075 for ; Thu, 9 Mar 2023 06:13:16 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F252BA0FAF for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) X-FDA: 80549098350.08.655B929 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf18.hostedemail.com (Postfix) with ESMTP id 023041C000D for ; Thu, 9 Mar 2023 11:13:13 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Mlm8A4Ho; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KJEXsfOB; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360394; a=rsa-sha256; cv=none; b=75ZWU/Q/MVuxz83gRWhWV5IKdvprXeKLrv14sIzr902k3Jj1coB84a9GQngzBKqLGeNIoo cBOenLfJM4rmubJkyfwtnbeS3Ae2tWDnhGIrd9iXmxRWz8YpfDigGmxhZsjgbvwTk2aHNB BdLQKT02IgneVkR+E62Exq7cZKgBEU4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Mlm8A4Ho; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KJEXsfOB; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360394; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=q9S49Vc4wP4VJtPP7U3rbG14z7j2ldE6Nx08zIq8xuM=; b=KigtQf/dsJMkRBadC8WpaYcqiZqHunrKYz7Mr1969mpyXXjHizEPBmwrKUcPQR09o+pKFp NKYp4dxHTkiFvPXJ3vI5b77cD0DHPWIDEERUnhpSB0j6vBl5XDag6JyaJqYm6WmU3WPFim qtHt/SwxneFswWVFi36uuwy7i4doXQw= 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 1E47C20036; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360391; 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=Mlm8A4HoqAH0hJcmIH7nkeq7Ena0KY5bDzJYjrppMfaDBbBA3WohkCm9JIIgswP2JrYIvo zNTW4ebhcCAJOcnFqxgBVFKAYXWUz3I4R0UU5OTZYPI1D/0Rllmax+6SsLOiWp4rvMpYLW wBWINPA6bXrywVw+WjfS23ZYMKflGJ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360391; 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=KJEXsfOBSotb9dP5aHuNoEqWsFqw2hDjbbgnBUqsAQxTVJXXmvPoLo19GujxjABiZmRJoR Jf7IWKTG6XnAJ8AQ== 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 F1C0A13A73; Thu, 9 Mar 2023 11:13:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MPmCOka/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:10 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 01/10] mm/mmap/vma_merge: use only primary pointers for preparing merge Date: Thu, 9 Mar 2023 12:12:49 +0100 Message-Id: <20230309111258.24079-2-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 023041C000D X-Rspamd-Server: rspam01 X-Stat-Signature: i1et4nbcz6r38qrq8md9uwk9x94mibus X-HE-Tag: 1678360393-131904 X-HE-Meta: U2FsdGVkX19mFAN+44bRWlHistXmL/+PIV/XUCxmc+SoNDWL/NQlMcAMwJtjB3ZGAg71AwIJTqx4mXKek6ymnHsbLWPMh91sKC00Vgv1EktZAKHVIi8WPbhMnmXp8F2+daYxVR3UQRA9e0QvdvR1X13PJpTXshpqYlwEZcVlVlenGZGILKATlgC6qlFF8bbSzlZsLxVOkMKGT7Qxe2KEAs4kP6KYCKq1+O2Q2U2bek8yXGXRFhnt9MEcPhn+jVWqSOUtPhNKtgxLbdQ/LXWxq7FagxED83qtYUS4cfgFwHX1x0WSTUgfqvlEjAj+dj5xNSgiuDRFzd44Mv22Pgh+9p7KmZuIKV0YmUSsje/qGVONEwo4zqJ2ex2T+hx9hPyzbxrv4pf5EnJpLnq8jd2i+DDtj5mQMKZX1ZAN2Hv3KqA2/CArFNPEytu5LunQWJ6tofeROMGNYwK+lYdll4b64h5EiDUniaYtIFSXNpHyjAO0vYnaB0uFxZ9yJ+1kjJOLwELP4ppx8pe9huk9c9I2S2TlXB0T+72QiMwvWhkxeUeZkm2M/a0lD55mFnj88vmFHSOCsvjvOTjEDkt9GCOAtWEauLw7WwNjUSor9aZ3nhWHJA65NkB0n3TWK/dcSyEuIt7z8/USPNGiRM0k5W3C2WercKaq0P536fj4aqDZScwgvt3FAsbVkQtYuLuasuwrZExb4LOdCyNjN8JA40UULBxIF2iAh+cl81TWy26DKw5QCZ8VicSzlzomvOUEPEc3W3eQGgDEetkYskWHhfq2RvhLA+wAMlL0qlxJp/mOsslDt1pMUNEBGppOCLrqc1NYrrOGHzjVVR3rGhE531Z1XY9iJquOFe5VRU/zBx9k+ODRVf7OLCLlsSoEn65SuBiPU+OZ5LwdcytHzayRxt4jVS9FhT8OUY5y+zgF2dTYvoVEzsnP1cre1Bwm0L66JQzB3dW6kz/YM4AwBhZ1jOW PebeKw64 ax/2uUjZnV4mKLd89YiGa91E+YQX0MzrmHgKj6F7YCvL/aQ5SB7BuJlMrHTAGs932TrIhv9eV1HOoN/xbAis03cWGX9ib2Qa0jBQ6Mu0LGpuJICtdQnJrWLH34a6aXPZQL8dsdCuydd0JHALchHzvZu2E3CIe30/Bqk3z1diKldIVj432LrWZJoSreydMxC+Takxe+boYJhKBy/dXbRXA7IF0lDN1cf6JfLToEUnBgZRsslOvGo053fJ5dw== 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: 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 Reviewed-by: Lorenzo Stoakes --- 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 = mid; /* case 1 */ vma_end = next->vm_end; - err = dup_anon_vma(res, remove); + err = dup_anon_vma(prev, mid); if (mid != next) { /* case 6 */ remove2 = next; - if (!remove->anon_vma) - err = dup_anon_vma(res, remove2); + if (!mid->anon_vma) + err = dup_anon_vma(prev, next); } } else if (merge_prev) { err = 0; /* case 2 */ if (mid && end > mid->vm_start) { - err = dup_anon_vma(res, mid); + err = dup_anon_vma(prev, mid); if (end == mid->vm_end) { /* case 7 */ remove = mid; } else { /* case 5 */ @@ -972,8 +972,8 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, if (prev && addr < prev->vm_end) { /* case 4 */ vma_end = addr; adjust = mid; - adj_next = -(vma->vm_end - addr); - err = dup_anon_vma(adjust, prev); + adj_next = -(prev->vm_end - addr); + err = dup_anon_vma(mid, prev); } else { vma = next; /* case 3 */ vma_start = addr; @@ -982,7 +982,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, err = 0; if (mid != next) { /* case 8 */ remove = mid; - err = dup_anon_vma(res, remove); + err = dup_anon_vma(next, mid); } } } From patchwork Thu Mar 9 11:12:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167258 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 3034EC64EC4 for ; Thu, 9 Mar 2023 11:13:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2636280002; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A84106B007D; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AA4A280002; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5A5476B007D for ; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 34BAB1C6929 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) X-FDA: 80549098350.17.B1B42F0 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf19.hostedemail.com (Postfix) with ESMTP id 7E2BB1A0003 for ; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=CakbiMz7; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KdmlvilY; spf=pass (imf19.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360393; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Y+XTfDYhuPvIRFRoJO2lR/Vb/n6vI/gDEgoJ+zMr3So=; b=xTdE2uv782/2STSJn1lRdEZwC9KMRHzguFThVgFQU3Cxn/x062ZnElGd3SACnlaEaNBdss 8wk5A3S8rD6HP7A7sxdrdjnZR+LeXsvi1X/pdzyA+XD5K+dOyf/FtIpA0vu27rV+DEssB4 Yes7gGwJIYktbmDU9ozhPS5L1sVk+Js= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=CakbiMz7; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KdmlvilY; spf=pass (imf19.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360393; a=rsa-sha256; cv=none; b=OOqyB8w7NE4ZgKwtE4CuEVTQo6ftfFNpZ0xDF2+tW5z5mbA3cUzrQm6A51vDJPBNJ8jhuj JkO91zsVEGwY8+MRRu+QoKjHUbjP7gXH5mNVyBza+fE+COaOQwfAxtn2ux49gKLfJCHzy2 yZISUvDP7nZgSNKKFE2S9WTv5OL1kE8= 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 3DD00219CF; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360391; 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=CakbiMz7ESp+PZBarcLSQa0zNpQqPvaGnV/6HiVYEPoMIYL1uJzvY535TNRzkNuNJfHm8G baHvFFMgkduFCh/uLKeEcTYTEWWaphwgtng3tkUYz7FxKlXvAyKhCwO7c5U8LHd5QdUk7I YULMMvndw22a7fBi1ajnip1FpJXQM3g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360391; 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=KdmlvilYt6kG1JZfFees5yu/jB+aJaAamtgpKBaCa/Pg0TK3VAOWwZHYhpcyUwwyYFS03v TWMMhE7pACjsZmBg== 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 1F0C21391B; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WD7lBke/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 02/10] mm/mmap/vma_merge: use the proper vma pointer in case 3 Date: Thu, 9 Mar 2023 12:12:50 +0100 Message-Id: <20230309111258.24079-3-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7E2BB1A0003 X-Stat-Signature: dhgy7n6ogkjafwyfeufeiy464xot69ut X-Rspam-User: X-HE-Tag: 1678360392-900868 X-HE-Meta: U2FsdGVkX1+nkfH9iEnjI6oFImuEdrcJ49FvXvkMEdiIZ824s01sXjtAi/09DLHv8g1C+0rRmqjCZMjDZgoC+p76lp3KDJC+JQGPU9hNfW7mPxkoBnshQy2qmRey43mdUUkfYDo57xvdS2g8AVLLnw4eJ1G367Jdp7lPAvtl1jp2G70k++d45zNapmklEdek3FOePpZNXJLBq/2xJSwEB9cySLO8FQ+gQ4MbwlngwpeK6S8W5S5a69E7OoMNBUD5gL/l8SlM10xnlrQ3xtpT2/ZQdHn72skkGWxonmuht2JZIeWe6qthFYfuNqUfThVvJrNOruYjnzc9plJxPYdYnlu+TE17AVD5OWvc2R/bP8axtjFfII2rir68Fs9Q7eTUsR3TNO+Enyrog1f73oAy/XyC3aWbXc4OSyQCRwyiurK9L5OvSQSK/zOzazpQsPwuxA0+rSONPYSHaQLrSG8XYcGE4PhpFHpMqA25jH12Ix4fyX89GbkAkATL5JNxevVGm1JV82IvBAD39cEB8R5VmCsjyHQZnA4rFm6D5OloHOZPZkEWjnj4YQJXNxlf/shvYyh6iqxU89ebJvOmvuzURFJB60/cvwbYga8eSNwNByxoxy7JcPLdVvBlpqkdWgr9gVHZB8R/XcIXDHYhyZDul2HEGcF0ly8WbSZaXgbTSzznMI2m0efXRPBgqPK0hNNfD3sXNvbRNThv5GlM7qqeht4WM2MMLbGcp6nM7jhDp9n0XMvv7xXYEozvKoMNLw+7/kpsMfyNkC/DarOA0Oaj0itx/prNr+WZ1QG9qBg5GmM0EaElBtZYG1BitBAuoG8T6rhu9OwnOSrfz89/OOxQYwkdhqFnfhf8IaCvbXdZbMy8AkCOcA2KJB6FeuulJ2rxygwu0k0uBpqS8W9T4cm7Y+JiyGwtiebegkyfkbuSM9caf8+wvaNUH/4rK8ActFrkjEBY/Too80c2E2Mc/K7 MI/3+Qfo eAZWq7vy1IXPy2u8Hl1xAZLNzRX6T2vcd9nlGPgPr0BkRM4+IcxU2qMtPC3f2FjXuWvLbqmIvG21AbNyWBBPUz0osD9fxPUk5YLP/LwNjUep2JOReX2YQqtYZnesGByQsIeDT8nCysTZJJ8kG3CPuioVpW9Nxi8zql1K6SpYLFr94vFAXV+/6eUAv8e0lMXu0cMnA2Bp4xRlYOiDVQ56vQ+L0BY0juDI8IYAKrtS+H/g4JeKlDBqGiriVGg== 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: 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 Reviewed-by: Lorenzo Stoakes --- 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, unsigned 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 = next; /* case 3 */ vma_start = addr; vma_end = next->vm_end; - vma_pgoff = mid->vm_pgoff; + vma_pgoff = next->vm_pgoff; err = 0; if (mid != next) { /* case 8 */ + vma_pgoff = mid->vm_pgoff; remove = mid; err = dup_anon_vma(next, mid); } From patchwork Thu Mar 9 11:12:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167259 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 9CFB7C6FD1C for ; Thu, 9 Mar 2023 11:13:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2D2B280004; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB62C6B007B; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9725E6B0075; Thu, 9 Mar 2023 06:13:15 -0500 (EST) 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 4E0856B007B for ; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2E95F80832 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) X-FDA: 80549098350.13.8A53EE4 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf12.hostedemail.com (Postfix) with ESMTP id 7EF1A40004 for ; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=vEtLBCb2; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=uW6jZY4O; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360393; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+3YUrWV7jfpXoA++JeKVk7hZ9f1CmC3d5xDMhvCnqQY=; b=P12ZqJBsfJoxmSXb0wURK1zYPuxjddFZdAVhbYGfzX6CkcSrmONIF0fvrMkogsSuipwDVy UjjqHneDdGyEZJ0f1Dg6rKt09xzoB0Z6XT6cgvyUlOmT69afjFRt8BFgfbvd11u4z4CnB7 QFcF5X3Bd9UFnkyWYcmXdcrzLjJBt3k= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=vEtLBCb2; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=uW6jZY4O; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360393; a=rsa-sha256; cv=none; b=lSb+/OrIJPAQhjWtGmSpEJpwq3FBaL8CJWwvrdyfbidOYvouSRQS/AC2NMfn1A+6LN3D2K D0InvVhZwFmJrXu3229aHvmcH1A4AjFqDlAVXWGyzQTIdlylGLfSGuMpBkNAaNbZfey2vb KPGz6+Lq6tfXwziPd1zbmEXYkIW7K6k= 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 5D51921E8A; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360391; 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=+3YUrWV7jfpXoA++JeKVk7hZ9f1CmC3d5xDMhvCnqQY=; b=vEtLBCb2yry/emu/jQIc82ZS1qlwzsWUD3kbJjRDcSQH1Plr6grvNfNZcmXccfFFnXIVOJ KXC3aZGxY+Q4fR2CySOSWAp5CLIId9rmeDxY7aMapaHDH2HsOYxzL7hfo+3kQUVZBHKdau tbbQR77ynnrN30wYRBqIe6kqhTK7okQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360391; 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=+3YUrWV7jfpXoA++JeKVk7hZ9f1CmC3d5xDMhvCnqQY=; b=uW6jZY4OeymUbTM2/kEI4rtBKz9eeX37/5LcvI4Yc+ms/o0L55GgSWDvQw5rEuIxSmmxfT kLvXbh1WeGCFo0Dg== 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 3E55F13A73; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wFGoDke/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 03/10] mm/mmap/vma_merge: use the proper vma pointers in cases 1 and 6 Date: Thu, 9 Mar 2023 12:12:51 +0100 Message-Id: <20230309111258.24079-4-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: odpdfhq43hqh43yqiqutoon6rpfie9qa X-Rspamd-Queue-Id: 7EF1A40004 X-HE-Tag: 1678360392-459967 X-HE-Meta: U2FsdGVkX1+DqXjagfxMfEV50viV/61uh8C0OaoOVZfsZ9Lx97i1GkNAGQ5m/vT00oO9f7JfYNhTp1jlXCrfhnU6O6IK0SSjnxWiDJaa6tOiLS7or0bNKRRRCR3IejCQyT4qqx3cmBg7FBWTVrefsi0k6kWs9AcP27HZo5gSk/9BSlZr6DyT4u3oyaoTNrW1EeEBTbM6A9SNSpeDjzjDsT8dWNp03iKfrxRvQ3J3G3CFMcR4MDrs3fV017QyC2l99c8djmdsNzMFrPKyYD6FY8CEJb+yT5d7WOv9BrHVweptTpvyWjspy3aB6GjFmhCtQnrqOW5zWrQYSSZ9cqk5mc0oZKFXrjJIomdiWE1Th3Y3haF4RIrIVoyji+scQR29j7QnELGvHpPYhueHMnf43A4DQaXKiZ+soLJxlQadwYNHUT0ZVAe5BarlB57pzZ28EwaqnTHpQbpda2MpaCkDTYSsBWiOscsK6zVtmaogE8cgXErqde7o0XEiwSzqYtKOzyj8Dz/BQzHwDzyVi3o5UfMw2HmOp9uOm88WFgV9dLrsMWp0Gnvi3Hr+D+m/5JrYW/v4XeNTvHj31n/UtGHWWYbe8/GT46cToHH0DKFgJ+rY3uRm92Aovd0zpTtSAk13MM2SN17FQPHMYoaXwOyMiuNaJp1h9PsXcCKVEs2zXT8/f46scY3/0y2g3tyykfP6Sxgf5rEk+AS817n/0NQWdvmWVvBzBBa/mvlWrR26tTuUR10MKxOdFPzNwU4MxVWl3sPJjoiuDaxt1T8DJmDu9oYWoOsK4WMDcYA7kGOUeSWq+xHqAGldNAMGUpG0YQBeJYnE6wkRBf6opTB/yA63AXypzi+PnzP8BCbXzOkdXK5DlO8zoMMMIrZFP1Jc6ZOcwm8z44vwkBZGXXj5PrafZI32OXupeb2tE19fPE3HfQrP1KqKm68Yv1LheOoJlOUwLZAA9njmGj4pCV7Jn1x 0xI+qeKR bi9Q9WLb22uRWM2KDXSMschn7vJdpvnSG2Gtn3GFKlNTs2Q71JRsf73yjlCLqBUw8nIMQfyYMHggz9Ztlqgu4cV49YwzRn8L8u/GgOjUbLuPyj2b+WgHQ9FJh1g5SXKKT9WLltqoHVoCIIziNGJaca2nSKvu1suoSJuzPzFKoK3klvb5+MbWDisdSjuWnzvlvIlb82cFfcJc1o+g3H7sXgrEmZvpXuKc1tIorx4lyqH0VGlQ3lbllk3QrJA== 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: 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 Reviewed-by: Lorenzo Stoakes --- mm/mmap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 1af4c9bc2c87..c33237b283c9 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -605,7 +605,7 @@ static inline void vma_complete(struct vma_prepare *vp, /* * 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 vmas */ if (vp->remove2) { vp->remove = 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 = mid; /* case 1 */ + remove = next; /* case 1 */ vma_end = next->vm_end; - err = dup_anon_vma(prev, mid); + err = dup_anon_vma(prev, next); if (mid != next) { /* case 6 */ + remove = mid; remove2 = next; - if (!mid->anon_vma) - err = dup_anon_vma(prev, next); + if (!next->anon_vma) + err = dup_anon_vma(prev, mid); } } else if (merge_prev) { err = 0; /* case 2 */ From patchwork Thu Mar 9 11:12:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167255 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 8B246C64EC4 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC3E56B0078; Thu, 9 Mar 2023 06:13:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E51936B0071; Thu, 9 Mar 2023 06:13:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7C0F280001; Thu, 9 Mar 2023 06:13:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B29036B0071 for ; Thu, 9 Mar 2023 06:13:14 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 97D7980832 for ; Thu, 9 Mar 2023 11:13:14 +0000 (UTC) X-FDA: 80549098308.22.B8A142C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf05.hostedemail.com (Postfix) with ESMTP id A98A410000D for ; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=veUZEMzE; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=uNtMsgjS; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360392; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wE1al//pCc1to1HvUyvkZo2jQrSNJIISu5e3jqOmb4s=; b=oLvkzFbxpF3+BtOx04F988j0SJVJOMa838v9mhpkFW8301/HuWKJuGlwjs+gNLM3dB+XjV hNi5eTzW5G05jw/rlKbdH00ySZjHXk5kESgv105soE+vvIhu4JllXrklZ9/vt2xlBWi88y wmiM8n3Kku7A11kMZCI6YVEoeJpyU/I= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=veUZEMzE; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=uNtMsgjS; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360392; a=rsa-sha256; cv=none; b=te2QgJHq24yfjc8SUTiCfTDYusu7qLv/Q3QyUNnUXUoPBbyY3aRxuteQ6ktUdE/JGmm11A kjxd84+juLPlu9PSLQyNBmvqbcdPVdPcODqkmYmIYzNACitUXBVnOoBmn7uHiBL/RZ3j/A 6cFgGwm4T8FzL4/tlwiYTzpps0H8meg= 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 7CE9821E8C; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360391; 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=wE1al//pCc1to1HvUyvkZo2jQrSNJIISu5e3jqOmb4s=; b=veUZEMzEMFoFQBSMkP7TVCeLql/YYD/acm4DYFiB8bth7DfTCzjmSL7zWAGRSKNsFvCzPv 80vdMoqx0HTQ4/7N9cFLCg8kRPqV7ipaRyEJY3x42qSIis4ntpoOTThU2WXvVT+g36j1KN RtXw5mM+Lk132MHltILMEq5ZhGqMj0Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360391; 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=wE1al//pCc1to1HvUyvkZo2jQrSNJIISu5e3jqOmb4s=; b=uNtMsgjSDTk/7Nv8XNxPldzlzzfl+cS/tPmooh3HejHqR7vHiuhfcC3t1a+EIzZdoeipTI HFfyME6YvqFto0Bg== 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 5DE691391B; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qHtIFke/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 04/10] mm/mmap/vma_merge: use the proper vma pointer in case 4 Date: Thu, 9 Mar 2023 12:12:52 +0100 Message-Id: <20230309111258.24079-5-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A98A410000D X-Rspam-User: X-Stat-Signature: u7cb5b1tr8s6ir55abahn8g8iati5r1f X-HE-Tag: 1678360392-139187 X-HE-Meta: U2FsdGVkX19ulT0Z2UY7hLpoiHg0foPfMYoxUcN47/uxtTflLrV/7uOO20iYMKPv9bfKz//moFc2jfonoSJVb1a+neUBH49/SlnEFMFWKo8fMl/+WEnCMpHlI5n4uZwtFDMTgcqwtt83UIO2qK6OKU3UAvE55PSB8MxjVQ83ySiwAlXIJOyw0pZwoXYkecLKruqhI48kDaGbGp/Vr22Nu086UOV5TtjwbXiVQybPRV8sjtPnHq61bT6sNUFR6ll4rOT8Fi+4DHGakPVKTvim1AF9bytsjtCqHKY/BfZojq1SH9fWFfviu/g4pv9YgMN9qaOjX4//4s31bbKM7AOgaFEGtdMrPyBiRTe2jEgmU1G1Za3Wu54uqMSfDzbuG1uro6tz/L4j//o+NqF4DFYsC7VXhl9mt6KVmuDzRRWzEJ2430GgefbFaK5c3l+MFSnhSzayi+t5BFxB3UAysm1SsysFwH9NpkN8LvlXufE62/qLLiAz6Au99WiJoDI4/0pmeNYUdA6YKTUx7SFMwfHy1YG3I8tn+sOxdYo+EESENaaD0M1ufZz+nI88B2HLOv430lXzPnfgCs4SoVz4XXMa9q4Oqb3XxX6Xq/63haSyFaO6LX3BmYthnZJv2RPGIQyOGu2LaxAuNv2GxD6Iyl+YrEE/7Hw3nScwP7U9XXScfVRBqahxpfSRg224bWjfKE97aX2yvctfmCfjGaN3sWHbiy6eCYU8YS6kjDwM95akUN/5g7RHthO70a5NXw2v9MBcEf5U5KZsD9/xtCcxWf4cYO3XtUQS1nobtbxvedEy2qR8ADsD4KJ3PwY1zmxFkCpNB7WUwX1+PpFzQreyFCwSZxQIQafEphxW5MoN/AZWeJP8mTZBOCFyKnR2cHl5ecYgZc4X+s5lAd6X2/FbfTc/Ml2TdZD3pi1EaOGYMiePyPcf5PEtQNYJnB4qgf8CwcIjotvglns62bpG4lSLSEw BhF5dFCb qtwexQF58ToxhLmlRa4qaIPH0069uEsn6g9yhq4zZUcigS09Qkm/wVsNCGvQiQvKPCdpPD7jAph/X+b9CSnt0TPfcIoB2Ax6/DLo9UiqJ69MPbUJ5hrP/A3LOxRuqT1Osw5aQfam5R3E7jYnsgEHcGOjG5dbkpWgKFQEWi9I75QSTYCQ+HNnWyH/fE8sTujlXMNQwyV1jTJQkN272tFzH1VHl0r5fghTtHcUiTl4SPWXjiNMrlMIOMCBDAg== 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: 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 Reviewed-By: Lorenzo Stoakes --- mm/mmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index c33237b283c9..420d6847c94c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -851,9 +851,9 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned 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 *vmi, struct mm_struct *mm, res = next; if (prev && addr < prev->vm_end) { /* case 4 */ vma_end = addr; - adjust = mid; + adjust = next; adj_next = -(prev->vm_end - addr); - err = dup_anon_vma(mid, prev); + err = dup_anon_vma(next, prev); } else { vma = next; /* case 3 */ vma_start = addr; From patchwork Thu Mar 9 11:12:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167257 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 CBC85C742A7 for ; Thu, 9 Mar 2023 11:13:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 486B96B0072; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 37AF66B0075; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1601D280001; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DA1DE6B0072 for ; Thu, 9 Mar 2023 06:13:14 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A19841410C7 for ; Thu, 9 Mar 2023 11:13:14 +0000 (UTC) X-FDA: 80549098308.21.F76682C Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf26.hostedemail.com (Postfix) with ESMTP id C733E14001E for ; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=lF0QP81+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=yKYa9OI8; dmarc=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360393; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MSk6Q5fXV5lgNPoon595PuYz0dxCHrt88iESPc6EpdI=; b=bMHe6zHVMe2HDrpkF8quSO5xvjs9EgOpTA7kJ/Lxtinvv6sCk3D8l0Gk+QpHkkX5qykSPK 8iz3aBicvWLjxwEGbGekbC55TKG7rZvMrpFPTrnit/6t7dsKAOm38fZbfoR3UbyjjwVKbk vVUz1KWeckMDTPDhpZ9KlzFJKTB3tO4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=lF0QP81+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=yKYa9OI8; dmarc=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360393; a=rsa-sha256; cv=none; b=3t6xSvDlaZadDJzUin7whSJpFASKUpDvfcb26+lExOyVyktPiAbpCmDuKDLTfDo7Z0JxIw 08VfP5Sw3Szv75g+cHp41fqVmJGf7WI4Xitr9f7ksBCvVy80ZuLLjB2jz6tB5wN44gOwqy abN7p4ForUqZrBLN0bFhoYmtMfespsk= 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 9EADF20037; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360391; 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=MSk6Q5fXV5lgNPoon595PuYz0dxCHrt88iESPc6EpdI=; b=lF0QP81+QKvoOQpeTgIS8OuYXUwgoPjaJ5K5ZuviX/M/vhmhbbatmHhloTBMPt7pUSLB32 /+yCTqzD2huaZPmtnyXRtujsZXWpG3bYItFfpYYmsPHXpawLsT5fwHVTyI+MkMTpj5EOcT I5QmCvc+sLG68EuiMAJ0C84/1DmeuQo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360391; 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=MSk6Q5fXV5lgNPoon595PuYz0dxCHrt88iESPc6EpdI=; b=yKYa9OI8nzeEPmzRVx1GveVD6Yxc49Mh1tRy3l6C/KWuUi/LdCH1RQG0V03rxZhqphs1Fs HDCjKEqqNgJt48CQ== 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 7D5AE13A73; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YAsDHke/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 05/10] mm/mmap/vma_merge: initialize mid and next in natural order Date: Thu, 9 Mar 2023 12:12:53 +0100 Message-Id: <20230309111258.24079-6-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Queue-Id: C733E14001E X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 497p4ux4rfdndc1mqifczfirdssoz5ni X-HE-Tag: 1678360392-216796 X-HE-Meta: U2FsdGVkX18h+7rESYiLKuf8JKXa9JFExL4HXujtNCO80EwLifmfkoNxXYZ5W9LqMF/X6hryqgfTrvYO+ceJO/tDavkSnmlD3jtxbZHphP97xfUAc4o6Wp0wH+lJ5niJ1DuAIBH4hLUApXRzEYkRkExY8AU8LkLJS9mCL7OPaHt2eFfmwaIVa1+HIcgZyM51JsHIdtsO4zEjPINaqN4cYBqb0r8xQybxbj3cphYmMjne8GjVPrfGhSqZOcQ5Z88HnM/R7h8VqQr6cvRsHBu032wxyLkvqwuD5feLnbCe11ND5z1L8S4Q5OowRiNbB+p0yyuXiuotDwD46mo7J49Ms/K9lnJ1Kw5dlkNENi0+vYCqruIdEFf9KyfPXfp7/x/bv3QWDV9zeZOYt6tBpmShf6ipPhE2rAGLPcRpvf27mimbTT2zM/z5gCseGdxxcRpU4fT/x2uO2SAxdhIelCi/uxWEKnkntzO7MxspwEYn4QT7iomPN8f41iuBbOmz61x8NCETOg3tc8OoXVE0SfvRLh+kKkwF+Ojjr7cSPE5Rx9X6+KAJ2rV49NPvU2S61BDKVe3Gisu9jTl8D4GgklSNnH5NNgZk/q/0Z8RueGYb/0+a8N/wd94txZyB6KNB/Q/wiJwI+576yYxDhhoUntgvtMWIoNQvIDJ2ilDvEoYRMg5cY5d3EpXewjgt/68LUX7WoWKy2VAg0ANsImd2YdjMfBmkyqIgsJJGDa6dzf2g2DtHhjgOiBQdzmmaBUwORlcg0VsNuP+HcgwVxOkgnCOFdw5axusszQ5ZDZp9mdHeCWOISMgJe52mviNv9ELcUQWQZu06ZGxhgm8Lkcrv2s/t24RaPtU0sarQQiHRAkHWfBTrrz0wxkEawkpz9qCgX94z5AwJjB/bSJuoZrc1QzZNlFnlqpxzOZCz1zBWkjVjZ5KIIjYW4oBGHaZ5Xim9I7xGvVDYH6EAXkE5boDSwZf 2P/DD1lU RavbJjD8Fnk2PHESfo7CPht42BTCbklFdbIxS3lYdm1QQgf7HvR+gKPhapdZkLBz8r9JgpcAomdtwQ55ZjH0ojFHkVOKEAlqyXRL309VPDUa34o+h/I5KKtIlwCCQmTbDp5UveoqYOcgZD2TMDgH1b6I5YcikjYJ9nHp6Ghu8QtF24Z293FJbVhuy4qTjrY1TG49PaN6ZlPiJSt5dXMF6FbJpzyFBF/5L+n7s6kA4xhTwFZZvqdY8s5aOfQ== 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: It is more intuitive to go from prev to mid and then next. No functional change. Signed-off-by: Vlastimil Babka Reviewed-by: Lorenzo Stoakes --- mm/mmap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 420d6847c94c..be60b344e4b1 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; - next = find_vma(mm, prev ? prev->vm_end : 0); - mid = next; - if (next && next->vm_end == end) /* cases 6, 7, 8 */ - next = find_vma(mm, next->vm_end); + mid = find_vma(mm, prev ? prev->vm_end : 0); + if (mid && mid->vm_end == end) /* cases 6, 7, 8 */ + next = find_vma(mm, mid->vm_end); + else + next = mid; /* verify some invariant that must be enforced by the caller */ VM_WARN_ON(prev && addr <= prev->vm_start); From patchwork Thu Mar 9 11:12:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167262 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 C4F37C64EC4 for ; Thu, 9 Mar 2023 11:13:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70079280001; Thu, 9 Mar 2023 06:13:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D1806B007D; Thu, 9 Mar 2023 06:13:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F4226B007E; Thu, 9 Mar 2023 06:13:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F3A8E280003 for ; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 17DD51410CD for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) X-FDA: 80549098350.18.8C140EC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf20.hostedemail.com (Postfix) with ESMTP id 1E1C11C0010 for ; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=L4GQl+rC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RqUUZs3z; spf=pass (imf20.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360393; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Gbf95vBZ5k9dAL8M3+AX1LlYXPAiH98C9Dqf/EiMlS8=; b=r0wqWAj/8xuidn0J3BhizmskRiUhN80gp9XlAWm2L+kuex+IpP58qkjNvL9un7mCeBkMnx 1ZHrGOTuiMQhIYBQkbNZ12qxqdo0V8g/ex6cTko0DFIi2Sz+Eezfd9ZDZG5TOEbSQiNolc iGYXWxbRRqmrMG6Swoz1pTLmlZN59cU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=L4GQl+rC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RqUUZs3z; spf=pass (imf20.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360393; a=rsa-sha256; cv=none; b=Vhh9CsJ7iVWNXL1O1ZtrDJht/A2mav5YpsQfQtKsBYaLHFlotPT4C/9hoBatjeX8Vztgut vDxB0my800nDkEcQElS4WqnTWmFM6laTeWmXtAvFL+MC5mP7WR0Wqa4ULbzFWVcINMlyn+ duvVjRNhbEbkCdt/505TKBgUwXX7IPw= 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 BA22820038; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360391; 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=Gbf95vBZ5k9dAL8M3+AX1LlYXPAiH98C9Dqf/EiMlS8=; b=L4GQl+rCi7b/MlyiNCdlvP2/QHKYSvrumdcDGMrBzztwmi38bCFmnGky5OC57tE0RHNqs1 7ixmN+UDKQDs7qdXNJXp8kM4Yh6i0SgG3yx2LHagLLa6elEk0YbHrXOHaRnzB3yiNaZ15O 06yPlYNnALxdXMnr1zP8jY0WKHDijDI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360391; 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=Gbf95vBZ5k9dAL8M3+AX1LlYXPAiH98C9Dqf/EiMlS8=; b=RqUUZs3zze8kfxz8IeZ6c3MJNo33G7eXkX3dJBPrfXidjrYIU6s49P6pyslGajl/2z7Pgk kkgN3lTDU9B34LBw== 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 9F19A1391B; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4KlAJke/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 06/10] mm/mmap/vma_merge: set mid to NULL if not applicable Date: Thu, 9 Mar 2023 12:12:54 +0100 Message-Id: <20230309111258.24079-7-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1E1C11C0010 X-Stat-Signature: 4p9fquizairejenc4sx6fh4133erh1sr X-HE-Tag: 1678360392-210427 X-HE-Meta: U2FsdGVkX1/VFpHEk/Wm9173KjqgunkQgNof6arg9Vma26ZiiY4Yy536b1D9UU3CaFlTqGZF+z5+aE7exQ1pzsnOunewTMGlr5VMxnrCkHrNWDXjTPae74r+XN8SCnLiiOcm0XCrrf+z5j4UvNsBKsZ28/EeA3qUtEDFvk5VK/Qqtvar6ies+e04Ew9VUdEGQVQ2fbCRo+K7dQ5OErk2xXTsakQHMYZfZXuddC/+4V2cP7Gdj7PrvUWlAYXBF8Ut9r79Q7NahllZsc/r13GhdNqugYl9juQ2U6e9V6w5lOcaXxsgbSZz2+DXTq41R6wZClYNgHchQQW+mE2lAjslWnAsUX7Dqf98A5q5ILU+bmLbmAgINHWsvv/2ckWbaUGiLCFdCxARcwEuNyEeP+iWjSJ7WVKVbswPWYPTvl5HkKkjrMrLoTjx57PbaA8+bJhh4EemcW8zkA+PXtUK7p/lT//dwFYnxa/yJrJQLp+MvWBUvdFk/TuqALb6uYWun7WQ2eVR7BUkMYzUwGMwrKcvb0eTqB9f9KZNMP+CDLONoEIwNpC7KxjSBgdB77hgYVXWR4CSGXvslxD3u4LsbmNpoOQNa+ocSAGYgu3/OfoXg5Va5gJPJZ7guNhE6QoGMpbZ15AK4k6rg7KqJBdAJRffHgrejbhgLKa+0EtyhjdFzbFtYzFRcfkwrb0CWRlSy2ztJGFO9Eopso6RUp4EGFJLTYhSmTsFUYbf0WL2K77rNmMFuwYlJ7PwpxD9LRR3KYwB2BxowX2fvEhnzLYTpY3V1FZyKXmVpqia1RObDNjaaFvbPrW1Whyvz79g2FtcCByuMXQE1h+C1C60papaF8Uk84pJB5IXQYvclUDjr1j/PiAEcbianDEifwJy7+Vm+HiXPoRQV6TNe83PePekHm1Ar98bJh07xWQw2y1lnzidKL4JcyEQoUi2Oz30SpOm3dTprSQw3Xg4FZJMO7fezSs BBk1782x BOczM5IEnNTwE8c0Abq9PZPBul2sYHV6QE00MY9mPqskOTnmGbumsh0y2uenvTKMbcOadDJ1vDx1iJJ2ovxuUHgOaDdcM0qPiNskaqOM2mAF7xTm5rk3XqK0d1KIDBOlLf4dMMioSeBT0e01bqcltqrrgIrUM1RyGA0MSKZXUhp4FkdP9U02KJIv+Ij/fGS68gBVQ5Z3cJEa6agZ+tw5m6otIZtk5DYK3dHXfE/+tHyn7e9vNHiDjdxAGOQ== 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: 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 Reviewed-By: Lorenzo Stoakes 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 be60b344e4b1..3396c9b13f1c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -848,10 +848,11 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned 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, unsigned 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_struct *mm, struct vm_area_struct *prev, unsigned long addr, @@ -918,6 +920,9 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, else next = mid; + if (mid && end <= mid->vm_start) + mid = NULL; + /* verify some invariant that must be enforced by the caller */ VM_WARN_ON(prev && addr <= prev->vm_start); VM_WARN_ON(mid && end > mid->vm_end); @@ -952,7 +957,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, remove = next; /* case 1 */ vma_end = next->vm_end; err = dup_anon_vma(prev, next); - if (mid != next) { /* case 6 */ + if (mid) { /* case 6 */ remove = mid; remove2 = next; if (!next->anon_vma) @@ -960,7 +965,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, } } else if (merge_prev) { err = 0; /* case 2 */ - if (mid && end > mid->vm_start) { + if (mid) { err = dup_anon_vma(prev, mid); if (end == mid->vm_end) { /* case 7 */ remove = mid; @@ -982,7 +987,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, vma_end = next->vm_end; vma_pgoff = next->vm_pgoff; err = 0; - if (mid != next) { /* case 8 */ + if (mid) { /* case 8 */ vma_pgoff = mid->vm_pgoff; remove = mid; err = dup_anon_vma(next, mid); From patchwork Thu Mar 9 11:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167260 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 05633C64EC4 for ; Thu, 9 Mar 2023 11:13:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D7A76B007B; Thu, 9 Mar 2023 06:13:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2B7B280001; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B26A1280003; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5B4FF6B007E for ; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 24E4680784 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) X-FDA: 80549098350.16.290F6C9 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf04.hostedemail.com (Postfix) with ESMTP id 2991E40011 for ; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="B/CM6zj2"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="oNHa/N2c"; spf=pass (imf04.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360393; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=H5Xl+u0fh2FgM3W17DN3PSvRbLMjIOp4J+v3PnRSZIo=; b=amtTpUb1Ba7oXTk7tqV4BiX2fzxgYENRFbkq6N5Zb0p/1VKNZcS0k+BT4MpNEy2pQsVudA 481MYBWiznJtsXswWHu/vhuyJbuB0T7lanq+tJyy5qNKf1coiCr0Hx18rOvkdtT2AgAbFa 4De1xlVXCutsWN9Ewwf55a+g6FQQOZQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="B/CM6zj2"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="oNHa/N2c"; spf=pass (imf04.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360393; a=rsa-sha256; cv=none; b=nLSblx7Jbe42q8b6h6sSbCnQzXEqsFuBEUaDtAcV01A+zrQ/chyavuzWZEYABFkcKJ0+DA swkpSeAuPHziVBKZnq0nCvrtk7bqv3LwNCzpEbEUD/iau3QmOq474V2PNsMhFBpfi5EudA 4x3WkUQJtq2YNYrMJEPzLCOTNfUnK18= 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 DD1FE20039; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360391; 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=H5Xl+u0fh2FgM3W17DN3PSvRbLMjIOp4J+v3PnRSZIo=; b=B/CM6zj2HePtuxZyWrSBOI+UpLPmAYIkevuMn8C1gakrbEx7dx4iWnWdEWCjgvFUYVVUZy k7q5PeFsmR6+U94AH7pmEh964kEjclVSO7u6kyj/hU04saF+BWM8C0OR9Ec46vrX2itxVX nosl3jQgoKjWKudlG81Kp3fkVEQczgc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360391; 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=H5Xl+u0fh2FgM3W17DN3PSvRbLMjIOp4J+v3PnRSZIo=; b=oNHa/N2cnuMf0OOPPR/beI9/RMdRl/JNf5JcX8V2U8tICXzM5KqpPDQQXmiUIn/6euVKKV y9QumAAEW80pDOBw== 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 BC57113A73; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eL1bLUe/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 07/10] mm/mmap/vma_merge: rename adj_next to adj_start Date: Thu, 9 Mar 2023 12:12:55 +0100 Message-Id: <20230309111258.24079-8-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2991E40011 X-Stat-Signature: bsbkxtnm3ag65ffenc4mfd78bawdtcuu X-HE-Tag: 1678360392-256688 X-HE-Meta: U2FsdGVkX18V9GEEahY2iClBe01MokYEM+rrEzY81KCid6EZbhIWynhsDJJKkiAZGu6BHPZ5ZEgmcIv8WHXDKXteh7nEdaGofJY88psCZAFVXpE+l0ELTnwE+9Pai2dVETiEGsAk+vSUe+PIoknB5cGFUAK2MlrvsZwMmxHHeLRZ08pejo8YmtCYVc5eLQlK/Ex+Khlo0U7CPPn3BaMk5Jt/OAsSM2/cnfDfyzrVZ9dv75QHywxNviDpQU9YlrJ/lSkzrnjtk6DChqYYuA5K8uNPcNlQ2h5wqawejlLvIHmbhmZWC+SmjoPldVMzvI4aJ2sScW0S9CCoOLpWYvGlgUmF2GAJBK7uWhWK+7KpesINcJPaYQqzqD7fHy6PjUjYlnA3wXNJFhqnxodQbFPVIqyFHU5EJ2XsrnMiVsnOtxB03hL0sMXhtdRLGOr/payMidZtOjQW5WLdgghDEzUQ4BB4vQ/6CJIRkkd+osCcoQCR4UOM69kAMHHuIuOIpjPGUhcZYUcjbScPdYriGk73be/lHkrUgoh1G2oMCU6DzoLVWVlgDAiTnGj5KPk50DQErKoIICcTS2X5/RbsW2u+0v+fRaJwH+0ajtFkJVZFqN1Wymq59Fj2O9LTpvRr0q7fO8dxI6a6xFZpff6EHP1jFxWvstITNArLNJa6Lvj+IeLHp4RG2pzTH7bL9ZveyTAi6kKxdQH4uMUItsR7+NUtQv/EEXU9brI0BxjC5qodF7RucmpAujpJCz2jdNEuiRl07xKDvjrze//M8x290OuyOE4Hab+rilBDf+DFPwbr+s83w9EbepLeCis7Bzu760pMr/nuh1cRebth4e7Rg3Ri2hvzcOJ/hfdaPWxQl+uFZYmi8POX/n8+Wj/snrJwz4cwy9QtCX67jOXgRE3gceoOiC6yDOD7XQNEgTHGCLaukg0QHA+yXWiP/b/JhRXZx1L7E5Bn0j6f5CJPYmTBAlq QxuhEvJo J8/VRAQj7F5TfDFs9Lm96Vj0NxLedn4Tb/fB/1/jByrgJLRqTxFE7c9JalLP8XRYKVVpoEOBisHRFDe7z+7EM2++ysRqlE2G1qd9tt2GWuel7ekHsID6JsH1bOhnkglSnfyvLC8wCngxyBizQ4WwLYjJ1CDmhxyKDzRCTn78jK4/kM5w3D3ttoEDW996oDkCmDx64kxvD8EZnJhhMaOUIZ/ll0VOPViiri9YYKlnM8EnppxIKzfUh+fQNVozbqaznUVgv 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: 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 Reviewed-By: Lorenzo Stoakes --- mm/mmap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 3396c9b13f1c..c51d69592e4e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -903,7 +903,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, bool vma_expanded = false; struct vma_prepare vp; unsigned long vma_end = end; - long adj_next = 0; + long adj_start = 0; unsigned long vma_start = addr; validate_mm(mm); @@ -971,7 +971,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, remove = mid; } else { /* case 5 */ adjust = mid; - adj_next = (end - mid->vm_start); + adj_start = (end - mid->vm_start); } } } else if (merge_next) { @@ -979,7 +979,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, if (prev && addr < prev->vm_end) { /* case 4 */ vma_end = addr; adjust = next; - adj_next = -(prev->vm_end - addr); + adj_start = -(prev->vm_end - addr); err = dup_anon_vma(next, prev); } else { vma = 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; - 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 != adjust->anon_vma); @@ -1018,10 +1018,10 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, if (vma_expanded) vma_iter_store(vmi, vma); - if (adj_next) { - adjust->vm_start += adj_next; - adjust->vm_pgoff += adj_next >> PAGE_SHIFT; - if (adj_next < 0) { + if (adj_start) { + adjust->vm_start += adj_start; + adjust->vm_pgoff += adj_start >> PAGE_SHIFT; + if (adj_start < 0) { WARN_ON(vma_expanded); vma_iter_store(vmi, next); } From patchwork Thu Mar 9 11:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167265 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 DED51C61DA4 for ; Thu, 9 Mar 2023 11:13:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CE406B007D; Thu, 9 Mar 2023 06:13:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 614B7280003; Thu, 9 Mar 2023 06:13:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15BDD6B007E; Thu, 9 Mar 2023 06:13:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EA1666B007D for ; Thu, 9 Mar 2023 06:13:17 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B59A240F29 for ; Thu, 9 Mar 2023 11:13:17 +0000 (UTC) X-FDA: 80549098434.18.A8B94DD Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf22.hostedemail.com (Postfix) with ESMTP id BC4DCC0016 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sfxic2yr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZVdLPchM; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360396; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ra+ZGGzJYIV0TLCmIAChn/kbsadv6V77veypyDRFCLA=; b=mInv7hrcKBbNUSEakp7qnsofygBitl2NtAorQhLM+rhSn5H9KdQ/dRD7ywRNUHH0EULsJU WoR41gzX6GKQgfrIaViXOq0OQ+RrUTqwKfLgRIHM5YtbrIFqWCgvBRo2YX1MuZPlOZJHr4 4YpCDt2xhZK8RFd+MNBSlOK7jJ3ilrk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sfxic2yr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZVdLPchM; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360396; a=rsa-sha256; cv=none; b=sMjUXWLIGvk5VgVdwXAygr97zNXBzx8wk1+BzwXpZON42VoXANSkIw3vx6ninWdB71UNpE VNjOyayzDuF92YRc3kssGSNT0nOEchOcPufZNYmMEb+tq7dQViIMcHyP2GWBxpC10FQoTR z3isI5OTSqCJeaQW1/OGXQi/SGgM2SQ= 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 0AD7A2003A; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360392; 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=Ra+ZGGzJYIV0TLCmIAChn/kbsadv6V77veypyDRFCLA=; b=sfxic2yrLYOvf66YwRLo8vqMxBrnEtpeVOKZnduvnOFxfSBSWr+Ytm/xNhb5n20j255PvX t+du4oTVsh6QvJqua4oHxcROcbIiXrFamN2P9bqn5mT8G9WLrOHw+25Q7mZK++ja0cL8sB vwqwHI03IUf7LPghvULpND5TXoXN2lk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360392; 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=Ra+ZGGzJYIV0TLCmIAChn/kbsadv6V77veypyDRFCLA=; b=ZVdLPchMQVSGJL1pIvlz6mWv9fXxKyxo2lYK74riQvY8KZIR2pdZpE3B6EqnBXl13tI9YV HySToS2GsUT+/YBw== 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 DD1311391B; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iGVVNUe/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 08/10] mm/mmap/vma_merge: convert mergeability checks to return bool Date: Thu, 9 Mar 2023 12:12:56 +0100 Message-Id: <20230309111258.24079-9-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BC4DCC0016 X-Stat-Signature: 6c4wj677brrrm1d7z7rz3u18c7utkefm X-Rspam-User: X-HE-Tag: 1678360395-385690 X-HE-Meta: U2FsdGVkX1/+sZhNKEkFhrNa0jbrlkVEYcCQyHkYyWcoOA9jOF4Xs1VwYvzwSvNjCQicAsn4JVR3do4aCnn302s5IMZFpOejiIzLAAulXOhVmoB7DK9q23eO3F2dvdI55nlo7+r9AabVfZY8VScSvxrzRzXWXIxBOmqw/LJO8SYZQIjfXDf94tTlobm0he9P6pKN657FHmvOsCL4YfVw8yxfqiGrmQB/8f564bBFMsKC6HGKfZtG5HYhKJnt5Gn8bQ98eeaTHuFpBtnPpc2I6mQB409B2aZYMGoTAOne8m0UNmxrCzpxePiI48EA9eLuI+m8ksqS5kwsAqgy5SlLbYgA7+MG9axooh24IXbDVIVUTH0SuS3HO6+cwpKSioFDn5kqhD2hmfHRei5sZatkOHeoHfo+WgMTlvyDMcOC/x/U5Nai1WRRGJxuJSNSgAgjtZUwCuHZoGmMTo3EqplExi/Hm+S+ihUDSV1xHW9M0qyLInXgJTTDYBHMKrUdWBW1IGZ7P3sLM+hpdNJ1RTjGafGo6TYTDJSqT8dEDxgaMiK6A+DW5BWJHSa6fRCNcwuE4UaV2LEkcaEyeh7vqb6HjzvT/crR7vJ7WlXgxYP8DOlvGIDxII7FTRj/N2a2GbEX8MkbwqNdGUP69HzLh+Dgm8thrICq0liQsvHnXn2m2yQJv5zyljRmNROapnYhWob14cVdtCJR+UHq+FLgwMi5lgoDksnVsCRldJ7Yjo4O4MDYU3ckglOG4A9zfHqjvTD3fO40krQY6f3OvDHUeGZet2A6ED79ubslCKRooS5EQB6x1z22creSdyVzzsrWGLZuczu41VF6nPANnujXGY1Vydp3q50pICnA1Y2NL4eEXIJ8ftvw4OCyYwyvLN92ACZQJH49HNxgYPZZ07Z+S8UybLPmENQZCgCYX0ZY0ISYaG3jYoTE5/+Xk8c6qGfkphxSJbw7YlR6lC59jlpAFFD iv+q8Bse Ct6+54A+fUmIprcWHuDBj9hx3SW/nyJChLJeMiiVaeeVepNUTH+bak4lcTWoN/zpql2rHfwtxKQZzTp7lTeEmMwUFavZXjzfF1BLGl0bOzcYRrPO15lm8reINqjTlpok6c7n/wH02qEo2DMFuRREGA30WKJ6f6etkU7AKT3niBbmqEpipxe+nRwHV5Dh8O67C22WBr8tQMsZD+1Yj0w0VgldG8TFbzEP/sfWoj5LjOyZtcjdpqBL7Zv+fH3bPWpYGdY/i 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: The comments already mention returning 'true' so make the code match them. Signed-off-by: Vlastimil Babka Reviewed-By: Lorenzo Stoakes --- mm/mmap.c | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index c51d69592e4e..d20bbe9ec613 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -744,10 +744,10 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, * If the vma has a ->close operation then the driver probably needs to release * 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,20 @@ static inline int is_mergeable_vma(struct vm_area_struct *vma, * extended instead. */ if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY) - return 0; + return false; if (vma->vm_file != 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; } -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 +779,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 == anon_vma2; } @@ -795,19 +794,18 @@ 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, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) + struct anon_vma *anon_vma, struct file *file, + pgoff_t vm_pgoff, 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) && is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { if (vma->vm_pgoff == vm_pgoff) - return 1; + return true; } - return 0; + return false; } /* @@ -817,21 +815,20 @@ can_vma_merge_before(struct vm_area_struct *vma, unsigned 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, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) + struct anon_vma *anon_vma, struct file *file, + pgoff_t vm_pgoff, 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) && is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { pgoff_t vm_pglen; vm_pglen = vma_pages(vma); if (vma->vm_pgoff + vm_pglen == vm_pgoff) - return 1; + return true; } - return 0; + return false; } /* From patchwork Thu Mar 9 11:12:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167261 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 69E66C61DA4 for ; Thu, 9 Mar 2023 11:13:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 416EF6B0080; Thu, 9 Mar 2023 06:13:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BC406B007D; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFD446B0075; Thu, 9 Mar 2023 06:13:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 878A5280001 for ; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5ADC240671 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) X-FDA: 80549098350.13.3BF3D3A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf25.hostedemail.com (Postfix) with ESMTP id 5D44AA001B for ; Thu, 9 Mar 2023 11:13:13 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=smy++lI0; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=e4ZqfoND; dmarc=none; spf=pass (imf25.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360393; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2Qu5xXTySwPTF8dLZgi/I8vkKzIjKqyV6OaDVaB++xA=; b=phxLpMECc4qmdxHNJFOHHgQlT9f9sJ9WjMVJvBdZBmbEdRdqtwNGAGG0ltAUGLC8ip04dm vI6k3bVGknbNg+mJh3Fz69FcWTn+kprwIOMS1OYLy+PqZPEbXXioZ3XNeMGu7JVgDBSsOP puFc1M++GjFIKXzzr9sAdIOgCU6NBPU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=smy++lI0; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=e4ZqfoND; dmarc=none; spf=pass (imf25.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360393; a=rsa-sha256; cv=none; b=13V5GfRgEde+lmNpHVavnVi6yHqHJVxxL/9jBFDx8W+RqXdscW/kBhXmC6eOAwrEIRnl5J piUO5ye2vEhr5iE6LxU5RZnlo+ehwa96RpqI9OcdwBdCIvD9E/KZxVZUM1FxsuA+vchM3C bf0lXRDls55tC7FSb2YcFR7S+mnGGLA= 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 28AA521E8D; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360392; 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=2Qu5xXTySwPTF8dLZgi/I8vkKzIjKqyV6OaDVaB++xA=; b=smy++lI06RTR8P0db6O40WjBYDL0CeoTsxIDL+R5wzE6TncyoEn05HoKhjDWqaGzli6JEI 3GPGSrV0LDlKChKJhDhqhxVaooJcuqBjs0RN+6O6N1NHB8W9t1Iyg0t2hLpFQzhKeULqs2 dgjXsXdgZiumNxXHEFV8o0dUFaFQGfI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360392; 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=2Qu5xXTySwPTF8dLZgi/I8vkKzIjKqyV6OaDVaB++xA=; b=e4ZqfoNDC7qdrfkIKt0ip7rtx+nWJSRX54u1pQUZUHNLoo3srPoDVcEHGdEnh7PdXiVbw2 e9byDlL3I6x1iZAA== 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 09FA513A73; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YLbTAUi/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:12 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 09/10] mm/mmap: start distinguishing if vma can be removed in mergeability test Date: Thu, 9 Mar 2023 12:12:57 +0100 Message-Id: <20230309111258.24079-10-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5D44AA001B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 6se6eq4ifidq9947cxznt4uhpdwtserk X-HE-Tag: 1678360393-560519 X-HE-Meta: U2FsdGVkX18YGabsZXQDI+4AzPsz6HNbGOi3EyJ9l5WEAz54bLlIfKeqmJKj38R0iF1Xzkgxj1xgsYaYL51M38Xb5CiV2vc/oXLrDs1wkbc7mHn0JxC9q89ExtTqpsah9gzmpviq4IXaagK0k0sCaB53df1BkB1NNZXF4hr0VwM3mIfMTtc+6P8e/Rif9DBZb2cUVDtTl+zKwRpg7tLkN2jE6VMxHhTlXR3q1FDm1ihQJyb2wN2wYKle7nqVCxufThTwf2V5zkvdo1waegVfTtmNkWuYFRa+fLcBbilx9ExojyPPCtGP1wMzjmovTrS9vQc63lD+fqPoneqTmG2NoFUt9BwtSZ+zq5kLVe+IjIjR/E7z7Un7UTJcYvU8r6X6kN0BbN7Va1lRPfj2CCQjlgwnB61XphEjFnIs25HF1IEV59qz5X0NJaJyLiojtXaBEPmwv0lBnoGAkyOGWW+Z7rjlo/2LufGYO0HglOryRrWoU3jod7GaN5akN4KrD56PMvl18ThP3iw4HcxV45GQI9yS6A2LHgME0bPa1D+3zl7/AYHFjdYaLks7Ckh99NKiOI/oCRtdrDOHADvPPS5hLLq2EjZ2Iw11DXpR2UTxwUBfv+giAjSfvL5tqLQtSyzPOArsLCAOJOCJxEO99duh3ym572VsLfInWjG3TiSBNRQUlbMfuaffTUd+4qwIt4Hp5cMlB4MV1hcSxPrO3foAWwerN5iqG0/zilRYuba7qDWqB2Wu8oXXNiEa/ekeTOP6T7JgPTXVZRPwupVCGsoZWm2cVUZt3gN6Q+HrLpnXTO5/A3nRQMRvPsYQS5YvqQRac+DfUCJnSe/aWPrJspNbXy8rBiZI494iTJLS4X2bAdQjCfQTpKZnjzSOnC6HyeK33mKzwpgQieXtpkTBrT0zJGit6bwolRR1uB8f8R2AqS3wiacf9Cc3fP71kjz1xNhOXrLp/nuskpUo9XdK5pX xVfxIiOI eFUpPS+EklcH+M9w0Y7S761svSvMHHjASLndZF8LNFTRJELwHtD/j90AmY8We8lmoErEvYfSQnHdMGOWHT3iIhuP5nCtJQPQhc918tCdK/1e2sw5Sty6mCq5D8kQZS7Ov3o2fkj3CwGkRrHJ3qcYU2Gnxmyq0FjoAqsWL3yVhbY4P+WEaaS7n3txXqoJFDc6R9gwI+wN/H2ObhsE= 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: 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 Reviewed-By: Lorenzo Stoakes Signed-off-by: Vlastimil Babka --- mm/mmap.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index d20bbe9ec613..65503ea07f32 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -742,12 +742,13 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, /* * If the vma has a ->close operation then the driver probably needs to release - * 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 +762,7 @@ static inline bool is_mergeable_vma(struct vm_area_struct *vma, return false; if (vma->vm_file != 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; @@ -793,6 +794,8 @@ static inline bool is_mergeable_anon_vma(struct anon_vma *anon_vma1, * We don't check here for the merged mmap wrapping around the end of pagecache * 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, @@ -800,7 +803,7 @@ can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, pgoff_t vm_pgoff, 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 == vm_pgoff) return true; @@ -814,6 +817,8 @@ can_vma_merge_before(struct vm_area_struct *vma, unsigned 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, @@ -821,7 +826,7 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, pgoff_t vm_pgoff, 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 = vma_pages(vma); From patchwork Thu Mar 9 11:12:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167264 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 A46DFC6FD1C for ; Thu, 9 Mar 2023 11:13:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 160706B0083; Thu, 9 Mar 2023 06:13:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0240F6B0081; Thu, 9 Mar 2023 06:13:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB75F280003; Thu, 9 Mar 2023 06:13:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B90196B007D for ; Thu, 9 Mar 2023 06:13:17 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 77196A75A8 for ; Thu, 9 Mar 2023 11:13:17 +0000 (UTC) X-FDA: 80549098434.22.2ABAE07 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf17.hostedemail.com (Postfix) with ESMTP id 8603840012 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IN9yYJDP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=hsyPFizF; dmarc=none; spf=pass (imf17.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360395; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Am3Z7D3PJEF75x3/HiQBrnXvVKIlV3/Qp4c3FogRta0=; b=kFkbSRXrAhZV5Ie/p7ZI9awUzdtpDa6stald7mk9vEjxb1B/THCuOiq3kPU7DK2stK8NZX LDCgKoB01JxPmk0ivX2DzsAzOz2ndj4dmLwog+Q/4lNmLZRvxZhSzhECTUJJP2mjD7cYx0 RXFb9gDwMCNlbkixScYnW+nGZfHOMAU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IN9yYJDP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=hsyPFizF; dmarc=none; spf=pass (imf17.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360395; a=rsa-sha256; cv=none; b=QizU15vjTOgBL7FHu5FKAqCeErkNj34DQJEpto9u4taPKbaIl7CEb4yXdfYTQ+IInoR3bq gDh2UKOxh5OVHDB5AHP9GFSVJm2r/O/MOodC2Ocf82qA22iwmsPu7EZjHu2/LQVQ2AqNsj Q6WsiEqAHI8a4lV4obbf9STxdF+jmCA= 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 47ACB2003B; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360392; 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=IN9yYJDPpAsUzcK/lBOeD2OcF3abAzwQ1DWsa1jg7+7eKnFdayh/P6CMtsBy7OtrQm00nA +0vQ3fFLUakpP8Rn+BjzZ5fmS5nIOFNikGqmEYsrfsawuNGhaI1yOvLmxMGMeyqPH1PF3a nm4+jG513He9UWKRAiy73yO6m8P43sc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360392; 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=hsyPFizFKqJYnSdS3E6xpTXq9S6r1rJ5Jji3li+g88rTqmX7AeSbhzGXDyIih4Pl7bflMh GAWJAY6loxrLWZCw== 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 2AA711391B; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mBDLCUi/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:12 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 10/10] mm/mremap: simplify vma expansion again Date: Thu, 9 Mar 2023 12:12:58 +0100 Message-Id: <20230309111258.24079-11-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8603840012 X-Stat-Signature: t4qzxnfgmjpadjjomf3on3ibsc6nn7a3 X-HE-Tag: 1678360395-265368 X-HE-Meta: U2FsdGVkX18vjT3QjgkpPUauz9c3jN21dJgoEJgLFeIb3cND1Gjvbwxppn+VhARifWCkWAfZAYKYjhtG18faA7ohn8MkEWf+VjlFPoX2fgjRpyGjUOELjNqMt94u6frSXNc+sAso8skgXc8GP0Gs9i7WQe5wqY9HUdrOSYWJYf2xTls1IOxI4RHtkvYvCjTI56CtZxxHxiCy7k70x8FPYtt1ADSQGpy2CUL7aaSwTGIH39C8ZyTH7PGGrGNOJj43hk/3RNVylCL1cUEioIEd+AomtYXqazB1wHO9grKKqN5pH26uoI67PVlla78lvI2UZOP9YwonKDRRFtfgkgQp7dmenX4O1SIww2Zw6IakzSMngmwOvbB2op0kp0/vniKN2yM8a26T5tMnORlyYU/Pk72ZkoQLnAyhpiiauLL5W9Dbn2+e8ds/SXzO/5/kLPBCdvUUS4L+L1GOguYTFcwwyUgLbZCIsj8OSkX51mI5uq6ASEFdcUmH8FEI2qCxG8l694WhAaQrvlB7rYhhZFCas0CsCgqqCSmF+MZg0X5+Ay3RhK8J18ulepdE3CQ18Kad3uZjE2n1UGvoPA/9HgLEejtTuYDcOOxkvwh1vQ0XhB53qzZyZ781YzZg+QG0Vkv6qaLhQfJ2vhUa1V40IG77jhB5AFlTGxTmMvRToupzpkOohFKe0hb/BNau+A/5YB+42JxCb+JC51hJL4ijDT4XyGbF3779Qyu4A/oBk6rMkhukpldnQptlbK2GgSCMBEl7/WyZjsY9xzOR4rptMK3Hp8z1XOj02NA0F92+VNpCCGCZYA2qYGMpzeV+aWcdAQZRviVM88r4wIF4getKiEjwlblANchWeCKNws0HtXk645PKTBVGpT6yaErfID4D4YMiH/ahwwE0snb2xYby/jRhnRA4EPx8/6j+gYA/q73i85qUi2IIvwoqOxINWJsvMT9DTiVM3QHwij7IZS2leXQ 6ur2b5Oo PwyLA504HJ00A5yHUGD0xFKBUyvRwTRJ7BIPXsjIOQPrGKRmyFXRBRLM/bZsdcxJ6o3q8vKw3LQJJW/rVA57Juz2GrYYY2VA0S++9jNdJayI5RRw20IRpRBAHuVGV8pw6kpdXJ3Qt4sj3MLaXcXFL52f/SlR2L7TdMOMQCZt7sBfa0+9iuUYjB19j12x39ncpLPUi8ptfyB/qU6g= 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: 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 Reviewed-by: Lorenzo Stoakes --- 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, unsigned 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 = 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 = NULL; - } + vma = 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 = -ENOMEM;