Skip to contentSkip to conversation

arm64/mm: avoid max_pinned_asids underflow

PATCH In review Reda CHERKAOUI 2 participants 2 messages Feb 19 – Feb 26 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 arm64/mm: avoid max_pinned_asids underflow

---
 arch/arm64/mm/context.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm64/mm/context.c +6 -6
index 74c1ece7db78..fdcee1127954 100644
@@ -386,11 +386,7 @@ static int asids_update_limit(void)
 		if (pinned_asid_map)
 			set_kpti_asid_bits(pinned_asid_map);
 	}
-	/*
-	 * Expect allocation after rollover to fail if we don't have at least
-	 * one more ASID than CPUs. ASID #0 is reserved for init_mm.
-	 */
-	WARN_ON(num_available_asids - 1 <= num_possible_cpus());
+
 	pr_info("ASID allocator initialised with %lu entries\n",
 		num_available_asids);
 
@@ -399,7 +395,11 @@ static int asids_update_limit(void)
 	 * even if all CPUs have a reserved ASID and the maximum number of ASIDs
 	 * are pinned, there still is at least one empty slot in the ASID map.
 	 */
-	max_pinned_asids = num_available_asids - num_possible_cpus() - 2;
+	if (WARN_ON(num_available_asids <= num_possible_cpus() + 2))
+		max_pinned_asids = 0;
+	else
+		max_pinned_asids = num_available_asids - num_possible_cpus() - 2;
+
 	return 0;
 }
 arch_initcall(asids_update_limit);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Reda CHERKAOUI

Please add a commit message.

Quoted 8 lines
 arch/arm64/mm/context.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm64/mm/context.c +0 -0
index 74c1ece7db78..fdcee1127954 100644

arch/arm64/mm/context.c static int asids_update_limit(void) · line 392

Quoted 7 lines
arch/arm64/mm/context.c +0 -4
@@ -386,11 +386,7 @@ static int asids_update_limit(void)
 		if (pinned_asid_map)
 			set_kpti_asid_bits(pinned_asid_map);
 	}
-	/*
-	 * Expect allocation after rollover to fail if we don't have at least
-	 * one more ASID than CPUs. ASID #0 is reserved for init_mm.
-	 */

Why remove this comment?

Quoted 6 lines
arch/arm64/mm/context.c +1 -1
-	WARN_ON(num_available_asids - 1 <= num_possible_cpus());
+
 	pr_info("ASID allocator initialised with %lu entries\n",
 		num_available_asids);
 

arch/arm64/mm/context.c static int asids_update_limit(void) · line 401

Quoted 8 lines
arch/arm64/mm/context.c +4 -1
@@ -399,7 +395,11 @@ static int asids_update_limit(void)
 	 * even if all CPUs have a reserved ASID and the maximum number of ASIDs
 	 * are pinned, there still is at least one empty slot in the ASID map.
 	 */
-	max_pinned_asids = num_available_asids - num_possible_cpus() - 2;
+	if (WARN_ON(num_available_asids <= num_possible_cpus() + 2))
+		max_pinned_asids = 0;
+	else
+		max_pinned_asids = num_available_asids - num_possible_cpus() - 2;

How about something like the below instead?

Will

--->8

arch/arm64/mm/context.c +11 -8
index b2ac06246327..94cffda52e4c 100644
@@ -380,20 +380,23 @@ static int asids_update_limit(void)
 		if (pinned_asid_map)
 			set_kpti_asid_bits(pinned_asid_map);
 	}
+
 	/*
 	 * Expect allocation after rollover to fail if we don't have at least
 	 * one more ASID than CPUs. ASID #0 is reserved for init_mm.
 	 */
-	WARN_ON(num_available_asids - 1 <= num_possible_cpus());
+	if (!WARN_ON(num_available_asids - 1 <= num_possible_cpus())) {
+		/*
+		 * There must always be an ASID available after rollover. Ensure
+		 * that, even if all CPUs have a reserved ASID and the maximum
+		 * number of ASIDs are pinned, there still is at least one empty
+		 * slot in the ASID map.
+		 */
+		max_pinned_asids = num_available_asids - num_possible_cpus() - 2;
+	}
+
 	pr_info("ASID allocator initialised with %lu entries\n",
 		num_available_asids);
-
-	/*
-	 * There must always be an ASID available after rollover. Ensure that,
-	 * even if all CPUs have a reserved ASID and the maximum number of ASIDs
-	 * are pinned, there still is at least one empty slot in the ASID map.
-	 */
-	max_pinned_asids = num_available_asids - num_possible_cpus() - 2;
 	return 0;
 }
 arch_initcall(asids_update_limit);