Commit Graph

167 Commits

Author SHA1 Message Date
Frediano Ziglio
524acca643 windows: Disable code not working on Windows
- global signals;
- CLOEXEC flag;
- mmap and statistics;
- IPTOS_LOWDELAY flag;
- Unix sockets;
- sharing file descriptors through Unix sockets;
- TCP_CORK flag.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:22 +01:00
Frediano Ziglio
ed68d491fd Do not check for HAVE_CONFIG_H
This should always be defined and including config.h is a requirement.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-04-30 09:26:55 +01:00
Frediano Ziglio
e8fb0957ef red-worker: Use bool for driver_cap_monitors_config
Easier to understand.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-29 15:18:47 +00:00
Frediano Ziglio
ee5cdb7e2f Move image_compression field from RedWorker to DisplayChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
163b3c39b6 Check image compression value earlier
Do not check it after assigning to reds->config->image_compression,
check the value as soon as possible.
This prevent potential invalid settings.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
bd55e74f64 red-worker: Remove only assigned fields
DisplayChannelClient get them directly from reds (they are changed
only during initialisation so they can be read freely from any
thread).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Jonathon Jongsma
14403117b5 Make channel client callbacks virtual functions
Rather than having an API to register client callbacks for each channel
type, make them vfuncs.

Since the client callbacks are registered identically for each channel
of the same type, it doesn't make sense for to require these to be
registered separately for each object.  It's cleaner to have these be
per-class properties, so they've been converted to virtual functions.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
0399cd2f90 Move DisplayChannel callbacks from RedWorker to DisplayChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Jonathon Jongsma
b0eab081be Save running property in QXLState
This is a preparatory patch that states the running property in QXLState
and provides accessor functions that allows us to check whether the QXL
device is running from different threads.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
571dc645c5 Move thread/dispatching handling to RedChannel
Currently channel threading/handling is spread between RedQxl,
RedWorker and RedChannel.
Move more to RedChannel simplify RedQxl and RedWorker.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Christophe Fergeau
4f8db6fac3 worker: Fix potential sprintf overflow
If worker->qxl->id is bigger than 0x7ffffff (in other words, it's a
negative signed int) then
printf(worker_str, "display[%d]", worker->qxl->id);
will need:

"display[]" -> 9 bytes
%d -> 11 bytes

