From nobody Thu Dec 18 19:37:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1562034448; cv=none; d=zoho.com; s=zohoarc; b=W5ef9SCQATfc2EImgYY2vgNBUsSr3ZjiN1GMOSXHxt5ugEE2ErhAkJuiC0BEnZv2Gm4BEJ6mv4PdNl/29rm9Z+5tKeG5CxFWaCmwvZ3P9Jo3TdsUdLKFqEOsG3LRjQo/zN0ACwBnHraMbnrg7l+ZLNNrYodrJsWGE9MZj9scR+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562034448; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SM8mY+R0SiuBOfCMBxDLwmP2jvWXg+rVriH+MW5T7NQ=; b=n0UoUL/ivbW9Wh5M2YqMGc/JYXTk8o+eP0BkTN0hTLYQwutfY5hQaMc6Na2AcgzqChZBKm3JJXIfLuHAnXelPLuptpElsJLtk+KFYNiZp3f/mxmFvxYduMU659oQU20aYX9QX66/UzWO4pWnnGeV/ZY9Nf8YOVPcy8Xy7gXpuPs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562034448162879.6134051657734; Mon, 1 Jul 2019 19:27:28 -0700 (PDT) Received: from localhost ([::1]:47264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hi8Vz-00059u-5m for importer@patchew.org; Mon, 01 Jul 2019 22:27:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58855) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hi4Z1-00058v-8U for qemu-devel@nongnu.org; Mon, 01 Jul 2019 18:14:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hi4Z0-0003mR-74 for qemu-devel@nongnu.org; Mon, 01 Jul 2019 18:14:19 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41720) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hi4Z0-0003m0-0P for qemu-devel@nongnu.org; Mon, 01 Jul 2019 18:14:18 -0400 Received: by mail-wr1-f66.google.com with SMTP id c2so15466177wrm.8 for ; Mon, 01 Jul 2019 15:14:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id o6sm26573508wra.27.2019.07.01.09.40.03 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 09:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=SM8mY+R0SiuBOfCMBxDLwmP2jvWXg+rVriH+MW5T7NQ=; b=BcKv3pdK6VP3YAvICZ3IjFWl8q1SUNfgZVufEMve5wV23Y9aKngp7BhjFG3Lfwflji vXaGU0aO3uJnFcAWRygMdhXJ2ZePDe53efT/3XN0Gyh7T8rx8CrV0auXxalGzoJBw4/A c65cRGaNitO2d9kW75cz8dkPys7TAN6z8VE1OMAqSUs3x/wPrnp/a/q7JVd9T+zJ5PFi jmi86rSre0NHaa2KEhF9dPRNvMwxDsM9WjptMZA2SCkSE0UgeS1xGz/O/vUV2V6dOXPQ j0dpacPdzSyBERnahO2v4ZVbmXGnG0hQzm6s6ZtqwNJY8p7GR3pFkhYoDV4Yn2TnmlUP VXSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SM8mY+R0SiuBOfCMBxDLwmP2jvWXg+rVriH+MW5T7NQ=; b=C8eP99jhMev0rUeJzXjc2IV2LbLpnKoqer7wdYe7Zy57+PHXaVAEbgSg8tzhiMGPB0 0kldTxoIw3jORbNq52wLdxUvzgsP39BfENolcsqKvznyLUeSdG42EHcT6rkXdoX5rKon FRsSMAyrQrqhfu7oyqmVFEwamjdFlJCmNl4xI8vmOTX4m8l7XyZvjZOKcC7Ar2vXvsUG FAExM3ZzaRDmgBU9ZIvin/4AtpOn4kX8zNzsLHv5khmrpi7C3f5V/tJeNVwPBmNX9fUY 08ddBes0usyUttWZIB8IWZtrbXKErHWVCrwTfvRYoDI5/LmDqPIriToObCsxVCGkjAW2 G/Fg== X-Gm-Message-State: APjAAAWrxXxKui2m54gR2Q5r+pEgwkLrI9lj1r2sPnXLGBXCRDGt0S+V uimN+HyVhw4aNqhiU9a14yK34PpPDwjBzA== X-Google-Smtp-Source: APXvYqxKgF3m5Olw4flHXvWP4Bn+sryjaKJzfiMfXIOtoIT+qhRcBaYZhuPwFrzbfEsEiq/7UC+pzA== X-Received: by 2002:adf:dc09:: with SMTP id t9mr1952549wri.69.1561999204945; Mon, 01 Jul 2019 09:40:04 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 1 Jul 2019 17:39:15 +0100 Message-Id: <20190701163943.22313-19-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701163943.22313-1-peter.maydell@linaro.org> References: <20190701163943.22313-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.221.66 Subject: [Qemu-devel] [PULL 18/46] aspeed/timer: Ensure positive muldiv delta X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Christian Svensson If the host decrements the counter register that results in a negative delta. This is then passed to muldiv64 which only handles unsigned numbers resulting in bogus results. This fix ensures the delta being operated on is positive. Test case: kexec a kernel using aspeed_timer and it will freeze on the second bootup when the kernel initializes the timer. With this patch that no longer happens and the timer appears to run OK. Signed-off-by: Christian Svensson Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Joel Stanley Reviewed-by: Andrew Jeffery Message-id: 20190618165311.27066-12-clg@kaod.org Signed-off-by: Peter Maydell --- hw/timer/aspeed_timer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c index 745eb8608b5..29cc5e80708 100644 --- a/hw/timer/aspeed_timer.c +++ b/hw/timer/aspeed_timer.c @@ -275,7 +275,11 @@ static void aspeed_timer_set_value(AspeedTimerCtrlStat= e *s, int timer, int reg, int64_t delta =3D (int64_t) value - (int64_t) calculate_ticks(= t, now); uint32_t rate =3D calculate_rate(t); =20 - t->start +=3D muldiv64(delta, NANOSECONDS_PER_SECOND, rate); + if (delta >=3D 0) { + t->start +=3D muldiv64(delta, NANOSECONDS_PER_SECOND, rate= ); + } else { + t->start -=3D muldiv64(-delta, NANOSECONDS_PER_SECOND, rat= e); + } aspeed_timer_mod(t); } break; --=20 2.20.1