Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1251210lqp; Sun, 14 Apr 2024 23:39:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWchOipC8nfMvN9dNYH0H9FLjN1zeYh0lJg3FAjnJWx6yFD8qMCYs849g/44KYIXNTL1MteadbYvLR98WTgdxLBjCvXAa1+ypuNScLiCQ== X-Google-Smtp-Source: AGHT+IE5jQ0q8r7dCGNb6TP6HryDeUMAAPOjAyXHxKxYdFP5un4UbIlAgsd54Fg4f3rfJ/Ala1h1 X-Received: by 2002:a05:6870:6394:b0:233:ac4c:733e with SMTP id t20-20020a056870639400b00233ac4c733emr10517085oap.52.1713163199159; Sun, 14 Apr 2024 23:39:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713163199; cv=pass; d=google.com; s=arc-20160816; b=dem73iFXEulWKm71zvuVtEPAqdL/kcOSLiNMXodtIcMpP25w2Zndf/wuPc6cMHRFxV Ame+8sKA2AGl9RdQEhfHgZbVozjs/FGzyOnh0vNRkmzpPn52pjP4WseK1YUCc+45jKPL EGbjmRrtWjLPFSqd6iwHFqfQ8ye+sqCHcu+cTyFAKWe8hTwoq+8hblNVaTp86X5Cjmdy jj3+myrIb4w5T+I/yPQbJv5vOvDD7+c6f5KvZIG9ABqwY3Y1E0I2b+dSZsiWat2oOAy4 FbnkPG3npprwYmIkug/Nmciguf973npmv7VYJHmIYq5IhiOsbtslHBgFtMxIyGJnRLs5 onSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=2DhWQ9ya7/x3VVHECWToS+f1YLKdTn/fsoOlaYUXnhA=; fh=4ce6ABZJUwxEuFeSmYZjxbjHu15VtVdC6pZMXM3uKUY=; b=umGykVmFBdSkpe7lt2UE8TuPnfW/uqUzdgMJT0ZLr/FqCZJNh+f+g+Uncb1ATKapel 7jqxqZ8c64vw1I7HrH2RR/7JYDhnvOsyW/B8RZNhYw78IZDwNnqVG/5WwXU1Os6Avmov 28NvodIVRe8QXqizkS7RyaqObZz4SrjPc5fQJqi0N0t0WjPwWhkTXM2ZjpXUwGeifDOh i6/fEe9w1Ggv218DOcbxhL2TZUfj8kpwgUFEq9UXglMhww2qxLA0SNqh3mepfg56u3SW QhzGGwA/r7pLrXMU3HPqIBBxPNTGB0Lz9L347is8CaPrMJHl0mrMQcckrt1lDLzMLCx2 tlmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ErcIv7ML; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-144602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h130-20020a636c88000000b005dc48945ce7si7218278pgc.802.2024.04.14.23.39.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Apr 2024 23:39:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ErcIv7ML; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-144602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C6FD9281317 for ; Mon, 15 Apr 2024 06:39:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 013581D54A; Mon, 15 Apr 2024 06:39:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ErcIv7ML" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1704A1C6B9 for ; Mon, 15 Apr 2024 06:39:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713163145; cv=none; b=PzoL5XP3efVUdoJ5w2c/xa9I9smxLXHP6XhYxGF0nkL9jEa7hQVuXGyBG0ELANbK9v5KfBd7+A+JwJ9OI5oxGkC8sWrjq5hd+I4ZIUpxNh+YBY13CAN1WaF4gUU0l3huAYWIjLcyzQVOs2WSd6boX3nfStdsCxE8JdR1iI9hgVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713163145; c=relaxed/simple; bh=WfgQkz1O24qdMgxAqlkplv/ziGxYLznIbd05tGFu1IA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=aMRWMGNU3GiNoNs0+Kc6lLyFt71Nt7w4vg+/5p29lgQ1b2yeRMrUQvEUEXX1PK32p3Ixrc5sffEWkSFr37E92pryfGVdVpv3kQRtnXgqOnFaQZxRR5MY8lCa1IglUsqGCx8JamirvWl4L8WRJi18S1Grk5UYZu88dGIcvlllI6Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ErcIv7ML; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 959F4C32781 for ; Mon, 15 Apr 2024 06:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713163144; bh=WfgQkz1O24qdMgxAqlkplv/ziGxYLznIbd05tGFu1IA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ErcIv7ML1uwx3A3L+0shIh63p7Y0HlvRmP6y/EePlnvGF37wfIMSDRgPkzrIbyXDU +Kkw56yrxjZi5qTx0DvL1HzhkmAFYpoEAj7kQzxyA3NyNcgwTv4NmQ/7F8+aTqu/RE UvEDXNSqJp1zWC0Wa9xuVk9Wz3j4d1kodypw6psBowS+UxPKkFPQeTMpwZoNg9RYAG 6Gtj1ju26SsQcVmKcla/SCRtPvSoTaV6AxN9g0QpwM3tnNd4FMuvlMVYw2N56Jm0AL g5KFzrW1AWLNi4SmdPcemnjKGW6AmbBXyg3+2B5NyJg2g8ksez47Fb/TqQFMSmSZQA LnjN47XTLS7Dg== Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2da68af6c6fso10431401fa.3 for ; Sun, 14 Apr 2024 23:39:04 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWOi8DWl12YkkxNJS4So//50BhD2XKlCRtXkXjLVklme/UWOsaN/fQu4d3jEdX8zQJEKuaUwcNO1/cSspIRUsIZO2ZOzmdaZjjYJzds X-Gm-Message-State: AOJu0Yx6wWY2ermOmEpBPmsOFWbIGzaqnnGzCO8NkkQVKc0NVM3Y/jTu 0/ehhk/8saMXIG7iibxWq1zx4eSD6HK72HYOaOYmbypz0BicHUzZrWC11O6leAa6YdMLUQD/CJg qCwWpZaOmNVX4onJFYX6Bg7AJ+AU= X-Received: by 2002:a2e:bc19:0:b0:2da:9d98:5ec2 with SMTP id b25-20020a2ebc19000000b002da9d985ec2mr110279ljf.4.1713163142885; Sun, 14 Apr 2024 23:39:02 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240415063110.1795707-1-anshuman.khandual@arm.com> In-Reply-To: <20240415063110.1795707-1-anshuman.khandual@arm.com> From: Ard Biesheuvel Date: Mon, 15 Apr 2024 08:38:51 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] arm64/hugetlb: Fix page table walk in huge_pte_alloc() To: Anshuman Khandual Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Ryan Roberts , Mark Rutland , linux-kernel@vger.kernel.org, Dev Jain Content-Type: text/plain; charset="UTF-8" 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? > pudp = pud_alloc(mm, p4dp, addr); > if (!pudp) > return NULL; > -- > 2.25.1 >