From: Danilo Krummrich <dakr@redhat.com>
To: Timur Tabi <ttabi@nvidia.com>
Cc: David Airlie <airlied@gmail.com>,
bskeggs@nvidia.com, nouveau@lists.freedesktop.org
Subject: Re: [PATCH 1/2] [v2] drm/nouveau: retain device pointer in nvkm_gsp_mem object
Date: Mon, 17 Jun 2024 19:48:43 +0200 [thread overview]
Message-ID: <ZnB2-3UIAq-aTLpG@cassiopeiae> (raw)
In-Reply-To: <20240612235253.1624004-1-ttabi@nvidia.com>
On Wed, Jun 12, 2024 at 06:52:52PM -0500, Timur Tabi wrote:
> Store the struct device pointer used to allocate the DMA buffer in
> the nvkm_gsp_mem object. This allows nvkm_gsp_mem_dtor() to release
> the buffer without needing the nvkm_gsp. This is needed so that
> we can retain DMA buffers even after the nvkm_gsp object is deleted.
>
> Signed-off-by: Timur Tabi <ttabi@nvidia.com>
> ---
> v2: rebased to drm-misc-next
>
> .../gpu/drm/nouveau/include/nvkm/subdev/gsp.h | 1 +
> .../gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 36 ++++++++++---------
> 2 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
> index 9e6f39912368..a45a4ad843b9 100644
> --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
> +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
> @@ -9,6 +9,7 @@
> #define GSP_PAGE_SIZE BIT(GSP_PAGE_SHIFT)
>
> struct nvkm_gsp_mem {
> + struct device *dev;
> size_t size;
> void *data;
> dma_addr_t addr;
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
> index cf58f9da9139..bbab6d452aa2 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
> @@ -1000,7 +1000,7 @@ r535_gsp_rpc_get_gsp_static_info(struct nvkm_gsp *gsp)
> }
>
> static void
> -nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem)
> +nvkm_gsp_mem_dtor(struct nvkm_gsp_mem *mem)
> {
> if (mem->data) {
> /*
> @@ -1009,7 +1009,7 @@ nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem)
> */
> memset(mem->data, 0xFF, mem->size);
>
> - dma_free_coherent(gsp->subdev.device->dev, mem->size, mem->data, mem->addr);
> + dma_free_coherent(mem->dev, mem->size, mem->data, mem->addr);
> memset(mem, 0, sizeof(*mem));
> }
> }
> @@ -1017,11 +1017,13 @@ nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem)
> static int
> nvkm_gsp_mem_ctor(struct nvkm_gsp *gsp, size_t size, struct nvkm_gsp_mem *mem)
> {
> - mem->size = size;
> mem->data = dma_alloc_coherent(gsp->subdev.device->dev, size, &mem->addr, GFP_KERNEL);
> if (WARN_ON(!mem->data))
> return -ENOMEM;
>
> + mem->size = size;
> + mem->dev = gsp->subdev.device->dev;
If this can potentially out-live the drivers remove() callback, we have to take
a device reference here and drop it in nvkm_gsp_mem_dtor().
mem->dev = get_device(gsp->subdev.device->dev);
> +
> return 0;
> }
>
> @@ -1054,8 +1056,8 @@ r535_gsp_postinit(struct nvkm_gsp *gsp)
> nvkm_wr32(device, 0x110004, 0x00000040);
>
> /* Release the DMA buffers that were needed only for boot and init */
> - nvkm_gsp_mem_dtor(gsp, &gsp->boot.fw);
> - nvkm_gsp_mem_dtor(gsp, &gsp->libos);
> + nvkm_gsp_mem_dtor(&gsp->boot.fw);
> + nvkm_gsp_mem_dtor(&gsp->libos);
>
> return ret;
> }
> @@ -2234,8 +2236,8 @@ static void
> nvkm_gsp_radix3_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_radix3 *rx3)
> {
> nvkm_gsp_sg_free(gsp->subdev.device, &rx3->lvl2);
> - nvkm_gsp_mem_dtor(gsp, &rx3->lvl1);
> - nvkm_gsp_mem_dtor(gsp, &rx3->lvl0);
> + nvkm_gsp_mem_dtor(&rx3->lvl1);
> + nvkm_gsp_mem_dtor(&rx3->lvl0);
> }
>
> /**
> @@ -2323,9 +2325,9 @@ nvkm_gsp_radix3_sg(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size,
>
> if (ret) {
> lvl2_fail:
> - nvkm_gsp_mem_dtor(gsp, &rx3->lvl1);
> + nvkm_gsp_mem_dtor(&rx3->lvl1);
> lvl1_fail:
> - nvkm_gsp_mem_dtor(gsp, &rx3->lvl0);
> + nvkm_gsp_mem_dtor(&rx3->lvl0);
> }
>
> return ret;
> @@ -2417,7 +2419,7 @@ r535_gsp_init(struct nvkm_gsp *gsp)
>
> done:
> if (gsp->sr.meta.data) {
> - nvkm_gsp_mem_dtor(gsp, &gsp->sr.meta);
> + nvkm_gsp_mem_dtor(&gsp->sr.meta);
> nvkm_gsp_radix3_dtor(gsp, &gsp->sr.radix3);
> nvkm_gsp_sg_free(gsp->subdev.device, &gsp->sr.sgt);
> return ret;
> @@ -2498,7 +2500,7 @@ r535_gsp_dtor(struct nvkm_gsp *gsp)
> mutex_destroy(&gsp->client_id.mutex);
>
> nvkm_gsp_radix3_dtor(gsp, &gsp->radix3);
> - nvkm_gsp_mem_dtor(gsp, &gsp->sig);
> + nvkm_gsp_mem_dtor(&gsp->sig);
> nvkm_firmware_dtor(&gsp->fw);
>
> nvkm_falcon_fw_dtor(&gsp->booter.unload);
> @@ -2509,12 +2511,12 @@ r535_gsp_dtor(struct nvkm_gsp *gsp)
>
> r535_gsp_dtor_fws(gsp);
>
> - nvkm_gsp_mem_dtor(gsp, &gsp->rmargs);
> - nvkm_gsp_mem_dtor(gsp, &gsp->wpr_meta);
> - nvkm_gsp_mem_dtor(gsp, &gsp->shm.mem);
> - nvkm_gsp_mem_dtor(gsp, &gsp->loginit);
> - nvkm_gsp_mem_dtor(gsp, &gsp->logintr);
> - nvkm_gsp_mem_dtor(gsp, &gsp->logrm);
> + nvkm_gsp_mem_dtor(&gsp->rmargs);
> + nvkm_gsp_mem_dtor(&gsp->wpr_meta);
> + nvkm_gsp_mem_dtor(&gsp->shm.mem);
> + nvkm_gsp_mem_dtor(&gsp->loginit);
> + nvkm_gsp_mem_dtor(&gsp->logintr);
> + nvkm_gsp_mem_dtor(&gsp->logrm);
> }
>
> int
>
> base-commit: a13aaf157467e694a3824d81304106b58d4c20d6
> prerequisite-patch-id: 1428f57d0b137672ec09da08e76c5d3069b35432
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-06-17 17:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-12 23:52 [PATCH 1/2] [v2] drm/nouveau: retain device pointer in nvkm_gsp_mem object Timur Tabi
2024-06-12 23:52 ` [PATCH 2/2] [v5] drm/nouveau: expose GSP-RM logging buffers via debugfs Timur Tabi
2024-06-17 19:54 ` Danilo Krummrich
2024-06-18 21:02 ` Timur Tabi
2024-06-24 13:20 ` Danilo Krummrich
2024-06-17 17:48 ` Danilo Krummrich [this message]
2024-06-18 18:33 ` [PATCH 1/2] [v2] drm/nouveau: retain device pointer in nvkm_gsp_mem object Timur Tabi
-- strict thread matches above, loose matches on Subject: below --
2024-07-29 23:07 Timur Tabi
2024-07-29 23:09 ` Timur Tabi
2024-07-29 23:10 ` Danilo Krummrich
2024-08-02 19:05 Timur Tabi
2024-09-10 21:56 Timur Tabi
2024-10-30 20:29 Timur Tabi
2024-12-04 22:20 ` Danilo Krummrich
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=ZnB2-3UIAq-aTLpG@cassiopeiae \
--to=dakr@redhat.com \
--cc=airlied@gmail.com \
--cc=bskeggs@nvidia.com \
--cc=nouveau@lists.freedesktop.org \
--cc=ttabi@nvidia.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 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.