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 X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B06EC4338F for ; Wed, 4 Aug 2021 10:19:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E473A60FC3 for ; Wed, 4 Aug 2021 10:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237265AbhHDKTW (ORCPT ); Wed, 4 Aug 2021 06:19:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52980 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235522AbhHDKTV (ORCPT ); Wed, 4 Aug 2021 06:19:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628072348; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JpNym3PhHBiG2R7OBr9EbOywreJxnv7DJQK3hgv/PcA=; b=Qy8nHwoPvzjqk0HrVIjnThJsp9Et/zd5Gua8uVq7EJFYe4ip6HAFG/tRUAYbvFfSQ4V2Tq Rs9qBWepMnP/qAd7mv+xGxt18GyXtfyVrKVIEiprwh6z8lU6Ar4f6VEgN44gvLLUHLdRdF nnxlYOgDQtslbnglZVdqvMBnrLIuYEQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-I80oAytYORKfLtIrS0QM8Q-1; Wed, 04 Aug 2021 06:19:07 -0400 X-MC-Unique: I80oAytYORKfLtIrS0QM8Q-1 Received: by mail-ed1-f69.google.com with SMTP id cm18-20020a0564020c92b02903bc7f21d540so1209711edb.13 for ; Wed, 04 Aug 2021 03:19:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JpNym3PhHBiG2R7OBr9EbOywreJxnv7DJQK3hgv/PcA=; b=H2RSLcZkG+j1YZpfZkfAoc6vhMQ1BFUu/tK4LVLSpXepGFBuepqf8ZwZUrMdaRvGGS 6fzoE6bJblpY6wt3xGCOs/TvZ+icfckfDV0zgaB4PzhDq1OZfS1K6Av3bk3LxpssCrtp 5PQ94Yco5fqbfpYUB/hNENmM/BFBXmcilZX8qegT6zsS9TosQl97O4DKEykO6knXgXXG o8k/7kjT5yo0ewc+ffVblhQGRZC5T/Qkp8htWdTZtgnPFEDYnopsu6rtWhp8dsJ8KjTm H1Oyptwl1R29oaa+nv49GXJ7Bl5zFW6hefhlM+iCLPX9ZXh8Qhr/3m/h+B4B5RLZrBdD VPjw== X-Gm-Message-State: AOAM531lbAvok/HKeBBXcMM9yNAW20w+3jaPaVVlK/cvRyTJ/M89S7Nk xG3saChzUapTnuUay4iL8hZ2VtUzcKjNfyTGgYlcZ/4M+NTnVOAjUcy/444akFaNN/4EGfpsBau AWE9mm5oUO89N X-Received: by 2002:a05:6402:22b0:: with SMTP id cx16mr31181348edb.185.1628072346269; Wed, 04 Aug 2021 03:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynmhEZkIMhWx+PRVqGR61bwf7cgXKe96j5baJK90yrMt+GBIqVMmzYMWmFgf1rT3lH7xIO0w== X-Received: by 2002:a05:6402:22b0:: with SMTP id cx16mr31181329edb.185.1628072346086; Wed, 04 Aug 2021 03:19:06 -0700 (PDT) Received: from gator.home (cst2-174-132.cust.vodafone.cz. [31.30.174.132]) by smtp.gmail.com with ESMTPSA id r27sm762827edb.66.2021.08.04.03.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 03:19:05 -0700 (PDT) Date: Wed, 4 Aug 2021 12:19:03 +0200 From: Andrew Jones To: Oliver Upton Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Paolo Bonzini , Sean Christopherson , Marc Zyngier , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Will Deacon , Catalin Marinas Subject: Re: [PATCH v6 12/21] KVM: arm64: Separate guest/host counter offset values Message-ID: <20210804101903.3grfwrv5mlm5sydd@gator.home> References: <20210804085819.846610-1-oupton@google.com> <20210804085819.846610-13-oupton@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210804085819.846610-13-oupton@google.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Aug 04, 2021 at 08:58:10AM +0000, Oliver Upton wrote: > In some instances, a VMM may want to update the guest's counter-timer > offset in a transparent manner, meaning that changes to the hardware > value do not affect the synthetic register presented to the guest or the > VMM through said guest's architectural state. Lay the groundwork to > separate guest offset register writes from the hardware values utilized > by KVM. > > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/arch_timer.c | 48 ++++++++++++++++++++++++++++++++---- > include/kvm/arm_arch_timer.h | 3 +++ > 2 files changed, 46 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > index c0101db75ad4..4c2b763a8849 100644 > --- a/arch/arm64/kvm/arch_timer.c > +++ b/arch/arm64/kvm/arch_timer.c > @@ -87,6 +87,18 @@ static u64 timer_get_offset(struct arch_timer_context *ctxt) > struct kvm_vcpu *vcpu = ctxt->vcpu; > > switch(arch_timer_ctx_index(ctxt)) { > + case TIMER_VTIMER: > + return ctxt->host_offset; > + default: > + return 0; > + } > +} > + > +static u64 timer_get_guest_offset(struct arch_timer_context *ctxt) > +{ > + struct kvm_vcpu *vcpu = ctxt->vcpu; > + > + switch (arch_timer_ctx_index(ctxt)) { > case TIMER_VTIMER: > return __vcpu_sys_reg(vcpu, CNTVOFF_EL2); > default: > @@ -132,13 +144,31 @@ static void timer_set_offset(struct arch_timer_context *ctxt, u64 offset) > > switch(arch_timer_ctx_index(ctxt)) { > case TIMER_VTIMER: > - __vcpu_sys_reg(vcpu, CNTVOFF_EL2) = offset; > + ctxt->host_offset = offset; > break; > default: > WARN(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); > } > } > > +static void timer_set_guest_offset(struct arch_timer_context *ctxt, u64 offset) > +{ > + struct kvm_vcpu *vcpu = ctxt->vcpu; > + > + switch (arch_timer_ctx_index(ctxt)) { > + case TIMER_VTIMER: { > + u64 host_offset = timer_get_offset(ctxt); > + > + host_offset += offset - __vcpu_sys_reg(vcpu, CNTVOFF_EL2); > + __vcpu_sys_reg(vcpu, CNTVOFF_EL2) = offset; > + timer_set_offset(ctxt, host_offset); > + break; > + } > + default: > + WARN_ONCE(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); > + } > +} > + > u64 kvm_phys_timer_read(void) > { > return timecounter->cc->read(timecounter->cc); > @@ -749,7 +779,8 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) > > /* Make offset updates for all timer contexts atomic */ > static void update_timer_offset(struct kvm_vcpu *vcpu, > - enum kvm_arch_timers timer, u64 offset) > + enum kvm_arch_timers timer, u64 offset, > + bool guest_visible) > { > int i; > struct kvm *kvm = vcpu->kvm; > @@ -758,13 +789,20 @@ static void update_timer_offset(struct kvm_vcpu *vcpu, > lockdep_assert_held(&kvm->lock); > > kvm_for_each_vcpu(i, tmp, kvm) > - timer_set_offset(vcpu_get_timer(tmp, timer), offset); > + if (guest_visible) > + timer_set_guest_offset(vcpu_get_timer(tmp, timer), > + offset); > + else > + timer_set_offset(vcpu_get_timer(tmp, timer), offset); > > /* > * When called from the vcpu create path, the CPU being created is not > * included in the loop above, so we just set it here as well. > */ > - timer_set_offset(vcpu_get_timer(vcpu, timer), offset); > + if (guest_visible) > + timer_set_guest_offset(vcpu_get_timer(vcpu, timer), offset); > + else > + timer_set_offset(vcpu_get_timer(vcpu, timer), offset); > } > > static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) > @@ -772,7 +810,7 @@ static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) > struct kvm *kvm = vcpu->kvm; > > mutex_lock(&kvm->lock); > - update_timer_offset(vcpu, TIMER_VTIMER, cntvoff); > + update_timer_offset(vcpu, TIMER_VTIMER, cntvoff, true); > mutex_unlock(&kvm->lock); > } > > diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h > index 51c19381108c..9d65d4a29f81 100644 > --- a/include/kvm/arm_arch_timer.h > +++ b/include/kvm/arm_arch_timer.h > @@ -42,6 +42,9 @@ struct arch_timer_context { > /* Duplicated state from arch_timer.c for convenience */ > u32 host_timer_irq; > u32 host_timer_irq_flags; > + > + /* offset relative to the host's physical counter-timer */ > + u64 host_offset; > }; > > struct timer_map { > -- > 2.32.0.605.g8dce9f2422-goog > Reviewed-by: Andrew Jones 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 X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65037C432BE for ; Wed, 4 Aug 2021 10:19:13 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id CB2E460FC4 for ; Wed, 4 Aug 2021 10:19:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CB2E460FC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 4026740667; Wed, 4 Aug 2021 06:19:12 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7dxBUGa6Ynpa; Wed, 4 Aug 2021 06:19:11 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 17E5A49FB7; Wed, 4 Aug 2021 06:19:11 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id CE70640FC7 for ; Wed, 4 Aug 2021 06:19:09 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mcQTwHcVx1Yo for ; Wed, 4 Aug 2021 06:19:08 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BCE5D40667 for ; Wed, 4 Aug 2021 06:19:08 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628072348; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JpNym3PhHBiG2R7OBr9EbOywreJxnv7DJQK3hgv/PcA=; b=Qy8nHwoPvzjqk0HrVIjnThJsp9Et/zd5Gua8uVq7EJFYe4ip6HAFG/tRUAYbvFfSQ4V2Tq Rs9qBWepMnP/qAd7mv+xGxt18GyXtfyVrKVIEiprwh6z8lU6Ar4f6VEgN44gvLLUHLdRdF nnxlYOgDQtslbnglZVdqvMBnrLIuYEQ= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-375-ZgZ7sCYzNjOFKSbyYNnB6w-1; Wed, 04 Aug 2021 06:19:07 -0400 X-MC-Unique: ZgZ7sCYzNjOFKSbyYNnB6w-1 Received: by mail-ej1-f72.google.com with SMTP id k22-20020a1709061596b02905a370b2f477so657887ejd.17 for ; Wed, 04 Aug 2021 03:19:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JpNym3PhHBiG2R7OBr9EbOywreJxnv7DJQK3hgv/PcA=; b=Mu1jntzw/YdvQZTWTJVGLKM8ktwPAvAzxdhSW6dnDvq0U8ax4NNzMXYMLKNl0Pfhv2 MZsPyFlODqF7xUXyqleajSp35SHowB2/x/ShHIROvZG6/m7zIPRk9ZrXCcfYzCYaKtRC MRat1jdSIfQMGmaslEcl9WBEMT6lmkDipMCUfE6DSy9b2fgYFi0zNfPrAvfg974W/2jg CGRyWm9C0DtTpiO+wEXVqFEK+ZC7WXWlyLiYg9Eq0onDZgIRLG1uNrt2MHxEWRJZvC9k R6e3z/yNUrl5j1Ur92ec7uojOfMX2TPRyPKkk6tCKQ+hycHa0kGdoYaY8Xq4ku+SSq7w Lw3g== X-Gm-Message-State: AOAM530mjGgEerZvIkOiKCEnStDnq4zNcgEQIBsvQncRTcYhoI2mOMP2 O81wwYWVYM96Fw85MTlJpbnze70TJyP6fQUPKPaNnaaQLFgUNrnAjU3tbDn6VpGRdsFsxGK6DVG Dx2eEpYW1wIdFEAaJTZL746iS X-Received: by 2002:a05:6402:22b0:: with SMTP id cx16mr31181364edb.185.1628072346379; Wed, 04 Aug 2021 03:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynmhEZkIMhWx+PRVqGR61bwf7cgXKe96j5baJK90yrMt+GBIqVMmzYMWmFgf1rT3lH7xIO0w== X-Received: by 2002:a05:6402:22b0:: with SMTP id cx16mr31181329edb.185.1628072346086; Wed, 04 Aug 2021 03:19:06 -0700 (PDT) Received: from gator.home (cst2-174-132.cust.vodafone.cz. [31.30.174.132]) by smtp.gmail.com with ESMTPSA id r27sm762827edb.66.2021.08.04.03.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 03:19:05 -0700 (PDT) Date: Wed, 4 Aug 2021 12:19:03 +0200 From: Andrew Jones To: Oliver Upton Subject: Re: [PATCH v6 12/21] KVM: arm64: Separate guest/host counter offset values Message-ID: <20210804101903.3grfwrv5mlm5sydd@gator.home> References: <20210804085819.846610-1-oupton@google.com> <20210804085819.846610-13-oupton@google.com> MIME-Version: 1.0 In-Reply-To: <20210804085819.846610-13-oupton@google.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Cc: Catalin Marinas , kvm@vger.kernel.org, Will Deacon , Marc Zyngier , Raghavendra Rao Anata , Peter Shier , Sean Christopherson , David Matlack , Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Jim Mattson X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Wed, Aug 04, 2021 at 08:58:10AM +0000, Oliver Upton wrote: > In some instances, a VMM may want to update the guest's counter-timer > offset in a transparent manner, meaning that changes to the hardware > value do not affect the synthetic register presented to the guest or the > VMM through said guest's architectural state. Lay the groundwork to > separate guest offset register writes from the hardware values utilized > by KVM. > > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/arch_timer.c | 48 ++++++++++++++++++++++++++++++++---- > include/kvm/arm_arch_timer.h | 3 +++ > 2 files changed, 46 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > index c0101db75ad4..4c2b763a8849 100644 > --- a/arch/arm64/kvm/arch_timer.c > +++ b/arch/arm64/kvm/arch_timer.c > @@ -87,6 +87,18 @@ static u64 timer_get_offset(struct arch_timer_context *ctxt) > struct kvm_vcpu *vcpu = ctxt->vcpu; > > switch(arch_timer_ctx_index(ctxt)) { > + case TIMER_VTIMER: > + return ctxt->host_offset; > + default: > + return 0; > + } > +} > + > +static u64 timer_get_guest_offset(struct arch_timer_context *ctxt) > +{ > + struct kvm_vcpu *vcpu = ctxt->vcpu; > + > + switch (arch_timer_ctx_index(ctxt)) { > case TIMER_VTIMER: > return __vcpu_sys_reg(vcpu, CNTVOFF_EL2); > default: > @@ -132,13 +144,31 @@ static void timer_set_offset(struct arch_timer_context *ctxt, u64 offset) > > switch(arch_timer_ctx_index(ctxt)) { > case TIMER_VTIMER: > - __vcpu_sys_reg(vcpu, CNTVOFF_EL2) = offset; > + ctxt->host_offset = offset; > break; > default: > WARN(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); > } > } > > +static void timer_set_guest_offset(struct arch_timer_context *ctxt, u64 offset) > +{ > + struct kvm_vcpu *vcpu = ctxt->vcpu; > + > + switch (arch_timer_ctx_index(ctxt)) { > + case TIMER_VTIMER: { > + u64 host_offset = timer_get_offset(ctxt); > + > + host_offset += offset - __vcpu_sys_reg(vcpu, CNTVOFF_EL2); > + __vcpu_sys_reg(vcpu, CNTVOFF_EL2) = offset; > + timer_set_offset(ctxt, host_offset); > + break; > + } > + default: > + WARN_ONCE(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); > + } > +} > + > u64 kvm_phys_timer_read(void) > { > return timecounter->cc->read(timecounter->cc); > @@ -749,7 +779,8 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) > > /* Make offset updates for all timer contexts atomic */ > static void update_timer_offset(struct kvm_vcpu *vcpu, > - enum kvm_arch_timers timer, u64 offset) > + enum kvm_arch_timers timer, u64 offset, > + bool guest_visible) > { > int i; > struct kvm *kvm = vcpu->kvm; > @@ -758,13 +789,20 @@ static void update_timer_offset(struct kvm_vcpu *vcpu, > lockdep_assert_held(&kvm->lock); > > kvm_for_each_vcpu(i, tmp, kvm) > - timer_set_offset(vcpu_get_timer(tmp, timer), offset); > + if (guest_visible) > + timer_set_guest_offset(vcpu_get_timer(tmp, timer), > + offset); > + else > + timer_set_offset(vcpu_get_timer(tmp, timer), offset); > > /* > * When called from the vcpu create path, the CPU being created is not > * included in the loop above, so we just set it here as well. > */ > - timer_set_offset(vcpu_get_timer(vcpu, timer), offset); > + if (guest_visible) > + timer_set_guest_offset(vcpu_get_timer(vcpu, timer), offset); > + else > + timer_set_offset(vcpu_get_timer(vcpu, timer), offset); > } > > static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) > @@ -772,7 +810,7 @@ static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) > struct kvm *kvm = vcpu->kvm; > > mutex_lock(&kvm->lock); > - update_timer_offset(vcpu, TIMER_VTIMER, cntvoff); > + update_timer_offset(vcpu, TIMER_VTIMER, cntvoff, true); > mutex_unlock(&kvm->lock); > } > > diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h > index 51c19381108c..9d65d4a29f81 100644 > --- a/include/kvm/arm_arch_timer.h > +++ b/include/kvm/arm_arch_timer.h > @@ -42,6 +42,9 @@ struct arch_timer_context { > /* Duplicated state from arch_timer.c for convenience */ > u32 host_timer_irq; > u32 host_timer_irq_flags; > + > + /* offset relative to the host's physical counter-timer */ > + u64 host_offset; > }; > > struct timer_map { > -- > 2.32.0.605.g8dce9f2422-goog > Reviewed-by: Andrew Jones _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91A4BC4338F for ; Wed, 4 Aug 2021 10:21:27 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6075B60EB2 for ; Wed, 4 Aug 2021 10:21:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6075B60EB2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1zbbbbR6Lrw2PkLhpGZ4B2q8wUL60Ibfe9lKvpM0FOM=; b=fxyEf/sEnH3rFG CzmN39B/cY8T2Tt/NwuJtGNEorp2nqTEJ9/I5L3hsfCKDSKEdbDG0kZ/A9U+MUUHmbcfrpWBZa5oE 4eEVx+hpN79vF09c/jv0RcvGE/7TV7vvN2O9qjHGMqCUrDTw23HYkgwXsuvMrBjUpnBDtjfRLwlUH AMyk0zwPyLOuJM2VxA1sYDjSLIy3Raw/cZk3m1FcE5d5dYiznttKex0nd4lMMQuxSi9JlFn5nWC1j bGWQuQ0jpDZ513DSCUolAp4mUsK13Ck4rLlWsEM5K9KozW3K4DmfIY0D73cXt/nsPzQMkn41Osdak wsOctkR13ZFslTNJ5TzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBDza-005gw8-GY; Wed, 04 Aug 2021 10:19:19 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBDzR-005guW-Kq for linux-arm-kernel@lists.infradead.org; Wed, 04 Aug 2021 10:19:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628072348; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JpNym3PhHBiG2R7OBr9EbOywreJxnv7DJQK3hgv/PcA=; b=Qy8nHwoPvzjqk0HrVIjnThJsp9Et/zd5Gua8uVq7EJFYe4ip6HAFG/tRUAYbvFfSQ4V2Tq Rs9qBWepMnP/qAd7mv+xGxt18GyXtfyVrKVIEiprwh6z8lU6Ar4f6VEgN44gvLLUHLdRdF nnxlYOgDQtslbnglZVdqvMBnrLIuYEQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-xjqe_kiPPOepaefF2UNzNQ-1; Wed, 04 Aug 2021 06:19:07 -0400 X-MC-Unique: xjqe_kiPPOepaefF2UNzNQ-1 Received: by mail-ed1-f69.google.com with SMTP id y19-20020a0564021713b02903bbfec89ebcso1199875edu.16 for ; Wed, 04 Aug 2021 03:19:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JpNym3PhHBiG2R7OBr9EbOywreJxnv7DJQK3hgv/PcA=; b=eyLPluEzKmu0AOtjj3RUcyiKIP7L7gvW66/9QB7dXADpcmcmFLOCmnOYnrtDgAUGJF uRS3gxOAKJDu241z+uzkeGvXGtFjRk8iXcn9na7joI50T2TzGDKW9P4Tqbe2EfQJT4gc ouKD+5PksT3KCzlEtXT/lyD/LzsJjGL3LJPao+swE9goMIbMwtBhlNiyeXqSBBGYzQq+ 7nywkGUOhJUfbm0hPj6tSJa2gNZpVl9zzbcf4ykZjAwTF/QOnPWI3XEfYc4gaKHlHUGr YXheE2IzrBjo40bXEhKXOYDpvQEwXIfCpQQ4VyXP5NKA1u22eUczjD4ZtGV/8mevE3zE W5pQ== X-Gm-Message-State: AOAM530MV6a0M9XQ2F6ImHPnhOD5Gh76x7eKR/UbR4sEoFGkRzR2+oOE 4SwdoKWH6Af+Y2oHmMsgt0qYmjrZDj76Srjxp1+cD1B4EArmKr29BQ68Ke+5oqRL3W75Y1PXVwC h2uT5y2YaCRdAglIcCP41IQdu7wBbSgLZQ7U= X-Received: by 2002:a05:6402:22b0:: with SMTP id cx16mr31181345edb.185.1628072346269; Wed, 04 Aug 2021 03:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynmhEZkIMhWx+PRVqGR61bwf7cgXKe96j5baJK90yrMt+GBIqVMmzYMWmFgf1rT3lH7xIO0w== X-Received: by 2002:a05:6402:22b0:: with SMTP id cx16mr31181329edb.185.1628072346086; Wed, 04 Aug 2021 03:19:06 -0700 (PDT) Received: from gator.home (cst2-174-132.cust.vodafone.cz. [31.30.174.132]) by smtp.gmail.com with ESMTPSA id r27sm762827edb.66.2021.08.04.03.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 03:19:05 -0700 (PDT) Date: Wed, 4 Aug 2021 12:19:03 +0200 From: Andrew Jones To: Oliver Upton Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Paolo Bonzini , Sean Christopherson , Marc Zyngier , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Will Deacon , Catalin Marinas Subject: Re: [PATCH v6 12/21] KVM: arm64: Separate guest/host counter offset values Message-ID: <20210804101903.3grfwrv5mlm5sydd@gator.home> References: <20210804085819.846610-1-oupton@google.com> <20210804085819.846610-13-oupton@google.com> MIME-Version: 1.0 In-Reply-To: <20210804085819.846610-13-oupton@google.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210804_031909_869393_F21195DD X-CRM114-Status: GOOD ( 26.12 ) 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 On Wed, Aug 04, 2021 at 08:58:10AM +0000, Oliver Upton wrote: > In some instances, a VMM may want to update the guest's counter-timer > offset in a transparent manner, meaning that changes to the hardware > value do not affect the synthetic register presented to the guest or the > VMM through said guest's architectural state. Lay the groundwork to > separate guest offset register writes from the hardware values utilized > by KVM. > > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/arch_timer.c | 48 ++++++++++++++++++++++++++++++++---- > include/kvm/arm_arch_timer.h | 3 +++ > 2 files changed, 46 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > index c0101db75ad4..4c2b763a8849 100644 > --- a/arch/arm64/kvm/arch_timer.c > +++ b/arch/arm64/kvm/arch_timer.c > @@ -87,6 +87,18 @@ static u64 timer_get_offset(struct arch_timer_context *ctxt) > struct kvm_vcpu *vcpu = ctxt->vcpu; > > switch(arch_timer_ctx_index(ctxt)) { > + case TIMER_VTIMER: > + return ctxt->host_offset; > + default: > + return 0; > + } > +} > + > +static u64 timer_get_guest_offset(struct arch_timer_context *ctxt) > +{ > + struct kvm_vcpu *vcpu = ctxt->vcpu; > + > + switch (arch_timer_ctx_index(ctxt)) { > case TIMER_VTIMER: > return __vcpu_sys_reg(vcpu, CNTVOFF_EL2); > default: > @@ -132,13 +144,31 @@ static void timer_set_offset(struct arch_timer_context *ctxt, u64 offset) > > switch(arch_timer_ctx_index(ctxt)) { > case TIMER_VTIMER: > - __vcpu_sys_reg(vcpu, CNTVOFF_EL2) = offset; > + ctxt->host_offset = offset; > break; > default: > WARN(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); > } > } > > +static void timer_set_guest_offset(struct arch_timer_context *ctxt, u64 offset) > +{ > + struct kvm_vcpu *vcpu = ctxt->vcpu; > + > + switch (arch_timer_ctx_index(ctxt)) { > + case TIMER_VTIMER: { > + u64 host_offset = timer_get_offset(ctxt); > + > + host_offset += offset - __vcpu_sys_reg(vcpu, CNTVOFF_EL2); > + __vcpu_sys_reg(vcpu, CNTVOFF_EL2) = offset; > + timer_set_offset(ctxt, host_offset); > + break; > + } > + default: > + WARN_ONCE(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); > + } > +} > + > u64 kvm_phys_timer_read(void) > { > return timecounter->cc->read(timecounter->cc); > @@ -749,7 +779,8 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) > > /* Make offset updates for all timer contexts atomic */ > static void update_timer_offset(struct kvm_vcpu *vcpu, > - enum kvm_arch_timers timer, u64 offset) > + enum kvm_arch_timers timer, u64 offset, > + bool guest_visible) > { > int i; > struct kvm *kvm = vcpu->kvm; > @@ -758,13 +789,20 @@ static void update_timer_offset(struct kvm_vcpu *vcpu, > lockdep_assert_held(&kvm->lock); > > kvm_for_each_vcpu(i, tmp, kvm) > - timer_set_offset(vcpu_get_timer(tmp, timer), offset); > + if (guest_visible) > + timer_set_guest_offset(vcpu_get_timer(tmp, timer), > + offset); > + else > + timer_set_offset(vcpu_get_timer(tmp, timer), offset); > > /* > * When called from the vcpu create path, the CPU being created is not > * included in the loop above, so we just set it here as well. > */ > - timer_set_offset(vcpu_get_timer(vcpu, timer), offset); > + if (guest_visible) > + timer_set_guest_offset(vcpu_get_timer(vcpu, timer), offset); > + else > + timer_set_offset(vcpu_get_timer(vcpu, timer), offset); > } > > static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) > @@ -772,7 +810,7 @@ static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) > struct kvm *kvm = vcpu->kvm; > > mutex_lock(&kvm->lock); > - update_timer_offset(vcpu, TIMER_VTIMER, cntvoff); > + update_timer_offset(vcpu, TIMER_VTIMER, cntvoff, true); > mutex_unlock(&kvm->lock); > } > > diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h > index 51c19381108c..9d65d4a29f81 100644 > --- a/include/kvm/arm_arch_timer.h > +++ b/include/kvm/arm_arch_timer.h > @@ -42,6 +42,9 @@ struct arch_timer_context { > /* Duplicated state from arch_timer.c for convenience */ > u32 host_timer_irq; > u32 host_timer_irq_flags; > + > + /* offset relative to the host's physical counter-timer */ > + u64 host_offset; > }; > > struct timer_map { > -- > 2.32.0.605.g8dce9f2422-goog > Reviewed-by: Andrew Jones _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel