All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] habanalabs: Fix virtual address access via debugfs for 2MB pages
@ 2019-06-03 11:25 Tomer Tayar
  2019-06-04 11:00 ` Oded Gabbay
  0 siblings, 1 reply; 2+ messages in thread
From: Tomer Tayar @ 2019-06-03 11:25 UTC (permalink / raw)
  To: oded.gabbay; +Cc: linux-kernel

The debugfs interface for accessing DRAM virtual addresses currently
uses the 12 LSBs of a virtual address as an offset.
However, it should use the 20 LSBs in case the device MMU page size is
2MB instead of 4KB.
This patch fixes the offset calculation to be based on the page size.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
---
 drivers/misc/habanalabs/debugfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/habanalabs/debugfs.c b/drivers/misc/habanalabs/debugfs.c
index 0ce5621c1324..ba418aaa404c 100644
--- a/drivers/misc/habanalabs/debugfs.c
+++ b/drivers/misc/habanalabs/debugfs.c
@@ -500,6 +500,7 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
 {
 	struct hl_ctx *ctx = hdev->user_ctx;
 	u64 hop_addr, hop_pte_addr, hop_pte;
+	u64 offset_mask = HOP4_MASK | OFFSET_MASK;
 	int rc = 0;
 
 	if (!ctx) {
@@ -542,12 +543,14 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
 			goto not_mapped;
 		hop_pte_addr = get_hop4_pte_addr(ctx, hop_addr, virt_addr);
 		hop_pte = hdev->asic_funcs->read_pte(hdev, hop_pte_addr);
+
+		offset_mask = OFFSET_MASK;
 	}
 
 	if (!(hop_pte & PAGE_PRESENT_MASK))
 		goto not_mapped;
 
-	*phys_addr = (hop_pte & PTE_PHYS_ADDR_MASK) | (virt_addr & OFFSET_MASK);
+	*phys_addr = (hop_pte & ~offset_mask) | (virt_addr & offset_mask);
 
 	goto out;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] habanalabs: Fix virtual address access via debugfs for 2MB pages
  2019-06-03 11:25 [PATCH] habanalabs: Fix virtual address access via debugfs for 2MB pages Tomer Tayar
@ 2019-06-04 11:00 ` Oded Gabbay
  0 siblings, 0 replies; 2+ messages in thread
From: Oded Gabbay @ 2019-06-04 11:00 UTC (permalink / raw)
  To: Tomer Tayar; +Cc: linux-kernel

On Mon, Jun 3, 2019 at 2:25 PM Tomer Tayar <ttayar@habana.ai> wrote:
>
> The debugfs interface for accessing DRAM virtual addresses currently
> uses the 12 LSBs of a virtual address as an offset.
> However, it should use the 20 LSBs in case the device MMU page size is
> 2MB instead of 4KB.
> This patch fixes the offset calculation to be based on the page size.
>
> Signed-off-by: Tomer Tayar <ttayar@habana.ai>
> ---
>  drivers/misc/habanalabs/debugfs.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/habanalabs/debugfs.c b/drivers/misc/habanalabs/debugfs.c
> index 0ce5621c1324..ba418aaa404c 100644
> --- a/drivers/misc/habanalabs/debugfs.c
> +++ b/drivers/misc/habanalabs/debugfs.c
> @@ -500,6 +500,7 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
>  {
>         struct hl_ctx *ctx = hdev->user_ctx;
>         u64 hop_addr, hop_pte_addr, hop_pte;
> +       u64 offset_mask = HOP4_MASK | OFFSET_MASK;
>         int rc = 0;
>
>         if (!ctx) {
> @@ -542,12 +543,14 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
>                         goto not_mapped;
>                 hop_pte_addr = get_hop4_pte_addr(ctx, hop_addr, virt_addr);
>                 hop_pte = hdev->asic_funcs->read_pte(hdev, hop_pte_addr);
> +
> +               offset_mask = OFFSET_MASK;
>         }
>
>         if (!(hop_pte & PAGE_PRESENT_MASK))
>                 goto not_mapped;
>
> -       *phys_addr = (hop_pte & PTE_PHYS_ADDR_MASK) | (virt_addr & OFFSET_MASK);
> +       *phys_addr = (hop_pte & ~offset_mask) | (virt_addr & offset_mask);
>
>         goto out;
>
> --
> 2.17.1
>
This patch is:
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
applied to -fixes

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-04 11:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 11:25 [PATCH] habanalabs: Fix virtual address access via debugfs for 2MB pages Tomer Tayar
2019-06-04 11:00 ` Oded Gabbay

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.