From patchwork Fri Mar 7 15:06:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 871188 Delivered-To: patch@linaro.org Received: by 2002:a5d:64c8:0:b0:38f:210b:807b with SMTP id f8csp809301wri; Fri, 7 Mar 2025 07:09:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUQ4qo3Gxb7EXoQFuVvb9kr55rjeUGDErQph1I/sYmaRvhLlV5kiUkkJleDaW+v59o53mrTeQ==@linaro.org X-Google-Smtp-Source: AGHT+IEtwaq10cwTqydwTSkVo2yhCJjIy+dihdAWzH03u0rY9t6lfZ5rMYgGxpnsqV3vLPFujsl3 X-Received: by 2002:a05:620a:8017:b0:7c3:dc24:ce9d with SMTP id af79cd13be357-7c4e1676833mr644656285a.7.1741360173340; Fri, 07 Mar 2025 07:09:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741360173; cv=none; d=google.com; s=arc-20240605; b=Ptd59JaT82t6kvkffP9pikP2KsiBTEXB8Ttpx+PM+X4GxiL0KAbuqVv/JmoCG3iHNr MIFLmotS3jxT46guLa/0SNztS4MniGLjrGzVVHIWOdZqM8Yku2pB1t+ImBTvYFU+WVEr bJF1+JwABvt4XEC23QOEQPrFHp1Q9hODloZKNi03iO06P+khV66AmmptysAgzoxsaOjR RHTtJFn+lhkUGOJp8wbdmm1mHVXKUAR/nq8b8zpgBUkRTXXxdmTpOKy/+Iebw9jP3kUO QZq6MKGZzIRI5wk0v0eRcGozahhD0/1NnP/96QO1WFH3ZcCYqR/J6cHcAgOJ2zwWuOFP TsJA== 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:to:from :dkim-signature; bh=aSWu7SERkDl4TrKpc52a/rImNAR7H05Ny8NJ0H5vIQY=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=QHRU+YPJ5hAtmltN4283lmMygadrPrl+c7lIsO6bbENXqFXFZoe9g9y94Hrdk/kL1p f0wXd1liSTjmwre5WrEHQS2Z/vQouzwCMse8cNsgs422cLsgpfvBgmZ3wdU0o1/FMUsD TSiOCNC+oBL9HCZ7a1xlraiTAncn6jW7B5biKZiCbItI4SlqRm9kDKxBqVA1WB9KTdiQ bLnFRYalXrAMngG/2GAg6rGD2/K9tVFV2eJSw7/xEXNNLO9b+PEq43K+QQvkm1cs+Aot A+cznq2z5A3CWiFimOP+uIX7KQbTAg7S2j6LmG0V9YgzP3W9y5GR8fsmEOuEjlzseENL DMaA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uCABt+86; 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-7c3e550f8dcsi362380885a.353.2025.03.07.07.09.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Mar 2025 07:09:33 -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=uCABt+86; 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 1tqZIL-0000x2-So; Fri, 07 Mar 2025 10:07:25 -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 1tqZIH-0000vM-8e for qemu-devel@nongnu.org; Fri, 07 Mar 2025 10:07:21 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqZIF-0008D3-I0 for qemu-devel@nongnu.org; Fri, 07 Mar 2025 10:07:21 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-39129fc51f8so1697890f8f.0 for ; Fri, 07 Mar 2025 07:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741360038; x=1741964838; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=aSWu7SERkDl4TrKpc52a/rImNAR7H05Ny8NJ0H5vIQY=; b=uCABt+866vWW+CObqd+rU+h5jLeK34m7UnixvPcPSfrRkwo30yZ6OVIg42KCJEfRB/ FJSrNcv70X/YDA0mICK1XF11NpTK+mH6x0LuGrUjh+FlZNC+ICGQwxHf+TTCUZB4OAKc 6RNuhKALz3xR6lZJW4U4FvjE7e0+DIGG3qH7wp8zV03l0ydcHakph6Yr9+kOPgl7XG5s lFU7x/j1nwCafkjmkq9ol6jBt2O4k4UNekvYvDc2CcCSrKFPF10ED1oEiE25rklw4e4z KzU+mKGWpqcQ+3ibGIfhhtInUXViH//sH6NWon4Wy/qki0Jp8WinFIb8DjzKKs+VgKvu bAkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741360038; x=1741964838; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aSWu7SERkDl4TrKpc52a/rImNAR7H05Ny8NJ0H5vIQY=; b=E4VaY8DkhSA/HVU5oiHVpJzsLb1sfvk8zq23NJzuOEaKKJE+AhKrg64egjQGlCHBGy 9yHWqsF9fT/GhrZBDp7v+lVYiJOnz+xKYSxaAg3FOWtWFOcjUz5PfC+vEIf5k4XwIeTZ KsuWVPXhhAI+h4QPKMXeXP5MFjO1aJjuqI0qnOVNZpSmNJs8pi5zgKhGw7sqzO9greOc Q+3/9b3qQmV6/9hLWpQ2QdUsiYRCbxVdahpc0JUme5kH8JrtJYT1tlKh7nLBxE4Sxj+m 0ZmxJzYjyrLcLSGDBzv/zHTuqIHx1RS2OdjLasUC+YE9hQEUSAbrE3NQAoCHYc9hGz2b pl6g== X-Gm-Message-State: AOJu0Yza7hz1cWjjK572Dre7K0ZmDpiLecRLsoMxm8v/Sh8JHhR2Jifc oeYbueDn6XfFLVRynOFp8OrlQkDX4If+P4ZBc/ctcwyyt1J2I/tFdYWDujHDrtdrFIN1yRXx7ef m X-Gm-Gg: ASbGncsRRor+VY1Gg/r0rydGTevtLgycGaDPSQubSSlxXdAauRoETbEVC8FCdGTSmYw r7bZ1xyUz/KO5HZytYMWmlzEG+74VrTWtbP1dRFLCOb0Rf7K3+E7K7dbEiZ5jsIg9B01eGZbLGy fXdvduK/BVyiMJJyKNAl46t4P/xG94t8EHkRitQnzwesAA9o9b12QcSpux/877wMLqN35IyEYO0 9deyLuztKkiTdMbYe4TmOEeHLtIqoe6cgnu3fkKZHGY/QKIVqKONx4j2EEOEFLarYnh8DXnQoQd 7nC4A72JgDBf1+FZLRIXYWvqs6YMVyQWs3DPT4343pIDe/D/1UM= X-Received: by 2002:a05:6000:1fa9:b0:391:2e31:c7e1 with SMTP id ffacd0b85a97d-39132d2b0ebmr2397201f8f.4.1741360036529; Fri, 07 Mar 2025 07:07:16 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912c1031fdsm5443627f8f.89.2025.03.07.07.07.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 07:07:15 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 04/21] target/arm: Apply correct timer offset when calculating deadlines Date: Fri, 7 Mar 2025 15:06:51 +0000 Message-ID: <20250307150708.3222813-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250307150708.3222813-1-peter.maydell@linaro.org> References: <20250307150708.3222813-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.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=ham 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 Reviewed-by: Alex Bennée Message-id: 20250204125009.2281315-2-peter.maydell@linaro.org --- 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 71dead7241b..7f341d753cd 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;