From patchwork Wed Jul 12 04:34:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13309561 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 2E126EB64D9 for ; Wed, 12 Jul 2023 04:34:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDADB6B0072; Wed, 12 Jul 2023 00:34:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B641A6B0075; Wed, 12 Jul 2023 00:34:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DE206B0078; Wed, 12 Jul 2023 00:34:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8EF436B0072 for ; Wed, 12 Jul 2023 00:34:33 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6D3C81C86C6 for ; Wed, 12 Jul 2023 04:34:33 +0000 (UTC) X-FDA: 81001693626.20.614FE49 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 9B562180005 for ; Wed, 12 Jul 2023 04:34:31 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=wnCVuIXu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of hughd@google.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689136471; 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=7tbEFbFk5pzLjwVra+37SCseEW8dJexk2Np2YDtZH+c=; b=ntOaKZe1jOHE2IizZ6HHSBoGeQR+baq6mTkw/NIRlo0ir+Gulm8WkkjOJSVn+CnVdbCzv/ ZB9RvBaBGtw9PGzdshpc0lkbx/ljslWVwv9buoqAFLwAY523qRY6G6SuY/MCes6cwxpKOP 7503PaLqLDISS2viHKTI+3dkDzbxyHA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=wnCVuIXu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of hughd@google.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689136471; a=rsa-sha256; cv=none; b=N9B775tiWA10zC/pRuivQScO/q9P+LHFNJ/gxIIAZpVGVTntkTLejlrPhlqdrxNhGzoDKZ izyB2GaCjFFvQFfPjRjK78jA3vOSnTvJHaYeIraIirMm2fgfFhoBJ3vlOWvLrTZJQIi6O+ 4h6uQe7ZG5jdVbEDN71XcgthbsQ6Wso= Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-5774335bb2aso71113717b3.0 for ; Tue, 11 Jul 2023 21:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689136470; x=1691728470; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=7tbEFbFk5pzLjwVra+37SCseEW8dJexk2Np2YDtZH+c=; b=wnCVuIXuiaG32yazd1jaE3W5ihs2aq10U+0VnqC0A4M5VW9f75uDvYaKtJTiOmyaue Sk3Hz9lSjZsRg5VYNIu7Hn2yE63ieOx4N3x7YzoU3Buew+NClS1OfLuPLWy/xU1Be4F4 Mj93usiX7kHcOZV19+ldiZyyL/p+CNJFiKm0gEtrogp1KtBAN0j2Dy4CImKpM6En2tcK aezkkRAxSKmsFJ7X4v2alSgKHi31+oMGpb01SlGprmt8mWgh7ncZkS4hJxBgagnaXOse tz8TLiOWqvvCKNWEav/8zM1LSgHqAZXlnZ87YVamvaqNDIExsUdGGqSiLd9h9BTV1Nu3 hsEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689136470; x=1691728470; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7tbEFbFk5pzLjwVra+37SCseEW8dJexk2Np2YDtZH+c=; b=En/iGyLQ+Asfml1vBWsAj9s1EknS9ZpXAD3r/DCnFR2CTOzAsH+yP7CWQ4TswwrAuU kYrNCS4I9li7CLc2HSmVRJMEtdth715dVLXLMtrKcGyqDTeUjSVkuWnLw69AMcoIvOBw gCJac4qtYfu+I+6jyFniPDoRfZCXR3nA3s7l8J295KFBEYNf13SlnV4HPyWJHRNXpGMo ovPVlTQxgacrOYSWEwibwE8+ieAqZweccSO4SVi4rhXCCTAaonGOVIa/9YOTYqwHC8hn meecksR6SpRE+uhpQ62W1q1gHspynu5yrVpiV7Es9Uk8+m5A6irV7N7thpqRLRCB8Vt7 KsRQ== X-Gm-Message-State: ABy/qLYRW/QMrXdSXpemAwiqArgFW2rlFZwMYJauhcQuMCwcT0YYmFUa qs7BtuDgOZ8wvyOtt7ct6gbJqg== X-Google-Smtp-Source: APBJJlGbNO1AMOmdt4OPi/Xng0KoIYGmRlccUjicbL3FXzg2JdRnfsqSYXaILeBHKbZKCy/ktJ28ZQ== X-Received: by 2002:a81:4ecb:0:b0:57d:24e9:e7f3 with SMTP id c194-20020a814ecb000000b0057d24e9e7f3mr2850117ywb.38.1689136470494; Tue, 11 Jul 2023 21:34:30 -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 c124-20020a0dc182000000b0057a05834754sm974979ywd.75.2023.07.11.21.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 21:34:30 -0700 (PDT) Date: Tue, 11 Jul 2023 21:34:25 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Russell King , "David S. Miller" , Michael Ellerman , "Aneesh Kumar K.V" , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda , Alexander Gordeev , Gerald Schaefer , Vasily Gorbik , Jann Horn , Vishal Moola , Vlastimil Babka , Zi Yan , linux-arm-kernel@lists.infradead.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 04/13] powerpc: assert_pte_locked() use pte_offset_map_nolock() In-Reply-To: <7cd843a9-aa80-14f-5eb2-33427363c20@google.com> Message-ID: References: <7cd843a9-aa80-14f-5eb2-33427363c20@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9B562180005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 57eb59h6j3uqdx3x1n141qrsb46esnk5 X-HE-Tag: 1689136471-884393 X-HE-Meta: U2F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pGOiSWect0iVEIcjAoX/pLHvzw+yCtp8Crn7zktdDOVcfC4XwkV+QHrvx8S2Kk6IFwsqLIvfLGdPKDwlVXwDXDm532oMLC+by7E2k2FH+n9lK/jCDy+XJjMhAYuoPZlutDAuew1g/a7H+Wc5dM5B89/xWU1ZI86rW4wymWaG37IOrz4vR6AtCho31b4sVBSrd8OFYgkH/kfbZtYT+cJ24WtA5ovCIdceXPTfgGI1IjqEZ+fUrlryPeK8hNQU2+/wChn5+yX3LGFrelUwWW9GU+7dG6hhnZN22aL+4pY+4FJSa16fFXw40RtAFYvjQhXUalO4tCpBEVCu+2Kk3rLrdgAUrZfwkhOYFbn1S4UWcsTBd7prpP3A/T48HibHBNXNNAx4LNMIZz1tXNsnNAKnSwsrjN 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: Instead of pte_lockptr(), use the recently added pte_offset_map_nolock() in assert_pte_locked(). BUG if pte_offset_map_nolock() fails: this is stricter than the previous implementation, which skipped when pmd_none() (with a comment on khugepaged collapse transitions): but wouldn't we want to know, if an assert_pte_locked() caller can be racing such transitions? This mod might cause new crashes: which either expose my ignorance, or indicate issues to be fixed, or limit the usage of assert_pte_locked(). Signed-off-by: Hugh Dickins --- arch/powerpc/mm/pgtable.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index cb2dcdb18f8e..16b061af86d7 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -311,6 +311,8 @@ void assert_pte_locked(struct mm_struct *mm, unsigned long addr) p4d_t *p4d; pud_t *pud; pmd_t *pmd; + pte_t *pte; + spinlock_t *ptl; if (mm == &init_mm) return; @@ -321,16 +323,10 @@ void assert_pte_locked(struct mm_struct *mm, unsigned long addr) pud = pud_offset(p4d, addr); BUG_ON(pud_none(*pud)); pmd = pmd_offset(pud, addr); - /* - * khugepaged to collapse normal pages to hugepage, first set - * pmd to none to force page fault/gup to take mmap_lock. After - * pmd is set to none, we do a pte_clear which does this assertion - * so if we find pmd none, return. - */ - if (pmd_none(*pmd)) - return; - BUG_ON(!pmd_present(*pmd)); - assert_spin_locked(pte_lockptr(mm, pmd)); + pte = pte_offset_map_nolock(mm, pmd, addr, &ptl); + BUG_ON(!pte); + assert_spin_locked(ptl); + pte_unmap(pte); } #endif /* CONFIG_DEBUG_VM */