Commit Graph

791189 Commits

Author SHA1 Message Date
David Riley
3240ebbba9 UPSTREAM: drm/virtio: Fix cache entry creation race.
virtio_gpu_cmd_get_capset would check for the existence of an entry
under lock.  If it was not found, it would unlock and call
virtio_gpu_cmd_get_capset to create a new entry.  The new entry would
be added it to the list without checking if it was added by another
task during the period where the lock was not held resulting in
duplicate entries.

Compounding this issue, virtio_gpu_cmd_capset_cb would stop iterating
after find the first matching entry.  Multiple callbacks would modify
the first entry, but any subsequent entries and their associated waiters
would eventually timeout since they don't become valid, also wasting
memory along the way.

Signed-off-by: David Riley <davidriley@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190605234423.11348-3-davidriley@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 5934ce998f)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I29e15059f0603a9723891d23ac27d44c932ef0ad
2019-08-19 11:29:57 -07:00
David Riley
32bb6b58d0 UPSTREAM: drm/virtio: Wake up all waiters when capset response comes in.
If multiple callers occur simultaneously, wake them all up.

Signed-off-by: David Riley <davidriley@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190605234423.11348-2-davidriley@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 676a905b09)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ia6b18613dded27f78417c34d19604bbaa5e53901
2019-08-19 11:29:56 -07:00
David Riley
bc371c3453 UPSTREAM: drm/virtio: Ensure cached capset entries are valid before copying.
virtio_gpu_get_caps_ioctl could return success with invalid data if a
second caller to the function occurred after the entry was created in
virtio_gpu_cmd_get_capset but prior to the virtio_gpu_cmd_capset_cb
callback being called.  This could leak contents of memory as well
since the caps_cache allocation is done without zeroing.

Signed-off-by: David Riley <davidriley@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190605234423.11348-1-davidriley@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 7fdf478a43)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I4b984184f3ad77cc48e2d449abc031d1dc8530bd
2019-08-19 11:29:56 -07:00
Gurchetan Singh
72ace7ce28 UPSTREAM: drm/virtio: use u64_to_user_ptr macro
Other DRM drivers use it too.

Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190604234428.23252-1-gurchetansingh@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 4b013bb2d3)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ide0a298304b5ad0fbbd15130b96376b4303b84e5
2019-08-19 11:29:56 -07:00
Emil Velikov
830f4dad4e UPSTREAM: drm/virtio: remove irrelevant DRM_UNLOCKED flag
DRM_UNLOCKED doesn't do anything for non-legacy drivers. Remove it.

Cc: David Airlie <airlied@linux.ie>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190522154702.16269-2-emil.l.velikov@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit cbb56814fb)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I2a99803f684ed6a87b6ffa503502974c2d569f9d
2019-08-19 11:29:56 -07:00
Robert Foss
f586e0dc59 UPSTREAM: drm/virtio: Remove redundant return type
virtio_gpu_fence_emit() always returns 0, since it
has no error paths.

