diff mbox

drm/radeon: TTM must be init with cpu-visible VRAM

Message ID 20140227233848.78fffa58.cand@gmx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lauri Kasanen Feb. 27, 2014, 9:38 p.m. UTC
Without this, a bo may get created in the cpu-inaccessible vram.
Before the CP engines get setup, all copies are done via cpu memcpy.

This means that the cpu tries to read from inaccessible memory, fails,
and the radeon module proceeds to disable acceleration.

Doing this has no downsides, as the real VRAM size gets set as soon as the
CP engines get init.

This is a candidate for 3.14 fixes.

Signed-off-by: Lauri Kasanen <cand@gmx.com>
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Christian König Feb. 28, 2014, 9:36 a.m. UTC | #1
Am 27.02.2014 22:38, schrieb Lauri Kasanen:
> Without this, a bo may get created in the cpu-inaccessible vram.
> Before the CP engines get setup, all copies are done via cpu memcpy.
>
> This means that the cpu tries to read from inaccessible memory, fails,
> and the radeon module proceeds to disable acceleration.
>
> Doing this has no downsides, as the real VRAM size gets set as soon as the
> CP engines get init.
>
> This is a candidate for 3.14 fixes.

This should be unnecessary, since TTM gets initialized only seeing the 
visible VRAM and later on radeon_ttm_set_active_vram_size gets called to 
increase the limit.

If this isn't the case any more we should figure out why instead of 
working around it like this.

Christian.

>
> Signed-off-by: Lauri Kasanen <cand@gmx.com>
> ---
>   drivers/gpu/drm/radeon/radeon_ttm.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index 3aa853c..35eae91 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -715,6 +715,8 @@ int radeon_ttm_init(struct radeon_device *rdev)
>   		DRM_ERROR("Failed initializing VRAM heap.\n");
>   		return r;
>   	}
> +	radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
> +
>   	r = radeon_bo_create(rdev, 256 * 1024, PAGE_SIZE, true,
>   			     RADEON_GEM_DOMAIN_VRAM,
>   			     NULL, &rdev->stollen_vga_memory);
Lauri Kasanen Feb. 28, 2014, 3:30 p.m. UTC | #2
On Fri, 28 Feb 2014 10:36:59 +0100
Christian König <deathsimple@vodafone.de> wrote:

> Am 27.02.2014 22:38, schrieb Lauri Kasanen:
> > Without this, a bo may get created in the cpu-inaccessible vram.
> > Before the CP engines get setup, all copies are done via cpu memcpy.
> >
> > This means that the cpu tries to read from inaccessible memory, fails,
> > and the radeon module proceeds to disable acceleration.
> >
> > Doing this has no downsides, as the real VRAM size gets set as soon as the
> > CP engines get init.
> >
> > This is a candidate for 3.14 fixes.
> 
> This should be unnecessary, since TTM gets initialized only seeing the 
> visible VRAM and later on radeon_ttm_set_active_vram_size gets called to 
> increase the limit.
> 
> If this isn't the case any more we should figure out why instead of 
> working around it like this.

Negative, TTM gets initialized with real_vram just a few lines above
this patch, not visible_vram.

- Lauri
Lauri Kasanen Feb. 28, 2014, 3:36 p.m. UTC | #3
On Fri, 28 Feb 2014 17:30:39 +0200
Lauri Kasanen <cand@gmx.com> wrote:

> On Fri, 28 Feb 2014 10:36:59 +0100
> Christian König <deathsimple@vodafone.de> wrote:
> 
> > Am 27.02.2014 22:38, schrieb Lauri Kasanen:
> > > Without this, a bo may get created in the cpu-inaccessible vram.
> > > Before the CP engines get setup, all copies are done via cpu memcpy.
> > >
> > > This means that the cpu tries to read from inaccessible memory, fails,
> > > and the radeon module proceeds to disable acceleration.
> > >
> > > Doing this has no downsides, as the real VRAM size gets set as soon as the
> > > CP engines get init.
> > >
> > > This is a candidate for 3.14 fixes.
> > 
> > This should be unnecessary, since TTM gets initialized only seeing the 
> > visible VRAM and later on radeon_ttm_set_active_vram_size gets called to 
> > increase the limit.
> > 
> > If this isn't the case any more we should figure out why instead of 
> > working around it like this.
> 
> Negative, TTM gets initialized with real_vram just a few lines above
> this patch, not visible_vram.

git blame shows 7a50f01a from 2009, "drm/radeon/kms: vram sizing on
certain r100 chips needs workaround." by Dave Airlie.

So the TTM VRAM init has been wrong for five years, and only worked by
accident because until now all allocations were done bottom-up.

- Lauri
Christian König Feb. 28, 2014, 3:43 p.m. UTC | #4
Am 28.02.2014 16:36, schrieb Lauri Kasanen:
> On Fri, 28 Feb 2014 17:30:39 +0200
> Lauri Kasanen <cand@gmx.com> wrote:
>
>> On Fri, 28 Feb 2014 10:36:59 +0100
>> Christian König <deathsimple@vodafone.de> wrote:
>>
>>> Am 27.02.2014 22:38, schrieb Lauri Kasanen:
>>>> Without this, a bo may get created in the cpu-inaccessible vram.
>>>> Before the CP engines get setup, all copies are done via cpu memcpy.
>>>>
>>>> This means that the cpu tries to read from inaccessible memory, fails,
>>>> and the radeon module proceeds to disable acceleration.
>>>>
>>>> Doing this has no downsides, as the real VRAM size gets set as soon as the
>>>> CP engines get init.
>>>>
>>>> This is a candidate for 3.14 fixes.
>>> This should be unnecessary, since TTM gets initialized only seeing the
>>> visible VRAM and later on radeon_ttm_set_active_vram_size gets called to
>>> increase the limit.
>>>
>>> If this isn't the case any more we should figure out why instead of
>>> working around it like this.
>> Negative, TTM gets initialized with real_vram just a few lines above
>> this patch, not visible_vram.
> git blame shows 7a50f01a from 2009, "drm/radeon/kms: vram sizing on
> certain r100 chips needs workaround." by Dave Airlie.
>
> So the TTM VRAM init has been wrong for five years, and only worked by
> accident because until now all allocations were done bottom-up.

