From patchwork Fri Feb 24 10:00:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151070 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 CE3E6C64ED8 for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17BB56B0072; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B7136B0073; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E99816B0074; Fri, 24 Feb 2023 05:00:44 -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 DBC686B0072 for ; Fri, 24 Feb 2023 05:00:44 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AF928AC25D for ; Fri, 24 Feb 2023 10:00:44 +0000 (UTC) X-FDA: 80501741208.04.9642891 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf22.hostedemail.com (Postfix) with ESMTP id C7A16C0023 for ; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=eOJS6frd; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=8uSvZSyN; spf=pass (imf22.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=1677232843; 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=bQMJWpenP6OEu3AR0STwSIwzPSjq3AkhCnZCUwU4em4=; b=mNAXMQAVjTkp2EwdOo15w9lucHKHqBlJGfhp7ZeqPLdvZ3uFBGQ4OdRJHBa/uycqALONt2 oREyl24EX5gaRAEIL31rKYu9n4v1PmWU1iyKcZ2QuOrAyxL+h/o0Z9pvVOUk2dDaET7SO+ NTlPU3QV5wn0jyBGTlZiAwYSrJw/88o= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=eOJS6frd; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=8uSvZSyN; spf=pass (imf22.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=1677232843; a=rsa-sha256; cv=none; b=g7VeBTfqabFJ44YjsVk1mlg6MsMkwQfNGaHBYerDRJ6cFYOa8ohE6eJeUcsk1JV9miGv3N +jJN7BxvXNd/O0rL9kAVcmaB/mBkoJJfrypPPXQJ7ZsV9FiSHByS9lJKa58RmWuc4MpF4q 4+ZR4QJN11h7CSoufcUCGRuZQJ9UEL0= 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 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C7A16C0023 X-Rspam-User: X-Stat-Signature: eg1598ybnsndc3c4qoq75bcdkc6irp6c X-HE-Tag: 1677232842-968228 X-HE-Meta: U2FsdGVkX187MfmxbdrbuQYhJPno+wOahAOtCN7tl1oBg2I5ITmku+ws80qp/5b5f+7LkOGx1GEMpWBSTkKodXvywlZ6G2Tu6jqnzflQOCC6OdbQreEHhJwxyTNEUMgSxxK18jsFQlZV882THbYD3a9VslJ+Dm6CAuqdlc4hmEkKgpqL5oMRgiZKRUoxFhHEOvhhze9k6GZJvaX/UYv9nCoXdxRPxvrtzleDDqB09/wMpCgPy23V2Tns27sFjPk1q1eggofZ7EKDH3fpIRLgKHX6v7TFyzJsG3FDGQxeaiFR8FUcTpmNCftYZRX2ev5ga5oQFHh1sW9rN4EGws7iu2bncdmbGYd2Ta6ymDpvn+Rdjp6mO2RHOIoox7n+TJtAK/uMPSA3VpWK57WXni8Gh1+xoO9TFE9nnS0rogplhQfoY7OCCHs/4dIM00Y9PDOJS5VI3NniC4z5hPxBW1cBvPuRXA0O7zxsL4AfI/ykPyJAlYytoXF30V/uDpGvpQMKXzmJrLDHHrtXfXX1NaMViNaFiiYblhdGH44frWPKOo9J4mczB4LgWOUjPzkrrQNPTYjURWuWY24tAUUB62ttMXHLTaor80Szs1qL+rZOgh3S4lBzQJHPPBHapN0vZ2XifmaLJFtrWT+jjly/iUOAH1uanDmKzUH9VY3IE1r9hm40fgLPPXw7MzDMfi9rby8jsGce5kEOSku/a9NtAJXzwHk3Za2JP9BwKAd9NDXA2CIOfKyC1sTDc8dRXF3vMsbWccN4ShzT4wWtzFsX30aDHW8QYXW7KHuHcQGdzxjAXjLQCagRKoA9yyNaadWRT/0QbFrmkVMAcZpXtL0mNMvadQ/n/gOytp8WPSIKZHQ/mCkdC9AlbyQjwMYjWQLi6N8RGXfTMsk2WpRyvJlDm+FZD3bcATyDzZnP2yXNZHZuK1rIdioWUS8w8XE+ybSUcsPDXH1gZx0xvofNbmGhoq4 XayYBgS8 x4FemPC6SsFSeupKzYYtlt+vYDoEYpehQI7OXmIqmNA6sxrS+lTGvlgZdLziiWmUVJFL/dh097X4C9jWQLbJsTND47XQaAMgWruQ62tZ31WSDpH4Xik5fw6lw2mVUlBPW1ieP1706aGarIUpfYWZm/Exo9gXqDspSPrUgFcSMRWUByUVsZu9fxLVCU6mvfiN0ZeafGkOPUnTzwAjImJU4N+sIOYcMptmgnq1ODM/dua0O4/nnlBUF3lvtQw== 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 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 == next, adjust == mid and mid == 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 *vmi, struct mm_struct *mm, vma_end = addr; adjust = mid; adj_next = -(vma->vm_end - addr); - err = dup_anon_vma(res, adjust); + err = dup_anon_vma(adjust, prev); } else { vma = next; /* case 3 */ vma_start = addr; From patchwork Fri Feb 24 10:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151071 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 B8692C61DA3 for ; Fri, 24 Feb 2023 10:00:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 572936B0078; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5238A6B0080; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32E2E6B0078; Fri, 24 Feb 2023 05:00:45 -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 0DD856B0074 for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C4511AC261 for ; Fri, 24 Feb 2023 10:00:44 +0000 (UTC) X-FDA: 80501741208.28.052B663 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf17.hostedemail.com (Postfix) with ESMTP id C4A9240013 for ; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Tr78MlmM; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="vEOsnZ/8"; 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=1677232843; 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=U9MQWP4bIr+oRG2J5ZuaMVynOkEKHcmwNXLVQ6mIe93q8VG+8MvHAeY5AdQ2dOLTVLi/J/ /B9nT4Bs+/wVziv1ueNK92hjJQ6Culggd+AYuqIlY7AIF64iOgREC73WSnuxKZgFEn69q/ 96ftPVj0gLmC0MRxtNyhMDR+mdmUOU8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Tr78MlmM; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="vEOsnZ/8"; 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=1677232843; a=rsa-sha256; cv=none; b=LFvIT9lbhdN9Yzk6wPYq251U2xmLD5TECgowvI6bCYF7mxyhMmTTxpC95ZJLvUWP0FkOq0 vqA6tw4fOn3XzMkqFpbqHP8SGjA9Spi+JyeLZz/1cRVvGm6aqhBlpqBy0MxI+OtbQ6sJRN VKfM+RGrkqdB+/FaYpFxWEk3pOkGbwM= 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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C4A9240013 X-Stat-Signature: qcdwnrwrf3c47s7fuzsxg58conygq5uj X-HE-Tag: 1677232842-57093 X-HE-Meta: U2FsdGVkX19P5v8+ONBhLiBsMzwcDunCho34YBkeHe4PMnUI81ZlbrESjFxewk3VEOASKK7GzMFNvw+MrKdOq/oMBu+BuOlh1wrhVhFcR5anr8BAnegrsWSv/vzQr0LR67v+Zx/5b+QyNPB8tQEwBDot1rM22kaeTe/0JmGQHI6QVsuoNyhn5rDHAAm/TvfAs8hS3POd4OZTx1H6NhZvtO4vN8/ZjZcptJC6GHEABIHdnbOYG16GMe/dfkVuc5+h19RsFN15fXy+l0e6isawi8q3jGz0x0JTNUAoIgTJCWy9plgCuX6cM2W5DcDLJ34gVYi+fFBd72vqmcerUQHRKpEqh5N6pbvygs9fS/VRUhz/KKg5oAiqjj90FeAxOmJqaNHZq+BIkelts7t11DPE+q6ghjTEP+YG7tWWQ+15A0ICaXMwwyJoBkYmLLyuvweRTmZMz9PsRBtzzW9OMsIGSAAUESsmTqPTdUuh2pd5XMnYRiUP/hCO0i/SjDFuLFqYAEZqUHBXEfASXvBzAyqHHcWBHnXCzzC8pnaF7yr1Vu+A1jvZkSggGvuO6L4dJWEgSp+U1mct/5x0GZENHjKw85Xy0CVy3jmOqJyFgxhHFJQh/+lbqDwWUaesvvYOllmygmyJcSVOhLcIkMKtuTT4Jynz4wurjD7gZ+FU/Zuur4S3y8SHfcLOXaKN6Q7aFnp5zMkQ6CRZYAcX3RwMOCaLgbLNzNX53pGy2trwlNYTjJ3J/6z0xoHI28dBvoZPMAJYl40OxlKAGtAjvIf3mel2XIPBgdQIXFY0ZUQwY/ACrCE5wmLHir9XjUxmt4lE1ys52oHU5D44TniAsbO3L86naCey4kBYENiIw+OfdGQi9M0IYCUhAfdaF4dpQxGLVhiS4IqlzTT4EdPEu2fKLFwdPIlk9YB9vmVAe8B/kp5ISgiDDUIVNqKwbtNgeEgDkiwbjORZ2RmUahkQNXLs2MY sOiCLhZH hsRkOPSKGd18uMsIaho57nN+NjLTHpGQ9NR60f6QNQjvKhhTmSWjEe3wJ07d6N4RdaAdi3ZtVUYT+ulFmN57rOENTVU5y/Sz4dnKyNVDVo/7mLolOVEni3mIdPRlJp26YJ4XK6/t39BCXCiog9OmS+liiMnrJDN4ti5cKWdkaTnIT0ZqdKLffqRb4yPPhHRiqJH74ezdo8rEHv6jeZ6DtyjPckIFTnDJ3PVyXOBxe3zuHaY10wPiCrtdaLA== 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 --- 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 Fri Feb 24 10:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151075 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 96AEBC678DB for ; Fri, 24 Feb 2023 10:00:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25BB76B007B; Fri, 24 Feb 2023 05:00:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 135066B007D; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79B696B0081; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4673C6B0075 for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DBE80AC264 for ; Fri, 24 Feb 2023 10:00:44 +0000 (UTC) X-FDA: 80501741208.23.6065D2C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf21.hostedemail.com (Postfix) with ESMTP id D08291C002F for ; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xNyWzaIm; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=x7ev2C++; spf=pass (imf21.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=1677232843; a=rsa-sha256; cv=none; b=cxmmfD3nxul8nvvU7bhwbuynEo9B68K/Fj5vMgZ1A/as31b/0lCjDqs/2OYEgJDAKnXAue LZ7Zr8E4EoUeUzOjYj6w3IVgMt2RyHpiPDR7zCgYrzNOR9Ma4h2n/hh6HimjEGJHIr3dYb gRPb5Cr1AaTxvG3fNwx6bzn5dLPOF6E= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xNyWzaIm; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=x7ev2C++; spf=pass (imf21.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=1677232843; 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=bme1CKWAZZLvHbkgLnd0wpQMuY5C9Hk/dudC+CBE5tXX7tUnTnsvJXRc3M7Y5qpSCisVYV T6zHyQ8ptJNEvvoPC+34h8ogILOYDpxNGi6R/WG2v2bXnqGjOTAMGgrhG6DyNmBc56t6PN kTeIbwKbP96XLmY+YDTrrPKNeecfujk= 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 X-Rspam-User: X-Rspamd-Queue-Id: D08291C002F X-Rspamd-Server: rspam01 X-Stat-Signature: d39npdoeyzy1q4foyyjcwf3t4ag9p3wk X-HE-Tag: 1677232842-453879 X-HE-Meta: U2FsdGVkX1/IUA+TZzRyxX4ZIyh9BOlng5RTLIliSDy67A9zIx3Qg1UPpLB9l3QzhMIhfYhwpGaRLaJbpNt0STF05JsBHvQWBK3kIcGb61b3owu17FNUwug9XTOEFyhz6CIk+I/36omC5/ODreYXHPa13zNJRTrlzr8PwacjAGOOM47dX0qnhHPpX90nLpqZRrKcBCvMHIOBoYC0Lbb6mONb8NGYYLas/OBJ+E6wq4BG1LxteeD8MBYbpum2eVdjI7O+YiFgYxVEhUt0sG36oc813aRu5xnmiWFyVDZoodWLa98z5MfzZ5dr/qPK3+PzNUvnwY99nC/jqunygwaPyRm+1duCi0chQr0/uTTF5K165LogRUSj51OwV5rRnDAYGZPiD67Pqa+wACtWMPnKdTfnNpiFOsg5ymnxvjrBxNZ4fVl0359PVJhi7hS3h9yVUMCD6O/j4me9NwP6bKWYxDuOG61yS+RvTxdhwzgB2Pwq/0aaN9dXvcfgtGniRbLJGyss8UGqoMeB9uC7DEYFZCbRNcx7zZv1Gvnjkjh+h5SpVgf1vckfUqQQWJ9fRWoU63Ipu2UncQ60cVctf9Hk07kBkKwX0hthZHV1kQaJgU1Fvih0eDHwMrClNIQO90cTsrcMWufrQmJToa7RCAb4TxzCqJwYgO+dac8KjjW6v7xsyU/GHUeIT1LuAgUnCgyQlnXnyeIL/GEffL21AiXnBe8ThY9U+1vQsLtQGtmzRQGj7VSDEiZchhPn/vWTAQeVvSzT+pS9KrWosKgT7zBiQF03qXFm7cNuABT9Hn3PaYcvjyqzlcAkkVA+aN99ke7dt+9uizjJpc8CIOvrIXtDWoIG4ll0kwVzNFiqTsYPYjUietFp0xIlTZD+o0677GGIaDdvN6wSfn+8rQ3dATbD5lgcfX63iOmvFhzIaDxFowKn2uXtKm/ADE/Y0Al+kbIbrLP+Qb7jvZX+hlXU+w7 +LygOeT4 AeKrZHo5X8XcLtkVQCe/qge6v+TSG6KsLXCtzkjetyVEVUdT8+7bJkFTgRj9Z+8zuB6Pf3AmryJ2k8jaVFniN9AuN8Eon+tlFQbWd5sf70woEHPrpjdZMyDDsoNeuviFzqCwoqNUXB+fswcSe2K4soFDSiIhJaOnLxpLGpkvUAXgTk9sX6CES6vBzpLcdK3EExMEvgBKx9vKK/E7teOkQuN0NI813DVPNUBD6LQwArVFNmCJuBnVd2rA1yg== 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 --- 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 Fri Feb 24 10:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151072 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 C3E16C677F1 for ; Fri, 24 Feb 2023 10:00:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8815A6B0074; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 831B86B0073; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 571916B0073; Fri, 24 Feb 2023 05:00:45 -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 39B396B0073 for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0557C1217EE for ; Fri, 24 Feb 2023 10:00:44 +0000 (UTC) X-FDA: 80501741250.23.6B0A702 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf05.hostedemail.com (Postfix) with ESMTP id DC498100013 for ; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=3SY5VXph; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="/jIAtMOp"; dmarc=none; spf=pass (imf05.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=1677232843; 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=qDnc8EEjpBsvOiKhZLRnNlYD59HvUD8m9uXQyW8ks/U=; b=lPdolvJRm1IK6kES3f1gSIdzjM/zZNMRD6gErR+RMpq9yYf4uNA4gUB8fpLMZFG61r+ezc blXtAoqEuKgUVxeU+p+Dr3RadLKDm41bS9yUMd0A5xmmMJMrTQu4Bua1XygdmrTHof9YgY 2hjoG9YwKpgnG0c8kFw3Nz2vahr47XI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=3SY5VXph; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="/jIAtMOp"; dmarc=none; spf=pass (imf05.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=1677232843; a=rsa-sha256; cv=none; b=d3IbqhXsWc+ZSBGSniWp1BWvnRzIuEGXRvFFp07qKnZGTE3x+QxIcV+SnPO+K5yz/SF73Q xmsFhebY8aFhlWB9Ila2ZTsqPog3d625BVF9C13YaTTIoAi+4UJ+S7gdeWyyHKjXaVQ2vE dm1LwG03nmJxruk6oeX/fdBtYYHCfwM= 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 X-Rspamd-Queue-Id: DC498100013 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: sike8np4k3nqy5dq36tnse4pnpgdj8g5 X-HE-Tag: 1677232842-690266 X-HE-Meta: U2FsdGVkX18t19US4H2p4aqUlsKm3+/FRSS/xkC6kQcOT5zgKRoWvZ58y4PXKGBarcwfseLBCGavXCTkxePGKUGS5DTAzjArPTFT0KB4VDFbZswiNLUX0BvypsVdiRqn/SBD6X8zUbLiy5YYPvSQ5YjoqyBHSiCh9PsM26VdoFMyYjHYXskGoRmj6fK8/cZ+5TNvldb8uRiRNPgEfJjZPW22oyTxNgUFtMhQZid3WS1HuVHmR1X9x4gjr68AvOKhK13NIbGdmj3EMkH6zSPAke3Zovi9VltWjRHrulIsEUBFILEMYEVipAtF8MT5DIt31+8vZXn5s7u7BiuEPl9WPhpy4KI41lwN5+X0tH1Fi4K2+rOwlFHpY8HFwai9rlW5oX+0zhjyGbDSfOv1H3Rc0ixOEQmL8ObWILUdp+5itprzXj99Uk9/YzMox/rmim5LDqXcKTjIHXUJ6mt2a/e0n8lLWLYuAXlwjT2sAIVrsbqGRI4o2T+07QJ7qFY6zH4aNfgC8hwEuVUsaGObaTJC2Tua0aBbLs4PFMh4SqfuvYUffWETLCJLGOMr8mj3EMZJpRyhx9EfBJLIdV/7HdqmrCbkGCrS2cUtndKdX7Xyv7CWmZ62umM1FgRJZWAfZmGLQx+gHe7k8UZxMakYx/HFRbrDb80Pdeu3W7xu/GXkQAhBVR5CjNehoRK2k+lwujaTSB+Q26w0UmHnOLRqgfTYVkSV3rTBxz3s5Uzdp/4tQCjumjrYLYuJCPUyHIwaErYBcUyp3ofDf7b36ZJ0jSwVrlV30LH9RvymmqtWlyG8aNNhF8ufwy3qvDkTZmokKbYDobK8hSUUk2LjyAu2AjP+hqYM4IRYEX7jrg04lzsk2L7Q0BHcc8Tak2hDoyfplclGQjEtJhY0xRX1lzJa2+aZecj3xtNwCM9q//nTFWbzcWuskM0aImcpU6IVu3jAQgTxBWDe7BPh6UU49NYSLYX lzhSnZ40 WtbZ+gK7Y3hpYAIvEs2TFJju0SblNfCS/X2Y5Kd8mhzBIMOuJEx15C6P+1Qno02JiWP3UN72uAgjqTTN79PgiFStEbcpxQIHwc37KnNGgVyQOHrre3HM2ZAfNnbmdodcw993tpm8fNz8aTXDFrEHTE6J+w8wZRleTi9yMxbplHlNS69/zPxPh3imlwMwZQAWP+fn8RY0wuOg5N9Eibrxa9oFtvm5qvPRHft4OmT/dneLKKhR2COaA2oNSiw== 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 --- 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, /* * 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 = 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 Fri Feb 24 10:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151074 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 A0402C677F1 for ; Fri, 24 Feb 2023 10:00:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9DE56B0082; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB11B6B007B; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65BEB6B007D; Fri, 24 Feb 2023 05:00:45 -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 467556B007B for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 08D9FA17BB for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) X-FDA: 80501741250.22.2A6CEB2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf29.hostedemail.com (Postfix) with ESMTP id 2EC13120011 for ; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=fYzhrj11; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=pRm1v3KH; spf=pass (imf29.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=1677232843; 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=NhRb7OEjq72gATHH+81L0Pb56Fl0vIOvf0iCMN4nYIU=; b=fy6p5tGXzjOapwg/g5X0foXhK7wB+l0wFH9NZXAf+yhNUWhNqnhfm0CdHy1/hkj8NFat5S ztJkMIJDfrXDXTbFQJhkgbiv88C/bwhI5lqlxka5S/IJ8LIk6ozHyocS3PIBdXGBa//esJ TcysXMTs1h1ky3MsWQ5y/Ln4nbEjvuo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=fYzhrj11; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=pRm1v3KH; spf=pass (imf29.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=1677232843; a=rsa-sha256; cv=none; b=JSMuuJbSSiGstfB1eNtb/l52mqSeibM+oSnH1o8xa18a2s7OfgVbNnhpQm1b3lgSCXboVU nmcwjP5uZZw1r4VN0otiv2UGXTSdPXRSIrtopc42tV2GFj6ddo9RrIMlMaBjzY0b0Ab1/T VsWETQbT6rioWjZBjySGUt31FwX473c= 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 X-Rspamd-Queue-Id: 2EC13120011 X-Stat-Signature: hycdo8tu81mf5ooxrcm4zcpeiky1nt7y X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677232842-711237 X-HE-Meta: U2FsdGVkX1/u9l91V4lRsIJQv4XAOABnKE3NdYulTJ+Ye/29aGUQS6Jqu5CmOyPjFRWtniiGuJW6P4H12r5eJkDG3yEfCVspp3LSQUyYKBhXk3arJR1qS80/vN9t4IBdHBIUVJ7UOtkwbhj4JLyztWT9tdGqJVy45GieXSeyYBcfaliDJu1DRSI9DkLLWDVW1mxX3w1LxWX1gw/SyRU0R2n8so/V/jnWI/8sVHCU2dwc8HvWMJnSCB52qdX+71v9UVUbdVLQNNUGWu2knlST78NBKqDs2pwHc+HjwDkwkuhZN5az+PrdnAoXLC07Q2h/zYkFc6UrVYGSRFUnmOmuGZrOr7T5zutjj8DKqlYy0Fyvg4eG9vJWp8oVCFuogAHp/frBcuvYGjgt65YWPJ5D4ai7ruK1q0jGUsvgwCOvBpsiHw0zV70uYrizLeLg2gcIl1mWc9VcuVc8Op/JVT5s5blO0q/5pftlF35kXq1AIeHMc+/Vk8d7hRfZw/aZqGRmQL4a4MjP8WWr1a6UNO+L6BjzASTO2jo9+8uLaAtyZoX7B8ZSoG/GxW30RdFCBTjIIBJ2dcqwLzlNKuuiFHWP/f5t2y6tMJOPepOu4p3nTJ6/6irA3sKfU1GkmrGgKy3cMo5UAt8nf4+rmoSrLPvXxmZhqtXPlS/TJBr9hzMJgTdZ5TBhHn31fIqgz6SF1qeCS031HhOugAfohS/RRux24fOferGIeiGvhgQEIig1RP7qQWbUP2+meNlCBAgXI0Yn01at1k4vyHG6cXjpDwmG+yV9QjnbA9z2wyqOS+Tzcfx3KHaXQxVsoC1smuiFQzHpitpDE/ERFDXPNSXqGVvv0JH9hIzZ5/ccK3F0Tn4SCoDgUz158mKK7zkhfhp1pZurYZPdQFHh4W5AP5EkOUZ0a5NtMmFAvI4Ck67O4vmvzIeQD0oflmx7hAC1BYKq0d6wzvq84hJ33MCvC9o9Ez/ URDXfllx Eszk6N6Zq4w2lThZqH5DH0o4Ffa0ZdnT4Gaxc0SD1qXOX6kYjilX/MEYPunqsZK10e48kRPBOIuPIpWfNVlH/XxZyRoIYy3bv3x9INyWw3N6UOoS5HmQv0NvK+iQFv6GfWoik0pLkvDlgh3dEYVTNZ3lwnFLse2SPE8FOOear5xq1xN8YzvvdLL2JfMiDDaWuY4naXQMHeianYCYno719+TkrsGOCBJGaj1FTipH7Ml5byUuDs75Typ+rSA== 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 --- 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, 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 Fri Feb 24 10:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151076 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 5143AC677F1 for ; Fri, 24 Feb 2023 10:00:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DFEF6B007D; Fri, 24 Feb 2023 05:00:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41A116B0087; Fri, 24 Feb 2023 05:00:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF0B86B0085; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9E1736B007B for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 26141A17C0 for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) X-FDA: 80501741250.23.CA2CC74 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf16.hostedemail.com (Postfix) with ESMTP id 2CB9018000B for ; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=FkZbX3oM; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=D1veafK8; dmarc=none; spf=pass (imf16.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=1677232843; 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=O5q8VKPwKROzkXifx9I8bCKvnOQ0g3mM/tusCr5mero=; b=d6gQb1M19mWPTwd6NrfKcJhQ6z4wNxt2IvvW4CetDpE54TtR0GJW3yp4T2l01tlCcx4Hr9 4tPsdDuS6TqKJy1JX1Gv5Q1MeNaLGELUc2o1EoGzGxq1b4+ro8JUChbpRnM8DJWAwZd4Bu efAqJHOkCYTqWBgfRaDA3IYUCwu6M1w= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=FkZbX3oM; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=D1veafK8; dmarc=none; spf=pass (imf16.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=1677232843; a=rsa-sha256; cv=none; b=Xjx2M766VaTQjGuwsiY6VR6fpvlUCDxiyqffAU1ktWpldjyOcQ66PZassG+0hyNLebqKiA qeyUKlu31wJcGsIAf23AyulxKLZKy1I3l0A3Oh3Umu2D1qe+44/O8TndPP9q6L1rjZZadN Oa2DHf017rKA0yFHvFowI+QvtV2FSXE= 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 X-Rspamd-Queue-Id: 2CB9018000B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: adzbndcxfioa51pwzjek3m1qzgjqs4wp X-HE-Tag: 1677232842-650981 X-HE-Meta: U2FsdGVkX196JnVcbMCx2WseR4thbu+GCao9BcGfJZiB1VGc0SelbBN3+rk6EyfelmMFDCnc3gvx0K6dm+sNLpIfmw5EoKDmq2Z5jPEuw4w3cH+A23jlULomoU84gmaWPe5p3bjNmCr+yt1cqDfS+YgDENsb0YLqf+CN45Wc012ngZ/FwCKTm3ERkqR5lYB/OWtJDg2tY2ynMHvRxyUixKdsNxOt6B0rvN1M/id+ObT5fTamQM5+GKtUY4zWsoFI4EobCmNg6ChJljZkoxY8XiDh2kbdkLvkn7vPQK75ZIVn4dJNRGSFCRixp1Ib2RdkUI+bdUhGWAkzmESIGA0Wl1RjRV+BSvRV1mrrgNReRHO1U5d2E91j2ZZw6gdWAE7bFP59R318P8ndrfK80dcbAN0yrnaNKrbSL2wnBVWpttX+Y8lKrAczANUTPdHOhqtF+Cc4VcJYuLYXThNB3oL7hr+9E1pWup6viEKcmAfEENGkcJfP0pBjX30pj9k2JUtT4/c/EJ6StT6DfXxcxTXvxg9hxDgbYiOudonjI/DT+FPwG+GH4UkMRSggBLhCY4ji5FFQ9Y/FIh8Xwyp6MuKSdc0Pj0MsaUl+b0zkmqt48sNgxbHJlvOWhtxYC6Vl2U92cfSqKv9xytfz/sHU6S/RrJN8fKA+Yz2ALJkvYcBhFGZopS3y6X0QIYizigsEjE/phaftK31QYatcJXUqvYpQtORX90BaPPcJe2jCS0qXN7e5HrJ3rHeojxzaNXj7oNhdrsX0eSAISJGlyq4JsXacGX71/ezD/LeJi3KAB7vJmD5TBuqC8Zuxir2YxGA3ZomI4HAbLNQEWvdcWFLbfhOBygTKVthB0b5csY2NvuXG/IZWQ9PBhpml1rNMKOCDkr+MkWcjtxRxuaXY7VFmpdvcZO/JD25/PdOiDgKWsj82LAuOLUTebfuSw4JID4Y8RnZkwpnj82XlzFfZuPem6q8 w9WH2Kxv fA8TezVkdv68Ej38x0pSLMysb8co9pZd2HOjmZRlDNj39tFn8adUf0Q2DgYiJhgC8riGMzAAphjm+g04PQX1A+PezP7hGIIhGv0Rmml3NDnyS+dChHKZAveDx2n+ZQFFhHuubM72pbF+4hO2kTBxNHCpOhn3DZW63ACCaEvBh8FohG1psyY/4B2hVIrnbeyxOx+t2GW2hiEeLqloTvvIEO3KZWzVftetw22aW0AEbTGU3Cd9VRWGtWudFeg== 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 --- 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; - 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 Fri Feb 24 10:00:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151078 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 1AA61C64ED8 for ; Fri, 24 Feb 2023 10:01:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DE906B0081; Fri, 24 Feb 2023 05:00:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 80A4E6B0085; Fri, 24 Feb 2023 05:00:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 216D86B0073; Fri, 24 Feb 2023 05:00:45 -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 CE93E6B0083 for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9E9ADAC253 for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) X-FDA: 80501741250.17.F27F137 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf09.hostedemail.com (Postfix) with ESMTP id 5928614000E for ; Fri, 24 Feb 2023 10:00:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=GUdLjF+L; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=FPIaDwkS; dmarc=none; spf=pass (imf09.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=1677232843; 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=X/29+kAqWfgwFrv7r8G7PU+eQXJAc+t/i9BDpOhdUqo=; b=nRkz+dw18qoPsP5feEnKU0GhKqNg99ez/vQ8nRPeGDWBsP0aWcWJ9uZDOkR8AzD0V0kEp9 vUg6C67EPOlmHnSzF7q6QdrFKk+sCzSlha1ebD9FOJ3FZGrsM9C4lS0l3UAILBaA0H7uIC anTVyxbIWyQmza0c7h6t78vq68WLYU0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=GUdLjF+L; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=FPIaDwkS; dmarc=none; spf=pass (imf09.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=1677232843; a=rsa-sha256; cv=none; b=B4adFJuE0wAQ/ahiQj5VwoQyAAP7PHC4+EDWOaPiEcKe74qMd3hdLrQx0I7svtGxeSPrw3 s9+cLGLz4WdVzEO0RJm4FjA20kdS1wN6NSaW9iERv9AJSApBDCki0iEu4N+9gWAW1nybsF bj8AcLxoOOhYKN9Oed0Mz5e+05jDjvs= 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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5928614000E X-Stat-Signature: qf3k1dje4gdfohs6rm6wwydsq9yqdsxr X-HE-Tag: 1677232843-825511 X-HE-Meta: U2FsdGVkX19At8Fn62ChzRblVq1GzalGk/2C3BsPHvfP5z9PzjEw6tbb3EduRk7VPptpRXpKBtvra/mc3ryPZCjaegDW3DzFs/19pCr/SIKlH79fL+ZiVJDd6/GYfV62sxGsreaToYyxUxQKlTGHerjeOtLQih5cx7I4/fWv4PfMqRLPHppo10QshiLmzu62okALLoiL//6QXGz+nxrueUKPH/3aXvEftJQfcqn8OP41pcgMSrb5RKZAWhf8S3ZapvJk/NbS/oGfG/G7rRA+zMAOmkThJe0+wEW15hRZRTHUOCwVSEaJJ7jAKAMGd9pw57sqLS0Vs78eyfB4hMH4Sb5ijQJLUtpFOTx8m0CE6/etWrd59sB/B2J5VU6UGD56H1b5K3wiElFiNLqDEmC2I1IoLoy9J91pqmVDgkpieJTqZaYMxgEKiwh0ApCkhnq0xK86WGKrt/BJekDDSdHSA38guoYvkfQxaufpxZwSVHqUUNYZYs67it81QLrX3Qc0+gnNPU/VN6xEpIpp/yAg6A5eQOJJCMVRy2Pp6LTJlA5cpylm1RrgXjlrwvhj+sJtudaw5jJBdOeI+Vdneq8F1gqEaGTD5RtY3+7uV18M/4I2FVz4ZYCtyHSlm/0idkbrCJVKU38aOqJJ/kAACkF/XMcErrDCIbXbAE0XzfXkzCxvxqMstix0P7c443yPa1Yo+d88IKC8M06EIPrUkiI3MrqfCq+7YF7AMr/n/qQ3wex3YOP8dC8ur18eZC5roD1/Q04afgJtYpXV0ZMIWjGN0I1i6SVbqqiwjlEuotjPHkRa520H/KibIOT8qbIYTcIt0TsgzcR0Cw4DnXUp/MvBKRH4Hgxrggk6dwPYy8pySw8WDLS4B6DE2JlLxSRqI/uYFy5jI/an8st1Yku/drkgQBI1vC3vijr9J5SRYIFqYnusFWVWbeOYUigVUH2lR4QkpAWkVzH/EgRRaaXzJRj b2ov4UN/ yEcJieC23hIIIw4L3Yc5y1fddv3jp6MYyTOdUnSpelZsuVjZsznou/ZHIjmOT7I9PsifMCmDXyMpe5IbygXF+fcG3z8A429AH5xOeDzee66CwZjxYtX0aJqpvJcq27SRAcs2ioZz2Me+qSyXpodOQ/t3WrNUGyXFQtFQsdb6WB4DbgdMbgw2IVgw9oAUGNrUjAI6HcE/R8jLmRlxZVQwqZgihlshak2gQnhv0VV6cYCLe6DH+irW8Wcr2cw== 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 --- 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, 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 Fri Feb 24 10:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151077 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 C61DDC61DA3 for ; Fri, 24 Feb 2023 10:00:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 747F36B007E; Fri, 24 Feb 2023 05:00:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68C8B6B0083; Fri, 24 Feb 2023 05:00:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9C8A6B0080; Fri, 24 Feb 2023 05:00:45 -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 B09A66B0073 for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 84EA41417FC for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) X-FDA: 80501741250.18.B47263A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf04.hostedemail.com (Postfix) with ESMTP id 6103E4000A for ; Fri, 24 Feb 2023 10:00:43 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=voy2FpNW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=wTXXBZ45; spf=pass (imf04.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=1677232843; 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=mjxA/DFoKz/EDUMQDrlO5jdAE8nM57iTZhngVmIGq8k=; b=UdW+AmzxAj0riNlE5GUeBe/wFowUMMzKjRF43BOAlr6/QcZxKfotZQ13AG+QrgfpYIVGzu c6zDqa7fMTYd+m8Vdcz71EqsBJZ34t6qlsM2P/vc0KxoFRNoxuFw4b8pP6/4N0JXfCzQO1 0cUtMnaTE2rYa8KethSdTgaJnk4Ua1s= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=voy2FpNW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=wTXXBZ45; spf=pass (imf04.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=1677232843; a=rsa-sha256; cv=none; b=xr/G8q7bAocjj1fSR5yzBBqKsio82VC6TKdHYcx/1e0WuY1VXQgZrbbd/qLSKQEqgSRMwT BKVl94R1PjvvzkbTJIAhuxkL5TtYZMkPqbxnJmufqZnr9TL+Z6TvE7vOS9fpZt9W/SH5FQ 0cNc5JfZe/8XvORl0KM5+YNmdkCM3nw= 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 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6103E4000A X-Rspam-User: X-Stat-Signature: 43oko3t4bx9k97t1thqkb14zeuijbact X-HE-Tag: 1677232843-293534 X-HE-Meta: U2FsdGVkX1/krnYf8oa0CGkQpbN+DxvAqwurUd3fLX30bOPdmlqiso7ecP2Lty4Rswo2/AJX7o7GzdcB8TUV30B39rcQMAwYzWdVvsI1/M3YAu/rzBVfEbNZGNnSAii3+EjvoiUM+fTyAlOmO0kUVjLa1BdI2nRCEo76BCLl6Uq3+8dCpC/vGbWTBDIuKZNzWd+EfKRvx9S5x2OM2vLBXlZCSQA5c8FNEG0kYfXDx/6I3jpzjkRu6aWQyygaN/ZmaO+4mJ1yK/zBFjQwXp2rDhfM/4t6df1KgEJ1uoqnEZail05cMWTuGgwYsvvxMyJkilsEvtlNPujfR78rwUD8PfQwez5OV7n6o5yjymlaceKRVYbVwVHwW4RASZE1JEmlAMuprW26SlwD78i6G1q97rOTkYMRaN5ZceOxc5AgRnc7jbbjiss5cL9mnKT3iqOYg0RX/B2lA2Z6WFsW9NQRU7yc686VWa9DRp7iZSH5mIPwzm9pbV/fOjlmXccgP76IE54p3f9As+NUjUgEk/Uo21lxqE7AJPkB5LKQ2XQMxtDcSA5yYRVZwrIC6c7Sgj+CApu6w/ch+HOs7qNbQgjBSMKGGPrU34Ijrpc1h0VVITB8DVzzSC8eP/UF086dsNFB25hJYBfGXR1Q+7Fx1MfskajmcXRFk8mvc6n3GyQWDOT9eJxlH82f+FNYVuYNcglHgIl6H4/lfZnkJlOOTE6j2SDuQ9mPS9lp0ot336g+wFSrtwByFWXNvBg8UAlYT9q3dtzB6z8L30ngGsKAExfdBTNVmkduCOxpBWbq7+PTD3Uj8kfMrU1917MHdJyCHXVFx2pl+spLDkgK9JXdKJG3AwW0dHRvYR5NDo9lZLBNtUfLrbhesEmhTq01iMTV9vTBoVuGxFQ5VtTSqgScpNuPx9OZzP/1tuGAr+VtUT3BTdBNF9Z9UnTIdSbvai0ljmp//Z8oG6sDNf4rO+IOt0J 8VMsV3Qo hr2Ln2VkRWayuBDT2MQccYPOeudyHLuJtHEA43hLWctRN/hwbaX8y+6oz6wTLfjn5q0cC28fEen4a3RPeylV82QOeiCxQ1OcEGWoC8c20SEkywUJ9+gh/Y6nnobtGRULbcbSiM4wGjAlxhJzhWN41B7wRkM1SLwkASmT1KM0AOEXyeFzW5LxcbGsiKnGhZ3giz41mOy6um1Zn7Y/2vZM3Wi2YOTaSOR0NlhUW/rR6o2CsaLSdfljJnnCSTQ== 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 --- 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 *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 Fri Feb 24 10:00:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151080 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 4B641C6FA99 for ; Fri, 24 Feb 2023 10:01:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DC2C6B0080; Fri, 24 Feb 2023 05:00:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2647D6B0083; Fri, 24 Feb 2023 05:00:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 090276B0085; Fri, 24 Feb 2023 05:00:48 -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 E9DAD6B0080 for ; Fri, 24 Feb 2023 05:00:47 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BC66114180D for ; Fri, 24 Feb 2023 10:00:47 +0000 (UTC) X-FDA: 80501741334.06.A139379 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf24.hostedemail.com (Postfix) with ESMTP id A3BE618000C for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=KWXyMuNX; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=f0IpufU3; spf=pass (imf24.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=1677232846; 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=U0wR3jwDHdRrK2cxRZw/xy12wIZu3wsnwhuoBXj0MMQ=; b=7fQOpVsCwVBGVVAVvwCEmSHxPgiuUGz9r8OqD+k0U6Nb+Pl94THUTRSDKbN2rw/yxtYL6F uQpGMNshQ1OJpeNvrR52pymhTKXM6ADl74ODyOR7nFl7I3X4EBSNdVaa6DooGMvosb03oD uhSeS4KrZBX/6i65ze44E5Lhpr9WV/A= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=KWXyMuNX; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=f0IpufU3; spf=pass (imf24.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=1677232846; a=rsa-sha256; cv=none; b=KPEPDWQapQDZnTvHBvePxEzf9V3/zL8/5HhZsykBcKGvtQwUTDDMSSdr9IsvksY+mi1NNZ 3lk+eJD4p0ggzSaVuGt2U/QSoT1Nau4ia3mzhcaXGLGByUpVZlLiYIsvH1EPKwECNa4L6C +pAoGy7HQmUhM+cjNbsabOM4OZYUEqo= 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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A3BE618000C X-Stat-Signature: xzgqxjjdurex1qb5o4m19yr7r4quc66z X-Rspam-User: X-HE-Tag: 1677232845-936062 X-HE-Meta: U2FsdGVkX1/E1P5CvWN7/IT+sRxvlXrb4OHjSYnDSIc+HQsoLMO6caAhzkLxrKtIjqHO1xkb5jLNao4Kb6Te2ebC5YS4SjbVyr6KbWs4qj+cmeOE7GWCSQMfbmhBwiVPqQqR6EHE8Sz1rvGTGurohsI4/RMbtsvGjtoqUhbuo16l/3Xwsgs7choOlMEa8h29uLNOgTcYCzfvrmYfffB0LTtlyLWhe4Ed48vfa+MxhHGZiaB+vNBuXbiZzuIf1uT/EpE34kRBq4J5HDzWuuvdR1yS1DY1glQ0ij8pnXH7Dan0ne7g0GAvFIsg7jK3oujfc9hoAf2fl+ch3NQoE2PjedMSKon4i06xjUEOvvoxwydJ5lTf2fIUG3Avnupf4kpobOrVvgxKo3kcILwJYVgF+rwcQmBglNGRpxSQVCxk4IgdMeN06lb7x1SOArH/DEYZr1nYWnnb0HyOUx3qOyM5CmsHTsjUZszzrNTrnPvB9SFvFtif0lRIIBErCnJJF/EkhQJpWM6d5VcxCcQJjh8XTIMtgwsjl7OSvR9lEmGUVc7n6JTV1PBZ/3DtDJtkdb1ecVBdXSfBT425H4gy9tgAE3bpbp3msg5ZT8l52+6VhXjQEBx0EKgGuVwdcBDrQ+7RvBtnawAhaN2JbnuugtPnt+Qe427BsomO9N+KDV81Lwd8hY0+VJML0ATUyoM8XHn/VSPoUFdghe9r6JOjax0xxbwh89q2hiUINmYKr2qgHGyeDspp4EA7FOYXxy8YjvpuVzWArqE6sQHn/4SXEjH3YsD3N0beBz8zyAPVYZurf8bijzsZRJ5ElfQBskESRD2Pr+NW7LCEGjL+20m+5ca3Eh2Ekj1CWYBlxXlawRxFTiY7+kAuIIB6sa81Yn157WAdf2EMRinWmUVh7stX33STaTupk7I1ZlugZPwOCpwEa9kw9MJL7kxjLv9QyIvtw4yOD5p/m4oZzMN+fi+Xjdf aX4qCYOH /zWRMKzcxbaryc1PSbIjvhTHxBhO92GflYINGO+QmT7SHIpTvsKxiDzUdCKmEPUKoSLblT4JrbwHK5Sn8G5gPdMiI1/G7clbSDK2j1Ny436lokgJp2EQV1vfTNFoQjgKPLTnTQ0YzWUYQcKtkZNEOfsmlcyKeJj61CxulvCcwPenCEbBkBBfGUMp7G8LlG7kGrf7DO8YCHrTem0R3HnpsQaNMXNxIGP1fXP+Ln3M0mdJJCDRJUXE3LpixqQ== 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 --- 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_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,21 @@ 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 +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 == anon_vma2; } @@ -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, unsigned 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 == vm_pgoff) - return 1; + return true; } - return 0; + return false; } /* @@ -817,7 +817,7 @@ 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, @@ -829,9 +829,9 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, 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 Fri Feb 24 10:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151081 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 E7E12C64ED8 for ; Fri, 24 Feb 2023 10:01:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 748496B0083; Fri, 24 Feb 2023 05:00:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F97C6B0085; Fri, 24 Feb 2023 05:00:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AD066B0088; Fri, 24 Feb 2023 05:00:48 -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 2F6E76B0085 for ; Fri, 24 Feb 2023 05:00:48 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E944CA1756 for ; Fri, 24 Feb 2023 10:00:47 +0000 (UTC) X-FDA: 80501741334.30.CE93433 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf26.hostedemail.com (Postfix) with ESMTP id EE86514002F for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=zXBjdlaH; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="ve/+OwGM"; spf=pass (imf26.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=1677232846; 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=T637DVEgnPwS8p7L5KrNfCTDsHvOXi2P3RnjOxBPfWY=; b=GYYlLe2XS+OhKIvGSO7oUYPFuZyiznKYjfo40/CaRJOhHL0XKqH0FS/I7SUdycTsVJhq26 1pmKrRF3t5DhMyA7S1HSIAcxJit9bzfmFRo4skBlQC8XLoOs+z///QAN5jLh6DroORu1U9 cATO6a0GC0wWSfU5yrSytegRm7dHTCc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=zXBjdlaH; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="ve/+OwGM"; spf=pass (imf26.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=1677232846; a=rsa-sha256; cv=none; b=QEc6oMw2La2DtUI1dgt+Ohy4vUo3pS9VvrGjs9xNk+Bn00bmPs9Bu/NzHKkproklcRCCq1 MZtPMuH8wocdro3BoCUUOLISAqinZt9MdkuUYyMNm2kQOsNuxqsj09Ktk6hK3KkJxhPEK7 pIk5dd+cjzpjyla4AGooCb4K59X+2Ys= 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 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: crym9y5h8ud5zqdqfnapfrumxx61gp45 X-Rspamd-Queue-Id: EE86514002F X-HE-Tag: 1677232845-340262 X-HE-Meta: U2FsdGVkX19Qzr5lRk75r6O3J//RWktFpgpI6xM/D0kBzphTUjFiad6wJOytXYTEjki+e1iP4cvKRDIUIa7cYTdJrqx/NIx7caOckAdY9G97Qk1sP2VzpRDioP4Ls7GwCK9yw2tauZFVPwxg5lnQW2xdnJvcfA8ytteO2seaP6ilmsTgRjpxfrSBMEBMQn99tjiNw/nSMOG1OSjBcSjCA19Q9VUi+3d1git5WWBcpeaUUD6UZo6LewIR8c4bXgFzd9/KrLvbMTppuflaA9KHSaQ5Tdksmhy2tuAefbJEejnQqfcgELHjUv6e1S9eCDnspDeVaVr0kAmDJIPZvZ9yJ+jn3wLpxgqXIUCZYSwUVCbHtg+k33BGHkKZOSwrcxIF4YRSpE59e3l8lpZ8e/lVDHZRHE94QagHLYQPLzvtFfwrvl0UhA0RjgBinYjtlKrEN72YJhT0RpQpKCN2dbjVLzgqa32dNGMp0OVO7ZjkqpT/9OJuv0oIuEsTe/kZETh2Fer3mbrwiNGxV/yJBSVqT9MtN88GQ0BAk9fzJZr7OOjXrzeHDwxp+d9rMzkhos6sADNen8BwePh5B+x1lq6yT15bJNZmGl1jAy4UafFn6bH/5CYE6HJoEL8dtY7ERgdeZnFulJrE2i1ze5YU1+God5WloZeZx5icGnmOO4yuypJrk4rlxQLW0YyVdIzZr44PCTORg2SHTcxHg6+rgiPz4hcEaj7J9f0TxjTefrpL2+mtNBe3aHnIJpHfYPbaFA7QBQYmLLm5y6SwwtlYhfSuh9AduYKJJfAFNVoTDZdxc9YNAJBxlooAgDmppgF+kn8uHhIlnMP8oIbFwHf814trw+g18ZIvlp1sanBe66ggBovb81cUUbMWAqJ1Madtgk2OoX36HmQZSrabj6E22bdUkbKB+ZuQgzsQNg9V2Q6h8VryODrTWv2ZBXnSHsbypKl/0JebS+UHgmacec8dn3d btuCjWHp 6BBIm9453fu2zILKOVFV7DlBTkHRm5q9f8WkYXeg/dMg6y1owwoqIjF1vNMn9s6wbtOBv5FcOmmyGTAKnvid7/HiZ7TbICT6mCpPvjmn/npURcwMhgjiSpQlcG0uMvsMYQNTV3utTyi081XXRuwb+ryUajUE6fs9ZzRegNIQAZiyAV5FeSpgXAlWaynNXCoOJx83RXEVtFUJqYr0= 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 --- 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_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 +763,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; @@ -794,6 +796,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, @@ -802,7 +806,7 @@ can_vma_merge_before(struct vm_area_struct *vma, unsigned 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 == vm_pgoff) return true; @@ -816,6 +820,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, @@ -824,7 +830,7 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned 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 = vma_pages(vma); From patchwork Fri Feb 24 10:00:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151079 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 971DCC61DA3 for ; Fri, 24 Feb 2023 10:01:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD7236B0073; Fri, 24 Feb 2023 05:00:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 98DAF6B0080; Fri, 24 Feb 2023 05:00:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 460436B0081; Fri, 24 Feb 2023 05:00:46 -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 E686E6B007E for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AC250AC258 for ; Fri, 24 Feb 2023 10:00:45 +0000 (UTC) X-FDA: 80501741250.11.48E3005 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf06.hostedemail.com (Postfix) with ESMTP id C682D180014 for ; Fri, 24 Feb 2023 10:00:43 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=p3ZE5uLw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="exyNXp/O"; spf=pass (imf06.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=1677232844; a=rsa-sha256; cv=none; b=fQQ1qGMmzHVFWdLO7/R60kPo98hX78uAkuM8yO6hZ9jhG+hunl5XA6hDqRcmDCpXyuC26s SxNd1Go6/RvWU0HTLeRVd+/uFYNFZKfDrgpAcWqvCMFy7l8W9mu3xkWjLeKa/9Whlvx8xb rn0ofjJG7XHcLmiLAqG0C7OrSRMvKvA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=p3ZE5uLw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="exyNXp/O"; spf=pass (imf06.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=1677232844; 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=git4jgtojWFCr3LkFcNcJKqanXKk9lAMGlvEDNt0WgQ28d57Q53+I7wzq3Kh83HsoFBUf9 L8eaE1QXwKzCjEcwWBAiRhXnx7L1IxtJQrvZo3iLM8ivD2enzdvsFX8m4LmEYBgytLKweS +bqs7htiibJFbOFreTPINq5iXawNdUk= 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 X-Rspam-User: X-Rspamd-Queue-Id: C682D180014 X-Rspamd-Server: rspam01 X-Stat-Signature: s5wrdag8q7gj958bbc5d6fq1xf1p4ng6 X-HE-Tag: 1677232843-55485 X-HE-Meta: U2FsdGVkX19LKTRoRAgZ5VIeU/p7qv6Z7pmWxK3DGMnLaRkKQrnfunzIQ5PbMOeaaLptSA1a3k2UyyHXkWRQwEjb2HrR+6QIpaVixi0xm2SSF7EegcbaH9apScf18Zow4b53AcdpWwe9HWLGL8OZNnPKObD6Kgugit5AS/uX7GIg0U5gbO/yLLBbLCYC2qg9JqcCkNmiH8TemdKQ/tsW/xVkIjnViC+ScWDDr5JXkejmK9fZwKjliZ30HcL3uf5GrCTbQ2by6KUNjbXG0vnDNwHGGRgCYG9o/GbkAw9Jiyje/aKyDq3Ugw3XpbtUOj8GYxAhZ0B6Dx6FvvVPt70cfwS0Zw1xPMj7m/PFdFTR+le5YOWy9A9024+dnFMeW5uUYuadL8ItPkIgW/Kptxomq3GKEpIvsTGQP79u+x8ZE3/l/CbiLL9EMnkeAUKVlIQCuvJkynHKX4BJOHOkKKHmW+k9e4h5nlUGCSWepo4pjx+6tEcsx3cdymZDN/22O9cdrYpb4dZregUhpe898zGyICYYesxhKiNuMgqzJM752Z37rSzX6lvRt40tUPY3oONyOgBKNKsNwqNT13VovdZBQRIuUa7wxd7YnTdD57sQEsyhXICzUq6edGjg4p4S/NfCvTQDCH7fx1fc7sjIthpWpSzBFkeuRXw7D/7Y/Vue/IYhhdX15CVF4A42FZEl3WCEVJ5dynq6nbUbQfwKgV4M/kgEPk3hsLaDeoLxz58Hil9cqQN5jZ0jYoyQhTPoiAh0CdszVrPFxOPi7+15Tq3gW7qjkvEvCVBcGGYpEs4dH3STVogRkooPaX/7IybXvEMNMO3wLH22MM/wOrnqQVe4hnlzPVsQ4WUx0aRLhbvSoP3G6gmkEjO6SeIKRVqHnrDP205v0JxQguKE2RMd8p1J5ii0d5GSq5L1xBU6ZGzmt0FVSg7Fm7PbN0auKO+/AIN2vEgT0hwxpDmKwJPxTyg lVqaDzL6 dweLE1Gs/U3AekWFXrbW+cOrJzzUpro9pavOnHVmjWO705Wv9q/6e2Y0UKbKPsCZdPabPyOmWgstFqiMm3dHJcWTIVZyGw2AZB1o2dgLDzMEoAnTJT2TM8IbRiKWcrBb2M/n11tm6LR0VbuLnpW4LMyfyj9XKSGykWcy2cZtf/kQR/0peQwMtZeIIlxrsn9SqF2O4Yrd5cHyiufY= 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 --- 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;