From: "Jan Beulich" Subject: Re: [PATCH RFC V3 5/5] xen: Handle resumed instruction based on previous mem_event reply Date: Thu, 24 Jul 2014 16:42:14 +0100 Message-ID: <53D145760200007800025A79@mail.emea.novell.com> References: <1406118884-16628-1-git-send-email-rcojocaru@bitdefender.com> <1406118884-16628-5-git-send-email-rcojocaru@bitdefender.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1406118884-16628-5-git-send-email-rcojocaru@bitdefender.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Razvan Cojocaru Cc: kevin.tian@intel.com, Ian.Campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, eddie.dong@intel.com, xen-devel@lists.xen.org, andres@lagarcavilla.org, jun.nakajima@intel.com, Ian.Jackson@eu.citrix.com List-Id: xen-devel@lists.xenproject.org >>> On 23.07.14 at 14:34, wrote: > @@ -1434,6 +1444,37 @@ bool_t p2m_mem_access_check(paddr_t gpa, bool_t gla_valid, unsigned long gla, > return 1; > } > } > + else > + { > + /* There's a mem_event listener */ > + if ( hvm_funcs.exited_by_pagefault && !hvm_funcs.exited_by_pagefault() ) /* don't send a mem_event */ > + { > + if ( v->arch.mem_event.emulate_flags == 0 ) The five lines above (leaving aside the comment) should all become a simple "else if()". > + { > + v->arch.mem_event.emulate_flags = MEM_EVENT_FLAG_EMULATE; > + v->arch.mem_event.gpa = gpa; > + v->arch.mem_event.eip = eip; > + } > + } > + } > + > + if ( v->arch.mem_event.gpa != gpa || v->arch.mem_event.eip != eip ) > + { > + v->arch.mem_event.emulate_flags = 0; > + v->arch.mem_event.gpa = gpa; > + v->arch.mem_event.eip = eip; > + } So the default value for gpa and eip is zero - how do you deal with guests having code/data at virtual/physical address zero? It would seem to me that you need a "valid" qualification for these fields, but since the purpose of this last block isn't really clear to me maybe I'm simply missing something and a comment might help. > + > + if ( v->arch.mem_event.emulate_flags ) > + { > + if ( v->arch.mem_event.emulate_flags & MEM_EVENT_FLAG_EMULATE_NOWRITE ) > + hvm_emulate_one_full(1, TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE); > + else > + hvm_emulate_one_full(0, TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE); I'd prefer such to be coded as a single call with the first argument being suitable calculated (you wouldn't even need a conditional operator here). > @@ -1475,11 +1516,74 @@ void p2m_mem_access_resume(struct domain *d) > /* Pull all responses off the ring */ > while( mem_event_get_response(d, &d->mem_event->access, &rsp) ) > { > + struct vcpu *v; > + > if ( rsp.flags & MEM_EVENT_FLAG_DUMMY ) > continue; > + > + /* Validate the vcpu_id in the response. */ > + if ( (rsp.vcpu_id >= d->max_vcpus) || !d->vcpu[rsp.vcpu_id] ) > + continue; > + > + v = d->vcpu[rsp.vcpu_id]; > + > + /* Mark vcpu for skipping one instruction upon rescheduling */ > + if ( rsp.flags & MEM_EVENT_FLAG_EMULATE ) > + { > + xenmem_access_t access; > + int violation = 1; bool_t? > + > + v->arch.mem_event.emulate_flags = 0; > + > + if ( p2m_get_mem_access(d, rsp.gfn, &access) == 0 ) > + { > + violation = 0; > + > + switch (access) Coding style. Jan