Yeah, just came to the same conclusion. We probably never hit the case 
in the last five years because we don't really access the memory before 
we start the copy ring.

Please fix ttm_bo_init_mm to use rdev->mc.visible_vram_size instead.

That allocations are made bottom-up is relied upon in a couple of other 
cases as well, the stolen VGA memory and the UVD firmware handling for 
example.

Christian.

> - Lauri
Lauri Kasanen Feb. 28, 2014, 4:52 p.m. UTC | #5
On Fri, 28 Feb 2014 16:43:54 +0100
Christian König <deathsimple@vodafone.de> wrote:

> >>> Am 27.02.2014 22:38, schrieb Lauri Kasanen:
> >>>> Without this, a bo may get created in the cpu-inaccessible vram.
> >>>> Before the CP engines get setup, all copies are done via cpu memcpy.
> >>>>
> >>>> This means that the cpu tries to read from inaccessible memory, fails,
> >>>> and the radeon module proceeds to disable acceleration.
> >>>>
> >>>> Doing this has no downsides, as the real VRAM size gets set as soon as the
> >>>> CP engines get init.
> >>>>
> >>>> This is a candidate for 3.14 fixes.
> >>> This should be unnecessary, since TTM gets initialized only seeing the
> >>> visible VRAM and later on radeon_ttm_set_active_vram_size gets called to
> >>> increase the limit.
> >>>
> >>> If this isn't the case any more we should figure out why instead of
> >>> working around it like this.
> >> Negative, TTM gets initialized with real_vram just a few lines above
> >> this patch, not visible_vram.
> > git blame shows 7a50f01a from 2009, "drm/radeon/kms: vram sizing on
> > certain r100 chips needs workaround." by Dave Airlie.
> >
> > So the TTM VRAM init has been wrong for five years, and only worked by
> > accident because until now all allocations were done bottom-up.
> 
> Yeah, just came to the same conclusion. We probably never hit the case 
> in the last five years because we don't really access the memory before 
> we start the copy ring.
> 
> Please fix ttm_bo_init_mm to use rdev->mc.visible_vram_size instead.
> 
> That allocations are made bottom-up is relied upon in a couple of other 
> cases as well, the stolen VGA memory and the UVD firmware handling for 
> example.

I initially did that, but it caused some issues. I didn't investigage
it further, but I guess it has to be init to the maximum size, and then
only the size lowered, so that the change only affects lpfn.

- Lauri
Christian König Feb. 28, 2014, 5:27 p.m. UTC | #6
Am 28.02.2014 17:52, schrieb Lauri Kasanen:
> On Fri, 28 Feb 2014 16:43:54 +0100
> Christian König <deathsimple@vodafone.de> wrote:
>
>>>>> Am 27.02.2014 22:38, schrieb Lauri Kasanen:
>>>>>> Without this, a bo may get created in the cpu-inaccessible vram.
>>>>>> Before the CP engines get setup, all copies are done via cpu memcpy.
>>>>>>
>>>>>> This means that the cpu tries to read from inaccessible memory, fails,
>>>>>> and the radeon module proceeds to disable acceleration.
>>>>>>
>>>>>> Doing this has no downsides, as the real VRAM size gets set as soon as the
>>>>>> CP engines get init.
>>>>>>
>>>>>> This is a candidate for 3.14 fixes.
>>>>> This should be unnecessary, since TTM gets initialized only seeing the
>>>>> visible VRAM and later on radeon_ttm_set_active_vram_size gets called to
>>>>> increase the limit.
>>>>>
>>>>> If this isn't the case any more we should figure out why instead of
>>>>> working around it like this.
>>>> Negative, TTM gets initialized with real_vram just a few lines above
>>>> this patch, not visible_vram.
>>> git blame shows 7a50f01a from 2009, "drm/radeon/kms: vram sizing on
>>> certain r100 chips needs workaround." by Dave Airlie.
>>>
>>> So the TTM VRAM init has been wrong for five years, and only worked by
>>> accident because until now all allocations were done bottom-up.
>> Yeah, just came to the same conclusion. We probably never hit the case
>> in the last five years because we don't really access the memory before
>> we start the copy ring.
>>
>> Please fix ttm_bo_init_mm to use rdev->mc.visible_vram_size instead.
>>
>> That allocations are made bottom-up is relied upon in a couple of other
>> cases as well, the stolen VGA memory and the UVD firmware handling for
>> example.
> I initially did that, but it caused some issues. I didn't investigage
> it further, but I guess it has to be init to the maximum size, and then
> only the size lowered, so that the change only affects lpfn.

Fair enough, probably something gets allocated on init or something like 
that.

Please document that with a comment and resend the patch.

Christian.

>
> - Lauri
diff mbox

Patch

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 3aa853c..35eae91 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -715,6 +715,8 @@  int radeon_ttm_init(struct radeon_device *rdev)
 		DRM_ERROR("Failed initializing VRAM heap.\n");
 		return r;
 	}
+	radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
+
 	r = radeon_bo_create(rdev, 256 * 1024, PAGE_SIZE, true,
 			     RADEON_GEM_DOMAIN_VRAM,
 			     NULL, &rdev->stollen_vga_memory);