The example from docs/system/i386/sgx.rst section "Launching a guest"
fails for me like this:

    $ qemu-system-x86_64 -cpu host,+sgx-provisionkey -object 
memory-backend-epc,id=mem1,size=64M,prealloc=on -M 
sgx-epc.0.memdev=mem1,sgx-epc.0.node=0
    qemu-system-x86_64: invalid object type: memory-backend-epc

Device "sgx-epc" has a link property to a "memory-backend-epc" (SgxEPC
member memdev).  It's not optional, so we must create a
"memory-backend-epc" to be able to create an "sgx-epc".  In the test
shown above, "sgx-epc" exists, but "memory-backend-epc" does not.

The latter doesn't exist for me, because we register QOM type
"memory-backend-epc" only when we can open /dev/sgx_vepc read/write,
which fails for me.  Such conditional registration is unusual and
problematic:

1. Management applications use introspection interfaces to find out
what a certain QEMU can do.  Conditional type registration makes QOM
introspection results depend on the condition, which generally makes
them valid only for the process that produced them.  Undesirable.

2. For user-creatable objects like "memory-backend-epc", it also makes
QAPI introspection unreliable: query-qmp-schema claims the type
exists (object-add argument @qom-type accepts "memory-backend-epc")
even when it doesn't.

Conditional registration actually serves no purpose here, because we
still have to open /dev/sgx_vepc for real when we create the object,
and need and do handle errors then.

Register unconditionally.  The example now fails to create the object,
like this:

    qemu-system-x86_64: can't create 'memory-backend-epc': Could not open 
'/dev/sgx_vepc': No such file or directory

Signed-off-by: Markus Armbruster <[email protected]>
---
 backends/hostmem-epc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c
index e1c784249ff..bf5aecdfd45 100644
--- a/backends/hostmem-epc.c
+++ b/backends/hostmem-epc.c
@@ -62,12 +62,7 @@ static const TypeInfo sgx_epc_backed_info = {
 
 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);
-    }
+    type_register_static(&sgx_epc_backed_info);
 }
 
 type_init(register_types);
-- 
2.55.0


Reply via email to