Consequently no calls for virtio_gpu_fence_emit()
use the return value, and it can be removed.

Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190506091034.30289-1-robert.foss@collabora.com
Suggested-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit fa2b7c21d9)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I3a9d3351efb7c89ec4109c66cb89249f79455593
2019-08-19 11:29:56 -07:00
Chia-I Wu
1041ceb0c3 UPSTREAM: drm/virtio: allocate fences with GFP_KERNEL
It was changed to GFP_ATOMIC in commit ec2f0577c (add & use
virtio_gpu_queue_fenced_ctrl_buffer) because the allocation happened
with a spinlock held.  That was no longer true after commit
9fdd90c0f (add virtio_gpu_alloc_fence()).

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190429221021.159784-1-olvaffe@gmail.com
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Gustavo Padovan <gustavo.padovan@collabora.com>
Cc: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 4d8979b3a6)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ia97ebceeefb3241e718871343dff6b1c6ba855c6
2019-08-19 11:29:56 -07:00
Chia-I Wu
1677d5031b UPSTREAM: drm/virtio: add trace events for commands
Trace when commands are queued for both ctrlq and cursorq.  Trace
when responses are received for ctrlq.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190429220825.156644-3-olvaffe@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 5daf8857c9)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ic24748031a4f42340d283ffaff64e88e0c04dc68
2019-08-19 11:29:56 -07:00
Chia-I Wu
1730e962ac UPSTREAM: drm/virtio: trace drm_fence_emit
For most drivers, drm_fence_init is followed by drm_fence_emit
immediately.  But for our driver, they are done separately.  We also
don't know the fence seqno until drm_fence_emit.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190429220825.156644-2-olvaffe@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 48ad7751db)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I4151334ae2b2955968e1451c35503fc6f4f44348
2019-08-19 11:29:56 -07:00
Chia-I Wu
76787a745d BACKPORT: drm/virtio: set seqno for dma-fence
This is motivated by having meaningful ftrace events, but it also
fixes use cases where dma_fence_is_later is called, such as in
sync_file_merge.

In other drivers, fence creation and cmdbuf submission normally
happen atomically,

  mutex_lock();
  fence = dma_fence_create(..., ++timeline->seqno);
  submit_cmdbuf();
  mutex_unlock();

and have no such issue.  But in our driver, because most ioctls
queue commands into ctrlq, we do not want to grab a lock.  Instead,
we set seqno to 0 when a fence is created, and update it when the
command is finally queued and the seqno is known.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190429220825.156644-1-olvaffe@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit efe2bf9655)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I2d865c14fa06e3a6fc86a23600c1678a39583c61
2019-08-19 11:29:56 -07:00
Gerd Hoffmann
7a086e5142 UPSTREAM: drm/virtio: move drm_connector_update_edid_property() call
drm_connector_update_edid_property can sleep, we must not
call it while holding a spinlock.  Move the callsite.

Fixes: b4b01b4995 ("drm/virtio: add edid support")
Reported-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Max Filippov <jcmvbkbc@gmail.com>
Tested-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190405044602.2334-1-kraxel@redhat.com
(cherry picked from commit 41de4be6f6)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ied8aeb059be4d10c5c67ab94d2a37f1d8129b77a
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
6c5eba8b29 UPSTREAM: drm/virtio: add missing drm_atomic_helper_shutdown() call.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20190401140306.28063-2-kraxel@redhat.com
(cherry picked from commit 7ff8a316d1)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ic4c2eb5bb4de639fc9fbae55b8848299acfe5f14
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
ef5be4af7e UPSTREAM: drm/virtio: rework resource creation workflow.
This patch moves the virtio_gpu_cmd_create_resource() call (which
notifies the host about the new resource created) into the
virtio_gpu_object_create() function.  That way we can call
virtio_gpu_cmd_create_resource() before ttm_bo_init(), so the host
already knows about the object when ttm initializes the object and calls
our driver callbacks.

Specifically the object is already created when the
virtio_gpu_ttm_tt_bind() callback invokes virtio_gpu_object_attach(),
so the extra virtio_gpu_object_attach() calls done after
virtio_gpu_object_create() are not needed any more.

