qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christoffer Dall <christoffer.dall@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "marc.zyngier@arm.com" <marc.zyngier@arm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, Anthony Liguori <aliguori@amazon.com>,
	patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH for-2.2] qemu-timer: Avoid overflows when converting timeout to struct timespec
Date: Tue, 25 Nov 2014 21:29:49 +0100	[thread overview]
Message-ID: <20141125202949.GA27070@cbox> (raw)
In-Reply-To: <1416939705-1272-1-git-send-email-peter.maydell@linaro.org>

On Tue, Nov 25, 2014 at 06:21:45PM +0000, Peter Maydell wrote:
> In qemu_poll_ns(), when we convert an int64_t nanosecond timeout into
> a struct timespec, we may accidentally run into overflow problems if
> the timeout is very long. This happens because the tv_sec field is a
> time_t, which is signed, so we might end up setting it to a negative
> value by mistake. This will result in what was intended to be a
> near-infinite timeout turning into an instantaneous timeout, and we'll
> busy loop. Cap the maximum timeout at INT32_MAX seconds (about 68 years)
> to avoid this problem.
> 
> This specifically manifested on ARM hosts as an extreme slowdown on
> guest shutdown (when the guest reprogrammed the PL031 RTC to not
> generate alarms using a very long timeout) but could happen on other
> hosts and guests too.
> 
> Reported-by: Christoffer Dall <christoffer.dall@linaro.org>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> It's not quite clear why this only causes problems in some KVM
> configurations -- presumably in the others we complete the guest
> shutdown reasonably quickly without the busy-waiting QEMU thread
> interfering, but in some setups, notably on TC2 host, we go into
> an extreme slowdown printing out the final bits of the guest shutdown
> to its serial port. Given that (and given that I think this is fairly
> safe) I'd like to get this into 2.2 if possible...
> 
It's visibly a cleaner shutdown on my cubieboard2 (ubuntu kernel config)
than without this patch.

I've been running a VM on TC2 in a loop with shutdown for a couple of
hours and it just works now, so this patch definitely solves the issue
I was seeing.

I'm wondering if the timespec struct field is an unsigned long and
that's why we werent' seeing the overflow on arm64?

In any case, huge thanks for chasing this down.

-Christoffer

  parent reply	other threads:[~2014-11-25 20:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-25 18:21 [Qemu-devel] [PATCH for-2.2] qemu-timer: Avoid overflows when converting timeout to struct timespec Peter Maydell
2014-11-25 19:55 ` Paolo Bonzini
2014-11-25 20:29 ` Christoffer Dall [this message]
2014-11-25 23:22   ` Peter Maydell
2014-11-26  3:09 ` Fam Zheng
2014-11-27 11:33   ` 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=20141125202949.GA27070@cbox \
    --to=christoffer.dall@linaro.org \
    --cc=aliguori@amazon.com \
    --cc=marc.zyngier@arm.com \
    --cc=patches@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).