linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frediano Ziglio <fziglio@redhat.com>
To: Dave Airlie <airlied@gmail.com>
Cc: spice-devel <spice-devel@lists.freedesktop.org>,
	Dave Airlie <airlied@linux.ie>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Dave Airlie <airlied@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [Spice-devel] [PATCH 09/11] Move main reference counter to GEM object instead of TTM ones
Date: Fri, 29 May 2015 07:11:52 -0400 (EDT)	[thread overview]
Message-ID: <1775637487.6685866.1432897912303.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <CAPM=9txWjm_nY=7t3OvfF2yB1YmikyTA8u9cB7x+6FU2hL6rsw@mail.gmail.com>


> On 27 May 2015 at 20:04, Frediano Ziglio <fziglio@redhat.com> wrote:
> > qxl_bo structure has two reference counters, one in the GEM object and
> > another in the TTM object. The GEM object keep a counter to the TTM object
> > so when GEM counter reached zero the TTM counter (using qxl_bo_unref) was
> > decremented. The qxl object is fully freed (both GEM and TTM part are
> > cleaned)
> > when the TTM counter reach zero.
> > One issue was that surface idr structure has no owning on qxl_bo objects
> > however
> > it contains a pointer to qxl_bo object. This caused some nasty race
> > condition
> > for instance qxl_bo object was reaped even after counter was already zero.
> > This patch fix these races moving main counter (the one used by
> > qxl_bo_(un)ref)
> > to GEM object which cleanup routine (qxl_gem_object_free) remove the idr
> > pointer
> > (using qxl_surface_evict) when the counters are still valid.
> 
> Uggh, but yes, not sure I like this fix for the problem, but if it works,
> 
> Reviewed-by: Dave Airlie <airlied@redhat.com>
> 

Well, the patch does not surely looks very clear but I can assure the problems it fixes are much less clear to understand.
Having a pointer to a object the is going to be deleted whenever another thread decide to causes difficult races. I tried to avoid this kind of change and fix the races instead but was a nightmare.
My first experimental patch added an additional counter on top of GEM and TTM one as the main counter but at the end was much more complicated and result was similar to move the main counter to GEM.
Mainly external references (from userspace and kernel) are pointers to GEM. Pointers to TTM are from memory mapped files. Deleting the spice id after GEM object has no references assure the not owning reference from spice id still refer to a valid object. As user can't retrieve a pointer from a mapping (at most can remap it) so there are no risks counter to GEM is incremented again.

Frediano

  reply	other threads:[~2015-05-29 11:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 10:03 [PATCH 00/11] Miscellaneous stability patches Frediano Ziglio
2015-05-27 10:03 ` [PATCH 01/11] Do not cause spice-server to clean our objects Frediano Ziglio
2015-05-28  3:08   ` [Spice-devel] " Dave Airlie
2015-05-27 10:03 ` [PATCH 02/11] Do not leak memory if qxl_release_list_add fails Frediano Ziglio
2015-05-28  3:09   ` [Spice-devel] " Dave Airlie
2015-05-27 10:03 ` [PATCH 03/11] Fix print statement not using uninitialized variable Frediano Ziglio
2015-05-28  3:10   ` [Spice-devel] " Dave Airlie
2015-05-27 10:03 ` [PATCH 04/11] Avoid double free on error Frediano Ziglio
2015-05-28  3:11   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 05/11] Handle all errors in qxl_surface_evict Frediano Ziglio
2015-05-28  3:16   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 06/11] Fix return for qxl_release_alloc Frediano Ziglio
2015-05-28  3:17   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 07/11] Handle correctly failures in qxl_alloc_relase_reserved Frediano Ziglio
2015-05-28  3:20   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 08/11] Remove format string errors Frediano Ziglio
2015-05-28  3:20   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 09/11] Move main reference counter to GEM object instead of TTM ones Frediano Ziglio
2015-05-28  3:31   ` [Spice-devel] " Dave Airlie
2015-05-29 11:11     ` Frediano Ziglio [this message]
2015-05-27 10:04 ` [PATCH 10/11] Simplify cleaning qxl processing command Frediano Ziglio
2015-05-28  3:32   ` [Spice-devel] " Dave Airlie
2015-05-27 10:04 ` [PATCH 11/11] Propagate correctly errors from qxlhw_handle_to_bo Frediano Ziglio
2015-05-28  3:33   ` [Spice-devel] " Dave Airlie
2015-05-27 12:47 ` [PATCH 00/11] Miscellaneous stability patches Josh Boyer
2015-05-27 12:49   ` Josh Boyer
2015-05-27 13:28     ` Frediano Ziglio
2015-05-28  3:07       ` [Spice-devel] " Dave Airlie
2015-05-28 14:10         ` Frediano Ziglio
2015-05-29  5:48           ` Frans Klaver

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=1775637487.6685866.1432897912303.JavaMail.zimbra@redhat.com \
    --to=fziglio@redhat.com \
    --cc=airlied@gmail.com \
    --cc=airlied@linux.ie \
    --cc=airlied@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spice-devel@lists.freedesktop.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;
as well as URLs for NNTP newsgroup(s).