From: "Jan Beulich" Subject: Re: [PATCH v4 12/17] x86/hvm: split I/O completion handling from state model Date: Thu, 25 Jun 2015 10:40:38 +0100 Message-ID: <558BE8B602000078000896D4@mail.emea.novell.com> References: <1435145089-21999-1-git-send-email-paul.durrant@citrix.com> <1435145089-21999-13-git-send-email-paul.durrant@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z83eE-0006HB-5i for xen-devel@lists.xenproject.org; Thu, 25 Jun 2015 09:40:42 +0000 In-Reply-To: <1435145089-21999-13-git-send-email-paul.durrant@citrix.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: Paul Durrant Cc: Andrew Cooper , Keir Fraser , xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> On 24.06.15 at 13:24, wrote: > @@ -428,26 +429,12 @@ static void hvm_io_assist(ioreq_t *p) > vio->io_state = HVMIO_completed; > vio->io_data = p->data; > break; > - case HVMIO_handle_mmio_awaiting_completion: > - vio->io_state = HVMIO_completed; > - vio->io_data = p->data; > - (void)handle_mmio(); > - break; > - case HVMIO_handle_pio_awaiting_completion: > - if ( vio->io_size == 4 ) /* Needs zero extension. */ > - guest_cpu_user_regs()->rax = (uint32_t)p->data; > - else > - memcpy(&guest_cpu_user_regs()->rax, &p->data, vio->io_size); > - break; > default: > break; > } > > - if ( p->state == STATE_IOREQ_NONE ) > - { > - msix_write_completion(curr); > - vcpu_end_shutdown_deferral(curr); > - } > + msix_write_completion(curr); > + vcpu_end_shutdown_deferral(curr); > } Doesn't this mean that these can now potentially be called more than once for a single instruction (due to retries)? That's presumably not a problem for vcpu_end_shutdown_deferral(), but I'm uncertain about msix_write_completion(). > @@ -508,8 +496,36 @@ void hvm_do_resume(struct vcpu *v) > } > } > > - if ( vio->mmio_retry ) > + io_completion = vio->io_completion; > + vio->io_completion = HVMIO_no_completion; > + > + switch ( io_completion ) > + { > + case HVMIO_no_completion: > + break; > + case HVMIO_mmio_completion: > (void)handle_mmio(); > + break; > + case HVMIO_pio_completion: > + if ( vio->io_size == 4 ) /* Needs zero extension. */ > + guest_cpu_user_regs()->rax = (uint32_t)vio->io_data; > + else > + memcpy(&guest_cpu_user_regs()->rax, &vio->io_data, vio->io_size); > + vio->io_state = HVMIO_none; > + break; > + case HVMIO_realmode_completion: > + { > + struct hvm_emulate_ctxt ctxt; > + > + hvm_emulate_prepare(&ctxt, guest_cpu_user_regs()); > + vmx_realmode_emulate_one(&ctxt); > + hvm_emulate_writeback(&ctxt); > + > + break; > + } > + default: > + BUG(); I'd prefer such to be ASSERT_UNREACHABLE(), as I don't see getting here to be a reason to crash the hypervisor (and the guest would likely crash in such a case anyway). Or maybe fold in the first case and make this ASSERT(io_completion == HVMIO_no_completion). > @@ -46,9 +51,10 @@ struct hvm_vcpu_asid { > > struct hvm_vcpu_io { > /* I/O request in flight to device model. */ > - enum hvm_io_state io_state; > - unsigned long io_data; > - int io_size; > + enum hvm_io_state io_state; > + unsigned long io_data; > + int io_size; Unless this can validly be negative, please make this unsigned int if you already touch it. Jan