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

Re: [Xen-devel] [PATCH v3] xen: handle paged gfn in wrmsr_hypervisor_regs



>>> On 03.05.13 at 17:17, Olaf Hering <olaf@xxxxxxxxx> wrote:
> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -1569,7 +1569,7 @@ static int svm_msr_read_intercept(unsign
>  
>  static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
>  {
> -    int ret;
> +    int ret, result = X86EMUL_OKAY;
>      struct vcpu *v = current;
>      struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
>      int sync = 0;
> @@ -1682,14 +1682,24 @@ static int svm_msr_write_intercept(unsig
>          if ( wrmsr_viridian_regs(msr, msr_content) )
>              break;
>  
> -        wrmsr_hypervisor_regs(msr, msr_content);
> +        switch ( wrmsr_hypervisor_regs(msr, msr_content) )
> +        {
> +            case -EAGAIN:
> +                result = X86EMUL_RETRY;
> +                break;
> +            case 0:
> +            case 1:
> +                break;
> +            default:
> +             goto gpf;
> +        }
>          break;
>      }
>  
>      if ( sync )
>          svm_vmload(vmcb);
>  
> -    return X86EMUL_OKAY;
> +    return result;
>  
>   gpf:
>      hvm_inject_hw_exception(TRAP_gp_fault, 0);
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -2088,7 +2088,16 @@ static int vmx_msr_write_intercept(unsig
>              case HNDL_unhandled:
>                  if ( (vmx_write_guest_msr(msr, msr_content) != 0) &&
>                       !is_last_branch_msr(msr) )
> -                    wrmsr_hypervisor_regs(msr, msr_content);
> +                    switch ( wrmsr_hypervisor_regs(msr, msr_content) )
> +                    {
> +                        case -EAGAIN:
> +                            return X86EMUL_RETRY;
> +                        case 0:
> +                        case 1:
> +                            break;
> +                        default:
> +                            goto gp_fault;
> +                    }
>                  break;
>              case HNDL_exception_raised:
>                  return X86EMUL_EXCEPTION;

Apart from formatting things look okay up to here.

> --- a/xen/arch/x86/traps.c
> +++ b/xen/arch/x86/traps.c
> @@ -634,25 +634,33 @@ int wrmsr_hypervisor_regs(uint32_t idx, 
>          unsigned long gmfn = val >> 12;
>          unsigned int idx  = val & 0xfff;
>          struct page_info *page;
> +        p2m_type_t t;
>  
>          if ( idx > 0 )
>          {
>              gdprintk(XENLOG_WARNING,
>                       "Out of range index %u to MSR %08x\n",
>                       idx, 0x40000000);
> -            return 0;
> +            return -EINVAL;

But I'd stay away from converting to actual errors both here ...

>          }
>  
> -        page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
> +        page = get_page_from_gfn(d, gmfn, &t, P2M_ALLOC);
>  
>          if ( !page || !get_page_type(page, PGT_writable_page) )
>          {
>              if ( page )
>                  put_page(page);
> +
> +            if ( p2m_is_paging(t) )
> +            {
> +                p2m_mem_paging_populate(d, gmfn);
> +                return -EAGAIN;
> +            }
> +
>              gdprintk(XENLOG_WARNING,
>                       "Bad GMFN %lx (MFN %lx) to MSR %08x\n",
> -                     gmfn, page_to_mfn(page), base + idx);
> -            return 0;
> +                     gmfn, page ? page_to_mfn(page) : -1UL, base);
> +            return -EINVAL;

... and here. If at all these ought to go into a separate patch
(which we'd likely postpone until after 4.3).

Jan

>          }
>  
>          hypercall_page = __map_domain_page(page);
> @@ -2490,7 +2498,7 @@ static int emulate_privileged_op(struct 
>                  goto fail;
>              break;
>          default:
> -            if ( wrmsr_hypervisor_regs(regs->ecx, msr_content) )
> +            if ( wrmsr_hypervisor_regs(regs->ecx, msr_content) == 1 )
>                  break;
>  
>              rc = vmce_wrmsr(regs->ecx, msr_content);



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


 


Rackspace

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