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 1FE38C4345F for ; Mon, 15 Apr 2024 06:53:00 +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-Transfer-Encoding:Content-Type: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=cDIz362r3UWEWXSrCb8bNge2yN8JDj/2EZh9mQCceGk=; b=HRyle73/+mTxOx nTgV+rFuzSfnKxNMshNOc9OWTf7y5+2JZnSd7tc/M5Ekt9cQKE9b/FFhSILjMaxE21nCCTaZGlL1t SdbhdkHSux2z+RgjKPKlpcq0HI1bZYMbVfBBLUlBebaYRHCuvrSN0T6hKR2LmY6Q5EYfnl12hw3Gh noQUGjqIrp/LkIXRbe+uymmkiDZP63Yxl1+HejWDuTpldg4/767gng/T1AG1QBp5Li5StKk6aUXF8 Cp8Re1afyCviBqyUl/Ccb3zKdzZmxWB9ZBwK6OnsYH8dkWmfJTkYKK8iPBi9iBj38+soDsGc3v06M jp81RSCUvlyo3i9hc+iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwGCw-00000007Dyo-1FyR; Mon, 15 Apr 2024 06:52:50 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwGCt-00000007DyH-1tLF for linux-arm-kernel@lists.infradead.org; Mon, 15 Apr 2024 06:52:48 +0000 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 8F361339; Sun, 14 Apr 2024 23:53:14 -0700 (PDT) Received: from [10.162.41.8] (a077893.blr.arm.com [10.162.41.8]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8065B3F64C; Sun, 14 Apr 2024 23:52:43 -0700 (PDT) Message-ID: <5a6cdb94-3849-44bb-81d1-40c9c66852ed@arm.com> Date: Mon, 15 Apr 2024 12:22:40 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm64/hugetlb: Fix page table walk in huge_pte_alloc() Content-Language: en-US To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Ryan Roberts , Mark Rutland , linux-kernel@vger.kernel.org, Dev Jain References: <20240415063110.1795707-1-anshuman.khandual@arm.com> From: Anshuman Khandual In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_235247_692846_884242FC X-CRM114-Status: GOOD ( 16.50 ) 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 4/15/24 12:08, Ard Biesheuvel wrote: > Hello Anshuman, > > On Mon, 15 Apr 2024 at 08:31, Anshuman Khandual > wrote: >> >> Currently normal HugeTLB fault ends up crashing the kernel, as p4dp derived >> from p4d_offset() is an invalid address when PGTABLE_LEVEL = 5. A p4d level >> entry needs to be allocated when not available while walking the page table >> during HugeTLB faults. Let's call p4d_alloc() to allocate such entries when >> required instead of current p4d_offset(). >> >> Unable to handle kernel paging request at virtual address ffffffff80000000 >> Mem abort info: >> ESR = 0x0000000096000005 >> EC = 0x25: DABT (current EL), IL = 32 bits >> SET = 0, FnV = 0 >> EA = 0, S1PTW = 0 >> FSC = 0x05: level 1 translation fault >> Data abort info: >> ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000 >> CM = 0, WnR = 0, TnD = 0, TagAccess = 0 >> GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 >> swapper pgtable: 4k pages, 52-bit VAs, pgdp=0000000081da9000 >> [ffffffff80000000] pgd=1000000082cec003, p4d=0000000082c32003, pud=0000000000000000 >> Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP >> Modules linked in: >> CPU: 1 PID: 108 Comm: high_addr_hugep Not tainted 6.9.0-rc4 #48 >> Hardware name: Foundation-v8A (DT) >> pstate: 01402005 (nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) >> pc : huge_pte_alloc+0xd4/0x334 >> lr : hugetlb_fault+0x1b8/0xc68 >> sp : ffff8000833bbc20 >> x29: ffff8000833bbc20 x28: fff000080080cb58 x27: ffff800082a7cc58 >> x26: 0000000000000000 x25: fff0000800378e40 x24: fff00008008d6c60 >> x23: 00000000de9dbf07 x22: fff0000800378e40 x21: 0004000000000000 >> x20: 0004000000000000 x19: ffffffff80000000 x18: 1ffe00010011d7a1 >> x17: 0000000000000001 x16: ffffffffffffffff x15: 0000000000000001 >> x14: 0000000000000000 x13: ffff8000816120d0 x12: ffffffffffffffff >> x11: 0000000000000000 x10: fff00008008ebd0c x9 : 0004000000000000 >> x8 : 0000000000001255 x7 : fff00008003e2000 x6 : 00000000061d54b0 >> x5 : 0000000000001000 x4 : ffffffff80000000 x3 : 0000000000200000 >> x2 : 0000000000000004 x1 : 0000000080000000 x0 : 0000000000000000 >> Call trace: >> huge_pte_alloc+0xd4/0x334 >> hugetlb_fault+0x1b8/0xc68 >> handle_mm_fault+0x260/0x29c >> do_page_fault+0xfc/0x47c >> do_translation_fault+0x68/0x74 >> do_mem_abort+0x44/0x94 >> el0_da+0x2c/0x9c >> el0t_64_sync_handler+0x70/0xc4 >> el0t_64_sync+0x190/0x194 >> Code: aa000084 cb010084 b24c2c84 8b130c93 (f9400260) >> ---[ end trace 0000000000000000 ]--- >> >> Cc: Catalin Marinas >> Cc: Will Deacon >> Cc: Ard Biesheuvel >> Cc: Ryan Roberts >> Cc: Mark Rutland >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: linux-kernel@vger.kernel.org >> Fixes: a6bbf5d4d9d1 ("arm64: mm: Add definitions to support 5 levels of paging") >> Reported-by: Dev Jain >> Signed-off-by: Anshuman Khandual >> --- >> This patch applies on v6.9-rc4 >> >> arch/arm64/mm/hugetlbpage.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> > > Acked-by: Ard Biesheuvel > > Thanks for fixing this. One question below. > > >> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c >> index 0f0e10bb0a95..5c819459555a 100644 >> --- a/arch/arm64/mm/hugetlbpage.c >> +++ b/arch/arm64/mm/hugetlbpage.c >> @@ -276,7 +276,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, >> pte_t *ptep = NULL; >> >> pgdp = pgd_offset(mm, addr); >> - p4dp = p4d_offset(pgdp, addr); >> + p4dp = p4d_alloc(mm, pgdp, addr); > > Shouldn't we check p4dp for NULL here? Sure, makes sense. I will add a check for p4dp, just like pudp below. > >> pudp = pud_alloc(mm, p4dp, addr); >> if (!pudp) >> return NULL; >> -- >> 2.25.1 >> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel