Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3076670rdg; Tue, 17 Oct 2023 04:05:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhiVy//aAvfzT3fSulxlSibDBRtKHh/bTAqIGXY+OMIP2kDaW7xkXecTfehd57ygticlB9 X-Received: by 2002:a05:6359:5e02:b0:142:d04e:59f0 with SMTP id pw2-20020a0563595e0200b00142d04e59f0mr2013951rwb.14.1697540751198; Tue, 17 Oct 2023 04:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697540751; cv=none; d=google.com; s=arc-20160816; b=BkWCu/YIJGPqQo1HOOjUTiCAtC2V122GIsA5z/sNiaC+bhP98XH5SArAV4oTu6uR4W 9zg1GPhznKFWekSmiCD88OJ+6lATNPFCUskNZDo3yB6z9UhQD9h6JRFY0JXwxQPR6poD LKWzOQTkmB4hNBBr5YfC0/Pqu+3ecGr5SBWF7/aT6Y7HZZtjYpWTFymAd63rgy7CrOjX AlYFlsJJYIw5ehnXkTgDkYJG8FvxPpWf8DL5gDyJPLIuM+3bP4MSOvYGvyZglR0BPsci tCADjJ/BozVWMP1hqN1u2qBdGDcLb5O2oSDdw8hZYmTiGqk8fMfGRTtzdwHAIzc/Nuih I3UA== 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=Gwevp7HJw7fFper+R/wHv4eEB3710ahOjj7Jv5nz31M=; fh=q+n3uxE4vqKoK/8LoXwnC7jMnyMcKu1zlH1SjAPaWfQ=; b=rysGeVOvaAKVFivPZN468XRMqg/5ypryCHH0LcYCt51cL/NeiTV1/ndyohHY/hy9fS ARppHFFJ4iVTTyKZ7gAo96zlR+hFecbuflhQYAHqfJPCtHg2389A/5HW1OlcvDXYOf+2 FzvbdU4Kc4Nvq1jheQf8siCEC9qecHf/JT1QgVCPH4owL6TZrxFy8UPd2B2CBtQ8KP+1 VB/ojKsWWwzlY5jvwIX3rkLNYFwrKcAEl7N3f04V+tK0cLYZBDjgmKQ3sASWvZg5Dm4G xZxDb1/wdJjUh83YxBAEiCZ3GUODdG7qqecp1tjLm3eR8xwuvSmhZWqu0aPJkAalBF+e RfaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id h11-20020a65480b000000b00570505c5267si1432876pgs.262.2023.10.17.04.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:05:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0766B8075B21; Tue, 17 Oct 2023 04:05:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234605AbjJQLFR (ORCPT + 99 others); Tue, 17 Oct 2023 07:05:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234599AbjJQLFQ (ORCPT ); Tue, 17 Oct 2023 07:05:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 08EB0A2 for ; Tue, 17 Oct 2023 04:05:15 -0700 (PDT) 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 3D61B2F4; Tue, 17 Oct 2023 04:05:55 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.68.232]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 581FC3F5A1; Tue, 17 Oct 2023 04:05:13 -0700 (PDT) Date: Tue, 17 Oct 2023 12:05:10 +0100 From: Mark Rutland To: Gavin Shan Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, ryan.roberts@arm.com, anshuman.khandual@arm.com, shan.gavin@gmail.com Subject: Re: [PATCH] arm64: mm: Validate CONFIG_PGTABLE_LEVELS conditionally Message-ID: References: <20231017005300.334140-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231017005300.334140-1-gshan@redhat.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 17 Oct 2023 04:05:25 -0700 (PDT) On Tue, Oct 17, 2023 at 10:53:00AM +1000, Gavin Shan wrote: > It's allowed for the fixmap virtual address space to span multiple > PMD entries. Instead, the address space isn't allowed to span multiple > PUD entries. However, PMD entries are folded to PUD and PGD entries > in the following combination. In this particular case, the validation > on NR_BM_PMD_TABLES should be avoided. > > CONFIG_ARM64_PAGE_SHIFT = 14 > CONFIG_ARM64_VA_BITS_36 = y > CONFIG_PGTABLE_LEVELS = 2 Is this something you found by inspection, or are you hitting a real issue on a particular config? I built a kernel with: defconfig + CONFIG_ARM64_16K_PAGES=y + CONFIG_ARM64_VA_BITS_36=y ... which gives the CONFIG_* configuration you list above, and that works just fine. For 2-level 16K pages we'd need to reserve more than 32M of fixmap slots for the assertion to fire, and we only reserve ~6M of slots in total today, so I can't see how this would be a problem unless you have 26M+ of local additions to the fixmap? Regardless of that, I don't think it's right to elide the check entirely. The point of the check is to make sure that the fixmap VA range doesn't span across multiple PMD/PUD/P4D/PGD entries, as the early_fixmap_init() and fixmap_copy() code don't handle that in general. When using 2-level 16K pages, we still want to ensure the fixmap is contained within a single PGD, and checking that it falls within a single folded PMD will check that. See the message for commit: 414c109bdf496195 ("arm64: mm: always map fixmap at page granularity") ... and the bits that deleted from early_fixmap_init(). AFAICT this is fine as-is. Mark. > > Signed-off-by: Gavin Shan > --- > arch/arm64/mm/fixmap.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/mm/fixmap.c b/arch/arm64/mm/fixmap.c > index c0a3301203bd..5384e5c3aeaa 100644 > --- a/arch/arm64/mm/fixmap.c > +++ b/arch/arm64/mm/fixmap.c > @@ -18,10 +18,11 @@ > > #define NR_BM_PTE_TABLES \ > SPAN_NR_ENTRIES(FIXADDR_TOT_START, FIXADDR_TOP, PMD_SHIFT) > +#if CONFIG_PGTABLE_LEVELS > 2 > #define NR_BM_PMD_TABLES \ > SPAN_NR_ENTRIES(FIXADDR_TOT_START, FIXADDR_TOP, PUD_SHIFT) > - > static_assert(NR_BM_PMD_TABLES == 1); > +#endif > > #define __BM_TABLE_IDX(addr, shift) \ > (((addr) >> (shift)) - (FIXADDR_TOT_START >> (shift))) > -- > 2.41.0 >