From patchwork Mon Feb 27 17:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153977 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 0AD8AC7EE23 for ; Mon, 27 Feb 2023 17:37:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E7B36B0092; Mon, 27 Feb 2023 12:37:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 970366B0093; Mon, 27 Feb 2023 12:37:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 839136B0095; Mon, 27 Feb 2023 12:37:13 -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 73A296B0092 for ; Mon, 27 Feb 2023 12:37:13 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3D68E80A55 for ; Mon, 27 Feb 2023 17:37:13 +0000 (UTC) X-FDA: 80513777946.21.215B5B0 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf08.hostedemail.com (Postfix) with ESMTP id 5E57616001E for ; Mon, 27 Feb 2023 17:37:11 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qq9ST5KY; spf=pass (imf08.hostedemail.com: domain of 3Rur8YwYKCDUjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3Rur8YwYKCDUjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677519431; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QWCYeH3rb3vSAFp54Mmrv1+eix/+tyqClZQn+3lumNA=; b=eJl/Kf3d80MFfonKldym6G7f0K1tEn6qZyOVkc1HHwR/tnYfxMQJOx7eb87xsKPcPRwgwr nlJgpAEVtkGoHJ+x9MZk5DJFyOus0Ss36tdyhwYBfIL2HCgBkGk6OfMMCIlxHjpmW264iN gF2Sx9MdEpyIKAc+pkQsJtoa8eT2qcA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qq9ST5KY; spf=pass (imf08.hostedemail.com: domain of 3Rur8YwYKCDUjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3Rur8YwYKCDUjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519431; a=rsa-sha256; cv=none; b=w+jRE75eC6/TdhObovOBtHmft9TbwFRdRzLOncDr1qJKs+t6ynO0L6lXZL9HW3nCDIGjJZ yF4GasRPGYf6m8nsHIJmx9TYUlrR6NR5m1AWUreggUvyZpfzShTkxz+IFBuUIdFIsEVeDI 3vsSZ+QX+Snc1A5zBe6B5/Guuvz36x0= Received: by mail-pg1-f202.google.com with SMTP id e127-20020a636985000000b004bbc748ca63so2166410pgc.3 for ; Mon, 27 Feb 2023 09:37:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QWCYeH3rb3vSAFp54Mmrv1+eix/+tyqClZQn+3lumNA=; b=qq9ST5KYd7H0i08HiNSL8c29Xrjl3aIZNo0vqd33ohY7IlOekjqUFmHX1pCbc/0CIB UJYRScXv/uQI5WgiH6m5n3NDzNqXvXc+EBT3Nr8sb84051cUA5rcu7NsZAUPZLQbAT+k L1+D52rxNhib5vRaYFXHr0l0OBrPbhYiKHs0HG8E+v4FWKdNvWFhRWhiPM7+2blQtGKB AQqKpecJF/PSLRs/Iu3OWc/90nRfqSr4OY1HTu201oV1jp1/8gN3EH/qUSvYipkLdMaB KA1JreUYCECV/wYDbpy6/KFPjd6XlpEX5mJczzYRoBrzVCeQlTDt7q+I0gm0goYKe+3A HbFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QWCYeH3rb3vSAFp54Mmrv1+eix/+tyqClZQn+3lumNA=; b=oNGmomknAu071I29g4qitrfrfw1EpBZ7jMNsRLN6vkCLRvOaSa9osJiQO7O0ZBX3K4 J744vRcGWQhKEDEeoBWbYZELGgKFzIpmngYFCU3Zx4W6qhl315pN+7Zw4tc+vRkF0uN1 wBKNuQqsWrw096fevMb7X9UAw7AZh9tH604AZaXgs2OKl6xuWdUZF+pzsHzyUcRv2rpp VQphqTRhER9CusvHd9fBiuvuCXFwXjVSEaX8qPcTjyBniQQfswJvsRMmz4axg/ISIONO UUS+65E1VB7lreaysRTyvupR2xvwjmx8Hlj3lTV4/RWbPS7Uooy7ak0VMTGPdH82BaEt 1MPw== X-Gm-Message-State: AO0yUKXxOSHbID6nNwZL2gVgbfvMpzV9gLwVDBfSOovo9NEff2PGZKCz r5ibLBKT8uuFOx425leONYeP3dXrwt0= X-Google-Smtp-Source: AK7set8jO949nwq1qPTfiOwF5d/NxOGl9PwUBICmy0J7iLD+CPMrX0ZITRyhhJB1FHKtenUKzwzPrWF2iBQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a17:903:2682:b0:199:56f2:3fc4 with SMTP id jf2-20020a170903268200b0019956f23fc4mr6277864plb.8.1677519430200; Mon, 27 Feb 2023 09:37:10 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:13 -0800 In-Reply-To: <20230227173632.3292573-1-surenb@google.com> Mime-Version: 1.0 References: <20230227173632.3292573-1-surenb@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230227173632.3292573-15-surenb@google.com> Subject: [PATCH v4 14/33] mm/mmap: move vma_prepare before vma_adjust_trans_huge From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan X-Rspamd-Queue-Id: 5E57616001E X-Stat-Signature: j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bLjY27ZRho2A+4VcRNCCCi+2XKYtQ7Lpz1YMd8zK2DEKz910Vh0nAFJNVsvDD+s1b7pGvTgfBTs+EsC9abn9ZEXcZy0nS7DxsTCFjny3gW3GFLJTJ0qntiLqYZfKQjfYh9YxocgrR29UiJjpMmSSGpeoSASKtCx75VymQCzXUqBMzLx3tmkkKz2V5GPr2fWIboPbMX5U+mfQo3PJYGVqoELgBy/WX0vpB4yQkIPXcuVrMIQqANxj/IvssW7+Wx31CJ+yTOYoi3gWnPgQ4DAUtyeVzpUxGRi88v3myGElAAKV0+vr7uIa4dcvku8eeTsSNM3lvyoXFcUwajoruBOHqkg4dHxpx1mvfALXsAaZuO5kGq4Ov6UF0otUUaCnFVVvho9HWk1WJCjlJiueod9BG3fq3EjnM6AtVTjvUbiLcKA0/g+Puf1c0lLPFxffoQQTabBz8ArAAf7qYYJsysNoA2JnKqZHo7PgeFsA+67k20jsPF8Dud+TtlO/P2VGmRunCi+9RY6b5my2vfz++YJb0OCv5DIqMwoW+XTyl/ytQtjRpywZXn5StP2Q16YiJGQNGSRjVN+f+XHeifT24CpusGN/Z0/EgHyYmhef0248JA3Ig1RmK3pO0bhbffGZg7/1ZprbEypgdWbxDrFvnFCE2MuVR+JIks= 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: vma_prepare() acquires all locks required before VMA modifications. Move vma_prepare() before vma_adjust_trans_huge() so that VMA is locked before any modification. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index c234443ee24c..92893d86c0af 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -683,12 +683,12 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, if (vma_iter_prealloc(vmi)) goto nomem; + vma_prepare(&vp); vma_adjust_trans_huge(vma, start, end, 0); /* VMA iterator points to previous, so set to start if necessary */ if (vma_iter_addr(vmi) != start) vma_iter_set(vmi, start); - vma_prepare(&vp); vma->vm_start = start; vma->vm_end = end; vma->vm_pgoff = pgoff; @@ -723,8 +723,8 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, return -ENOMEM; init_vma_prep(&vp, vma); - vma_adjust_trans_huge(vma, start, end, 0); vma_prepare(&vp); + vma_adjust_trans_huge(vma, start, end, 0); if (vma->vm_start < start) vma_iter_clear(vmi, vma->vm_start, start); @@ -994,12 +994,12 @@ 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); 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); vma_prepare(&vp); + vma_adjust_trans_huge(vma, vma_start, vma_end, adj_next); if (vma_start < vma->vm_start || vma_end > vma->vm_end) vma_expanded = true; @@ -2198,10 +2198,10 @@ int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, if (new->vm_ops && new->vm_ops->open) new->vm_ops->open(new); - vma_adjust_trans_huge(vma, vma->vm_start, addr, 0); init_vma_prep(&vp, vma); vp.insert = new; vma_prepare(&vp); + vma_adjust_trans_huge(vma, vma->vm_start, addr, 0); if (new_below) { vma->vm_start = addr; @@ -2910,9 +2910,9 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, if (vma_iter_prealloc(vmi)) goto unacct_fail; - vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); init_vma_prep(&vp, vma); vma_prepare(&vp); + vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); vma->vm_end = addr + len; vm_flags_set(vma, VM_SOFTDIRTY); vma_iter_store(vmi, vma);