From: Thomas Hellstrom <thellstrom@vmware.com>
To: Chris Wilson <chris@chris-wilson.co.uk>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Subject: Re: drm_read() to paged-out memory area
Date: Wed, 25 Nov 2015 07:46:09 +0100 [thread overview]
Message-ID: <56555931.702@vmware.com> (raw)
In-Reply-To: <20151124221420.GA16277@nuc-i3427.alporthouse.com>
Hi!
On 11/24/2015 11:14 PM, Chris Wilson wrote:
> On Tue, Nov 24, 2015 at 09:49:58PM +0100, Thomas Hellstrom wrote:
>> Hi, Chris,
>>
>> With your new (well sort of) implementation of drm_read() it looks to me
>> like a drm_read() to a paged out
>> memory area will always fail with -EFAULT. From what I can tell, there's
>> nothing there to generate a page-fault to get the destination paged back
>> into memory?
> True. Whoops.
>
> If we take the first event (remove it from the list from a second reader
> cannot see it), fail to copy it and replace it at the head, the second
> reader may then get an out-of-order event.
>
> First we need something like:
A simple solution would be to add a new file_priv::read_mutex around all
functions that pull
stuff from the event queue, so that adding takes only the spinlock,
reading takes the mutex and the spinlock. There aren't that many such
places from what I can tell. We probably should keep the mutex held
around the wait for data during a blocking read, but make sure that any
locks are taken interruptibly so that we can signal the waiting process.
/Thomas
>
> diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
> index c59ce4d0ef75..b9ca549e0e99 100644
> --- a/drivers/gpu/drm/drm_fops.c
> +++ b/drivers/gpu/drm/drm_fops.c
> @@ -509,14 +509,21 @@ ssize_t drm_read(struct file *filp, char __user *buffer,
> ret = 0;
> } else {
> struct drm_pending_event *e;
> + int unwritten;
>
> e = list_first_entry(&file_priv->event_list,
> struct drm_pending_event, link);
> if (e->event->length + ret > count)
> break;
>
> - if (__copy_to_user_inatomic(buffer + ret,
> - e->event, e->event->length)) {
> + list_del(&e->link);
> +
> + spin_unlock_irq(&dev->event_lock);
> + unwritten = copy_to_user(buffer + ret,
> + e->event, e->event->length);
> + spin_lock_irq(&dev->event_lock);
> + if (unwritten) {
> + list_add(&e->link, &file_priv->event_list);
> if (ret == 0)
> ret = -EFAULT;
> break;
> @@ -524,7 +531,6 @@ ssize_t drm_read(struct file *filp, char __user *buffer,
>
> file_priv->event_space += e->event->length;
> ret += e->event->length;
> - list_del(&e->link);
> e->destroy(e);
> }
> }
>
>
> A task for tomorrow (along with a suitable testcase).
> -Chris
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-11-25 6:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <5654CD76.8000107@vmware.com>
2015-11-24 22:14 ` drm_read() to paged-out memory area Chris Wilson
2015-11-25 6:46 ` Thomas Hellstrom [this message]
2015-11-25 11:24 ` Chris Wilson
2015-11-25 14:39 ` [PATCH 1/2] drm: Drop dev->event_lock spinlock around faulting copy_to_user() Chris Wilson
2015-11-25 14:39 ` [PATCH 2/2] drm: Serialise multiple event readers Chris Wilson
2015-11-25 14:44 ` Thomas Hellstrom
2015-11-25 14:56 ` Chris Wilson
2015-11-26 11:19 ` Thomas Hellstrom
2015-11-26 14:21 ` Daniel Vetter
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=56555931.702@vmware.com \
--to=thellstrom@vmware.com \
--cc=chris@chris-wilson.co.uk \
--cc=dri-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.