From patchwork Tue Feb 4 12:50:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 861815 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:11cb:b0:385:e875:8a9e with SMTP id i11csp278880wrx; Tue, 4 Feb 2025 04:52:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUc80pegP5OrLvDQE8bADI6AjBacGhjpOB3V5eJnFzgstYisZijEqhqnbcpc67vc2yVgrSYkA==@linaro.org X-Google-Smtp-Source: AGHT+IFpZjdXof3HhkJYOH2kxtH8mv05M+sfVAa1Is874Q4tEepXSNmH/uButLvpzuhWDDpGdkZg X-Received: by 2002:a05:620a:2a13:b0:7b1:ae6c:fc60 with SMTP id af79cd13be357-7bffccea1bdmr4173127685a.8.1738673568528; Tue, 04 Feb 2025 04:52:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738673568; cv=none; d=google.com; s=arc-20240605; b=jmrRAYxG960s89Q47r4dqd3hNh6/cqHZY6cojF84SfQf+Soimsph9G7N30ghZJLHmk aKSMUlc6DcKJB++EtTClCdLbzS0KaDvzM/cgrDnVPGqDt/xEyJ5StxGKQyjoGzKTrigq QbAObAX36yS8oFAat1KpV+4gOefAcDnsHC0MOi/uvEas8kB9FpBzUUq+hnWMZNGx0m/z bkiyHmh0PVyGnWySr+eCU5MzN35tMkDK5WL3R/xeBoAiq+jGRyCas7MAdM71kC80/o1j rRkVFcGQP7Qd9/Tj4qQreh+V+O5UBmY6WIJVeFizyCzbnt7NFd12Ot45VQscR6lZKT29 i1zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5cl2nmICirpIXVtF8Zl43t73+3pCHJ4PZJWOB63ih4s=; fh=yk42NAs0G6hyBBihKuY1GyWIhxzQSIq/x2X1hV5SSi8=; b=VKpACFeVBrNJMIPYc9R3M7tQcm2NwxtUbLfI4Li8UbMQOft07cw5w8m6Gai0H5LMFA z44oM5JdXviRLVW9I+YMfVUuJXrAbfST8fbpD5YY/ZL+Ef11mNO7fQ7hPmXdUXF1owWT YfLph7bxmwR1dnHDELjaLVshP9IxlCpFF9138KU3zSoe2uCQvy6l9CD8jwd6jsBEO0iA 1jkPPxo8qDAH3uC3vIlFOtefOHwMkVmuSzoqqSI0K1O53fg7p64etpo5gzHOC5qX/B4l kjTKJj4PBFSJX+VNhH/reEnLs0YBcrO7ek1VK9+WpRKQ5wYsnkAOBWSyAdNk+bBoiE31 IOHg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YqfVa9dp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c02db4b7bbsi254339685a.127.2025.02.04.04.52.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Feb 2025 04:52:48 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YqfVa9dp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tfIO2-00005V-Rb; Tue, 04 Feb 2025 07:50:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tfINe-0008JM-3y for qemu-devel@nongnu.org; Tue, 04 Feb 2025 07:50:18 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tfINa-00029C-VG for qemu-devel@nongnu.org; Tue, 04 Feb 2025 07:50:17 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-38632b8ae71so4665268f8f.0 for ; Tue, 04 Feb 2025 04:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738673413; x=1739278213; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5cl2nmICirpIXVtF8Zl43t73+3pCHJ4PZJWOB63ih4s=; b=YqfVa9dpzxiR8jRkudOrwWJJEpan3CBqJbKh2m3p7sYaH1ftLVJSa4G/qg4VYKOp3w DEYXmVDp1kMyT/3BSGzBrST10kYa57WSUqmZkczFgCeC6yU5nM3ekZgcb2iqENkHpkoK dpyvtb15vvr/Xoc7YwDz3BvS5UvdoSvp1kN5T9PES13G4CAWjSjexybLQo23TRHuaIPG oQqKPvX3vhUpS9ou/cM5VVlhXb4PtahUt/jF8ii8SeQwPG2XRb+CnVnuuGxSpr2Xd2Uv Z6FbSJ3F9gnF7WnNhYb3AfqRU5TiAXofZP7jhtVhAeXJmNAJSA5lRX5iBzTnL3bM8dL1 tweA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738673413; x=1739278213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5cl2nmICirpIXVtF8Zl43t73+3pCHJ4PZJWOB63ih4s=; b=v0Lpm980fSGDSdUUfg+CmNM3s7r/RSmPik0yI+0oLFWZpjd4BN8i3bMJruVRpEgM4O PeFhkqAjCC7UlquLD5umzzIClLykjhYeCFmT87uftqrOlbyuqW5f4TQjcga8JzULRwm/ wSKK+qIXjVb7pYZZkRD4PU2HpSbx4YkEBdwb0cw80v8vYSBlAi78t1SmhaS+TRyCKZte x53YLa7snQcdmw20kCJ0xDYW5RBwQ2wLep2FKIJgg2pnrBTQy72gcjLbzRu2OJnQbPf5 BK3sRuYTnmpQAvDOh9UdGKGjBQdj36PeSTeVDwkFpvbWERVaWj7e/kSAILsz756mncRH FHHQ== X-Forwarded-Encrypted: i=1; AJvYcCVbKBgOdooK90kNw2KKXv+ayD79TZstltXP1g85cOb0Mkcfn8bGIoIm/rBriPZU3Dq0NydfpzTx17Fo@nongnu.org X-Gm-Message-State: AOJu0YyKjVa723n1S49AOSeu88i8QzZTKEQKFlZ6AYGNBhA2L/Hs4GD9 eD9npkMB7Bhll+SUiyRiYS6hoQTnB8tf6VSOKLOmhexXiQRxEkjfrOZsV08Ht+0= X-Gm-Gg: ASbGncv5yaWAOtWM/hc3O1e+BPyba1CUcxTkd8AvPk/jZUDl2tvvpzeX0pvnR/4Xnw6 T0T7RVCjKseD5qhbUb/AqeKb68J8tQO/0Hq60/Imn8V4Wecf8y9KUBXSL65cX+cge7BBjE++AZ2 rGwYh6zTOHfhfGnmZKUVzOi5yhlkeUW92hJX4DjnHCa6I2hvEnLQLyt2k78U7HPP23xmpkHiFk1 f8UAtkjLFO49ArYgJU43ko/FVRjMYz6a9fPPVpZxS5lgpsyAplDn12C8xtJh3uk5N4X3EM6KfHn UPGW5Xr6UnaNheK+2VrPZw== X-Received: by 2002:a05:6000:50c:b0:38a:8906:6b66 with SMTP id ffacd0b85a97d-38c52097153mr17445706f8f.38.1738673413147; Tue, 04 Feb 2025 04:50:13 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c5c122465sm15757919f8f.47.2025.02.04.04.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2025 04:50:12 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v3 1/9] target/arm: Apply correct timer offset when calculating deadlines Date: Tue, 4 Feb 2025 12:50:01 +0000 Message-Id: <20250204125009.2281315-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250204125009.2281315-1-peter.maydell@linaro.org> References: <20250204125009.2281315-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When we are calculating timer deadlines, the correct definition of whether or not to apply an offset to the physical count is described in the Arm ARM DDI4087 rev L.a section D12.2.4.1. This is different from when the offset should be applied for a direct read of the counter sysreg. We got this right for the EL1 physical timer and for the EL1 virtual timer, but got all the rest wrong: they should be using a zero offset always. Factor the offset calculation out into a function that has a comment documenting exactly which offset it is calculating and which gets the HYP, SEC, and HYPVIRT cases right. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell --- target/arm/helper.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 1fee8fae127..049362a5500 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2460,6 +2460,32 @@ static uint64_t gt_phys_cnt_offset(CPUARMState *env) return gt_phys_raw_cnt_offset(env); } +static uint64_t gt_indirect_access_timer_offset(CPUARMState *env, int timeridx) +{ + /* + * Return the timer offset to use for indirect accesses to the timer. + * This is the Offset value as defined in D12.2.4.1 "Operation of the + * CompareValue views of the timers". + * + * The condition here is not always the same as the condition for + * whether to apply an offset register when doing a direct read of + * the counter sysreg; those conditions are described in the + * access pseudocode for each counter register. + */ + switch (timeridx) { + case GTIMER_PHYS: + return gt_phys_raw_cnt_offset(env); + case GTIMER_VIRT: + return env->cp15.cntvoff_el2; + case GTIMER_HYP: + case GTIMER_SEC: + case GTIMER_HYPVIRT: + return 0; + default: + g_assert_not_reached(); + } +} + static void gt_recalc_timer(ARMCPU *cpu, int timeridx) { ARMGenericTimer *gt = &cpu->env.cp15.c14_timer[timeridx]; @@ -2469,8 +2495,7 @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx) * Timer enabled: calculate and set current ISTATUS, irq, and * reset timer to when ISTATUS next has to change */ - uint64_t offset = timeridx == GTIMER_VIRT ? - cpu->env.cp15.cntvoff_el2 : gt_phys_raw_cnt_offset(&cpu->env); + uint64_t offset = gt_indirect_access_timer_offset(&cpu->env, timeridx); uint64_t count = gt_get_countervalue(&cpu->env); /* Note that this must be unsigned 64 bit arithmetic: */ int istatus = count - offset >= gt->cval;