From patchwork Fri Mar 4 04:31:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12768444 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 326A5C433F5 for ; Fri, 4 Mar 2022 04:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4CAC8D0003; Thu, 3 Mar 2022 23:31:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BFB578D0001; Thu, 3 Mar 2022 23:31:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEAB18D0003; Thu, 3 Mar 2022 23:31:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id A1E4B8D0001 for ; Thu, 3 Mar 2022 23:31:35 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 654B44DAE for ; Fri, 4 Mar 2022 04:31:35 +0000 (UTC) X-FDA: 79205430150.16.4C1D6CE Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf28.hostedemail.com (Postfix) with ESMTP id EB9DFC0003 for ; Fri, 4 Mar 2022 04:31:34 +0000 (UTC) Received: by mail-qt1-f180.google.com with SMTP id e2so6473370qte.12 for ; Thu, 03 Mar 2022 20:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version; bh=aTbJtV8j5fplGh+y9hP64K8aiDbN2PZ+yad5jwKxTY8=; b=LbTdUllock64OE1OwMtnYr4r0KmMGLlymE7Lee64D5z+FkbK7nQj7/BhYDZNVg1M5K tLUHU8xB1wXdV2Gu4Winb3UnlhKZko26C4nxL4Ck6dleHa7C8p4Em7VP9H4d4aQIKqsX Je1Sk/eAq1OEKZ188GPC3M44Z/ozBUAgx/kasoe1RRt9xehf4Sc2Ezk7dCTm7gwdmjt9 5lVyHJtoBdxHdDfSeWcFuC0z4omqUaUV1saqJ9G4ptNeaHQzdqRIt88qcB9P8UkAwy7B SinFQ6F7fGs2YQfhs+tIjwY5eTGPH3ZPGWzb7QiavHaknUJqMf2dOB0lh+KS2Auu0CZQ AOsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=aTbJtV8j5fplGh+y9hP64K8aiDbN2PZ+yad5jwKxTY8=; b=CMi+tcknofq9AvD02yAY3ovWfo18mnu8vQqNeOh4/npuox5uyRvl7sKyL+OdSbHTkw bqaTxehsHAlTaXFQwoBcXqGRM11FF2D4JZdvibCVGw1Sh+oOm4kysk8tt89Qd2qmuwzH ACYuQG/TDESaeCNva6hlNbPzxFwDWJRPCw5kxEUnIVvJuD/UcBH8i3iFDr3c9evO+o18 JGvkp9Ps2BWJOu4cw/Q1aD0nOCi0dsqOYMmFaRT3I1W3nNMqf/74awsik2xJn8a1sryG MeBNAu/L/afpy0wEKhuXfGpG2P5nXq/fK1j5MhwPfMfgaaWa4ZXFByyDwEFE+5WKg5c5 qmIQ== X-Gm-Message-State: AOAM530hZ8+It4sdkYSEzhBq66aXZyjhrQJMiYEG8Ybbe9pOu5+b7kOY twK/V3zGicelmZueP393QNWr/A== X-Google-Smtp-Source: ABdhPJwifbzXSXQ/wLbXKhWHJKCumbHB5C1izqmvXzKPpCer3x9VCYc6tIjTcvMM6jMywJyktEHmrQ== X-Received: by 2002:ac8:5b04:0:b0:2dd:2600:2f1 with SMTP id m4-20020ac85b04000000b002dd260002f1mr29366129qtw.364.1646368294018; Thu, 03 Mar 2022 20:31:34 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d16-20020ac85ad0000000b002d71c463d9csm2694100qtd.24.2022.03.03.20.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 20:31:33 -0800 (PST) Date: Thu, 3 Mar 2022 20:31:31 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , Davidlohr Bueso , Sasha Levin , Mel Gorman , Mike Kravetz , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH mmotm] mm: unmap_mapping_range_tree() with i_mmap_rwsem shared Message-ID: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EB9DFC0003 X-Stat-Signature: 8383njh3pdhkycz5exkcr65ic9uwgyq6 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LbTdUllo; spf=pass (imf28.hostedemail.com: domain of hughd@google.com designates 209.85.160.180 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1646368294-628680 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: Revert 48ec833b7851 ("Revert "mm/memory.c: share the i_mmap_rwsem"") to reinstate c8475d144abb ("mm/memory.c: share the i_mmap_rwsem"): the unmap_mapping_range family of functions do the unmapping of user pages (ultimately via zap_page_range_single) without modifying the interval tree itself, and unmapping races are necessarily guarded by page table lock, thus the i_mmap_rwsem should be shared in unmap_mapping_pages() and unmap_mapping_folio(). Commit 48ec833b7851 was intended as a short-term measure, allowing the other shared lock changes into 3.19 final, before investigating three trinity crashes, one of which had been bisected to commit c8475d144ab: [1] https://lkml.org/lkml/2014/11/14/342 https://lore.kernel.org/lkml/5466142C.60100@oracle.com/ [2] https://lkml.org/lkml/2014/12/22/213 https://lore.kernel.org/lkml/549832E2.8060609@oracle.com/ [3] https://lkml.org/lkml/2014/12/9/741 https://lore.kernel.org/lkml/5487ACC5.1010002@oracle.com/ Two of those were Bad page states: free_pages_prepare() found PG_mlocked still set - almost certain to have been fixed by 4.4 commit b87537d9e2fe ("mm: rmap use pte lock not mmap_sem to set PageMlocked"). The NULL deref on rwsem in [2]: unclear, only happened once, not bisected to c8475d144ab. No change to the i_mmap_lock_write() around __unmap_hugepage_range_final() in unmap_single_vma(): IIRC that's a special usage, helping to serialize hugetlbfs page table sharing, not to be dabbled with lightly. No change to other uses of i_mmap_lock_write() by hugetlbfs. I am not aware of any significant gains from the concurrency allowed by this commit: it is submitted more to resolve an ancient misunderstanding. Signed-off-by: Hugh Dickins --- mm/memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/mm/memory.c +++ b/mm/memory.c @@ -3388,11 +3388,11 @@ void unmap_mapping_folio(struct folio *folio) details.even_cows = false; details.single_folio = folio; - i_mmap_lock_write(mapping); + i_mmap_lock_read(mapping); if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root))) unmap_mapping_range_tree(&mapping->i_mmap, first_index, last_index, &details); - i_mmap_unlock_write(mapping); + i_mmap_unlock_read(mapping); } /** @@ -3418,11 +3418,11 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, if (last_index < first_index) last_index = ULONG_MAX; - i_mmap_lock_write(mapping); + i_mmap_lock_read(mapping); if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root))) unmap_mapping_range_tree(&mapping->i_mmap, first_index, last_index, &details); - i_mmap_unlock_write(mapping); + i_mmap_unlock_read(mapping); } EXPORT_SYMBOL_GPL(unmap_mapping_pages);