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

Re: [Xen-devel] [PATCH v6 06/11] x86/vmce: emulate MSR_IA32_MCG_EXT_CTL



>>> On 05.07.17 at 05:12, <haozhong.zhang@xxxxxxxxx> wrote:
> @@ -878,6 +879,8 @@ long arch_do_domctl(
>          }
>          else
>          {
> +            static const unsigned long vmce_off = offsetof(typeof(*evc), 
> vmce);

I'm unconvinced the static is useful (and not potentially harmful)
here. I'm also not convinced this really needs to be unsigned long
(unsigned int is generally more efficient to deal with).

> @@ -917,9 +920,21 @@ long arch_do_domctl(
>                           offsetof(struct xen_domctl_ext_vcpucontext,
>                                    vmce.caps));
>              BUILD_BUG_ON(sizeof(evc->mcg_cap) != sizeof(evc->vmce.caps));
> -            if ( evc->size >= offsetof(typeof(*evc), vmce) +
> -                              sizeof(evc->vmce) )
> +            if ( evc->size >= vmce_off + sizeof(evc->vmce) )
>                  ret = vmce_restore_vcpu(v, &evc->vmce);
> +            else if ( evc->size >= vmce_off +
> +                                   offsetof(typeof(evc->vmce), mcg_ext_ctl) )
> +            {
> +                /*
> +                 * If migrating from old Xen that uses a smaller 'struct
> +                 * hvm_vmce_vcpu', only restore the components in the
> +                 * old version.
> +                 */
> +                struct hvm_vmce_vcpu vmce = { 0 };

Just { } would suffice.

> +                memcpy(&vmce, &evc->vmce, evc->size - vmce_off);
> +                ret = vmce_restore_vcpu(v, &vmce);
> +            }
>              else if ( evc->size >= offsetof(typeof(*evc), mcg_cap) +
>                                     sizeof(evc->mcg_cap) )
>              {

So you really have two choices here: Either mirror/clone what's
already there, or (preferable imo) carefully generalize the existing
code. But please don't use yet another slightly different model.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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