Peter Maydell <[email protected]> writes:
> On Fri, 23 Oct 2026 at 11:21, Daniel P. Berrangé <[email protected]> wrote:
>>
>> On Thu, Oct 22, 2026 at 02:58:16PM +0200, Markus Armbruster wrote:
>> > My build of qemu-system-x86_64 has device sgx-epc:
>> >
>> > --> {"execute": "qom-list-types", "arguments": {"implements": "sgx-epc"}}
>> > <-- {"return": [{"name": "sgx-epc", "parent": "device"}]}
>> >
>> > The device as a link property to a memory-backend-epc:
>> >
>> > --> {"execute": "qom-list-properties", "arguments": {"typename":
>> > "sgx-epc"}}
>> > <-- {"return": [...
>> > {"name": "memdev", "type": "link<memory-backend-epc>"},
>> > ...]}
>> >
>> > However, type memory-backend-epc does not exist:
>
>> There is some rather dubious code that conditionally registers
>> the type
>>
>> static void register_types(void)
>> {
>> int fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
>> if (fd >= 0) {
>> close(fd);
>>
>> type_register_static(&sgx_epc_backed_info);
>> }
>> }
>>
>>
>> Normal practice is for types to be unconditionally registered. Do we
>> have any examples outside of this SGX case where we conditionally
>> register types ? Should we change this to follow normal practice ?
>
> TYPE_MEMORY_BACKEND_MEMFD does the same. I did a quick grep for
> "calls to type_register not indented by exactly 4 spaces" and
> I think the other cases are "misindented" or "data-driven
> type registration" rather than trying to do things conditionally
> (but I didn't actually look at all of them, instead making
> guesses based on variable names, so maybe there's one or two
> more I missed).
Alright, I looked. In addition to "misindented" or "data-driven", I
found:
* register_types() in hostmem-memfd.c registers "memory-backend-memfd"
only when a test of memfd_create() succeeds. This is what Peter
reported.
* virtio_ccw_gpu_register() in hw/s390x/virtio-ccw-gpu.c registers
"virtio-gpu-ccw" only when have_virtio_ccw, which is true when
hw/s390x/virtio-ccw.c gets compiled into the binary. So it's
effectively compile-time conditional.
I wish it was literally compile-time conditional, either in meson or
using #if.
* qemu_console_early_init() in ui/console-vc.c registers "chardev-vc" if
it's not already registered. early_dbus_init() in ui/dbus.c,
early_gtk_display_init() in ui/gtk.c, and
spice_app_display_early_init() in ui/spice-app.c all register it.
These are all QemuDisplay .early_init() callbacks.
qemu_display_early_init() calls the selected display's .early_init(),
if non-null.
Because qemu_console_early_init() runs after
qemu_display_early_init(), this always registers a "chardev-vc": the
active display may register its own, and when it doesn't, we get
ui/console-vc.c's.
More moving parts than I'd like.
I'm going to post patches for backends/hostmem-{epc,memfd}.c. I don't
plan to clean up the other two at this time.
[...]