[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH v3] xen/arm: avoid overflow when setting vtimer in context switch


  • To: Jiamei Xie <Jiamei.Xie@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jiamei Xie <Jiamei.Xie@xxxxxxx>
  • Date: Thu, 30 Jun 2022 05:20:39 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G6T5dsvrZbLHrASVIXJrjfLKzJvl5HgT2BnlwJphvCo=; b=FsJNLUEeRiIj9CJHsIcFp62ISCpqp/jcr2H7leU2OGUIA9lyelPl4vIC3D1NMiUZHfYpek67N8GsXgmaB16cltrp9wc+eQScaxtkSW246XLO1UrLCu3Hr5ZBv0Vb5JUToe+2JlamxadAkr+2HpHqUInDoEtV6B9OxWGgg1Qey5hKWhMB/1WiuJbqBohwd0DmImTmafvtnXWh3OBq6WAZDf3vtKBmKYpJgtsNv98Fy2iGpzEi1EsoeUd3XnCA3ngjhjE/Jhej54uKF4cu1Vvx3rrFi6/uTnVDGeMMwlfEiklocxMlLj4MyExotSXUnkmbrXkiL/wOMT8r3MPtgGDCWw==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G6T5dsvrZbLHrASVIXJrjfLKzJvl5HgT2BnlwJphvCo=; b=IOa2XjHTvvNNDxmqVe+8nbpQa17VXIaR4yPiG5L19AHXESDy7/o/fM4EPp0HXeeEqVAv1FblAF/Fp2bDCtcz367OY75QyJHpj8U1fod8raqc/+8BY7OMk9HevaY08WX+rWWFPLXVu5YmR9mk5swd+73qFeuJeGhWIXaYSjhfUuD9ZhuK5+P4WviXt3YM0P7Rbs8MZeRTQUG8vYszYLwvlVO5n3XjMoOJTNzwpRvI74SflN9B6gbF+N0WM8Vtyozb3cYRxbt9IzI5wOAn8ZlUYbPWCk5p+r0bnH6VJaxWJJiWvDG7O5ukvOZdLllPIw1Gimc94XAHRfnyP+Y170AXFQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=UWU+9HcYydiu1Uv9aH8f+MArB4mGxBoXyuvM/+j/L/+g14ES8WdHZrh/0KAkqw1c3io3Z7OkSpfFeU5dy5aLeUfvJDqfaqmr6UM101AoF1RtJtjYfT6h+XZAAXg0wzwyxC433OFY8sizznNvmzorPaiWoa6uj4IyJo+R1BeMk5HaBVKftOJ1YA6sjs3Td9QRXSA8wl4+3xq5EyYkR6kmEqGRV4KF86Lc1hy9m5incVbZpT8FnD+2JOsjwanh/SNscm+E5iGva/tgMVk8N+WdL6m2SwIVH+RSMEkH0RBgPx1AehOqjG36CjLSDVMl4UyaaNQxUYTQjH641uBlQc6jxQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TnSWtrePLHlFiiIcdEP+dpm9iH9rjHG6TEXzzf1RHj95D5oQwgc2CCBwJlwH5fDjTFcrNYK2I6oGiibJRAWOxogOLDn9saE6tiBftUFeOVSWH0cRy7KFjpYZdAPNGMR+dwQEUC+JXlXUnmFGkccnFQkUwZ/JGfqc8k08XsEdA9K8Qc7O9G0ZF2fh9cQU4XNOad1dxuAdSAX8jYZICXEnFAB7g6cMmN9dk+bcMJQ4cHJNyVN89IyV83Wr+ZiTazQZ8hTXyXyBGd5VeVprB20xPLLgLdXOi91JQK8Jk+H3gIgG+ZlmMlhaZaJX57IPoxwMH85HakQTvqn29C2aZpt10A==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>
  • Delivery-date: Thu, 30 Jun 2022 05:21:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYjCSE7P53YpeE00S5Qtvr6kIMUK1naUjw
  • Thread-topic: [PATCH v3] xen/arm: avoid overflow when setting vtimer in context switch

Hi,

> -----Original Message-----
> From: Jiamei Xie <jiamei.xie@xxxxxxx>
> Sent: 2022年6月30日 9:54
> To: xen-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Jiamei Xie <Jiamei.Xie@xxxxxxx>; Stefano Stabellini
> <sstabellini@xxxxxxxxxx>; Julien Grall <julien@xxxxxxx>; Bertrand Marquis
> <Bertrand.Marquis@xxxxxxx>; Volodymyr Babchuk
> <Volodymyr_Babchuk@xxxxxxxx>; Wei Chen <Wei.Chen@xxxxxxx>
> Subject: [PATCH v3] xen/arm: avoid overflow when setting vtimer in context
> switch
> 
> virt_vtimer_save is calculating the new time for the vtimer in:
> "v->arch.virt_timer.cval + v->domain->arch.virt_timer_base.offset
> - boot_count".
> In this formula, "cval + offset" might cause uint64_t overflow.
> Changing it to "ticks_to_ns(v->domain->arch.virt_timer_base.offset -
> boot_count) + ticks_to_ns(v->arch.virt_timer.cval)" can avoid overflow,
> and "ticks_to_ns(arch.virt_timer_base.offset - boot_count)" will be
> always the same, which has been caculated in domain_vtimer_init.
> Introduce a new field virt_timer_base.nanoseconds to store this value
> for arm in struct arch_domain, so we can use it directly.
> 
> Signed-off-by: Jiamei Xie <jiamei.xie@xxxxxxx>
> Change-Id: Ib80cee51eaf844661e6f92154a0339ad2a652f9b

I am sorry I forget to remove the Change-Id.

> ---
> was "xen/arm: avoid vtimer flip-flop transition in context switch".
> v3 changes:
> -re-write commit message
> -store nanoseconds in virt_timer_base instead of adding a new structure
> -assign to nanoseconds first, then seconds
> ---
>  xen/arch/arm/include/asm/domain.h | 1 +
>  xen/arch/arm/vtimer.c             | 9 ++++++---
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/arch/arm/include/asm/domain.h
> b/xen/arch/arm/include/asm/domain.h
> index ed63c2b6f9..cd9ce19b4b 100644
> --- a/xen/arch/arm/include/asm/domain.h
> +++ b/xen/arch/arm/include/asm/domain.h
> @@ -71,6 +71,7 @@ struct arch_domain
> 
>      struct {
>          uint64_t offset;
> +        s_time_t nanoseconds;
>      } virt_timer_base;
> 
>      struct vgic_dist vgic;
> diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c
> index 6b78fea77d..aeaea78e4c 100644
> --- a/xen/arch/arm/vtimer.c
> +++ b/xen/arch/arm/vtimer.c
> @@ -63,7 +63,9 @@ static void virt_timer_expired(void *data)
>  int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig
> *config)
>  {
>      d->arch.virt_timer_base.offset = get_cycles();
> -    d->time_offset.seconds = ticks_to_ns(d->arch.virt_timer_base.offset -
> boot_count);
> +    d->arch.virt_timer_base.nanoseconds =
> +        ticks_to_ns(d->arch.virt_timer_base.offset - boot_count);
> +    d->time_offset.seconds = d->arch.virt_timer_base.nanoseconds;
>      do_div(d->time_offset.seconds, 1000000000);
> 
>      config->clock_frequency = timer_dt_clock_frequency;
> @@ -144,8 +146,9 @@ void virt_timer_save(struct vcpu *v)
>      if ( (v->arch.virt_timer.ctl & CNTx_CTL_ENABLE) &&
>           !(v->arch.virt_timer.ctl & CNTx_CTL_MASK))
>      {
> -        set_timer(&v->arch.virt_timer.timer, 
> ticks_to_ns(v->arch.virt_timer.cval
> +
> -                  v->domain->arch.virt_timer_base.offset - boot_count));
> +        set_timer(&v->arch.virt_timer.timer,
> +                  v->domain->arch.virt_timer_base.nanoseconds +
> +                  ticks_to_ns(v->arch.virt_timer.cval));
>      }
>  }
> 
> --
> 2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.