From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62A57606A68F for ; Tue, 1 Dec 2026 16:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=SDOdvaWM; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ovn44VHC DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=L80cFBmwg1c3A1WoD5qFzXotf/qlD1t/FF9rRRBu4Ag=; b=SDOdvaWMOywgiwtgKYP+2s5px8 2r8gw9ATHuNTC1Hey7zZkJfwEDt2lL/cBzJUIwqQ0rrGnSCHbl+VS8fwQv/1WnHg6YngEygrfOxmD KVVBCG2J/vHJ1BlEjONHmUXPg6u+XHrT/CvbuEnPb6Vlv23YbJgnfNtCSCLk8/7qdgJE6bUbpfr1S cV+eswUgCliDN3RFXbVhXWkbV0WmlChWZemRIh+1f22sSyxlPoU7AUAlgSf15I0Z4iuYb3DVKPjSX QdowtKAa4QCiCNOUoQjXKZZIa930pLlFRzOBHUFGHoM8uWvux7hgUQfMjH1d41sSrJtVMrKQiINEk U9v2WRHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPSx-00000008UDo-3Tsi; Tue, 01 Dec 2026 15:08:23 +0000 Received: from mail-pl1-x645.google.com ([2607:f8b0:4864:20::645]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPSq-00000008U5D-1UjW for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 15:08:17 +0000 Received: by mail-pl1-x645.google.com with SMTP id d9443c01a7336-2f03a137f6aso101648525ad.3 for ; Tue, 01 Dec 2026 07:08:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137695; x=1796742495; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=L80cFBmwg1c3A1WoD5qFzXotf/qlD1t/FF9rRRBu4Ag=; b=ovn44VHCWZSZxYI2TJiVWc8Jp8QwS3AEasCXK0IwMNpkvarHppvbbkO7wuzkKeDuZk KJtgRXsAnflr4Ol6ivU7CHNzzUFP8e9VLIBzG3tQY3l+9sgUcCGXt9X2Sa5xgNwiwMfU e5TKJrchKpMupPz0FERVjZmfO6t9nsTtkAXjqqUFKg+f+MZTpR6jJAuG4REoEVDWdHVo dPC3ZCFlx4EeWw69Z6T8u80MgEwvGjS5ADeMxu+WpKBp67tDaHxFcztWfnJgtsXPxuXj /2lU9PcLxxP/Zl9OVCnhVN0xn/wP082FKfbTl0DFxdMma04Q/S5dnLYK4aJYMCBneyNr cBog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137695; x=1796742495; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=L80cFBmwg1c3A1WoD5qFzXotf/qlD1t/FF9rRRBu4Ag=; b=gkKhvbJUPt17LxWn2eeIRm4ZH4EhIGEvaIUO3Ll17+ZZ4xKxONwAI6Osa6y/Qy7oY2 6ZQlFYUeQefD/sQz/dA7b83A1QdieQBibzRZMZAY74Za9xIdutdcxHofxw9Sid8ZQJGc HmXhgB9512YMUPqsexMYnVq2S4W6n1jCn67cTEphmc7FxoP29XxGzPEppY9ycx4jhKTH oObzEu+ivDqm13WYUAYDIyajenk3qf6LzApJKIVM2FDG5syTzPRgRCShGlzyrw+GQ/8g 0zyHw3/I3kd3CAik48bW70LNnM9/jpdzyeFWwQa+Z6ErqVHENCvQ5CAJaYjmWfUuefXQ 349g== X-Forwarded-Encrypted: i=1; AL+hErEjd7LW0WZ+Tx+N0KBH1Ueu+g8DF6BzWDoTA0KpaNFnl3BUuPbRz0B2hgG27UWC3w6tRkT7yLal3LB7JkOhI0YW@lists.infradead.org X-Gm-Message-State: APuU4Z+bQfh72RUA4ZoZ4O6G1Ji2hCLqbzyTUJI5znn6UNYGj4LflxFb Y3doVSmV0hkySwTwsw44eERDl87o/Yri7mx3pOQj5ele58BndE/rY9/wouKuZcwmNg+ZgwpF36I zmNUEULYMDqrQnlUaLh+R6g== X-Received: from plbmb6.prod.google.com ([2002:a17:903:986:b0:2e9:84f0:65ba]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d2cf:b0:2ef:dd60:39d1 with SMTP id d9443c01a7336-2f03ede9407mr416551445ad.0.1796137694637; Tue, 01 Dec 2026 07:08:14 -0800 (PST) Date: Tue, 1 Dec 2026 15:07:50 +0000 In-Reply-To: <20261201150801.2239894-1-jthoughton@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261201150801.2239894-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261201150801.2239894-9-jthoughton@google.com> Subject: [PATCH v4 08/18] arm64: Add bbm_through_af capability From: James Houghton To: Will Deacon , Catalin Marinas , Muchun Song , Oscar Salvador , Andrew Morton Cc: Kefeng Wang , Nikos Nikoleris , Linu Cherian , Mark Rutland , David Hildenbrand , Ryan Roberts , Nanyong Sun , Yu Zhao , Frank van der Linden , David Rientjes , James Houghton , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_070816_413743_3B19F2EC X-CRM114-Status: GOOD ( 22.81 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 HVO requires BBM Level 3 for the block -> table transitions when optimizing the vmemmap, and it requires hardware AF management to avoid taking page faults on the !AF translation that is installed as part of the RW table -> RO + new OA table transitions. Call this requirement "BBM through AF"; i.e., all CPUs support BBM-less, in-place TTD updates. All CPUs must support it for the kernel to use it, and BBML3 support may only be known from a CPU's MIDR, so model this as an early local CPU feature: it is checked on every early CPU, and if it is enabled, late CPUs that lack it are rejected. It may seem odd to check for HVO support directly in bbm_through_af(). If this weren't done, any system with mismatched HW AF will no longer be able to start late CPUs that are missing HW AF if all early CPUs have HW AF (and BBML3). This depends on HVO enablement not changing after boot, so select ARCH_HUGETLB_VMEMMAP_OPTIMIZATION_SYSCTL_RO. To know whether HVO has been requested, parse hugetlb_free_vmemmap= here as well. Early parameters are parsed in setup_arch(), before the boot CPU's features are detected, and all early parameter handlers with a matching name are called, so this does not interfere with HugeTLB's own handling of the parameter. Signed-off-by: James Houghton --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/cpufeature.h | 5 +++ arch/arm64/kernel/cpufeature.c | 50 +++++++++++++++++++++++++++++ arch/arm64/tools/cpucaps | 1 + 4 files changed, 57 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9b08b2457a55..4cce60c2de66 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -61,6 +61,7 @@ config ARM64 select ARCH_HAVE_ELF_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_HAVE_TRACE_MMIO_ACCESS + select ARCH_HUGETLB_VMEMMAP_OPTIMIZATION_SYSCTL_RO select ARCH_KEEP_MEMBLOCK select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE select ARCH_USE_CMPXCHG_LOCKREF diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 7d7b8eb7f72f..4434bec2cbd5 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -914,6 +914,11 @@ static inline bool system_supports_bbml3(void) return alternative_has_cap_unlikely(ARM64_HAS_BBML3); } +static inline bool system_supports_bbm_through_af(void) +{ + return alternative_has_cap_unlikely(ARM64_HAS_BBM_THROUGH_AF); +} + int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt); bool try_emulate_mrs(struct pt_regs *regs, u32 isn); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 866385b490eb..5259c620c0ac 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2041,6 +2041,49 @@ static bool has_bbml3(const struct arm64_cpu_capabilities *caps, int scope) return cpu_supports_bbml3(); } +/* + * Whether HVO has been requested with hugetlb_free_vmemmap=. This duplicates + * the parsing in mm/hugetlb_vmemmap.c, and the two must be kept in sync. + * Early parameters are parsed before the boot CPU's features are detected, + * and the HVO sysctl is read-only on arm64, so this reflects whether HVO is + * enabled for the lifetime of the system. + */ +static bool hvo_requested __ro_after_init = + IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON); + +#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP +static int __init hvo_requested_param(char *buf) +{ + return kstrtobool(buf, &hvo_requested); +} +early_param("hugetlb_free_vmemmap", hvo_requested_param); +#endif + +static bool has_bbm_through_af(const struct arm64_cpu_capabilities *caps, int scope) +{ + /* The kernel only enables HW AF updates with CONFIG_ARM64_HW_AFDBM. */ + if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM)) + return false; + + /* + * BBM-through-AF is only needed for HVO. If HVO is not in use, don't + * penalize systems with mismatched support. + */ + if (!hvo_requested) { + /* Only valid if HVO cannot be enabled later via the sysctl. */ + BUILD_BUG_ON(!IS_ENABLED(CONFIG_ARCH_HUGETLB_VMEMMAP_OPTIMIZATION_SYSCTL_RO)); + return false; + } + + /* + * We need BBML3 to support Block -> Table transitions without taking + * faults, and we need HW AF support to support changing the OA without + * taking faults. Both are properties of the local CPU (BBML3 support + * may only be known from its MIDR), so this is checked on every CPU. + */ + return cpu_supports_bbml3() && has_cpuid_feature(caps, scope); +} + static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) { /* @@ -2962,6 +3005,13 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .type = ARM64_CPUCAP_EARLY_LOCAL_CPU_FEATURE, .matches = has_bbml3, }, + { + .desc = "BBM-less TTD updates via Access Flag", + .capability = ARM64_HAS_BBM_THROUGH_AF, + .type = ARM64_CPUCAP_EARLY_LOCAL_CPU_FEATURE, + .matches = has_bbm_through_af, + ARM64_CPUID_FIELDS(ID_AA64MMFR1_EL1, HAFDBS, AF) + }, { .desc = "52-bit Virtual-Physical Addressing for S1 and S2 (LPA2)", .capability = ARM64_HAS_LPA2, diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index a0a0ee33fd09..d7d4ab9d07dd 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -15,6 +15,7 @@ HAS_ADDRESS_AUTH_IMP_DEF HAS_AMU_EXTN HAS_ARMv8_4_TTL HAS_BBML3 +HAS_BBM_THROUGH_AF HAS_CACHE_DIC HAS_CACHE_IDC HAS_CNP -- 2.56.1.839.g22a8290db9-goog