Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1547237rwb; Wed, 16 Nov 2022 20:41:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6EnmdNfNnZ80bK1cZRWVG5K0IEIt/mboMC2tvkUR+uODE2Ewal7O1dhIe6yN054JDhRqCG X-Received: by 2002:a17:907:986b:b0:7ad:b7c2:a2f7 with SMTP id ko11-20020a170907986b00b007adb7c2a2f7mr768724ejc.227.1668660109414; Wed, 16 Nov 2022 20:41:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668660109; cv=none; d=google.com; s=arc-20160816; b=kxoZai5JmM51kdKWSp2wHfTAqc1VIsl/hQhPFi8kQiEYvp9yNiZ5raXsm0Ce5hpWp+ FWpBwgbITpe45sNqWcDQjDBf27OCEFxeJvixGZwZcbmEsqqKXcNPdRZ+ruVv/XwhFxQK /r036Ynj83flPiDSZF5BFRA/erRNpXubxUx4lenp9HEY9XbTScp6EpQFBw59Go32owIg TPlHwSYiXGBR9zcGP/4RVpNb6Euem3vYd4qZ40mn/UCazYRPfvdkFgkScq1gL7XXp3V5 rPoLqrCzkcGzPOBPXSa5/FyLVzwcdWCbE+wVyB7pd+SCpSTFwDAyY6jgVZVAQaFp8Hrs 69Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=986GehMLaS+1TGg/IJQdgj3D+GnJdY1zZc+eU8PQ/KY=; b=GWF9BE7szgXo9DXK83Lwx52iQgfYynKX16LrLKNpX++MrLokdR520WCnRx3EDfTJhS lScw53jY0ENKJSI0sa5mS9Sah2A+9Tp1YsNaCvAcQBMvrjZMeWNgYGO5aqC+hdND94U1 nyRB340pJSqqFne7Pi1a0N6GtulA+WkCJIW9kiIclMI/3yb8u4KuesUDznqNRde6AVbZ gpPlUO1qy5PoNBvrAEl2DqQ/3FXG2SeLW6zzFWqHjUQs/6riWP0PV2jr9biFI8iWm7uk Zw4/GIvrNMn8S012H8ysgDQxS7+7u44Lktlcppz/Ay+zlNztZXtxcVDYvbFa9kof2hJB d4kQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cz10-20020a0564021caa00b0046453c36c4csi12643edb.513.2022.11.16.20.41.27; Wed, 16 Nov 2022 20:41:49 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234189AbiKQEJ7 (ORCPT + 90 others); Wed, 16 Nov 2022 23:09:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbiKQEJ4 (ORCPT ); Wed, 16 Nov 2022 23:09:56 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4BDD43134C for ; Wed, 16 Nov 2022 20:09:55 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1A8F813D5; Wed, 16 Nov 2022 20:10:01 -0800 (PST) Received: from [10.162.40.18] (unknown [10.162.40.18]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A1F163F73B; Wed, 16 Nov 2022 20:09:51 -0800 (PST) Message-ID: Date: Thu, 17 Nov 2022 09:39:48 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH 1/2] arm64/mm: fix incorrect file_map_count for non-leaf pmd/pud Content-Language: en-US To: Liu Shixin , Catalin Marinas , Will Deacon , Denys Vlasenko , Kefeng Wang , David Hildenbrand , Rafael Aquini , Pasha Tatashin Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20221116083811.464678-1-liushixin2@huawei.com> <20221116083811.464678-2-liushixin2@huawei.com> From: Anshuman Khandual In-Reply-To: <20221116083811.464678-2-liushixin2@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 On 11/16/22 14:08, Liu Shixin wrote: > The page table check trigger BUG_ON() unexpectedly when collapse hugepage: > > ------------[ cut here ]------------ > kernel BUG at mm/page_table_check.c:82! > Internal error: Oops - BUG: 00000000f2000800 [#1] SMP > Dumping ftrace buffer: > (ftrace buffer empty) > Modules linked in: > CPU: 6 PID: 68 Comm: khugepaged Not tainted 6.1.0-rc3+ #750 > Hardware name: linux,dummy-virt (DT) > pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) > pc : page_table_check_clear.isra.0+0x258/0x3f0 > lr : page_table_check_clear.isra.0+0x240/0x3f0 > [...] > Call trace: > page_table_check_clear.isra.0+0x258/0x3f0 > __page_table_check_pmd_clear+0xbc/0x108 > pmdp_collapse_flush+0xb0/0x160 > collapse_huge_page+0xa08/0x1080 > hpage_collapse_scan_pmd+0xf30/0x1590 > khugepaged_scan_mm_slot.constprop.0+0x52c/0xac8 > khugepaged+0x338/0x518 > kthread+0x278/0x2f8 > ret_from_fork+0x10/0x20 > [...] > > Since pmd_user_accessible_page() doesn't check if a pmd is leaf, it > decrease file_map_count for a non-leaf pmd comes from collapse_huge_page(). > and so trigger BUG_ON() unexpectedly. Could you please provide the pmd_val() on the pmd entry, that triggers this BUG_ON() here ? Only additional thing pmd_leaf() ensures, is that the entry is not a table one. #define pmd_leaf(pmd) (pmd_present(pmd) && !pmd_table(pmd)) collapse_huge_page() pmd is non-leaf because it has table bit on ? > > Fix this problem by using pmd_leaf() insteal of pmd_present() in > pmd_user_accessible_page(). Moreover, use pud_leaf() for > pud_user_accessible_page() too. > > Fixes: 42b2547137f5 ("arm64/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK") > Reported-by: Denys Vlasenko > Signed-off-by: Liu Shixin > --- > arch/arm64/include/asm/pgtable.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > index 71a1af42f0e8..edf6625ce965 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -863,12 +863,12 @@ static inline bool pte_user_accessible_page(pte_t pte) > > static inline bool pmd_user_accessible_page(pmd_t pmd) > { > - return pmd_present(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd)); > + return pmd_leaf(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd)); > } > > static inline bool pud_user_accessible_page(pud_t pud) > { > - return pud_present(pud) && pud_user(pud); > + return pud_leaf(pud) && pud_user(pud); > } > #endif >