The fence support for the create ioctl becomes a bit more tricky though.
The code moved into virtio_gpu_object_create() too.  We first submit the
(fenced) virtio_gpu_cmd_create_resource() command, then initialize the
ttm object, and finally attach just created object to the fence for the
command in case it didn't finish yet.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190318113332.10900-6-kraxel@redhat.com
(cherry picked from commit 530b28426a)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I08729493e57f858304d8e0986706fd88814f33e3
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
aa39f5f530 UPSTREAM: drm/virtio: params struct for virtio_gpu_cmd_create_resource_3d()
Add 3d resource parameters to virtio_gpu_object_params struct.  With
that in place we can use it for virtio_gpu_cmd_resource_create_3d()
calls.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190318113332.10900-5-kraxel@redhat.com
(cherry picked from commit fd4d6a4277)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I88e29aa79efb6455e98ea010a18dd0fe2d3725ba
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
2d20b3c324 UPSTREAM: drm/virtio: params struct for virtio_gpu_cmd_create_resource()
Add format, width and height fields to the virtio_gpu_object_params
struct.  With that in place we can use the parameter struct for
virtio_gpu_cmd_create_resource() calls too.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190318113332.10900-4-kraxel@redhat.com
(cherry picked from commit f9659329f2)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I9e24c7d58601ababe836aec628057893b90a2555
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
2898204d0e UPSTREAM: drm/virtio: use struct to pass params to virtio_gpu_object_create()
Create virtio_gpu_object_params, use that to pass object parameters to
virtio_gpu_object_create.  This is just the first step, followup patches
will add more parameters to the struct.  The plan is to use the struct
for all object parameters.

Drop unused "kernel" parameter for virtio_gpu_alloc_object(), it is
unused and always false.

Also drop "pinned" parameter.  virtio-gpu doesn't shuffle around
objects, so effecively they all are pinned anyway.  Hardcode
TTM_PL_FLAG_NO_EVICT so ttm knows.  Doesn't change much for the moment
as virtio-gpu supports TTM_PL_FLAG_TT only so there is no opportunity to
move around objects.  That'll probably change in the future though.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190318113332.10900-3-kraxel@redhat.com
(cherry picked from commit 4441235f95)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I9346eeaf87fcb23d94d3a3cea5d8e9f0ee9468ee
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
2ed8d2b814 UPSTREAM: drm/virtio: move virtio_gpu_object_{attach, detach} calls.
Drop the dummy ttm backend implementation, add a real one for
TTM_PL_FLAG_TT objects.  The bin/unbind callbacks will call
virtio_gpu_object_{attach,detach}, to update the object state
on the host side, instead of invoking those calls from the
move_notify() callback.

With that in place the move and move_notify callbacks are not
needed any more, so drop them.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190318113332.10900-2-kraxel@redhat.com
(cherry picked from commit 42ca472603)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I2cff23af466264a7b8fac284eceeb0618d31d400
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
ef02fe2372 UPSTREAM: drm/virtio: add virtio-gpu-features debugfs file.
This file prints which features the virtio-gpu device has.

Also add "virtio-gpu-" prefix to the existing fence file,
to make clear this is a driver-specific debugfs file.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190320083612.32067-1-kraxel@redhat.com
(cherry picked from commit 6bbeae35b6)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I35c5b4baadc240bbe0a452a1ee265be1dc2cd53c
2019-08-19 11:29:55 -07:00
YueHaibing
eb76c4cc93 UPSTREAM: drm/virtio: remove set but not used variable 'vgdev'
Fixes gcc '-Wunused-but-set-variable' warning:

drivers/gpu/drm/virtio/virtgpu_ttm.c: In function 'virtio_gpu_init_mem_type':
drivers/gpu/drm/virtio/virtgpu_ttm.c:117:28: warning:
 variable 'vgdev' set but not used [-Wunused-but-set-variable]

drivers/gpu/drm/virtio/virtgpu_ttm.c: In function 'virtio_gpu_bo_swap_notify':
drivers/gpu/drm/virtio/virtgpu_ttm.c:300:28: warning:
 variable 'vgdev' set but not used [-Wunused-but-set-variable]

