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 852C57479 for ; Thu, 16 Feb 2023 14:21:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 033A3C433A8; Thu, 16 Feb 2023 14:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676557311; bh=rCEjLLVsTGonFud3H7BkWOpBovbyq0wpTVXBpO5J6GE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=coJ+WuougGjW/dNobIz865CknMyLAE5fjJdQEW+mGMmcDgUKxiNHIqyVTptljtaII +pfCAabezbp2pdA3AZ4kwkyiRywf5XBay8G0ME4nVO72pe/aXzmZrvZ4jTP6xQpifJ /88LDImUQHNa5qWxel2mdKlCpZrqpXSI9rUjPvUnCR4AYhpHS91ZN5KFylCAPm4hPA RIKzZxDjGsoC2LAzFuC9/PThvp3WEWmWEwNpueId0agGBM75Hp5nRL8KyzKsLz04Dq YY8Z68IPRuJtLJIrYfLc5uCFJGJZ2Yk4h88Puw62P9VbJ4D0maz2R2G/0yAj3HWKKp jh5Es3YIASw8w== 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 1pSf8v-00AuwB-93; Thu, 16 Feb 2023 14:21:49 +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 09/16] KVM: arm64: timers: Allow save/restoring of the physical timer Date: Thu, 16 Feb 2023 14:21:16 +0000 Message-Id: <20230216142123.2638675-10-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 Nothing like being 10 year late to a party! Now that userspace can set counter offsets, we can save/restore the physical timer as well! Nobody really cared so far, but you're welcome anyway. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/guest.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 07444fa22888..46e910819de6 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -590,11 +590,16 @@ static unsigned long num_core_regs(const struct kvm_vcpu *vcpu) return copy_core_reg_indices(vcpu, NULL); } -/** - * ARM64 versions of the TIMER registers, always available on arm64 - */ +static const u64 timer_reg_list[] = { + KVM_REG_ARM_TIMER_CTL, + KVM_REG_ARM_TIMER_CNT, + KVM_REG_ARM_TIMER_CVAL, + KVM_REG_ARM_PTIMER_CTL, + KVM_REG_ARM_PTIMER_CNT, + KVM_REG_ARM_PTIMER_CVAL, +}; -#define NUM_TIMER_REGS 3 +#define NUM_TIMER_REGS ARRAY_SIZE(timer_reg_list) static bool is_timer_reg(u64 index) { @@ -602,6 +607,9 @@ static bool is_timer_reg(u64 index) case KVM_REG_ARM_TIMER_CTL: case KVM_REG_ARM_TIMER_CNT: case KVM_REG_ARM_TIMER_CVAL: + case KVM_REG_ARM_PTIMER_CTL: + case KVM_REG_ARM_PTIMER_CNT: + case KVM_REG_ARM_PTIMER_CVAL: return true; } return false; @@ -609,14 +617,11 @@ static bool is_timer_reg(u64 index) static int copy_timer_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) { - if (put_user(KVM_REG_ARM_TIMER_CTL, uindices)) - return -EFAULT; - uindices++; - if (put_user(KVM_REG_ARM_TIMER_CNT, uindices)) - return -EFAULT; - uindices++; - if (put_user(KVM_REG_ARM_TIMER_CVAL, uindices)) - return -EFAULT; + for (int i = 0; i < NUM_TIMER_REGS; i++) { + if (put_user(timer_reg_list[i], uindices)) + return -EFAULT; + uindices++; + } return 0; } -- 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 500B5C636CC for ; Thu, 16 Feb 2023 14:24:38 +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=9HJktr3n9RT3SyKBnSeMlPQmfsu2HXnAAEKJxb5mW30=; b=PK+e+BghebLUNR j/OUow1k41hp10ZJ5EInefXnMTjTPcgtKom0XPSmmtuq9GP/HHzguVW0/5LlXgPdoN2j0X1O9wwVP GAj4F6Mt7jf9bjNUZ6v3ZHNoiOxFaleaTaycjd1GysbjCyOshVw+a1LC+CHtzKOEAO0jAWwz0WYNR nmUx70HAmCCUAHpFqL0b0qaA1doJdZgvDazGU5GFuyCf3LlTc27H5/mLVMKZhcqowOdVJMVug8wyk qhPvg2pGURw6nlp3ZzMLAmPG4Y2wLwaPhQGnLXR8thfX57DJl+n//ACgP38/q4SDS0pvNHWT0WLy4 yw+u++8uZSh2lB8zCZ9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSfAV-00AaAc-Nr; Thu, 16 Feb 2023 14:23:28 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSf9A-00AZYx-57 for linux-arm-kernel@bombadil.infradead.org; Thu, 16 Feb 2023 14:22:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=sqePgZReL/W7zkJFR3huj8RAP6smyl0ILKYxIP18UgY=; b=VaQOcTRmaYzsKW/K3oVOGxyoct 2Atf4tCV9mWct3qDLUKcb3qZVIa/jGDLAQf1PtDK9x/bxa4e/2V/pcUdyCwvvxIwX5tbdpls4H76Y 7NIfNMHX63Mz/dbI4iRKTfEnHqW522HtJcT+UIp3lfYLs/D4Y8acEXiNUbxQ/kr7I++QAYYUklaml Q89tL5/AXcSS2ZW1narf16EhU4qjW8wrdx2Mkc3NKBve8EDxOOwfgbNzyMNYpvZusTHBfDQZZ0BZ7 9DOAXgkBuHDnw+ReCNPa0jft2C5v4+HKds2lc1iiFOrRetbD8b3a6RANZ+TUSwE7Lp9lGg1YO6VEC 9jSzBBPw==; Received: from ams.source.kernel.org ([145.40.68.75]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pSf8M-00AItc-1t for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2023 14:22:02 +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 ams.source.kernel.org (Postfix) with ESMTPS id 378C3B82847; Thu, 16 Feb 2023 14:21:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 033A3C433A8; Thu, 16 Feb 2023 14:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676557311; bh=rCEjLLVsTGonFud3H7BkWOpBovbyq0wpTVXBpO5J6GE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=coJ+WuougGjW/dNobIz865CknMyLAE5fjJdQEW+mGMmcDgUKxiNHIqyVTptljtaII +pfCAabezbp2pdA3AZ4kwkyiRywf5XBay8G0ME4nVO72pe/aXzmZrvZ4jTP6xQpifJ /88LDImUQHNa5qWxel2mdKlCpZrqpXSI9rUjPvUnCR4AYhpHS91ZN5KFylCAPm4hPA RIKzZxDjGsoC2LAzFuC9/PThvp3WEWmWEwNpueId0agGBM75Hp5nRL8KyzKsLz04Dq YY8Z68IPRuJtLJIrYfLc5uCFJGJZ2Yk4h88Puw62P9VbJ4D0maz2R2G/0yAj3HWKKp jh5Es3YIASw8w== 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 1pSf8v-00AuwB-93; Thu, 16 Feb 2023 14:21:49 +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 09/16] KVM: arm64: timers: Allow save/restoring of the physical timer Date: Thu, 16 Feb 2023 14:21:16 +0000 Message-Id: <20230216142123.2638675-10-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_142158_687188_36E27205 X-CRM114-Status: GOOD ( 13.52 ) 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 Nothing like being 10 year late to a party! Now that userspace can set counter offsets, we can save/restore the physical timer as well! Nobody really cared so far, but you're welcome anyway. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/guest.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 07444fa22888..46e910819de6 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -590,11 +590,16 @@ static unsigned long num_core_regs(const struct kvm_vcpu *vcpu) return copy_core_reg_indices(vcpu, NULL); } -/** - * ARM64 versions of the TIMER registers, always available on arm64 - */ +static const u64 timer_reg_list[] = { + KVM_REG_ARM_TIMER_CTL, + KVM_REG_ARM_TIMER_CNT, + KVM_REG_ARM_TIMER_CVAL, + KVM_REG_ARM_PTIMER_CTL, + KVM_REG_ARM_PTIMER_CNT, + KVM_REG_ARM_PTIMER_CVAL, +}; -#define NUM_TIMER_REGS 3 +#define NUM_TIMER_REGS ARRAY_SIZE(timer_reg_list) static bool is_timer_reg(u64 index) { @@ -602,6 +607,9 @@ static bool is_timer_reg(u64 index) case KVM_REG_ARM_TIMER_CTL: case KVM_REG_ARM_TIMER_CNT: case KVM_REG_ARM_TIMER_CVAL: + case KVM_REG_ARM_PTIMER_CTL: + case KVM_REG_ARM_PTIMER_CNT: + case KVM_REG_ARM_PTIMER_CVAL: return true; } return false; @@ -609,14 +617,11 @@ static bool is_timer_reg(u64 index) static int copy_timer_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) { - if (put_user(KVM_REG_ARM_TIMER_CTL, uindices)) - return -EFAULT; - uindices++; - if (put_user(KVM_REG_ARM_TIMER_CNT, uindices)) - return -EFAULT; - uindices++; - if (put_user(KVM_REG_ARM_TIMER_CVAL, uindices)) - return -EFAULT; + for (int i = 0; i < NUM_TIMER_REGS; i++) { + if (put_user(timer_reg_list[i], uindices)) + return -EFAULT; + uindices++; + } return 0; } -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel