From nobody Sat May 4 08:09:10 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1579619315; cv=none; d=zohomail.com; s=zohoarc; b=agCK5mz4w4UfaGSF78a9otK7UpFdSBJ0HQkXcZwXj7rChth+M5Oj5EwbzudHyBHQLKt2gyPz1A+aMdxu9ihEFozwSDXN2pGzHtbvpK2rzANeL7wCs7IPQMcpa0BQCacncVRWfhPA/iQvFfHTa2jWACbA/nUrByUzARuVumW8ymg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579619315; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WrxH9zDry+dD5srv4pXZPrZrfMSim82tcInEzyoF/1M=; b=ef9WhtcFTbbJWT+0jMLPVaQBk+x9oCpHE0hGiliTTEI5qynZU1RTuKFSXPp9ElzqjhP6Ay6uhIit/GfyBSGch2LRbwrIvX2CoermJrD3NGLlFtTMic792CFADdRcxwDfdl/A0UUCPBbMpMwRi9SohIsc3uGapC+gUZJmmYkFZ0o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1579619315331324.9766331923055; Tue, 21 Jan 2020 07:08:35 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1itv7n-0006G2-1C; Tue, 21 Jan 2020 15:07:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1itv7l-0006Fs-EW for xen-devel@lists.xenproject.org; Tue, 21 Jan 2020 15:07:25 +0000 Received: from webmail.dornerworks.com (unknown [12.207.209.150]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id b81082fb-3c5f-11ea-bacb-12813bfff9fa; Tue, 21 Jan 2020 15:07:21 +0000 (UTC) X-Inumbo-ID: b81082fb-3c5f-11ea-bacb-12813bfff9fa From: Jeff Kubascik To: Date: Tue, 21 Jan 2020 10:07:03 -0500 Message-ID: <20200121150704.126001-2-jeff.kubascik@dornerworks.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200121150704.126001-1-jeff.kubascik@dornerworks.com> References: <20200121150704.126001-1-jeff.kubascik@dornerworks.com> MIME-Version: 1.0 X-Originating-IP: [172.27.13.179] X-ClientProxiedBy: Mcbain.dw.local (172.27.1.45) To Mcbain.dw.local (172.27.1.45) X-spam-status: No, score=-2.9 required=3.5 tests=ALL_TRUSTED, BAYES_00, MAILSHELL_SCORE_0_4 X-Spam-Flag: NO Subject: [Xen-devel] [PATCH v4 1/2] xen/arm: remove physical timer offset X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stewart Hildebrand , Volodymyr Babchuk , Stefano Stabellini , Julien Grall Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The physical timer traps apply an offset so that time starts at 0 for the guest. However, this offset is not currently applied to the physical counter. Per the ARMv8 Reference Manual (ARM DDI 0487E.a), section D11.2.4 Timers, the "Offset" between the counter and timer should be zero for a physical timer. This removes the offset to make the timer and counter consistent. This also cleans up the physical timer implementation to better match the virtual timer - both cval's now hold the hardware value. Signed-off-by: Jeff Kubascik --- xen/arch/arm/vtimer.c | 34 ++++++++++++++++++---------------- xen/include/asm-arm/domain.h | 3 --- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index 240a850b6e..0c78a65863 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -62,7 +62,6 @@ static void virt_timer_expired(void *data) =20 int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *con= fig) { - d->arch.phys_timer_base.offset =3D NOW(); d->arch.virt_timer_base.offset =3D READ_SYSREG64(CNTPCT_EL0); d->time_offset.seconds =3D ticks_to_ns(d->arch.virt_timer_base.offset = - boot_count); do_div(d->time_offset.seconds, 1000000000); @@ -108,7 +107,6 @@ int vcpu_vtimer_init(struct vcpu *v) =20 init_timer(&t->timer, phys_timer_expired, t, v->processor); t->ctl =3D 0; - t->cval =3D NOW(); t->irq =3D d0 ? timer_get_irq(TIMER_PHYS_NONSECURE_PPI) : GUEST_TIMER_PHYS_NS_PPI; @@ -167,6 +165,7 @@ void virt_timer_restore(struct vcpu *v) static bool vtimer_cntp_ctl(struct cpu_user_regs *regs, uint32_t *r, bool = read) { struct vcpu *v =3D current; + s_time_t expires; =20 if ( !ACCESS_ALLOWED(regs, EL0PTEN) ) return false; @@ -184,8 +183,9 @@ static bool vtimer_cntp_ctl(struct cpu_user_regs *regs,= uint32_t *r, bool read) =20 if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE ) { - set_timer(&v->arch.phys_timer.timer, - v->arch.phys_timer.cval + v->domain->arch.phys_timer= _base.offset); + expires =3D v->arch.phys_timer.cval > boot_count + ? ticks_to_ns(v->arch.phys_timer.cval - boot_count) = : 0; + set_timer(&v->arch.phys_timer.timer, expires); } else stop_timer(&v->arch.phys_timer.timer); @@ -197,26 +197,27 @@ static bool vtimer_cntp_tval(struct cpu_user_regs *re= gs, uint32_t *r, bool read) { struct vcpu *v =3D current; - s_time_t now; + uint64_t cntpct; + s_time_t expires; =20 if ( !ACCESS_ALLOWED(regs, EL0PTEN) ) return false; =20 - now =3D NOW() - v->domain->arch.phys_timer_base.offset; + cntpct =3D get_cycles(); =20 if ( read ) { - *r =3D (uint32_t)(ns_to_ticks(v->arch.phys_timer.cval - now) & 0xf= fffffffull); + *r =3D (uint32_t)((v->arch.phys_timer.cval - cntpct) & 0xffffffffu= ll); } else { - v->arch.phys_timer.cval =3D now + ticks_to_ns(*r); + v->arch.phys_timer.cval =3D cntpct + *r; if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE ) { v->arch.phys_timer.ctl &=3D ~CNTx_CTL_PENDING; - set_timer(&v->arch.phys_timer.timer, - v->arch.phys_timer.cval + - v->domain->arch.phys_timer_base.offset); + expires =3D v->arch.phys_timer.cval > boot_count + ? ticks_to_ns(v->arch.phys_timer.cval - boot_count) = : 0; + set_timer(&v->arch.phys_timer.timer, expires); } } return true; @@ -226,23 +227,24 @@ static bool vtimer_cntp_cval(struct cpu_user_regs *re= gs, uint64_t *r, bool read) { struct vcpu *v =3D current; + s_time_t expires; =20 if ( !ACCESS_ALLOWED(regs, EL0PTEN) ) return false; =20 if ( read ) { - *r =3D ns_to_ticks(v->arch.phys_timer.cval); + *r =3D v->arch.phys_timer.cval; } else { - v->arch.phys_timer.cval =3D ticks_to_ns(*r); + v->arch.phys_timer.cval =3D *r; if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE ) { v->arch.phys_timer.ctl &=3D ~CNTx_CTL_PENDING; - set_timer(&v->arch.phys_timer.timer, - v->arch.phys_timer.cval + - v->domain->arch.phys_timer_base.offset); + expires =3D v->arch.phys_timer.cval > boot_count + ? ticks_to_ns(v->arch.phys_timer.cval - boot_count) = : 0; + set_timer(&v->arch.phys_timer.timer, expires); } } return true; diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index f3f3fb7d7f..adc7fe7210 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -65,9 +65,6 @@ struct arch_domain RELMEM_done, } relmem; =20 - struct { - uint64_t offset; - } phys_timer_base; struct { uint64_t offset; } virt_timer_base; --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 08:09:10 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1579619315; cv=none; d=zohomail.com; s=zohoarc; b=mUHjlSrfSxQdQRYFFFK/QsV0x78O5d3npxWWitGj8MW9hb/H7Ro/Ej+vHjSaCMOegqPmVrickuoSwNWA8ZEaDZT8J5uJioOqYDV06LfjXF/81d0ZqUNrtdH8xzeZh2+lpN5x88IrDPnmv+NWeDUFd4SOC7naEKkHegyjA3k9r+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579619315; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=srvCS0mXMa+8ywVpnd7/qeUyw0bRkkGNn38a3896Xy4=; b=l9a5yUKNCBoaHIcDT6TO/+cneMQAykPfsa2WLSnyD+EYLcGHjxBdOkD0KwC136kYkTwKDofPa+4uJtIxnkqjLmrba5wKxJKhKjcYMx7vfG/Zkb991Cxt5Niz2npuiyCnGFccvDlQAb26VKBDwjOYFjFIgfDTYUgp/jjHuR3vDXw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1579619315333203.31208198368188; Tue, 21 Jan 2020 07:08:35 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1itv7r-0006HR-Ah; Tue, 21 Jan 2020 15:07:31 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1itv7q-0006H5-1Y for xen-devel@lists.xenproject.org; Tue, 21 Jan 2020 15:07:30 +0000 Received: from webmail.dornerworks.com (unknown [12.207.209.150]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id bb7face0-3c5f-11ea-bacb-12813bfff9fa; Tue, 21 Jan 2020 15:07:26 +0000 (UTC) X-Inumbo-ID: bb7face0-3c5f-11ea-bacb-12813bfff9fa From: Jeff Kubascik To: Date: Tue, 21 Jan 2020 10:07:04 -0500 Message-ID: <20200121150704.126001-3-jeff.kubascik@dornerworks.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200121150704.126001-1-jeff.kubascik@dornerworks.com> References: <20200121150704.126001-1-jeff.kubascik@dornerworks.com> MIME-Version: 1.0 X-Originating-IP: [172.27.13.179] X-ClientProxiedBy: Mcbain.dw.local (172.27.1.45) To Mcbain.dw.local (172.27.1.45) X-spam-status: No, score=-2.9 required=3.5 tests=ALL_TRUSTED, BAYES_00, MAILSHELL_SCORE_0_4 X-Spam-Flag: NO Subject: [Xen-devel] [PATCH v4 2/2] xen/arm: Sign extend TimerValue when computing the CompareValue X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stewart Hildebrand , Volodymyr Babchuk , Stefano Stabellini , Julien Grall Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Xen will only store the CompareValue as it can be derived from the TimerValue (ARM DDI 0487E.a section D11.2.4): CompareValue =3D (Counter[63:0] + SignExtend(TimerValue))[63:0] While the TimerValue is a 32-bit signed value, our implementation assumed it is a 32-bit unsigned value. Signed-off-by: Jeff Kubascik Acked-by: Julien Grall --- xen/arch/arm/vtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index 0c78a65863..fed89498a9 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -211,7 +211,7 @@ static bool vtimer_cntp_tval(struct cpu_user_regs *regs= , uint32_t *r, } else { - v->arch.phys_timer.cval =3D cntpct + *r; + v->arch.phys_timer.cval =3D cntpct + (uint64_t)(int32_t)*r; if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE ) { v->arch.phys_timer.ctl &=3D ~CNTx_CTL_PENDING; --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel