xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Wei Huang <w1.huang@samsung.com>, xen-devel@lists.xen.org
Cc: keir@xen.org, ian.campbell@citrix.com,
	stefano.stabellini@eu.citrix.com, ian.jackson@eu.citrix.com,
	julien.grall@linaro.org, tim@xen.org, jaeyong.yoo@samsung.com,
	jbeulich@suse.com, yjhyun.yoo@samsung.com
Subject: Re: [RFC v3 3/6] xen/arm: Add save/restore support for ARM arch timer
Date: Fri, 09 May 2014 00:02:52 +0100	[thread overview]
Message-ID: <536C0D1C.6060406@citrix.com> (raw)
In-Reply-To: <1399583908-21755-4-git-send-email-w1.huang@samsung.com>

On 08/05/2014 22:18, Wei Huang wrote:
> This patch implements a save/resore support for ARM architecture
> timer.
>
> Signed-off-by: Evgeny Fedotov <e.fedotov@samsung.com>
> Signed-off-by: Wei Huang <w1.huang@samsung.com>
> ---
>  xen/arch/arm/vtimer.c                  |   90 ++++++++++++++++++++++++++++++++
>  xen/include/public/arch-arm/hvm/save.h |   16 +++++-
>  2 files changed, 105 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c
> index b93153e..6576408 100644
> --- a/xen/arch/arm/vtimer.c
> +++ b/xen/arch/arm/vtimer.c
> @@ -21,6 +21,7 @@
>  #include <xen/lib.h>
>  #include <xen/timer.h>
>  #include <xen/sched.h>
> +#include <xen/hvm/save.h>
>  #include <asm/irq.h>
>  #include <asm/time.h>
>  #include <asm/gic.h>
> @@ -285,6 +286,95 @@ int vtimer_emulate(struct cpu_user_regs *regs, union hsr hsr)
>      }
>  }
>  
> +/* Save timer info to support save/restore */
> +static int hvm_timer_save(struct domain *d, hvm_domain_context_t *h)
> +{
> +    struct hvm_arm_timer ctxt;
> +    struct vcpu *v;
> +    struct vtimer *t;
> +    int i;

unsigned int

> +    int rc = 0;
> +
> +    /* Save the state of vtimer and ptimer */
> +    for_each_vcpu( d, v )
> +    {
> +        t = &v->arch.virt_timer;
> +
> +        for ( i = 0; i < ARM_TIMER_TYPE_COUNT; i++ )
> +        {
> +            ctxt.cval = t->cval;
> +            ctxt.ctl = t->ctl;
> +
> +            switch ( i )
> +            {
> +            case ARM_TIMER_TYPE_PHYS:
> +                ctxt.vtb_offset = d->arch.phys_timer_base.offset;
> +                ctxt.type = ARM_TIMER_TYPE_PHYS;
> +                break;
> +            case ARM_TIMER_TYPE_VIRT:
> +                ctxt.vtb_offset = d->arch.virt_timer_base.offset;
> +                ctxt.type = ARM_TIMER_TYPE_VIRT;
> +            default:
> +                rc = -EINVAL;
> +                break;

This break is out of the switch, not out of the for loop, so you will
still try to save the bogus entry.

As you control i and want to save all timers, I suggest a BUG() instead;

> +            }
> +
> +            if ( (rc = hvm_save_entry(TIMER, v->vcpu_id, h, &ctxt)) != 0 )
> +                return rc;
> +
> +            t = &v->arch.phys_timer;

This updating of t looks suspect and fragile.

This is a good approximation of the "for case" programming paradigm
(http://thedailywtf.com/Comments/The_FOR-CASE_paradigm.aspx).

There are only two timers and they refer to different named items inside
struct domain.  It would be clearer to remove the loop.

> +        }
> +    }
> +
> +    return rc;
> +}
> +
> +/* Restore timer info from context to support save/restore */
> +static int hvm_timer_load(struct domain *d, hvm_domain_context_t *h)
> +{
> +    int vcpuid;

unsigned

> +    struct hvm_arm_timer ctxt;
> +    struct vcpu *v;
> +    struct vtimer *t = NULL;

With this initialised here...

> +    int rc = 0;
> +
> +    /* Which vcpu is this? */
> +    vcpuid = hvm_load_instance(h);
> +
> +    if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> +    {
> +        dprintk(XENLOG_ERR, "HVM restore: dom%u has no vcpu%u\n",
> +                d->domain_id, vcpuid);
> +        return -EINVAL;
> +    }
> +
> +    if ( hvm_load_entry(TIMER, h, &ctxt) != 0 )
> +        return -EINVAL;
> +
> +    switch ( ctxt.type )
> +    {
> +    case ARM_TIMER_TYPE_PHYS:
> +        t = &v->arch.phys_timer;
> +        d->arch.phys_timer_base.offset = ctxt.vtb_offset;
> +        break;
> +    case ARM_TIMER_TYPE_VIRT:
> +        t = &v->arch.virt_timer;
> +        d->arch.virt_timer_base.offset = ctxt.vtb_offset;
> +        break;
> +    default:
> +        rc = -EINVAL;
> +        break;

... and this error handling,

> +    }
> +
> +    t->cval = ctxt.cval;
> +    t->ctl = ctxt.ctl;
> +    t->v = v;

this is going to end in tears.  return -EINVAL from the default.

> +
> +    return rc;
> +}
> +
> +HVM_REGISTER_SAVE_RESTORE(TIMER, hvm_timer_save, hvm_timer_load, 2,
> +                          HVMSR_PER_VCPU);
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/xen/include/public/arch-arm/hvm/save.h b/xen/include/public/arch-arm/hvm/save.h
> index 421a6f6..8679bfd 100644
> --- a/xen/include/public/arch-arm/hvm/save.h
> +++ b/xen/include/public/arch-arm/hvm/save.h
> @@ -72,10 +72,24 @@ struct hvm_arm_gich_v2
>  };
>  DECLARE_HVM_SAVE_TYPE(GICH_V2, 3, struct hvm_arm_gich_v2);
>  
> +/* Two ARM timers (physical and virtual) are saved */
> +#define ARM_TIMER_TYPE_VIRT  0
> +#define ARM_TIMER_TYPE_PHYS  1
> +#define ARM_TIMER_TYPE_COUNT 2       /* total count */
> +
> +struct hvm_arm_timer
> +{
> +    uint64_t vtb_offset;
> +    uint32_t ctl;
> +    uint64_t cval;
> +    uint32_t type;
> +};

