Commit 0f37510c authored by Ohad Sharabi's avatar Ohad Sharabi Committed by Oded Gabbay
Browse files

habanalabs: fix mask to obtain page offset



When converting virtual address to physical we need to add correct
offset to the physical page.

For this we need to use mask that include ALL bits of page offset.

Signed-off-by: default avatarOhad Sharabi <osharabi@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent 6a785e36
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -501,12 +501,20 @@ static void hl_mmu_pa_page_with_offset(struct hl_ctx *ctx, u64 virt_addr,

	if ((hops->range_type == HL_VA_RANGE_TYPE_DRAM) &&
			!is_power_of_2(prop->dram_page_size)) {
		u32 bit;
		unsigned long dram_page_size = prop->dram_page_size;
		u64 page_offset_mask;
		u64 phys_addr_mask;
		u32 bit;

		bit = __ffs64((u64)prop->dram_page_size);
		page_offset_mask = ((1ull << bit) - 1);
		/*
		 * find last set bit in page_size to cover all bits of page
		 * offset. note that 1 has to be added to bit index.
		 * note that the internal ulong variable is used to avoid
		 * alignment issue.
		 */
		bit = find_last_bit(&dram_page_size,
					sizeof(dram_page_size) * BITS_PER_BYTE) + 1;
		page_offset_mask = (BIT_ULL(bit) - 1);
		phys_addr_mask = ~page_offset_mask;
		*phys_addr = (tmp_phys_addr & phys_addr_mask) |
				(virt_addr & page_offset_mask);