From patchwork Sat Jul 8 23:04:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13305715 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 A26D4EB64DA for ; Sat, 8 Jul 2023 23:04:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E67748D0002; Sat, 8 Jul 2023 19:04:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E17B86B0074; Sat, 8 Jul 2023 19:04:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDFA28D0002; Sat, 8 Jul 2023 19:04:13 -0400 (EDT) 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 BDCD66B0072 for ; Sat, 8 Jul 2023 19:04:13 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 68DAEA0257 for ; Sat, 8 Jul 2023 23:04:13 +0000 (UTC) X-FDA: 80989974786.17.D7A4C87 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by imf20.hostedemail.com (Postfix) with ESMTP id B6D841C0013 for ; Sat, 8 Jul 2023 23:04:11 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mgCi5qSa; spf=pass (imf20.hostedemail.com: domain of hughd@google.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688857451; a=rsa-sha256; cv=none; b=mMBcClnb/uBKceyjytpfdihB54q3mT7mMcDCuoTWeiJ4drb4ONPSYeFI2B1smXwZiS98W/ IN6d7hrCngo3EfvCCd9o0hGPm0bdr5S1d2z2LB0149ZSN/Z4cEj6qYivyfBkSf8iguM+m2 RzhhcE2IqolE/HFckWk5vZkWlS8NijY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mgCi5qSa; spf=pass (imf20.hostedemail.com: domain of hughd@google.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=hughd@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=1688857451; 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: references:dkim-signature; bh=O+qLESJCRFN7dcIsyw3NJtjwIsXtHYZLjT5v4tk5DvU=; b=Ob4RoPSLLVv4O+0pvJ/slTjt63y8iReZmif7wIXbsyyTkLjWKPW4KxJNJudS1oPux5STFN +FgPRWzH8jVovmUgLS9PQTPRSJAW5yL/hHHVK0Onqa6RCMm8cB/k6bB9PZcvP/B42F6ohW wGPovxoh3FTMEusAvYOnhbBcywZbUis= Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-579e5d54e68so39342947b3.1 for ; Sat, 08 Jul 2023 16:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688857451; x=1691449451; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=O+qLESJCRFN7dcIsyw3NJtjwIsXtHYZLjT5v4tk5DvU=; b=mgCi5qSaZ0QN848AO4FEdlrrUOrB86sH23LbXPcpsn4qyESlzAQawFfOF04UBU4Kgv 9/lqmDRKXg+cqWxZ2Jzz8dSkhhwyJvxS413AvX/bJBFnXjkhbSF26g90mSr+UkOXy8qt Lg0ffkvvfGuyQCAHGQNyalDtsOWJwlyjwicSAZnEWb8DRbiUVaPqcJE1hmf3pb5JbHCV F+aCGx7iX12vcDpSmC0d09+31EprSu+CfzDgy+pt2tM4zg6JDFCADKQwoJX7LmkAFVnW HfnY7DNlbwjqy3xmZ1ahFCq1H6iUoXJC9PL/ZtQyNPupEGpCxTeiUlFqcf0amr0w6t44 ARKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688857451; x=1691449451; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=O+qLESJCRFN7dcIsyw3NJtjwIsXtHYZLjT5v4tk5DvU=; b=OsATFHP6FxmXW3Za5tgLqNT8//VdOQl6r31p47uLbE9doQ3iGeNN3juzgf6CAOMEdd kcMja0JBmCy11X9uhRwOODnxKcbs6pGzAtzIOHqdOLfqMpqt8m1AUpywoDAHrzya7uPg taZ6S8t1ezJY1MmPZerRmdTY4hbF35a7TIzU/q8RdABha9CmcP0gKoB0kTDGBjgytbyr 9rGUCAMIUw32J9iKzxyILjAE5K1IBSaEwPqc7LrMYRoQWtsBsWVUnFk2oLpLp7RGzDwT mGnVKjzTwqNORJsKiiR4C8fImLG4BtbQdeUyNsXvJ7zDsWj4EnUzVmgJVEhr2+Rmmaei PGTQ== X-Gm-Message-State: ABy/qLYWOO+yebwM3C2tgBaeTplaFtsfOzsMEFbBQY+OoMTn3WLP+SBA h7vGUqHKWKESrmX5G/mmC5q0sw== X-Google-Smtp-Source: APBJJlHxsUrb2PsB8Vr/SdiFDl5l/hnimxuzYl85A5so5Ag/YE5k+SY0YoZnZodNyJi7fr5g0LxUxA== X-Received: by 2002:a81:4e87:0:b0:573:527b:747b with SMTP id c129-20020a814e87000000b00573527b747bmr8684830ywb.36.1688857450765; Sat, 08 Jul 2023 16:04:10 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d205-20020a8168d6000000b0056cd3e598d8sm2108255ywc.114.2023.07.08.16.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jul 2023 16:04:10 -0700 (PDT) Date: Sat, 8 Jul 2023 16:04:00 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Linus Torvalds cc: Suren Baghdasaryan , akpm@linux-foundation.org, regressions@leemhuis.info, bagasdotme@gmail.com, jacobly.alt@gmail.com, willy@infradead.org, liam.howlett@oracle.com, david@redhat.com, peterx@redhat.com, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, regressions@lists.linux.dev, stable@vger.kernel.org Subject: [PATCH] mm: lock newly mapped VMA with corrected ordering Message-ID: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B6D841C0013 X-Stat-Signature: uxs9hgtzn7pj6azth9x3dkdk8a3jiyec X-Rspam-User: X-HE-Tag: 1688857451-248591 X-HE-Meta: U2FsdGVkX1/EidB7MCaKJAInHVs+O6Wykp8H45LFleujYEbPNLbFIQjJViM7FVqVeERcb67OYlUFC/eueHtF4vBy9MnsIj5i7iTk36bhI7NYmuOHRSo6nG1s+fe7Yqtu2WcyjEv5iTYKlYxiwsc5zLuBdtkabTIMtn5tJLXqqyYEEh2sVnxpflg71l3YmSK0WmBDdrApf5Cj8uWBSd/mJs8YXaK43fMUKHNNHOUsP1VaV1X/2n14zJZJWPbhlcDjWOvtCWjBHWL146/dHPjcVYT4HtHkqb6jf6RqF42eMnGF4vn7tsBm3Cos2Tqzu0KjEjm4B349jLQOzxQ4t55qGUuvF35TJBM+JIoFbPVii1By9+rGmBJlDkI+T9IQzmMgpxpL6Jz0CTQ0gQ7y+62/SE8eLqWz1nSS5oOmojoKf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WBWyAtIfTDTOl83qLkPgdQ= 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: Lockdep is certainly right to complain about (&vma->vm_lock->lock){++++}-{3:3}, at: vma_start_write+0x2d/0x3f but task is already holding lock: (&mapping->i_mmap_rwsem){+.+.}-{3:3}, at: mmap_region+0x4dc/0x6db Invert those to the usual ordering. Fixes: 33313a747e81 ("mm: lock newly mapped VMA which can be modified after it becomes visible") Cc: stable@vger.kernel.org Signed-off-by: Hugh Dickins Tested-by: Suren Baghdasaryan --- mm/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 84c71431a527..3eda23c9ebe7 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2809,11 +2809,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (vma_iter_prealloc(&vmi)) goto close_and_free_vma; + /* Lock the VMA since it is modified after insertion into VMA tree */ + vma_start_write(vma); if (vma->vm_file) i_mmap_lock_write(vma->vm_file->f_mapping); - /* Lock the VMA since it is modified after insertion into VMA tree */ - vma_start_write(vma); vma_iter_store(&vmi, vma); mm->map_count++; if (vma->vm_file) {