From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtMDi-0000EA-95 for qemu-devel@nongnu.org; Tue, 25 Nov 2014 14:56:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XtMDW-0007h2-Qc for qemu-devel@nongnu.org; Tue, 25 Nov 2014 14:56:18 -0500 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]:54034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtMDW-0007gu-Km for qemu-devel@nongnu.org; Tue, 25 Nov 2014 14:56:06 -0500 Received: by mail-wi0-f170.google.com with SMTP id bs8so13069783wib.1 for ; Tue, 25 Nov 2014 11:56:06 -0800 (PST) Sender: Paolo Bonzini Message-ID: <5474DEC8.9030906@redhat.com> Date: Tue, 25 Nov 2014 20:55:52 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1416939705-1272-1-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1416939705-1272-1-git-send-email-peter.maydell@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH for-2.2] qemu-timer: Avoid overflows when converting timeout to struct timespec List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel@nongnu.org Cc: Christoffer Dall , Anthony Liguori , patches@linaro.org On 25/11/2014 19:21, 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 > Signed-off-by: Peter Maydell > --- > 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... Yes, this is safe. I also have two small patches that I'll send a pull request for tomorrow. Paolo