Loading new machines and devices from external modules
PATCH v3 1/1 Loading new machines and devices from external modules
From: "Drap, Anton" <[email protected]>
Current QEMU politics is to have all the supported
platforms inside QEMU source tree, but actually simulator core development, development of the devices standard library and development of virtual platforms are three different tasks.
Moreover different people interested in different parts of QEMU.
QEMU core developers not interested in supporting and maintaining tons of platforms available on the market. Virtual platform developers not interested and usually don’t have resources to merge their changes upstream. So we have a lots of abandoned QEMU forks for different platforms.
For example we’re now working on Raspberry Pi 4b implementation for our
internal needs and we’re planning to merge it upstream. It’s based on some QEMU fork author of which wasn’t able to complete it and commit upstream. And it can’t be used with later QEMU without some efforts to port it to newer QEMU version. Nobody supports and maintaining it since constant efforts necessary to be in sync with QEMU mainline. So my opinion is that core development, core device library and virtual platform development should be divided to make life easier for everybody. And this changes is first step to it.
About legal reasons and GPL violations. Possibility to make .so
with machine separately and load it without providing sources is a legal risk and can’t be completely solved with technical actions. Ban on external modules just makes it more difficult for everybody to use not upstream code (including GPL violators, but not only for them) and doesn’t block ability to distribute full QEMU fork with closed models without providing sources. So I don’t see any reason to make technical limitations which actually can’t solve legal problem.
This patch is to add two parameters add_machine and add_modinfo.add_machine is to add machines from external modules. add_modinfo is to add devices from external modules, needed for a new machine, for example.
Additional, 'arch' parameter of QemuModinfo is changed to a list.
---
v2: subject is changed
v3:
- description is changed
- rebased on last master
--- include/qapi/qmp/qjson.h | 2 + include/qemu/module.h | 4 +- qemu-options.hx | 38 ++++++ qobject/qjson.c | 14 ++ scripts/modinfo-generate.py | 7 +- softmmu/vl.c | 14 ++ util/module.c | 249 +++++++++++++++++++++++++++++++++++- 7 files changed, 320 insertions(+), 8 deletions(-)
include/qapi/qmp/qjson.h +2 -0
@@ -25,6 +25,8 @@ QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap)QDict *qdict_from_jsonf_nofail (const char *string, ...)G_GNUC_PRINTF (1 ,2 ); +QDict *qdict_from_json_nofail_nofmt (const char *string); +GString *qobject_to_json (const QObject *obj);GString *qobject_to_json_pretty (const QObject *obj,bool pretty);
include/qemu/module.h +3 -1
@@ -73,6 +73,8 @@ 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); +bool load_external_modules (const char *mods_list); +bool add_modinfo (const char *filename);/** * DOC: module info annotation macros
@@ -154,7 +156,7 @@ void module_allow_arch(const char *arch);typedef struct QemuModinfo QemuModinfo ;struct QemuModinfo {const char *name; -const char *arch; +const char **arch;const char **objs;const char **deps;const char **opts;
qemu-options.hx +38 -0
@@ -5540,6 +5540,44 @@ SRST (qemu) qom-set /objects/iothread1 poll-max-ns 100000 ERST +DEF("add_machines", HAS_ARG, QEMU_OPTION_add_machines, \ + "-add_machines libname[,...]\n", + QEMU_ARCH_ALL) +SRST +``-add_machines libname[,...]`` + Add machines from external modules. + For example: + + :: + + -add_machines custom-arm-machine,custom-arm-machine2 +ERST + +DEF("add_modinfo", HAS_ARG, QEMU_OPTION_add_modinfo, \ + "-add_modinfo filename\n", + QEMU_ARCH_ALL) +SRST +``-add_modinfo filename`` + Extend modinfo from file. Used to add devices from external modules. + Modinfo extention file is a JSON file with dictionary of modules: + { + "short name of module": {"name": "module-name", + "arch": ["supported_arch_1", "supported_arch_2",], + "objs": ["object1_description", "object2_description",], + "deps": ["depend_of_module_name1", "depend_of_module_name2",], + "opts": ["option1", "option2",] + } + } + + Architectures should be designated as they are printed by ./configure --help in target list + without "-softmmu" or "-linux-user" suffixes. e.g.: "arm", "x86_64", "riscv32", etc. + + For example: + + :: + + -add_modinfo modinfo_extention.json +ERST HXCOMM This is the last statement. Insert new options before this line!
qobject/qjson.c +14 -0
@@ -148,6 +148,20 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...)return qdict; } +/* +* Parse @string as JSON object without %-escapes interpolated. +* Abort on error. Do not use with untrusted @string. +* Return the resulting QDict. It is never null. +*/ +QDict *qdict_from_json_nofail_nofmt (const char *string) +{ +QDict *qdict; + qdict =qobject_to (QDict,qobject_from_json (string, &error_abort)); +assert (qdict); +return qdict; +} + +static void to_json (JSONWriter *writer,const char *name,const QObject *obj) {
scripts/modinfo-generate.py +3 -4
@@ -33,7 +33,7 @@ def parse_line(line): return (kind, data) def generate(name, lines, enabled): - arch = "" + arch = [] objs = [] deps = [] opts = []
@@ -47,7 +47,7 @@ def generate(name, lines, enabled): elif kind == 'opts': opts.append(data) elif kind == 'arch': - arch = data; + arch.append(data) elif kind == 'kconfig': # don't add a module which dependency is not enabled # in kconfig
@@ -61,8 +61,7 @@ def generate(name, lines, enabled): exit(1) print(" .name = \"%s\"," % name) - if arch != "": - print(" .arch = %s," % arch) + print_array("arch", arch) print_array("objs", objs) print_array("deps", deps) print_array("opts", opts)
softmmu/vl.c +14 -0
@@ -3460,6 +3460,20 @@ void qemu_init(int argc, char **argv, char **envp)case QEMU_OPTION_enable_sync_profile:qsp_enable ();break ; +case QEMU_OPTION_add_machines: +info_report ("External machines loading: %s" , optarg); +if (!load_external_modules (optarg)) { +error_report ("Modules loading error. Modules %s" , optarg); +exit (1 ); + } +break ; +case QEMU_OPTION_add_modinfo: +info_report ("Modinfo parsing: %s" , optarg); +if (!add_modinfo (optarg)) { +error_report ("Modinfo (%s) adding error" , optarg); +exit (1 ); + } +break ;case QEMU_OPTION_nouserconfig:/* Nothing to be parsed here. Especially, do not error out below. */ break ;
util/module.c +246 -3
285 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 8 lines · Drap Anton
From: "Drap, Anton" <[email protected]>
This patch is to add two parameters
add_machineandadd_modinfo.add_machineis to add machines from external modules.add_modinfois to add devices from external modules, needed for a new machine, for example.
Additional, 'arch' parameter of QemuModinfo is changed to a list.
I don't think there's much point in your continuing to post versions of this patchset, because the answer remains "we don't want to do this, as a policy and design decision". Until and unless you persuade us that it's a good idea to change that decision, time spent on code changes doesn't seem like a good use of effort to me.
thanks
-- PMM
Hi Peter,
Anton previously sent explanation of our position. Nobody commented. Could you please comment on it? It's necessary for us to better understand your position. From our point of view technical ban of external modules loading doesn't solve any of mentioned problems, but makes VP developer life harder.
Best Regards,
Vladimir
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, August 22, 2022 12:23 PM
To: Drap Anton <[email protected]>
Cc: [email protected]; Sebelev, Vladimir <[email protected]>; Drap, Anton <[email protected]>; Daniel P. Berrange <[email protected]>; Markus Armbruster <[email protected]>
Subject: Re: [PATCH v3] Loading new machines and devices from external modules
Quoted 8 lines · Drap Anton
From: "Drap, Anton" <[email protected]>
This patch is to add two parameters
add_machineandadd_modinfo.add_machineis to add machines from external modules.add_modinfois to add devices from external modules, needed for a new machine, for example.
Additional, 'arch' parameter of QemuModinfo is changed to a list.
I don't think there's much point in your continuing to post versions of this patchset, because the answer remains "we don't want to do this, as a policy and design decision". Until and unless you persuade us that it's a good idea to change that decision, time spent on code changes doesn't seem like a good use of effort to me.
thanks
-- PMM
Quoted 7 lines · Vladimir
Hi Peter,
Anton previously sent explanation of our position. Nobody commented. Could you please comment on it? It's necessary for us to better understand your position. From our point of view technical ban of external modules loading doesn't solve any of mentioned problems, but makes VP developer life harder.
In addition to what Peter just said, I'd like to quote the commit message itself
[quote]
Moreover different people interested in different parts of QEMU. QEMU core developers not interested in supporting and maintaining tons of platforms available on the market. Virtual platform developers not interested and usually don’t have resources to merge their changes upstream. So we have a lots of abandoned QEMU forks for different platforms
[/quote]
This is essentially saying that there are lots of people (often working for commercial companies) using QEMU and they are not interested in contributing upstream. At the same time complaining it is too hard to maintain their forked code. The proposal is then asking QEMU upstream to change its architecture & support public API for plugins in order to make it easier for these people to use QEMU while /still/ not contributing anything back to upstream.
That is not exactly giving a compelling story of the benefits for the QEMU community. The benefit is all about people who are intentionally outside the community and wish to remain that way, while giving QEMU contributors an extra maint burden to support external plugins indefinitely.
As for the point about the technical limitations and interactions with licensing not being perfect, and people already likely ignoring the licensing rules. That is very true, but at the same time, that is not a reason to abandon the community's licensing goals/intent. Again this is focusing on benefits to people who want to use QEMU without contributing back.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 3 lines · Vladimir
Anton previously sent explanation of our position. Nobody commented. Could you please comment on it? It's necessary for us to better understand your position.
The discussion was on this thread:
https://lore.kernel.org/qemu-devel/[email protected]/
Dan's email is a pretty straightforward summary of what upstream's position is, and why we have that view.
I understand that the way QEMU is today is not helpful for you, but it is the way it is. QEMU is not and doesn't really seek to be a standardized simulator platform with a fixed API that people can build device models for and then stitch those device models together into platforms, and have that work across different QEMU versions; and wishing that it was doesn't make it so. The gap between here and there is not just a 300 line patch, it is:
* a significantly different/enlarged set of contributors (in the sense of "companies willing to invest money to work on the project and have it fulfil their requirements")
* a major shift in project focus (for instance, it would have to care a lot more about providing well documented stable APIs to devices; it might need to care less about emulation performance improvements if they required breaking changes to existing devices)
* a lot of work and restructuring to be able to provide that "we are a simulator platform with a clean interface that makes it easy to write and wire up device models" interface. A lot of work would be needed to clean up and separate out what are currently ad-hoc and legacy interfaces between different pieces of the codebase. We'd want to consider whether we wanted to provide SystemC interfaces and compatibility. Etc.
Perhaps it would be cool if that open source project existed; but QEMU isn't currently it. The path to maybe causing QEMU to get closer to that idea is not "throw a short patch onto the mailing list", but to try to build a community of people who (a) agree with you (b) are willing to contribute to the upstream project to do the heavy lifting in the third bullet point above (c) can make the case over time for "these changes are good not just for us but also for you; we're going to be around for the long term to help maintain them; and we do our share of the work on the common parts of the system that everybody benefits from".
QEMU has had big changes in focus before -- most notably the addition of support for KVM and similar virtualization interfaces to what was originally purely an emulator. So it's not impossible -- but it isn't easy.
(Part 'c' is helpful for pretty much every non-trivial contribution to any open source project, incidentally. But the more you're trying to propose a major change in project focus the more it matters.)
Quoted 3 lines
From our point of view technical ban of external modules loading doesn't solve any of mentioned problems, but makes VP developer life harder.
Anything we provide as a user-facing interface is something we have to support. Not providing "load machine from external .so file" solves the problem of "this is not something we want to support or think we are able to support".
For example, this patch doesn't solve the kind of problem you list yourself in the commit message here:
Quoted 5 lines
For example we’re now working on Raspberry Pi 4b implementation for our internal needs and we’re planning to merge it upstream. It’s based on some QEMU fork author of which wasn’t able to complete it and commit upstream. And it can’t be used with later QEMU without some efforts to port it to newer QEMU version.
Having that in an external .so that's loaded via an -add_machines command line does nothing to make it work with multiple QEMU
versions: it will still only work with the QEMU version it was based on, because newer ones will provide different APIs and will have removed old functions that the code in the .so is relying on. So providing a "-add_machines" option is just going to cause a lot of bug reports of the form "my .so doesn't work" where the answer is "you need to use the exact matching QEMU version that the .so was built for". At which point you might as well just have built the machine model into the QEMU binary.
thanks
-- PMM