This is also going to have 32/64 alignment issues.

~Andrew

> +DECLARE_HVM_SAVE_TYPE(TIMER, 4, struct hvm_arm_timer);
> +
>  /*
>   * Largest type-code in use
>   */
> -#define HVM_SAVE_CODE_MAX 3
> +#define HVM_SAVE_CODE_MAX 4
>  
>  #endif
>  

  reply	other threads:[~2014-05-08 23:02 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-08 21:18 [RFC v3 0/6] xen/arm: ARM save/restore/migration support Wei Huang
2014-05-08 21:18 ` [RFC v3 1/6] xen/arm: Add basic save/restore support for ARM Wei Huang
2014-05-08 22:11   ` Andrew Cooper
2014-05-08 22:20     ` Wei Huang
2014-05-09  8:56       ` Julien Grall
2014-05-14 10:27         ` Ian Campbell
2014-05-14 10:25     ` Ian Campbell
2014-05-14 10:46       ` Andrew Cooper
2014-05-14 13:22         ` Ian Campbell
2014-05-09  9:06   ` Julien Grall
2014-05-09  9:42   ` Jan Beulich
2014-05-14 10:37   ` Ian Campbell
2014-05-14 18:54     ` Wei Huang
2014-05-08 21:18 ` [RFC v3 2/6] xen/arm: Add save/restore support for ARM GIC V2 Wei Huang
2014-05-08 22:47   ` Andrew Cooper
2014-05-09 14:12     ` Wei Huang
2014-05-09 14:24       ` Ian Campbell
2014-05-11 16:15         ` Julien Grall
2014-05-13 14:53     ` Wei Huang
2014-05-09  9:17   ` Julien Grall
2014-05-14 11:07   ` Ian Campbell
2014-05-14 12:05     ` Julien Grall
2014-05-14 12:23       ` Tim Deegan
2014-05-14 13:24         ` Ian Campbell
2014-05-15 17:15   ` Julien Grall
2014-05-16  7:36     ` Ian Campbell
2014-05-08 21:18 ` [RFC v3 3/6] xen/arm: Add save/restore support for ARM arch timer Wei Huang
2014-05-08 23:02   ` Andrew Cooper [this message]
2014-05-11  9:01     ` Julien Grall
2014-05-11  8:58   ` Julien Grall
2014-05-12  8:35     ` Ian Campbell
2014-05-12 11:42       ` Julien Grall
2014-05-14 11:14   ` Ian Campbell
2014-05-14 12:13     ` Julien Grall
2014-05-14 13:23       ` Ian Campbell
2014-05-14 19:04     ` Wei Huang
2014-05-08 21:18 ` [RFC v3 4/6] xen/arm: Add save/restore support for guest core registers Wei Huang
2014-05-08 23:10   ` Andrew Cooper
2014-05-09 16:35     ` Wei Huang
2014-05-09 16:52       ` Ian Campbell
2014-05-11  9:06   ` Julien Grall
2014-05-14 11:16     ` Ian Campbell
2014-05-14 12:23       ` Julien Grall
2014-05-14 13:25         ` Ian Campbell
2014-05-14 13:31           ` Julien Grall
2014-05-14 11:37   ` Ian Campbell
2014-05-08 21:18 ` [RFC v3 5/6] xen/arm: Add log_dirty support for ARM Wei Huang
2014-05-08 23:46   ` Andrew Cooper
2014-05-14 11:51     ` Ian Campbell
2014-05-11 15:28   ` Julien Grall
2014-05-12 14:00     ` Wei Huang
2014-05-12 14:11       ` Julien Grall
2014-05-14 12:04         ` Ian Campbell
2014-05-14 11:57     ` Ian Campbell
2014-05-14 12:20       ` Julien Grall
2014-05-14 13:24         ` Ian Campbell
2014-05-14 13:18   ` Ian Campbell
2014-05-16 10:59   ` Julien Grall
2014-05-08 21:18 ` [RFC v3 6/6] xen/arm: Implement toolstack for xl restore/save/migration Wei Huang
2014-05-14 13:20   ` Ian Campbell
2014-05-14 13:24     ` Andrew Cooper
2014-05-11  9:23 ` [RFC v3 0/6] xen/arm: ARM save/restore/migration support Julien Grall
2014-05-12 14:37   ` Wei Huang
2014-05-13 14:41     ` Julien Grall
2014-05-12 14:17 ` Julien Grall
2014-05-12 14:52   ` Wei Huang
2014-05-12 15:01     ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=536C0D1C.6060406@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jaeyong.yoo@samsung.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@linaro.org \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@xen.org \
    --cc=w1.huang@samsung.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yjhyun.yoo@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).