From: Haneen Mohammed <hamohammed.sa@gmail.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: rodrigosiqueiramelo@gmail.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/4] drm/vkms: Add functions to map GEM backing storage
Date: Tue, 10 Jul 2018 18:12:11 +0300 [thread overview]
Message-ID: <20180710151211.GA4114@haneen-vb> (raw)
In-Reply-To: <153121035583.18500.12528342272398519561@skylake-alporthouse-com>
On Tue, Jul 10, 2018 at 09:12:36AM +0100, Chris Wilson wrote:
> Quoting Haneen Mohammed (2018-07-09 16:44:26)
> > +struct page **get_pages(struct vkms_gem_object *vkms_obj)
> > +{
> > + struct drm_gem_object *gem_obj = &vkms_obj->gem;
> > + struct page **pages = vkms_obj->pages;
> > +
> > + if (!pages) {
> > + mutex_lock(&vkms_obj->pages_lock);
> > + pages = drm_gem_get_pages(gem_obj);
> > + if (IS_ERR(pages)) {
> > + mutex_unlock(&vkms_obj->pages_lock);
> > + return pages;
> > + }
> > +
> > + vkms_obj->pages = pages;
> > + mutex_unlock(&vkms_obj->pages_lock);
>
> You have a race here with two callers setting pages. Trivially you fix
> it by checking if (!pages) again inside the lock, but the lock is
> superfluous in this case:
> if (!vkms_obj->pages) {
> srtuct pages **pages;
>
> pages = drm_gem_get_pages(gem_obj);
> if (IS_ERR(pages))
> return pages;
>
> if (cmpxchg(&vkms_obj->pages, NULL, pages))
> put_pages(pages);
>
> /* barrier() is implied */
> }
>
> return vkms_obj->pages;
> -Chris
Thank you for the feedback!
- Haneen
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-07-10 15:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-09 15:42 [PATCH 0/4] Add infrastructure needed for CRC support Haneen Mohammed
2018-07-09 15:44 ` [PATCH 1/4] drm/vkms: Add functions to map GEM backing storage Haneen Mohammed
2018-07-10 8:00 ` Daniel Vetter
2018-07-10 8:12 ` Chris Wilson
2018-07-10 15:12 ` Haneen Mohammed [this message]
2018-07-09 15:46 ` [PATCH 2/4] drm/vkms: map/unmap buffers in [prepare/cleanup]_fb hooks Haneen Mohammed
2018-07-10 8:04 ` Daniel Vetter
2018-07-09 15:47 ` [PATCH 3/4] drm/vkms: Add atomic_helper_check_plane_state Haneen Mohammed
2018-07-10 8:07 ` Daniel Vetter
2018-07-09 15:48 ` [PATCH 4/4] drm/vkms: subclass CRTC state Haneen Mohammed
2018-07-10 8:10 ` Daniel Vetter
2018-07-10 15:13 ` Haneen Mohammed
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=20180710151211.GA4114@haneen-vb \
--to=hamohammed.sa@gmail.com \
--cc=chris@chris-wilson.co.uk \
--cc=dri-devel@lists.freedesktop.org \
--cc=rodrigosiqueiramelo@gmail.com \
/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).