From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137693; b=R2UCn91zBPkFxD0W+eV3zb5ICwr1qtJtAVtzfQHRNL7flFpZ7kQnX3TVqergEBomZeBg uzp9PaRUmUzdmlcqCjZRu4cXsY7/ej6Y0YJ0DG5ypSXFbtE9a9vkvumA3+NBuf49/8+SI f53Ikwc4N3waPflBqJUD0QsXOQXZtjYZtngm97BQczvDiMXdopJyu9n49CFovQ9K5er0M zTHsheV6QV1csHu0wNTttMUgvol7lK+w2twdwdQx60fcoBxxGCTPwSargxv/fKWKf+t9J oBP7LymG3JJKquhd9IgEJQ6vYasC8c6zcCHI5gvQVvN3I5c2syoUXfmPBzeFwoOznYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137693; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=7PZ1DPXQI31bbZTsuXtRqAigiuVHvCZHbQibPlOovu0=; b=4zVqQbIofMK6zJ6Swfyn4oWgPAnD1ml8QRZ3jlLN113VKqVr8YNu+RoEqWkJ+xvs8fdk BFBPMNkAwNyQcNLTZYgiz2IXSay8kYPgkNnhRE1qxxfwu5cVERvj35UiP632BymKjLtcl MrJapnLtoV7cgwLHHMRCLRz8jA1CmeLQkPmycW+7kbVkzVAA3IQnP86dg341255fIYIig M9H7ZPtevd1JbqB0/xtkLDeqYllydfB5OHxG5PUCY4L188PlrYV2OwcKthhtH0hiZ1GGF H72e6sjmRDO4dKtMdQAWE3y/Ycps33cW+8/mj6CjeG7DqV8KyhCbAH1YmjYD6PirJ6w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=oSp2bUVC; arc=none smtp.remote-ip=209.85.216.71 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D2A8606A322 for ; Tue, 1 Dec 2026 15:08:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6D2A8606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=oSp2bUVC Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-3b4b76a2b95so10565106a91.1 for ; Tue, 01 Dec 2026 07:08:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137692; x=1796742492; darn=vger.kernel.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=7PZ1DPXQI31bbZTsuXtRqAigiuVHvCZHbQibPlOovu0=; b=oSp2bUVCs4gJZjd0XT1h0HgTQds5t93psyk/V+INbzex68NgNMllIBloyd9ERwvdpg TKg+FuODhd8PtHx98B5Befjapr39m8X35g/eNfp+Lan6YPmEvT5ptUHc/P1Gq8MbaCro DHuG44dIsuM3Lx+3/yvDQIh/He48Ql0xlhZJGTkzXuTaqy1DdZB3I1P0w25I9mqSF1jC xqdT3eXF5wj97pseGrKClDaL7lvOo6TgWleICgWc7j9EH5fYA5AqZRb9a8JywCmnEby+ 6bKNAew17hIKwP/Xq1YTMxZWeVv6BI57WTVmyfwUM2kirxsnJQdgDEjTKk7l7kFDAUtU tBCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137692; x=1796742492; 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=7PZ1DPXQI31bbZTsuXtRqAigiuVHvCZHbQibPlOovu0=; b=oVXCo8nxJ3xznnfWUKBF2wB3UfC8SkrG840n1L9jUPCHHApCQnIYXonptKTsmqvHTj WQjg5u3/igkR/yqSOELq0FvB7ZXd/kQpVqAIU6w67T8ZqIDG8HCylvhRW/AsWvvh0S1m PIzxpj8ajnJlXLRk6JnTxG2LBz1lZfGqZF70jQkT06Tz3bBPrmD6wqn2d4RcUDmxtvK5 YhSPG8KJ2kNtEmvTkCT+tpR6xRgwQTXZsBySC51LeQgnEWQP2ws/4up6pnf6D7Gxt7sS fHYUTGi37EmQTj1ikC+oeA38aRJre2goVpiILIVu64+bnNHMcYkYbXtnBFvk58I2ibLK yBew== X-Forwarded-Encrypted: i=1; AL+hErFkB3U1BBVO86QVbXBg+H9T89zUU29PLK9ybxFSn+C/pOOAd2SBndEj6AjUiFnEGCWLqcaBhP36+ofepUI=@vger.kernel.org X-Gm-Message-State: APuU4Z+MPqjEjeKmdUPQMF/BiEAE9r9DFSRlhKqIcmASSCZoktscbPBV z1GE3+Dk6YECi8+tYGoe91W11e3F9Jw/1jfsduRUYWTGpomUhgXV5uyNSGXoHxo+vpIgaOQE2XW 3sASS7/gGskyxuD6sHfkn6A== X-Received: from pgp3-n1.prod.google.com ([2002:a05:6a02:62c3:10b0:cdd:ad4c:6247]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2f8f:b0:3b3:bd07:665b with SMTP id 98e67ed59e1d1-3b41c9325b1mr36999020a91.40.1796137692260; Tue, 01 Dec 2026 07:08:12 -0800 (PST) Date: Tue, 1 Dec 2026 15:07:47 +0000 In-Reply-To: <20261201150801.2239894-1-jthoughton@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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-6-jthoughton@google.com> Subject: [PATCH v4 05/18] hugetlb_vmemmap: Allow architectures to dynamically disallow HVO 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" For arm64, only some platforms support HVO. Add an arch hook, arch_supports_vmemmap_remap(), to prevent HVO from taking effect if the architecture lacks support. The hook is not HugeTLB-specific, so it can also be used by other users of in-place vmemmap remapping (e.g. FS-DAX). Check it in hugetlb_vmemmap_optimizable_size(), so that hstates are not reported or treated as optimizable (e.g. by report_hugepages() and the HugeTLB allocation and freeing paths) when the architecture does not support HVO. It may be the case that arch_supports_vmemmap_remap() returns false at first but eventually returns true. This is the case on arm64, where support depends on a system-wide CPU capability that is not yet known when bootmem hugepages are allocated. Such architectures cannot pre-HVO bootmem hugepages, so they must disable the section-based vmemmap optimization in their vmemmap population path with section_vmemmap_optimization_disable(). Their bootmem hugepages are then optimized when they are gathered instead. Signed-off-by: James Houghton --- include/linux/pgtable.h | 16 ++++++++++++++++ mm/hugetlb_vmemmap.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 13edae56c7e0..1ecfef54a2db 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -481,6 +481,22 @@ static inline int vmemmap_update_pte(unsigned long addr, pte_t *ptep, } #endif +#ifndef arch_supports_vmemmap_remap +/* + * arch_supports_vmemmap_remap - Whether in-use vmemmap mappings may be remapped. + * + * Vmemmap optimizations, such as the HugeTLB vmemmap optimization (HVO), + * remap vmemmap page table entries while they are in use. Architectures that + * can only do this under certain runtime conditions may override + * this hook. It may return false early during boot and true later. Once + * it becomes true, it must not start returning false. + */ +static inline bool arch_supports_vmemmap_remap(void) +{ + return IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION); +} +#endif + #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, pte_t *ptep, diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index 8b28063d78cc..5d4ad1b1d423 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -48,6 +48,8 @@ static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate if (!is_power_of_2(sizeof(struct page))) return 0; + if (!arch_supports_vmemmap_remap()) + return 0; return size > 0 ? size : 0; } #else -- 2.56.1.839.g22a8290db9-goog