From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76D64C4332F for ; Thu, 17 Nov 2022 07:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KAaH7ypolYCzt+8O4CVkIC93xCKTDaKYcWnbWHssVxU=; b=kCG0TXxxCmdm4O UcDg16W1aKJQq4AJv+Q9GjIo14RHppG4DeG9dhvbvCJwD/6q73xKHCDACnl5yA4dhq4knzx59g1rx v2/v8CVjGdzOdrfzjiSPZomiPVMLNWHgVXdlklLqFmBr99MCl2zMipKOLHQLfGKOMAZsTY/PC9gi9 gDM4kEAYL1uBOuqJWKePf/zuMMuJfbEYOOg8uxhVW51IYabsoKapcqgmPjbjmPrkHZH+AvHove1ew KynYIn89HKMbZa1yxnr9vD/MoEpHE0K357u+6h/lFJ20aylLbkUuS5ZpZTyRILHmGl3OgjWKxhtDH +ZFpOwN4wHEb558Wm47Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovZeh-00BLUl-4Z; Thu, 17 Nov 2022 07:49:51 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovZee-00BLTR-0M for linux-arm-kernel@lists.infradead.org; Thu, 17 Nov 2022 07:49:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668671386; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y2N7xLwoVXU6ukMGzXJcgviVQf/Bp/XT+1487tW1sk4=; b=UdJfFywJi+w3UbIlTIonGWbc4CzkUvtahF5JBkb5wBo2Inp+3qUzi8uOmlGluZlg0up/wi gLdbHylCJ4ppCwbN5ula4a5bGgKaHHf04UUXvjhFWi97N7OM6+yqCiySnhQVTJN+eYV+GC DeyZnBllCU1jSLg/b+XyifL7rXTZWsI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-578-2KLJkqAzMzS48wuCeKytjw-1; Thu, 17 Nov 2022 02:49:42 -0500 X-MC-Unique: 2KLJkqAzMzS48wuCeKytjw-1 Received: by mail-wr1-f72.google.com with SMTP id w11-20020adfbacb000000b002418a90da01so350067wrg.16 for ; Wed, 16 Nov 2022 23:49:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=y2N7xLwoVXU6ukMGzXJcgviVQf/Bp/XT+1487tW1sk4=; b=m+tdKW3DCDV8ss1Yr+ZmcezI6Cj9X96QVlnj0AYBC+edjoQpbB1XTxpUcNdS3nwzB1 eohnTsF3dzyTMyfVXXsKYx+lzTC393aujoIwWPRg3NDu7jRGHJvk1wRNhyr6gpge45kC Vsas6Zk0hBlpixds37bNXz8ek1NnRBvDlomo+HbYmTJ1annn+d833EH52lxDxHXzatKX 0mOhCz0ZTL/+t4mk5QOBT3GHtWhjuIu0dNf0avKGMojnObcbHRdkGubaR1itpWvOGRsZ 3gJjKJkWTrt4EJUfFL6LUaA+F2tHUG5AKi3Pc64M2+fV7hIQ2elBP1wT38TEf0q6ok+X dVOw== X-Gm-Message-State: ANoB5pkvX6PkIWqL8fgqGqwaHROKGsjkpskVgvuaLEf7wK8YPrYMqame VlLd7e50L94xsCqXecgwi/wiQ7Ey/OBvXqLbzWbEsqqbEyfhu3zOC+hTI1778rV790xDHYgS6H8 4Ph7vAc9VVKriYHByY63G+VAmMqwbk9VBnAw= X-Received: by 2002:a05:600c:3516:b0:3cf:a8a5:63ab with SMTP id h22-20020a05600c351600b003cfa8a563abmr768813wmq.101.1668671381549; Wed, 16 Nov 2022 23:49:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf682MiO2XGLvTeH42jZuNuCPofp/JskA2KYwkzF3hTXpKObK4Za6QoJRdoJrJIofbFlbbMxYQ== X-Received: by 2002:a05:600c:3516:b0:3cf:a8a5:63ab with SMTP id h22-20020a05600c351600b003cfa8a563abmr768806wmq.101.1668671381262; Wed, 16 Nov 2022 23:49:41 -0800 (PST) Received: from ?IPV6:2003:cb:c707:5200:39a9:b834:27c1:4ede? (p200300cbc707520039a9b83427c14ede.dip0.t-ipconnect.de. [2003:cb:c707:5200:39a9:b834:27c1:4ede]) by smtp.gmail.com with ESMTPSA id t65-20020a1c4644000000b003cfa622a18asm4645357wma.3.2022.11.16.23.49.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Nov 2022 23:49:40 -0800 (PST) Message-ID: Date: Thu, 17 Nov 2022 08:49:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH v2 2/2] arm64/mm: fix incorrect file_map_count for invalid pmd/pud To: Liu Shixin , Catalin Marinas , Will Deacon , Denys Vlasenko , Kefeng Wang , Anshuman Khandual , 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-3-liushixin2@huawei.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20221117075602.2904324-3-liushixin2@huawei.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221116_234948_155915_00FB2AAC X-CRM114-Status: GOOD ( 20.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 17.11.22 08:56, Liu Shixin wrote: > The page table check trigger BUG_ON() unexpectedly when split hugepage: > > ------------[ cut here ]------------ > kernel BUG at mm/page_table_check.c:119! > Internal error: Oops - BUG: 00000000f2000800 [#1] SMP > Dumping ftrace buffer: > (ftrace buffer empty) > Modules linked in: > CPU: 7 PID: 210 Comm: transhuge-stres Not tainted 6.1.0-rc3+ #748 > Hardware name: linux,dummy-virt (DT) > pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) > pc : page_table_check_set.isra.0+0x398/0x468 > lr : page_table_check_set.isra.0+0x1c0/0x468 > [...] > Call trace: > page_table_check_set.isra.0+0x398/0x468 > __page_table_check_pte_set+0x160/0x1c0 > __split_huge_pmd_locked+0x900/0x1648 > __split_huge_pmd+0x28c/0x3b8 > unmap_page_range+0x428/0x858 > unmap_single_vma+0xf4/0x1c8 > zap_page_range+0x2b0/0x410 > madvise_vma_behavior+0xc44/0xe78 > do_madvise+0x280/0x698 > __arm64_sys_madvise+0x90/0xe8 > invoke_syscall.constprop.0+0xdc/0x1d8 > do_el0_svc+0xf4/0x3f8 > el0_svc+0x58/0x120 > el0t_64_sync_handler+0xb8/0xc0 > el0t_64_sync+0x19c/0x1a0 > [...] > > On arm64, pmd_leaf() will return true even if the pmd is invalid due to > pmd_present_invalid() check. So in pmdp_invalidate() the file_map_count > will not only decrease once but also increase once. Then in set_pte_at(), > the file_map_count increase again, and so trigger BUG_ON() unexpectedly. > > Fix this problem by adding pmd_valid() in pmd_user_accessible_page(). > Moreover, add pud_valid() 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 > Acked-by: Pasha Tatashin > --- > 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 edf6625ce965..3bc64199aa2e 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_leaf(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd)); > + return pmd_valid(pmd) && pmd_leaf(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd)); > } > > static inline bool pud_user_accessible_page(pud_t pud) > { > - return pud_leaf(pud) && pud_user(pud); > + return pud_valid(pud) && pud_leaf(pud) && pud_user(pud); > } > #endif > Acked-by: David Hildenbrand -- Thanks, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel