qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>, qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [RFC PATCH] gdbstub: handle a potentially racing TaskState
Date: Sat, 20 Nov 2021 14:50:16 +0100	[thread overview]
Message-ID: <f15d60fd-0717-9357-dad5-72938d4f70f2@linaro.org> (raw)
In-Reply-To: <20211119145124.942390-1-alex.bennee@linaro.org>

On 11/19/21 3:51 PM, Alex Bennée wrote:
> When dealing with multi-threaded userspace programs there is a race
> condition with the addition of cpu->opaque (aka TaskState). This is
> due to cpu_copy calling cpu_create which updates the global vCPU list.
> However the task state isn't set until later. This shouldn't be a
> problem because the new thread can't have executed anything yet but
> the gdbstub code does liberally iterate through the CPU list in
> various places.
> 
> This sticking plaster ensure the not yet fully realized vCPU is given
> an pid of -1 which should be enough to ensure it doesn't show up
> anywhere else.
> 
> In the longer term I think the code that manages the association
> between vCPUs and attached GDB processes could do with a clean-up and
> re-factor.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/730
> ---
>   gdbstub.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index 23baaef40e..141d7bc4ec 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -94,7 +94,7 @@ static inline int cpu_gdb_index(CPUState *cpu)
>   {
>   #if defined(CONFIG_USER_ONLY)
>       TaskState *ts = (TaskState *) cpu->opaque;
> -    return ts->ts_tid;
> +    return ts ? ts->ts_tid : -1;
>   #else
>       return cpu->cpu_index + 1;
>   #endif

Tested-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


      reply	other threads:[~2021-11-20 13:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 14:51 [RFC PATCH] gdbstub: handle a potentially racing TaskState Alex Bennée
2021-11-20 13:50 ` Richard Henderson [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=f15d60fd-0717-9357-dad5-72938d4f70f2@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.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).