public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oded Gabbay <ogabbay@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Ohad Sharabi <osharabi@habana.ai>
Subject: [PATCH 8/8] habanalabs: fix VA range calculation
Date: Wed, 23 Nov 2022 16:58:01 +0200	[thread overview]
Message-ID: <20221123145801.542029-8-ogabbay@kernel.org> (raw)
In-Reply-To: <20221123145801.542029-1-ogabbay@kernel.org>

From: Ohad Sharabi <osharabi@habana.ai>

Current implementation is fixing the page size to PAGE_SIZE whereas the
input page size may be different.

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
---
 drivers/misc/habanalabs/common/memory.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/habanalabs/common/memory.c b/drivers/misc/habanalabs/common/memory.c
index 541e1b6a2176..7c5c18be294a 100644
--- a/drivers/misc/habanalabs/common/memory.c
+++ b/drivers/misc/habanalabs/common/memory.c
@@ -2508,24 +2508,20 @@ static int va_range_init(struct hl_device *hdev, struct hl_va_range **va_ranges,
 
 	/*
 	 * PAGE_SIZE alignment
-	 * it is the callers responsibility to align the addresses if the
+	 * it is the caller's responsibility to align the addresses if the
 	 * page size is not a power of 2
 	 */
 
 	if (is_power_of_2(page_size)) {
-		if (start & (PAGE_SIZE - 1)) {
-			start &= PAGE_MASK;
-			start += PAGE_SIZE;
-		}
+		start = round_up(start, page_size);
 
 		/*
 		 * The end of the range is inclusive, hence we need to align it
 		 * to the end of the last full page in the range. For example if
 		 * end = 0x3ff5 with page size 0x1000, we need to align it to
-		 * 0x2fff. The remainig 0xff5 bytes do not form a full page.
+		 * 0x2fff. The remaining 0xff5 bytes do not form a full page.
 		 */
-		if ((end + 1) & (PAGE_SIZE - 1))
-			end = ((end + 1) & PAGE_MASK) - 1;
+		end = round_down(end + 1, page_size) - 1;
 	}
 
 	if (start >= end) {
-- 
2.25.1


      parent reply	other threads:[~2022-11-23 14:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 14:57 [PATCH 1/8] habanalabs: fix rc when new CPUCP opcodes are not supported Oded Gabbay
2022-11-23 14:57 ` [PATCH 2/8] habanalabs: add RMWREG32_SHIFTED to set a val within a mask Oded Gabbay
2022-11-23 14:57 ` [PATCH 3/8] habanalabs: print context refcount value if hard reset fails Oded Gabbay
2022-11-23 14:57 ` [PATCH 4/8] habanalabs: don't put context in hl_encaps_handle_do_release_sob() Oded Gabbay
2022-11-23 14:57 ` [PATCH 5/8] habanalabs: clear non-released encapsulated signals Oded Gabbay
2022-11-23 14:57 ` [PATCH 6/8] habanalabs: make print of engines idle mask more readable Oded Gabbay
2022-11-23 14:58 ` [PATCH 7/8] habanalabs: fail driver load if EEPROM errors detected Oded Gabbay
2022-11-23 14:58 ` Oded Gabbay [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221123145801.542029-8-ogabbay@kernel.org \
    --to=ogabbay@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=osharabi@habana.ai \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox