From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3E83746C for ; Thu, 16 Feb 2023 14:31:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7094DC433A4; Thu, 16 Feb 2023 14:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676557886; bh=nIEyPcKSfGn/aSgYLXrCxCTer43Vb54hmCW7FGQkIaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jEpPqpYpXevvEFZAEcFOWQNHhfZGycRUi27WB3IhTLYEL8HDupxTALjOklRrHi5lB MuRZkHfSpXHT5YsZXUMk2oYjvuTPGFYH/6/lk12pvxLmGO6fCc0EOhvNgkCsnkZUvd a65QGRQcIoBknR5ws1QYhVXG8LChHSbvtdOJ+bvcuBq3xwzydGHwu+7sSCkBbXZMiP o7Xzb6q4YPO3gLb02SEE/MQ99joTwgWDsrzh9goMPQXH5v0nzxcK9GdakAJq4f0tt8 Oa0PRBUW201IHf7YeytBF4COqp/iC7QOdF3gYSnBlNeQWeye+jGDXBvTpV6ftd8f5J qVdJj7Zo5DkTg== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pSf8w-00AuwB-0A; Thu, 16 Feb 2023 14:21:50 +0000 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Ricardo Koller , Simon Veith , dwmw2@infradead.org Subject: [PATCH 12/16] KVM: arm64: nv: timers: Add a per-timer, per-vcpu offset Date: Thu, 16 Feb 2023 14:21:19 +0000 Message-Id: <20230216142123.2638675-13-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216142123.2638675-1-maz@kernel.org> References: <20230216142123.2638675-1-maz@kernel.org> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, ricarkol@google.com, sveith@amazon.de, dwmw2@infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Being able to set a global offset isn't enough. With NV, we also need to a per-vcpu, per-timer offset (for example, CNTVCT_EL0 being offset by CNTVOFF_EL2). Use a similar method as the VM-wide offset to have a timer point to the shadow register that contains the offset value. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/arch_timer.c | 13 ++++++++++--- include/kvm/arm_arch_timer.h | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index f968d6d3479b..1f442ac0c499 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -84,10 +84,17 @@ u64 timer_get_cval(struct arch_timer_context *ctxt) static u64 timer_get_offset(struct arch_timer_context *ctxt) { - if (ctxt && ctxt->offset.vm_offset) - return *ctxt->offset.vm_offset; + u64 offset = 0; - return 0; + if (!ctxt) + return 0; + + if (ctxt->offset.vm_offset) + offset += *ctxt->offset.vm_offset; + if (ctxt->offset.vcpu_offset) + offset += *ctxt->offset.vcpu_offset; + + return offset; } static void timer_set_ctl(struct arch_timer_context *ctxt, u32 ctl) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 62ef4883e644..e76e513b90c5 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -29,6 +29,11 @@ struct arch_timer_offset { * structure. If NULL, assume a zero offset. */ u64 *vm_offset; + /* + * If set, pointer to one of the offsets in the vcpu's sysreg + * array. If NULL, assume a zero offset. + */ + u64 *vcpu_offset; }; struct arch_timer_vm_offsets { -- 2.34.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57177C61DA4 for ; Thu, 16 Feb 2023 14:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rfWkdhsIgJnSpjTJZEEsmBWuhblk1/tpKzcJ3daVJxc=; b=TnYiPHk5L88yiT P4HHCYief4nCYe7yeY9jbrTcifkiJhd0ofLm31voXynLZR0X/R7EJAj0TuGSiusKAUmKOR8T4ho0X 4XNOwSWnAMPDb3GAdJueVJmdnqcSPrcfuEd/Gc7ExpRxcFXtCFxAId5O7AXs7Dv8iGl5z6xHhq6q3 SH4RcLefqm7I/0sba4BC42YAtM/OTfQrEdT10NGZCo2nVnrQMSkZfoFk5sg8LfzqGM9AId1bdzbLv t27TFWxhD/fyIr1p9nhk0PXguUsJoma9HxNOaIBeOEa8z1urBdudPqaJn6Tbx6gNf+Amr2XvFuLB0 g8WujWI8B2s7ddJgqPpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSfJT-00Aedl-RH; Thu, 16 Feb 2023 14:32:44 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSfIF-00Ae2z-7M for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2023 14:31:30 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A2130614F8; Thu, 16 Feb 2023 14:31:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7094DC433A4; Thu, 16 Feb 2023 14:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676557886; bh=nIEyPcKSfGn/aSgYLXrCxCTer43Vb54hmCW7FGQkIaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jEpPqpYpXevvEFZAEcFOWQNHhfZGycRUi27WB3IhTLYEL8HDupxTALjOklRrHi5lB MuRZkHfSpXHT5YsZXUMk2oYjvuTPGFYH/6/lk12pvxLmGO6fCc0EOhvNgkCsnkZUvd a65QGRQcIoBknR5ws1QYhVXG8LChHSbvtdOJ+bvcuBq3xwzydGHwu+7sSCkBbXZMiP o7Xzb6q4YPO3gLb02SEE/MQ99joTwgWDsrzh9goMPQXH5v0nzxcK9GdakAJq4f0tt8 Oa0PRBUW201IHf7YeytBF4COqp/iC7QOdF3gYSnBlNeQWeye+jGDXBvTpV6ftd8f5J qVdJj7Zo5DkTg== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pSf8w-00AuwB-0A; Thu, 16 Feb 2023 14:21:50 +0000 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Ricardo Koller , Simon Veith , dwmw2@infradead.org Subject: [PATCH 12/16] KVM: arm64: nv: timers: Add a per-timer, per-vcpu offset Date: Thu, 16 Feb 2023 14:21:19 +0000 Message-Id: <20230216142123.2638675-13-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216142123.2638675-1-maz@kernel.org> References: <20230216142123.2638675-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, ricarkol@google.com, sveith@amazon.de, dwmw2@infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230216_063127_409886_713AA499 X-CRM114-Status: GOOD ( 16.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Being able to set a global offset isn't enough. With NV, we also need to a per-vcpu, per-timer offset (for example, CNTVCT_EL0 being offset by CNTVOFF_EL2). Use a similar method as the VM-wide offset to have a timer point to the shadow register that contains the offset value. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/arch_timer.c | 13 ++++++++++--- include/kvm/arm_arch_timer.h | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index f968d6d3479b..1f442ac0c499 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -84,10 +84,17 @@ u64 timer_get_cval(struct arch_timer_context *ctxt) static u64 timer_get_offset(struct arch_timer_context *ctxt) { - if (ctxt && ctxt->offset.vm_offset) - return *ctxt->offset.vm_offset; + u64 offset = 0; - return 0; + if (!ctxt) + return 0; + + if (ctxt->offset.vm_offset) + offset += *ctxt->offset.vm_offset; + if (ctxt->offset.vcpu_offset) + offset += *ctxt->offset.vcpu_offset; + + return offset; } static void timer_set_ctl(struct arch_timer_context *ctxt, u32 ctl) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 62ef4883e644..e76e513b90c5 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -29,6 +29,11 @@ struct arch_timer_offset { * structure. If NULL, assume a zero offset. */ u64 *vm_offset; + /* + * If set, pointer to one of the offsets in the vcpu's sysreg + * array. If NULL, assume a zero offset. + */ + u64 *vcpu_offset; }; struct arch_timer_vm_offsets { -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel