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

Re: [Xen-devel] [PATCH v2] x86/hap: use the right cache attributes when MTRR is disabled



>>> On 02.08.16 at 15:55, <roger.pau@xxxxxxxxxx> wrote:
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -2283,7 +2283,11 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer)
>          if ( !nestedhvm_vmswitch_in_progress(v) && 
> nestedhvm_vcpu_in_guestmode(v) )
>              paging_update_nestedmode(v);
>          else
> +        {
>              paging_update_paging_modes(v);
> +            /* Force an update of the memory cache attributes. */
> +            memory_type_changed(d);
> +        }

Why only in the "else" case, rather than after the if/else block?

> --- a/xen/arch/x86/hvm/mtrr.c
> +++ b/xen/arch/x86/hvm/mtrr.c
> @@ -814,10 +814,19 @@ int epte_get_entry_emt(struct domain *d, unsigned long 
> gfn, mfn_t mfn,
>      if ( gmtrr_mtype == -EADDRNOTAVAIL )
>          return -1;
>  
> -    gmtrr_mtype = is_hvm_domain(d) && v ?
> -                  get_mtrr_type(&v->arch.hvm_vcpu.mtrr,
> -                                gfn << PAGE_SHIFT, order) :
> -                  MTRR_TYPE_WRBACK;
> +    if ( !v )
> +        gmtrr_mtype = MTRR_TYPE_WRBACK;
> +    else if ( v->arch.hvm_vcpu.mtrr.enabled & 0x2 )
> +        /* MTRR is enabled, use MTRR. */
> +        gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, gfn << 
> PAGE_SHIFT,
> +                                    order);
> +    else if ( !hvm_paging_enabled(v) )
> +        /* MTRR is not enabled and paging is disabled, force UC. */
> +        gmtrr_mtype = MTRR_TYPE_UNCACHABLE;
> +    else
> +        /* MTRR is not enabled and paging is enabled, use PAT. */
> +        gmtrr_mtype = MTRR_TYPE_WRBACK;

I'm afraid this needs to be UC, or else you provide non-architectural
behavior to the guest (see the SDM's description of the enable flag
being clear). Which means the original code was correct. I'm sorry
for not having checked the SDM upon looking at v1 already.

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®.