From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9412370AE0 for ; Wed, 8 Jul 2026 03:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783480300; cv=none; b=BuQouWzS5oerXGgaiFRJWn+e274fBSzTf8EjickJz5gO6sjyppgxOKKD2sW5vzzDrtoWqzBagq+CjGmdRsLKXsHyT1GViz/5fSiux6+bdGLMO/2C/S7nh9NGoKbwmr1xO4+J4QMtA5bxJdUNfC0c0AjyS+CGrpQKzU1PMwe304c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783480300; c=relaxed/simple; bh=vSc9UcvpGPmcld9MD/vJW+N/PkCuGGK9P6oKEPu7j2I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LYZRvb+bo8/GTVRF6v6E7J/Fyj+7vqlsAB7Fvmjq80QLoJq94I6rdYd2kNpZLnz5OGS2jiMy4A/XkC804QUTpKYcbRWmY2lLMokzzTxj7GJHkBtYjTWzYF3c1GAK2OuNU5DXp568bZnd+nXkF9YDP5ZHZ4Gl6lLvPDMcics6UU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bpjfmxCv; arc=none smtp.client-ip=209.85.214.202 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.b="bpjfmxCv" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2cc6dd43737so7764815ad.2 for ; Tue, 07 Jul 2026 20:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783480298; x=1784085098; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nqMjZmPsv3+liEaC57LQksKr8l/QZSzOSPi/lkAXRvo=; b=bpjfmxCvoMD9rAv+kINyfzhCmTF7So5Yc31FWIYxsGYK6n1GuotMpLgTsLiJiiA9p4 590U9l8OqPCkT9HNtELIbFdWuupWAYL28WjJQ2oTTTRWPsuDaL+OCri4CyNEV7PwW9Os 8b1mKQsuIgLszR6NgEiLvBHsuvQuatvYkPE5hT37fzUnEuFLS8luWbny7QUbscIt9NVk J0z0bLRHdmWep3Fth6YZMXtV/gZJFG/oDNpMNRM06r6wKAZ+xqyt0wxdth2MYGrcZm4q z0z9VqGStEXjtzBlN/vwlFzyzPnahz/VQNM+zWJvMSGr1f4QOoWh+S430M536RjCEo2r +c6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783480298; x=1784085098; h=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; bh=nqMjZmPsv3+liEaC57LQksKr8l/QZSzOSPi/lkAXRvo=; b=o+SBKu2xY0vytbs/o/J6eKutH6o6mdMbrYSHdkzj2+h2dFLLv7KNCx/UiMcvW/SYrB 4rTgKDJi7BXBJbcpG8+ExjQtdKcspH5nu1+aZ/cuXoxUcKSkMgUPQjWNjcYTrsC0N8xo swUdy3BkxPYITGsxR8dRitVSOOZp/M9ZdElxz0Dg9mPyqalJPjGMU3muoGN5PQOKvREO BTLaUrmOOEwc40SONUVBH7ckRgEejDXesyduhnFpbbBIl89Bfncdls2TYsq5uJTGPFVD NVStApcNhCy7TWqZZk/9GpqgY874/8xVwlBZzs4g3R7o8SGG6qO8fZ7OxwIJRdW7H8Fl 4A1g== X-Forwarded-Encrypted: i=1; AHgh+RpsfZNi/sz0aBjqsUVhFV6BWpOMpOJba3kmu/AgYM7acrKsFSSRULFbJQGJOKVXC0sYIdV1SR7YiN2RhBk=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9zb4IRDthRUBHYo5h7uDrsfNDY7yBGnKZMrwB76pOsQBv6WSh EWmknHLCJy5DXkT4WMi1qFsGn6n1GlFR+LLpiQbg65NJ34a7rbG8P6YWFfgQL6iXOGUeDjpQ4Dp alXaiBhJPhJ4k6wvhAwxzmw== X-Received: from plml12.prod.google.com ([2002:a17:903:184c:b0:2b6:417:db8d]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2b0b:b0:2ca:2753:f3cc with SMTP id d9443c01a7336-2ccea45a3a2mr7332045ad.33.1783480298065; Tue, 07 Jul 2026 20:11:38 -0700 (PDT) Date: Wed, 8 Jul 2026 03:11:15 +0000 In-Reply-To: <20260708031129.3503195-1-jthoughton@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260708031129.3503195-1-jthoughton@google.com> X-Mailer: git-send-email 2.55.0.795.g602f6c329a-goog Message-ID: <20260708031129.3503195-6-jthoughton@google.com> Subject: [PATCH 05/18] hugetlb_vmemmap: Allow architectures not to allow HVO at runtime From: James Houghton To: Will Deacon , Catalin Marinas , Muchun Song , Oscar Salvador Cc: Nikos Nikoleris , Linu Cherian , Mark Rutland , David Hildenbrand , Andrew Morton , 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" Even if HVO is enabled, architectures may at run-time determine that it cannot be used. It may be the case that arch_supports_hugetlb_vmemmap_optimization() returns false at first but eventually returns true. This is the case on arm64. When this happens, bootmem hugepages won't be immediately HVOed, but they will be optimized in prep_and_add_bootmem_folios(), part of hugetlb_init(). Signed-off-by: James Houghton --- include/asm-generic/hugetlb.h | 7 +++++++ mm/hugetlb_vmemmap.c | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index e1a2e1b7c8e7..c4796c54b702 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -128,4 +128,11 @@ static inline bool gigantic_page_runtime_supported(void) } #endif /* __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED */ +#ifndef __HAVE_ARCH_HVO_SUPPORTED +static inline bool arch_hugetlb_vmemmap_optimization_supported(void) +{ + return IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP); +} +#endif /* __HAVE_ARCH_HVO_SUPPORTED */ + #endif /* _ASM_GENERIC_HUGETLB_H */ diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 3951c043164a..21377f795293 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -17,6 +17,7 @@ #include #include +#include "linux/hugetlb.h" #include #include "hugetlb_vmemmap.h" #include "internal.h" @@ -556,6 +557,9 @@ static bool vmemmap_should_optimize_folio(const struct hstate *h, struct folio * if (!READ_ONCE(vmemmap_optimize_enabled)) return false; + if (!arch_hugetlb_vmemmap_optimization_supported()) + return false; + if (!hugetlb_vmemmap_optimizable(h)) return false; @@ -764,6 +768,14 @@ static bool vmemmap_should_optimize_bootmem_page(struct huge_bootmem_page *m) if (!READ_ONCE(vmemmap_optimize_enabled)) return false; + /* + * Architectures may return false here but true by the time + * hugetlb_init() is called. In this case, although the folios will + * not be pre-HVOed, they will be optimized in hugetlb_init(). + */ + if (!arch_hugetlb_vmemmap_optimization_supported()) + return false; + if (!hugetlb_vmemmap_optimizable(m->hstate)) return false; -- 2.55.0.795.g602f6c329a-goog