It is never used since introduction in dc5698e80c ("Add virtio gpu driver.")

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190325092631.152060-1-yuehaibing@huawei.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit df16a224d2)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I7611c3ecfb028e0b2dd776b1f3234e91a5749a9a
2019-08-19 11:29:55 -07:00
Gerd Hoffmann
a4f8cf10cf BACKPORT: drm/virtio: implement prime export
Just run drm_prime_pages_to_sg() on the ttm pages list to get an
sg_table for export.  The pages list is created at object initialization
time, so there should be no need to handle an unpopulated page list.
Add a sanity check nevertheless.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190227144441.6755-4-kraxel@redhat.com
(cherry picked from commit 98f41dc3b3)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: If0ab11829ec7a6166928e26b8f75e1510742493e
2019-08-19 11:29:54 -07:00
Gerd Hoffmann
a4be74b232 UPSTREAM: drm/virtio: remove prime pin/unpin callbacks.
virtio-gpu objects never move around, so effectively they are
pinned all the time.  Therefore we don't need the (optional)
pin/unpin callbacks.  Remove them.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190227144441.6755-3-kraxel@redhat.com
(cherry picked from commit 873f51d434)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ic20a17cdaef7a4764c98c47e5afbe9d98766c93a
2019-08-19 11:29:54 -07:00
Gerd Hoffmann
9d1aee8d1d UPSTREAM: drm/virtio: implement prime mmap
Sync gem vm_node.start with ttm vm_node.start,
then we can just call drm_gem_prime_mmap().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190227144441.6755-2-kraxel@redhat.com
(cherry picked from commit c837da88c3)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I7265df5080459372958f32b0086dc9af877a35f4
2019-08-19 11:29:54 -07:00
Dave Airlie
3a34c7001d BACKPORT: Revert "drm/virtio: drop prime import/export callbacks"
This patch does more harm than good, as it breaks both Xwayland and
gnome-shell with X11.

Xwayland requires DRI3 & DRI3 requires PRIME.

