qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Jose R. Ziviani" <jziviani@suse.de>
To: Claudio Fontana <cfontana@suse.de>
Cc: pbonzini@redhat.com, "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	richard.henderson@linaro.org, qemu-devel@nongnu.org,
	kraxel@redhat.com
Subject: Re: [PATCH v2 1/1] modules: Improve error message when module is not found
Date: Fri, 23 Jul 2021 10:50:41 -0300	[thread overview]
Message-ID: <YPrJMTF+3lfeNdC5@pizza> (raw)
In-Reply-To: <c26fc6f4-341f-c66f-5384-c811e1342891@suse.de>

[-- Attachment #1: Type: text/plain, Size: 5177 bytes --]

On Fri, Jul 23, 2021 at 11:41:19AM +0200, Claudio Fontana wrote:
> On 7/23/21 12:09 AM, Jose R. Ziviani wrote:
> > When a module is not found, specially accelerators, QEMU displays
> > a error message that not easy to understand[1]. This patch improves
> > the readability by offering a user-friendly message[2].
> > 
> > This patch also moves the accelerator ops check to runtine (instead
> > of the original g_assert) because it works better with dynamic
> > modules.
> > 
> > [1] qemu-system-x86_64 -accel tcg
> > ERROR:../accel/accel-softmmu.c:82:accel_init_ops_interfaces: assertion failed:
> > (ops != NULL)
> > Bail out! ERROR:../accel/accel-softmmu.c:82:accel_init_ops_interfaces:
> > assertion failed: (ops != NULL)
> >     31964 IOT instruction (core dumped)  ./qemu-system-x86_64 ...
> > 
> > [2] qemu-system-x86_64 -accel tcg
> > accel-tcg-x86_64 module is missing, install the package or config the library path correctly.
> > 
> > Signed-off-by: Jose R. Ziviani <jziviani@suse.de>
> > ---
> >  accel/accel-softmmu.c |  5 ++++-
> >  util/module.c         | 14 ++++++++------
> >  2 files changed, 12 insertions(+), 7 deletions(-)
> > 
> > diff --git a/accel/accel-softmmu.c b/accel/accel-softmmu.c
> > index 67276e4f52..52449ac2d0 100644
> > --- a/accel/accel-softmmu.c
> > +++ b/accel/accel-softmmu.c
> > @@ -79,7 +79,10 @@ void accel_init_ops_interfaces(AccelClass *ac)
> >       * all accelerators need to define ops, providing at least a mandatory
> >       * non-NULL create_vcpu_thread operation.
> >       */
> > -    g_assert(ops != NULL);
> > +    if (ops == NULL) {
> > +        exit(1);
> > +    }
> > +
> 
> 
> Ah, again, why?
> This change looks wrong to me, 
> 
> the ops code should be present when ops interfaces are initialized:
> it should be a code level assertion, as it has to do with the proper order of initializations in QEMU,
> 
> why would we want to do anything else but to assert here?
> 
> Am I blind to something obvious?

Hello!

Thank you for reviewing it!

The problem is that if your TCG module is not installed and you start
QEMU like:

./qemu-system-x86_64 -accel tcg

You'll get the error message + a crash with a core dump:

accel-tcg-x86_64 module is missing, install the package or config the library path correctly.
**
ERROR:../accel/accel-softmmu.c:82:accel_init_ops_interfaces: assertion failed: (ops != NULL)
Bail out! ERROR:../accel/accel-softmmu.c:82:accel_init_ops_interfaces: assertion failed: (ops != NULL)
[1]    5740 IOT instruction (core dumped)  ./qemu-system-x86_64 -accel tcg

I was digging a little bit more in order to move this responsibility to
module.c but there isn't enough information there to safely exit() in
all situations that a module may be loaded. As Gerd mentioned, more work
is needed in order to achieve that.

However, it's not nice to have a crash due to an optional module missing.
It's specially confusing because TCG has always been native. Considering
also that we're already in hard freeze for 6.1, I thought to have this
simpler check instead.

What do you think if we have something like:

/* FIXME: this isn't the right place to handle a missing module and
   must be reverted when the module refactoring is completely done */
#ifdef CONFIG_MODULES
if (ops == NULL) {
    exit(1);
}
#else
g_assert(ops != NULL);
#endif

Regards!

> 
> >      if (ops->ops_init) {
> >          ops->ops_init(ops);
> >      }
> > diff --git a/util/module.c b/util/module.c
> > index 6bb4ad915a..268a8563fd 100644
> > --- a/util/module.c
> > +++ b/util/module.c
> > @@ -206,13 +206,10 @@ static int module_load_file(const char *fname, bool mayfail, bool export_symbols
> >  out:
> >      return ret;
> >  }
> > -#endif
> >  
> >  bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
> >  {
> >      bool success = false;
> > -
> > -#ifdef CONFIG_MODULES
> >      char *fname = NULL;
> >  #ifdef CONFIG_MODULE_UPGRADES
> >      char *version_dir;
> > @@ -300,6 +297,9 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
> >  
> >      if (!success) {
> >          g_hash_table_remove(loaded_modules, module_name);
> > +        fprintf(stderr, "%s module is missing, install the "
> > +                        "package or config the library path "
> > +                        "correctly.\n", module_name);
> >          g_free(module_name);
> >      }
> >  
> > @@ -307,12 +307,9 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
> >          g_free(dirs[i]);
> >      }
> >  
> > -#endif
> >      return success;
> >  }
> >  
> > -#ifdef CONFIG_MODULES
> > -
> >  static bool module_loaded_qom_all;
> >  
> >  void module_load_qom_one(const char *type)
> > @@ -384,4 +381,9 @@ void qemu_load_module_for_opts(const char *group) {}
> >  void module_load_qom_one(const char *type) {}
> >  void module_load_qom_all(void) {}
> >  
> > +bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
> > +{
> > +    return false;
> > +}
> > +
> >  #endif
> > 
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-07-23 13:51 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22 22:09 [PATCH v2 0/1] Improve module accelerator error message Jose R. Ziviani
2021-07-22 22:09 ` [PATCH v2 1/1] modules: Improve error message when module is not found Jose R. Ziviani
2021-07-23  6:25   ` Gerd Hoffmann
2021-07-23  8:04     ` Claudio Fontana
2021-07-23  8:28   ` Markus Armbruster
2021-07-23  8:32     ` Claudio Fontana
2021-07-23  9:41   ` Claudio Fontana
2021-07-23  9:52     ` Gerd Hoffmann
2021-07-23 11:20       ` Claudio Fontana
2021-07-23 12:20         ` Claudio Fontana
2021-07-23 12:48           ` Gerd Hoffmann
2021-07-29  9:14             ` modular tcg (was: Re: [PATCH v2 1/1] modules: Improve error message when module is not) found Gerd Hoffmann
2021-07-29  9:40               ` modular tcg Claudio Fontana
2021-07-29 10:26                 ` Gerd Hoffmann
2021-07-29 10:42                   ` Claudio Fontana
2021-07-29  9:42               ` Claudio Fontana
2021-07-29 10:29                 ` Gerd Hoffmann
2021-07-29 10:44                   ` Claudio Fontana
2021-07-29 11:34                     ` Philippe Mathieu-Daudé
2021-07-29 11:39                       ` Claudio Fontana
2021-07-29 14:22                       ` Claudio Fontana
2021-07-29 14:59                         ` Philippe Mathieu-Daudé
2021-07-29 16:35                           ` Claudio Fontana
2021-07-29 16:40               ` modular tcg (was: Re: [PATCH v2 1/1] modules: Improve error message when module is not) found Paolo Bonzini
2021-07-30  9:05                 ` modular tcg Gerd Hoffmann
2021-07-30 10:02                   ` Claudio Fontana
2022-09-02  9:50               ` modular tcg (was: Re: [PATCH v2 1/1] modules: Improve error message when module is not) found Claudio Fontana
2021-07-23 13:50     ` Jose R. Ziviani [this message]
2021-07-23 14:02       ` [PATCH v2 1/1] modules: Improve error message when module is not found Claudio Fontana
2021-07-23 14:14         ` Philippe Mathieu-Daudé
2021-07-23 14:36         ` Jose R. Ziviani
2021-07-23 15:27           ` Claudio Fontana
2021-07-23 15:46             ` Jose R. Ziviani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YPrJMTF+3lfeNdC5@pizza \
    --to=jziviani@suse.de \
    --cc=cfontana@suse.de \
    --cc=f4bug@amsat.org \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).