From patchwork Sat Mar 15 06:17:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 873834 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1062017wrq; Fri, 14 Mar 2025 23:25:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUqwahtzy5NS0jGUzTXQFffmpJGFIyKv1aBsx/j9iVG1oD/WOhXSfpZriMNcl375/6yX1OXAw==@linaro.org X-Google-Smtp-Source: AGHT+IE8jgxmOIUpzv93ZHcKMVTLevgJzDycXlJJZcUmKd80sX8YlDpXSbCtFPUShWEbeLzndoVt X-Received: by 2002:a05:622a:47ca:b0:476:af54:5038 with SMTP id d75a77b69052e-476c8151059mr60007781cf.22.1742019914078; Fri, 14 Mar 2025 23:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742019914; cv=none; d=google.com; s=arc-20240605; b=iY+x6jVjIdvMz4uBdvEkzwOVco+v/FArn7rUkqCmy0+d26twb7AqttbXORRCxAas3x 1o8q1DSZDKEPhQpY0WoTEa5nIjGEQy4Xhc5wbrlitCEg/y822+z43kCcdCBqgz7xJSDr yWFfDulkwNT61mrqutlkzB8GupVz3LMIlYS4WqIiS94HEf7DNpjSzmvzZg/OGueV96KM wRhqbA1nulI7+3U2zkVKLAsYXMFIlWuTUcxklLc4HqW6pUgZSbQn7SzDqbbTTG0djv/d uOJHecAuWa0EN2BWERUo0k2EDFkpUe0KlGzms1AJxASThwKti0zTJOWXXxSx3cEVI0e7 Rwyg== 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; bh=QjoEBZlu07MD3YBKJz0Lrwya5FoRF4zhqTFnuAOsXjo=; fh=AguBzhNxG2iiwyQKHwF5YtCZ+FV/izMb9THQLjUeXjw=; b=I6GENltTRrmk6SrT2fpNqFsEiISK9xgq+93mmQm0I8Q96FSkpM562wkn2QI+G+V8X4 TYRZF6zbx1gYhYQjeoN8qhz7pGMdFuW4MzF+oavTr6g1YRfkQjKYu1a9GmFW2wWms/1T b6D3R8gHKDrdReokkMPXR1t6qCvs9Mzk9ebJljJY7rcPGkEKLY9MYebDqVxkaFZYhFWe 8qCcmBQM7hOYv7+O2TVpbDB82ZJci7cx7I2aIGO/QyM0pajj2f99oofYIrmNMPesyf4i /i6YabHb8MaszgQ0qU4jNfn13J52AamDPbJqmLUzpbHAKxtyqSi35Hflxbg6fQV3yaeC Ax/A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-476bb856bffsi54946491cf.521.2025.03.14.23.25.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Mar 2025 23:25:14 -0700 (PDT) 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; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ttKu3-0000dM-11; Sat, 15 Mar 2025 02:21:47 -0400 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 1ttKtS-0007I3-Sn; Sat, 15 Mar 2025 02:21:11 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ttKtQ-0003hE-GK; Sat, 15 Mar 2025 02:21:10 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id DFC29FF9EB; Sat, 15 Mar 2025 09:17:07 +0300 (MSK) Received: from gandalf.tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with ESMTP id B73811CAC54; Sat, 15 Mar 2025 09:18:01 +0300 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 75523558ED; Sat, 15 Mar 2025 09:18:01 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Michael Tokarev Subject: [Stable-9.2.3 31/51] target/arm: Apply correct timer offset when calculating deadlines Date: Sat, 15 Mar 2025 09:17:37 +0300 Message-Id: <20250315061801.622606-31-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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 From: Peter Maydell 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 (cherry picked from commit db6c2192839ee0282d38f6f6666a87e0629fcd13) Signed-off-by: Michael Tokarev diff --git a/target/arm/helper.c b/target/arm/helper.c index 8df38a30a1..417801d9c3 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2727,6 +2727,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]; @@ -2736,8 +2762,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;