X11 crash for obscure double-free reason which are hard to debug
(starting X11 by hand doesn't trigger the crash).

I don't see an apparent problem implementing those stub prime
functions, they may return an error at run-time, and it seems to be
handled fine by GNOME at least.

This reverts commit b318e3ff7c.
[airlied:
This broke userspace for virtio-gpus, and regressed things from DRI3 to DRI2.

This brings back the original problem, but it's better than regressions.]

Fixes: b318e3ff7c ("drm/virtio: drop prime import/export callbacks")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
(cherry picked from commit a0cecc23cf)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ie752f363df21c597e55cb1204cf464e4b1fd4b4b
2019-08-19 11:29:54 -07:00
Gerd Hoffmann
b3ca97fd4b UPSTREAM: drm/virtio: drop prime import/export callbacks
Also set prime_handle_to_fd and prime_fd_to_handle to NULL,
so drm will not advertive DRM_PRIME_CAP_{IMPORT,EXPORT} to
userspace.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190110111545.26768-1-kraxel@redhat.com
(cherry picked from commit b318e3ff7c)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I604c266f985e52764924eb6deb5363bc7c01853e
2019-08-19 11:29:54 -07:00
Gerd Hoffmann
67456f4233 UPSTREAM: drm/virtio: do NOT reuse resource ids
Bisected guest kernel changes crashing qemu.  Landed at
"6c1cd97bda drm/virtio: fix resource id handling".  Looked again, and
noticed we where not only leaking *some* ids, but *all* ids.  The old
code never ever called virtio_gpu_resource_id_put().

So, commit 6c1cd97bda effectively makes the linux kernel starting
re-using IDs after releasing them, and apparently virglrenderer can't
deal with that.  Oops.

This patch puts a temporary stopgap into place for the 5.0 release.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190208140409.15280-1-kraxel@redhat.com
(cherry picked from commit 16065fcdd1)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I606eecad29b877ad5da26dc9e4b5b71d99c8483d
2019-08-19 11:29:54 -07:00
Gerd Hoffmann
a62c058859 UPSTREAM: drm/virtio: drop virtio_gpu_fence_cleanup()
Just call drm_fence_put directly instead.
Also set vgfb->fence to NULL after dropping the reference.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181219122708.4586-4-kraxel@redhat.com
(cherry picked from commit cb66c6daa5)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I57ec957d37733db30aeb4b329415a1f81f59936f
2019-08-19 11:29:54 -07:00
Gerd Hoffmann
5186654ab5 UPSTREAM: drm/virtio: fix pageflip flush
Sending the flush command only makes sense if we actually have
a framebuffer attached to the scanout (handle != 0).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181219122708.4586-3-kraxel@redhat.com
(cherry picked from commit 6a01d277ac)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I9861c9e9c57c23fa2f6c67f0d5f6aac56bae5a4a
2019-08-19 11:29:54 -07:00
Gerd Hoffmann
fa3d9f0e0b UPSTREAM: drm/virtio: log error responses
If we got an error response code from the host, print it to the log.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181219122708.4586-2-kraxel@redhat.com
(cherry picked from commit 3630c2a24f)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I53e3c89cdf874e6cc0ea60ab6a619382d2c6ff23
2019-08-19 11:29:53 -07:00
Ezequiel Garcia
e8656dbe7a UPSTREAM: drm/virtio: Add missing virtqueue reset
As per the VirtIO spec, the virtqueues must be reset during cleanup
(see "3.3.1 Driver Requirements: Device Cleanup").

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190102175507.4653-2-ezequiel@collabora.com
(cherry picked from commit edde9fc58e)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I3d40dd7771bacb91b64d99b2139cbe7d0b203f5d
2019-08-19 11:29:53 -07:00
Ezequiel Garcia
c1b2cd0cfb UPSTREAM: drm/virtio: Remove incorrect kfree()
The virtio_gpu_output is a member of struct virtio_gpu_device
and is not a dynamically-allocated chunk, so it's wrong to kfree() it.
Removing it fixes a memory corruption BUG() that can be triggered
when the virtio-gpu driver is removed.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190102175507.4653-1-ezequiel@collabora.com
(cherry picked from commit 29cd2e2dac)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I57b78b049cecc5b8e89ea191dfa807e3725085ca
2019-08-19 11:29:53 -07:00
Gerd Hoffmann
c77fa1b8fc UPSTREAM: drm/virtio: switch to generic fbdev emulation
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181213134915.24722-1-kraxel@redhat.com
(cherry picked from commit 48a77d66cb)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I6f1506ee6bd92b1940b727549da45620cc7307c3
2019-08-19 11:29:53 -07:00
Gerd Hoffmann
b1007d2200 UPSTREAM: drm/virtio: virtio_gpu_cmd_resource_create_3d: drop unused fence arg
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181128151021.29565-3-kraxel@redhat.com
(cherry picked from commit d7a86dffc2)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I9f165ce8eb681cd11485da11975a91f1b1571255
2019-08-19 11:29:53 -07:00
Gerd Hoffmann
1e4ef4308a UPSTREAM: drm/virtio: fence: pass plain pointer
Since commit "9fdd90c0f4 drm/virtio: add virtio_gpu_alloc_fence()"
fences are not allocated any more by virtio_gpu_fence_emit().  So there
is no need to pass down a reference to the fence pointer, a plain
pointer is enough now.

Convert virtio_gpu_fence_emit() and callers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181128151021.29565-2-kraxel@redhat.com
(cherry picked from commit 4d55fd66b4)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ic4bc8f628716d230a88eba4f7f9c45cb3fc5a1bb
2019-08-19 11:29:53 -07:00
Gerd Hoffmann
d4f5248ba0 UPSTREAM: drm/virtio: add edid support
linux guest driver implementation of the VIRTIO_GPU_F_EDID feature.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20181030063206.19528-3-kraxel@redhat.com
(cherry picked from commit b4b01b4995)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Idb4433b65dfee118a3bb36bd6900bafff0f8c430
2019-08-19 11:29:53 -07:00
Gerd Hoffmann
03f5384082 UPSTREAM: virtio-gpu: add VIRTIO_GPU_F_EDID feature
The feature allows the guest request an EDID blob (describing monitor
capabilities) for a given scanout (aka virtual monitor connector).

It brings a new command message, which has just a scanout field (beside
the standard virtio-gpu header) and a response message which carries the
EDID data.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181030063206.19528-2-kraxel@redhat.com
(cherry picked from commit 610c0c2b28)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I1d4c11844307845b5829f1220b35938823ac7924
2019-08-19 11:29:53 -07:00
Colin Ian King
11b8dd566c UPSTREAM: drm/virtio: fix memory leak of vfpriv on error return path
The allocation for vfpriv is being leaked on an error return path,
fix this by kfree'ing it before returning.

Detected by CoverityScan, CID#1475380 ("Resource Leak")

Fixes: 6a37c49a94 ("drm/virtio: Handle context ID allocation errors")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181107203122.6861-1-colin.king@canonical.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 040b595a91)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I67f199a9fa2243a79927c908cbc4f47ac9b16f3d
2019-08-19 11:29:53 -07:00
Gustavo Padovan
3b90a75ad0 UPSTREAM: drm/virtio: bump driver version after explicit synchronization addition
To reflect the (backward compatible) changes in the uabi we are bumping
the driver's version.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181112165157.32765-5-robert.foss@collabora.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 6862965261)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I2bf6fa3700b6391e83a59007f98a128f89639557
2019-08-19 11:29:52 -07:00
Robert Foss
a62554de89 UPSTREAM: drm/virtio: add in/out fence support for explicit synchronization
When the execbuf call receives an in-fence it will get the dma_fence
related to that fence fd and wait on it before submitting the draw call.

On the out-fence side we get fence returned by the submitted draw call
and attach it to a sync_file and send the sync_file fd to userspace. On
error -1 is returned to userspace.

VIRTGPU_EXECBUF_FENCE_FD_IN & VIRTGPU_EXECBUF_FENCE_FD_OUT
are supported at the simultaneously and can be flagged
for simultaneously.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181112165157.32765-4-robert.foss@collabora.com
Suggested-by: Rob Herring <robh@kernel.org>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 2cd7b6f08b)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I169ce56d77083a8f7763225cd3e786ac057594c8
2019-08-19 11:29:52 -07:00
Robert Foss
54c534cf51 UPSTREAM: drm/virtio: add uapi for in and out explicit fences
Add a new field called fence_fd that will be used by userspace to send
in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of
dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the
out-fence.

On error -1 should be returned in the fence_fd field.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181112165157.32765-3-robert.foss@collabora.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit a56f9c868c)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Icdf083b865feb4e9b19998bc06ab18e2504608da
2019-08-19 11:29:52 -07:00
Robert Foss
cd33bd9aab UPSTREAM: drm/virtio: add virtio_gpu_alloc_fence()
Refactor fence creation, add fences to relevant GPU
operations and add cursor helper functions.

This removes the potential for allocation failures from the
cmd_submit and atomic_commit paths.
Now a fence will be allocated first and only after that
will we proceed with the rest of the execution.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181112165157.32765-2-robert.foss@collabora.com
Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 9fdd90c0f4)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I84003fd45344b1d3d368bd0d1669625c05fc11c2
2019-08-19 11:29:52 -07:00
Matthew Wilcox
39a21dedcf UPSTREAM: drm/virtio: Use IDAs more efficiently
0-based IDAs are more efficient than any other base.  Convert the
1-based IDAs to be 0-based.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20181030165352.13065-2-willy@infradead.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 2ae7f165c0)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I163fea3a31358bbaa478c1ce49b42de413ddc9d5
2019-08-19 11:29:52 -07:00
Matthew Wilcox
d620c93af6 UPSTREAM: drm/virtio: Handle error from virtio_gpu_resource_id_get
ida_alloc() can return -ENOMEM in the highly unlikely case we run out
of memory.  The current code creates an object with an invalid ID.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20181030165352.13065-1-willy@infradead.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 556c62e85f)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I0bc83d49fe6b40b6fb5d0e9b1da3cdf64b48f5b3
2019-08-19 11:29:52 -07:00
Sabyasachi Gupta
93d74d3618 UPSTREAM: gpu/drm/virtio/virtgpu_vq.c: Use kmem_cache_zalloc
Replaced kmem_cache_alloc + memset with kmem_cache_zalloc

