From nobody Mon May 6 01:50:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578673100; cv=none; d=zohomail.com; s=zohoarc; b=UJ4h/bnV9GnZj+L8UvMaof2f2LGQnk+HQNOLAfK58YCzE02ComQamKYPUQg340n9rOvK7/PVkGgaed/notLV6M9NSf9ziBx7GWkz+qxVe/SOmlOGjaVvObge9zJBgC5yEoXapCRGpYbkV/KhANXB4/scvOhKlOwRhc0w3TCwEyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578673100; h=Content-Type:Content-Transfer-Encoding:Cc: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; bh=sH1vHww7VcOtks3y+ZrcP6gPfRazqmJe6Ac+pRXoMAs=; b=laGnOv893exo/BI32AeZH8Rb04lmO3pTVQBiq61R5Ld/T3iUB8WJdIgwI8WzXjhUd1ISKKBWTHDG1twFeoci9onWG0kXDJQ5RdrN6HEjTLOYn7G+YrO8GgL7zOp369h31fCYrptkyjiLrbO9OL+kRBl8tJ6Pny9UQ+t3w4BP5SI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578673100047787.8627860295142; Fri, 10 Jan 2020 08:18:20 -0800 (PST) Received: from localhost ([::1]:48662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipwzK-0003Wk-Ld for importer@patchew.org; Fri, 10 Jan 2020 11:18:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44449) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipwxb-0002Ma-Fy for qemu-devel@nongnu.org; Fri, 10 Jan 2020 11:16:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipwxa-0007Yu-Ah for qemu-devel@nongnu.org; Fri, 10 Jan 2020 11:16:31 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:39596) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipwxa-0007Vf-48 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 11:16:30 -0500 Received: by mail-wr1-x441.google.com with SMTP id y11so2357028wrt.6 for ; Fri, 10 Jan 2020 08:16:30 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id d14sm2826056wru.9.2020.01.10.08.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 08:16:27 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5DC421FF8C; Fri, 10 Jan 2020 16:16:26 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sH1vHww7VcOtks3y+ZrcP6gPfRazqmJe6Ac+pRXoMAs=; b=v68t3ki4ejQvRt4C0La+V1Fgz4LWFtZzi6/nBc6Pa14wdFP5ctr6kPq9HOCs+aFCa5 IqthzQMFPMJtzW31N8g6rk9rhcKXSzpgwdB3FFyBRWqkOOsCi8vgjZCcUM8Vmyzc6cVt youK3jY9YVymMFynlCPqSnLw6uRBsk+9IerDQ5XuXCCpM/1dYa1uESDQODlM3YSS1y5W G+EjVbcRjkc2bcrVPKN8WPfCv/51Y0//6g2Mki1ZKX711EA0oyx0HhWd+C7ihnZNhlMi Ca34FiP+sEa7xHXpQnldl0/93avm29/i6NPSAwIlg2oBY3PkhI5C5J33dkDmcnyOvG3u Q4Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sH1vHww7VcOtks3y+ZrcP6gPfRazqmJe6Ac+pRXoMAs=; b=CC4d6w9nlz9D4RtTX8Im2PevPoVssWUjYRnVjFdL4rQQ7Y6Z7EgeUUKSrZdWQQdGZv C7u7JTWy83IRplGJ/TlcnWYSXY/UrRpRx97LVyMvVA7hHT3r6ns2n93uL98HIiKjmASK VEQEIV31LKJa79wIvIbVSaDfho7nGTVIv+6bS+ojHlSn8R9a7q0iNTDTAmbAWjgrpxfy Wu9hQYXIcVCmLgaGUSI0Q/iVlGBlG4DxQoXUwzd8GctLiDFNAvhN+EVwnVH1gdCfvciq HNIXsSjItHqEBZRdVEQD4Ivk47vzZDyi4Yf7JqjiiENJOiIfJe0//CttvZnPs2xuSsMG VVgw== X-Gm-Message-State: APjAAAX46J5kZQw7fL8/o+ZAhBBiu+8GSZ2JL//O43Lj+bsFOJFDgIGl v+nS6J/SMR3ABB5URT1MYI2kqA== X-Google-Smtp-Source: APXvYqx1RFo+DRbavUS8IOkjJ8AzAYnRiAqaqiHiSibBMorJpn5zJgZApcAruVZhByDQ0Lyvha8x7Q== X-Received: by 2002:a5d:6802:: with SMTP id w2mr4283925wru.353.1578672989119; Fri, 10 Jan 2020 08:16:29 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 1/2] target/arm: detect 64 bit overflow caused by high cval + voff Date: Fri, 10 Jan 2020 16:16:25 +0000 Message-Id: <20200110161626.31943-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200110161626.31943-1-alex.bennee@linaro.org> References: <20200110161626.31943-1-alex.bennee@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: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 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: , Cc: Peter Maydell , 1859021@bugs.launchpad.net, qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) If we don't detect this we will be stuck in a busy loop as we schedule a timer for before now which will continually trigger gt_recalc_timer even though we haven't reached the state required to trigger the IRQ. Bug: https://bugs.launchpad.net/bugs/1859021 Cc: 1859021@bugs.launchpad.net Signed-off-by: Alex Benn=C3=A9e --- target/arm/helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/arm/helper.c b/target/arm/helper.c index 19a57a17da5..eb17106f7bd 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2481,6 +2481,9 @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx) } else { /* Next transition is when we hit cval */ nexttick =3D gt->cval + offset; + if (nexttick < gt->cval) { + nexttick =3D UINT64_MAX; + } } /* Note that the desired next expiry time might be beyond the * signed-64-bit range of a QEMUTimer -- in this case we just --=20 2.20.1 From nobody Mon May 6 01:50:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578673191; cv=none; d=zohomail.com; s=zohoarc; b=LC3oolUUqXjD2nE0ptiXbRa5QGEvS5tYvNSLgAxMFe9gnyGnlda1BfhDMQq8j2Tt7zOtVqW0qr9OyghT9mLOL1O1UYmTLGCRt9fepBGuNaVPVdif09hFLaUOMcGsCkOTGw2SYlJ6tcYwj2uwarmzSJmMiwt5Sy2W6Q8U06bmHm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578673191; h=Content-Type:Content-Transfer-Encoding:Cc: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; bh=/2rz7VQka3qxbrkZEEttqfVPhw4gsf0iHRHcpHx8kNI=; b=ROeHNWkPgJMNLHXaOteucaM6wMJCLMRWilYqLryLOs5GbJh4ldiN4ehU0edxl31osRW+sGilapZeDN75RAiekJKilEzhATM4E5T7g7UQi5+tso+IC/KAOCd4GsB9J8gopzcxzoDy+K8Yl6TmbTAwSZrlxCu/ysyG3zFjW5tOCJo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578673191500321.28026895533685; Fri, 10 Jan 2020 08:19:51 -0800 (PST) Received: from localhost ([::1]:48692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipx0o-0005Ax-H8 for importer@patchew.org; Fri, 10 Jan 2020 11:19:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44559) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipwxc-0002Mz-VM for qemu-devel@nongnu.org; Fri, 10 Jan 2020 11:16:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipwxb-0007eO-IS for qemu-devel@nongnu.org; Fri, 10 Jan 2020 11:16:32 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:43178) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipwxb-0007bQ-Ab for qemu-devel@nongnu.org; Fri, 10 Jan 2020 11:16:31 -0500 Received: by mail-wr1-x444.google.com with SMTP id d16so2337381wre.10 for ; Fri, 10 Jan 2020 08:16:31 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n189sm2823804wme.33.2020.01.10.08.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 08:16:28 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 769031FF8F; Fri, 10 Jan 2020 16:16:26 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/2rz7VQka3qxbrkZEEttqfVPhw4gsf0iHRHcpHx8kNI=; b=Ehnx9x3ov/ICYOB9vYRNMy59Q4C2tK6xC6G9R2bPyYWbLWtO0QinyB0+2ZsGDGdj8J 47QRfcOyF5EKE7voQQ/zh2vsqYmLz5BKquxObbKWebKL6ksNBWhApCR2sXKWhjKYOZPz 39LeJlUvulT4vUGiJD2s8fhg5gWZHw5vfmL/JWNjUi3rsjHSnHGTzsqw4367Q/0seXqz qryFJ4b5k72nJ+Gt9/Z1kz5QD4R+V8+7s8juqmGfcSpQEBKbNifZN6xlFSfPCj3PcNe7 HqlQ/hEK//xHNeNpj0+Ow0BMflsz7cwVHOe+ZExrn2lpf8IpX1CsP2E3jxlOnDsL/1Kc MClA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/2rz7VQka3qxbrkZEEttqfVPhw4gsf0iHRHcpHx8kNI=; b=YhyZNOO7Ef9jraNNKuQor39ymNm5GaJmzjdWEeiKoh1GBKT2MYUZViQh0FvjHInBs3 nKSHRplZzcy/Y4DzNE/57fbKziM7dxxhyxDaKj6Op3SBRvqoIXfXsLls5BBpvnElfpyW uVe35RicyhgsJZkUROhLzzf0YfbyBFC6upkBdh3n/dCuttufhKJZpBhHZHLrf7uyIdw1 /n9gLb/kmmhdZNpzikQbcMCqpxbz+MGmqgSospN5cKt9HavdHy9IxDJK9qtymQvfkOK4 Pu4iKEbSCX0Y0hH/RU3nYNvVzz34Bo6QIBsNOm6AkmexoWaCfXyM2/QclybhMcH4rrY5 NZ5Q== X-Gm-Message-State: APjAAAVRODjAurf0CgNAzvwic/nk660Xuohll8mFvhl3bvkrcHME7tm2 7w9q9ImIUd8e0XsqYIbgyvxOuA== X-Google-Smtp-Source: APXvYqzBosUUlpCfqU5QqQmbDKPFIHn37l0LH+W7eqXbmoPsW6eir9mHjl5xs3JLZZLTVcuESB0Fbw== X-Received: by 2002:adf:f885:: with SMTP id u5mr4478652wrp.359.1578672990296; Fri, 10 Jan 2020 08:16:30 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 2/2] tests/tcg: add a vtimer test for aarch64 Date: Fri, 10 Jan 2020 16:16:26 +0000 Message-Id: <20200110161626.31943-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200110161626.31943-1-alex.bennee@linaro.org> References: <20200110161626.31943-1-alex.bennee@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: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 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: , Cc: Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Bug: https://bugs.launchpad.net/bugs/1859021 Signed-off-by: Alex Benn=C3=A9e --- tests/tcg/aarch64/system/vtimer.c | 80 +++++++++++++++++++++++ tests/tcg/aarch64/Makefile.softmmu-target | 4 ++ 2 files changed, 84 insertions(+) create mode 100644 tests/tcg/aarch64/system/vtimer.c diff --git a/tests/tcg/aarch64/system/vtimer.c b/tests/tcg/aarch64/system/v= timer.c new file mode 100644 index 00000000000..2f6299b5d2c --- /dev/null +++ b/tests/tcg/aarch64/system/vtimer.c @@ -0,0 +1,80 @@ +/* + * Simple Virtual Timer Tests + * + * Note: kvm-unit-tests has a much more comprehensive exercising of + * the timer sub-system. However this test case can tweak _EL2 values + * to trigger bugs which can't be done with that. + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +/* grabbed from Linux */ +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) + +#define read_sysreg(r) ({ \ + uint64_t __val; \ + asm volatile("mrs %0, " __stringify(r) : "=3Dr" (__val)); \ + __val; \ +}) + +#define write_sysreg(r, v) do { \ + uint64_t __val =3D (uint64_t)(v); \ + asm volatile("msr " __stringify(r) ", %x0" \ + : : "rZ" (__val)); \ +} while (0) + +/* Physical Counter */ +static uint64_t last_pct; +/* Timer Values */ +static uint32_t last_phys_tval; +static uint32_t last_virt_tval; + +static void dump_status(void) +{ + uint64_t pct =3D read_sysreg(cntpct_el0); + uint32_t phys_tval =3D read_sysreg(cntp_tval_el0); + uint32_t virt_tval =3D read_sysreg(cntv_tval_el0); + + ml_printf("timer values:\n"); + /* the physical timer monotonically increments */ + ml_printf("cntpct_el0=3D%ld (+%ld)\n", pct, pct - last_pct); + /* the various tvals decrement based on cval */ + ml_printf("cntp_tval_el0=3D%ld (-%ld)\n", phys_tval, + last_phys_tval - phys_tval); + ml_printf("cntv_tval_el0=3D%ld (-%ld)\n", virt_tval, + last_virt_tval - virt_tval); + + last_pct =3D pct; + last_phys_tval =3D phys_tval; + last_virt_tval =3D virt_tval; +} + +int main(void) +{ + int i; + + ml_printf("VTimer Tests\n"); + + dump_status(); + + ml_printf("Tweaking voff_el2 and cval\n"); + write_sysreg(cntvoff_el2, 1); + write_sysreg(cntv_cval_el0, -1); + + dump_status(); + + ml_printf("Enabling timer IRQs\n"); + write_sysreg(cntv_ctl_el0, 1); + /* for bug 1859021 we hang here */ + + dump_status(); + + ml_printf("End of Vtimer test\n"); + return 0; +} diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/= Makefile.softmmu-target index 7b4eede3f07..62cdddbb215 100644 --- a/tests/tcg/aarch64/Makefile.softmmu-target +++ b/tests/tcg/aarch64/Makefile.softmmu-target @@ -62,3 +62,7 @@ run-memory-replay: memory-replay run-memory-record "$< on $(TARGET_NAME)") =20 EXTRA_TESTS+=3Dmemory-record memory-replay + +# vtimer test +QEMU_EL2_MACHINE=3D-machine virt,virtualization=3Don,gic-version=3D2 -cpu = cortex-a57 -smp 4 +run-vtimer: QEMU_OPTS=3D$(QEMU_EL2_MACHINE) $(QEMU_SEMIHOST) -kernel --=20 2.20.1