From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EB4834BA42 for ; Mon, 10 Aug 2026 22:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786401391; cv=none; b=mVlj3z6X0oIm/HO0JSHa1tsNfAKXl4lQ/4RsLLRNRQKwb+V9pTbCVoXclkTCpUoV+KbkhVDzYPLUJNSW6oqFQxSlquvjcgnAYHdOdH3oqTbJflhccuiXoTHhUdRXrWxt1t5+C9ozA28IgGDIlyIzglrvU7vm9hKn8ob1oQzSLyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786401391; c=relaxed/simple; bh=JOO5cW0FccMno6KldugebgEfQy3idthFiJ5dzazLgpA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=KyaVPtmjv7WFhX3I48Tkkv7STpWrfWSYwX1UDuiVi9EKrtdQPy6UrbQDnFHF+lz8fXDnBdXeklcDc19BitOp7PzqA6FngAI7657o1WWk4Xw7jfV4XOtlJIz4XaXAKEoK5Loj6sJ3anmdghAZo7iUuTLPWcQovsj8DcZoVIiswYA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=BqER6ii8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="BqER6ii8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48F691F00A3A; Mon, 10 Aug 2026 22:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1786401389; bh=Sxvtq+dIwwU3yFI4tCujCyDFVlEgje+/ENJLI3Tg09c=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=BqER6ii8rP6FRY/NkYYyEQucd0+AtYHZb1aVAv1nJaet7sjRY4DvKpaScwlj6hH70 STxclYdXzNPEPjz9DJj4oroJ6inTBGt7aZVWKnVRSYS5lKOnRsujg1sn4T7GmDL7k4 df3AjAXRo6tPZOQYDAS0DHAiNu8DU7i9Ij23zig8= Date: Mon, 10 Aug 2026 15:36:28 -0700 From: Andrew Morton To: Sourav Panda Cc: Muchun Song , osalvador@suse.de, usama.arif@linux.dev, shakeel.butt@linux.dev, wangkefeng.wang@huawei.com, anshuman.khandual@arm.com, david@kernel.org, surenb@google.com, fvdl@google.com, gthelen@google.com, hannes@cmpxchg.org, riel@surriel.com, sj@kernel.org, vbabka@suse.cz, mhocko@suse.com, bjackman@google.com, zi.yan@sent.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5] mm/hugetlb_cma: Fix null nodemask dereference in hugetlb_cma_alloc_frozen_folio Message-Id: <20260810153628.c4049163bd92b5ce3d3d7d99@linux-foundation.org> In-Reply-To: References: <20260809043250.2917406-1-souravpanda@google.com> <60440F8D-5EE8-4254-9057-5FAD09B5D1FF@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 9 Aug 2026 23:39:22 -0700 Sourav Panda wrote: > > That way, we can remove the 'if (!page)' check here. > > Sure thing! Thanks! I shall send this tomorrow noon (PST) since I am > OOO starting Thursday. Sashiko said a thing - I don't think it reported this against previous iterations: https://sashiko.dev/#/patchset/20260726072935.3513996-1-souravpanda@google.com I'll add this v4->v5 update to mm-hotfixes-unstable, assuming it gets us a bit closer to the final version. --- a/mm/hugetlb_cma.c~mm-hugetlb_cma-fix-null-nodemask-dereference-in-hugetlb_cma_alloc_frozen_folio-v5 +++ a/mm/hugetlb_cma.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -30,12 +31,21 @@ struct folio *hugetlb_cma_alloc_frozen_f int node; struct folio *folio; struct page *page = NULL; + nodemask_t local_node_mask; if (!hugetlb_cma_size) return NULL; - if (!nodemask) - nodemask = &node_states[N_MEMORY]; + if (!nodemask) { + unsigned int cpuset_mems_cookie; + + do { + cpuset_mems_cookie = read_mems_allowed_begin(); + local_node_mask = cpuset_current_mems_allowed; + } while (read_mems_allowed_retry(cpuset_mems_cookie)); + + nodemask = &local_node_mask; + } if (hugetlb_cma[nid] && node_isset(nid, *nodemask)) page = cma_alloc_frozen_compound(hugetlb_cma[nid], order); _