Signed-off-by: Sabyasachi Gupta <sabyasachi.linux@gmail.com>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/5bc9ff7e.1c69fb81.105c2.1fef@mx.google.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 7fea1e0f38)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I1ec7f1c43f6e68bb2d25fde7ab523d21700a41f4
2019-08-19 11:29:52 -07:00
Matthew Wilcox
2e3622b76b UPSTREAM: drm/virtio: Handle context ID allocation errors
It is possible to run out of memory while allocating IDs.  The current
code would create a context with an invalid ID; change it to return
-ENOMEM to userspace.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20180926160031.15721-3-willy@infradead.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 6a37c49a94)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I009960f3fb372875f9e0fab403e01d1148bed23d
2019-08-19 11:29:52 -07:00
Matthew Wilcox
063ff2742e UPSTREAM: drm/virtio: Replace IDRs with IDAs
These IDRs were only being used to allocate unique numbers, not to look
up pointers, so they can use the more space-efficient IDA instead.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20180926160031.15721-2-willy@infradead.org

[ kraxel: resolve conflict ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 1938d1ae32)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ie7a81e0eedc7adf6ae7f4d75a0b7fa2533fae577
2019-08-19 11:29:51 -07:00
Gerd Hoffmann
1142e84ccb UPSTREAM: drm/virtio: fix resource id handling
Move virtio_gpu_resource_id_{get,put} to virtgpu_object.c and make them
static.  Allocate and free the id on creation and destroy, drop all
other calls.  That way objects have a valid handle for the whole
lifetime of the object.

Also fixes ids leaking.  Worst offender are dumb buffers, and I think
some error paths too.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181019061847.18958-7-kraxel@redhat.com
(cherry picked from commit 6c1cd97bda)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I4e1565804c923d18096edce63a5166015f4c9a4c
2019-08-19 11:29:51 -07:00
Gerd Hoffmann
bcc08f4c18 UPSTREAM: drm/virtio: drop resource_id argument.
We pass the obj anyway, so obj->hw_res_handle can be used instead
in virtio_gpu_object_attach() and virtio_gpu_cmd_create_resource().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181019061847.18958-6-kraxel@redhat.com
(cherry picked from commit 724cfdfd66)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Id1b7f9ff3a4e41fcc56e30ba6033caf12a252e43
2019-08-19 11:29:51 -07:00
Gerd Hoffmann
51face532e UPSTREAM: drm/virtio: use virtio_gpu_object->hw_res_handle in virtio_gpu_resource_create_ioctl()
Drop pointless res_id variable in virtio_gpu_resource_create_ioctl(),
just use the hw_res_handle field in virtio_gpu_object directly.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181019061847.18958-5-kraxel@redhat.com
(cherry picked from commit 70a0d6a377)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: Ie3ac3462acb28c780da97272466a6c3b2cc37b95
2019-08-19 11:29:51 -07:00
Gerd Hoffmann
68f8fc388a UPSTREAM: drm/virtio: use virtio_gpu_object->hw_res_handle in virtio_gpu_mode_dumb_create()
Drop pointless resid variable in virtio_gpu_mode_dumb_create(), just use
the hw_res_handle field in virtio_gpu_object directly.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181019061847.18958-4-kraxel@redhat.com
(cherry picked from commit c40336ba5e)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I151241825d4c8c51297d29bd229d3cd6ccf411af
2019-08-19 11:29:51 -07:00
Gerd Hoffmann
7a7d7a4a65 UPSTREAM: drm/virtio: use virtio_gpu_object->hw_res_handle in virtio_gpufb_create()
Drop pointless resid variable in virtio_gpufb_create(), just use
the hw_res_handle field in virtio_gpu_object directly.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181019061847.18958-3-kraxel@redhat.com
(cherry picked from commit ae0dc3cc38)
Signed-off-by: Greg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I3b9724f993a5407befd74534ec627703d49a91d5
2019-08-19 11:29:51 -07:00