From: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>,
<intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v2 2/4] drm/xe: Add ref counting for xe_file
Date: Thu, 18 Jul 2024 11:57:50 -0700 [thread overview]
Message-ID: <ZpllrlkHgzUsnFOH@orsosgc001> (raw)
In-Reply-To: <lp4tdx4qyguivat3q26d7yut3nxveqeakfnc4d5epe7lklmma3@uhs6eqhizoqi>
On Thu, Jul 18, 2024 at 08:01:14AM -0500, Lucas De Marchi wrote:
>On Tue, Jul 09, 2024 at 08:41:49PM GMT, Matthew Brost wrote:
>>On Mon, Jul 08, 2024 at 05:28:33PM -0700, Umesh Nerlige Ramappa wrote:
>>>Add ref counting for xe_file.
>>>
>>>v2:
>>>- Add kernel doc for exported functions (Matt)
>>>- Instead of xe_file_destroy, export the get/put helpers (Lucas)
>>
>>Won't get into this bikeshed here.
>
>in the previous version I also pointed at other alternatives that would
>allow the inlining you were talking about. Anyway, as we said we may
>want to make the pattern uniform across the driver later
>
>>
>>>
>>>Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
>>>---
>>> drivers/gpu/drm/xe/xe_device.c | 31 ++++++++++++++++++++++++++--
>>> drivers/gpu/drm/xe/xe_device.h | 3 +++
>>> drivers/gpu/drm/xe/xe_device_types.h | 3 +++
>>> 3 files changed, 35 insertions(+), 2 deletions(-)
>>>
>>>diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
>>>index c5464ad5d908..61dc0a37a4d0 100644
>>>--- a/drivers/gpu/drm/xe/xe_device.c
>>>+++ b/drivers/gpu/drm/xe/xe_device.c
>>>@@ -90,11 +90,14 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
>>> spin_unlock(&xe->clients.lock);
>>>
>>> file->driver_priv = xef;
>>>+ kref_init(&xef->refcount);
>>>+
>>> return 0;
>>> }
>>>
>>>-static void xe_file_destroy(struct xe_file *xef)
>>>+static void xe_file_destroy(struct kref *ref)
>>> {
>>>+ struct xe_file *xef = container_of(ref, struct xe_file, refcount);
>>> struct xe_device *xe = xef->xe;
>>>
>>> xa_destroy(&xef->exec_queue.xa);
>>>@@ -110,6 +113,30 @@ static void xe_file_destroy(struct xe_file *xef)
>>> kfree(xef);
>>> }
>>>
>>>+/**
>>>+ * xe_file_get: Take a reference to the xe file object
>>
>>s/xe_file_get/xe_file_get()
>>
>>>+ * @xef: Pointer to the xe file
>>>+ *
>>>+ * Anyone making a copy of xef must take a reference to the xe file
>>
>>s/'Anyone making a copy'/'Anyone with a pointer'
>>
>>>+ * object using this call.
>>
>>
>>Returns: xe file pointer
>>
>>>+ */
>>>+struct xe_file *xe_file_get(struct xe_file *xef)
>>>+{
>>>+ kref_get(&xef->refcount);
>>>+ return xef;
>>>+}
>>>+
>>>+/**
>>>+ * xe_file_put: Drop a reference to the xe file object
>>
>>s/xe_file_put/xe_file_put()
>>
>>With the nits fixed:
>>Reviewed-by: Matthew Brost <matthew.brost@intel.com>
>
>agreed with the comments, but the kernel-doc ones don't appear
>correct... we document the functions like
>
>/**
> * xe_file_put - Drop a reference to the xe file object
> * @ .... arguments
> *
> * ... additional doc
> *
> * Returns: ...
> */
Again, this is not consistent across Xe. I see some files following what
Lucas mentioned and others following this link (like Matt's suggestion):
https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation
I will follow the format in the link above and hope that we standardize
that across Xe.
Regards,
Umesh
>
>Lucas De Marchi
>
>>
>>>+ * @xef: Pointer to the xe file
>>>+ *
>>>+ * Used to drop reference to the xef object
>>>+ */
>>>+void xe_file_put(struct xe_file *xef)
>>>+{
>>>+ kref_put(&xef->refcount, xe_file_destroy);
>>>+}
>>>+
>>> static void xe_file_close(struct drm_device *dev, struct drm_file *file)
>>> {
>>> struct xe_file *xef = file->driver_priv;
>>>@@ -132,7 +159,7 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
>>> xe_vm_close_and_put(vm);
>>> mutex_unlock(&xef->vm.lock);
>>>
>>>- xe_file_destroy(xef);
>>>+ xe_file_put(xef);
>>> }
>>>
>>> static const struct drm_ioctl_desc xe_ioctls[] = {
>>>diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h
>>>index 0a2a3e7fd402..533ccfb2567a 100644
>>>--- a/drivers/gpu/drm/xe/xe_device.h
>>>+++ b/drivers/gpu/drm/xe/xe_device.h
>>>@@ -171,4 +171,7 @@ static inline bool xe_device_wedged(struct xe_device *xe)
>>>
>>> void xe_device_declare_wedged(struct xe_device *xe);
>>>
>>>+struct xe_file *xe_file_get(struct xe_file *xef);
>>>+void xe_file_put(struct xe_file *xef);
>>>+
>>> #endif
>>>diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
>>>index f0cf9020e463..70115fb8d806 100644
>>>--- a/drivers/gpu/drm/xe/xe_device_types.h
>>>+++ b/drivers/gpu/drm/xe/xe_device_types.h
>>>@@ -578,6 +578,9 @@ struct xe_file {
>>>
>>> /** @client: drm client */
>>> struct xe_drm_client *client;
>>>+
>>>+ /** @refcount: ref count of this xe file */
>>>+ struct kref refcount;
>>> };
>>>
>>> #endif
>>>--
>>>2.38.1
>>>
next prev parent reply other threads:[~2024-07-18 18:58 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 0:28 [PATCH v2 0/4] Have xe_vm and xe_exec_queue take references to xef Umesh Nerlige Ramappa
2024-07-09 0:28 ` [PATCH v2 1/4] drm/xe: Move part of xe_file cleanup to a helper Umesh Nerlige Ramappa
2024-07-09 0:37 ` Matthew Brost
2024-07-18 12:53 ` Lucas De Marchi
2024-07-09 0:28 ` [PATCH v2 2/4] drm/xe: Add ref counting for xe_file Umesh Nerlige Ramappa
2024-07-09 20:41 ` Matthew Brost
2024-07-18 13:01 ` Lucas De Marchi
2024-07-18 18:57 ` Umesh Nerlige Ramappa [this message]
2024-07-18 19:24 ` Lucas De Marchi
2024-07-09 0:28 ` [PATCH v2 3/4] drm/xe: Take a ref to xe file when user creates a VM Umesh Nerlige Ramappa
2024-07-18 13:01 ` Lucas De Marchi
2024-07-09 0:28 ` [PATCH v2 4/4] drm/xe: Fix use after free when client stats are captured Umesh Nerlige Ramappa
2024-07-09 20:46 ` Matthew Brost
2024-07-18 13:35 ` Lucas De Marchi
2024-07-09 0:33 ` ✓ CI.Patch_applied: success for Have xe_vm and xe_exec_queue take references to xef (rev2) Patchwork
2024-07-09 0:33 ` ✓ CI.checkpatch: " Patchwork
2024-07-09 0:34 ` ✓ CI.KUnit: " Patchwork
2024-07-09 0:46 ` ✓ CI.Build: " Patchwork
2024-07-09 0:49 ` ✓ CI.Hooks: " Patchwork
2024-07-09 0:50 ` ✓ CI.checksparse: " Patchwork
2024-07-09 1:04 ` ✓ CI.BAT: " Patchwork
2024-07-09 4:21 ` ✓ CI.FULL: " 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=ZpllrlkHgzUsnFOH@orsosgc001 \
--to=umesh.nerlige.ramappa@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=lucas.demarchi@intel.com \
--cc=matthew.brost@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