aboutsummaryrefslogtreecommitdiff
path: root/util/module.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2021-06-24 12:38:20 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2021-07-09 18:20:27 +0200
commitd7795d3cc52fa8c297908912a9541ecd4f810f03 (patch)
tree6993231691049b4c57dcbb1d9f4fbc0cedf27e78 /util/module.c
parent819b8b13c1bc48080f4ca526c6e12d58a27ea887 (diff)
modules: check arch and block load on mismatch
Add module_allow_arch() to set the target architecture. In case a module is limited to some arch verify arches match and ignore the module if not. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Jose R. Ziviani <jziviani@suse.de> Message-Id: <20210624103836.2382472-19-kraxel@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/module.c')
-rw-r--r--util/module.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/util/module.c b/util/module.c
index acaaecad56..065aed09ff 100644
--- a/util/module.c
+++ b/util/module.c
@@ -117,12 +117,33 @@ static const QemuModinfo module_info_stub[] = { {
/* end of list */
} };
static const QemuModinfo *module_info = module_info_stub;
+static const char *module_arch;
void module_init_info(const QemuModinfo *info)
{
module_info = info;
}
+void module_allow_arch(const char *arch)
+{
+ module_arch = arch;
+}
+
+static bool module_check_arch(const QemuModinfo *modinfo)
+{
+ if (modinfo->arch) {
+ if (!module_arch) {
+ /* no arch set -> ignore all */
+ return false;
+ }
+ if (strcmp(module_arch, modinfo->arch) != 0) {
+ /* mismatch */
+ return false;
+ }
+ }
+ return true;
+}
+
static int module_load_file(const char *fname, bool mayfail, bool export_symbols)
{
GModule *g_module;
@@ -224,6 +245,13 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
g_hash_table_add(loaded_modules, module_name);
for (modinfo = module_info; modinfo->name != NULL; modinfo++) {
+ if (modinfo->arch) {
+ if (strcmp(modinfo->name, module_name) == 0) {
+ if (!module_check_arch(modinfo)) {
+ return false;
+ }
+ }
+ }
if (modinfo->deps) {
if (strcmp(modinfo->name, module_name) == 0) {
/* we depend on other module(s) */
@@ -345,6 +373,7 @@ void qemu_load_module_for_opts(const char *group)
#else
+void module_allow_arch(const char *arch) {}
void qemu_load_module_for_opts(const char *group) {}
void module_load_qom_one(const char *type) {}
void module_load_qom_all(void) {}