2012-06-25 23:03:47 +08:00
|
|
|
/*
|
|
|
|
* QEMU Random Number Generator Backend
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-01-30 01:49:54 +08:00
|
|
|
#include "qemu/osdep.h"
|
2013-04-08 22:55:25 +08:00
|
|
|
#include "sysemu/rng.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 16:01:28 +08:00
|
|
|
#include "qapi/error.h"
|
2012-12-18 01:19:43 +08:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2019-05-23 22:35:07 +08:00
|
|
|
#include "qemu/module.h"
|
2014-01-17 00:34:38 +08:00
|
|
|
#include "qom/object_interfaces.h"
|
2012-06-25 23:03:47 +08:00
|
|
|
|
|
|
|
void rng_backend_request_entropy(RngBackend *s, size_t size,
|
|
|
|
EntropyReceiveFunc *receive_entropy,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
2016-03-03 16:37:18 +08:00
|
|
|
RngRequest *req;
|
2012-06-25 23:03:47 +08:00
|
|
|
|
|
|
|
if (k->request_entropy) {
|
2016-03-03 16:37:18 +08:00
|
|
|
req = g_malloc(sizeof(*req));
|
|
|
|
|
|
|
|
req->offset = 0;
|
|
|
|
req->size = size;
|
|
|
|
req->receive_entropy = receive_entropy;
|
|
|
|
req->opaque = opaque;
|
|
|
|
req->data = g_malloc(req->size);
|
|
|
|
|
|
|
|
k->request_entropy(s, req);
|
|
|
|
|
2016-03-03 21:16:11 +08:00
|
|
|
QSIMPLEQ_INSERT_TAIL(&s->requests, req, next);
|
2012-06-25 23:03:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool rng_backend_prop_get_opened(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
RngBackend *s = RNG_BACKEND(obj);
|
|
|
|
|
|
|
|
return s->opened;
|
|
|
|
}
|
|
|
|
|
2014-01-17 00:34:39 +08:00
|
|
|
static void rng_backend_complete(UserCreatable *uc, Error **errp)
|
2012-06-25 23:03:47 +08:00
|
|
|
{
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-08 00:05:54 +08:00
|
|
|
object_property_set_bool(OBJECT(uc), "opened", true, errp);
|
2012-06-25 23:03:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
RngBackend *s = RNG_BACKEND(obj);
|
|
|
|
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
2014-04-25 18:44:22 +08:00
|
|
|
Error *local_err = NULL;
|
2012-06-25 23:03:47 +08:00
|
|
|
|
|
|
|
if (value == s->opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value && s->opened) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_PERMISSION_DENIED);
|
2012-06-25 23:03:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k->opened) {
|
2014-04-25 18:44:22 +08:00
|
|
|
k->opened(s, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-25 23:03:47 +08:00
|
|
|
}
|
|
|
|
|
2014-04-25 18:44:22 +08:00
|
|
|
s->opened = true;
|
2012-06-25 23:03:47 +08:00
|
|
|
}
|
|
|
|
|
2016-03-03 16:37:17 +08:00
|
|
|
static void rng_backend_free_request(RngRequest *req)
|
|
|
|
{
|
|
|
|
g_free(req->data);
|
|
|
|
g_free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rng_backend_free_requests(RngBackend *s)
|
|
|
|
{
|
2016-03-03 21:16:11 +08:00
|
|
|
RngRequest *req, *next;
|
2016-03-03 16:37:17 +08:00
|
|
|
|
2016-03-03 21:16:11 +08:00
|
|
|
QSIMPLEQ_FOREACH_SAFE(req, &s->requests, next, next) {
|
|
|
|
rng_backend_free_request(req);
|
2016-03-03 16:37:17 +08:00
|
|
|
}
|
|
|
|
|
2016-03-03 21:16:11 +08:00
|
|
|
QSIMPLEQ_INIT(&s->requests);
|
2016-03-03 16:37:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rng_backend_finalize_request(RngBackend *s, RngRequest *req)
|
|
|
|
{
|
2016-03-03 21:16:11 +08:00
|
|
|
QSIMPLEQ_REMOVE(&s->requests, req, RngRequest, next);
|
2016-03-03 16:37:17 +08:00
|
|
|
rng_backend_free_request(req);
|
|
|
|
}
|
|
|
|
|
2012-06-25 23:03:47 +08:00
|
|
|
static void rng_backend_init(Object *obj)
|
|
|
|
{
|
2016-03-03 21:16:11 +08:00
|
|
|
RngBackend *s = RNG_BACKEND(obj);
|
|
|
|
|
|
|
|
QSIMPLEQ_INIT(&s->requests);
|
|
|
|
|
2012-06-25 23:03:47 +08:00
|
|
|
object_property_add_bool(obj, "opened",
|
|
|
|
rng_backend_prop_get_opened,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 23:29:22 +08:00
|
|
|
rng_backend_prop_set_opened);
|
2012-06-25 23:03:47 +08:00
|
|
|
}
|
|
|
|
|
2016-03-03 16:37:17 +08:00
|
|
|
static void rng_backend_finalize(Object *obj)
|
|
|
|
{
|
|
|
|
RngBackend *s = RNG_BACKEND(obj);
|
|
|
|
|
|
|
|
rng_backend_free_requests(s);
|
|
|
|
}
|
|
|
|
|
2014-01-17 00:34:39 +08:00
|
|
|
static void rng_backend_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
|
|
|
|
|
|
|
|
ucc->complete = rng_backend_complete;
|
|
|
|
}
|
|
|
|
|
2013-01-10 23:19:07 +08:00
|
|
|
static const TypeInfo rng_backend_info = {
|
2012-06-25 23:03:47 +08:00
|
|
|
.name = TYPE_RNG_BACKEND,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.instance_size = sizeof(RngBackend),
|
|
|
|
.instance_init = rng_backend_init,
|
2016-03-03 16:37:17 +08:00
|
|
|
.instance_finalize = rng_backend_finalize,
|
2012-06-25 23:03:47 +08:00
|
|
|
.class_size = sizeof(RngBackendClass),
|
2014-01-17 00:34:39 +08:00
|
|
|
.class_init = rng_backend_class_init,
|
2012-06-25 23:03:47 +08:00
|
|
|
.abstract = true,
|
2014-01-17 00:34:38 +08:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_USER_CREATABLE },
|
|
|
|
{ }
|
|
|
|
}
|
2012-06-25 23:03:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&rng_backend_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types);
|