qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Stefan Hajnoczi" <stefanha@gmail.com>,
	"Michal Suchánek" <msuchanek@suse.de>
Cc: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Subject: Re: qemu ppc64 crash when adding CPU
Date: Mon, 4 Dec 2023 20:42:52 +0100	[thread overview]
Message-ID: <7aa25b43-eb95-460e-9a80-22cb3991c7c8@linaro.org> (raw)
In-Reply-To: <CAJSP0QUShqgd18ZFib-EzwWbG1uz4E4pKNXpiTBauQhsDXUiyw@mail.gmail.com>

Hi,

On 4/12/23 19:57, Stefan Hajnoczi wrote:
> On Mon, 4 Dec 2023 at 13:37, Michal Suchánek <msuchanek@suse.de> wrote:

>> Looking at tcg.c line 784 is here:
>>
>> ster_thread(void)
>> {
>>      TCGContext *s = g_malloc(sizeof(*s));
>>      unsigned int i, n;
>>
>>      *s = tcg_init_ctx;
>>
>>      /* Relink mem_base.  */
>>      for (i = 0, n = tcg_init_ctx.nb_globals; i < n; ++i) {
>>          if (tcg_init_ctx.temps[i].mem_base) {
>>              ptrdiff_t b = tcg_init_ctx.temps[i].mem_base - tcg_init_ctx.temps;
>>              tcg_debug_assert(b >= 0 && b < n);
>>              s->temps[i].mem_base = &s->temps[b];
>>          }
>>      }
>>
>>      /* Claim an entry in tcg_ctxs */
>>      n = qatomic_fetch_inc(&tcg_cur_ctxs);
>>>>> g_assert(n < tcg_max_ctxs); <<<
>>      qatomic_set(&tcg_ctxs[n], s);
>>
>>      if (n > 0) {
>>          alloc_tcg_plugin_context(s);
>>          tcg_region_initial_alloc(s);
>>      }
>>
>>      tcg_ctx = s;
>> }
>>
>> Any idea why qemu would be crashing here?
> 
> Hi Michal,
> 
> $ git grep tcg_cur_ctxs
> tcg/region.c:409:    unsigned int n_ctxs = qatomic_read(&tcg_cur_ctxs);
> tcg/region.c:889:    unsigned int n_ctxs = qatomic_read(&tcg_cur_ctxs);
> tcg/tcg-internal.h:34:extern unsigned int tcg_cur_ctxs;
> tcg/tcg.c:241:unsigned int tcg_cur_ctxs;
> tcg/tcg.c:806:    n = qatomic_fetch_inc(&tcg_cur_ctxs);
> tcg/tcg.c:1369:    tcg_cur_ctxs = 1;
> 
> I don't see a qatomic_dec(&tcg_cur_ctxs) anywhere, so it seems hot
> unplugging a vcpu doesn't release the tcg_cur_ctxs refcount. Do we
> need a tcg_unregister_thread() function?

Suggested fix posted as RFC patch:
https://lore.kernel.org/qemu-devel/20231204194039.56169-1-philmd@linaro.org/


      reply	other threads:[~2023-12-04 19:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 18:36 qemu ppc64 crash when adding CPU Michal Suchánek
2023-12-04 18:57 ` Stefan Hajnoczi
2023-12-04 19:42   ` Philippe Mathieu-Daudé [this message]

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=7aa25b43-eb95-460e-9a80-22cb3991c7c8@linaro.org \
    --to=philmd@linaro.org \
    --cc=msuchanek@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@gmail.com \
    /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).