diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index d629d2d97e..81134de6c0 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -280,7 +280,8 @@ def gen_register_command(name: str,
                          success_response: bool,
                          allow_oob: bool,
                          allow_preconfig: bool,
-                         coroutine: bool) -> str:
+                         coroutine: bool,
+                         prefix: str) -> str:
     options = []
 
     if not success_response:
@@ -298,7 +299,7 @@ def gen_register_command(name: str,
 ''',
                 name=name, c_name=c_name(name),
                 opts=' | '.join(options) or 0,
-                feats=gen_features(features))
+                feats=gen_features(prefix, features))
     return ret
 
 
@@ -407,7 +408,7 @@ def visit_command(self,
             with ifcontext(ifcond, self._genh, self._genc):
                 self._genc.add(gen_register_command(
                     name, features, success_response, allow_oob,
-                    allow_preconfig, coroutine))
+                    allow_preconfig, coroutine, self._prefix))
 
 
 def gen_commands(schema: QAPISchema,
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index d1f639981a..8a489e559a 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -218,7 +218,8 @@ def visit_end(self) -> None:
         self._genh.add(gen_enum(self._event_enum_name,
                                 self._event_enum_members))
         self._genc.add(gen_enum_lookup(self._event_enum_name,
-                                       self._event_enum_members))
+                                       self._event_enum_members,
+                                       self._prefix))
         self._genh.add(mcgen('''
 
 void %(event_emit)s(%(event_enum)s event, QDict *qdict);
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 036977d989..399a0ae62d 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -41,9 +41,9 @@
 from .source import QAPISourceInfo
 
 
-def gen_features(features: Sequence[QAPISchemaFeature]) -> str:
-    features = [f"1u << {c_enum_const('QAPI_FEATURE', feat.name)}"
-                for feat in features if feat.is_special()]
+def gen_features(prefix, features: Sequence[QAPISchemaFeature]) -> str:
+    features = [f"1u << {c_enum_const(prefix + 'QAPI_FEATURE', feat.name)}"
+                for feat in features]
     return ' | '.join(features) or '0'
 
 
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
index ade6b7a3d7..b2d26c2ea8 100644
--- a/scripts/qapi/types.py
+++ b/scripts/qapi/types.py
@@ -43,6 +43,7 @@
 
 def gen_enum_lookup(name: str,
                     members: List[QAPISchemaEnumMember],
+                    modprefix: str,
                     prefix: Optional[str] = None) -> str:
     max_index = c_enum_const(name, '_MAX', prefix)
     feats = ''
@@ -61,7 +62,7 @@ def gen_enum_lookup(name: str,
                      index=index, name=memb.name)
         ret += memb.ifcond.gen_endif()
 
-        features = gen_features(memb.features)
+        features = gen_features(modprefix, memb.features)
         if features != '0':
             feats += mcgen('''
         [%(index)s] = %(features)s,
@@ -331,7 +332,7 @@ def visit_enum_type(self,
                         prefix: Optional[str]) -> None:
         with ifcontext(ifcond, self._genh, self._genc):
             self._genh.preamble_add(gen_enum(name, members, prefix))
-            self._genc.add(gen_enum_lookup(name, members, prefix))
+            self._genc.add(gen_enum_lookup(name, members, self._prefix, prefix))
 
     def visit_array_type(self,
                          name: str,
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 8dbf4ef1c3..883d720e36 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -62,6 +62,7 @@ def gen_visit_members_decl(name: str) -> str:
 
 
 def gen_visit_object_members(name: str,
+                             prefix: str,
                              base: Optional[QAPISchemaObjectType],
                              members: List[QAPISchemaObjectTypeMember],
                              branches: Optional[QAPISchemaBranches]) -> str:
@@ -103,7 +104,7 @@ def gen_visit_object_members(name: str,
 ''',
                          name=memb.name, has=has)
             indent.increase()
-        features = gen_features(memb.features)
+        features = gen_features(prefix, memb.features)
         if features != '0':
             ret += mcgen('''
     if (visit_policy_reject(v, "%(name)s", %(features)s, errp)) {
@@ -402,7 +403,7 @@ def visit_object_type(self,
             return
         with ifcontext(ifcond, self._genh, self._genc):
             self._genh.add(gen_visit_members_decl(name))
-            self._genc.add(gen_visit_object_members(name, base,
+            self._genc.add(gen_visit_object_members(name, self._prefix, base,
                                                     members, branches))
             # TODO Worth changing the visitor signature, so we could
             # directly use rather than repeat type.is_implicit()?
