From patchwork Mon Jan 9 20:53:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13094286 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 01978C54EBD for ; Mon, 9 Jan 2023 20:54:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D4398E0006; Mon, 9 Jan 2023 15:54:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85E938E0001; Mon, 9 Jan 2023 15:54:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D7928E0006; Mon, 9 Jan 2023 15:54:34 -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 5FA8E8E0001 for ; Mon, 9 Jan 2023 15:54:34 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 40DA3AB041 for ; Mon, 9 Jan 2023 20:54:34 +0000 (UTC) X-FDA: 80336464068.29.7602738 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf08.hostedemail.com (Postfix) with ESMTP id A37E4160015 for ; Mon, 9 Jan 2023 20:54:32 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=m9qNPQfv; spf=pass (imf08.hostedemail.com: domain of 3B3-8YwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3B3-8YwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@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=1673297672; 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=FDedOk4BDhI0jXVeiXMnt29MYEOAHvgEHolCeEtDVh8=; b=3lh1CWmHkR3shamHlUsvKB6jbMX4E2snQv9E3leLsH+weQEQFmhWhO+BN9YLX/mbKRdEkR RaYMZWkXS16/fmx9uWBaHW1u5KH7xF3FJ+hbTEw6fbq31Fzpi5pviVuA9GksHVcyfYk2NC k1W7L33LtT6fNrtvsV2vOPfJsEGv82Y= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=m9qNPQfv; spf=pass (imf08.hostedemail.com: domain of 3B3-8YwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3B3-8YwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673297672; a=rsa-sha256; cv=none; b=Z3BOCkog/y7BUXlKbhum52M94xe0sZTt0z9hrl9eMHEPTRjWISouNkWpJ3NCjO1vn/X2vP L1QSy9IrlyYHGRW5pmNvN4Eff40SOeu5ZdMlzUlsRuQgRhCftcS7QH+eBAWQArO1hewf6E dxWDL2kx0uXDow3IPP52pz9RyOuG43g= Received: by mail-yb1-f201.google.com with SMTP id i17-20020a25bc11000000b007b59a5b74aaso10157464ybh.7 for ; Mon, 09 Jan 2023 12:54:32 -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=FDedOk4BDhI0jXVeiXMnt29MYEOAHvgEHolCeEtDVh8=; b=m9qNPQfvAaSk/cZYvrILeQolkFuo8oX0rPOdz+ZeBZe0viaaMWSs2xM9wojEerSzR9 Ehc0liLdN4Rf9t9ITHbgyUo/TpjLKodzNOt3cYyWGhisrg0tQj8O7DOpS0TtK3tPQLQG qUB/3EWr0qIxJ9v9dQ2Qpf6kyj6P77wOGaZ+XxUB3NlRJ4nvQo0f4D36W3MPMO4ktFMc ysLVV5w6Mp+QnxSVtHOQDDwbxZ7kpIUBpnDdTFd6J6q0MuwMTyvve19XzRy6+EFEsY7p 5CEU/qiYVWTESVV3KMWaGXvUZnEBFFh/Tdv+49ubumcalCQjcVJZu4o8Eo8hhtY4lcfd RRGQ== 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=FDedOk4BDhI0jXVeiXMnt29MYEOAHvgEHolCeEtDVh8=; b=buFbuiDlpuxfJHauCOGuUMRNyMiczx9BAN9MkOYq7Du4qPY/MoK7k4SMdBuwaDmE66 8hxeNkW5RFnUZl7y73320rYxNHOgekXD55ZW0osixvHqSx/lGipMHt4CACHYZes278TB e7R/5lLUYp+jv5Jt3/5x09GegJEJIZnjveUPhqNb/fgTLAyhH7aSNBaCrVyDIF8g90XM v5YNRvEvtwXOp/anoX4d6LrNz4NpA2C4S1qXbuMYr3hqYCdcBV/AOrD2I4w5CS4IoHhs VdumsxTvhYEF3iz1DYcf8RgnBp/G8FtZ5HX5my2aY9z/76uA6q4yQ4rgtbdTEkZAxwc7 z65Q== X-Gm-Message-State: AFqh2kqyj8Fdu4uz8VHcq1+eMz0ioS44bK2lR15Lkck/G3EtoH+Heh5x uAo18iEiwM352PKsba6Hfdq+JK8OctY= X-Google-Smtp-Source: AMrXdXvGyOxiOv+MuSWvovzrd0so3mEpN1Edvcx+Z2HBXoeLvz+P6Hw4SXaxw2akuo9mk6+zHwkliVPrxQU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:9393:6f7a:d410:55ca]) (user=surenb job=sendgmr) by 2002:a25:1489:0:b0:6fb:ef1e:bb1a with SMTP id 131-20020a251489000000b006fbef1ebb1amr6925224ybu.168.1673297671808; Mon, 09 Jan 2023 12:54:31 -0800 (PST) Date: Mon, 9 Jan 2023 12:53:15 -0800 In-Reply-To: <20230109205336.3665937-1-surenb@google.com> Mime-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109205336.3665937-21-surenb@google.com> Subject: [PATCH 20/41] mm/mmap: write-lock VMAs in vma_adjust 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, laurent.dufour@fr.ibm.com, paulmck@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, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.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, surenb@google.com X-Rspamd-Queue-Id: A37E4160015 X-Stat-Signature: mghsnz1y3bon1efrufa167o1cx6iaebs X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1673297672-252037 X-HE-Meta: U2FsdGVkX19lHs8pqK17VfJVplkow/RvROGUFBEQhXZsURklACpNdalscCt9B7U6PUKmumoxVGugVxcGwMbUW46kWlrWwJcE4zCM10Gx2qkFQFf7rabyG6oBr38VWWQaUH09Og9Ng3/iwWMTL1TY7vQSwrR6POkQmj1mRrMUJT//kMf/ukrx+jlv2Ndk0JFXyje5Y2K/1s2xjcTdwA5oHibOekShcHeFv3qyQV9ExrSILK9inyouyfyjUjzcjHEg9j+PO7pWGzrsrFxQpZyCrXso3+uqMld8TyjO9eoRSpgSpD7VTgyVZIKsIjklc/iI0amDPdGfUxYKzdijfk0HmLhQEedCGxD91700OHY/NyjkBkwyKWxVDc/N6hoq18hoDUuaPvYx8Lmt10ygvqWydQcUhx80b/Yh5Wko7WMzozUL/9ZJhekEaoJgPF9nYNm9qocKNLlC2pUkJ22klj+aEyYjI6/FkwWQEGTkX1eMnBUfHUJA/bv9GjpMiEMuAUzVsADufr4SOIuXwZ4scXQPIw3q4DRYqT2M0voubaeQ2ZlfCAqo9C7TouVX1564Kwk4+QPxHQbP2F6UfkVatH7j1VMihoLcHzlFuVICHewNTU+wthkgDVLZsz24EXL1PqfiQeW2k1PcOZITmUorTr8lqKn09odQv09jeDuGCG++1DxDuwmeX7U6hS6n1PNliu28T6FiVwRxCyluH4OJljZKJmdjmie/i4QpGWfJ3dajA8V4HcgGigA72CP0CvsQbIKbZtE2m0CYfmhBxE8vkB+BlPvTw9kgrPpL9bkPait3NP6R8yLSMbw3/0fN2M20OTKlgjbzw6UMMr6QyQ3PDBUeSTlOxECyYRbpRb3zBJ6wCz4+/klztwJ4Wq3n+CoIQh1kO90hVNv0sDwiPh+St9/L1iDLKDU2TE50BzOI+mySDf87fTAlVTQmJ9jko6GeY18yWp3elbXKNKqI0uXEydm PWchRw4T jRemkRJlDjSVb1K6VwGsNhDAhBj19S6MCoV0RGoP5hHM37pID0Uw+ucFiQwEPFu7AfiRNVSrBAVYjBZP6wZtf9hKWCLF/yo2EusR4x+Via3nQ6Q6SztjY+1H7N8HoJ+vFF7ztw4QbjbWrmwKa7Wk5H6H0lGYgQHFS0Pt7u6Uo29BpiHH7TaXeBfH7x8conQHB7brmfFvhP+czJcg1rETgAGfAmAVALz6vXTBzuY/w+ent+0wwP++An010gSmxvl+gYqHK4Q295SEQ5ujCUhKvlzRVpM9MnEwUl1Qs8xlaEDcCd72htdCkp1GrhUHDLdxlRyh49sU0mQvlP5KaAqhvxEmn9o+Hg82t3A/BIoySDzTd+dyZzidIe1sjDgL+jM8pzpRkAk/FKnoUUfAZkfrJGOUXkOxRN3arhMTD X-Bogosity: Ham, tests=bogofilter, spamicity=0.000037, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: vma_adjust modifies a VMA and possibly its neighbors. Write-lock them before making the modifications. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index f6ca4a87f9e2..1e2154137631 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -614,6 +614,12 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma, * The following helper function should be used when such adjustments * are necessary. The "insert" vma (if any) is to be inserted * before we drop the necessary locks. + * 'expand' vma is always locked before it's passed to __vma_adjust() + * from vma_merge() because vma should not change from the moment + * can_vma_merge_{before|after} decision is made. + * 'insert' vma is used only by __split_vma() and it's always a brand + * new vma which is not yet added into mm's vma tree, therefore no need + * to lock it. */ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, unsigned long end, pgoff_t pgoff, struct vm_area_struct *insert, @@ -633,6 +639,10 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, MA_STATE(mas, &mm->mm_mt, 0, 0); struct vm_area_struct *exporter = NULL, *importer = NULL; + vma_write_lock(vma); + if (next) + vma_write_lock(next); + if (next && !insert) { if (end >= next->vm_end) { /* @@ -676,8 +686,11 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, * If next doesn't have anon_vma, import from vma after * next, if the vma overlaps with it. */ - if (remove_next == 2 && !next->anon_vma) + if (remove_next == 2 && !next->anon_vma) { exporter = next_next; + if (exporter) + vma_write_lock(exporter); + } } else if (end > next->vm_start) { /* @@ -850,6 +863,8 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, if (remove_next == 2) { remove_next = 1; next = next_next; + if (next) + vma_write_lock(next); goto again; } }