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

Message ID 20231103142650.108394-1-michael.roth@amd.com
State New
Headers
Series efi/unaccepted: Fix off-by-one when checking for overlapping ranges |

Commit Message

Michael Roth Nov. 3, 2023, 2:26 p.m. UTC
  When a thread needs to accept memory it will scan the accepting_list
to see if any ranges already being processed by other threads overlap
with its range. Due to an off-by-one in the range comparisons, a thread
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")
Link: https://lore.kernel.org/linux-mm/20231101004523.vseyi5bezgfaht5i@amd.com/T/#me2eceb9906fcae5fe958b3fe88e41f920f8335b6
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
 drivers/firmware/efi/unaccepted_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Kirill A. Shutemov Nov. 3, 2023, 2:53 p.m. UTC | #1
On Fri, Nov 03, 2023 at 09:26:50AM -0500, Michael Roth wrote:
> When a thread needs to accept memory it will scan the accepting_list
> to see if any ranges already being processed by other threads overlap
> with its range. Due to an off-by-one in the range comparisons, a thread
> might falsely determine that an overlapping range is being accepted,
> leading to an unnecessary delay before it begins processing the range.

Maybe s/thread/task/g ?

> 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")
> Link: https://lore.kernel.org/linux-mm/20231101004523.vseyi5bezgfaht5i@amd.com/T/#me2eceb9906fcae5fe958b3fe88e41f920f8335b6
> Signed-off-by: Michael Roth <michael.roth@amd.com>

Otherwise, looks good:

Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>
  
Michael Roth Nov. 3, 2023, 3:15 p.m. UTC | #2
On Fri, Nov 03, 2023 at 05:53:53PM +0300, Kirill A . Shutemov wrote:
> On Fri, Nov 03, 2023 at 09:26:50AM -0500, Michael Roth wrote:
> > When a thread needs to accept memory it will scan the accepting_list
> > to see if any ranges already being processed by other threads overlap
> > with its range. Due to an off-by-one in the range comparisons, a thread
> > might falsely determine that an overlapping range is being accepted,
> > leading to an unnecessary delay before it begins processing the range.
> 
> Maybe s/thread/task/g ?
> 
> > 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")
> > Link: https://lore.kernel.org/linux-mm/20231101004523.vseyi5bezgfaht5i@amd.com/T/#me2eceb9906fcae5fe958b3fe88e41f920f8335b6
> > Signed-off-by: Michael Roth <michael.roth@amd.com>
> 
> Otherwise, looks good:
> 
> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

Thanks! Sending a v2 with suggested changes.

-Mike

> > 
> 
> -- 
>   Kiryl Shutsemau / Kirill A. Shutemov
  

Patch

diff --git a/drivers/firmware/efi/unaccepted_memory.c b/drivers/firmware/efi/unaccepted_memory.c
index 135278ddaf62..79fb687bb90f 100644
--- a/drivers/firmware/efi/unaccepted_memory.c
+++ b/drivers/firmware/efi/unaccepted_memory.c
@@ -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;