[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 18/34] modules: check arch and block load on mismatch
From: |
Gerd Hoffmann |
Subject: |
[PATCH v4 18/34] modules: check arch and block load on mismatch |
Date: |
Thu, 24 Jun 2021 12:38:20 +0200 |
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>
---
include/qemu/module.h | 1 +
softmmu/vl.c | 3 +++
util/module.c | 29 +++++++++++++++++++++++++++++
3 files changed, 33 insertions(+)
diff --git a/include/qemu/module.h b/include/qemu/module.h
index a98748d501d3..7f4b1af8198c 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -72,6 +72,7 @@ void module_call_init(module_init_type type);
bool module_load_one(const char *prefix, const char *lib_name, bool mayfail);
void module_load_qom_one(const char *type);
void module_load_qom_all(void);
+void module_allow_arch(const char *arch);
/*
* module info annotation macros
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 5c26e80126db..a70e7b4658e8 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -126,6 +126,8 @@
#include "sysemu/iothread.h"
#include "qemu/guest-random.h"
+#include "config-host.h"
+
#define MAX_VIRTIO_CONSOLES 1
typedef struct BlockdevOptionsQueueEntry {
@@ -2725,6 +2727,7 @@ void qemu_init(int argc, char **argv, char **envp)
#ifdef CONFIG_MODULES
module_init_info(qemu_modinfo);
+ module_allow_arch(TARGET_NAME);
#endif
qemu_init_subsystems();
diff --git a/util/module.c b/util/module.c
index acaaecad56c9..065aed09ffef 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) {}
--
2.31.1
- [PATCH v4 09/34] modules: add usb-redir module annotations, (continued)
- [PATCH v4 09/34] modules: add usb-redir module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 08/34] modules: add audio module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 10/34] modules: add ccid module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 11/34] modules: add ui module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 12/34] modules: add s390x module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 13/34] modules: add block module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 14/34] modules: use modinfo for dependencies, Gerd Hoffmann, 2021/06/24
- [PATCH v4 15/34] modules: use modinfo for qom load, Gerd Hoffmann, 2021/06/24
- [PATCH v4 17/34] modules: add tracepoints, Gerd Hoffmann, 2021/06/24
- [PATCH v4 16/34] modules: use modinfo for qemu opts load, Gerd Hoffmann, 2021/06/24
- [PATCH v4 18/34] modules: check arch and block load on mismatch,
Gerd Hoffmann <=
- [PATCH v4 19/34] modules: check arch on qom lookup, Gerd Hoffmann, 2021/06/24
- [PATCH v4 20/34] modules: target-specific module build infrastructure, Gerd Hoffmann, 2021/06/24
- [PATCH v4 23/34] modules: module.h kerneldoc annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 21/34] modules: add documentation for module sourcesets, Gerd Hoffmann, 2021/06/24
- [PATCH v4 22/34] modules: add module_obj() note to QOM docs, Gerd Hoffmann, 2021/06/24
- [PATCH v4 24/34] modules: hook up modules.h to docs build, Gerd Hoffmann, 2021/06/24
- [PATCH v4 25/34] accel: autoload modules, Gerd Hoffmann, 2021/06/24
- [PATCH v4 26/34] accel: add qtest module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 27/34] accel: build qtest modular, Gerd Hoffmann, 2021/06/24
- [PATCH v4 29/34] accel: build tcg modular, Gerd Hoffmann, 2021/06/24