From: Matthew Brost <matthew.brost@intel.com>
To: Oak Zeng <oak.zeng@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <thomas.hellstrom@intel.com>,
<brian.welty@intel.com>, <himal.prasad.ghimiray@intel.com>
Subject: Re: [PATCH 2/3] drm/xe: Introduce a helper to free sg table
Date: Wed, 3 Apr 2024 03:06:36 +0000 [thread overview]
Message-ID: <ZgzHvMem5GRl6wuJ@DUT025-TGLU.fm.intel.com> (raw)
In-Reply-To: <20240322035520.2382600-3-oak.zeng@intel.com>
On Thu, Mar 21, 2024 at 11:55:19PM -0400, Oak Zeng wrote:
> Introduce xe_userptr_free_sg helper to dma-unmap all
> addresses in userptr's sg table and free sg table.
>
> Signed-off-by: Oak Zeng <oak.zeng@intel.com>
> Suggested by: Matthew Brost <matthew.brost@intel.com>
> ---
> drivers/gpu/drm/xe/xe_hmm.c | 30 ++++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_hmm.h | 1 +
> 2 files changed, 31 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_hmm.c b/drivers/gpu/drm/xe/xe_hmm.c
> index 4011207630a5..427c6bc49949 100644
> --- a/drivers/gpu/drm/xe/xe_hmm.c
> +++ b/drivers/gpu/drm/xe/xe_hmm.c
> @@ -3,6 +3,7 @@
> * Copyright © 2024 Intel Corporation
> */
>
> +#include <linux/scatterlist.h>
> #include <linux/mmu_notifier.h>
> #include <linux/dma-mapping.h>
> #include <linux/memremap.h>
> @@ -107,6 +108,32 @@ static int xe_build_sg(struct xe_device *xe, struct hmm_range *range,
> return ret;
> }
>
> +/**
> + * xe_userptr_free_sg() - Free the scatter gather table of userptr
> + *
> + * @uvma: the userptr vma which hold the scatter gather table
> + *
> + * With function xe_userptr_populate_range, we allocate storage of
> + * the userptr sg table. This is a helper function to free this
> + * sg table, and dma unmap the address in the table.
> + */
> +void xe_userptr_free_sg(struct xe_userptr_vma *uvma)
See my comment about passing in xe_userptr_vma as an argument in the
previous patch, anyways can live with it.
But s/xe_userptr_free_sg/xe_hmm_userptr_free_sg?
Also I'd squash into the previous patch.
Otherwise LGMT.
Matt
> +{
> + struct xe_userptr *userptr = &uvma->userptr;
> + struct xe_vma *vma = &uvma->vma;
> + bool write = !xe_vma_read_only(vma);
> + struct xe_vm *vm = xe_vma_vm(vma);
> + struct xe_device *xe = vm->xe;
> + struct device *dev = xe->drm.dev;
> +
> + xe_assert(xe, userptr->sg);
> + dma_unmap_sgtable(dev, userptr->sg,
> + write ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE, 0);
> +
> + sg_free_table(userptr->sg);
> + userptr->sg = NULL;
> +}
> +
> /**
> * xe_userptr_populate_range() - Populate physical pages of a virtual
> * address range
> @@ -156,6 +183,9 @@ int xe_userptr_populate_range(struct xe_userptr_vma *uvma)
> if (notifier_seq == userptr->notifier_seq)
> return 0;
>
> + if (userptr->sg)
> + xe_userptr_free_sg(uvma);
> +
> npages = xe_npages_in_range(start, end);
> pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL);
> if (unlikely(!pfns))
> diff --git a/drivers/gpu/drm/xe/xe_hmm.h b/drivers/gpu/drm/xe/xe_hmm.h
> index 91686a751711..7bb49bbde5a4 100644
> --- a/drivers/gpu/drm/xe/xe_hmm.h
> +++ b/drivers/gpu/drm/xe/xe_hmm.h
> @@ -15,3 +15,4 @@ static inline int xe_userptr_populate_range(struct xe_userptr_vma *uvma)
> return -ENODEV;
> }
> #endif
> +void xe_userptr_free_sg(struct xe_userptr_vma *uvma);
> --
> 2.26.3
>
next prev parent reply other threads:[~2024-04-03 3:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 3:55 [PATCH 0/3] Use hmm_range_fault to populate user page Oak Zeng
2024-03-22 3:55 ` [PATCH 1/3] drm/xe: Introduce helper to populate userptr Oak Zeng
2024-04-03 3:03 ` Matthew Brost
2024-04-03 3:54 ` Zeng, Oak
2024-04-03 4:15 ` Matthew Brost
2024-04-03 4:43 ` Zeng, Oak
2024-03-22 3:55 ` [PATCH 2/3] drm/xe: Introduce a helper to free sg table Oak Zeng
2024-04-03 3:06 ` Matthew Brost [this message]
2024-03-22 3:55 ` [PATCH 3/3] drm/xe: Use hmm_range_fault to populate user pages Oak Zeng
2024-04-03 3:09 ` Matthew Brost
2024-03-22 4:51 ` ✓ CI.Patch_applied: success for Use hmm_range_fault to populate user page Patchwork
2024-03-22 4:52 ` ✗ CI.checkpatch: warning " Patchwork
2024-03-22 4:53 ` ✓ CI.KUnit: success " Patchwork
2024-03-22 5:03 ` ✓ CI.Build: " Patchwork
2024-03-22 5:06 ` ✓ CI.Hooks: " Patchwork
2024-03-22 5:07 ` ✓ CI.checksparse: " Patchwork
2024-03-22 5:35 ` ✓ CI.BAT: " Patchwork
2024-04-01 14:32 ` ✓ CI.Patch_applied: success for Use hmm_range_fault to populate user page (rev2) Patchwork
2024-04-01 14:32 ` ✗ CI.checkpatch: warning " Patchwork
2024-04-01 14:33 ` ✓ CI.KUnit: success " Patchwork
2024-04-01 14:44 ` ✓ CI.Build: " Patchwork
2024-04-01 14:47 ` ✓ CI.Hooks: " Patchwork
2024-04-01 14:48 ` ✓ CI.checksparse: " Patchwork
2024-04-01 15:20 ` ✓ CI.BAT: " Patchwork
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=ZgzHvMem5GRl6wuJ@DUT025-TGLU.fm.intel.com \
--to=matthew.brost@intel.com \
--cc=brian.welty@intel.com \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=oak.zeng@intel.com \
--cc=thomas.hellstrom@intel.com \
/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