mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sui Jingfeng <sui.jingfeng@linux.dev>
To: Lucas Stach <l.stach@pengutronix.de>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>,
	Russell King <linux+etnaviv@armlinux.org.uk>,
	dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v15 11/19] drm/etnaviv: Add etnaviv_gem_obj_remove() helper
Date: Wed, 2 Oct 2024 02:22:44 +0800	[thread overview]
Message-ID: <1779a56a-8735-4c65-a2fd-1e56ae6064b0@linux.dev> (raw)
In-Reply-To: <45b8eb9a0a2b91d85f9dd6b7e66a1796398fa27c.camel@pengutronix.de>

Hi,

On 2024/10/1 22:21, Lucas Stach wrote:
> Am Sonntag, dem 08.09.2024 um 17:43 +0800 schrieb Sui Jingfeng:
>> Which is corresonding to the etnaviv_gem_obj_add()
>>
> While symmetry is nice,


Thanks a lot for understanding and review my patch.


> it's still not really symmetric,

patch 0016 will try try to make it symmetric.
It will do this uniformly for all etnaviv GEM buffer objects.


> as this
> function isn't exported into the PRIME parts of the driver like
> etnaviv_gem_obj_add().

Yes, exactly.

> Given that I don't really see how this patch
> improves code legibility.

When the reference counter of a GEM buffer object decrease to 0,
the drm_gem_object_free() will be get called. which in turn,
etnaviv_gem_free_object() will get called.

The etnaviv_gem_free_object() will remove the GEM BO node
from the 'priv->gem_list' without checking if it has been
added into the list.

The data field of the struct etnaviv_gem_object::gem_node
will be all ZERO under such a case.

When drm/etnaviv import a shared buffer from an another driver.
etnaviv_gem_prime_import_sg_table() will be get called. But it
could fails before the "etnaviv_gem_obj_add(dev, &etnaviv_obj->base)"
get executed. The fails might either due to out of memory or
drm_prime_sg_to_page_array() failed.


Those fails will lead to NULL pointer de-reference, as we will
use uninitialized data member(say the 'gem_node') of an GEM
buffer object.

This is also the reason why we want to add it into the
etnaviv_drm_private::gem_list immediately after an etnaviv
GEM buffer object is successfully created.

