xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@novell.com>
To: Eddie Dong <eddie.dong@intel.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: A simple clean up of __get_instruction_length & __update_guest_eip
Date: Wed, 15 Sep 2010 16:25:32 +0100	[thread overview]
Message-ID: <4C91018C02000078000165DD@vpn.id2.novell.com> (raw)
In-Reply-To: <1A42CE6F5F474C41B63392A5F80372B22A8C23BA@shsmsx501.ccr.corp.intel.com>

>>> On 15.09.10 at 16:34, "Dong, Eddie" <eddie.dong@intel.com> wrote:
> Replace so many sparsed __get_instruction_length & __update_guest_eip with 
> one function call.
> 
> Signed-off-by: Eddie Dong <eddie.dong@intel.com>
> 
> diff -r 221cf46cbf2c xen/arch/x86/hvm/vmx/vmx.c
> --- a/xen/arch/x86/hvm/vmx/vmx.c	Wed Sep 15 17:31:53 2010 +0800
> +++ b/xen/arch/x86/hvm/vmx/vmx.c	Wed Sep 15 17:46:24 2010 +0800
> @@ -1494,6 +1494,14 @@
>          vmx_inject_hw_exception(TRAP_debug, HVM_DELIVER_NO_ERROR_CODE);
>  }
>  
> +static void update_guest_eip(void)
> +{
> +    unsigned long inst_len;
> +
> +    inst_len = __get_instruction_length();
> +    __update_guest_eip(inst_len);
> +}
> +
>  static void vmx_fpu_dirty_intercept(void)
>  {
>      struct vcpu *curr = current;
> @@ -2244,8 +2252,7 @@
>      if ( (((exit_qualification >> 12) & 0xf) == 1) &&
>           ((exit_qualification & 0xfff) == APIC_EOI) )
>      {
> -        int inst_len = __get_instruction_length(); /* Safe: APIC data write 
> */
> -        __update_guest_eip(inst_len);
> +        update_guest_eip();

Is it really a good idea to remove all these "Safe: ..." comments?
Without them, I think it'll be much easier to not remember that
this cannot be done everywhere and hence to add an inappropriate
call to this function.

Jan

>          vlapic_EOI_set(vcpu_vlapic(current));
>          return 1;
>      }
> @@ -2424,8 +2431,7 @@
>          case TRAP_int3:
>              if ( !v->domain->debugger_attached )
>                  goto exit_and_crash;
> -            inst_len = __get_instruction_length(); /* Safe: INT3 */
> -            __update_guest_eip(inst_len);
> +            update_guest_eip();
>              current->arch.gdbsx_vcpu_event = TRAP_int3;
>              domain_pause_for_debugger();
>              break;
> @@ -2516,18 +2522,15 @@
>          break;
>      }
>      case EXIT_REASON_CPUID:
> -        inst_len = __get_instruction_length(); /* Safe: CPUID */
> -        __update_guest_eip(inst_len);
> +        update_guest_eip();
>          vmx_do_cpuid(regs);
>          break;
>      case EXIT_REASON_HLT:
> -        inst_len = __get_instruction_length(); /* Safe: HLT */
> -        __update_guest_eip(inst_len);
> +        update_guest_eip();
>          hvm_hlt(regs->eflags);
>          break;
>      case EXIT_REASON_INVLPG:
> -        inst_len = __get_instruction_length(); /* Safe: INVLPG */
> -        __update_guest_eip(inst_len);
> +        update_guest_eip();
>          exit_qualification = __vmread(EXIT_QUALIFICATION);
>          vmx_invlpg_intercept(exit_qualification);
>          break;
> @@ -2535,19 +2538,17 @@
>          regs->ecx = hvm_msr_tsc_aux(v);
>          /* fall through */
>      case EXIT_REASON_RDTSC:
> -        inst_len = __get_instruction_length();
> -        __update_guest_eip(inst_len);
> +        update_guest_eip();
>          hvm_rdtsc_intercept(regs);
>          break;
>      case EXIT_REASON_VMCALL:
>      {
>          int rc;
>          HVMTRACE_1D(VMMCALL, regs->eax);
> -        inst_len = __get_instruction_length(); /* Safe: VMCALL */
>          rc = hvm_do_hypercall(regs);
>          if ( rc != HVM_HCALL_preempted )
>          {
> -            __update_guest_eip(inst_len);
> +            update_guest_eip();
>              if ( rc == HVM_HCALL_invalidate )
>                  send_invalidate_req();
>          }
> @@ -2556,9 +2557,8 @@
>      case EXIT_REASON_CR_ACCESS:
>      {
>          exit_qualification = __vmread(EXIT_QUALIFICATION);
> -        inst_len = __get_instruction_length(); /* Safe: MOV Cn, LMSW, CLTS 
> */
>          if ( vmx_cr_access(exit_qualification, regs) )
> -            __update_guest_eip(inst_len);
> +            update_guest_eip();
>          break;
>      }
>      case EXIT_REASON_DR_ACCESS:
> @@ -2568,22 +2568,20 @@
>      case EXIT_REASON_MSR_READ:
>      {
>          uint64_t msr_content;
> -        inst_len = __get_instruction_length(); /* Safe: RDMSR */
>          if ( hvm_msr_read_intercept(regs->ecx, &msr_content) == X86EMUL_OKAY )
>          {
>              regs->eax = (uint32_t)msr_content;
>              regs->edx = (uint32_t)(msr_content >> 32);
> -            __update_guest_eip(inst_len);
> +            update_guest_eip();
>          }
>          break;
>      }
>      case EXIT_REASON_MSR_WRITE:
>      {
>          uint64_t msr_content;
> -        inst_len = __get_instruction_length(); /* Safe: WRMSR */
>          msr_content = ((uint64_t)regs->edx << 32) | (uint32_t)regs->eax;
>          if ( hvm_msr_write_intercept(regs->ecx, msr_content) == X86EMUL_OKAY 
> )
> -            __update_guest_eip(inst_len);
> +            update_guest_eip();
>          break;
>      }
>  
> @@ -2652,8 +2650,7 @@
>      case EXIT_REASON_INVD:
>      case EXIT_REASON_WBINVD:
>      {
> -        inst_len = __get_instruction_length(); /* Safe: INVD, WBINVD */
> -        __update_guest_eip(inst_len);
> +        update_guest_eip();
>          vmx_wbinvd_intercept();
>          break;
>      }
> @@ -2686,8 +2683,7 @@
>          u64 new_bv  =  (((u64)regs->edx) << 32) | regs->eax;
>          if ( vmx_handle_xsetbv(new_bv) == 0 )
>          {
> -            inst_len = __get_instruction_length();
> -            __update_guest_eip(inst_len);
> +            update_guest_eip();
>          }
>          break;
>      }

  reply	other threads:[~2010-09-15 15:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-15 14:34 A simple clean up of __get_instruction_length & __update_guest_eip Dong, Eddie
2010-09-15 15:25 ` Jan Beulich [this message]
2010-09-15 15:38   ` Keir Fraser

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=4C91018C02000078000165DD@vpn.id2.novell.com \
    --to=jbeulich@novell.com \
    --cc=eddie.dong@intel.com \
    --cc=xen-devel@lists.xensource.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).