Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Matthew Auld <matthew.auld@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	 <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 01/20] drm/drm_managed: try to improve the drmm DOC
Date: Mon, 13 May 2024 11:38:19 -0400	[thread overview]
Message-ID: <ZkIz6zLbwiXy8hEx@intel.com> (raw)
In-Reply-To: <20240510181212.264622-23-matthew.auld@intel.com>

On Fri, May 10, 2024 at 07:12:14PM +0100, Matthew Auld wrote:
> Hopefully make it clearer when to use devm vs drmm.
> 
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> ---
>  drivers/gpu/drm/drm_managed.c | 42 +++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c
> index 7646f67bda4e..20d705bbc0a3 100644
> --- a/drivers/gpu/drm/drm_managed.c
> +++ b/drivers/gpu/drm/drm_managed.c
> @@ -34,6 +34,48 @@
>   * during the lifetime of the driver, all the functions are fully concurrent
>   * safe. But it is recommended to use managed resources only for resources that
>   * change rarely, if ever, during the lifetime of the &drm_device instance.
> + *
> + * Note that the distinction between devm and drmm is important to get right.
> + * Consider some hotunplug scenarios, where it is valid for there to be multiple
> + * unplugged struct &drm_device instances each being kept alive by an open
> + * driver fd. The driver needs a clean separation between what needs to happen
> + * when the struct &device is removed and what needs to happen when a given
> + * struct &drm_device instance is released, as well as in some cases a more
> + * finer grained marking of critical sections that require hardware interaction.
> + * See below.
> + *
> + * devm
> + * ~~~~
> + * In general use devm for cleaning up anything hardware related. So removing
> + * pci mmaps, releasing interrupt handlers, basically anything hw related.  The
                                                                              ^
Extra space.

> + * devm release actions are called when the struct &device is removed, shortly
> + * after calling into the drivers struct &pci_driver.remove() callback, if this
> + * is a pci device.
> + *
> + * devm can be thought of as an alternative to putting all the hw related

nit: perhaps s/thought/seen ?

> + * cleanup directly in the struct &pci_driver.remove() callback, where the
> + * correct ordering of the unwind steps needs to be manually done in the error
> + * path of the struct &pci_driver.probe() and again on the remove side.  With
> + * devm this is all done automatically.
> + *
> + * drmm
> + * ~~~~
> + * In general use this for cleaning up anything software related. So data
> + * structures and the like which are tied to the lifetime of a particular struct
> + * &drm_device instance.
> + *
> + * drmm can be thought of as an alternative to putting all the software related

nit: perhaps s/thought/seen ?

> + * cleanup directly in the struct &drm_driver.release() callback, where again
> + * the correct ordering of the unwind steps needs to be done manually. As with
> + * devm this is instead done automatically.
> + *
> + * Sometimes there is no clean separation between software and hardware, which
> + * is where drm_dev_enter() comes in. For example, a driver might have some
> + * state tied to a struct &drm_device instance, for which the same cleanup path
> + * is called for both a plugged and unplugged device, and the cleanup itself
> + * might require talking to the device if it's still attached to this particular
> + * struct &drm_device. For that we instead mark the device sections.  See
> + * drm_dev_enter(), drm_dev_exit() and drm_dev_unplug().

perhaps open up a bit more here?

anyway, everything looks good to me.

Sima, thoughts?

>   */
>  
>  struct drmres_node {
> -- 
> 2.45.0
> 

  parent reply	other threads:[~2024-05-13 15:38 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-10 18:12 [PATCH 00/20] core_hotunplug improvements Matthew Auld
2024-05-10 18:12 ` [PATCH 01/20] drm/drm_managed: try to improve the drmm DOC Matthew Auld
2024-05-13  7:06   ` Andrzej Hajda
2024-05-13 15:38   ` Rodrigo Vivi [this message]
2024-05-10 18:12 ` [PATCH 02/20] drm/amdgpu: don't trample pdev drvdata Matthew Auld
2024-05-13 11:54   ` Christian König
2024-05-10 18:12 ` [PATCH 03/20] drm/xe/pci: remove broken driver_release Matthew Auld
2024-05-13  7:14   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 04/20] drm/xe: covert sysfs over to devm Matthew Auld
2024-05-10 18:12 ` [PATCH 05/20] drm/xe/ggtt: use drm_dev_enter to mark device section Matthew Auld
2024-05-13  7:16   ` Andrzej Hajda
2024-05-13 19:34   ` Randhawa, Jagmeet
2024-05-10 18:12 ` [PATCH 06/20] drm/xe/guc: move guc_fini over to devm Matthew Auld
2024-05-10 18:12 ` [PATCH 07/20] drm/xe/guc: s/guc_fini/guc_fini_hw/ Matthew Auld
2024-05-13  7:30   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 08/20] drm/xe/guc_pc: move pc_fini to devm Matthew Auld
2024-05-10 18:12 ` [PATCH 09/20] drm/xe/guc_pc: s/pc_fini/pc_fini_hw/ Matthew Auld
2024-05-11  9:19   ` kernel test robot
2024-05-13  7:37   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 10/20] drm/xe/irq: move irq_uninstall over to devm Matthew Auld
2024-05-10 18:12 ` [PATCH 11/20] drm/xe/device: move flr " Matthew Auld
2024-05-10 18:12 ` [PATCH 12/20] drm/xe/device: move xe_device_sanitize over " Matthew Auld
2024-05-10 18:12 ` [PATCH 13/20] drm/xe/coredump: move " Matthew Auld
2024-05-13  7:38   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 14/20] drm/xe/gt: break out gt_fini into sw vs hw state Matthew Auld
2024-05-13  7:50   ` Andrzej Hajda
2024-05-13  8:37     ` Matthew Auld
2024-05-13  9:19       ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 15/20] drm/xe: make gt_remove use devm Matthew Auld
2024-05-13  7:58   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 16/20] drm/xe/mmio: move mmio_fini over to devm Matthew Auld
2024-05-13  8:00   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 17/20] drm/xe: reset mmio mappings with devm Matthew Auld
2024-05-13  8:12   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 18/20] drm/xe/display: move display fini stuff to devm Matthew Auld
2024-05-13  8:13   ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 19/20] drm/xe/display: stop calling domains_driver_remove twice Matthew Auld
2024-05-13  8:19   ` Andrzej Hajda
2024-05-13  8:27     ` Matthew Auld
2024-05-13  9:17       ` Andrzej Hajda
2024-05-10 18:12 ` [PATCH 20/20] drm/xe/display: move device_remove over to drmm Matthew Auld
2024-05-11 10:33   ` kernel test robot
2024-05-11 10:43   ` kernel test robot
2024-05-13  8:22   ` Andrzej Hajda
2024-05-10 18:17 ` ✓ CI.Patch_applied: success for core_hotunplug improvements Patchwork
2024-05-10 18:18 ` ✗ CI.checkpatch: warning " Patchwork
2024-05-10 18:18 ` ✗ CI.KUnit: failure " 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=ZkIz6zLbwiXy8hEx@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@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