> Regards,
> Lucas
>
>> Signed-off-by: Sui Jingfeng <sui.jingfeng@linux.dev>
>> ---
>>   drivers/gpu/drm/etnaviv/etnaviv_gem.c | 17 +++++++++++++----
>>   1 file changed, 13 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
>> index 39cfece67b90..3732288ff530 100644
>> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
>> @@ -19,6 +19,8 @@
>>   static struct lock_class_key etnaviv_shm_lock_class;
>>   static struct lock_class_key etnaviv_userptr_lock_class;
>>   
>> +static void etnaviv_gem_obj_remove(struct drm_gem_object *obj);
>> +
>>   static void etnaviv_gem_scatter_map(struct etnaviv_gem_object *etnaviv_obj)
>>   {
>>   	struct drm_device *dev = etnaviv_obj->base.dev;
>> @@ -555,15 +557,12 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj)
>>   {
>>   	struct drm_device *drm = obj->dev;
>>   	struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
>> -	struct etnaviv_drm_private *priv = obj->dev->dev_private;
>>   	struct etnaviv_vram_mapping *mapping, *tmp;
>>   
>>   	/* object should not be active */
>>   	drm_WARN_ON(drm, is_active(etnaviv_obj));
>>   
>> -	mutex_lock(&priv->gem_lock);
>> -	list_del(&etnaviv_obj->gem_node);
>> -	mutex_unlock(&priv->gem_lock);
>> +	etnaviv_gem_obj_remove(obj);
>>   
>>   	list_for_each_entry_safe(mapping, tmp, &etnaviv_obj->vram_list,
>>   				 obj_node) {
>> @@ -595,6 +594,16 @@ void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj)
>>   	mutex_unlock(&priv->gem_lock);
>>   }
>>   
>> +static void etnaviv_gem_obj_remove(struct drm_gem_object *obj)
>> +{
>> +	struct etnaviv_drm_private *priv = to_etnaviv_priv(obj->dev);
>> +	struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
>> +
>> +	mutex_lock(&priv->gem_lock);
>> +	list_del(&etnaviv_obj->gem_node);
>> +	mutex_unlock(&priv->gem_lock);
>> +}
>> +
>>   static const struct vm_operations_struct vm_ops = {
>>   	.fault = etnaviv_gem_fault,
>>   	.open = drm_gem_vm_open,

-- 
Best regards,
Sui


  reply	other threads:[~2024-10-01 18:23 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-08  9:43 [PATCH v15 00/19] drm/etnaviv: Add driver wrapper for vivante GPUs attached on PCI(e) device Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 01/19] drm/etnaviv: Implement drm_gem_object_funcs::print_info() Sui Jingfeng
2024-10-01 13:04   ` Lucas Stach
2024-11-09  7:23     ` Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 02/19] drm/etnaviv: Export drm_gem_print_info() and use it Sui Jingfeng
2024-10-01 13:10   ` Lucas Stach
2024-09-08  9:43 ` [PATCH v15 03/19] drm/etnaviv: Implement drm_gem_object_funcs::vunmap() Sui Jingfeng
2024-10-01 13:34   ` Lucas Stach
2024-09-08  9:43 ` [PATCH v15 04/19] drm/etnaviv: Make etnaviv_gem_prime_vmap() a static function Sui Jingfeng
2024-10-01 13:40   ` Lucas Stach
2024-10-01 14:05     ` Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 05/19] drm/etnaviv: Add contructor and destructor for etnaviv_gem_get_mapping structure Sui Jingfeng
2024-10-01 13:51   ` Lucas Stach
2024-09-08  9:43 ` [PATCH v15 06/19] drm/etnaviv: Prefer drm_device based drm_WARN_ON() over regular WARN_ON() Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 07/19] drm/etnaviv: Add a dedicated helper function to get various clocks Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 08/19] drm/etnaviv: Fix wrong caching mode being used for non writecombine buffers Sui Jingfeng
2024-10-01 13:58   ` Lucas Stach
2024-09-08  9:43 ` [PATCH v15 09/19] drm/etnaviv: Add constructor and destructor for the etnaviv_drm_private structure Sui Jingfeng
2024-10-01 14:07   ` Lucas Stach
2024-09-08  9:43 ` [PATCH v15 10/19] drm/etnaviv: Embed struct drm_device into struct etnaviv_drm_private Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 11/19] drm/etnaviv: Add etnaviv_gem_obj_remove() helper Sui Jingfeng
2024-10-01 14:21   ` Lucas Stach
2024-10-01 18:22     ` Sui Jingfeng [this message]
2024-09-08  9:43 ` [PATCH v15 12/19] drm/etnaviv: Add support for cached coherent caching mode Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 13/19] drm/etnaviv: Add support for vivante GPU cores attached via PCIe device Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 14/19] drm/etnaviv: Add PCIe IP setup code Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 15/19] drm/etnaviv: Make more use of the etnaviv_gem_new_private() function Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 16/19] drm/etnaviv: Call etnaviv_gem_obj_add() in ernaviv_gem_new_private() Sui Jingfeng
2024-10-01 14:39   ` Lucas Stach
2024-10-01 18:52     ` Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 17/19] drm/etnaviv: Support to manage dedicated VRAM base on drm_mm Sui Jingfeng
2024-09-08  9:43 ` [PATCH v15 18/19] drm/etnaviv: Allow userspace specify the domain of etnaviv GEM buffer object Sui Jingfeng
2024-10-01 14:51   ` Lucas Stach
2024-09-08  9:43 ` [PATCH v15 19/19] drm/etnaviv: Expose basic sanity tests via debugfs Sui Jingfeng

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=1779a56a-8735-4c65-a2fd-1e56ae6064b0@linux.dev \
    --to=sui.jingfeng@linux.dev \
    --cc=christian.gmeiner@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=etnaviv@lists.freedesktop.org \
    --cc=l.stach@pengutronix.de \
    --cc=linux+etnaviv@armlinux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /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

Powered by JetHome