From: Eric Anholt Subject: Re: [PATCH] vc4_bo.c: always set bo->resv Date: Fri, 02 Jun 2017 14:48:33 -0700 Message-ID: <87mv9q83im.fsf@eliezer.anholt.net> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0132952848==" Return-path: Received: from anholt.net (anholt.net [50.246.234.109]) by gabe.freedesktop.org (Postfix) with ESMTP id 0682E6E40A for ; Fri, 2 Jun 2017 21:48:51 +0000 (UTC) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Hans Verkuil , Maling list - DRI developers List-Id: dri-devel@lists.freedesktop.org --===============0132952848== Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hans Verkuil writes: > The bo->resv pointer could be NULL, leading to kernel oopses like the one= below. > It looks like .fb_probe -> drm_fbdev_cma_create() -> drm_gem_cma_create()= would > end up not initializing resv, because we're doing that in vc4_bo_create()= , not > vc4_create_object(). > > This patch ensures that bo->resv is always set in vc4_create_object > ensuring that it is never NULL. > > Thanks to Eric Anholt for pointing to the correct solution. Folks that know dma-buf better: Will having two reservations around for the lifetime of the BO in the case of CMA dma-buf imports be a bad thing? I'm assuming reservations are cheap, given that we're unconditionally allocating them per BO for un-shared BOs already. > Signed-off-by: Hans Verkuil > --- > drivers/gpu/drm/vc4/vc4_bo.c | 12 ++++-------- > 1 file changed, 4 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c > index 80b2f9e55c5c..2231ee76cd8d 100644 > --- a/drivers/gpu/drm/vc4/vc4_bo.c > +++ b/drivers/gpu/drm/vc4/vc4_bo.c > @@ -91,8 +91,7 @@ static void vc4_bo_destroy(struct vc4_bo *bo) > vc4->bo_stats.num_allocated--; > vc4->bo_stats.size_allocated -=3D obj->size; > > - if (bo->resv =3D=3D &bo->_resv) > - reservation_object_fini(bo->resv); > + reservation_object_fini(bo->resv); This one would need to be "reservation_object_fini(&bo->_resv);" -- we need to free the reservation that we created (and left unused in the case of an import), not the one that was imported from someone else. > drm_gem_cma_free_object(obj); > } > @@ -212,6 +211,8 @@ struct drm_gem_object *vc4_create_object(struct drm_d= evice *dev, size_t size) > vc4->bo_stats.num_allocated++; > vc4->bo_stats.size_allocated +=3D size; > mutex_unlock(&vc4->bo_lock); > + bo->resv =3D &bo->_resv; > + reservation_object_init(bo->resv); > > return &bo->base.base; > } > @@ -250,12 +251,7 @@ struct vc4_bo *vc4_bo_create(struct drm_device *dev,= size_t unaligned_size, > return ERR_PTR(-ENOMEM); > } > } > - bo =3D to_vc4_bo(&cma_obj->base); > - > - bo->resv =3D &bo->_resv; > - reservation_object_init(bo->resv); > - > - return bo; > + return to_vc4_bo(&cma_obj->base); > } > > int vc4_dumb_create(struct drm_file *file_priv, > --=20 > 2.11.0 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE/JuuFDWp9/ZkuCBXtdYpNtH8nugFAlkx3TEACgkQtdYpNtH8 nugAww/+JsvFuPgNHEZ+RIA1lBI92VxuhlmZ8plICDnF8TW1T5VvJC8Ebl0Yz8lF V46ISjXVui7QMJJplsZOF+T4VNcUKr53LOv81J3s4yhOHIJfBOGpMZuRiEfIlav7 NhxJY0kaUOqD8ge76TAyvXPmS1vdHsHTSQ0duCWC+qiIe5iSXObpFOlUhYgJDcTl bA9+oOcgtiuo6nBro5ySl6dq17THQOLqCt8ZMW8YJDcLe+0d/KM4FBPHP43SgLs1 fD5O+otnhwgq48t0sYNYnNUoyfmsNSFtJkRV2yPlHJy+PvmKQIIO31paYjfvxUy+ USjnP+H5JBgNAe4XSlmu+6dcT6sRMMXrzhUcxb1BtWIgG0UDE1ViGl3ENd8C4tfo GxxVbH+wzYLWGH9JyTFtdBAmZNPbfL0ELlORZz925kM0PxcPHGHoAcHkuMt3zbki 5dRLctoHHkSILiQapqLYsoR/LmEXqaQTckdxJoe9xfYviWY5gAZfJbeLYYPcXAlz I8toUh9e6t1+deI/Ai3AYqXrVHD1Gc+yQ1Yk4wnIIK1hnzupe2fw8V857XjQswNs yooGZ9+xnwB3Wcx4Kn8ZHARH2P6++42a9KAY3DvpBjnYYA4me549RUtJDJW/849y Vg0BXGxqRfVxcbyvvkBZYwmQ+kPjxGpzdyzIQuEeT/Y3TSn95q0= =GFCF -----END PGP SIGNATURE----- --=-=-=-- --===============0132952848== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVsCg== --===============0132952848==--