Skip to contentSkip to conversation

drm/nouveau: fix relocations applying logic and a double-free

PATCH In review Matti Hamalainen 3 participants 3 messages Nov 20, 2020 – Nov 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau: fix relocations applying logic and a double-free

Commit 03e0d26fcf79 ("drm/nouveau: slowpath for pushbuf ioctl") included a logic-bug which results in the relocations not actually getting applied at all as the call to nouveau_gem_pushbuf_reloc_apply() is never reached. This causes a regression with graphical corruption, triggered when relocations need to be done (for example after a suspend/resume cycle.)

Fix by setting *apply_relocs value only if there were more than 0 relocations.

Additionally, the never reached code had a leftover u_free() call, which, after fixing the logic, now got called and resulted in a double-free. Fix by removing one u_free(), moving the other and adding check for errors.

Cc Daniel Vetter <[email protected]>
Cc Ben Skeggs <[email protected]>
Fixes 03e0d26fcf79 ("drm/nouveau: slowpath for pushbuf ioctl")
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +5 -3
index 549bc67feabb..c2051380d18c 100644
@@ -558,8 +558,10 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 			NV_PRINTK(err, cli, "validating bo list\n");
 		validate_fini(op, chan, NULL, NULL);
 		return ret;
+	} else if (ret > 0) {
+		*apply_relocs = true;
 	}
-	*apply_relocs = ret;
+
 	return 0;
 }
 
@@ -662,7 +664,6 @@ nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
 		nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
 	}
 
-	u_free(reloc);
 	return ret;
 }
 
@@ -872,9 +873,10 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 				break;
 			}
 		}
-		u_free(reloc);
 	}
 out_prevalid:
+	if (!IS_ERR(reloc))
+		u_free(reloc);
 	u_free(bo);
 	u_free(push);
 

base-commit: 3494d58865ad4a47611dbb427b214cc5227fa5eb

Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Matti Hamalainen

Commit 03e0d26fcf79 ("drm/nouveau: slowpath for pushbuf ioctl") included a logic-bug which results in the relocations not actually getting applied at all as the call to nouveau_gem_pushbuf_reloc_apply() is never reached. This causes a regression with graphical corruption, triggered when relocations need to be done (for example after a suspend/resume cycle.)

Fix by setting *apply_relocs value only if there were more than 0 relocations.

Additionally, the never reached code had a leftover u_free() call, which, after fixing the logic, now got called and resulted in a double-free. Fix by removing one u_free(), moving the other and adding check for errors.

Quoted 7 lines
Cc Daniel Vetter <daniel.vetter-/[email protected]>
Cc Ben Skeggs <[email protected]>
Fixes 03e0d26fcf79 ("drm/nouveau: slowpath for pushbuf ioctl")

Link: is for the mailing list submission of the patch itself (to link the git log to the mailing list discussions), this should be
References: or similar. Aside from this:

Ben, I'm assuming you'll push this through your tree. -Daniel

Quoted 45 lines
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +5 -3
index 549bc67feabb..c2051380d18c 100644
@@ -558,8 +558,10 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
                        NV_PRINTK(err, cli, "validating bo list\n");
                validate_fini(op, chan, NULL, NULL);
                return ret;
+       } else if (ret > 0) {
+               *apply_relocs = true;
        }
-       *apply_relocs = ret;
+
        return 0;
 }
 
@@ -662,7 +664,6 @@ nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
                nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
        }
 
-       u_free(reloc);
        return ret;
 }
 
@@ -872,9 +873,10 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
                                break;
                        }
                }
-               u_free(reloc);
        }
 out_prevalid:
+       if (!IS_ERR(reloc))
+               u_free(reloc);
        u_free(bo);
        u_free(push);
 

base-commit: 3494d58865ad4a47611dbb427b214cc5227fa5eb --
2.29.2

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#2 lore raw
Quoted 25 lines · Daniel Vetter
Quoted 16 lines · Matti Hamalainen

Commit 03e0d26fcf79 ("drm/nouveau: slowpath for pushbuf ioctl") included a logic-bug which results in the relocations not actually getting applied at all as the call to nouveau_gem_pushbuf_reloc_apply() is never reached. This causes a regression with graphical corruption, triggered when relocations need to be done (for example after a suspend/resume cycle.)

Fix by setting *apply_relocs value only if there were more than 0 relocations.

Additionally, the never reached code had a leftover u_free() call, which, after fixing the logic, now got called and resulted in a double-free. Fix by removing one u_free(), moving the other and adding check for errors.

Quoted 7 lines
Cc Daniel Vetter <daniel.vetter-/[email protected]>
Cc Ben Skeggs <[email protected]>
Fixes 03e0d26fcf79 ("drm/nouveau: slowpath for pushbuf ioctl")
Quoted 7 lines

Link: is for the mailing list submission of the patch itself (to link the git log to the mailing list discussions), this should be
References: or similar. Aside from this:

Ben, I'm assuming you'll push this through your tree.

Ok Dave asked me to just push it into drm-misc-fixes.

Thanks for your patch!
-Daniel

Quoted 54 lines

-Daniel

Quoted 45 lines
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +5 -3
index 549bc67feabb..c2051380d18c 100644
@@ -558,8 +558,10 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
                        NV_PRINTK(err, cli, "validating bo list\n");
                validate_fini(op, chan, NULL, NULL);
                return ret;
+       } else if (ret > 0) {
+               *apply_relocs = true;
        }
-       *apply_relocs = ret;
+
        return 0;
 }
 
@@ -662,7 +664,6 @@ nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
                nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
        }
 
-       u_free(reloc);
        return ret;
 }
 
@@ -872,9 +873,10 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
                                break;
                        }
                }
-               u_free(reloc);
        }
 out_prevalid:
+       if (!IS_ERR(reloc))
+               u_free(reloc);
        u_free(bo);
        u_free(push);
 

base-commit: 3494d58865ad4a47611dbb427b214cc5227fa5eb --
2.29.2

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch