From patchwork Tue Feb 11 17:48:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11376145 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F37B414B4 for ; Tue, 11 Feb 2020 17:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D21BF21569 for ; Tue, 11 Feb 2020 17:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581443466; bh=rJBmEKFRZFOWJv/B4wYb9PONOF6F0qnBy4rtT5zDmRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Q4Jvsb+j1VS0M6J4VeVX+2kt0MvZzRuF/Bcm6KHhd+OV7+NN+11ACWJ6+oQHElTRC tYrI1jGXV3cA7lIoCGNiFe7Jzn+7I5hFx38LBWn2HK6XvtL8MZp9sgTQ0NoVi10AUJ m7t4yoMLmQswHJnivAS5w1GS1/xVAgHtaVKFO1vM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730161AbgBKRvG (ORCPT ); Tue, 11 Feb 2020 12:51:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:53244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730103AbgBKRvF (ORCPT ); Tue, 11 Feb 2020 12:51:05 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D3D83206CC; Tue, 11 Feb 2020 17:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581443465; bh=rJBmEKFRZFOWJv/B4wYb9PONOF6F0qnBy4rtT5zDmRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BqTob0BqhPgzNi5/b9r+TN6JYuiw7rmAanEUHhQiUzVWdVX2DkldPd4AtBiWJvtEf Gr8szpPUauAVh73orHzwprtH1y9k1VxkhzMEjzryJu8vg0BaIUHTBQ4Cy5DCqAT4wk P8dthgUEXxmXo3EZivUgN6Ty9jLHRkG1TyWIWJVk= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j1Zfy-004O7k-8f; Tue, 11 Feb 2020 17:50:22 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: Andre Przywara , Christoffer Dall , Dave Martin , Jintack Lim , Alexandru Elisei , James Morse , Julien Thierry , Suzuki K Poulose Subject: [PATCH v2 49/94] KVM: arm64: nv: Propagate CNTVOFF_EL2 to the virtual EL1 timer Date: Tue, 11 Feb 2020 17:48:53 +0000 Message-Id: <20200211174938.27809-50-maz@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200211174938.27809-1-maz@kernel.org> References: <20200211174938.27809-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, andre.przywara@arm.com, christoffer.dall@arm.com, Dave.Martin@arm.com, jintack@cs.columbia.edu, alexandru.elisei@arm.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We need to allow a guest hypervisor to virtualize the virtual timer. FOr that, let's propagate CNTVOFF_EL2 to the guest's view of that timer. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 1 - arch/arm64/kvm/sys_regs.c | 7 ++++++- include/kvm/arm_arch_timer.h | 1 + virt/kvm/arm/arch_timer.c | 8 ++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 36bb463dc16a..e35165de51a2 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -247,7 +247,6 @@ enum vcpu_sysreg { RMR_EL2, /* Reset Management Register */ CONTEXTIDR_EL2, /* Context ID Register (EL2) */ TPIDR_EL2, /* EL2 Software Thread ID Register */ - CNTVOFF_EL2, /* Counter-timer Virtual Offset register */ CNTHCTL_EL2, /* Counter-timer Hypervisor Control register */ SP_EL2, /* EL2 Stack Pointer */ diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 5d9ca3988745..7e2553480721 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1373,6 +1373,11 @@ static bool access_arch_timer(struct kvm_vcpu *vcpu, tmr = TIMER_PTIMER; treg = TIMER_REG_CVAL; break; + case SYS_CNTVOFF_EL2: + tmr = TIMER_VTIMER; + treg = TIMER_REG_VOFF; + break; + default: BUG(); } @@ -2075,7 +2080,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_CONTEXTIDR_EL2), access_rw, reset_val, CONTEXTIDR_EL2, 0 }, { SYS_DESC(SYS_TPIDR_EL2), access_rw, reset_val, TPIDR_EL2, 0 }, - { SYS_DESC(SYS_CNTVOFF_EL2), access_rw, reset_val, CNTVOFF_EL2, 0 }, + { SYS_DESC(SYS_CNTVOFF_EL2), access_arch_timer }, { SYS_DESC(SYS_CNTHCTL_EL2), access_rw, reset_val, CNTHCTL_EL2, 0 }, { SYS_DESC(SYS_CNTHP_TVAL_EL2), access_arch_timer }, diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 3a5d9255120e..3389606f3029 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -23,6 +23,7 @@ enum kvm_arch_timer_regs { TIMER_REG_CVAL, TIMER_REG_TVAL, TIMER_REG_CTL, + TIMER_REG_VOFF, }; struct arch_timer_context { diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index c7edefced838..3c88a4c0a296 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -917,6 +917,10 @@ static u64 kvm_arm_timer_read(struct kvm_vcpu *vcpu, val = kvm_phys_timer_read() - timer->cntvoff; break; + case TIMER_REG_VOFF: + val = timer->cntvoff; + break; + default: BUG(); } @@ -959,6 +963,10 @@ static void kvm_arm_timer_write(struct kvm_vcpu *vcpu, timer->cnt_cval = val; break; + case TIMER_REG_VOFF: + timer->cntvoff = val; + break; + default: BUG(); }