Skip to content

Commit 19a17a9

Browse files
osharabiogabbay
authored andcommitted
habanalabs: fix VA range calculation
Current implementation is fixing the page size to PAGE_SIZE whereas the input page size may be different. Signed-off-by: Ohad Sharabi <[email protected]> Reviewed-by: Oded Gabbay <[email protected]> Signed-off-by: Oded Gabbay <[email protected]>
1 parent 5354a2a commit 19a17a9

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

drivers/misc/habanalabs/common/memory.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,24 +2508,20 @@ static int va_range_init(struct hl_device *hdev, struct hl_va_range **va_ranges,
25082508

25092509
/*
25102510
* PAGE_SIZE alignment
2511-
* it is the callers responsibility to align the addresses if the
2511+
* it is the caller's responsibility to align the addresses if the
25122512
* page size is not a power of 2
25132513
*/
25142514

25152515
if (is_power_of_2(page_size)) {
2516-
if (start & (PAGE_SIZE - 1)) {
2517-
start &= PAGE_MASK;
2518-
start += PAGE_SIZE;
2519-
}
2516+
start = round_up(start, page_size);
25202517

25212518
/*
25222519
* The end of the range is inclusive, hence we need to align it
25232520
* to the end of the last full page in the range. For example if
25242521
* end = 0x3ff5 with page size 0x1000, we need to align it to
2525-
* 0x2fff. The remainig 0xff5 bytes do not form a full page.
2522+
* 0x2fff. The remaining 0xff5 bytes do not form a full page.
25262523
*/
2527-
if ((end + 1) & (PAGE_SIZE - 1))
2528-
end = ((end + 1) & PAGE_MASK) - 1;
2524+
end = round_down(end + 1, page_size) - 1;
25292525
}
25302526

25312527
if (start >= end) {

0 commit comments

Comments
 (0)