Daniel P. Berrangé <[email protected]> writes:

> 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:
>> 
>>  --> {"execute": "qom-list-types", "arguments": {"implements": 
>> "memory-backend"}}
>>  <-- {"return": [{"name": "memory-backend-ram", "parent": "memory-backend"}, 
>> {"name": "memory-backend-file", "parent": "memory-backend"}, {"name": 
>> "memory-backend-memfd", "parent": "memory-backend"}, {"name": 
>> "memory-backend-shm", "parent": "memory-backend"}]}
>
> 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 ?

Loosely related: conditional *class* properties.  Example:

    static void
    memfd_backend_class_init(ObjectClass *oc, const void *data)
    {
        HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);

        bc->alloc = memfd_backend_memory_alloc;

        if (qemu_memfd_check(MFD_HUGETLB)) {
            object_class_property_add_bool(oc, "hugetlb",
                                           memfd_backend_get_hugetlb,
                                           memfd_backend_set_hugetlb);
            object_class_property_set_description(oc, "hugetlb",
                                                  "Use huge pages");
            object_class_property_add(oc, "hugetlbsize", "uint64",
                                      &uint64_type_info,
                                      memfd_backend_get_hugetlbsize,
                                      memfd_backend_set_hugetlbsize,
                                      NULL, NULL);
            object_class_property_set_description(oc, "hugetlbsize",
                                                  "Huge pages size (ex: 2M, 
1G)");
        }

        [...]
    }

These properties are also declared in qapi/qom.json if CONFIG_LINUX.
QAPI introspection (query-qmp-schema) shows them then.  QOM
introspection (qom-list-properties etc.) only shows them when the
MFD_HUGETLB check succeeded.

Feels undesirable to me.

Should we instead make them read-only when the check fails?


Reply via email to