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: 117469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4167363vqx; Sat, 8 Jul 2023 16:18:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGzwd7duYZsxbFk6e18qoqy9HIACEC2qTn/SNycNxvrAU3RqZEUwCbXKooXvAchOW4nOyMa X-Received: by 2002:a05:6a00:845:b0:67a:8fc7:1b57 with SMTP id q5-20020a056a00084500b0067a8fc71b57mr9064276pfk.2.1688858293883; Sat, 08 Jul 2023 16:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688858293; cv=none; d=google.com; s=arc-20160816; b=AF/KeNS7CnnxxPxklc4b4RJlvOEVe8uFqh1jGEac6n3pUs+gW6vSDHmhGbio8Oi0O2 r+MckoSoHaLTAauh2J+wIwNejuXYILzx+X4k05bPGTLT2SYjBYZFSdVpkdap2V/rilbR IkbytCbFi4UNe74seVPvm8s36x5SJ/PqEpOyA8/n/07G1GfBpoqFYGhw8UMNpR89A5ph 87tgBkOnOuIi8GkT5vk9wEXvEZw34T1MWZYl/AqDm8J5Zlp7J4SCnf331Yml/yODQcWa Y60t1KCKlAg/8QkzQ8dqG4aP8kXvuKFOp9WR3ppRclmEmxI6Bd7nfQbrtENTq7N1TG5s ashw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=O+qLESJCRFN7dcIsyw3NJtjwIsXtHYZLjT5v4tk5DvU=; fh=X3kXMdyekVkftbN47tiSvyCjZXzz1keBW5mR3LMXhSg=; b=WUn5WhcmLHMIMHRF2TPf5VeNXbWXWX7XU5We1JT/tdEHbs58cTaHLYA49+bC+SbGeP 9HkENPrmMbVqulD8na+2Hg+up89kaI5633g2KcCxuXi4OYX4P4ic+sDXLKQ0NrQ/MmTP L7LEG0FEcDOkG0gGeNGXqqW79MOpSNmgcCebHfNMJt1JwTyqUNug3B4/sBGjtPHKTr4U xKZwZyL+XMzCy4QbSyQxbwk+0C3wbI9jHc35Ma/sR6NLp9U5uduaagKaPX0aoYmrQo7W HHrD1lG0JgXlIBoZbZhsRvVcWfAlEI1NN1W1pIiX0dATm1b02pPcqpU2fVenVFEZ+4MY uZAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=mgCi5qSa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k14-20020aa788ce000000b00668705a86ccsi6637106pff.319.2023.07.08.16.17.59; Sat, 08 Jul 2023 16:18:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=mgCi5qSa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229763AbjGHXER (ORCPT + 99 others); Sat, 8 Jul 2023 19:04:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbjGHXEP (ORCPT ); Sat, 8 Jul 2023 19:04:15 -0400 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B15FDE46 for ; Sat, 8 Jul 2023 16:04:11 -0700 (PDT) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-57026f4bccaso39292277b3.2 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=RJ/EjDGZdATk/QQnc7nEyXaSmISuE3DibPtPLpUFnn/+s6cyL4IGxSE4Z+FX5GEsGp NxZvw15JPClPnERkHvRLXHitYPKQ09GiRlT6kgwJeEspegh4z2wS5nDaAispalgH6L+e 045YTfHEaWHvvFliRmaqGlxfQa/Bia2HQ9IvBvmrC5zroig/KRGH7WZ4MarJcWut7nb5 YzGH6lisXNsULGulIY+HWJZJBZLEn0/KXSIBgbZkS/IfSzJMAbAGxtpghxc0kIEGpsJ0 g2BXUS7GVv1vUdsBi6W5WoExLKEBH9ud1eaPbSQmZt3we8vrSVVPyZJjC27BgrXGSIGg NhtA== X-Gm-Message-State: ABy/qLadXNFvArQDCOCdZeIM1u+qpDWPn+7rbesuTJu7HXeog63Zpc98 1mvUWM2MtmQQnU3wwzRymeobsQ== 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-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770896274324948209?= X-GMAIL-MSGID: =?utf-8?q?1770896274324948209?= 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) {