drm/nouveau: fix off-by-one bugs related to command submission in IB mode
Subsystems (3)
PATCH 10/10 drm/nouveau: fix off-by-one bugs related to command submission in IB mode
Commit "drm/nouveau: port all engines to new engine module format" changed IB size calculation to be less wasteful, but didn't take into account already existing off-by-one bugs :).
So:
- ib_max is the last entry, so we need to +1 when calculating number of free entries
- nv50_dma_wait already does +1 (for FIRE_RING), so we don't need another +1 on nouveau_gem_ioctl_pushbuf side
- there are 512 allocated IB entries (and it needs to be round number), so we can accept at most 511 entries from userspace (we need one for FIRE_RING) - fortunately userspace already flushes at 511, so nr_push check change won't have any impact
--- drivers/gpu/drm/nouveau/nouveau_chan.c | 2 +- drivers/gpu/drm/nouveau/nouveau_dma.c | 2 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -1
@@ -318,7 +318,7 @@ nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart) chan->dma.ib_base =0x10000 /4 ; chan->dma.ib_max = (0x01000 /8 ) -1 ; chan->dma.ib_put =0 ; - chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put; + chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put +1 ; chan->dma.max = chan->dma.ib_base;break ; }
drivers/gpu/drm/nouveau/nouveau_dma.c +1 -1
@@ -128,7 +128,7 @@ nv50_dma_push_wait(struct nouveau_channel *chan, int count) chan->dma.ib_free = get - chan->dma.ib_put;if (chan->dma.ib_free <=0 ) - chan->dma.ib_free += chan->dma.ib_max; + chan->dma.ib_free += chan->dma.ib_max +1 ; }return 0 ;
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -2
@@ -662,7 +662,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,if (unlikely (req->nr_push ==0 )) goto out_next; -if (unlikely (req->nr_push >NOUVEAU_GEM_MAX_PUSH )) { +if (unlikely (req->nr_push >=NOUVEAU_GEM_MAX_PUSH )) {NV_ERROR (drm,"pushbuf push count exceeds limit: %d max %d\n" , req->nr_push,NOUVEAU_GEM_MAX_PUSH );return nouveau_abi16_put (abi16, -EINVAL );
@@ -718,7 +718,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, }if (chan->dma.ib_max) { - ret =nouveau_dma_wait (chan, req->nr_push +1 ,16 ); + ret =nouveau_dma_wait (chan, req->nr_push,16 );if (ret) {NV_ERROR (drm,"nv50cal_space: %d\n" , ret); goto out;
Signature · 1 line
1.7.8.6
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 70 lines · Marcin Slusarz
Commit "drm/nouveau: port all engines to new engine module format" changed IB size calculation to be less wasteful, but didn't take into account already existing off-by-one bugs :).
So:
-ib_maxis the last entry, so we need to +1 when calculating number of free entries
-nv50_dma_waitalready does +1 (forFIRE_RING), so we don't need another +1 onnouveau_gem_ioctl_pushbufside
- there are 512 allocated IB entries (and it needs to be round number), so we can accept at most 511 entries from userspace (we need one forFIRE_RING) - fortunately userspace already flushes at 511, sonr_pushcheck change won't have any impactSigned-off-by Marcin Slusarz <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_chan.c | 2 +- drivers/gpu/drm/nouveau/nouveau_dma.c | 2 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/nouveau/nouveau_chan.c +1
-1@@ -318,7 +318,7 @@ nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart) chan->dma.ib_base =0x10000 /4 ; chan->dma.ib_max = (0x01000 /8 ) -1 ; chan->dma.ib_put =0 ; - chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put; + chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put +1 ; chan->dma.max = chan->dma.ib_base;break ; }drivers/gpu/drm/nouveau/nouveau_dma.c +1
-1@@ -128,7 +128,7 @@ nv50_dma_push_wait(struct nouveau_channel *chan, int count) chan->dma.ib_free = get - chan->dma.ib_put;if (chan->dma.ib_free <=0 ) - chan->dma.ib_free += chan->dma.ib_max; + chan->dma.ib_free += chan->dma.ib_max +1 ; }return 0 ;drivers/gpu/drm/nouveau/nouveau_gem.c +2
-3@@ -662,7 +662,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,if (unlikely (req->nr_push ==0 )) goto out_next; -if (unlikely (req->nr_push >NOUVEAU_GEM_MAX_PUSH )) { +if (unlikely (req->nr_push >=NOUVEAU_GEM_MAX_PUSH )) {NV_ERROR (drm,"pushbuf push count exceeds limit: %d max %d\n" , req->nr_push,NOUVEAU_GEM_MAX_PUSH );return nouveau_abi16_put (abi16, -EINVAL );@@ -718,7 +718,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, }if (chan->dma.ib_max) { - ret =nouveau_dma_wait (chan, req->nr_push +1 ,16 ); + ret =nouveau_dma_wait (chan, req->nr_push,16 );if (ret) {NV_ERROR (drm,"nv50cal_space: %d\n" , ret); goto out; --
Quoted 2 lines
1.7.8.6
<Tested-by: Maarten Maathuis <[email protected]>
I would however like to voice a concern about the reinterpretation of MAX_PUSH. Strictly speaking the number needs to go down one as far as i'm concerned. But i'll Ben decide about the API/ABI concerns :-)
Signature · 2 lines
Far away from the primal instinct, the song seems to fade away, the river get wider between your thoughts and the things we do and say.
Quoted 4 lines · Marcin Slusarz
Commit "drm/nouveau: port all engines to new engine module format" changed IB size calculation to be less wasteful, but didn't take into account already existing off-by-one bugs :).
Quoted 9 lines
So:
-ib_maxis the last entry, so we need to +1 when calculating number of free entries
-nv50_dma_waitalready does +1 (forFIRE_RING), so we don't need another +1 onnouveau_gem_ioctl_pushbufside
- there are 512 allocated IB entries (and it needs to be round number), so we can accept at most 511 entries from userspace (we need one forFIRE_RING) - fortunately userspace already flushes at 511, sonr_pushcheck change won't have any impact
Also skipped this patch for now as I have work in progress that will improve this and related code. I should have it in the tree soon.
Quoted 63 lines
Signed-off-by Marcin Slusarz <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_chan.c | 2 +- drivers/gpu/drm/nouveau/nouveau_dma.c | 2 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/nouveau/nouveau_chan.c +1
-1@@ -318,7 +318,7 @@ nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart) chan->dma.ib_base =0x10000 /4 ; chan->dma.ib_max = (0x01000 /8 ) -1 ; chan->dma.ib_put =0 ; - chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put; + chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put +1 ; chan->dma.max = chan->dma.ib_base;break ; }drivers/gpu/drm/nouveau/nouveau_dma.c +1
-1@@ -128,7 +128,7 @@ nv50_dma_push_wait(struct nouveau_channel *chan, int count) chan->dma.ib_free = get - chan->dma.ib_put;if (chan->dma.ib_free <=0 ) - chan->dma.ib_free += chan->dma.ib_max; + chan->dma.ib_free += chan->dma.ib_max +1 ; }return 0 ;drivers/gpu/drm/nouveau/nouveau_gem.c +2
-2@@ -662,7 +662,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,if (unlikely (req->nr_push ==0 )) goto out_next; -if (unlikely (req->nr_push >NOUVEAU_GEM_MAX_PUSH )) { +if (unlikely (req->nr_push >=NOUVEAU_GEM_MAX_PUSH )) {NV_ERROR (drm,"pushbuf push count exceeds limit: %d max %d\n" , req->nr_push,NOUVEAU_GEM_MAX_PUSH );return nouveau_abi16_put (abi16, -EINVAL );@@ -718,7 +718,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, }if (chan->dma.ib_max) { - ret =nouveau_dma_wait (chan, req->nr_push +1 ,16 ); + ret =nouveau_dma_wait (chan, req->nr_push,16 );if (ret) {NV_ERROR (drm,"nv50cal_space: %d\n" , ret); goto out;Signature · 6 lines
1.7.8.6 _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): 20120820063323.GF2013-7ZJhIA9XobAf7BdofF/[email protected]
Quoted 14 lines · Ben Skeggs
Quoted 4 lines · Marcin Slusarz
Commit "drm/nouveau: port all engines to new engine module format" changed IB size calculation to be less wasteful, but didn't take into account already existing off-by-one bugs :).
Quoted 9 lines
So:
-ib_maxis the last entry, so we need to +1 when calculating number of free entries
-nv50_dma_waitalready does +1 (forFIRE_RING), so we don't need another +1 onnouveau_gem_ioctl_pushbufside
- there are 512 allocated IB entries (and it needs to be round number), so we can accept at most 511 entries from userspace (we need one forFIRE_RING) - fortunately userspace already flushes at 511, sonr_pushcheck change won't have any impact
Quoted 2 lines
Also skipped this patch for now as I have work in progress that will improve this and related code. I should have it in the tree soon.
Maybe I should have written this in the changelog, but this patch fixes total mayhem seen in warsow and nexuiz (at least). It's better to integrate it sooner than later.
Marcin
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am Dienstag, 21. August 2012 schrieb Marcin Slusarz :
Quoted 22 lines · Ben Skeggs
Quoted 2 lines · Marcin Slusarz
Quoted 1 line
Commit "drm/nouveau: port all engines to new engine module format"
changed
Quoted 1 line
Quoted 1 line
IB size calculation to be less wasteful, but didn't take into account
already
Quoted 6 lines
Quoted 6 lines
existing off-by-one bugs :).
So:
-ib_maxis the last entry, so we need to +1 when calculating number of free entries
-nv50_dma_waitalready does +1 (forFIRE_RING), so we don't needanother +1
Quoted 2 lines
Quoted 2 lines
on
nouveau_gem_ioctl_pushbufside
- there are 512 allocated IB entries (and it needs to be roundnumber), so we
Quoted 1 line
Quoted 1 line
can accept at most 511 entries from userspace (we need one for
FIRE_RING) -Quoted 1 line
Quoted 1 line
fortunately userspace already flushes at 511, so
nr_pushcheckchange won't
Quoted 2 lines
Quoted 1 line
have any impact
Also skipped this patch for now as I have work in progress that will
Quoted 8 lines
improve this and
Quoted 1 line
related code. I should have it in the tree soon.
Maybe I should have written this in the changelog, but this patch fixes total
mayhem seen in warsow and nexuiz (at least). It's better to integrate it sooner
than later.
I presume bumping the IB size to 8KiB also helps? I prefer this in the meantime, and it's probably best to do anyway, I didn't take into account what we allow userspace to do in one shot. If this works too, i'll push that change this morning.
I did try and reproduce on a couple of cards with warsow and wasn't able to.
Also, what happened to instmem being the culprit here?
Marcin
Quoted 1 line
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): CACAvsv7FKZFoVi9akwfmnry8O+draX_ZfuBbFF_2zEOV9kkK6Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 33 lines · Ben Skeggs
Am Dienstag, 21. August 2012 schrieb Marcin Slusarz :
On Mon, Aug 20, 2012 at 04:33:24PM +1000, Ben Skeggs wrote:
> On Sun, Aug 19, 2012 at 11:02:00PM +0200, Marcin Slusarz wrote:
> > Commit "drm/nouveau: port all engines to new engine module format" changed
> > IB size calculation to be less wasteful, but didn't take into account already
> > existing off-by-one bugs :).
> >
> > So:
> > -ib_maxis the last entry, so we need to +1 when calculating number of
> > free entries
> > -nv50_dma_waitalready does +1 (forFIRE_RING), so we don't need another +1
> > onnouveau_gem_ioctl_pushbufside
> > - there are 512 allocated IB entries (and it needs to be round number), so we
> > can accept at most 511 entries from userspace (we need one for
FIRE_RING) -
> > fortunately userspace already flushes at 511, sonr_pushcheck
change won't
> > have any impact
> Also skipped this patch for now as I have work in progress that will improve this and
> related code. I should have it in the tree soon. Maybe I should have written this in the changelog, but this patch fixes total
mayhem seen in warsow and nexuiz (at least). It's better to integrate it sooner
than later.
Quoted 1 line
I presume bumping the IB size to 8KiB also helps?
Yes, my first patch did exactly this and it worked.
However, Maarten can still reproduce this bug, so my patch is not completely correct. I discovered that RING_SPACE calls nouveau_dma_wait with slots=1 and nv50_dma_wait increases it again, so we need to move +1 from nv50_dma_wait to nouveau_gem_ioctl_pushbuf. But once I do this everything explodes, because we do 2 FIRE_RING's (one from fence_emit, and one from nv50_dma_wait), so...
Quoted 4 lines
I prefer this in the
meantime, and it's probably best to do anyway, I didn't take into account what we allow userspace to do in one shot. If this works too, i'll push that change this morning.
... it's probably a good idea to do this and forget about the problem.
Quoted 2 lines
I did try and reproduce on a couple of cards with warsow and wasn't able to.
Nexuiz is even better. It draws artifacts immediately after demo start.
Quoted 1 line
Also, what happened to instmem being the culprit here?
It was bad bisection. Once I knew what is the problem, I verified "drm/nouveau: port all engines to new engine module format" is the first bad commit.
Marcin
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 62 lines · Marcin Slusarz
Quoted 33 lines · Ben Skeggs
Am Dienstag, 21. August 2012 schrieb Marcin Slusarz :
On Mon, Aug 20, 2012 at 04:33:24PM +1000, Ben Skeggs wrote:
> On Sun, Aug 19, 2012 at 11:02:00PM +0200, Marcin Slusarz wrote:
> > Commit "drm/nouveau: port all engines to new engine module format" changed
> > IB size calculation to be less wasteful, but didn't take into account already
> > existing off-by-one bugs :).
> >
> > So:
> > -ib_maxis the last entry, so we need to +1 when calculating number of
> > free entries
> > -nv50_dma_waitalready does +1 (forFIRE_RING), so we don't need another +1
> > onnouveau_gem_ioctl_pushbufside
> > - there are 512 allocated IB entries (and it needs to be round number), so we
> > can accept at most 511 entries from userspace (we need one for
FIRE_RING) -
> > fortunately userspace already flushes at 511, sonr_pushcheck
change won't
> > have any impact
> Also skipped this patch for now as I have work in progress that will improve this and
> related code. I should have it in the tree soon. Maybe I should have written this in the changelog, but this patch fixes total
mayhem seen in warsow and nexuiz (at least). It's better to integrate it sooner
than later.Quoted 1 line
I presume bumping the IB size to 8KiB also helps?
Yes, my first patch did exactly this and it worked.
However, Maarten can still reproduce this bug, so my patch is not completely correct. I discovered that
RING_SPACEcallsnouveau_dma_waitwith slots=1 andnv50_dma_waitincreases it again, so we need to move +1 fromnv50_dma_waittonouveau_gem_ioctl_pushbuf. But once I do this everything explodes, because we do 2 FIRE_RING's (one fromfence_emit, and one fromnv50_dma_wait), so...Quoted 4 lines
I prefer this in the
meantime, and it's probably best to do anyway, I didn't take into account what we allow userspace to do in one shot. If this works too, i'll push that change this morning.... it's probably a good idea to do this and forget about the problem.
Quoted 2 lines
I did try and reproduce on a couple of cards with warsow and wasn't able to.
Nexuiz is even better. It draws artifacts immediately after demo start.
Quoted 1 line
Also, what happened to instmem being the culprit here?
It was bad bisection. Once I knew what is the problem, I verified "drm/nouveau: port all engines to new engine module format" is the first bad commit.
Quoted 5 lines
Marcin
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
One thing, i think FIRE_RING should check for available ib slots, currently it doesn't and that seems a bit dangerous. Just a thought for Ben :-)
Signature · 2 lines
Far away from the primal instinct, the song seems to fade away, the river get wider between your thoughts and the things we do and say.