From nobody Tue Feb 10 00:22:27 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 7D8331DE2A4 for ; Mon, 27 Jan 2025 23:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738020171; cv=none; b=YopSUEPiiDtmIqQuUHTXKr8duQmbvCpNUdEk6MqtieZ2ei4sobstfl+RDDHkkMVqYFlM+bABWWx2+Zj3BlUy/OKpBG+hHvcfW9seutNa3Cc5SDp6LU6lSQP73QiNnNKfpwKrwJl4rajTFSORkFg0+JLTC6hROZx0m+cenUU9FSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738020171; c=relaxed/simple; bh=7FRbZlIapsmOLPkpz95/S82UEQkKoFbNdPXuxd+YrJs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PdEvsgO5fgh6gtz0cLkNVcp5c/22rob4n8UiexbLmmeJjOsqK4HfujbWGw7v7mjhzuhFcapoDB/szR9RycpxTOjg864Iml8b59ne5qWM+BBDsV3Ke9qMJGAwimhNQiJAUQHuHlsDQQt234g9dKATn1XoSI3eQBNm2dm5SeEoU4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--fvdl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dH5TiJRH; arc=none smtp.client-ip=209.85.216.74 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--fvdl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dH5TiJRH" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9e4c5343so14036446a91.0 for ; Mon, 27 Jan 2025 15:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738020170; x=1738624970; 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=yQdEXb7VrREiqENOyRwQSlPqHVu4TlSVRGhdtKj9UPA=; b=dH5TiJRHP4wIbX86Dn27q0UVxqbmBjX1I2KuwqfUC6HaVTZpt774bYaFdWG38qyD0P UVV0uJh2l2TWKcpFJJz3cYUr88w67G8Q8R3qyDi4AUK2kXot6JPSLlBUwEiE8S13gqsi sHWgIxLcL2Rv5OCbGbNQ0300Z5rgNfaoGPRxcOU6CUd2HkZF1LueyNuBcCu1dk4zGCs/ rN6ZTNJ8vhAc2VHHYoEmhIllYRmijjgUzcmT6EroFztuhM8n25T8eykxfVZnJunsD9+2 CHCGgqXrPTiyx7oOTIEF2m+pa+rhjRb0+kAOGNUd54N5PL4A0VDz6/qp99S/eqC6PhDh 23zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738020170; x=1738624970; 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=yQdEXb7VrREiqENOyRwQSlPqHVu4TlSVRGhdtKj9UPA=; b=NhW/JFyXWu3nC+mV2zg1gt1Ozs8SByuj9p0SbPOR2EloPDK7izfu0DSLRJ6OrO8SBT Ijmz7DxpLkjpbtBtEAD3cz6BbD7v5piLrc1SkUkNgHTUo0xP850kKXqPBVvJ6bfzPUpS 3d1pVzpZCK1tisvLsrV+uHP8SCqGjwDMef+DmxtP0Mh67ZcV5p0AzhWtCEuTnoRrr/GN m/SuEro5fUMX3Ua6Mddf/Ls00kr8NZi4G6jvDZ4/sST/kkrOzhLW+ZWlPwQhe63LPMIX tP73lFgSBCoegzCcL2p2qmfoF8jFmbhP/sFXWZUKzMQ/PoHFQfvJBaWPRk08nbRGfpHa c+7g== X-Forwarded-Encrypted: i=1; AJvYcCV8re4QZvtJONBju/s0RzKTXJcWIBCxnhrF3iq74Ay52PdLXQJYynv0BioGm8iCJDz1jehggtEZfoVrj+E=@vger.kernel.org X-Gm-Message-State: AOJu0YyhcNDRRoyDvPWhRRbSXzAzIgWHDHAWWrZU6gEAhWehC7gfp4UC F4TU2KnFwtAAsoZKjr19A05IV3yScZSZ3nEmfoJRcWGeR2aPRpXQ2F9dM9N1ydTe/5sIQg== X-Google-Smtp-Source: AGHT+IGOxA/LjCFXYDhUCJvwKiwBW39Jv15WSyjwI6Z7bApcIx6+wrwzNjIWdbWHTiCawWQ9bGPb1PBa X-Received: from pfbds10.prod.google.com ([2002:a05:6a00:4aca:b0:725:ceac:b484]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2917:b0:71e:13ac:d835 with SMTP id d2e1a72fcca58-72dafa442bdmr62065805b3a.11.1738020169612; Mon, 27 Jan 2025 15:22:49 -0800 (PST) Date: Mon, 27 Jan 2025 23:21:56 +0000 In-Reply-To: <20250127232207.3888640-1-fvdl@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250127232207.3888640-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127232207.3888640-17-fvdl@google.com> Subject: [PATCH 16/27] mm/hugetlb: deal with multiple calls to hugetlb_bootmem_alloc From: Frank van der Linden To: akpm@linux-foundation.org, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: yuzhao@google.com, usama.arif@bytedance.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Architectures that want pre-HVO of hugetlb vmemmap pages will need to call hugetlb_bootmem_alloc from an earlier spot in boot (before sparse_init). To facilitate some architectures doing this, protect hugetlb_bootmem_alloc against multiple calls. Also provide a helper function to check if it's been called, so that the early HVO code, to be added later, can see if there is anything to do. Signed-off-by: Frank van der Linden --- include/linux/hugetlb.h | 6 ++++++ mm/hugetlb.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 9cd7c9dacb88..5061279e5f73 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -175,6 +175,7 @@ extern int sysctl_hugetlb_shm_group; extern struct list_head huge_boot_pages[MAX_NUMNODES]; =20 void hugetlb_bootmem_alloc(void); +bool hugetlb_bootmem_allocated(void); =20 /* arch callbacks */ =20 @@ -1256,6 +1257,11 @@ static inline bool hugetlbfs_pagecache_present( static inline void hugetlb_bootmem_alloc(void) { } + +static inline bool hugetlb_bootmem_allocated(void) +{ + return false; +} #endif /* CONFIG_HUGETLB_PAGE */ =20 static inline spinlock_t *huge_pte_lock(struct hstate *h, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a4d29a4f3efe..18cd232b5df2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4911,16 +4911,28 @@ static int __init default_hugepagesz_setup(char *s) } hugetlb_early_param("default_hugepagesz", default_hugepagesz_setup); =20 +static bool __hugetlb_bootmem_allocated __initdata; + +bool __init hugetlb_bootmem_allocated(void) +{ + return __hugetlb_bootmem_allocated; +} + void __init hugetlb_bootmem_alloc(void) { struct hstate *h; =20 + if (__hugetlb_bootmem_allocated) + return; + hugetlb_parse_params(); =20 for_each_hstate(h) { if (hstate_is_gigantic(h)) hugetlb_hstate_alloc_pages(h); } + + __hugetlb_bootmem_allocated =3D true; } =20 static unsigned int allowed_mems_nr(struct hstate *h) --=20 2.48.1.262.g85cc9f2d1e-goog