Skip to contentSkip to conversation

efi/unaccepted: Fix off-by-one when checking for overlapping ranges

PATCH In review Michael Roth 3 participants 5 messages Nov 3, 2023 – Nov 28, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi/unaccepted: Fix off-by-one when checking for overlapping ranges

When a task needs to accept memory it will scan the accepting_list to see if any ranges already being processed by other tasks overlap with its range. Due to an off-by-one in the range comparisons, a task might falsely determine that an overlapping range is being accepted, leading to an unnecessary delay before it begins processing the range.

Fix the off-by-one in the range comparison to prevent this and slightly improve performance.

Fixes 50e782a86c98 ("efi/unaccepted: Fix soft lockups caused by parallel memory acceptance")

---
v2:
* Improve commit message terminology (Kirill)

---
 drivers/firmware/efi/unaccepted_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/unaccepted_memory.c +1 -1
index 135278ddaf62..79fb687bb90f 100644
@@ -100,7 +100,7 @@ void accept_memory(phys_addr_t start, phys_addr_t end)
 	 * overlap on physical address level.
 	 */
 	list_for_each_entry(entry, &accepting_list, list) {
-		if (entry->end < range.start)
+		if (entry->end <= range.start)
 			continue;
 		if (entry->start >= range.end)
 			continue;
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#1 lore raw
Quoted 6 lines · Michael Roth

When a task needs to accept memory it will scan the accepting_list to see if any ranges already being processed by other tasks overlap with its range. Due to an off-by-one in the range comparisons, a task might falsely determine that an overlapping range is being accepted, leading to an unnecessary delay before it begins processing the range.

Quoted 7 lines

Fix the off-by-one in the range comparison to prevent this and slightly improve performance.

Fixes 50e782a86c98 ("efi/unaccepted: Fix soft lockups caused by parallel memory acceptance")

More justification for introducing a common ranges_overlap() helper somewhere :)

Quoted 20 lines

---
v2:
* Improve commit message terminology (Kirill)

---
 drivers/firmware/efi/unaccepted_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/unaccepted_memory.c +1 -1
index 135278ddaf62..79fb687bb90f 100644
@@ -100,7 +100,7 @@ void accept_memory(phys_addr_t start, phys_addr_t end)
 	 * overlap on physical address level.
 	 */
 	list_for_each_entry(entry, &accepting_list, list) {
-		if (entry->end < range.start)
+		if (entry->end <= range.start)
 			continue;
 		if (entry->start >= range.end)
 			continue;
maintainer
#2 lore raw
Quoted 11 lines · Vlastimil Babka
Quoted 9 lines · Michael Roth

When a task needs to accept memory it will scan the accepting_list to see if any ranges already being processed by other tasks overlap with its range. Due to an off-by-one in the range comparisons, a task might falsely determine that an overlapping range is being accepted, leading to an unnecessary delay before it begins processing the range.

Fix the off-by-one in the range comparison to prevent this and slightly improve performance.

Quoted 9 lines
Quoted 4 lines
Fixes 50e782a86c98 ("efi/unaccepted: Fix soft lockups caused by parallel memory acceptance")

More justification for introducing a common ranges_overlap() helper somewhere :)

Thanks, I'll take this as a fix.

Quoted 21 lines
Quoted 20 lines

---
v2:
* Improve commit message terminology (Kirill)

---
 drivers/firmware/efi/unaccepted_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/unaccepted_memory.c +1 -1
index 135278ddaf62..79fb687bb90f 100644
@@ -100,7 +100,7 @@ void accept_memory(phys_addr_t start, phys_addr_t end)
       * overlap on physical address level.
       */
      list_for_each_entry(entry, &accepting_list, list) {
-             if (entry->end < range.start)
+             if (entry->end <= range.start)
                      continue;
              if (entry->start >= range.end)
                      continue;
#3 lore raw
Quoted 17 lines · Ard Biesheuvel
Quoted 16 lines · Vlastimil Babka
Quoted 13 lines · Michael Roth

When a task needs to accept memory it will scan the accepting_list to see if any ranges already being processed by other tasks overlap with its range. Due to an off-by-one in the range comparisons, a task might falsely determine that an overlapping range is being accepted, leading to an unnecessary delay before it begins processing the range.

Fix the off-by-one in the range comparison to prevent this and slightly improve performance.

Fixes 50e782a86c98 ("efi/unaccepted: Fix soft lockups caused by parallel memory acceptance")
Quoted 6 lines
Quoted 4 lines

More justification for introducing a common ranges_overlap() helper somewhere :)

Thanks, I'll take this as a fix.

Ping, can't see it in mainline nor -next?

Quoted 23 lines
Quoted 22 lines
Quoted 21 lines

---
v2:
* Improve commit message terminology (Kirill)

---
 drivers/firmware/efi/unaccepted_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/unaccepted_memory.c +1 -1
index 135278ddaf62..79fb687bb90f 100644
@@ -100,7 +100,7 @@ void accept_memory(phys_addr_t start, phys_addr_t end)
       * overlap on physical address level.
       */
      list_for_each_entry(entry, &accepting_list, list) {
-             if (entry->end < range.start)
+             if (entry->end <= range.start)
                      continue;
              if (entry->start >= range.end)
                      continue;
maintainer
#4 lore raw
Quoted 19 lines · Vlastimil Babka
Quoted 17 lines · Ard Biesheuvel
Quoted 16 lines · Vlastimil Babka
Quoted 13 lines · Michael Roth

When a task needs to accept memory it will scan the accepting_list to see if any ranges already being processed by other tasks overlap with its range. Due to an off-by-one in the range comparisons, a task might falsely determine that an overlapping range is being accepted, leading to an unnecessary delay before it begins processing the range.

Fix the off-by-one in the range comparison to prevent this and slightly improve performance.

Fixes 50e782a86c98 ("efi/unaccepted: Fix soft lockups caused by parallel memory acceptance")
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

More justification for introducing a common ranges_overlap() helper somewhere :)

Thanks, I'll take this as a fix.

Ping, can't see it in mainline nor -next?

Apologies - queued up now.