All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [PATCH 1/3] util/qemu-timer: Make timer_free() imply timer_del()
Date: Tue, 15 Dec 2020 11:56:40 +0000	[thread overview]
Message-ID: <CAFEAcA_z4rXSmc-aS9WGOgSmugVSZW1O58mn+Fe0pmnCp0-ezQ@mail.gmail.com> (raw)
In-Reply-To: <cc8ff905-0830-2ba1-1ec0-3f336625e269@redhat.com>

On Tue, 15 Dec 2020 at 11:53, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 15/12/20 12:44, Peter Maydell wrote:
> >
> >> +static inline void timer_free(QEMUTimer *ts)
> >> +{
> >> +
> >> +    if (ts->expire_time != -1) {
> >> +        timer_del(ts);
> >> +    }
> >> +    g_free(ts);
> >> +}
> > I was thinking about this again this morning, and I'm not sure
> > this is thread-safe.
>
> It may not be thread-safe in principle, but any code that calls
> timer_mod, and isn't itself protected by a lock against timer_free, will
> be racing against the g_free immediately after.  That is, that code
> could run after g_free and have a use-after-free bug.

I was thinking about potential races between the thread doing
the timer_free() and the iothread trying to run timers. Or
can that not happen ?

> But yes, I agree it is also an unnecessary optimization.  It's better
> done in timer_del_locked, and removed from timer_mod_anticipate_ns.
> Since you are at it, you may also want to push the call to
> timer_del_locked down from timer_mod_ns and timer_mod_anticipate_ns to
> their callee, timer_mod_ns_locked.

One thing at a time :-)

thanks
-- PMM


  reply	other threads:[~2020-12-15 12:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 20:30 [PATCH 0/3] qemu-timer: Make timer_free() imply timer_del() Peter Maydell
2020-12-14 20:30 ` [PATCH 1/3] util/qemu-timer: " Peter Maydell
2020-12-15 11:44   ` Peter Maydell
2020-12-15 11:53     ` Paolo Bonzini
2020-12-15 11:56       ` Peter Maydell [this message]
2020-12-14 20:30 ` [PATCH 2/3] scripts/coccinelle: New script to remove unnecessary timer_del() calls Peter Maydell
2020-12-14 20:30 ` [PATCH 3/3] Remove superfluous " Peter Maydell
2020-12-15  0:02   ` Corey Minyard
2020-12-15 10:07 ` [PATCH 0/3] qemu-timer: Make timer_free() imply timer_del() Paolo Bonzini
2020-12-15 11:39   ` Peter Maydell

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=CAFEAcA_z4rXSmc-aS9WGOgSmugVSZW1O58mn+Fe0pmnCp0-ezQ@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.