Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5246423rwb; Mon, 21 Nov 2022 19:25:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+7N6q+dMjU3ycAsdb9R38q6xz2uqWrreS4u/IqSWLBWN5YixCWttp8AWfNfD5mz7OvEfv X-Received: by 2002:a17:907:2b15:b0:78d:51c0:d4d1 with SMTP id gc21-20020a1709072b1500b0078d51c0d4d1mr17681191ejc.161.1669087535053; Mon, 21 Nov 2022 19:25:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669087535; cv=none; d=google.com; s=arc-20160816; b=0C9p3IXxrWLqIUUDOMHTYyszmzw76E2Kp1sdVE8fWjgDpcyT7JBY156fj2QMfdRoPc ztXbl+LESUpvB6q+0stDimT8ZPiemnQSYPCwfph4tUutAI+xZ3al5FtV45OMKfifMN2f 5NpNNFdg+IJhpbBvaeCYdXJW2Chv2NKmg8MmdeCuDJsIQiYwXjpRHtgBUNodp93NieKZ jrROUPXu7RjpMA/7U7NvRODBLew0cPuxWn0TZvR0rHGbFRBh9ZkkXbwkHwViqVJRInnE T7wTUoX78vu9de4audOuvvmx7c9vqcqxsWXrTx044PR7Ogt8NwnAhd18+JLV4mwGsl4Q ntPw== 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=RVJlsZrRNH08oXfpat0zJEXFSNWq69X6N9ywh0K9fXQ=; b=O/BhR3zaZap5X3hFUP8jcdpyBbMtTOrP73UfF21wFUhxH3PqlbcqmreSCmmyqEkEid zd/U3qQCOkqHeR8bkZlue84+x2kDxDV+5JV4YYePjseZdWQEO+PqVTjb8eE4c3HpGo3C fy/fFcP1SqubZK/4R3ihZXIWt91DF1ezaAJBr/Qz2ZBqeBXym4NV4SLtrjBYY9z9lXuw /qJcSJBT4pNn453yquEYKjZ037jBAgLtACGDYso4j9cJgFgrI+YiV54YDGEO/PXHQZPD Zr7oDINHdKoDD0xqrIBjDn0A9t6beWRN6tXN3pO+LULBCOQPdN+7aqRk0JHvp2cupvLx BwCg== 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 f7-20020a170906138700b0078e063fc78csi8951505ejc.576.2022.11.21.19.25.09; Mon, 21 Nov 2022 19:25:35 -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 S231325AbiKVDVo (ORCPT + 92 others); Mon, 21 Nov 2022 22:21:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbiKVDVm (ORCPT ); Mon, 21 Nov 2022 22:21:42 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AD78F23384 for ; Mon, 21 Nov 2022 19:21:41 -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 E2A561FB; Mon, 21 Nov 2022 19:21:47 -0800 (PST) Received: from [10.162.40.16] (unknown [10.162.40.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2939A3F587; Mon, 21 Nov 2022 19:21:37 -0800 (PST) Message-ID: <0a961c6f-31bf-8952-7520-debe81d70b59@arm.com> Date: Tue, 22 Nov 2022 08:51:35 +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 v2 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: <20221117075602.2904324-1-liushixin2@huawei.com> <20221117075602.2904324-2-liushixin2@huawei.com> From: Anshuman Khandual In-Reply-To: <20221117075602.2904324-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/17/22 13:26, 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. > > 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 > Reviewed-by: David Hildenbrand > Acked-by: Pasha Tatashin > --- Reviewed-by: Anshuman Khandual > 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 >