Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4177825rwb; Mon, 21 Nov 2022 04:49:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5gyy9js1zWx3yWLL7y4PHafH/DY9Srg9CltXYCswdEI4EmQnX7A9GU602xhmeCCRr4yLZ3 X-Received: by 2002:a17:907:a80b:b0:7b5:cab4:68b8 with SMTP id vo11-20020a170907a80b00b007b5cab468b8mr4565006ejc.685.1669034985694; Mon, 21 Nov 2022 04:49:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669034985; cv=none; d=google.com; s=arc-20160816; b=epWamRXTeajkCnmKJNC8n0xYqy27+dgd+9p5rkzfOzlMs1zVrvaO8Jca6Zm/X6ZQoX AnDkfOYbwI+FVReWpnhOX5tb9zZWHdAX/o9Ri2AbLyOsXI7oEsh32epktXRXpXhBLzYV m8vh43ygUXbij8/WkSFlaXtBrRDLwK0R8xoR5vI/qcqLcebScOuOY8mSgScZ2KPKe+uD /vQsuX1L81WVM+LmJ6eSX64h3joFL7+o9a+AT2WtRbiPKxzc+AAJXEGa4k+Xt2AfeEAJ v52AAI6OyrOfERxKazFFYV7HjFih51VjvYx5vBzGw5oYmS/sO4AxL8wodY8xXERFrVDS tR5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=RXZghvA40ssAo2+vuY1LB1wWbiqz1uTNn/0T+f9sOQ8=; b=B8wI0oRPafsFHwO3sGl9TrajG8wkXk/588W8vLV349BN8v9PF2712OSI/s1aU1tiyB GwEiyFhbEHlmwE4lD3ZJV1lsSMSpXwV85Ro1bwggKPzS9xNK5wb4cJAbsXLjW3SOSqW6 QZJejXup9OpEIZ+OXsIE/ycxC9uC6YYIreVoR/qCQSGV3kQWQJ7d18cxdV7jlw1uIDlL Iv43oq2QYLIaK9h+7JM8AeyATmW/drECpxXGCWRw7nKCnCTsjlTs/zcORAviCZAYacp5 KQvnza+/WMQiLiqd9o/mZYZMdpMf1X1yRE2c2ces6EbC9I0nlrEz7CVW0kV9Br8Aqh6V WXNA== 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 l4-20020aa7d944000000b00467e2dc8d13si3280376eds.94.2022.11.21.04.49.23; Mon, 21 Nov 2022 04:49:45 -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 S230339AbiKUM2z (ORCPT + 92 others); Mon, 21 Nov 2022 07:28:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230101AbiKUM2g (ORCPT ); Mon, 21 Nov 2022 07:28:36 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A57965FDF for ; Mon, 21 Nov 2022 04:27: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 B8ACB23A; Mon, 21 Nov 2022 04:28:01 -0800 (PST) Received: from FVFF77S0Q05N.cambridge.arm.com (FVFF77S0Q05N.cambridge.arm.com [10.1.25.132]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 299953F7D8; Mon, 21 Nov 2022 04:27:54 -0800 (PST) Date: Mon, 21 Nov 2022 12:27:51 +0000 From: Mark Rutland To: Anshuman Khandual Cc: Nathan Chancellor , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Andrew Morton , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] arm64/mm: Drop redundant BUG_ON(!pgtable_alloc) Message-ID: References: <20221118053102.500216-1-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,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 Mon, Nov 21, 2022 at 11:00:42AM +0530, Anshuman Khandual wrote: > Hello Nathan, > > Thanks for the report. > > On 11/20/22 21:46, Nathan Chancellor wrote: > > Hi Anshuman, > > I just bisected a boot failure in our QEMU-based continuous integration > > setup to this change as commit 9ed2b4616d4e ("arm64/mm: Drop redundant > > BUG_ON(!pgtable_alloc)") in the arm64 tree. There is no output so the > > panic clearly happens early at boot. If I move back to the previous > > commit and add a WARN_ON() like so: > > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > index d386033a074c..9280a92ff920 100644 > > --- a/arch/arm64/mm/mmu.c > > +++ b/arch/arm64/mm/mmu.c > > @@ -383,6 +383,7 @@ static void __create_pgd_mapping_locked(pgd_t *pgdir, phys_addr_t phys, > > phys &= PAGE_MASK; > > addr = virt & PAGE_MASK; > > end = PAGE_ALIGN(virt + size); > > + WARN_ON(!pgtable_alloc); > > > > do { > > next = pgd_addr_end(addr, end); > > > > I do see some stacktraces. I have attached the boot log from QEMU. > > > > If there is any additional information I can provide or patches I can > > test, I am more than happy to do so. > > There are couple of instances, where __create_pgd_mapping() function gets called > without a valid pgtable alloc function (NULL is passed on instead), as it is not > expected to allocate page table pages, during the mapping process. The following > change after this patch should solve the reported problem. > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 9ea8e9039992..a00563122fcb 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -42,6 +42,7 @@ > #define NO_BLOCK_MAPPINGS BIT(0) > #define NO_CONT_MAPPINGS BIT(1) > #define NO_EXEC_MAPPINGS BIT(2) /* assumes FEAT_HPDS is not used */ > +#define NO_ALLOC_MAPPINGS BIT(3) /* does not allocate page table pages */ > > int idmap_t0sz __ro_after_init; > > @@ -380,7 +381,7 @@ static void __create_pgd_mapping_locked(pgd_t *pgdir, phys_addr_t phys, > phys &= PAGE_MASK; > addr = virt & PAGE_MASK; > end = PAGE_ALIGN(virt + size); > - BUG_ON(!pgtable_alloc); > + BUG_ON(!(flags & NO_ALLOC_MAPPINGS) && !pgtable_alloc); > > do { > next = pgd_addr_end(addr, end); > @@ -453,7 +454,7 @@ static void __init create_mapping_noalloc(phys_addr_t phys, unsigned long virt, > return; > } > __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, NULL, > - NO_CONT_MAPPINGS); > + NO_CONT_MAPPINGS | NO_ALLOC_MAPPINGS); > } > > void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, > @@ -481,7 +482,7 @@ static void update_mapping_prot(phys_addr_t phys, unsigned long virt, > } > > __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, NULL, > - NO_CONT_MAPPINGS); > + NO_CONT_MAPPINGS | NO_ALLOC_MAPPINGS); > > /* flush the TLBs after updating live kernel mappings */ > flush_tlb_kernel_range(virt, virt + size); This is now more complicated than what we had originally, and it doesn't catch the case where the caller sets NO_ALLOC_MAPPINGS but the callee ends up needing to perform an allocation, which the old code would have caught. This is clearly more subtle than we thought initially; for now could we please just drop the patch? Thanks, Mark.