From nobody Sun Feb 8 09:12:52 2026 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.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 C6B2D2D97AC; Wed, 24 Dec 2025 17:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=158.69.130.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766597653; cv=none; b=mcmS4NbPrmjhu7UvcSe3DN/8g22mxeTQEPjRHGoMqDH/WTD5JZxjfG8onpBfGy6ywvBbPJC8ygAonnMJzLIiLaeq40C8FVMp8s9E7ZvNtsO9wKiDQtdAOPPxm9z0RnQfP3F4SAK95FSX+Ienht0STb3ef9K4twmh4e4+8Sl7hCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766597653; c=relaxed/simple; bh=Ogk/dngzVOmKb1C80LeAS2BE01H8MPAYx/arFDCFiok=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IvB7j0O3QE4oHJwTxNOyvUyh6St58I6UQhANQuSNarzG+CsZ8AlIwXTBmDNWhh9y8aAocObDF9bq3XfpVOWwHN9yT+rYyjScghl1WqyAhg7Ufe3nK51ECRepcdhWEghSLLf8pFlF8NLN0jSFAShScA3Fw6FBOsQGPDOZ6rX5uoU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=mwV8vjej; arc=none smtp.client-ip=158.69.130.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="mwV8vjej" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1766597645; bh=Mq4W7sDg/Agh00nn/sSC9HgKzw4XSoLV+yJE0vShXuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mwV8vjejIZtBnu/BJjgSoh3W8IJpP5EO2IJSE+RFcgANHPCeB+IvJzRN24gfE2q/n G+qD4TBldsguubC1CzBWgXCZk9cHb6JJGcRY0+A68Qolw2M5dEs2l38UfCj2pM6HFG zfNMYKNSyAO0TChR5iBq28RBTxRKjHoXd2P0MfRXFoUsisfj5/1OkkG+ZYy2SnC+my Q3y321qFZXstB2beDmbgavxfWHzwRRAUR8ARIBm37KXRnsVj0a/kUoQ9sD8N6/7ODe oeJ8PR6D2iPQjP+61hbSwEncWMcef/vyaEQ4YYzfsF7E1LmAPdHZDFUMvSs4268PC9 3lTVo5ib/oSyw== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4dbzWd36bLzfHp; Wed, 24 Dec 2025 12:34:05 -0500 (EST) From: Mathieu Desnoyers To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Thomas Gleixner , stable@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 1/3] mm: Add missing static initializer for init_mm::mm_cid.lock Date: Wed, 24 Dec 2025 12:33:56 -0500 Message-Id: <20251224173358.647691-2-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251224173358.647691-1-mathieu.desnoyers@efficios.com> References: <20251224173358.647691-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Initialize the mm_cid.lock struct member of init_mm. Fixes: 8cea569ca785 ("sched/mmcid: Use proper data structures") Signed-off-by: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: stable@vger.kernel.org Cc: linux-mm@kvack.org Reviewed-by: Thomas Gleixner --- mm/init-mm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/init-mm.c b/mm/init-mm.c index 4600e7605cab..a514f8ce47e3 100644 --- a/mm/init-mm.c +++ b/mm/init-mm.c @@ -44,6 +44,9 @@ struct mm_struct init_mm =3D { .mm_lock_seq =3D SEQCNT_ZERO(init_mm.mm_lock_seq), #endif .user_ns =3D &init_user_ns, +#ifdef CONFIG_SCHED_MM_CID + .mm_cid.lock =3D __RAW_SPIN_LOCK_UNLOCKED(init_mm.mm_cid.lock), +#endif .cpu_bitmap =3D CPU_BITS_NONE, INIT_MM_CONTEXT(init_mm) }; --=20 2.39.5 From nobody Sun Feb 8 09:12:52 2026 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.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 C6A39237163; Wed, 24 Dec 2025 17:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=158.69.130.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766597653; cv=none; b=D6vUn2MMfIt7Lb9VNTk+xJ62FGE5HTX00V0t7aZxVHJJMeOR+p2eirnQwZUtE3veFUhT5WIE9IJrDXa8oLwt6bFMsDmJ5K/WMZvGbxIeiwnE2HktR6qs+YXtDlRf5KZUcs/aVXIywwJhl5KtrrRZyx2A9GvuHrjrMk4XRCFVBHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766597653; c=relaxed/simple; bh=dpDggfA1CUPIWadnRIUWexZZYKzKAFim45G5ZHnxFZU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G0fICvDbnEGKAvMcZfy6dyBZn6SCX9jmDn7KQ24DiZbYuYlGc//lo0VvruX5h55TcA3b3m0NDc7E4dKmxyd4K6GiiJ9/XdjkqpM8eP8+6w/gE4LfVyGrD++9HjJS4kvY6urerjR2rnm4uVjuwa+ED1Pmrwu2zWFUjZqrVGKJ8JQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=wPGl1lV8; arc=none smtp.client-ip=158.69.130.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="wPGl1lV8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1766597645; bh=2CDN18JsLQ2lkxbVIsQQjPwRxfXSOdUFY21zfgGMtQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wPGl1lV8BtmA4wS9kzpWh8wFbWbXztbx81F3m8K9r6NMNkeUCc7vFctVGUWmcmiQr Rj8lbZL82zZVEyBSvdbVlpmqpRpB1InHW2RfF6sQCI/bjZu4CaLolZEYt8XN600fGd 1l0Mlu9P9U+WY5noI8j8mDBoQs+LbILtIS4Ia+j7qulcXMQis7kD9gXQoCc0eo1/nU Qi+9AiHBzkSuy7d5379rWGrNdcFtYNuxEZSCnriXfaMEvzKREX3ZJoHVxfoqoSOcyf 6oNSC3IfoQehKI/qSrOZWderVFIdT8SexI/hyIGs/3bXjVWJdM8GjfZ3BZG610ABvI ck8PPcc17Z26g== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4dbzWd4H7lzfHq; Wed, 24 Dec 2025 12:34:05 -0500 (EST) From: Mathieu Desnoyers To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Thomas Gleixner , stable@vger.kernel.org, linux-mm@kvack.org, Mark Brown Subject: [PATCH v1 2/3] mm: Rename cpu_bitmap field to flexible_array Date: Wed, 24 Dec 2025 12:33:57 -0500 Message-Id: <20251224173358.647691-3-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251224173358.647691-1-mathieu.desnoyers@efficios.com> References: <20251224173358.647691-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The cpu_bitmap flexible array now contains more than just the cpu_bitmap. In preparation for changing the static mm_struct definitions to cover for the additional space required, change the cpu_bitmap type from "unsigned long" to "char", require an unsigned long alignment of the flexible array, and rename the field from "cpu_bitmap" to "flexible_array". Introduce the MM_STRUCT_FLEXIBLE_ARRAY_INIT macro to statically initialize the flexible array. This covers the init_mm and efi_mm static definitions. This is a preparation step for fixing the missing mm_cid size for static mm_struct definitions. Signed-off-by: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Mark Brown Cc: stable@vger.kernel.org Cc: linux-mm@kvack.org Reviewed-by: Thomas Gleixner --- drivers/firmware/efi/efi.c | 2 +- include/linux/mm_types.h | 13 +++++++++---- mm/init-mm.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index a9070d00b833..3f5c2ae50024 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -73,10 +73,10 @@ struct mm_struct efi_mm =3D { MMAP_LOCK_INITIALIZER(efi_mm) .page_table_lock =3D __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), .mmlist =3D LIST_HEAD_INIT(efi_mm.mmlist), - .cpu_bitmap =3D { [BITS_TO_LONGS(NR_CPUS)] =3D 0}, #ifdef CONFIG_SCHED_MM_CID .mm_cid.lock =3D __RAW_SPIN_LOCK_UNLOCKED(efi_mm.mm_cid.lock), #endif + .flexible_array =3D MM_STRUCT_FLEXIBLE_ARRAY_INIT, }; =20 struct workqueue_struct *efi_rts_wq; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 42af2292951d..110b319a2ffb 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1329,7 +1329,7 @@ struct mm_struct { * The mm_cpumask needs to be at the end of mm_struct, because it * is dynamically sized based on nr_cpu_ids. */ - unsigned long cpu_bitmap[]; + char flexible_array[] __aligned(__alignof__(unsigned long)); }; =20 /* Copy value to the first system word of mm flags, non-atomically. */ @@ -1366,19 +1366,24 @@ static inline void __mm_flags_set_mask_bits_word(st= ruct mm_struct *mm, MT_FLAGS_USE_RCU) extern struct mm_struct init_mm; =20 +#define MM_STRUCT_FLEXIBLE_ARRAY_INIT \ +{ \ + [0 ... sizeof(cpumask_t)-1] =3D 0 \ +} + /* Pointer magic because the dynamic array size confuses some compilers. */ static inline void mm_init_cpumask(struct mm_struct *mm) { unsigned long cpu_bitmap =3D (unsigned long)mm; =20 - cpu_bitmap +=3D offsetof(struct mm_struct, cpu_bitmap); + cpu_bitmap +=3D offsetof(struct mm_struct, flexible_array); cpumask_clear((struct cpumask *)cpu_bitmap); } =20 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */ static inline cpumask_t *mm_cpumask(struct mm_struct *mm) { - return (struct cpumask *)&mm->cpu_bitmap; + return (struct cpumask *)&mm->flexible_array; } =20 #ifdef CONFIG_LRU_GEN @@ -1469,7 +1474,7 @@ static inline cpumask_t *mm_cpus_allowed(struct mm_st= ruct *mm) { unsigned long bitmap =3D (unsigned long)mm; =20 - bitmap +=3D offsetof(struct mm_struct, cpu_bitmap); + bitmap +=3D offsetof(struct mm_struct, flexible_array); /* Skip cpu_bitmap */ bitmap +=3D cpumask_size(); return (struct cpumask *)bitmap; diff --git a/mm/init-mm.c b/mm/init-mm.c index a514f8ce47e3..c5556bb9d5f0 100644 --- a/mm/init-mm.c +++ b/mm/init-mm.c @@ -47,7 +47,7 @@ struct mm_struct init_mm =3D { #ifdef CONFIG_SCHED_MM_CID .mm_cid.lock =3D __RAW_SPIN_LOCK_UNLOCKED(init_mm.mm_cid.lock), #endif - .cpu_bitmap =3D CPU_BITS_NONE, + .flexible_array =3D MM_STRUCT_FLEXIBLE_ARRAY_INIT, INIT_MM_CONTEXT(init_mm) }; =20 --=20 2.39.5 From nobody Sun Feb 8 09:12:52 2026 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.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 10691314D2F; Wed, 24 Dec 2025 17:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=158.69.130.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766597655; cv=none; b=hEZ0IXk+ygVgvuVtPs0tL5ydr91xtw+3I0g3XPGUxky/lrNOeg3WxqjREmOlAbGsXa+KTi2G3c4PEDWtmQglWtU4bVYEcTZGUenO7DmUCgnmwhrRa9Seqlm+gva8d6xZ9BYw+ZE9eIwhbxsl+wQJrFl1VhkF5Mvfrj0igO6P7o8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766597655; c=relaxed/simple; bh=atWssxs+RIcjWyqrHPYSzQAP5QOUdHyokABMAGKdIkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H1yv3I3IrfNiTSu11UIVq0CJTueY47KW37JV7MizIpYAQWFPNCjWmKz++m/CtF6VOBzssdG3gpHKIClkuX5Wk5oVeULx55QCrN3yZpZndwplVyK50hF3jOoOklHT1A5xvLnx3IfHWMSX5YWDLC0a2YgzJ5pR17r16q7kElHy4ms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=azpTgwXx; arc=none smtp.client-ip=158.69.130.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="azpTgwXx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1766597645; bh=WIh1XzVs83L7IUYypMXcMemNQQ0OLf+PJujjXTHlUNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=azpTgwXxj0eWzpifwpvE/easXXJA1SasvPI3MXVrTCE0gfqrkvb3denE9UoKHQKr4 WJU2h/pONKmiU8CDPPYQYKm6TwgFUAM1FiF5sKOsjaG3tFfXEoU5DbmfvP1dJL6TF3 Jwd+PyGrO2g2bLMnk1LuLnzXMFhGU/nYtLisiWHv8xuoSFDJQp7LM+Rh+KioSrvOmp W6XlG6TfMMe7eu6lL6ierMwvJ3wFhbWO9buO3LM1I62Oiei0+ytfkbuSgAhjweTUT3 BKdUdEgJ2lpleMXSeGKDxJQ+iplAWpL8ca5z87F12ZkpHcxsexTgQc7GMKloh484lM FcGFA3UfPh/uA== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4dbzWd5XcRzfHr; Wed, 24 Dec 2025 12:34:05 -0500 (EST) From: Mathieu Desnoyers To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Thomas Gleixner , stable@vger.kernel.org, linux-mm@kvack.org, Mark Brown Subject: [PATCH v1 3/3] mm: Take into account mm_cid size for mm_struct static definitions Date: Wed, 24 Dec 2025 12:33:58 -0500 Message-Id: <20251224173358.647691-4-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251224173358.647691-1-mathieu.desnoyers@efficios.com> References: <20251224173358.647691-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Both init_mm and efi_mm static definitions need to make room for the 2 mm_cid cpumasks. This fixes possible out-of-bounds accesses to init_mm and efi_mm. Add a space between # and define for the mm_alloc_cid() definition to make it consistent with the coding style used in the rest of this header file. Fixes: af7f588d8f73 ("sched: Introduce per-memory-map concurrency ID") Signed-off-by: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Mark Brown Cc: stable@vger.kernel.org Cc: linux-mm@kvack.org Reviewed-by: Thomas Gleixner --- include/linux/mm_types.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 110b319a2ffb..aa4639888f89 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1368,7 +1368,7 @@ extern struct mm_struct init_mm; =20 #define MM_STRUCT_FLEXIBLE_ARRAY_INIT \ { \ - [0 ... sizeof(cpumask_t)-1] =3D 0 \ + [0 ... sizeof(cpumask_t) + MM_CID_STATIC_SIZE - 1] =3D 0 \ } =20 /* Pointer magic because the dynamic array size confuses some compilers. */ @@ -1500,7 +1500,7 @@ static inline int mm_alloc_cid_noprof(struct mm_struc= t *mm, struct task_struct * mm_init_cid(mm, p); return 0; } -#define mm_alloc_cid(...) alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__)) +# define mm_alloc_cid(...) alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__)) =20 static inline void mm_destroy_cid(struct mm_struct *mm) { @@ -1514,6 +1514,8 @@ static inline unsigned int mm_cid_size(void) return cpumask_size() + bitmap_size(num_possible_cpus()); } =20 +/* Use 2 * NR_CPUS as worse case for static allocation. */ +# define MM_CID_STATIC_SIZE (2 * sizeof(cpumask_t)) #else /* CONFIG_SCHED_MM_CID */ static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p= ) { } static inline int mm_alloc_cid(struct mm_struct *mm, struct task_struct *p= ) { return 0; } @@ -1522,6 +1524,7 @@ static inline unsigned int mm_cid_size(void) { return 0; } +# define MM_CID_STATIC_SIZE 0 #endif /* CONFIG_SCHED_MM_CID */ =20 struct mmu_gather; --=20 2.39.5