The trailing \0 will thus overflow our 20 bytes destination.
As QXLInstance::id should be an unsigned int, this commit changes the
format string to use %u. This also switches to snprintf.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-21 11:14:53 +00:00
Frediano Ziglio
bcf55b978f red-worker: Use mnemonic for statistic buffer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-21 11:14:30 +00:00
Jonathon Jongsma
6f90c003e8 Move channel registration to constructed vfunc
For the Display Channel and the Cursor channel, move the call to
reds_register_channel() to the _constructed() vfunc rather than calling
it explicitly from RedWorker. This matches what other channels do.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-15 09:01:28 +00:00
Frediano Ziglio
b4825e4b6b display-channel: Remove unused includes
display-channel.h is not using any of the definition from
these headers.
Adding a missing include to red-worker.c.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-01-30 15:44:47 +00:00
Christophe Fergeau
8669c933ff qxl: Add red_surface_cmd_{new, ref, unref} helpers
Currently, RedWorker is using stack-allocated variables for RedSurfaceCmd.
Surface commands are rare enough that we can dynamically allocate them
instead, and make the API in red-parse-qxl.h consistent with how other
QXL commands are handled.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:58 +00:00
Christophe Fergeau
decfe65d73 qxl: Add red_update_cmd_{new, ref, unref} helpers
Currently, RedUpdateCmd are allocated on the stack, and then
initialized/uninitialized with red_{get,put}_update_cmd
This makes the API inconsistent with what is being done for RedDrawable,
RedCursor and RedMessage. QXLUpdateCmd are not occurring very often,
we can dynamically allocate them instead, and get a consistent API.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:55 +00:00
Christophe Fergeau
74663be7fc qxl: Release QXL resources in red_put_update_cmd
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:52 +00:00
Christophe Fergeau
5840ba2a89 qxl: Add red_message_{new, ref, unref} helpers
Currently, RedMessage are allocated on the stack, and then
initialized/uninitialized with red_{get,put}_message
This makes the API inconsistent with what is being done for RedDrawable
and RedCursor. Since QXLMessage is just a (mostly unused/unsecure) debugging tool,
we can dynamically allocate it instead, and get a consistent API.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:49 +00:00
Christophe Fergeau
60c425011c qxl: Release QXL resource in red_put_message
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:43 +00:00
Christophe Fergeau
fb3c602d75 qxl: Add red_cursor_cmd_{new, ref, unref} helpers
Currently, the cursor channel is allocating RedCursorCmd instances itself, and then
calling into red-parse-qxl.h to initialize it, and doing something
similar when releasing the data. This commit moves this common code to
red-parse-qxl.[ch]
The ref/unref are not strictly needed, red_cursor_cmd_free() would
currently be enough, but this makes the API consistent with
red_drawable_{new,ref,unref}.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:36 +00:00
Christophe Fergeau
179134a4e8 qxl: Make red_{get, put}_drawable static
Rather than needing to call red_drawable_new() and then initialize it
with red_get_drawable(), we can improve slightly red_drawable new so
that red_drawable_{new,ref,unref} is all which is used by code out of
red-parse-qxl.c.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:31 +00:00
Christophe Fergeau
7f8228b540 qxl: Move red_drawable_unref/red_drawable_new
RedDrawable really is a RedDrawCmd which is parsed by red-parse-qxl.h
Moreover, red_drawable_ref() is already defined inline in
red-parse-qxl.h, and red_drawable_unref() is declared there too even if
its code is still in red-worker.c
This commit moves them close to the other functions creating/unref'ing
QXL commands parsed by red-parse-qxl.h.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-12-06 13:03:20 +00:00
Christophe Fergeau
8559a69fa6 worker: Fix 'seemless' typo in comment
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-07-20 09:15:33 +01:00
Frediano Ziglio
dde5fd04ad memslot: Remove error parameter from memslot_get_virt
Pointers to memory allocated in user space are never NULL.
The only exception can be if you explicitly map memory at zero.
There is however no reasons for such requirement and this practise
was also removed from Linux due to security reasons.
This API looks copied from a kernel environment where valid virtual
addresses can be NULL.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-03 12:23:54 +01:00
Christophe Fergeau
47ca1f0da0 channel: Remove unused 3rd red_channel_register_client_cbs() arg
It was probably meant to be used as a "user_data" argument for the
various callbacks, but turns out not to be used.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-21 17:54:27 +01:00
Frediano Ziglio
dbc4bcb24b red-worker: Remove not used include
poll is not used anymore by this file.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Lukáš Hrázký <lhrazky@redhat.com>
2018-06-20 14:20:59 +01:00
Christophe Fergeau
612c94c61b worker: Remove display_is_connected()
It's only called once, and when it's called, we will have dereferenced
worker->display_channel a few lines before in
display_channel_set_monitors_config_to_primary(), so this cannot be
NULL. The 'if (worker->display_channel)' check can thus be removed, so
display_is_connected() becomes just red_channel_is_connected().

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 17:29:06 +01:00
Christophe Fergeau
ca8ffdb8ef worker: Use more local vars in dev_create_primary_surface
There's already a 'display' variable equal to worker->display_channel
which is not consistently used. This commit also adds a new 'channel'
local variable to limit the number of  upcasts to RedChannel.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 17:29:06 +01:00
Christophe Fergeau
b547919190 cursor: Delay release of QXL guest cursor resources
There's an implicit API/ABI contract between QEMU and SPICE that SPICE
will keep the guest QXL resources alive as long as QEMU can hold a
pointer to them. This implicit contract was broken in 1c6e7cf7 "Release
cursor as soon as possible", causing crashes at migration time.
While the proper fix would be in QEMU so that spice-server does not need
to have that kind of knowledge regarding QEMU internal implementation,
this commit reverts to the pre-1c6e7cf7 behaviour to avoid a regression
while QEMU is being fixed.

This version of the fix is based on a suggestion from Frediano Ziglio.

https://bugzilla.redhat.com/show_bug.cgi?id=1540919

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-04-16 11:46:01 +02:00
Frediano Ziglio
7a25e46c8b Minor compatibility with FreeBSD system
Some additional header are needed to avoid undefined types.
SOL_TCP and IPPROTO_TCP have the same value in Linux but SOL_TCP
is not defined in FreeBSD.
Provide pthread_setname_np using pthread_set_name_np (same parameters).

Patch is based on a patch from Oleg Ginzburg <olevole@olevole.ru>

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-15 16:52:57 +00:00
Christophe Fergeau
dd8e205aaf worker: Remove unneeded include
Nothing seems to be using openssl in red-worker.c

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-12-08 15:22:16 +01:00
Frediano Ziglio
9872e7b8e5 Reduce dependencies from red-qxl.h
This header is mainly exporting functions to handle public
interface for the QXL devices.
Avoid spreading its inclusion including this header in other
headers.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-12-01 22:19:31 +00:00
Jonathon Jongsma
2e08354ce1 Rename Stream to VideoStream
To prevent confusion between Stream (a video stream) and RedStream (a
generic data stream between client and server), change the name to
VideoStream to be more explicit about what it is.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-11-30 11:51:09 -06:00
Frediano Ziglio
b83eb77c30 red-qxl: Remove surface_create field
This field was used just to store a value and retrieve again
while we can just pass it instead.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-10-17 21:56:20 +01:00
Frediano Ziglio
04bc835326 worker: Use GLib memory functions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-10-11 12:52:17 +01:00
Frediano Ziglio
a99043771a Start using GLib memory allocation
Start reducing the usage of spice_new*/spice_malloc allocations.
They were designed in a similar way to GLib ones.
Now that we use GLib make sense to remove them.
However the versions we support for GLib can use different memory
allocators so we have to match g_free with GLib allocations
and spice_* ones (which uses always malloc allocator) with free().
This patch remove some easy ones.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-09-19 16:17:10 +01:00
Frediano Ziglio
eb6c8ba025 red-qxl: Remove AsyncCommand
This structure was used to store the cookie for the async
reply and the message for the generic async callback.
Most async messages do not require extra action beside sending back the
cookie for the reply so instead of having a switch on the message type
in red_qxl_async_complete, this commit moves the message-specific
behaviour to the callers, which allows us to store the cookie directly
in RedWorkerMessageAsync rather than needing an intermediate
AsyncCommand structure.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-09-18 17:49:25 +01:00
Christophe Fergeau
685a6288f3 channel: Call red_channel_disconnect_if_pending_send() from red_channel_wait_all_sent()
red_channel_disconnect_if_pending_send() and red_channel_wait_all_sent() are
always called together, we can remove one of the 2 methods.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-09-12 18:19:33 +02:00
Frediano Ziglio
08dd9c4f48 red-worker: Start processing commands as soon as possible
When the worker is started it could take a while to start processing
commands.
The reason is that the dispatcher handler is called after the worker
so GLib will receive a FALSE answer to both prepare and check
callbacks of the RedWorkerSource causing GLib to wait till another
event is received.
This is a regression since the introduction of GLib event loop, before
the command processing was always attempted after any events.
Commands (from QXL interface for cursor and display) are processed
during the RedWorkerSource dispatch so if they are not processed just
when the VM is started they will be processed on next event which
could be from dispatcher (main thread requests), from existing
connections or from pending timers. However in the case there are no
clients connected and no other requests from main thread the worker
thread won't process them.
Setting the event_timeout to 0 cause the prepare callback to return
TRUE so GLib will dispatch the RedWorkerSource.
This was discovered attempting to use the tests in server/tests
directory to reproduce a leak in RedWorker.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-09-12 14:15:39 +01:00
Jonathon Jongsma
439fa1574f Dispatcher: remove async_done callback
This callback was only executed for message types that were registered
with DISPATCHER_ASYNC ack type. However, the async_done handler was
called immediately after the message-specific handler and was called in
the same thread, so the async_done stuff can just as easily be done from
within the message-specific handler. This allows to simplify the
dispatcher_register_handler() method to simply require a boolean
argument for whether the message type requires an ACK or not.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-09-07 10:22:15 -05:00
Frediano Ziglio
8e7d5ac580 cursor-channel: Remove dependency from QXL
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-09-07 06:41:49 +01:00
Frediano Ziglio
1c6e7cf73e Release cursor as soon as possible
Cursor resources (basically the shape of it) was retained till
it was used however it was copied so there were no reason to not release
this resource.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-09-07 06:41:17 +01:00
Frediano Ziglio
662d197a7d red-worker: Fix leak processing update commands
Is possible to have a leak processing update commands if
the update command is synchronous and the rectangle list
is empty. Note that Qemu always pass an empty list.

