dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Lucas Stach <l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 1/5] drm/prime: fix potential race in drm_gem_map_detach
Date: Wed, 28 Feb 2018 11:25:59 +0100	[thread overview]
Message-ID: <3a4f9020-235d-ef05-a246-1ba920070f09@gmail.com> (raw)
In-Reply-To: <1519811307.6253.5.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

Am 28.02.2018 um 10:48 schrieb Lucas Stach:
> Hi Christian,
>
> Am Dienstag, den 27.02.2018, 12:49 +0100 schrieb Christian König:
>> Unpin the GEM object only after freeing the sg table.
> What is the race that is being fixed here? The SG table is private to
> the importer and the importer should hopefully only call map_detach if
> it is done with all operations using the SG table. Thus it shouldn't
> matter that the SG table might point to moved pages during execution of
> this function.

Exactly, it shouldn't matter. This is just a precaution.

When the device driver is buggy I want proper error messages from IOMMU 
and not accessing pages which might already be reused for something else.

Regards,
Christian.

>
> Regards,
> Lucas
>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/drm_prime.c | 32 ++++++++++++++++----------------
>>   1 file changed, 16 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_prime.c
>> b/drivers/gpu/drm/drm_prime.c
>> index e82a976f0fba..c38dacda6119 100644
>> --- a/drivers/gpu/drm/drm_prime.c
>> +++ b/drivers/gpu/drm/drm_prime.c
>> @@ -230,26 +230,26 @@ void drm_gem_map_detach(struct dma_buf
>> *dma_buf,
>>   	struct drm_prime_attachment *prime_attach = attach->priv;
>>   	struct drm_gem_object *obj = dma_buf->priv;
>>   	struct drm_device *dev = obj->dev;
>> -	struct sg_table *sgt;
>>   
>> -	if (dev->driver->gem_prime_unpin)
>> -		dev->driver->gem_prime_unpin(obj);
>> +	if (prime_attach) {
>> +		struct sg_table *sgt = prime_attach->sgt;
>>   
>> -	if (!prime_attach)
>> -		return;
>> -
>> -	sgt = prime_attach->sgt;
>> -	if (sgt) {
>> -		if (prime_attach->dir != DMA_NONE)
>> -			dma_unmap_sg_attrs(attach->dev, sgt->sgl,
>> sgt->nents,
>> -					   prime_attach->dir,
>> -					   DMA_ATTR_SKIP_CPU_SYNC);
>> -		sg_free_table(sgt);
>> +		if (sgt) {
>> +			if (prime_attach->dir != DMA_NONE)
>> +				dma_unmap_sg_attrs(attach->dev, sgt-
>>> sgl,
>> +						   sgt->nents,
>> +						   prime_attach-
>>> dir,
>> +						   DMA_ATTR_SKIP_CPU
>> _SYNC);
>> +			sg_free_table(sgt);
>> +		}
>> +
>> +		kfree(sgt);
>> +		kfree(prime_attach);
>> +		attach->priv = NULL;
>>   	}
>>   
>> -	kfree(sgt);
>> -	kfree(prime_attach);
>> -	attach->priv = NULL;
>> +	if (dev->driver->gem_prime_unpin)
>> +		dev->driver->gem_prime_unpin(obj);
>>   }
>>   EXPORT_SYMBOL(drm_gem_map_detach);
>>   

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-02-28 10:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27 11:49 [PATCH 1/5] drm/prime: fix potential race in drm_gem_map_detach Christian König
2018-02-28  9:48 ` Lucas Stach
     [not found]   ` <1519811307.6253.5.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2018-02-28 10:25     ` Christian König [this message]
     [not found]       ` <3a4f9020-235d-ef05-a246-1ba920070f09-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-06  9:15         ` Daniel Vetter
2018-03-06  9:30           ` Christian König
2018-03-06  9:39             ` Daniel Vetter
     [not found] ` <20180227115000.4105-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-02-27 11:49   ` [PATCH 2/5] drm/prime: make the pages array optional for drm_prime_sg_to_page_addr_arrays Christian König
2018-03-06  9:21     ` Daniel Vetter
     [not found]       ` <20180306092102.GM22212-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2018-03-06  9:25         ` Christian König
2018-03-06  9:37           ` Daniel Vetter
2018-02-27 11:49   ` [PATCH 3/5] drm/ttm: move ttm_tt defines into ttm_tt.h Christian König
     [not found]     ` <20180227115000.4105-3-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-03-06  9:13       ` Christian König
2018-03-06  9:56         ` Michel Dänzer
2018-03-06 10:00         ` Thomas Hellstrom
2018-02-27 11:49   ` [PATCH 4/5] drm/ttm: add ttm_sg_tt_init Christian König
     [not found]     ` <20180227115000.4105-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-02-27 12:07       ` Christian König
     [not found]         ` <b5cb1980-7865-f45a-bc9d-9569f860fb50-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-03-05 12:06           ` Christian König
2018-03-05 20:55             ` Ben Skeggs
     [not found]             ` <1592dc9f-d76e-7174-1785-624cbd69d744-5C7GfCeVMHo@public.gmane.org>
2018-03-06  1:52               ` He, Roger
2018-03-06  9:19           ` [Nouveau] " Daniel Vetter
2018-02-27 11:50   ` [PATCH 5/5] drm/amdgpu: stop allocating a page array for prime shared BOs Christian König
2018-03-05 12:05   ` [PATCH 1/5] drm/prime: fix potential race in drm_gem_map_detach Christian König

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=3a4f9020-235d-ef05-a246-1ba920070f09@gmail.com \
    --to=ckoenig.leichtzumerken-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=christian.koenig-5C7GfCeVMHo@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.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