Skip to content
Snippets Groups Projects
  1. Sep 29, 2023
    • Markus Armbruster's avatar
      qobject atomics osdep: Make a few macros more hygienic · bb718463
      Markus Armbruster authored
      
      Variables declared in macros can shadow other variables.  Much of the
      time, this is harmless, e.g.:
      
          #define _FDT(exp)                                                  \
              do {                                                           \
                  int ret = (exp);                                           \
                  if (ret < 0) {                                             \
                      error_report("error creating device tree: %s: %s",   \
                              #exp, fdt_strerror(ret));                      \
                      exit(1);                                               \
                  }                                                          \
              } while (0)
      
      Harmless shadowing in h_client_architecture_support():
      
              target_ulong ret;
      
              [...]
      
              ret = do_client_architecture_support(cpu, spapr, vec, fdt_bufsize);
              if (ret == H_SUCCESS) {
                  _FDT((fdt_pack(spapr->fdt_blob)));
                  [...]
              }
      
              return ret;
      
      However, we can get in trouble when the shadowed variable is used in a
      macro argument:
      
          #define QOBJECT(obj) ({                                 \
              typeof(obj) o = (obj);                              \
              o ? container_of(&(o)->base, QObject, base) : NULL; \
           })
      
      QOBJECT(o) expands into
      
          ({
      --->    typeof(o) o = (o);
              o ? container_of(&(o)->base, QObject, base) : NULL;
          })
      
      Unintended variable name capture at --->.  We'd be saved by
      -Winit-self.  But I could certainly construct more elaborate death
      traps that don't trigger it.
      
      To reduce the risk of trapping ourselves, we use variable names in
      macros that no sane person would use elsewhere.  Here's our actual
      definition of QOBJECT():
      
          #define QOBJECT(obj) ({                                         \
              typeof(obj) _obj = (obj);                                   \
              _obj ? container_of(&(_obj)->base, QObject, base) : NULL;   \
          })
      
      Works well enough until we nest macro calls.  For instance, with
      
          #define qobject_ref(obj) ({                     \
              typeof(obj) _obj = (obj);                   \
              qobject_ref_impl(QOBJECT(_obj));            \
              _obj;                                       \
          })
      
      the expression qobject_ref(obj) expands into
      
          ({
              typeof(obj) _obj = (obj);
              qobject_ref_impl(
                  ({
      --->            typeof(_obj) _obj = (_obj);
                      _obj ? container_of(&(_obj)->base, QObject, base) : NULL;
                  }));
              _obj;
          })
      
      Unintended variable name capture at --->.
      
      The only reliable way to prevent unintended variable name capture is
      -Wshadow.
      
      One blocker for enabling it is shadowing hiding in function-like
      macros like
      
           qdict_put(dict, "name", qobject_ref(...))
      
      qdict_put() wraps its last argument in QOBJECT(), and the last
      argument here contains another QOBJECT().
      
      Use dark preprocessor sorcery to make the macros that give us this
      problem use different variable names on every call.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-ID: <20230921121312.1301864-8-armbru@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      bb718463
  2. Apr 20, 2023
    • Paolo Bonzini's avatar
      monitor: mark mixed functions that can suspend · a50c99bc
      Paolo Bonzini authored
      
      There should be no paths from a coroutine_fn to aio_poll, however in
      practice coroutine_mixed_fn will call aio_poll in the !qemu_in_coroutine()
      path.  By marking mixed functions, we can track accurately the call paths
      that execute entirely in coroutine context, and find more missing
      coroutine_fn markers.  This results in more accurate checks that
      coroutine code does not end up blocking.
      
      If the marking were extended transitively to all functions that call
      these ones, static analysis could be done much more efficiently.
      However, this is a start and makes it possible to use vrc's path-based
      searches to find potential bugs where coroutine_fns call blocking functions.
      
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      a50c99bc
  3. Mar 13, 2023
  4. Feb 23, 2023
    • Markus Armbruster's avatar
      rocker: Tweak stubbed out monitor commands' error messages · 11787102
      Markus Armbruster authored
      
      The QERR_ macros are leftovers from the days of "rich" error objects.
      We've been trying to reduce their remaining use.
      
      The stubbed out Rocker monitor commands are the last remaining users
      of QERR_FEATURE_DISABLED.  They fail like this:
      
          (qemu) info rocker mumble
          Error: The feature 'rocker' is not enabled
      
      The real rocker commands fail like this when the named object doesn't
      exist:
      
          Error: rocker mumble not found
      
      If that's good enough when Rocker is enabled, then it's good enough
      when it's disabled, so replace QERR_FEATURE_DISABLED with that, and
      drop the macro.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20230207075115.1525-13-armbru@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
      11787102
    • Markus Armbruster's avatar
      replay: Simplify setting replay blockers · 0ec8384f
      Markus Armbruster authored
      
      replay_add_blocker() takes an Error *.  All callers pass one created
      like this:
      
          error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "some feature");
      
      Folding this into replay_add_blocker() simplifies the callers, losing
      a bit of generality we haven't needed in more than six years.
      
      Since there are no other uses of macro QERR_REPLAY_NOT_SUPPORTED,
      replace the remaining one by its expansion, and drop the macro.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20230207075115.1525-10-armbru@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      0ec8384f
  5. Oct 27, 2022
  6. Apr 21, 2022
  7. Apr 06, 2022
  8. Mar 22, 2022
  9. Nov 02, 2021
  10. Oct 29, 2021
  11. Oct 27, 2021
  12. Jul 23, 2021
    • Paolo Bonzini's avatar
      qapi: introduce forwarding visitor · 18fa3ebc
      Paolo Bonzini authored
      
      This new adaptor visitor takes a single field of the adaptee, and exposes it
      with a different name.
      
      This will be used for QOM alias properties.  Alias targets can of course
      have a different name than the alias property itself (e.g. a machine's
      pflash0 might be an alias of a property named 'drive').  When the target's
      getter or setter invokes the visitor, it will use a different name than
      what the caller expects, and the visitor will not be able to find it
      (or will consume erroneously).
      
      The solution is for alias getters and setters to wrap the incoming
      visitor, and forward the sole field that the target is expecting while
      renaming it appropriately.
      
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      18fa3ebc
  13. Jun 04, 2021
  14. Apr 08, 2021
  15. Mar 19, 2021
    • Markus Armbruster's avatar
      qapi: Implement deprecated-input=reject for QMP command arguments · db291641
      Markus Armbruster authored
      
      This policy rejects deprecated input, and thus permits "testing the
      future".  Implement it for QMP command arguments: reject commands with
      deprecated ones.  Example: when QEMU is run with -compat
      deprecated-input=reject, then
      
          {"execute": "eject", "arguments": {"device": "cd"}}
      
      fails like this
      
          {"error": {"class": "GenericError", "desc": "Deprecated parameter 'device' disabled by policy"}}
      
      When the deprecated parameter is removed, the error will change to
      
          {"error": {"class": "GenericError", "desc": "Parameter 'device' is unexpected"}}
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20210318155519.1224118-11-armbru@redhat.com>
      db291641
    • Markus Armbruster's avatar
      qapi: Implement deprecated-input=reject for QMP commands · d2032598
      Markus Armbruster authored
      
      This policy rejects deprecated input, and thus permits "testing the
      future".  Implement it for QMP commands: make deprecated ones fail.
      Example: when QEMU is run with -compat deprecated-input=reject, then
      
          {"execute": "query-cpus"}
      
      fails like this
      
          {"error": {"class": "CommandNotFound", "desc": "Deprecated command query-cpus disabled by policy"}}
      
      When the deprecated command is removed, the error will change to
      
          {"error": {"class": "CommandNotFound", "desc": "The command query-cpus has not been found"}}
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20210318155519.1224118-10-armbru@redhat.com>
      d2032598
    • Markus Armbruster's avatar
      qapi: Implement deprecated-output=hide for QMP command results · 91fa93e5
      Markus Armbruster authored
      
      This policy suppresses deprecated bits in output, and thus permits
      "testing the future".  Implement it for QMP command results.  Example:
      when QEMU is run with -compat deprecated-output=hide, then
      
          {"execute": "query-cpus-fast"}
      
      yields
      
          {"return": [{"thread-id": 9805, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
      
      instead of
      
          {"return": [{"arch": "x86", "thread-id": 22436, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
      
      Note the suppression of deprecated member "arch".
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20210318155519.1224118-4-armbru@redhat.com>
      91fa93e5
    • Markus Armbruster's avatar
      qemu-options: New -compat to set policy for deprecated interfaces · 6dd75472
      Markus Armbruster authored
      
      New option -compat lets you configure what to do when deprecated
      interfaces get used.  This is intended for testing users of the
      management interfaces.  It is experimental.
      
      -compat deprecated-input=<input-policy> configures what to do when
      deprecated input is received.  Input policy can be "accept" (accept
      silently), or "reject" (reject the request with an error).
      
      -compat deprecated-output=<out-policy> configures what to do when
      deprecated output is sent.  Output policy can be "accept" (pass on
      unchanged), or "hide" (filter out the deprecated parts).
      
      Default is "accept".  Policies other than "accept" are implemented
      later in this series.
      
      For now, -compat covers only syntactic aspects of QMP, i.e. stuff
      tagged with feature 'deprecated'.  We may want to extend it to cover
      semantic aspects, CLI, and experimental features.
      
      Note that there is no good way for management application to detect
      presence of -compat: it's not visible output of query-qmp-schema or
      query-command-line-options.  Tolerable, because it's meant for
      testing.  If running with -compat fails, skip the test.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20210318155519.1224118-3-armbru@redhat.com>
      6dd75472
  16. Mar 17, 2021
  17. Mar 15, 2021
  18. Mar 05, 2021
  19. Jan 28, 2021
  20. Dec 19, 2020
Loading