If the list is empty display_channel_update fill the list.
This is used to send back the list in case of asynchronous
requests. But in handle_dev_update_async (the callback that
handle the asynchronous case) the list is correctly freed.

This was discovered by accident looking at the code.

Reproduced with a Windows recording file using GCC address
sanitizer and this patch to spice-server-replay:

  --- a/server/red-replay-qxl.c
  +++ b/server/red-replay-qxl.c
  @@ -1280,7 +1280,13 @@ static void replay_handle_dev_input(QXLWorker *worker, SpiceReplay *replay,
           replay->created_primary = FALSE;
           worker->destroy_surfaces(worker);
           break;
  -    case RED_WORKER_MESSAGE_UPDATE:
  +    case RED_WORKER_MESSAGE_UPDATE: {
  +        static uint8_t count = 0;
  +        QXLRect dummy;
  +        QXLRect update = { 0, 0, 100, 100 };
  +        count ^= 1;
  +        worker->update_area(worker, 0, &update, count ? &dummy : NULL, count ? 1 : 0, 0);
  +        } break;
           // XXX do anything? we record the correct bitmaps already.
       case RED_WORKER_MESSAGE_DISPLAY_CONNECT:
           // we want to ignore this one - it is sent on client connection, we

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-09-06 12:54:42 +01:00
Frediano Ziglio
f712f2637d red-worker: Set thread name if possible
Name will be visible in debugger and /proc filesystem

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-08-31 17:36:18 +01:00
Frediano Ziglio
d248714439 red-qxl: Reference RCC pointer in migration request
The message is asynchronous so to avoid the object to potentially
been released before being processed keep a strong reference to
it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-08-31 17:28:37 +01:00
Christophe Fergeau
b89bd9ef9a worker: Fix 'immediatly' typo in comment
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-08-31 15:51:57 +02:00
Christophe Fergeau
ab1348486d worker: Simplify flush_commands()
red_disconnect_display() is duplicating what red_channel_disconnect()
already does, so red_disconnect_display() and red_disconnect_cursor()
are actually identical code-wise. We can directly call
red_channel_disconnect() from flush_commands() rather than passing a
'red_disconnect_t disconnect' argument to that function.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-08-31 15:51:57 +02:00
Christophe Fergeau
becd0d30f6 cursor: Remove cursor_channel_disconnect()
cursor_channel_disconnect() calls
cursor_channel_client_reset_cursor_cache() on all CursorChannelClient
associated with the current CursorChannel before calling
red_channel_disconnect().

red_channel_disconnect() will iterate over all CursorChannelClient
calling red_channel_client_disconnect(), which will eventually call
CursorChannelClient::on_disconnect. This will in turn
cursor_channel_client_reset_cursor_cache(), so calling it in
cursor_channel_disconnect() before calling red_channel_disconnect() is
redundant.

cursor_channel_disconnect() can thus be replaced by a direct call to
red_channel_disconnect().

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-08-31 15:51:57 +02:00
Frediano Ziglio
975d10c9ef red-qxl: Avoid using dangling pointers to RedClient
A RedClient can be freed from the main thread following a main channel
disconnection (reds_client_disconnect). This can happen while another
thread is allocating a new channel client for that client.
To prevent the usage of a pointer which can be invalid
take ownership of the pointer.
Note that we don't need this when disconnecting as disconnection is
done synchronously (the dispatch messages are registered with
DISPATCH_ACK).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-08-29 16:28:47 +01:00
Frediano Ziglio
b496e4a037 worker: Add some loop statistics
Trace the number of loops done processing display commands
and the number of loops in which the queue was full.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-08-29 16:18:41 +01:00