Support for running secondary emulators
v4 cover Support for running secondary emulators
This patch series adds the ioreq server interface which I mentioned in my talk at the Xen developer summit in Edinburgh at the end of last year. The code is based on work originally done by Julien Grall but has been re-written to allow existing versions of QEMU to work unmodified.
The code is available in my xen.git [1] repo on xenbits, under the 'savannah4' branch, and I have also written a demo emulator to test the code, which can be found in my demu.git [2] repo.
The series has been re-worked since v3. The modifications are now broken down as follows:
Patch #1 is a pre-series tidy-up. No semantic change.
Patch #2 moves some code around to centralize use of the ioreq_t data structure.
Patch #3 introduces the new hvm_ioreq_server structure.
Patch #4 defers creation of the ioreq server until something actually reads one of the HVM parameters concerned with emulation.
Patch #5 makes the single ioreq server of previous patches into the default ioreq server and introduces an API for creating secondary servers.
Patch #6 adds an enable/disable operation to the API for secondary servers which makes sure that they cannot be active whilst their shared pages are present in the guest's P2M.
Patch #7 adds makes handling bufferd ioreqs optional for secondary servers. This saves a page of memory.
Patch #8 pulls the PCI hotplug controller emulation into Xen. This is necessary to allow a secondary emulator to hotplug a PCI device into the VM. The code implements the controller in the same way as upstream QEMU and thus the variant of the DSDT ASL used for upstream QEMU is retained.
The demo emulator can simply be invoked from a shell and will hotplug its device onto the PCI bus (and remove it again when it's killed). The emulated device is not an awful lot of use at this stage - it appears as a SCSI controller with one IO BAR and one MEM BAR and has no intrinsic functionality... but then it is only supposed to be demo :-)
Paul
[1] http://xenbits.xen.org/gitweb/?p=people/pauldu/xen.git
[2] http://xenbits.xen.org/gitweb/?p=people/pauldu/demu.git
v2:
- First non-RFC posting
v3:
- Addressed comments from Jan Beulich
v4:
- Addressed comments from Ian Campbell and George Dunlap
- Series heavily re-worked, 2 patches added
PATCH v4 1/8 ioreq-server: pre-series tidy up
This patch tidies up various parts of the code that following patches move around. If these modifications were combined with the code motion it would be easy to miss them.
There's also some function renaming to reflect purpose and a single whitespace fix.
--- xen/arch/x86/hvm/hvm.c | 24 ++++++++++++------------ xen/arch/x86/hvm/io.c | 36 +++++++++++++++--------------------- xen/arch/x86/hvm/stdvga.c | 2 +- xen/include/asm-x86/hvm/io.h | 2 +- xen/include/asm-x86/hvm/support.h | 2 ++ 5 files changed, 31 insertions(+), 35 deletions(-)
xen/arch/x86/hvm/hvm.c +12 -12
@@ -354,7 +354,7 @@ void hvm_migrate_pirqs(struct vcpu *v)void hvm_do_resume (struct vcpu *v) { -ioreq_t *p; +ioreq_t *p =get_ioreq (v);check_wakeup_from_wait ();
@@ -362,7 +362,7 @@ void hvm_do_resume(struct vcpu *v)pt_restore_timer (v);/* NB. Optimised for common case (p->state == STATE_IOREQ_NONE). */ -if ( !(p =get_ioreq (v)) ) +if ( !p ) goto check_inject_trap;while ( p->state !=STATE_IOREQ_NONE )
@@ -415,7 +415,7 @@ void destroy_ring_for_helper( } } -static void hvm_destroy_ioreq_page ( +static void hvm_unmap_ioreq_page (struct domain *d,struct hvm_ioreq_page *iorp) {spin_lock (&iorp->lock);
@@ -471,7 +471,7 @@ int prepare_ring_for_helper(return 0 ; } -static int hvm_set_ioreq_page ( +static int hvm_map_ioreq_page (struct domain *d,struct hvm_ioreq_page *iorp,unsigned long gmfn) {struct page_info *page;
@@ -485,7 +485,7 @@ static int hvm_set_ioreq_page(if ( (iorp->va !=NULL ) || d->is_dying ) { -destroy_ring_for_helper (&iorp->va, iorp->page); +destroy_ring_for_helper (&va, page);spin_unlock (&iorp->lock);return -EINVAL ; }
@@ -641,8 +641,8 @@ void hvm_domain_relinquish_resources(struct domain *d)if ( hvm_funcs.nhvm_domain_relinquish_resources ) hvm_funcs.nhvm_domain_relinquish_resources (d); -hvm_destroy_ioreq_page (d, &d->arch.hvm_domain.ioreq); -hvm_destroy_ioreq_page (d, &d->arch.hvm_domain.buf_ioreq); +hvm_unmap_ioreq_page (d, &d->arch.hvm_domain.ioreq); +hvm_unmap_ioreq_page (d, &d->arch.hvm_domain.buf_ioreq);msixtbl_pt_cleanup (d);
@@ -1416,12 +1416,12 @@ void hvm_vcpu_down(struct vcpu *v)bool_t hvm_send_assist_req (struct vcpu *v) { -ioreq_t *p; +ioreq_t *p =get_ioreq (v);if (unlikely (!vcpu_start_shutdown_deferral (v)) )return 0 ;/* implicitly bins the i/o operation */ -if ( !(p =get_ioreq (v)) ) +if ( !p )return 0 ;if (unlikely (p->state !=STATE_IOREQ_NONE ) )
@@ -4118,7 +4118,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) {case HVM_PARAM_IOREQ_PFN : iorp = &d->arch.hvm_domain.ioreq; -if ( (rc =hvm_set_ioreq_page (d, iorp, a.value)) !=0 ) +if ( (rc =hvm_map_ioreq_page (d, iorp, a.value)) !=0 )break ;spin_lock (&iorp->lock);if ( iorp->va !=NULL )
@@ -4127,9 +4127,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)get_ioreq (v)->vp_eport = v->arch.hvm_vcpu.xen_port;spin_unlock (&iorp->lock);break ; -case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : iorp = &d->arch.hvm_domain.buf_ioreq; - rc =hvm_set_ioreq_page (d, iorp, a.value); + rc =hvm_map_ioreq_page (d, iorp, a.value);break ;case HVM_PARAM_CALLBACK_IRQ :hvm_set_callback_via (d, a.value);
xen/arch/x86/hvm/io.c +15 -21
@@ -46,10 +46,9 @@#include <xen/iocap.h> #include <public/hvm/ioreq.h> -int hvm_buffered_io_send (ioreq_t *p) +int hvm_buffered_io_send (struct domain *d,const ioreq_t *p) { -struct vcpu *v = current; -struct hvm_ioreq_page *iorp = &v->domain->arch.hvm_domain.buf_ioreq; +struct hvm_ioreq_page *iorp = &d->arch.hvm_domain.buf_ioreq;buffered_iopage_t *pg = iorp->va;buf_ioreq_t bp;/* Timeoffset sends 64b data, but no address. Use two consecutive slots. */
@@ -104,22 +103,20 @@ int hvm_buffered_io_send(ioreq_t *p)return 0 ; } -memcpy (&pg->buf_ioreq[pg->write_pointer %IOREQ_BUFFER_SLOT_NUM ], - &bp,sizeof (bp)); + pg->buf_ioreq[pg->write_pointer %IOREQ_BUFFER_SLOT_NUM ] = bp;if ( qw ) { bp.data = p->data >>32 ; -memcpy (&pg->buf_ioreq[(pg->write_pointer+1 ) %IOREQ_BUFFER_SLOT_NUM ], - &bp,sizeof (bp)); + pg->buf_ioreq[(pg->write_pointer+1 ) %IOREQ_BUFFER_SLOT_NUM ] = bp; }/* Make the ioreq_t visible /before/ write_pointer. */ wmb (); pg->write_pointer += qw ?2 :1 ; -notify_via_xen_event_channel (v->domain, - v->domain->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ]); +notify_via_xen_event_channel (d, + d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ]);spin_unlock (&iorp->lock);return 1 ;
@@ -127,22 +124,19 @@ int hvm_buffered_io_send(ioreq_t *p)void send_timeoffset_req (unsigned long timeoff) { -ioreq_t p[1 ]; +ioreq_t p = { + .type =IOREQ_TYPE_TIMEOFFSET , + .size =8 , + .count =1 , + .dir =IOREQ_WRITE , + .data = timeoff, + .state =STATE_IOREQ_READY , + };if ( timeoff ==0 )return ; -memset (p,0 ,sizeof (*p)); - - p->type =IOREQ_TYPE_TIMEOFFSET ; - p->size =8 ; - p->count =1 ; - p->dir =IOREQ_WRITE ; - p->data = timeoff; - - p->state =STATE_IOREQ_READY ; - -if ( !hvm_buffered_io_send (p) ) +if ( !hvm_buffered_io_send (current->domain, &p) )printk ("Unsuccessful timeoffset update\n" ); }
xen/arch/x86/hvm/stdvga.c +1 -1
@@ -580,7 +580,7 @@ static int stdvga_intercept_mmio(ioreq_t *p) buf = (p->dir ==IOREQ_WRITE ); } - rc = (buf &&hvm_buffered_io_send (p)); + rc = (buf &&hvm_buffered_io_send (d, p));spin_unlock (&s->lock);
xen/include/asm-x86/hvm/io.h +1 -1
@@ -92,7 +92,7 @@ static inline int hvm_buffered_io_intercept(ioreq_t *p) }int hvm_mmio_intercept (ioreq_t *p); -int hvm_buffered_io_send (ioreq_t *p); +int hvm_buffered_io_send (struct domain *d,const ioreq_t *p); static inline void register_portio_handler( struct domain *d, unsigned long addr,
xen/include/asm-x86/hvm/support.h +2 -0
@@ -31,7 +31,9 @@ static inline ioreq_t *get_ioreq(struct vcpu *v) {struct domain *d = v->domain;shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; +ASSERT ((v == current) ||spin_is_locked (&d->arch.hvm_domain.ioreq.lock)); +return p ? &p->vcpu_ioreq[v->vcpu_id] :NULL ; }
Signature · 1 line
1.7.10.4
Re: [PATCH v4 1/8] ioreq-server: pre-series tidy up
xen/arch/x86/hvm/hvm.c static int hvm_set_ioreq_page( · line 488
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +1
-1@@ -485,7 +485,7 @@ static int hvm_set_ioreq_page(if ( (iorp->va !=NULL ) || d->is_dying ) { -destroy_ring_for_helper (&iorp->va, iorp->page); +destroy_ring_for_helper (&va, page);
This clearly isn't just tidying: The bug fix should at least be mentioned in the description, but for the purposes of backporting it should probably be submitted as a separate patch.
xen/arch/x86/hvm/io.c line 51
Quoted 12 lines
xen/arch/x86/hvm/io.c +2
-3@@ -46,10 +46,9 @@#include <xen/iocap.h> #include <public/hvm/ioreq.h> -int hvm_buffered_io_send (ioreq_t *p) +int hvm_buffered_io_send (struct domain *d,const ioreq_t *p) { -struct vcpu *v = current; -struct hvm_ioreq_page *iorp = &v->domain->arch.hvm_domain.buf_ioreq; +struct hvm_ioreq_page *iorp = &d->arch.hvm_domain.buf_ioreq;
This isn't a purely cosmetic change either, especially without an ASSERT(current->domain == d). It looks to be correct with one minor
exception: There's a gdprintk() in this function, which - if you don't expect the function to be called for the current domain only - needs to be altered to not falsely print the current vCPU as subject anymore.
Jan
Re: [PATCH v4 1/8] ioreq-server: pre-series tidy up
Quoted 10 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 07 April 2014 11:49
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH v4 1/8] ioreq-server: pre-series tidy upQuoted 3 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
(quoted diff) +0
-0@@ -485,7 +485,7 @@ static int hvm_set_ioreq_page(
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int hvm_set_ioreq_page( · line 488
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +1
-1if ( (iorp->va !=NULL ) || d->is_dying ) { -destroy_ring_for_helper (&iorp->va, iorp->page); +destroy_ring_for_helper (&va, page);This clearly isn't just tidying: The bug fix should at least be mentioned in the description, but for the purposes of backporting it should probably be submitted as a separate patch.
Ok. I'll separate it.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/hvm/io.c +0
-0@@ -46,10 +46,9 @@#include <xen/iocap.h> #include <public/hvm/ioreq.h>
Quoted 14 lines
xen/arch/x86/hvm/io.c line 51
Quoted 7 lines
xen/arch/x86/hvm/io.c +2
-3-int hvm_buffered_io_send (ioreq_t *p) +int hvm_buffered_io_send (struct domain *d,const ioreq_t *p) { -struct vcpu *v = current; -struct hvm_ioreq_page *iorp = &v->domain- arch.hvm_domain.buf_ioreq; +struct hvm_ioreq_page *iorp = &d->arch.hvm_domain.buf_ioreq;This isn't a purely cosmetic change either, especially without an
ASSERT(current->domain == d). It looks to be correct with one minor
exception: There's agdprintk()in this function, which - if you don't expect the function to be called for the current domain only - needs to be altered to not falsely print the current vCPU as subject anymore.
It will only by called for the current domain - I was just making it more analogous with hvm_send_assist_req() which takes a vcpu as an argument even though, in practice, it's always current. Perhaps I should tidy away that argument rather than introducing a new one here.
Paul
Quoted 1 line
Jan
PATCH v4 2/8 ioreq-server: centralize access to ioreq structures
In reply to Paul DurrantTo simplify creation of the ioreq server abstraction in a subsequent patch, this patch centralizes all use of the shared ioreq structure and the buffered ioreq ring to the source module xen/arch/x86/hvm/hvm.c.
The patch moves an rmb() from inside hvm_io_assist() to hvm_do_resume() because the former may now be passed a data structure on stack, in which case the barrier is unnecessary.
--- xen/arch/x86/hvm/emulate.c | 70 +++++++++------------- xen/arch/x86/hvm/hvm.c | 118 +++++++++++++++++++++++++++++++++++-- xen/arch/x86/hvm/io.c | 104 +++----------------------------- xen/arch/x86/hvm/vmx/vvmx.c | 13 +++- xen/include/asm-x86/hvm/hvm.h | 15 ++++- xen/include/asm-x86/hvm/support.h | 21 ++++--- 6 files changed, 185 insertions(+), 156 deletions(-)
xen/arch/x86/hvm/emulate.c +29 -41
@@ -57,24 +57,11 @@ static int hvmemul_do_io(int value_is_ptr = (p_data ==NULL );struct vcpu *curr = current;struct hvm_vcpu_io *vio; -ioreq_t *p =get_ioreq (curr); -ioreq_t _ioreq; +ioreq_t p;unsigned long ram_gfn =paddr_to_pfn (ram_gpa);p2m_type_t p2mt;struct page_info *ram_page;int rc; -bool_t has_dm =1 ; - -/* -* Domains without a backing DM, don't have an ioreq page. Just -* point to a struct on the stack, initialising the state as needed. -*/ -if ( !p ) - { - has_dm =0 ; - p = &_ioreq; - p->state =STATE_IOREQ_NONE ; - }/* Check for paged out page */ ram_page =get_page_from_gfn (curr->domain, ram_gfn, &p2mt,P2M_UNSHARE );
@@ -173,15 +160,6 @@ static int hvmemul_do_io(return X86EMUL_UNHANDLEABLE ; } -if ( p->state !=STATE_IOREQ_NONE ) - { -gdprintk (XENLOG_WARNING ,"WARNING: io already pending (%d)?\n" , - p->state); -if ( ram_page ) -put_page (ram_page); -return X86EMUL_UNHANDLEABLE ; - } - vio->io_state = (p_data ==NULL ) ? HVMIO_dispatched : HVMIO_awaiting_completion; vio->io_size = size;
@@ -193,38 +171,38 @@ static int hvmemul_do_io(if ( vio->mmio_retrying ) *reps =1 ; - p->dir = dir; - p->data_is_ptr = value_is_ptr; - p->type = is_mmio ?IOREQ_TYPE_COPY :IOREQ_TYPE_PIO ; - p->size = size; - p->addr = addr; - p->count = *reps; - p->df = df; - p->data = value; + p.dir = dir; + p.data_is_ptr = value_is_ptr; + p.type = is_mmio ?IOREQ_TYPE_COPY :IOREQ_TYPE_PIO ; + p.size = size; + p.addr = addr; + p.count = *reps; + p.df = df; + p.data = value;if ( dir ==IOREQ_WRITE ) -hvmtrace_io_assist (is_mmio, p); +hvmtrace_io_assist (is_mmio, &p);if ( is_mmio ) { - rc =hvm_mmio_intercept (p); + rc =hvm_mmio_intercept (&p);if ( rc ==X86EMUL_UNHANDLEABLE ) - rc =hvm_buffered_io_intercept (p); + rc =hvm_buffered_io_intercept (&p); }else { - rc =hvm_portio_intercept (p); + rc =hvm_portio_intercept (&p); }switch ( rc ) {case X86EMUL_OKAY :case X86EMUL_RETRY : - *reps = p->count; - p->state =STATE_IORESP_READY ; + *reps = p.count; + p.state =STATE_IORESP_READY ;if ( !vio->mmio_retry ) { -hvm_io_assist (p); +hvm_io_assist (&p); vio->io_state = HVMIO_none; }else
@@ -233,7 +211,7 @@ static int hvmemul_do_io(break ;case X86EMUL_UNHANDLEABLE :/* If there is no backing DM, just ignore accesses */ -if ( !has_dm ) +if ( !hvm_has_dm (curr->domain) ) { rc =X86EMUL_OKAY ; vio->io_state = HVMIO_none;
@@ -241,7 +219,7 @@ static int hvmemul_do_io(else { rc =X86EMUL_RETRY ; -if ( !hvm_send_assist_req (curr) ) +if ( !hvm_send_assist_req (curr, &p) ) vio->io_state = HVMIO_none;else if ( p_data ==NULL ) rc =X86EMUL_OKAY ;
@@ -260,7 +238,7 @@ static int hvmemul_do_io( finish_access:if ( dir ==IOREQ_READ ) -hvmtrace_io_assist (is_mmio, p); +hvmtrace_io_assist (is_mmio, &p);if ( p_data !=NULL )memcpy (p_data, &vio->io_data, size);
@@ -1292,3 +1270,13 @@ struct segment_register *hvmemul_get_seg_reg(hvm_get_segment_register (current, seg, &hvmemul_ctxt->seg_reg[seg]);return &hvmemul_ctxt->seg_reg[seg]; } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/x86/hvm/hvm.c +114 -4
152 lines not on this page · raw message
xen/arch/x86/hvm/io.c +7 -97
123 lines not on this page · raw message
xen/arch/x86/hvm/vmx/vvmx.c +11 -2
@@ -1394,7 +1394,6 @@ void nvmx_switch_guest(void)struct vcpu *v = current;struct nestedvcpu *nvcpu = &vcpu_nestedhvm (v);struct cpu_user_regs *regs =guest_cpu_user_regs (); -const ioreq_t *ioreq =get_ioreq (v);/* * A pending IO emulation may still be not finished. In this case, no
@@ -1404,7 +1403,7 @@ void nvmx_switch_guest(void)* don't want to continue as this setup is not implemented nor supported * as of right now. */ -if ( !ioreq || ioreq->state !=STATE_IOREQ_NONE ) +if (hvm_io_pending (v) )return ;/* * a softirq may interrupt us between a virtual vmentry is
@@ -2522,3 +2521,13 @@ void nvmx_set_cr_read_shadow(struct vcpu *v, unsigned int cr)/* nvcpu.guest_cr is what L2 write to cr actually. */ __vmwrite (read_shadow_field, v->arch.hvm_vcpu.nvcpu.guest_cr[cr]); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-x86/hvm/hvm.h +14 -1
@@ -26,6 +26,7 @@#include <asm/hvm/asid.h> #include <public/domctl.h> #include <public/hvm/save.h> +#include <public/hvm/ioreq.h> #include <asm/mm.h> /* Interrupt acknowledgement sources. */
@@ -227,7 +228,7 @@ int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, struct page_info **_page, void **_va);void destroy_ring_for_helper (void **_va,struct page_info *page); -bool_t hvm_send_assist_req (struct vcpu *v); +bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *p);void hvm_get_guest_pat (struct vcpu *v,u64 *guest_pat);int hvm_set_guest_pat (struct vcpu *v,u64 guest_pat);
@@ -339,6 +340,8 @@ static inline unsigned long hvm_get_shadow_gs_base(struct vcpu *v)void hvm_cpuid (unsigned int input,unsigned int *eax,unsigned int *ebx,unsigned int *ecx,unsigned int *edx);void hvm_migrate_timers (struct vcpu *v); +bool_t hvm_has_dm (struct domain *d); +bool_t hvm_io_pending (struct vcpu *v);void hvm_do_resume (struct vcpu *v);void hvm_migrate_pirqs (struct vcpu *v);
@@ -522,3 +525,13 @@ bool_t nhvm_vmcx_hap_enabled(struct vcpu *v);enum hvm_intblk nhvm_interrupt_blocked (struct vcpu *v);#endif /* __ASM_X86_HVM_HVM_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-x86/hvm/support.h +10 -11
@@ -22,21 +22,10 @@#define __ASM_X86_HVM_SUPPORT_H__#include <xen/types.h> -#include <public/hvm/ioreq.h> #include <xen/sched.h> #include <xen/hvm/save.h> #include <asm/processor.h> -static inline ioreq_t *get_ioreq (struct vcpu *v) -{ -struct domain *d = v->domain; -shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; - -ASSERT ((v == current) ||spin_is_locked (&d->arch.hvm_domain.ioreq.lock)); - -return p ? &p->vcpu_ioreq[v->vcpu_id] :NULL ; -} -#define HVM_DELIVER_NO_ERROR_CODE -1#ifndef NDEBUG
@@ -144,3 +133,13 @@ int hvm_mov_to_cr(unsigned int cr, unsigned int gpr);int hvm_mov_from_cr (unsigned int cr,unsigned int gpr);#endif /* __ASM_X86_HVM_SUPPORT_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
Re: [PATCH v4 2/8] ioreq-server: centralize access to ioreq structures
Quoted 8 lines · Paul Durrant
To simplify creation of the ioreq server abstraction in a subsequent patch, this patch centralizes all use of the shared ioreq structure and the buffered ioreq ring to the source module
xen/arch/x86/hvm/hvm.c.The patch moves an
rmb()from insidehvm_io_assist()tohvm_do_resume()because the former may now be passed a data structure on stack, in which case the barrier is unnecessary.
Quoted 6 lines
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Jun Nakajima <[email protected]>Cc Eddie Dong <[email protected]>Cc Kevin Tian <[email protected]>
Quoted 567 lines
--- xen/arch/x86/hvm/emulate.c | 70 +++++++++------------- xen/arch/x86/hvm/hvm.c | 118 +++++++++++++++++++++++++++++++++++-- xen/arch/x86/hvm/io.c | 104 +++----------------------------- xen/arch/x86/hvm/vmx/vvmx.c | 13 +++- xen/include/asm-x86/hvm/hvm.h | 15 ++++- xen/include/asm-x86/hvm/support.h | 21 ++++--- 6 files changed, 185 insertions(+), 156 deletions(-)xen/arch/x86/hvm/emulate.c +29
-41@@ -57,24 +57,11 @@ static int hvmemul_do_io(int value_is_ptr = (p_data ==NULL );struct vcpu *curr = current;struct hvm_vcpu_io *vio; -ioreq_t *p =get_ioreq (curr); -ioreq_t _ioreq; +ioreq_t p;unsigned long ram_gfn =paddr_to_pfn (ram_gpa);p2m_type_t p2mt;struct page_info *ram_page;int rc; -bool_t has_dm =1 ; - -/* -* Domains without a backing DM, don't have an ioreq page. Just -* point to a struct on the stack, initialising the state as needed. -*/ -if ( !p ) - { - has_dm =0 ; - p = &_ioreq; - p->state =STATE_IOREQ_NONE ; - }/* Check for paged out page */ ram_page =get_page_from_gfn (curr->domain, ram_gfn, &p2mt,P2M_UNSHARE );@@ -173,15 +160,6 @@ static int hvmemul_do_io(return X86EMUL_UNHANDLEABLE ; } -if ( p->state !=STATE_IOREQ_NONE ) - { -gdprintk (XENLOG_WARNING ,"WARNING: io already pending (%d)?\n" , - p->state); -if ( ram_page ) -put_page (ram_page); -return X86EMUL_UNHANDLEABLE ; - } - vio->io_state = (p_data ==NULL ) ? HVMIO_dispatched : HVMIO_awaiting_completion; vio->io_size = size;@@ -193,38 +171,38 @@ static int hvmemul_do_io(if ( vio->mmio_retrying ) *reps =1 ; - p->dir = dir; - p->data_is_ptr = value_is_ptr; - p->type = is_mmio ?IOREQ_TYPE_COPY :IOREQ_TYPE_PIO ; - p->size = size; - p->addr = addr; - p->count = *reps; - p->df = df; - p->data = value; + p.dir = dir; + p.data_is_ptr = value_is_ptr; + p.type = is_mmio ?IOREQ_TYPE_COPY :IOREQ_TYPE_PIO ; + p.size = size; + p.addr = addr; + p.count = *reps; + p.df = df; + p.data = value;if ( dir ==IOREQ_WRITE ) -hvmtrace_io_assist (is_mmio, p); +hvmtrace_io_assist (is_mmio, &p);if ( is_mmio ) { - rc =hvm_mmio_intercept (p); + rc =hvm_mmio_intercept (&p);if ( rc ==X86EMUL_UNHANDLEABLE ) - rc =hvm_buffered_io_intercept (p); + rc =hvm_buffered_io_intercept (&p); }else { - rc =hvm_portio_intercept (p); + rc =hvm_portio_intercept (&p); }switch ( rc ) {case X86EMUL_OKAY :case X86EMUL_RETRY : - *reps = p->count; - p->state =STATE_IORESP_READY ; + *reps = p.count; + p.state =STATE_IORESP_READY ;if ( !vio->mmio_retry ) { -hvm_io_assist (p); +hvm_io_assist (&p); vio->io_state = HVMIO_none; }else @@ -233,7 +211,7 @@ static int hvmemul_do_io(break ;case X86EMUL_UNHANDLEABLE :/* If there is no backing DM, just ignore accesses */ -if ( !has_dm ) +if ( !hvm_has_dm (curr->domain) ) { rc =X86EMUL_OKAY ; vio->io_state = HVMIO_none;@@ -241,7 +219,7 @@ static int hvmemul_do_io(else { rc =X86EMUL_RETRY ; -if ( !hvm_send_assist_req (curr) ) +if ( !hvm_send_assist_req (curr, &p) ) vio->io_state = HVMIO_none;else if ( p_data ==NULL ) rc =X86EMUL_OKAY ;@@ -260,7 +238,7 @@ static int hvmemul_do_io( finish_access:if ( dir ==IOREQ_READ ) -hvmtrace_io_assist (is_mmio, p); +hvmtrace_io_assist (is_mmio, &p);if ( p_data !=NULL )memcpy (p_data, &vio->io_data, size);@@ -1292,3 +1270,13 @@ struct segment_register *hvmemul_get_seg_reg(hvm_get_segment_register (current, seg, &hvmemul_ctxt->seg_reg[seg]);return &hvmemul_ctxt->seg_reg[seg]; } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/x86/hvm/hvm.c +114
-4@@ -352,6 +352,26 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } +static ioreq_t *get_ioreq (struct vcpu *v) +{ +struct domain *d = v->domain; +shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; + +ASSERT ((v == current) ||spin_is_locked (&d->arch.hvm_domain.ioreq.lock)); + +return p ? &p->vcpu_ioreq[v->vcpu_id] :NULL ; +} + +bool_t hvm_io_pending (struct vcpu *v) +{ +ioreq_t *p =get_ioreq (v); + +if ( !p ) +return 0 ; + +return ( p->state !=STATE_IOREQ_NONE ); +} +void hvm_do_resume (struct vcpu *v) {ioreq_t *p =get_ioreq (v);@@ -370,11 +390,12 @@ void hvm_do_resume(struct vcpu *v)switch ( p->state ) {case STATE_IORESP_READY :/* IORESP_READY -> NONE */ +rmb ();/* see IORESP_READY /then/ read contents of ioreq */ hvm_io_assist (p);break ;case STATE_IOREQ_READY :/* IOREQ_{READY,INPROCESS} -> IORESP_READY */ case STATE_IOREQ_INPROCESS : -wait_on_xen_event_channel (v->arch.hvm_vcpu.xen_port, +wait_on_xen_event_channel (p->vp_eport, (p->state !=STATE_IOREQ_READY ) && (p->state !=STATE_IOREQ_INPROCESS ));break ;@@ -1414,7 +1435,87 @@ void hvm_vcpu_down(struct vcpu *v) } } -bool_t hvm_send_assist_req (struct vcpu *v) +int hvm_buffered_io_send (struct domain *d,const ioreq_t *p) +{ +struct hvm_ioreq_page *iorp = &d->arch.hvm_domain.buf_ioreq; +buffered_iopage_t *pg = iorp->va; +buf_ioreq_t bp; +/* Timeoffset sends 64b data, but no address. Use two consecutive slots. */ +int qw =0 ; + +/* Ensure buffered_iopage fits in a page */ +BUILD_BUG_ON (sizeof (buffered_iopage_t) >PAGE_SIZE ); + +/* +* Return 0 for the cases we can't deal with: +* - 'addr' is only a 20-bit field, so we cannot address beyond 1MB +* - we cannot buffer accesses to guest memory buffers, as the guest +* may expect the memory buffer to be synchronously accessed +* - the count field is usually used with data_is_ptr and since we don't +* support data_is_ptr we do not waste space for the count field either +*/ +if ( (p->addr >0xffffful ) || p->data_is_ptr || (p->count !=1 ) ) +return 0 ; + + bp.type = p->type; + bp.dir = p->dir; +switch ( p->size ) + { +case 1 : + bp.size =0 ; +break ; +case 2 : + bp.size =1 ; +break ; +case 4 : + bp.size =2 ; +break ; +case 8 : + bp.size =3 ; + qw =1 ; +break ; +default : +gdprintk (XENLOG_WARNING ,"unexpected ioreq size: %u\n" , p->size); +return 0 ; + } + + bp.data = p->data; + bp.addr = p->addr; + +spin_lock (&iorp->lock); + +if ( (pg->write_pointer - pg->read_pointer) >= + (IOREQ_BUFFER_SLOT_NUM - qw) ) + { +/* The queue is full: send the iopacket through the normal path. */ +spin_unlock (&iorp->lock); +return 0 ; + } + + pg->buf_ioreq[pg->write_pointer %IOREQ_BUFFER_SLOT_NUM ] = bp; + +if ( qw ) + { + bp.data = p->data >>32 ; + pg->buf_ioreq[(pg->write_pointer+1 ) %IOREQ_BUFFER_SLOT_NUM ] = bp; + } + +/* Make the ioreq_t visible /before/ write_pointer. */ +wmb (); + pg->write_pointer += qw ?2 :1 ; + +notify_via_xen_event_channel (d, d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ]); +spin_unlock (&iorp->lock); + +return 1 ; +} + +bool_t hvm_has_dm (struct domain *d) +{ +return !!d->arch.hvm_domain.ioreq.va; +} + +bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *proto_p) {ioreq_t *p =get_ioreq (v);@@ -1432,14 +1533,23 @@ bool_t hvm_send_assist_req(struct vcpu *v)return 0 ; } -prepare_wait_on_xen_event_channel (v->arch.hvm_vcpu.xen_port); + p->dir = proto_p->dir; + p->data_is_ptr = proto_p->data_is_ptr; + p->type = proto_p->type; + p->size = proto_p->size; + p->addr = proto_p->addr; + p->count = proto_p->count; + p->df = proto_p->df; + p->data = proto_p->data; + +prepare_wait_on_xen_event_channel (p->vp_eport);/* * Following happens /after/ blocking and setting up ioreq contents. * prepare_wait_on_xen_event_channel() is an implicit barrier. */ p->state =STATE_IOREQ_READY ; -notify_via_xen_event_channel (v->domain, v->arch.hvm_vcpu.xen_port); +notify_via_xen_event_channel (v->domain, p->vp_eport);return 1 ; }xen/arch/x86/hvm/io.c +7
-97@@ -46,82 +46,6 @@#include <xen/iocap.h> #include <public/hvm/ioreq.h> -int hvm_buffered_io_send (struct domain *d,const ioreq_t *p) -{ -struct hvm_ioreq_page *iorp = &d->arch.hvm_domain.buf_ioreq; -buffered_iopage_t *pg = iorp->va; -buf_ioreq_t bp; -/* Timeoffset sends 64b data, but no address. Use two consecutive slots. */ -int qw =0 ; - -/* Ensure buffered_iopage fits in a page */ -BUILD_BUG_ON (sizeof (buffered_iopage_t) >PAGE_SIZE ); - -/* -* Return 0 for the cases we can't deal with: -* - 'addr' is only a 20-bit field, so we cannot address beyond 1MB -* - we cannot buffer accesses to guest memory buffers, as the guest -* may expect the memory buffer to be synchronously accessed -* - the count field is usually used with data_is_ptr and since we don't -* support data_is_ptr we do not waste space for the count field either -*/ -if ( (p->addr >0xffffful ) || p->data_is_ptr || (p->count !=1 ) ) -return 0 ; - - bp.type = p->type; - bp.dir = p->dir; -switch ( p->size ) - { -case 1 : - bp.size =0 ; -break ; -case 2 : - bp.size =1 ; -break ; -case 4 : - bp.size =2 ; -break ; -case 8 : - bp.size =3 ; - qw =1 ; -break ; -default : -gdprintk (XENLOG_WARNING ,"unexpected ioreq size: %u\n" , p->size); -return 0 ; - } - - bp.data = p->data; - bp.addr = p->addr; - -spin_lock (&iorp->lock); - -if ( (pg->write_pointer - pg->read_pointer) >= - (IOREQ_BUFFER_SLOT_NUM - qw) ) - { -/* The queue is full: send the iopacket through the normal path. */ -spin_unlock (&iorp->lock); -return 0 ; - } - - pg->buf_ioreq[pg->write_pointer %IOREQ_BUFFER_SLOT_NUM ] = bp; - -if ( qw ) - { - bp.data = p->data >>32 ; - pg->buf_ioreq[(pg->write_pointer+1 ) %IOREQ_BUFFER_SLOT_NUM ] = bp; - } - -/* Make the ioreq_t visible /before/ write_pointer. */ -wmb (); - pg->write_pointer += qw ?2 :1 ; - -notify_via_xen_event_channel (d, - d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ]); -spin_unlock (&iorp->lock); - -return 1 ; -} -void send_timeoffset_req (unsigned long timeoff) {ioreq_t p = {@@ -143,26 +67,14 @@ void send_timeoffset_req(unsigned long timeoff)/* Ask ioemu mapcache to invalidate mappings. */ void send_invalidate_req (void ) { -struct vcpu *v = current; -ioreq_t *p =get_ioreq (v); - -if ( !p ) -return ; - -if ( p->state !=STATE_IOREQ_NONE ) - { -gdprintk (XENLOG_ERR ,"WARNING: send invalidate req with something " -"already pending (%d)?\n" , p->state); -domain_crash (v->domain); -return ; - } - - p->type =IOREQ_TYPE_INVALIDATE ; - p->size =4 ; - p->dir =IOREQ_WRITE ; - p->data = ~0UL ;/* flush all */ +ioreq_t p = { + .type =IOREQ_TYPE_INVALIDATE , + .size =4 , + .dir =IOREQ_WRITE , + .data = ~0UL ,/* flush all */ + }; - (void )hvm_send_assist_req (v); + (void )hvm_send_assist_req (current, &p); }int handle_mmio (void )@@ -265,8 +177,6 @@ void hvm_io_assist(ioreq_t *p)struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;enum hvm_io_state io_state; -rmb ();/* see IORESP_READY /then/ read contents of ioreq */ - p->state =STATE_IOREQ_NONE ; io_state = vio->io_state;xen/arch/x86/hvm/vmx/vvmx.c +11
-2@@ -1394,7 +1394,6 @@ void nvmx_switch_guest(void)struct vcpu *v = current;struct nestedvcpu *nvcpu = &vcpu_nestedhvm (v);struct cpu_user_regs *regs =guest_cpu_user_regs (); -const ioreq_t *ioreq =get_ioreq (v);/* * A pending IO emulation may still be not finished. In this case, no @@ -1404,7 +1403,7 @@ void nvmx_switch_guest(void)* don't want to continue as this setup is not implemented nor supported * as of right now. */ -if ( !ioreq || ioreq->state !=STATE_IOREQ_NONE ) +if (hvm_io_pending (v) )return ;/* * a softirq may interrupt us between a virtual vmentry is @@ -2522,3 +2521,13 @@ void nvmx_set_cr_read_shadow(struct vcpu *v, unsigned int cr)/* nvcpu.guest_cr is what L2 write to cr actually. */ __vmwrite (read_shadow_field, v->arch.hvm_vcpu.nvcpu.guest_cr[cr]); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/asm-x86/hvm/hvm.h +14
-1@@ -26,6 +26,7 @@#include <asm/hvm/asid.h> #include <public/domctl.h> #include <public/hvm/save.h> +#include <public/hvm/ioreq.h> #include <asm/mm.h> /* Interrupt acknowledgement sources. */ @@ -227,7 +228,7 @@ int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, struct page_info **_page, void **_va);void destroy_ring_for_helper (void **_va,struct page_info *page); -bool_t hvm_send_assist_req (struct vcpu *v); +bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *p);void hvm_get_guest_pat (struct vcpu *v,u64 *guest_pat);int hvm_set_guest_pat (struct vcpu *v,u64 guest_pat);@@ -339,6 +340,8 @@ static inline unsigned long hvm_get_shadow_gs_base(struct vcpu *v)void hvm_cpuid (unsigned int input,unsigned int *eax,unsigned int *ebx,unsigned int *ecx,unsigned int *edx);void hvm_migrate_timers (struct vcpu *v); +bool_t hvm_has_dm (struct domain *d); +bool_t hvm_io_pending (struct vcpu *v);void hvm_do_resume (struct vcpu *v);void hvm_migrate_pirqs (struct vcpu *v);@@ -522,3 +525,13 @@ bool_t nhvm_vmcx_hap_enabled(struct vcpu *v);enum hvm_intblk nhvm_interrupt_blocked (struct vcpu *v);#endif /* __ASM_X86_HVM_HVM_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/asm-x86/hvm/support.h +10
-12@@ -22,21 +22,10 @@#define __ASM_X86_HVM_SUPPORT_H__#include <xen/types.h> -#include <public/hvm/ioreq.h> #include <xen/sched.h> #include <xen/hvm/save.h> #include <asm/processor.h> -static inline ioreq_t *get_ioreq (struct vcpu *v) -{ -struct domain *d = v->domain; -shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; - -ASSERT ((v == current) ||spin_is_locked (&d->arch.hvm_domain.ioreq.lock)); - -return p ? &p->vcpu_ioreq[v->vcpu_id] :NULL ; -} -#define HVM_DELIVER_NO_ERROR_CODE -1#ifndef NDEBUG @@ -144,3 +133,13 @@ int hvm_mov_to_cr(unsigned int cr, unsigned int gpr);int hvm_mov_from_cr (unsigned int cr,unsigned int gpr);#endif /* __ASM_X86_HVM_SUPPORT_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ --1.7.10.4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 2/8] ioreq-server: centralize access to ioreq structures
In reply to Paul DurrantQuoted 4 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/emulate.c +0
-0@@ -173,15 +160,6 @@ static int hvmemul_do_io(return X86EMUL_UNHANDLEABLE ; }
xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 184
Quoted 10 lines
xen/arch/x86/hvm/emulate.c +0
-9-if ( p->state !=STATE_IOREQ_NONE ) - { -gdprintk (XENLOG_WARNING ,"WARNING: io already pending (%d)?\n" , - p->state); -if ( ram_page ) -put_page (ram_page); -return X86EMUL_UNHANDLEABLE ; - } -
Shouldn't this be replaced with a call to hvm_io_pending() instead of just getting deleted?
Quoted 14 lines
xen/arch/x86/hvm/hvm.c +8
-0@@ -352,6 +352,26 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } +static ioreq_t *get_ioreq (struct vcpu *v) +{ +struct domain *d = v->domain; +shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; + +ASSERT ((v == current) ||spin_is_locked (&d->arch.hvm_domain.ioreq.lock)); + +return p ? &p->vcpu_ioreq[v->vcpu_id] :NULL ;
xen/arch/x86/hvm/hvm.c void hvm_migrate_pirqs(struct vcpu *v) · line 372
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+} + +bool_t hvm_io_pending (struct vcpu *v) +{ +ioreq_t *p =get_ioreq (v); + +if ( !p ) +return 0 ; + +return ( p->state !=STATE_IOREQ_NONE );
The parentheses are pointless but a matter of taste (but then again using them here makes little sense if you don't also use them around the conditional expression in the function right above), but the blanks inside them clearly don't belong there according to our coding style.
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req(struct vcpu *v) · line 1543
Quoted 13 lines
xen/arch/x86/hvm/hvm.c +8
-1@@ -1432,14 +1533,23 @@ bool_t hvm_send_assist_req(struct vcpu *v)return 0 ; } -prepare_wait_on_xen_event_channel (v->arch.hvm_vcpu.xen_port); + p->dir = proto_p->dir; + p->data_is_ptr = proto_p->data_is_ptr; + p->type = proto_p->type; + p->size = proto_p->size; + p->addr = proto_p->addr; + p->count = proto_p->count; + p->df = proto_p->df; + p->data = proto_p->data;
I realize that you do this piecemeal copying because of wanting to leave alone ->state. If you didn't have the input pointer const, and if no caller depended on that field having any specific contents (I'm sure none of them cares), you could set the input structure's field first to STATE_IOREQ_NONE and then copy the whole structure in one go. And that all if the field's value is meaningful at all across the call to prepare_wait_on_xen_event_channel(), as it gets set to STATE_IOREQ_READY right afterwards.
Hmm, I see vp_eport also needs to be left untouched. I wonder whether there shouldn't be a sub-structure with all the fields set above, and with only that sub-structure getting passed around after setting up on-stack.
Jan
Re: [PATCH v4 2/8] ioreq-server: centralize access to ioreq structures
Quoted 24 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 07 April 2014 12:10
To: Paul Durrant
Cc: Eddie Dong; Jun Nakajima; Kevin Tian; [email protected]; Keir (Xen.org)
Subject: Re: [PATCH v4 2/8] ioreq-server: centralize access to ioreq structuresxen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 178
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/emulate.c +0
-3@@ -173,15 +160,6 @@ static int hvmemul_do_io(return X86EMUL_UNHANDLEABLE ; } -if ( p->state !=STATE_IOREQ_NONE ) - { - gdprintk(XENLOG_WARNING, "WARNING: io already pending(%d)?\n",
xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 184
Quoted 6 lines
xen/arch/x86/hvm/emulate.c +0
-6- p->state); -if ( ram_page ) -put_page (ram_page); -return X86EMUL_UNHANDLEABLE ; - } -
Quoted 2 lines
Shouldn't this be replaced with a call to
hvm_io_pending()instead of just getting deleted?
Yes, that's probably better.
Quoted 23 lines
Quoted 23 lines
xen/arch/x86/hvm/hvm.c +15
-0@@ -352,6 +352,26 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } +static ioreq_t *get_ioreq (struct vcpu *v) +{ +struct domain *d = v->domain; +shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; + +ASSERT ((v == current) ||spin_is_locked (&d- arch.hvm_domain.ioreq.lock)); + +return p ? &p->vcpu_ioreq[v->vcpu_id] :NULL ; +} + +bool_t hvm_io_pending (struct vcpu *v) +{ +ioreq_t *p =get_ioreq (v); + +if ( !p )
Quoted 9 lines
xen/arch/x86/hvm/hvm.c void hvm_migrate_pirqs(struct vcpu *v) · line 372
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +3
-0+return 0 ; + +return ( p->state !=STATE_IOREQ_NONE );The parentheses are pointless but a matter of taste (but then again using them here makes little sense if you don't also use them around the conditional expression in the function right above), but the blanks inside them clearly don't belong there according to our coding style.
Ok.
Quoted 23 lines
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req(struct vcpu *v) · line 1543
Quoted 13 lines
xen/arch/x86/hvm/hvm.c +8
-1@@ -1432,14 +1533,23 @@ bool_t hvm_send_assist_req(struct vcpu *v)return 0 ; } -prepare_wait_on_xen_event_channel (v->arch.hvm_vcpu.xen_port); + p->dir = proto_p->dir; + p->data_is_ptr = proto_p->data_is_ptr; + p->type = proto_p->type; + p->size = proto_p->size; + p->addr = proto_p->addr; + p->count = proto_p->count; + p->df = proto_p->df; + p->data = proto_p->data;I realize that you do this piecemeal copying because of wanting to leave alone ->state. If you didn't have the input pointer const, and if no caller depended on that field having any specific contents (I'm sure none of them cares), you could set the input structure's field first to
STATE_IOREQ_NONEand then copy the whole structure in one go. And that all if the field's value is meaningful at all across the call toprepare_wait_on_xen_event_channel(), as it gets set toSTATE_IOREQ_READYright afterwards.
Quoted 5 lines
Hmm, I see
vp_eportalso needs to be left untouched. I wonder whether there shouldn't be a sub-structure with all the fields set above, and with only that sub-structure getting passed around after setting up on-stack.
The layout of ioreq_t is stable (as it's an ABI with QEMU) so I can't change it. I could introduce a new variant without vp_eport or state and change xen to use that internally, but that's going to be quite a big patch. Alternatively I could copy vp_eport aside here an assign the struct - which should lead to a smaller hunk, so I'll do that.
Paul
PATCH v4 3/8 ioreq-server: create basic ioreq server abstraction.
In reply to Paul DurrantCollect together data structures concerning device emulation together into a new struct hvm_ioreq_server.
Code that deals with the shared and buffered ioreq pages is extracted from functions such as hvm_domain_initialise, hvm_vcpu_initialise and do_hvm_op and consolidated into a set of hvm_ioreq_server manipulation functions. The lock in the hvm_ioreq_page served two different purposes and has been replaced by separate locks in the hvm_ioreq_server.
--- xen/arch/x86/hvm/hvm.c | 406 ++++++++++++++++++++++++++------------ xen/include/asm-x86/hvm/domain.h | 35 +++- xen/include/asm-x86/hvm/vcpu.h | 12 +- 3 files changed, 322 insertions(+), 131 deletions(-)
xen/arch/x86/hvm/hvm.c +280 -126
@@ -352,39 +352,49 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } -static ioreq_t *get_ioreq (struct vcpu *v) +static ioreq_t *get_ioreq (struct hvm_ioreq_server *s,struct vcpu *v) { -struct domain *d = v->domain; -shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; +shared_iopage_t *p = s->ioreq.va; -ASSERT ((v == current) ||spin_is_locked (&d->arch.hvm_domain.ioreq.lock)); +/* +* Manipulation of the shared ioreq structure (to update the event +* channel) is protected by a domain_pause(). So this function should +* only ever be executed for the current vcpu or one that is paused. +*/ +ASSERT ((v == current) || !vcpu_runnable (v)); +ASSERT (p !=NULL ); -return p ? &p->vcpu_ioreq[v->vcpu_id] :NULL ; +return &p->vcpu_ioreq[v->vcpu_id]; }bool_t hvm_io_pending (struct vcpu *v) { -ioreq_t *p =get_ioreq (v); +struct hvm_ioreq_server *s = v->domain->arch.hvm_domain.ioreq_server; +ioreq_t *p; -if ( !p ) +if ( !s )return 0 ; + p =get_ioreq (s, v);return ( p->state !=STATE_IOREQ_NONE ); }void hvm_do_resume (struct vcpu *v) { -ioreq_t *p =get_ioreq (v); +struct domain *d = v->domain; +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +ioreq_t *p;check_wakeup_from_wait ();if (is_hvm_vcpu (v) )pt_restore_timer (v); -/* NB. Optimised for common case (p->state == STATE_IOREQ_NONE). */ -if ( !p ) +if ( !s ) goto check_inject_trap; +/* NB. Optimised for common case (p->state == STATE_IOREQ_NONE). */ + p =get_ioreq (s, v);while ( p->state !=STATE_IOREQ_NONE ) { switch ( p->state )
@@ -415,14 +425,6 @@ void hvm_do_resume(struct vcpu *v) } } -static void hvm_init_ioreq_page ( -struct domain *d,struct hvm_ioreq_page *iorp) -{ -memset (iorp,0 ,sizeof (*iorp)); -spin_lock_init (&iorp->lock); -domain_pause (d); -} -void destroy_ring_for_helper (void **_va,struct page_info *page) {
@@ -436,16 +438,9 @@ void destroy_ring_for_helper( } } -static void hvm_unmap_ioreq_page ( -struct domain *d,struct hvm_ioreq_page *iorp) +static void hvm_unmap_ioreq_page (struct hvm_ioreq_page *iorp) { -spin_lock (&iorp->lock); - -ASSERT (d->is_dying); -destroy_ring_for_helper (&iorp->va, iorp->page); - -spin_unlock (&iorp->lock); } int prepare_ring_for_helper(
@@ -502,22 +497,15 @@ static int hvm_map_ioreq_page(if ( (rc =prepare_ring_for_helper (d, gmfn, &page, &va)) )return rc; -spin_lock (&iorp->lock); -if ( (iorp->va !=NULL ) || d->is_dying ) {destroy_ring_for_helper (&va, page); -spin_unlock (&iorp->lock);return -EINVAL ; } iorp->va = va; iorp->page = page; -spin_unlock (&iorp->lock); - -domain_unpause (d); -return 0 ; }
@@ -561,8 +549,227 @@ static int handle_pvh_io(return X86EMUL_OKAY ; } +static void hvm_update_ioreq_evtchn (struct hvm_ioreq_server *s, +struct hvm_ioreq_vcpu *sv) +{ +ASSERT (spin_is_locked (&s->lock)); + +if ( s->ioreq.va !=NULL ) + { +ioreq_t *p =get_ioreq (s, sv->vcpu); + + p->vp_eport = sv->ioreq_evtchn; + } +} + +static int hvm_ioreq_server_add_vcpu (struct hvm_ioreq_server *s, +struct vcpu *v) +{ +struct hvm_ioreq_vcpu *sv; +int rc; + +spin_lock (&s->lock); + + sv = xzalloc(struct hvm_ioreq_vcpu); + + rc = -ENOMEM ; +if ( !sv ) + goto fail1; + + rc =alloc_unbound_xen_event_channel (v, s->domid,NULL ); +if ( rc <0 ) + goto fail2; + + sv->ioreq_evtchn = rc; + +if ( v->vcpu_id ==0 ) + { +struct domain *d = s->domain; + + rc =alloc_unbound_xen_event_channel (v, s->domid,NULL ); +if ( rc <0 ) + goto fail3; + + s->bufioreq_evtchn = rc; + d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ] = + s->bufioreq_evtchn; + } + + sv->vcpu = v; + +list_add (&sv->list_entry, &s->ioreq_vcpu_list); + +hvm_update_ioreq_evtchn (s, sv); + +spin_unlock (&s->lock); +return 0 ; + + fail3: +free_xen_event_channel (v, sv->ioreq_evtchn); + + fail2: +xfree (sv); + + fail1: +spin_unlock (&s->lock); +return rc; +} + +static void hvm_ioreq_server_remove_vcpu (struct hvm_ioreq_server *s, +struct vcpu *v) +{ +struct list_head *entry; + +spin_lock (&s->lock); + + list_for_each ( entry, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); + +if ( sv->vcpu != v ) +continue ; + +list_del_init (&sv->list_entry); + +if ( v->vcpu_id ==0 ) +free_xen_event_channel (v, s->bufioreq_evtchn); + +free_xen_event_channel (v, sv->ioreq_evtchn); + +xfree (sv); +break ; + } + +spin_unlock (&s->lock); +} + +static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +{ +struct hvm_ioreq_server *s; + + s = xzalloc(struct hvm_ioreq_server); +if ( !s ) +return -ENOMEM ; + + s->domain = d; + s->domid = domid; + +spin_lock_init (&s->lock); +INIT_LIST_HEAD (&s->ioreq_vcpu_list); +spin_lock_init (&s->bufioreq_lock); + + d->arch.hvm_domain.ioreq_server = s; +return 0 ; +} + +static void hvm_destroy_ioreq_server (struct domain *d) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; + +hvm_unmap_ioreq_page (&s->bufioreq); +hvm_unmap_ioreq_page (&s->ioreq); + +xfree (s); +} + +static int hvm_set_ioreq_pfn (struct domain *d,bool_t buf, +unsigned long pfn) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; +int rc; + +spin_lock (&s->lock); + + rc =hvm_map_ioreq_page (d, iorp, pfn); +if ( rc ) + goto fail; + +if (!buf) { +struct list_head *entry; + + list_for_each ( entry, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); + +hvm_update_ioreq_evtchn (s, sv); + } + } + +spin_unlock (&s->lock); +return 0 ; + + fail: +spin_unlock (&s->lock); +return rc; +} + +static int hvm_replace_event_channel (struct vcpu *v,domid_t remote_domid, +evtchn_port_t *p_port) +{ +evtchn_port_t old_port, new_port; + + new_port =alloc_unbound_xen_event_channel (v, remote_domid,NULL ); +if ( new_port <0 ) +return new_port; + +/* xchg() ensures that only we call free_xen_event_channel(). */ + old_port =xchg (p_port, new_port); +free_xen_event_channel (v, old_port); +return 0 ; +} + +static int hvm_set_dm_domain (struct domain *d,domid_t domid) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +int rc =0 ; + +spin_lock (&s->lock); +domain_pause (d); + +if ( s->domid != domid ) { +struct list_head *entry; + + list_for_each ( entry, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); +struct vcpu *v = sv->vcpu; + +if ( v->vcpu_id ==0 ) { + rc =hvm_replace_event_channel (v, domid, + &s->bufioreq_evtchn); +if ( rc ) +break ; + + d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ] = + s->bufioreq_evtchn; + } + + rc =hvm_replace_event_channel (v, domid, &sv->ioreq_evtchn); +if ( rc ) +break ; + +hvm_update_ioreq_evtchn (s, sv); + } + + s->domid = domid; + } + +domain_unpause (d); +spin_unlock (&s->lock); + +return rc; +} +int hvm_domain_initialise (struct domain *d) { +domid_t domid;int rc;if ( !hvm_enabled )
@@ -628,17 +835,21 @@ int hvm_domain_initialise(struct domain *d)rtc_init (d); -hvm_init_ioreq_page (d, &d->arch.hvm_domain.ioreq); -hvm_init_ioreq_page (d, &d->arch.hvm_domain.buf_ioreq); + domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; + rc =hvm_create_ioreq_server (d, domid); +if ( rc !=0 ) + goto fail2;register_portio_handler (d,0xe9 ,1 , hvm_print_line); rc = hvm_funcs.domain_initialise (d);if ( rc !=0 ) - goto fail2; + goto fail3;return 0 ; + fail3: +hvm_destroy_ioreq_server (d); fail2:rtc_deinit (d);stdvga_deinit (d);
@@ -662,8 +873,7 @@ void hvm_domain_relinquish_resources(struct domain *d)if ( hvm_funcs.nhvm_domain_relinquish_resources ) hvm_funcs.nhvm_domain_relinquish_resources (d); -hvm_unmap_ioreq_page (d, &d->arch.hvm_domain.ioreq); -hvm_unmap_ioreq_page (d, &d->arch.hvm_domain.buf_ioreq); +hvm_destroy_ioreq_server (d);msixtbl_pt_cleanup (d);
@@ -1296,7 +1506,7 @@ int hvm_vcpu_initialise(struct vcpu *v) {int rc;struct domain *d = v->domain; -domid_t dm_domid; +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server;hvm_asid_flush_vcpu (v);
@@ -1339,30 +1549,10 @@ int hvm_vcpu_initialise(struct vcpu *v) && (rc = nestedhvm_vcpu_initialise(v)) < 0 ) /* teardown: nestedhvm_vcpu_destroy */ goto fail5; - dm_domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; - -/* Create ioreq event channel. */ - rc =alloc_unbound_xen_event_channel (v, dm_domid,NULL );/* teardown: none */ -if ( rc <0 ) + rc =hvm_ioreq_server_add_vcpu (s, v); +if ( rc !=0 ) goto fail6; -/* Register ioreq event channel. */ - v->arch.hvm_vcpu.xen_port = rc; - -if ( v->vcpu_id ==0 ) - { -/* Create bufioreq event channel. */ - rc =alloc_unbound_xen_event_channel (v, dm_domid,NULL );/* teardown: none */ -if ( rc <0 ) - goto fail6; - d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ] = rc; - } - -spin_lock (&d->arch.hvm_domain.ioreq.lock); -if ( d->arch.hvm_domain.ioreq.va !=NULL ) -get_ioreq (v)->vp_eport = v->arch.hvm_vcpu.xen_port; -spin_unlock (&d->arch.hvm_domain.ioreq.lock); -if ( v->vcpu_id ==0 ) {/* NB. All these really belong in hvm_domain_initialise(). */
@@ -1395,6 +1585,11 @@ int hvm_vcpu_initialise(struct vcpu *v)void hvm_vcpu_destroy (struct vcpu *v) { +struct domain *d = v->domain; +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; + +hvm_ioreq_server_remove_vcpu (s, v); +nestedhvm_vcpu_destroy (v);free_compat_arg_xlat (v);
@@ -1406,9 +1601,6 @@ void hvm_vcpu_destroy(struct vcpu *v)vlapic_destroy (v); hvm_funcs.vcpu_destroy (v); - -/* Event channel is already freed by evtchn_destroy(). */ -/*free_xen_event_channel(v, v->arch.hvm_vcpu.xen_port);*/ }void hvm_vcpu_down (struct vcpu *v)
@@ -1437,8 +1629,9 @@ void hvm_vcpu_down(struct vcpu *v)int hvm_buffered_io_send (struct domain *d,const ioreq_t *p) { -struct hvm_ioreq_page *iorp = &d->arch.hvm_domain.buf_ioreq; -buffered_iopage_t *pg = iorp->va; +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_page *iorp; +buffered_iopage_t *pg;buf_ioreq_t bp;/* Timeoffset sends 64b data, but no address. Use two consecutive slots. */ int qw =0 ;
@@ -1446,6 +1639,12 @@ int hvm_buffered_io_send(struct domain *d, const ioreq_t *p)/* Ensure buffered_iopage fits in a page */ BUILD_BUG_ON (sizeof (buffered_iopage_t) >PAGE_SIZE ); +if ( !s ) +return 0 ; + + iorp = &s->bufioreq; + pg = iorp->va; +/* * Return 0 for the cases we can't deal with: * - 'addr' is only a 20-bit field, so we cannot address beyond 1MB
@@ -1482,13 +1681,13 @@ int hvm_buffered_io_send(struct domain *d, const ioreq_t *p) bp.data = p->data; bp.addr = p->addr; -spin_lock (&iorp->lock); +spin_lock (&s->bufioreq_lock);if ( (pg->write_pointer - pg->read_pointer) >= (IOREQ_BUFFER_SLOT_NUM - qw) ) {/* The queue is full: send the iopacket through the normal path. */ -spin_unlock (&iorp->lock); +spin_unlock (&s->bufioreq_lock);return 0 ; }
@@ -1504,32 +1703,36 @@ int hvm_buffered_io_send(struct domain *d, const ioreq_t *p)wmb (); pg->write_pointer += qw ?2 :1 ; -notify_via_xen_event_channel (d, d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ]); -spin_unlock (&iorp->lock); +notify_via_xen_event_channel (d, s->bufioreq_evtchn); +spin_unlock (&s->bufioreq_lock);return 1 ; }bool_t hvm_has_dm (struct domain *d) { -return !!d->arch.hvm_domain.ioreq.va; +return !!d->arch.hvm_domain.ioreq_server; }bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *proto_p) { -ioreq_t *p =get_ioreq (v); +struct domain *d = v->domain; +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +ioreq_t *p;if (unlikely (!vcpu_start_shutdown_deferral (v)) )return 0 ;/* implicitly bins the i/o operation */ -if ( !p ) +if ( !s )return 0 ; + p =get_ioreq (s, v); +if (unlikely (p->state !=STATE_IOREQ_NONE ) ) {/* This indicates a bug in the device model. Crash the domain. */ gdprintk (XENLOG_ERR ,"Device model set bad IO state %d.\n" , p->state); -domain_crash (v->domain); +domain_crash (d);return 0 ; }
@@ -4167,21 +4370,6 @@ static int hvmop_flush_tlb_all(void)return 0 ; } -static int hvm_replace_event_channel (struct vcpu *v,domid_t remote_domid, -int *p_port) -{ -int old_port, new_port; - - new_port =alloc_unbound_xen_event_channel (v, remote_domid,NULL ); -if ( new_port <0 ) -return new_port; - -/* xchg() ensures that only we call free_xen_event_channel(). */ - old_port =xchg (p_port, new_port); -free_xen_event_channel (v, old_port); -return 0 ; -} -long do_hvm_op (unsigned long op,XEN_GUEST_HANDLE_PARAM (void ) arg) {
@@ -4194,7 +4382,6 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)case HVMOP_get_param: {struct xen_hvm_param a; -struct hvm_ioreq_page *iorp;struct domain *d;struct vcpu *v;
@@ -4227,19 +4414,10 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)switch ( a.index ) {case HVM_PARAM_IOREQ_PFN : - iorp = &d->arch.hvm_domain.ioreq; -if ( (rc =hvm_map_ioreq_page (d, iorp, a.value)) !=0 ) -break ; -spin_lock (&iorp->lock); -if ( iorp->va !=NULL ) -/* Initialise evtchn port info if VCPUs already created. */ - for_each_vcpu ( d, v ) -get_ioreq (v)->vp_eport = v->arch.hvm_vcpu.xen_port; -spin_unlock (&iorp->lock); + rc =hvm_set_ioreq_pfn (d,0 , a.value);break ;case HVM_PARAM_BUFIOREQ_PFN : - iorp = &d->arch.hvm_domain.buf_ioreq; - rc =hvm_map_ioreq_page (d, iorp, a.value); + rc =hvm_set_ioreq_pfn (d,1 , a.value);break ;case HVM_PARAM_CALLBACK_IRQ :hvm_set_callback_via (d, a.value);
@@ -4294,31 +4472,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)if ( a.value ==DOMID_SELF ) a.value = curr_d->domain_id; - rc =0 ; -domain_pause (d);/* safe to change per-vcpu xen_port */ -if ( d->vcpu[0 ] ) - rc =hvm_replace_event_channel (d->vcpu[0 ], a.value, - (int *)&d->vcpu[0 ]->domain->arch.hvm_domain.params - [HVM_PARAM_BUFIOREQ_EVTCHN ]); -if ( rc ) - { -domain_unpause (d); -break ; - } - iorp = &d->arch.hvm_domain.ioreq; - for_each_vcpu ( d, v ) - { - rc =hvm_replace_event_channel (v, a.value, - &v->arch.hvm_vcpu.xen_port); -if ( rc ) -break ; - -spin_lock (&iorp->lock); -if ( iorp->va !=NULL ) -get_ioreq (v)->vp_eport = v->arch.hvm_vcpu.xen_port; -spin_unlock (&iorp->lock); - } -domain_unpause (d); + rc =hvm_set_dm_domain (d, a.value);break ;case HVM_PARAM_ACPI_S_STATE :/* Not reflexive, as we must domain_pause(). */
xen/include/asm-x86/hvm/domain.h +32 -3
@@ -36,14 +36,34 @@#include <public/hvm/save.h> struct hvm_ioreq_page { -spinlock_t lock;struct page_info *page;void *va; }; -struct hvm_domain { +struct hvm_ioreq_vcpu { +struct list_head list_entry; +struct vcpu *vcpu; +evtchn_port_t ioreq_evtchn; +}; + +struct hvm_ioreq_server { +/* Lock to serialize toolstack modifications */ +spinlock_t lock; +struct domain *domain; + +/* Domain id of emulating domain */ +domid_t domid;struct hvm_ioreq_page ioreq; -struct hvm_ioreq_page buf_ioreq; +struct list_head ioreq_vcpu_list; +struct hvm_ioreq_page bufioreq; + +/* Lock to serialize access to buffered ioreq ring */ +spinlock_t bufioreq_lock; +evtchn_port_t bufioreq_evtchn; +}; + +struct hvm_domain { +struct hvm_ioreq_server *ioreq_server;struct pl_time pl_time;
@@ -100,3 +120,12 @@ struct hvm_domain {#endif /* __ASM_X86_HVM_DOMAIN_H__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-x86/hvm/vcpu.h +10 -2
@@ -138,8 +138,6 @@ struct hvm_vcpu {spinlock_t tm_lock;struct list_head tm_list; -int xen_port; -bool_t flag_dr_dirty;bool_t debug_state_latch;bool_t single_step;
@@ -186,3 +184,13 @@ struct hvm_vcpu { };#endif /* __ASM_X86_HVM_VCPU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
Quoted 29 lines · Paul Durrant
Collect together data structures concerning device emulation together into a new struct
hvm_ioreq_server.Code that deals with the shared and buffered ioreq pages is extracted from functions such as
hvm_domain_initialise,hvm_vcpu_initialiseanddo_hvm_opand consolidated into a set ofhvm_ioreq_servermanipulation functions. The lock in thehvm_ioreq_pageserved two different purposes and has been replaced by separate locks in thehvm_ioreq_server.Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>--- xen/arch/x86/hvm/hvm.c | 406 ++++++++++++++++++++++++++------------ xen/include/asm-x86/hvm/domain.h | 35 +++- xen/include/asm-x86/hvm/vcpu.h | 12 +- 3 files changed, 322 insertions(+), 131 deletions(-)xen/arch/x86/hvm/hvm.c +1
-1@@ -352,39 +352,49 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } -static ioreq_t *get_ioreq (struct vcpu *v) +static ioreq_t *get_ioreq (struct hvm_ioreq_server *s,struct vcpu *v) {
xen/arch/x86/hvm/hvm.c void hvm_migrate_pirqs(struct vcpu *v) · line 363
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-3-struct domain *d = v->domain; -shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; +shared_iopage_t *p = s->ioreq.va; -ASSERT ((v == current) ||spin_is_locked (&d->arch.hvm_domain.ioreq.lock)); +/* +* Manipulation of the shared ioreq structure (to update the event +* channel) is protected by a domain_pause(). So this function should +* only ever be executed for the current vcpu or one that is paused. +*/
What on earth is "manipulation of the shared ioreq structure is protected by domain_pause()" supposed to mean? Do you mean that the only time there may be a race is between something in the emulation code writing to it, and something in the resume path reading it? That there are never any other races to access the structure? And that since the resume path won't be taken when the domain is paused, there can be no races, and therefore we do not need to be locked?
-George
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
Quoted 47 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Dunlap
Sent: 03 April 2014 15:50
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org); Jan Beulich
Subject: Re: [Xen-devel] [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.Quoted 5 lines · Paul Durrant
Collect together data structures concerning device emulation together into a new struct
hvm_ioreq_server.Code that deals with the shared and buffered ioreq pages is extracted from functions such as
hvm_domain_initialise,hvm_vcpu_initialiseand
do_hvm_opQuoted 1 line
and consolidated into a set of
hvm_ioreq_servermanipulation functions.The
Quoted 8 lines
lock in the
hvm_ioreq_pageserved two different purposes and has been replaced by separate locks in thehvm_ioreq_server.Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>--- xen/arch/x86/hvm/hvm.c | 406 ++++++++++++++++++++++++++------------
Quoted 19 lines
xen/include/asm-x86/hvm/domain.h | 35 +++- xen/include/asm-x86/hvm/vcpu.h | 12 +- 3 files changed, 322 insertions(+), 131 deletions(-)xen/arch/x86/hvm/hvm.c +2
-3@@ -352,39 +352,49 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } -static ioreq_t *get_ioreq (struct vcpu *v) +static ioreq_t *get_ioreq (struct hvm_ioreq_server *s,struct vcpu *v) { -struct domain *d = v->domain; -shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; +shared_iopage_t *p = s->ioreq.va;
Quoted 16 lines
xen/arch/x86/hvm/hvm.c void hvm_migrate_pirqs(struct vcpu *v) · line 363
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +5
-1-ASSERT ((v == current) ||spin_is_locked (&d- arch.hvm_domain.ioreq.lock)); +/* +* Manipulation of the shared ioreq structure (to update the event +* channel) is protected by a domain_pause(). So this function should +* only ever be executed for the current vcpu or one that is paused. +*/ What on earth is "manipulation of the shared ioreq structure is protected by
domain_pause()" supposed to mean? Do you mean that the only time there may be a race is between something in the emulation code writing to it, and something in the resume path reading it? That there are never any other races to access the structure? And that since the resume path won't be taken when the domain is paused, there can be no races, and therefore we do not need to be locked?
The sentiment I'm trying to express is that the shared structure can never be in use in the emulation path whilst it is being modified as the code that modifies always pauses the domain before doing so, so the assertion is that either v == current (in which case the domain is clearly not paused and we're in the emulation path) or !vcpu_runnable(v) (in which case the domain is paused and we're making a change).
Paul
Quoted 1 line
-George
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
Quoted 62 lines · Paul Durrant
Quoted 47 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Dunlap
Sent: 03 April 2014 15:50
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org); Jan Beulich
Subject: Re: [Xen-devel] [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.Quoted 5 lines · Paul Durrant
Collect together data structures concerning device emulation together into a new struct
hvm_ioreq_server.Code that deals with the shared and buffered ioreq pages is extracted from functions such as
hvm_domain_initialise,hvm_vcpu_initialiseand
do_hvm_opQuoted 1 line
and consolidated into a set of
hvm_ioreq_servermanipulation functions.The
Quoted 8 lines
lock in the
hvm_ioreq_pageserved two different purposes and has been replaced by separate locks in thehvm_ioreq_server.Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>--- xen/arch/x86/hvm/hvm.c | 406 ++++++++++++++++++++++++++------------
Quoted 19 lines
xen/include/asm-x86/hvm/domain.h | 35 +++- xen/include/asm-x86/hvm/vcpu.h | 12 +- 3 files changed, 322 insertions(+), 131 deletions(-)xen/arch/x86/hvm/hvm.c +2
-3@@ -352,39 +352,49 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } -static ioreq_t *get_ioreq (struct vcpu *v) +static ioreq_t *get_ioreq (struct hvm_ioreq_server *s,struct vcpu *v) { -struct domain *d = v->domain; -shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; +shared_iopage_t *p = s->ioreq.va;Quoted 15 lines
xen/arch/x86/hvm/hvm.c void hvm_migrate_pirqs(struct vcpu *v) · line 363
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +5
-1-ASSERT ((v == current) ||spin_is_locked (&d- arch.hvm_domain.ioreq.lock)); +/* +* Manipulation of the shared ioreq structure (to update the event +* channel) is protected by a domain_pause(). So this function should +* only ever be executed for the current vcpu or one that is paused. +*/ What on earth is "manipulation of the shared ioreq structure is protected by
domain_pause()" supposed to mean? Do you mean that the only time there may be a race is between something in the emulation code writing to it, and something in the resume path reading it? That there are never any other races to access the structure? And that since the resume path won't be taken when the domain is paused, there can be no races, and therefore we do not need to be locked?
Quoted 1 line
The sentiment I'm trying to express is that the shared structure can never be in use in the emulation path whilst it is being modified as the code that modifies always pauses the domain before doing so, so the assertion is that either v == current (in which case the domain is clearly not paused and we're in the emulation path) or !vcpu_runnable(v) (in which case the domain is paused and we're making a change).
Sure, but is there a risk of two different invocations of the "code that modifies" happening at the same time? (Perhaps, for instance, because of a buggy toolstack that makes two calls on the same ioreq server?)
-George
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
Quoted 83 lines
-----Original Message-----
From: George Dunlap [mailto:[email protected]]
Sent: 03 April 2014 16:49
To: Paul Durrant; George Dunlap
Cc: [email protected]; Keir (Xen.org); Jan Beulich
Subject: Re: [Xen-devel] [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.Quoted 9 lines · Paul Durrant
Quoted 9 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Dunlap
Sent: 03 April 2014 15:50
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org); Jan Beulich
Subject: Re: [Xen-devel] [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Paul Durrant
Collect together data structures concerning device emulation together
into
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
a new struct
hvm_ioreq_server.Code that deals with the shared and buffered ioreq pages is extracted
from
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
functions such as
hvm_domain_initialise,hvm_vcpu_initialiseand
do_hvm_opQuoted 1 line
and consolidated into a set of
hvm_ioreq_servermanipulation functions.The
Quoted 1 line
lock in the
hvm_ioreq_pageserved two different purposes and hasbeen
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
replaced by separate locks in the
hvm_ioreq_server.Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>--- xen/arch/x86/hvm/hvm.c | 406++++++++++++++++++++++++++----
Quoted 20 lines
Quoted 20 lines
--------
Quoted 19 lines
xen/include/asm-x86/hvm/domain.h | 35 +++- xen/include/asm-x86/hvm/vcpu.h | 12 +- 3 files changed, 322 insertions(+), 131 deletions(-)xen/arch/x86/hvm/hvm.c +2
-3@@ -352,39 +352,49 @@ void hvm_migrate_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } -static ioreq_t *get_ioreq (struct vcpu *v) +static ioreq_t *get_ioreq (struct hvm_ioreq_server *s,struct vcpu *v) { -struct domain *d = v->domain; -shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; +shared_iopage_t *p = s->ioreq.va;Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/hvm.c void hvm_migrate_pirqs(struct vcpu *v) · line 363
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +5
-1-ASSERT ((v == current) ||spin_is_locked (&d- arch.hvm_domain.ioreq.lock)); +/* +* Manipulation of the shared ioreq structure (to update the event +* channel) is protected by a domain_pause(). So this function should +* only ever be executed for the current vcpu or one that is paused. +*/ What on earth is "manipulation of the shared ioreq structure is protected by
domain_pause()" supposed to mean? Do you mean thatthe
Quoted 7 lines
Quoted 6 lines
only time there may be a race is between something in the emulation code writing to it, and something in the resume path reading it? That there are never any other races to access the structure? And that since the resume path won't be taken when the domain is paused, there can be no races, and therefore we do not need to be locked?
The sentiment I'm trying to express is that the shared structure can never
be in use in the emulation path whilst it is being modified as the code that modifies always pauses the domain before doing so, so the assertion is that either v == current (in which case the domain is clearly not paused and we're in the emulation path) or !vcpu_runnable(v) (in which case the domain is paused and we're making a change).
Quoted 4 lines
Sure, but is there a risk of two different invocations of the "code that modifies" happening at the same time? (Perhaps, for instance, because of a buggy toolstack that makes two calls on the same ioreq server?)
No, hvm_ioreq_server->lock prevents that. (See comment in structure definition).
Paul
Quoted 1 line
-George
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
In reply to Paul DurrantQuoted 4 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +3
-0+static int hvm_ioreq_server_add_vcpu (struct hvm_ioreq_server *s, +struct vcpu *v) +{
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 577
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+struct hvm_ioreq_vcpu *sv; +int rc; + +spin_lock (&s->lock); + + sv = xzalloc(struct hvm_ioreq_vcpu); + + rc = -ENOMEM ; +if ( !sv ) + goto fail1;
I don't see why this allocation needs to be done with the lock already held. For the other (event channel) allocations further down I would also prefer if you allocated them without holding the lock yet, even if that means freeing the per-domain one if you find it already set.
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 586
Quoted 9 lines
xen/arch/x86/hvm/hvm.c +9
-0+ + rc =alloc_unbound_xen_event_channel (v, s->domid,NULL ); +if ( rc <0 ) + goto fail2; + + sv->ioreq_evtchn = rc; + +if ( v->vcpu_id ==0 ) + {
I generally dislike needless dependencies on vCPU 0 being the first one to make it into any specific function. Can't you check emptiness of s->ioreq_vcpu_list instead?
Quoted 15 lines
xen/arch/x86/hvm/hvm.c +15
-0+static void hvm_ioreq_server_remove_vcpu (struct hvm_ioreq_server *s, +struct vcpu *v) +{ +struct list_head *entry; + +spin_lock (&s->lock); + + list_for_each ( entry, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); + +if ( sv->vcpu != v ) +continue ;
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 642
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+ +list_del_init (&sv->list_entry); + +if ( v->vcpu_id ==0 ) +free_xen_event_channel (v, s->bufioreq_evtchn); + +free_xen_event_channel (v, sv->ioreq_evtchn); + +xfree (sv); +break ;
Similar comments as above: Try to avoid depending on vCPU 0 being the last one to be cleaned up (I'm not even certain this is the case), and try freeing stuff with the lock already dropped.
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 686
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+static int hvm_set_ioreq_pfn (struct domain *d,bool_t buf, +unsigned long pfn) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; +int rc; + +spin_lock (&s->lock); + + rc =hvm_map_ioreq_page (d, iorp, pfn);
While I realize that at this point there's only one server per domain, the locking and operation still look to be out of sync at the first
glance: As this can't remain that way anyway till the end of the series, can't this be brought back in sync here right away (whether that's by passing s instead of d into the function or acquiring the lock only after the call I don't know offhand)?
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 690
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +4
-0+if ( rc ) + goto fail; + +if (!buf) {
Coding style.
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 717
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +7
-0+static int hvm_replace_event_channel (struct vcpu *v,domid_t remote_domid, +evtchn_port_t *p_port) +{ +evtchn_port_t old_port, new_port; + + new_port =alloc_unbound_xen_event_channel (v, remote_domid,NULL ); +if ( new_port <0 )
evtchn_port_t is an unsigned type, so this check won't work.
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 732
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +7
-0+static int hvm_set_dm_domain (struct domain *d,domid_t domid) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +int rc =0 ; + +spin_lock (&s->lock); +domain_pause (d);
The other way around perhaps?
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 734
Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2
-0+ +if ( s->domid != domid ) {
Coding style again.
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 744
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+struct list_head *entry; + + list_for_each ( entry, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); +struct vcpu *v = sv->vcpu; + +if ( v->vcpu_id ==0 ) {
And again; won't make further remarks to this effect.
Quoted 3 lines
int
hvm_domain_initialise(struct domain *d)
{
+domid_tdomid;
Do you really need this new variable, being used just once? (There is at least one more similar case elsewhere.)
xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v) · line 1553
Quoted 12 lines
(quoted diff) +0
-0@@ -1339,30 +1549,10 @@ int hvm_vcpu_initialise(struct vcpu *v) && (rc = nestedhvm_vcpu_initialise(v)) < 0 ) /* teardown:
nestedhvm_vcpu_destroy*/goto fail5;xen/arch/x86/hvm/hvm.c +2
-5- dm_domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; - -/* Create ioreq event channel. */ - rc =alloc_unbound_xen_event_channel (v, dm_domid,NULL );/* teardown: none */ -if ( rc <0 ) + rc =hvm_ioreq_server_add_vcpu (s, v); +if ( rc !=0 )
Can this really be > 0 now, and if so is this being handled correctly in the caller(s)?
Jan
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
Quoted 19 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 07 April 2014 12:37
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +10
-0+static int hvm_ioreq_server_add_vcpu (struct hvm_ioreq_server *s, +struct vcpu *v) +{ +struct hvm_ioreq_vcpu *sv; +int rc; + +spin_lock (&s->lock); + + sv = xzalloc(struct hvm_ioreq_vcpu); +
Quoted 9 lines
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 577
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +3
-0+ rc = -ENOMEM ; +if ( !sv ) + goto fail1;I don't see why this allocation needs to be done with the lock already held. For the other (event channel) allocations further down I would also prefer if you allocated them without holding the lock yet, even if that means freeing the per-domain one if you find it already set.
Ok.
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +5
-0+ + rc =alloc_unbound_xen_event_channel (v, s->domid,NULL ); +if ( rc <0 ) + goto fail2; +
Quoted 9 lines
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 586
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +4
-0+ sv->ioreq_evtchn = rc; + +if ( v->vcpu_id ==0 ) + {I generally dislike needless dependencies on vCPU 0 being the first one to make it into any specific function. Can't you check emptiness of
s->ioreq_vcpu_listinstead?
That will need a bit more code. I could create the buffered channel on first cpu addition but, I'd then need to track which cpu that was and re-plumb the event channel if that cpu disappears. Also, the default server has always bound the buffered channel to cpu 0 so would I not risk a compatibility issue by changing this?
Quoted 39 lines
Quoted 15 lines
xen/arch/x86/hvm/hvm.c +15
-0+static void hvm_ioreq_server_remove_vcpu (struct hvm_ioreq_server *s, +struct vcpu *v) +{ +struct list_head *entry; + +spin_lock (&s->lock); + + list_for_each ( entry, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); + +if ( sv->vcpu != v ) +continue ;xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 642
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+ +list_del_init (&sv->list_entry); + +if ( v->vcpu_id ==0 ) +free_xen_event_channel (v, s->bufioreq_evtchn); + +free_xen_event_channel (v, sv->ioreq_evtchn); + +xfree (sv); +break ;Similar comments as above: Try to avoid depending on vCPU 0 being the last one to be cleaned up (I'm not even certain this is the case), and try freeing stuff with the lock already dropped.
Quoted 9 lines
xen/arch/x86/hvm/hvm.c +9
-0+static int hvm_set_ioreq_pfn (struct domain *d,bool_t buf, +unsigned long pfn) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; +int rc; + +spin_lock (&s->lock); +
Quoted 8 lines
Quoted 1 line
+ rc =
hvm_map_ioreq_page(d, iorp, pfn);While I realize that at this point there's only one server per domain, the locking and operation still look to be out of sync at the first
glance: As this can't remain that way anyway till the end of the series, can't this be brought back in sync here right away (whether that's by passing s instead of d into the function or acquiring the lock only after the call I don't know offhand)?
I don't follow what you mean by 'out of sync' here: The lock is taken, the pfn is mapped, the lock is dropped. What am I missing?
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 690
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +4
-0+if ( rc ) + goto fail; + +if (!buf) {Coding style.
Ok.
Quoted 8 lines
Quoted 1 line
+static int hvm_replace_event_channel(struct vcpu *v,
domid_t
remote_domid,xen/arch/x86/hvm/hvm.c static int handle_pvh_io(
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +5
-0+ evtchn_port_t *p_port) +{ +evtchn_port_t old_port, new_port; + + new_port = alloc_unbound_xen_event_channel(v, remote_domid,NULL);
Quoted 4 lines
Quoted 1 line
+ if (
new_port< 0 )
evtchn_port_tis an unsigned type, so this check won't work.
Yes, it should be an int. Over-zealous type cleanup.
Quoted 9 lines
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 732
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +7
-0+static int hvm_set_dm_domain (struct domain *d,domid_t domid) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +int rc =0 ; + +spin_lock (&s->lock); +domain_pause (d);The other way around perhaps?
Yes.
Quoted 19 lines
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 734
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +2
-0+ +if ( s->domid != domid ) {Coding style again.
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 744
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+struct list_head *entry; + + list_for_each ( entry, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); +struct vcpu *v = sv->vcpu; + +if ( v->vcpu_id ==0 ) {And again; won't make further remarks to this effect.
Quoted 6 lines
Quoted 3 lines
int
hvm_domain_initialise(struct domain *d)
{
+domid_tdomid;Do you really need this new variable, being used just once? (There is at least one more similar case elsewhere.)
This is to avoid a line becoming very long.
Quoted 12 lines
xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v)
Quoted 11 lines
(quoted diff) +0
-0@@ -1339,30 +1549,10 @@ int hvm_vcpu_initialise(struct vcpu *v) && (rc = nestedhvm_vcpu_initialise(v)) < 0 ) /* teardown:
nestedhvm_vcpu_destroy*/goto fail5;-
dm_domid= d-
arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN];xen/arch/x86/hvm/hvm.c +0
-3- -/* Create ioreq event channel. */ - rc =alloc_unbound_xen_event_channel (v, dm_domid,NULL );/* teardown: none */
Quoted 6 lines
xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v) · line 1553
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +2
-1-if ( rc <0 ) + rc =hvm_ioreq_server_add_vcpu (s, v); +if ( rc !=0 )Can this really be > 0 now, and if so is this being handled correctly in the caller(s)?
It's not the same function being called. hvm_ioreq_server_add_vcpu () can only return 0 or a -ve errno. I can test for < 0 but IIRC you objected to doing that in a review of a previous patch if the function never returns > 0. Would you prefer 'if ( rc )'?
Paul
Quoted 2 lines
Jan
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
Quoted 18 lines
Quoted 17 lines
Quoted 1 line · On 08.04.14 at 11:32, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 586
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +9
-0+ + rc =alloc_unbound_xen_event_channel (v, s->domid,NULL ); +if ( rc <0 ) + goto fail2; + + sv->ioreq_evtchn = rc; + +if ( v->vcpu_id ==0 ) + {I generally dislike needless dependencies on vCPU 0 being the first one to make it into any specific function. Can't you check emptiness of
s->ioreq_vcpu_listinstead?
Quoted 5 lines
That will need a bit more code. I could create the buffered channel on first cpu addition but, I'd then need to track which cpu that was and re-plumb the event channel if that cpu disappears. Also, the default server has always bound the buffered channel to cpu 0 so would I not risk a compatibility issue by changing this?
Hmm, good point. Albeit I still wonder what would happen if vCPU 0 went away.
But yes, considering that this is code effectively getting moved here (i.e. having special cased vCPU 0 already before), I guess I withdraw my change request for now.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/hvm.c +9
-0+static int hvm_set_ioreq_pfn (struct domain *d,bool_t buf, +unsigned long pfn) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; +int rc; + +spin_lock (&s->lock); +Quoted 8 lines
Quoted 1 line
+ rc =
hvm_map_ioreq_page(d, iorp, pfn);While I realize that at this point there's only one server per domain, the locking and operation still look to be out of sync at the first
glance: As this can't remain that way anyway till the end of the series, can't this be brought back in sync here right away (whether that's by passing s instead of d into the function or acquiring the lock only after the call I don't know offhand)?
Quoted 2 lines
I don't follow what you mean by 'out of sync' here: The lock is taken, the pfn is mapped, the lock is dropped. What am I missing?
You lock "s" but operate on "d".
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v)
Quoted 10 lines
(quoted diff) +0
-0@@ -1339,30 +1549,10 @@ int hvm_vcpu_initialise(struct vcpu *v) && (rc = nestedhvm_vcpu_initialise(v)) < 0 ) /* teardown:
nestedhvm_vcpu_destroy*/goto fail5;-
dm_domid= d-
arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN];xen/arch/x86/hvm/hvm.c +0
-3- -/* Create ioreq event channel. */ - rc =alloc_unbound_xen_event_channel (v, dm_domid,NULL );/* teardown: none */
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +2
-1-if ( rc <0 ) + rc =hvm_ioreq_server_add_vcpu (s, v); +if ( rc !=0 )
Quoted 5 lines
Quoted 2 lines
Can this really be > 0 now, and if so is this being handled correctly in the caller(s)?
It's not the same function being called.
hvm_ioreq_server_add_vcpu() can only return 0 or a -ve errno.
Oh, sorry, didn't pay close enough attention.
Quoted 3 lines
I can test for < 0 but IIRC you objected to doing
that in a review of a previous patch if the function never returns > 0. Would you prefer 'if ( rc )'?
Yes, "if ( rc )" would seem better, but with the called function changing it doesn't really matter all that much.
Jan
Re: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.
Quoted 59 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 08 April 2014 10:47
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: RE: [PATCH v4 3/8] ioreq-server: create basic ioreq server abstraction.Quoted 18 lines
Quoted 17 lines
Quoted 1 line · On 08.04.14 at 11:32, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 586
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +9
-0+ + rc =alloc_unbound_xen_event_channel (v, s->domid,NULL ); +if ( rc <0 ) + goto fail2; + + sv->ioreq_evtchn = rc; + +if ( v->vcpu_id ==0 ) + {I generally dislike needless dependencies on vCPU 0 being the first one to make it into any specific function. Can't you check emptiness of
s->ioreq_vcpu_listinstead?Quoted 2 lines
That will need a bit more code. I could create the buffered channel on first cpu addition but, I'd then need to track which cpu that was and re-plumb
the
Quoted 2 lines
event channel if that cpu disappears. Also, the default server has always bound the buffered channel to cpu 0 so would I not risk a compatibility
issue
Quoted 1 line
by changing this?
Hmm, good point. Albeit I still wonder what would happen if vCPU 0 went away.
But yes, considering that this is code effectively getting moved here (i.e. having special cased vCPU 0 already before), I guess I withdraw my change request for now.
Quoted 18 lines
Quoted 17 lines
xen/arch/x86/hvm/hvm.c static int handle_pvh_io( · line 686
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+static int hvm_set_ioreq_pfn (struct domain *d,bool_t buf, +unsigned long pfn) +{ +struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; +int rc; + +spin_lock (&s->lock); + + rc =hvm_map_ioreq_page (d, iorp, pfn);While I realize that at this point there's only one server per domain, the locking and operation still look to be out of sync at the first
glance: As this can't remain that way anyway till the end of the series, can't this be brought back in sync here right away (whether that's by passing s instead of d into the function or acquiring the lock only after the call I don't know offhand)?
Quoted 4 lines
Quoted 2 lines
I don't follow what you mean by 'out of sync' here: The lock is taken, the pfn is mapped, the lock is dropped. What am I missing?
You lock "s" but operate on "d".
Ah, I see what you mean. I'll mod. the function to take s rather than d then.
Quoted 22 lines
Quoted 16 lines
Quoted 16 lines
xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v)
Quoted 11 lines
(quoted diff) +0
-0@@ -1339,30 +1549,10 @@ int hvm_vcpu_initialise(struct vcpu *v) && (rc = nestedhvm_vcpu_initialise(v)) < 0 ) /* teardown:
nestedhvm_vcpu_destroy*/goto fail5;-
dm_domid= d-
arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN];xen/arch/x86/hvm/hvm.c +0
-3- -/* Create ioreq event channel. */ - rc =alloc_unbound_xen_event_channel (v, dm_domid,NULL );/* teardown: none */
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +2
-1-if ( rc <0 ) + rc =hvm_ioreq_server_add_vcpu (s, v); +if ( rc !=0 )Quoted 5 lines
Quoted 2 lines
Can this really be > 0 now, and if so is this being handled correctly in the caller(s)?
It's not the same function being called.
hvm_ioreq_server_add_vcpu() can only return 0 or a -ve errno.
Quoted 8 lines
Oh, sorry, didn't pay close enough attention.
Quoted 3 lines
I can test for < 0 but IIRC you objected to doing
that in a review of a previous patch if the function never returns > 0. Would you prefer 'if ( rc )'?Yes, "if ( rc )" would seem better, but with the called function changing it doesn't really matter all that much.
Ok. I'll check for consistency with what I did elsewhere.
Paul
Quoted 2 lines
Jan
PATCH v4 4/8 ioreq-server: on-demand creation of ioreq server
In reply to Paul DurrantThis patch only creates the ioreq server when the legacy HVM parameters are read (by an emulator).
A lock is introduced to protect access to the ioreq server by multiple emulator/tool invocations should such an eventuality arise. The guest is protected by creation of the ioreq server only being done whilst the domain is paused.
--- xen/arch/x86/hvm/hvm.c | 262 +++++++++++++++++++++++++++++++------- xen/include/asm-x86/hvm/domain.h | 1 + 2 files changed, 215 insertions(+), 48 deletions(-)
xen/arch/x86/hvm/hvm.c +214 -48
@@ -383,40 +383,38 @@ void hvm_do_resume(struct vcpu *v) {struct domain *d = v->domain;struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; -ioreq_t *p;check_wakeup_from_wait ();if (is_hvm_vcpu (v) )pt_restore_timer (v); -if ( !s ) - goto check_inject_trap; - -/* NB. Optimised for common case (p->state == STATE_IOREQ_NONE). */ - p =get_ioreq (s, v); -while ( p->state !=STATE_IOREQ_NONE ) +if ( s ) { -switch ( p->state ) +ioreq_t *p =get_ioreq (s, v); + +while ( p->state !=STATE_IOREQ_NONE ) { -case STATE_IORESP_READY :/* IORESP_READY -> NONE */ -rmb ();/* see IORESP_READY /then/ read contents of ioreq */ -hvm_io_assist (p); -break ; -case STATE_IOREQ_READY :/* IOREQ_{READY,INPROCESS} -> IORESP_READY */ -case STATE_IOREQ_INPROCESS : -wait_on_xen_event_channel (p->vp_eport, - (p->state !=STATE_IOREQ_READY ) && - (p->state !=STATE_IOREQ_INPROCESS )); -break ; -default : -gdprintk (XENLOG_ERR ,"Weird HVM iorequest state %d.\n" , p->state); -domain_crash (v->domain); -return ;/* bail */ +switch ( p->state ) + { +case STATE_IORESP_READY :/* IORESP_READY -> NONE */ +rmb ();/* see IORESP_READY /then/ read contents of ioreq */ +hvm_io_assist (p); +break ; +case STATE_IOREQ_READY :/* IOREQ_{READY,INPROCESS} -> IORESP_READY */ +case STATE_IOREQ_INPROCESS : +wait_on_xen_event_channel (p->vp_eport, + (p->state !=STATE_IOREQ_READY ) && + (p->state !=STATE_IOREQ_INPROCESS )); +break ; +default : +gdprintk (XENLOG_ERR ,"Weird HVM iorequest state %d.\n" , p->state); +domain_crash (d); +return ;/* bail */ + } } } - check_inject_trap:/* Inject pending hw/sw trap */ if ( v->arch.hvm_vcpu.inject_trap.vector !=-1 ) {
@@ -645,13 +643,68 @@ static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s,spin_unlock (&s->lock); } -static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +static void hvm_ioreq_server_remove_all_vcpus (struct hvm_ioreq_server *s) { -struct hvm_ioreq_server *s; +struct list_head *entry, *next; - s = xzalloc(struct hvm_ioreq_server); -if ( !s ) -return -ENOMEM ; +spin_lock (&s->lock); + + list_for_each_safe ( entry, next, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry); +struct vcpu *v = sv->vcpu; + +list_del_init (&sv->list_entry); + +if ( v->vcpu_id ==0 ) +free_xen_event_channel (v, s->bufioreq_evtchn); + +free_xen_event_channel (v, sv->ioreq_evtchn); + +xfree (sv); + } + +spin_unlock (&s->lock); +} + +static int hvm_ioreq_server_map_pages (struct hvm_ioreq_server *s) +{ +struct domain *d = s->domain; +unsigned long pfn; +int rc; + + pfn = d->arch.hvm_domain.params[HVM_PARAM_IOREQ_PFN ]; + rc =hvm_map_ioreq_page (d, &s->ioreq, pfn); +if ( rc ) + goto fail1; + + pfn = d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN ]; + rc =hvm_map_ioreq_page (d, &s->bufioreq, pfn); +if ( rc ) + goto fail2; + +return 0 ; + +fail2: +hvm_unmap_ioreq_page (&s->ioreq); + +fail1: +return rc; +} + +static void hvm_ioreq_server_unmap_pages (struct hvm_ioreq_server *s) +{ +hvm_unmap_ioreq_page (&s->bufioreq); +hvm_unmap_ioreq_page (&s->ioreq); +} + +static int hvm_ioreq_server_init (struct hvm_ioreq_server *s,struct domain *d, +domid_t domid) +{ +struct vcpu *v; +int rc; s->domain = d; s->domid = domid;
@@ -660,29 +713,112 @@ static int hvm_create_ioreq_server(struct domain *d, domid_t domid)INIT_LIST_HEAD (&s->ioreq_vcpu_list);spin_lock_init (&s->bufioreq_lock); + rc =hvm_ioreq_server_map_pages (s); +if ( rc ) +return rc; + + for_each_vcpu ( d, v ) + { + rc =hvm_ioreq_server_add_vcpu (s, v); +if ( rc ) + goto fail; + } + +return 0 ; + + fail: +hvm_ioreq_server_remove_all_vcpus (s); +hvm_ioreq_server_unmap_pages (s); + +return rc; +} + +static void hvm_ioreq_server_deinit (struct hvm_ioreq_server *s) +{ +hvm_ioreq_server_remove_all_vcpus (s); +hvm_ioreq_server_unmap_pages (s); +} + +static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +{ +struct hvm_ioreq_server *s; +int rc; + +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + rc = -EEXIST ; +if ( d->arch.hvm_domain.ioreq_server !=NULL ) + goto fail1; + + rc = -ENOMEM ; + s = xzalloc(struct hvm_ioreq_server); +if ( !s ) + goto fail2; + +domain_pause (d); + + rc =hvm_ioreq_server_init (s, d, domid); +if ( rc ) + goto fail3; + d->arch.hvm_domain.ioreq_server = s; + +domain_unpause (d); + +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock);return 0 ; + + fail3: +domain_unpause (d); + +xfree (s); + + fail2: + fail1: +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock); +return rc; }static void hvm_destroy_ioreq_server (struct domain *d) { -struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_server *s; -hvm_unmap_ioreq_page (&s->bufioreq); -hvm_unmap_ioreq_page (&s->ioreq); +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + s = d->arch.hvm_domain.ioreq_server; +if ( !s ) + goto done; + + d->arch.hvm_domain.ioreq_server =NULL ; + +domain_pause (d); + +hvm_ioreq_server_deinit (s); + +domain_unpause (d);xfree (s); + + done: +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock); }static int hvm_set_ioreq_pfn (struct domain *d,bool_t buf,unsigned long pfn) { -struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; -struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; +struct hvm_ioreq_server *s; +struct hvm_ioreq_page *iorp;int rc; +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + s = d->arch.hvm_domain.ioreq_server; +if ( !s ) + goto done; +spin_lock (&s->lock); + iorp = buf ? &s->bufioreq : &s->ioreq; rc =hvm_map_ioreq_page (d, iorp, pfn);if ( rc ) goto fail;
@@ -701,10 +837,14 @@ static int hvm_set_ioreq_pfn(struct domain *d, bool_t buf, }spin_unlock (&s->lock); + + done: +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock);return 0 ; fail:spin_unlock (&s->lock); +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock);return rc; }
@@ -725,9 +865,15 @@ static int hvm_replace_event_channel(struct vcpu *v, domid_t remote_domid,static int hvm_set_dm_domain (struct domain *d,domid_t domid) { -struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_server *s;int rc =0 ; +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + s = d->arch.hvm_domain.ioreq_server; +if ( !s ) + goto done; +spin_lock (&s->lock);domain_pause (d);
@@ -764,12 +910,13 @@ static int hvm_set_dm_domain(struct domain *d, domid_t domid)domain_unpause (d);spin_unlock (&s->lock); + done: +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock);return rc; }int hvm_domain_initialise (struct domain *d) { -domid_t domid;int rc;if ( !hvm_enabled )
@@ -795,6 +942,7 @@ int hvm_domain_initialise(struct domain *d) } +spin_lock_init (&d->arch.hvm_domain.ioreq_server_lock);spin_lock_init (&d->arch.hvm_domain.irq_lock);spin_lock_init (&d->arch.hvm_domain.uc_lock);
@@ -835,21 +983,14 @@ int hvm_domain_initialise(struct domain *d)rtc_init (d); - domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; - rc =hvm_create_ioreq_server (d, domid); -if ( rc !=0 ) - goto fail2; -register_portio_handler (d,0xe9 ,1 , hvm_print_line); rc = hvm_funcs.domain_initialise (d);if ( rc !=0 ) - goto fail3; + goto fail2;return 0 ; - fail3: -hvm_destroy_ioreq_server (d); fail2:rtc_deinit (d);stdvga_deinit (d);
@@ -1506,7 +1647,7 @@ int hvm_vcpu_initialise(struct vcpu *v) {int rc;struct domain *d = v->domain; -struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_server *s;hvm_asid_flush_vcpu (v);
@@ -1549,7 +1690,14 @@ int hvm_vcpu_initialise(struct vcpu *v) && (rc = nestedhvm_vcpu_initialise(v)) < 0 ) /* teardown: nestedhvm_vcpu_destroy */ goto fail5; - rc =hvm_ioreq_server_add_vcpu (s, v); +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + s = d->arch.hvm_domain.ioreq_server; +if ( s ) + rc =hvm_ioreq_server_add_vcpu (s, v); + +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock); +if ( rc !=0 ) goto fail6;
@@ -1586,9 +1734,15 @@ int hvm_vcpu_initialise(struct vcpu *v)void hvm_vcpu_destroy (struct vcpu *v) {struct domain *d = v->domain; -struct hvm_ioreq_server *s = d->arch.hvm_domain.ioreq_server; +struct hvm_ioreq_server *s; + +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + s = d->arch.hvm_domain.ioreq_server; +if ( s ) +hvm_ioreq_server_remove_vcpu (s, v); -hvm_ioreq_server_remove_vcpu (s, v); +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock);nestedhvm_vcpu_destroy (v);
@@ -4464,7 +4618,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)domctl_lock_release ();break ;case HVM_PARAM_DM_DOMAIN : -/* Not reflexive, as we must domain_pause(). */ +/* Not reflexive, as we may need to domain_pause(). */ rc = -EPERM ;if ( curr_d == d )break ;
@@ -4570,6 +4724,18 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)case HVM_PARAM_ACPI_S_STATE : a.value = d->arch.hvm_domain.is_s3_suspended ?3 :0 ;break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_BUFIOREQ_EVTCHN : { +domid_t domid; + +/* May need to create server */ + domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; + rc =hvm_create_ioreq_server (d, domid); +if ( rc !=0 && rc != -EEXIST ) + goto param_fail; +/*FALLTHRU*/ + }default : a.value = d->arch.hvm_domain.params[a.index];break ;
xen/include/asm-x86/hvm/domain.h +1 -0
@@ -63,6 +63,7 @@ struct hvm_ioreq_server { };struct hvm_domain { +spinlock_t ioreq_server_lock;struct hvm_ioreq_server *ioreq_server;struct pl_time pl_time;
Signature · 1 line
1.7.10.4
Re: [PATCH v4 4/8] ioreq-server: on-demand creation of ioreq server
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2
-2@@ -645,13 +643,68 @@ static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s,spin_unlock (&s->lock); } -static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +static void hvm_ioreq_server_remove_all_vcpus (struct hvm_ioreq_server *s) { -struct hvm_ioreq_server *s; +struct list_head *entry, *next;
xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s, · line 656
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +7
-3- s = xzalloc(struct hvm_ioreq_server); -if ( !s ) -return -ENOMEM ; +spin_lock (&s->lock); + + list_for_each_safe ( entry, next, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry);
list_for_each_entry_safe() avoids the need for the explicit use of container_of(), making the code easier to read.
xen/arch/x86/hvm/hvm.c static int hvm_create_ioreq_server(struct domain *d, domid_t domid) · line 754
Quoted 13 lines
xen/arch/x86/hvm/hvm.c +13
-0+static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +{ +struct hvm_ioreq_server *s; +int rc; + +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + rc = -EEXIST ; +if ( d->arch.hvm_domain.ioreq_server !=NULL ) + goto fail1; + + rc = -ENOMEM ; + s = xzalloc(struct hvm_ioreq_server);
Similar comment as on an earlier patch: Please try to avoid allocations with lock held.
xen/arch/x86/hvm/hvm.c static int hvm_create_ioreq_server(struct domain *d, domid_t domid) · line 758
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +4
-0+if ( !s ) + goto fail2; + +domain_pause (d);
And with that adjusted I would then again wonder whether taking the lock after pausing the domain wouldn't be the better model.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 4734
Quoted 12 lines
xen/arch/x86/hvm/hvm.c +8
-0@@ -4570,6 +4724,18 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)case HVM_PARAM_ACPI_S_STATE : a.value = d->arch.hvm_domain.is_s3_suspended ?3 :0 ;break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_BUFIOREQ_EVTCHN : { +domid_t domid; + +/* May need to create server */ + domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; + rc =hvm_create_ioreq_server (d, domid);
Pretty odd that you do this on reads, but not on writes. What's the rationale behind this?
Jan
Re: [PATCH v4 4/8] ioreq-server: on-demand creation of ioreq server
Quoted 32 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 07 April 2014 12:51
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH v4 4/8] ioreq-server: on-demand creation of ioreq serverReview static void
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
(quoted diff) +0
-0@@ -645,13 +643,68 @@ static voidhvm_ioreq_server_remove_vcpu(struct
hvm_ioreq_server*s,xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s,
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1
-1spin_unlock (&s->lock); } -static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +static void hvm_ioreq_server_remove_all_vcpus(struct
hvm_ioreq_server*s)Quoted 4 lines
xen/arch/x86/hvm/hvm.c +1
-1{ -struct hvm_ioreq_server *s; +struct list_head *entry, *next;xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s, · line 656
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +7
-3- s = xzalloc(struct hvm_ioreq_server); -if ( !s ) -return -ENOMEM ; +spin_lock (&s->lock); + + list_for_each_safe ( entry, next, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry);
Quoted 3 lines
list_for_each_entry_safe()avoids the need for the explicit use ofcontainer_of(), making the code easier to read.
It also expands the scope of sv.
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/hvm/hvm.c +8
-0+static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +{ +struct hvm_ioreq_server *s; +int rc; + +spin_lock (&d->arch.hvm_domain.ioreq_server_lock); + + rc = -EEXIST ;
Quoted 9 lines
xen/arch/x86/hvm/hvm.c static int hvm_create_ioreq_server(struct domain *d, domid_t domid) · line 754
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +5
-0+if ( d->arch.hvm_domain.ioreq_server !=NULL ) + goto fail1; + + rc = -ENOMEM ; + s = xzalloc(struct hvm_ioreq_server);Similar comment as on an earlier patch: Please try to avoid allocations with lock held.
Ok.
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int hvm_create_ioreq_server(struct domain *d, domid_t domid) · line 758
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +4
-0+if ( !s ) + goto fail2; + +domain_pause (d);And with that adjusted I would then again wonder whether taking the lock after pausing the domain wouldn't be the better model.
Yes, it would.
Quoted 15 lines
Review long do_hvm_op(unsigned long op,
Quoted 1 line
(quoted diff) +0
-0@@ -4570,6 +4724,18 @@ long do_hvm_op(unsigned long op,
XEN_GUEST_HANDLE_PARAM(void)arg)xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 4734
Quoted 12 lines
xen/arch/x86/hvm/hvm.c +8
-0case HVM_PARAM_ACPI_S_STATE : a.value = d->arch.hvm_domain.is_s3_suspended ?3 :0 ;break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_BUFIOREQ_EVTCHN : { +domid_t domid; + +/* May need to create server */ + domid = d- arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; + rc =hvm_create_ioreq_server (d, domid);
Quoted 3 lines
Pretty odd that you do this on reads, but not on writes. What's the rationale behind this?
The default server does not actually need to be there until something (i.e. QEMU) looks for it by reading one of these params. In future I hope that QEMU can be modified to use the explicit ioreq server creation API and we can eventually drop the default server.
Paul
Quoted 1 line
Jan
Re: [PATCH v4 4/8] ioreq-server: on-demand creation of ioreq server
Quoted 28 lines
Quoted 13 lines
Quoted 1 line · On 08.04.14 at 11:35, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2
-2@@ -645,13 +643,68 @@ static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s,spin_unlock (&s->lock); } -static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +static void hvm_ioreq_server_remove_all_vcpus (struct hvm_ioreq_server *s) { -struct hvm_ioreq_server *s; +struct list_head *entry, *next;Quoted 14 lines
xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s, · line 656
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +7
-3- s = xzalloc(struct hvm_ioreq_server); -if ( !s ) -return -ENOMEM ; +spin_lock (&s->lock); + + list_for_each_safe ( entry, next, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry);
list_for_each_entry_safe()avoids the need for the explicit use ofcontainer_of(), making the code easier to read.
Quoted 1 line
It also expands the scope of sv.
Which does no harm afaict. "entry" (which effectively is "sv") has the same wider scope already.
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +3
-0@@ -4570,6 +4724,18 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)case HVM_PARAM_ACPI_S_STATE : a.value = d->arch.hvm_domain.is_s3_suspended ?3 :0 ;break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_BUFIOREQ_EVTCHN : {Quoted 9 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 4734
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +5
-0+domid_t domid; + +/* May need to create server */ + domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; + rc =hvm_create_ioreq_server (d, domid);Pretty odd that you do this on reads, but not on writes. What's the rationale behind this?
Quoted 4 lines
The default server does not actually need to be there until something (i.e. QEMU) looks for it by reading one of these params. In future I hope that QEMU can be modified to use the explicit ioreq server creation API and we can eventually drop the default server.
Oh, okay - the writer of these values just drops them in without caring what Xen (or another consumer) does with them?
Jan
Re: [PATCH v4 4/8] ioreq-server: on-demand creation of ioreq server
Quoted 61 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 08 April 2014 10:51
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: RE: [PATCH v4 4/8] ioreq-server: on-demand creation of ioreq serverQuoted 4 lines
Quoted 4 lines
Quoted 1 line · On 08.04.14 at 11:35, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Review static void
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
(quoted diff) +0
-0@@ -645,13 +643,68 @@ static voidhvm_ioreq_server_remove_vcpu(struct
hvm_ioreq_server*s,Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_remove_vcpu(struct hvm_ioreq_server *s,
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1
-1spin_unlock (&s->lock); } -static int hvm_create_ioreq_server (struct domain *d,domid_t domid) +static void hvm_ioreq_server_remove_all_vcpus(struct
hvm_ioreq_server*s)Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
xen/arch/x86/hvm/hvm.c +8
-4{ -struct hvm_ioreq_server *s; +struct list_head *entry, *next; - s = xzalloc(struct hvm_ioreq_server); -if ( !s ) -return -ENOMEM ; +spin_lock (&s->lock); + + list_for_each_safe ( entry, next, &s->ioreq_vcpu_list ) + { +struct hvm_ioreq_vcpu *sv =container_of (entry, + struct hvm_ioreq_vcpu, + list_entry);Quoted 5 lines
Quoted 3 lines
list_for_each_entry_safe()avoids the need for the explicit use ofcontainer_of(), making the code easier to read.It also expands the scope of sv.
Which does no harm afaict. "entry" (which effectively is "sv") has the same wider scope already.
Quoted 1 line
Quoted 1 line
Review long do_hvm_op(unsigned long op,
Quoted 1 line
(quoted diff) +0
-0@@ -4570,6 +4724,18 @@ long do_hvm_op(unsigned long op,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 17 lines
Quoted 10 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +7
-0case HVM_PARAM_ACPI_S_STATE : a.value = d->arch.hvm_domain.is_s3_suspended ?3 :0 ;break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_BUFIOREQ_EVTCHN : { +domid_t domid; + +/* May need to create server */ + domid = d-arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN];
Quoted 5 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 4734
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+ rc =hvm_create_ioreq_server (d, domid);Pretty odd that you do this on reads, but not on writes. What's the rationale behind this?
Quoted 9 lines
Quoted 2 lines
The default server does not actually need to be there until something (i.e. QEMU) looks for it by reading one of these params. In future I hope that
QEMU
Quoted 2 lines
can be modified to use the explicit ioreq server creation API and we can eventually drop the default server.
Oh, okay - the writer of these values just drops them in without caring what Xen (or another consumer) does with them?
Yes, that's right. setup_guest() in xc_hvm_build_x86.c writes the pfns in , along with the other specials (like store, etc.). In the case of these, nothing actually needs to happen until QEMU goes looking for what the tools wrote.
Paul
Quoted 1 line
Jan
PATCH v4 5/8 ioreq-server: add support for multiple servers
In reply to Paul DurrantThe previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change the API.
--- tools/libxc/xc_domain.c | 175 +++++++ tools/libxc/xc_domain_restore.c | 27 + tools/libxc/xc_domain_save.c | 24 + tools/libxc/xc_hvm_build_x86.c | 30 +- tools/libxc/xenctrl.h | 52 ++ tools/libxc/xg_save_restore.h | 2 + xen/arch/x86/hvm/hvm.c | 1035 +++++++++++++++++++++++++++++++++++--- xen/arch/x86/hvm/io.c | 2 +- xen/include/asm-x86/hvm/domain.h | 34 +- xen/include/asm-x86/hvm/hvm.h | 3 +- xen/include/asm-x86/hvm/io.h | 2 +- xen/include/public/hvm/hvm_op.h | 70 +++ xen/include/public/hvm/ioreq.h | 1 + xen/include/public/hvm/params.h | 5 +- 14 files changed, 1383 insertions(+), 79 deletions(-)
tools/libxc/xc_domain.c +175 -0
@@ -1284,6 +1284,181 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned longreturn rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + rc =do_xen_hypercall (xch, &hypercall); + *id = arg->id; +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_get_ioreq_server_info (xc_interface *xch, +domid_t domid, +ioservid_t id, +xen_pfn_t *ioreq_pfn, +xen_pfn_t *bufioreq_pfn, +evtchn_port_t *bufioreq_port) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_get_ioreq_server_info_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_get_ioreq_server_info; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + rc =do_xen_hypercall (xch, &hypercall); +if ( rc !=0 ) + goto done; + +if ( ioreq_pfn ) + *ioreq_pfn = arg->ioreq_pfn; + +if ( bufioreq_pfn ) + *bufioreq_pfn = arg->bufioreq_pfn; + +if ( bufioreq_port ) + *bufioreq_port = arg->bufioreq_port; + +done: +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_map_io_range_to_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,int is_mmio, +uint64_t start,uint64_t end) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_map_io_range_to_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_map_io_range_to_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->is_mmio = is_mmio; + arg->start = start; + arg->end = end; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_unmap_io_range_from_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,int is_mmio, +uint64_t start) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_unmap_io_range_from_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_unmap_io_range_from_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->is_mmio = is_mmio; + arg->start = start; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_map_pcidev_to_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,uint16_t bdf) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_map_pcidev_to_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_map_pcidev_to_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->bdf = bdf; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_unmap_pcidev_from_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,uint16_t bdf) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_unmap_pcidev_from_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_unmap_pcidev_from_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->bdf = bdf; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_destroy_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_destroy_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_destroy_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +} +int xc_domain_setdebugging (xc_interface *xch,uint32_t domid,unsigned int enable)
tools/libxc/xc_domain_restore.c +27 -0
@@ -740,6 +740,8 @@ typedef struct {uint64_t acpi_ioport_location;uint64_t viridian;uint64_t vm_generationid_addr; +uint64_t ioreq_server_pfn; +uint64_t nr_ioreq_server_pages;struct toolstack_data_t tdata; } pagebuf_t;
@@ -990,6 +992,26 @@ static int pagebuf_get_one(xc_interface *xch, struct restore_ctx *ctx,DPRINTF ("read generation id buffer address" );return pagebuf_get_one (xch, ctx, buf, fd, dom); +case XC_SAVE_ID_HVM_IOREQ_SERVER_PFN : +/* Skip padding 4 bytes then read the ioreq server gmfn base. */ +if (RDEXACT (fd, &buf->ioreq_server_pfn,sizeof (uint32_t )) || +RDEXACT (fd, &buf->ioreq_server_pfn,sizeof (uint64_t )) ) + { +PERROR ("error read the ioreq server gmfn base" ); +return -1 ; + } +return pagebuf_get_one (xch, ctx, buf, fd, dom); + +case XC_SAVE_ID_HVM_NR_IOREQ_SERVER_PAGES : +/* Skip padding 4 bytes then read the ioreq server gmfn count. */ +if (RDEXACT (fd, &buf->nr_ioreq_server_pages,sizeof (uint32_t )) || +RDEXACT (fd, &buf->nr_ioreq_server_pages,sizeof (uint64_t )) ) + { +PERROR ("error read the ioreq server gmfn count" ); +return -1 ; + } +return pagebuf_get_one (xch, ctx, buf, fd, dom); +default :if ( (count >MAX_BATCH_SIZE ) || (count <0 ) ) {ERROR ("Max batch size exceeded (%d). Giving up." , count);
@@ -1748,6 +1770,11 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,if (pagebuf.viridian !=0 )xc_set_hvm_param (xch, dom,HVM_PARAM_VIRIDIAN ,1 ); +xc_set_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , + pagebuf.ioreq_server_pfn); +xc_set_hvm_param (xch, dom,HVM_PARAM_NR_IOREQ_SERVER_PAGES , + pagebuf.nr_ioreq_server_pages); +if (pagebuf.acpi_ioport_location ==1 ) {DBGPRINTF ("Use new firmware ioport from the checkpoint\n" );xc_set_hvm_param (xch, dom,HVM_PARAM_ACPI_IOPORTS_LOCATION ,1 );
tools/libxc/xc_domain_save.c +24 -0
@@ -1737,6 +1737,30 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterPERROR ("Error when writing the viridian flag" ); goto out; } + + chunk.id =XC_SAVE_ID_HVM_IOREQ_SERVER_PFN ; + chunk.data =0 ; +xc_get_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , + (unsigned long *)&chunk.data); + +if ( (chunk.data !=0 ) && +wrexact (io_fd, &chunk,sizeof (chunk)) ) + { +PERROR ("Error when writing the ioreq server gmfn base" ); + goto out; + } + + chunk.id =XC_SAVE_ID_HVM_NR_IOREQ_SERVER_PAGES ; + chunk.data =0 ; +xc_get_hvm_param (xch, dom,HVM_PARAM_NR_IOREQ_SERVER_PAGES , + (unsigned long *)&chunk.data); + +if ( (chunk.data !=0 ) && +wrexact (io_fd, &chunk,sizeof (chunk)) ) + { +PERROR ("Error when writing the ioreq server gmfn count" ); + goto out; + } }if ( callbacks !=NULL && callbacks->toolstack_save !=NULL )
tools/libxc/xc_hvm_build_x86.c +29 -1
@@ -49,6 +49,9 @@#define NR_SPECIAL_PAGES 8#define special_pfn (x) (0xff000u - NR_SPECIAL_PAGES + (x)) +#define NR_IOREQ_SERVER_PAGES 8 +#define ioreq_server_pfn (x) (special_pfn(0) - NR_IOREQ_SERVER_PAGES + (x)) +#define VGA_HOLE_SIZE (0x20) static int modules_init(struct xc_hvm_build_args *args,
@@ -114,7 +117,7 @@ static void build_hvm_info(void *hvm_info_page, uint64_t mem_size,/* Memory parameters. */ hvm_info->low_mem_pgend = lowmem_end >>PAGE_SHIFT ; hvm_info->high_mem_pgend = highmem_end >>PAGE_SHIFT ; - hvm_info->reserved_mem_pgstart =special_pfn (0 ); + hvm_info->reserved_mem_pgstart =ioreq_server_pfn (0 );/* Finish with the checksum. */ for ( i =0 , sum =0 ; i < hvm_info->length; i++ )
@@ -502,6 +505,31 @@ static int setup_guest(xc_interface *xch, special_pfn(SPECIALPAGE_SHARING));/* +* Allocate and clear additional ioreq server pages. The default +* server will use the IOREQ and BUFIOREQ special pages above. +*/ +for ( i =0 ; i <NR_IOREQ_SERVER_PAGES ; i++ ) + { +xen_pfn_t pfn =ioreq_server_pfn (i); + + rc =xc_domain_populate_physmap_exact (xch, dom,1 ,0 ,0 , &pfn); +if ( rc !=0 ) + { +PERROR ("Could not allocate %d'th ioreq server page." , i); + goto error_out; + } + +if (xc_clear_domain_page (xch, dom, pfn) ) + goto error_out; + } + +/* Tell the domain where the pages are and how many there are */ +xc_set_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , +ioreq_server_pfn (0 )); +xc_set_hvm_param (xch, dom,HVM_PARAM_NR_IOREQ_SERVER_PAGES , +NR_IOREQ_SERVER_PAGES ); + +/* * Identity-map page table is required for running with CR0.PG=0 when * using Intel EPT. Create a 32-bit non-PAE page directory of superpages. */
tools/libxc/xenctrl.h +52 -0
61 lines not on this page · raw message
tools/libxc/xg_save_restore.h +2 -0
@@ -259,6 +259,8 @@#define XC_SAVE_ID_HVM_ACCESS_RING_PFN -16#define XC_SAVE_ID_HVM_SHARING_RING_PFN -17#define XC_SAVE_ID_TOOLSTACK -18/* Optional toolstack specific info */ +#define XC_SAVE_ID_HVM_IOREQ_SERVER_PFN -19 +#define XC_SAVE_ID_HVM_NR_IOREQ_SERVER_PAGES -20/* ** We process save/restore/migrate in batches of pages; the below
xen/arch/x86/hvm/hvm.c +962 -73
1,296 lines not on this page · raw message
xen/arch/x86/hvm/io.c +1 -1
@@ -74,7 +74,7 @@ void send_invalidate_req(void) .data = ~0UL, /* flush all */ }; - (void )hvm_send_assist_req (current, &p); +hvm_broadcast_assist_req (current, &p); }int handle_mmio (void )
xen/include/asm-x86/hvm/domain.h +33 -1
@@ -36,10 +36,23 @@#include <public/hvm/save.h> struct hvm_ioreq_page { +unsigned long gmfn;struct page_info *page;void *va; }; +struct hvm_io_range { +struct list_head list_entry; +uint64_t start, end; +struct rcu_head rcu; +}; + +struct hvm_pcidev { +struct list_head list_entry; +uint16_t bdf; +struct rcu_head rcu; +}; +struct hvm_ioreq_vcpu {struct list_head list_entry;struct vcpu *vcpu;
@@ -47,6 +60,9 @@ struct hvm_ioreq_vcpu { };struct hvm_ioreq_server { +struct list_head list_entry; +ioservid_t id; +/* Lock to serialize toolstack modifications */ spinlock_t lock;struct domain *domain;
@@ -60,11 +76,27 @@ struct hvm_ioreq_server {/* Lock to serialize access to buffered ioreq ring */ spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn; +struct list_head mmio_range_list; +struct list_head portio_range_list; +struct list_head pcidev_list; };struct hvm_domain { +/* Guest page range used for non-default ioreq servers */ +unsigned long ioreq_gmfn_base; +unsigned int ioreq_gmfn_count; +unsigned long ioreq_gmfn_mask; + +/* Lock protects all other values in the following block */ spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +ioservid_t ioreq_server_id; +struct list_head ioreq_server_list; +unsigned int ioreq_server_count; +struct hvm_ioreq_server *default_ioreq_server; + +/* Cached CF8 for guest PCI config cycles */ +uint32_t pci_cf8; +spinlock_t pci_lock;struct pl_time pl_time;
xen/include/asm-x86/hvm/hvm.h +2 -1
@@ -228,7 +228,8 @@ int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, struct page_info **_page, void **_va);void destroy_ring_for_helper (void **_va,struct page_info *page); -bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *p); +bool_t hvm_send_assist_req (struct vcpu *v,ioreq_t *p); +void hvm_broadcast_assist_req (struct vcpu *v,ioreq_t *p);void hvm_get_guest_pat (struct vcpu *v,u64 *guest_pat);int hvm_set_guest_pat (struct vcpu *v,u64 guest_pat);
xen/include/asm-x86/hvm/io.h +1 -1
@@ -92,7 +92,7 @@ static inline int hvm_buffered_io_intercept(ioreq_t *p) }int hvm_mmio_intercept (ioreq_t *p); -int hvm_buffered_io_send (struct domain *d,const ioreq_t *p); +int hvm_buffered_io_send (struct domain *d,ioreq_t *p); static inline void register_portio_handler( struct domain *d, unsigned long addr,
xen/include/public/hvm/hvm_op.h +70 -0
82 lines not on this page · raw message
xen/include/public/hvm/ioreq.h +1 -0
@@ -34,6 +34,7 @@#define IOREQ_TYPE_PIO 0/* pio */ #define IOREQ_TYPE_COPY 1/* mmio ops */ +#define IOREQ_TYPE_PCI_CONFIG 2/* pci config ops */ #define IOREQ_TYPE_TIMEOFFSET 7#define IOREQ_TYPE_INVALIDATE 8/* mapcache */
xen/include/public/hvm/params.h +4 -1
@@ -145,6 +145,9 @@/* SHUTDOWN_* action in case of a triple fault */ #define HVM_PARAM_TRIPLE_FAULT_REASON 31 -#define HVM_NR_PARAMS 32 +#define HVM_PARAM_IOREQ_SERVER_PFN 32 +#define HVM_PARAM_NR_IOREQ_SERVER_PAGES 33 + +#define HVM_NR_PARAMS 34#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Signature · 1 line
1.7.10.4
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 62 lines · Paul Durrant
The previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change the API.
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>--- tools/libxc/xc_domain.c | 175 +++++++ tools/libxc/xc_domain_restore.c | 27 + tools/libxc/xc_domain_save.c | 24 + tools/libxc/xc_hvm_build_x86.c | 30 +- tools/libxc/xenctrl.h | 52 ++ tools/libxc/xg_save_restore.h | 2 + xen/arch/x86/hvm/hvm.c | 1035 +++++++++++++++++++++++++++++++++++--- xen/arch/x86/hvm/io.c | 2 +- xen/include/asm-x86/hvm/domain.h | 34 +- xen/include/asm-x86/hvm/hvm.h | 3 +- xen/include/asm-x86/hvm/io.h | 2 +- xen/include/public/hvm/hvm_op.h | 70 +++ xen/include/public/hvm/ioreq.h | 1 + xen/include/public/hvm/params.h | 5 +- 14 files changed, 1383 insertions(+), 79 deletions(-)tools/libxc/xc_domain.c +11
-0@@ -1284,6 +1284,181 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned longreturn rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ;
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1307
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+ + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + rc =do_xen_hypercall (xch, &hypercall); + *id = arg->id; +xc_hypercall_buffer_free (xch, arg); +return rc; +}
Sorry if I missed it, but was there anywhere the 8-server limit is checked? What happens if someone calls xc_hvm_create_ioreq_server() 9 times?
Quoted 15 lines
tools/libxc/xc_domain.c +4
-2@@ -728,18 +877,53 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d, fail:hvm_ioreq_server_remove_all_vcpus (s); -hvm_ioreq_server_unmap_pages (s); +hvm_ioreq_server_unmap_pages (s, is_default); +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock);return rc; } -static void hvm_ioreq_server_deinit (struct hvm_ioreq_server *s) +static void hvm_ioreq_server_deinit (struct hvm_ioreq_server *s, +bool_t is_default) {
tools/libxc/xc_domain.c static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d, · line 898
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+struct list_head *entry; + +list_for_each ( entry, + &s->mmio_range_list ) + { +struct hvm_io_range *x =list_entry (entry, + struct hvm_io_range, + list_entry); + +xfree (x);
Hang on, isn't x still actually on mmio_range_list at this point, and doesn't entry equal &(x->list_entry)? So the next time around list_for_each(), you're using x after you've freed it?
I think you're missing a list_del_entry(), here and in the other 2 loops in this function.
I haven't gone through the rest of it with a fine-tooth comb, but interface-wise it looks good.
-George
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 113 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Dunlap
Sent: 03 April 2014 16:33
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Ian Campbell; Jan Beulich; Stefano Stabellini
Subject: Re: [Xen-devel] [PATCH v4 5/8] ioreq-server: add support for multiple serversQuoted 26 lines · Paul Durrant
The previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change the API.
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>Quoted 8 lines
--- tools/libxc/xc_domain.c | 175 +++++++ tools/libxc/xc_domain_restore.c | 27 + tools/libxc/xc_domain_save.c | 24 + tools/libxc/xc_hvm_build_x86.c | 30 +- tools/libxc/xenctrl.h | 52 ++ tools/libxc/xg_save_restore.h | 2 + xen/arch/x86/hvm/hvm.c | 1035+++++++++++++++++++++++++++++++++++---
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle,
Quoted 14 lines
xen/arch/x86/hvm/io.c | 2 +- xen/include/asm-x86/hvm/domain.h | 34 +- xen/include/asm-x86/hvm/hvm.h | 3 +- xen/include/asm-x86/hvm/io.h | 2 +- xen/include/public/hvm/hvm_op.h | 70 +++ xen/include/public/hvm/ioreq.h | 1 + xen/include/public/hvm/params.h | 5 +- 14 files changed, 1383 insertions(+), 79 deletions(-)tools/libxc/xc_domain.c +0
-0@@ -1284,6 +1284,181 @@ int xc_get_hvm_param(xc_interface *handle,
domid_tdom, int param, unsigned longQuoted 14 lines
tools/libxc/xc_domain.c +11
-0return rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ;tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1307
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+ + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + rc =do_xen_hypercall (xch, &hypercall); + *id = arg->id; +xc_hypercall_buffer_free (xch, arg); +return rc; +}Sorry if I missed it, but was there anywhere the 8-server limit is checked? What happens if someone calls
xc_hvm_create_ioreq_server()9 times?tools/libxc/xc_domain.c static int hvm_ioreq_server_init(struct
Quoted 1 line
tools/libxc/xc_domain.c +0
-0@@ -728,18 +877,53 @@ static int hvm_ioreq_server_init(struct
hvm_ioreq_server*s, struct domain *d,Quoted 20 lines
tools/libxc/xc_domain.c +10
-2fail:hvm_ioreq_server_remove_all_vcpus (s); -hvm_ioreq_server_unmap_pages (s); +hvm_ioreq_server_unmap_pages (s, is_default); +spin_unlock (&d->arch.hvm_domain.ioreq_server_lock);return rc; } -static void hvm_ioreq_server_deinit (struct hvm_ioreq_server *s) +static void hvm_ioreq_server_deinit (struct hvm_ioreq_server *s, +bool_t is_default) { +struct list_head *entry; + +list_for_each ( entry, + &s->mmio_range_list ) + { + struct hvm_io_range *x = list_entry(entry,
Quoted 9 lines
tools/libxc/xc_domain.c static int hvm_ioreq_server_init(struct · line 897
Quoted 4 lines
tools/libxc/xc_domain.c +4
-0+ struct hvm_io_range, + list_entry); + +xfree (x);Hang on, isn't x still actually on
mmio_range_listat this point, and doesn't entry equal &(x->list_entry)? So the next time aroundlist_for_each(), you're using x after you've freed it?
Good catch, I should be using list_for_each_safe().
Quoted 3 lines
I think you're missing a
list_del_entry(), here and in the other 2 loops in this function.
I don't the del as this is a full teardown, but I do need to avoid invalidating my iterator :-)
Paul
Quoted 4 lines
I haven't gone through the rest of it with a fine-tooth comb, but interface-wise it looks good.
-George
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 39 lines · Paul Durrant
Quoted 39 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Dunlap
Sent: 03 April 2014 16:33
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Ian Campbell; Jan Beulich; Stefano Stabellini
Subject: Re: [Xen-devel] [PATCH v4 5/8] ioreq-server: add support for multiple serversOn Wed, Apr 2, 2014 at 4:11 PM, Paul Durrant <[email protected]> wrote:
+++++++++++++++++++++++++++++++++++---tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle,
Quoted 6 lines
tools/libxc/xc_domain.c +0
-0@@ -1284,6 +1284,181 @@ int xc_get_hvm_param(xc_interface *handle,
domid_tdom, int param, unsigned longQuoted 19 lines
tools/libxc/xc_domain.c +16
-0return rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid;
Quoted 8 lines
Quoted 8 lines
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1307
Quoted 5 lines
tools/libxc/xc_domain.c +5
-0+ rc =do_xen_hypercall (xch, &hypercall); + *id = arg->id; +xc_hypercall_buffer_free (xch, arg); +return rc; +}Sorry if I missed it, but was there anywhere the 8-server limit is checked? What happens if someone calls
xc_hvm_create_ioreq_server()9 times?
Just checking -- did you miss this question, or are you going to come back to it later? :-)
-George
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 59 lines
-----Original Message-----
From: George Dunlap [mailto:[email protected]]
Sent: 03 April 2014 16:43
To: Paul Durrant; George Dunlap
Cc: [email protected]; Ian Jackson; Ian Campbell; Jan Beulich; Stefano Stabellini
Subject: Re: [Xen-devel] [PATCH v4 5/8] ioreq-server: add support for multiple serversQuoted 6 lines · Paul Durrant
Quoted 6 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Dunlap
Sent: 03 April 2014 16:33
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Ian Campbell; Jan Beulich;Stefano
Quoted 8 lines
Quoted 8 lines
Stabellini
Subject: Re: [Xen-devel] [PATCH v4 5/8] ioreq-server: add support for multiple serversOn Wed, Apr 2, 2014 at 4:11 PM, Paul Durrant <[email protected]> wrote:
+++++++++++++++++++++++++++++++++++---Quoted 1 line
Quoted 5 lines
Quoted 5 lines
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface
Quoted 5 lines
tools/libxc/xc_domain.c +0
-0@@ -1284,6 +1284,181 @@ int xc_get_hvm_param(xc_interface*handle,
Quoted 10 lines
Quoted 10 lines
domid_tdom, int param, unsigned longtools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long
Quoted 9 lines
tools/libxc/xc_domain.c +6
-0return rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ; + DECLARE_HYPERCALL_BUFFER(xen_hvm_create_ioreq_server_t,arg);
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tools/libxc/xc_domain.c +9
-0+int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg);Quoted 8 lines
Quoted 8 lines
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1307
Quoted 6 lines
tools/libxc/xc_domain.c +6
-0+ arg->domid = domid; + rc =do_xen_hypercall (xch, &hypercall); + *id = arg->id; +xc_hypercall_buffer_free (xch, arg); +return rc; +}Sorry if I missed it, but was there anywhere the 8-server limit is checked? What happens if someone calls
xc_hvm_create_ioreq_server()
Quoted 6 lines
9
Quoted 1 line
Quoted 1 line
times?
Just checking -- did you miss this question, or are you going to come back to it later? :-)
Sorry, I did miss that. The limit of 8 is not the number of servers, it's the number of pages. If someone tries to create too many servers the page allocation code will fail and thus the creation will fail with an ENOMEM.
Paul
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
In reply to Paul DurrantQuoted 16 lines · Paul Durrant
The previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
Quoted 4 lines
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change the API.
A pool of 8 implies 4 servers with a buffered and unbuffered page each? Or later on some combination of servers using both or one or the other?
Quoted 35 lines
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>--- tools/libxc/xc_domain.c | 175 +++++++ tools/libxc/xc_domain_restore.c | 27 + tools/libxc/xc_domain_save.c | 24 + tools/libxc/xc_hvm_build_x86.c | 30 +- tools/libxc/xenctrl.h | 52 ++ tools/libxc/xg_save_restore.h | 2 + xen/arch/x86/hvm/hvm.c | 1035 +++++++++++++++++++++++++++++++++++--- xen/arch/x86/hvm/io.c | 2 +- xen/include/asm-x86/hvm/domain.h | 34 +- xen/include/asm-x86/hvm/hvm.h | 3 +- xen/include/asm-x86/hvm/io.h | 2 +- xen/include/public/hvm/hvm_op.h | 70 +++ xen/include/public/hvm/ioreq.h | 1 + xen/include/public/hvm/params.h | 5 +- 14 files changed, 1383 insertions(+), 79 deletions(-)tools/libxc/xc_domain.c +5
-0@@ -1284,6 +1284,181 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned longreturn rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ;
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1301
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg);
Can you add some newlines please.
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1302
Quoted 1 line
tools/libxc/xc_domain.c +1
-0+ arg->domid = domid;
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1303
Quoted 1 line
tools/libxc/xc_domain.c +1
-0+ rc =do_xen_hypercall (xch, &hypercall);
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1304
Quoted 1 line
tools/libxc/xc_domain.c +1
-0+ *id = arg->id;
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1305
Quoted 1 line
tools/libxc/xc_domain.c +1
-0+xc_hypercall_buffer_free (xch, arg);
Here
Quoted 11 lines
tools/libxc/xc_domain.c +11
-0+return rc; +} + +int xc_hvm_get_ioreq_server_info (xc_interface *xch, +domid_t domid, +ioservid_t id, +xen_pfn_t *ioreq_pfn, +xen_pfn_t *bufioreq_pfn, +evtchn_port_t *bufioreq_port) +{ +DECLARE_HYPERCALL ;
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1326
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+DECLARE_HYPERCALL_BUFFER (xen_hvm_get_ioreq_server_info_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_get_ioreq_server_info; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg);
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1328
Quoted 2 lines
tools/libxc/xc_domain.c +2
-0+ arg->domid = domid; + arg->id = id;
Here
Quoted 23 lines
tools/libxc/xc_domain.c +23
-0+ rc =do_xen_hypercall (xch, &hypercall); +if ( rc !=0 ) + goto done; + +if ( ioreq_pfn ) + *ioreq_pfn = arg->ioreq_pfn; + +if ( bufioreq_pfn ) + *bufioreq_pfn = arg->bufioreq_pfn; + +if ( bufioreq_port ) + *bufioreq_port = arg->bufioreq_port; + +done: +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_map_io_range_to_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,int is_mmio, +uint64_t start,uint64_t end) +{ +DECLARE_HYPERCALL ;
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1361
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+DECLARE_HYPERCALL_BUFFER (xen_hvm_map_io_range_to_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_map_io_range_to_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg);
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1366
Quoted 5 lines
tools/libxc/xc_domain.c +5
-0+ arg->domid = domid; + arg->id = id; + arg->is_mmio = is_mmio; + arg->start = start; + arg->end = end;
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1367
Quoted 1 line
tools/libxc/xc_domain.c +1
-0+ rc =do_xen_hypercall (xch, &hypercall);
Here
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1368
Quoted 1 line
tools/libxc/xc_domain.c +1
-0+xc_hypercall_buffer_free (xch, arg);
Here
Well, you get the picture, it applies for the rest of these bindings too. The actual code looks correct.
[...]
tools/libxc/xc_domain.c int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, · line 1776
Quoted 8 lines
tools/libxc/xc_domain.c +4
-0@@ -1748,6 +1770,11 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,if (pagebuf.viridian !=0 )xc_set_hvm_param (xch, dom,HVM_PARAM_VIRIDIAN ,1 ); +xc_set_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , + pagebuf.ioreq_server_pfn); +xc_set_hvm_param (xch, dom,HVM_PARAM_NR_IOREQ_SERVER_PAGES , + pagebuf.nr_ioreq_server_pages);
When migrating into this from the previous version of Xen both of these will be zero. Does that do the right thing? I didn't see any special handling on the hypervisor side. In fact it looks like it will EINVAL.
Quoted 10 lines
tools/libxc/xc_domain.c +1
-0+if (pagebuf.acpi_ioport_location ==1 ) {DBGPRINTF ("Use new firmware ioport from the checkpoint\n" );xc_set_hvm_param (xch, dom,HVM_PARAM_ACPI_IOPORTS_LOCATION ,1 );tools/libxc/xenctrl.h +0
-0
tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1806
Quoted 6 lines
tools/libxc/xenctrl.h +3
-0@@ -1801,6 +1801,48 @@ void xc_clear_last_error(xc_interface *xch);int xc_set_hvm_param (xc_interface *handle,domid_t dom,int param,unsigned long value);int xc_get_hvm_param (xc_interface *handle,domid_t dom,int param,unsigned long *value); +/* +* IOREQ server API +*/
Hopefully xen/include/public has the associated docs for what all these functions do.
Ian.
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 24 lines
-----Original Message-----
From: Ian Campbell
Sent: 07 April 2014 16:58
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 5/8] ioreq-server: add support for multiple serversQuoted 16 lines · Paul Durrant
The previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
Quoted 8 lines
Quoted 4 lines
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change the API.
A pool of 8 implies 4 servers with a buffered and unbuffered page each? Or later on some combination of servers using both or one or the other?
Yes, it seems like enough room for now.
Quoted 41 lines
Quoted 5 lines
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>Quoted 8 lines
--- tools/libxc/xc_domain.c | 175 +++++++ tools/libxc/xc_domain_restore.c | 27 + tools/libxc/xc_domain_save.c | 24 + tools/libxc/xc_hvm_build_x86.c | 30 +- tools/libxc/xenctrl.h | 52 ++ tools/libxc/xg_save_restore.h | 2 + xen/arch/x86/hvm/hvm.c | 1035+++++++++++++++++++++++++++++++++++---
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle,
Quoted 14 lines
xen/arch/x86/hvm/io.c | 2 +- xen/include/asm-x86/hvm/domain.h | 34 +- xen/include/asm-x86/hvm/hvm.h | 3 +- xen/include/asm-x86/hvm/io.h | 2 +- xen/include/public/hvm/hvm_op.h | 70 +++ xen/include/public/hvm/ioreq.h | 1 + xen/include/public/hvm/params.h | 5 +- 14 files changed, 1383 insertions(+), 79 deletions(-)tools/libxc/xc_domain.c +0
-0@@ -1284,6 +1284,181 @@ int xc_get_hvm_param(xc_interface *handle,
domid_tdom, int param, unsigned longQuoted 12 lines
tools/libxc/xc_domain.c +9
-0return rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg));
Quoted 9 lines
tools/libxc/xc_domain.c int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long · line 1301
Quoted 6 lines
tools/libxc/xc_domain.c +6
-0+if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg);Can you add some newlines please.
Sure.
[snip]
Quoted 8 lines
tools/libxc/xc_domain.c int xc_domain_restore(xc_interface *xch, int
Quoted 1 line
tools/libxc/xc_domain.c +0
-0@@ -1748,6 +1770,11 @@ int xc_domain_restore(xc_interface *xch, int
io_fd,uint32_tdom,tools/libxc/xc_domain.c int xc_domain_restore(xc_interface *xch, int · line 1775
Quoted 6 lines
tools/libxc/xc_domain.c +3
-0if (pagebuf.viridian !=0 )xc_set_hvm_param (xch, dom,HVM_PARAM_VIRIDIAN ,1 ); +xc_set_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , + pagebuf.ioreq_server_pfn); + xc_set_hvm_param(xch, dom,
Quoted 7 lines
HVM_PARAM_NR_IOREQ_SERVER_PAGES,tools/libxc/xc_domain.c int xc_domain_restore(xc_interface *xch, int · line 1776
Quoted 1 line
tools/libxc/xc_domain.c +1
-0+ pagebuf.nr_ioreq_server_pages);When migrating into this from the previous version of Xen both of these will be zero. Does that do the right thing? I didn't see any special handling on the hypervisor side. In fact it looks like it will EINVAL.
Yes, it will be EINVAL which is why the return code is deliberately not checked. I can special-case if you think that would be clearer, or stick '(void)' in front of these calls to show the return code is being deliberately ignored.
Quoted 14 lines
tools/libxc/xc_domain.c int xc_domain_restore(xc_interface *xch, int · line 1780
Quoted 4 lines
tools/libxc/xc_domain.c +1
-0+if (pagebuf.acpi_ioport_location ==1 ) {DBGPRINTF ("Use new firmware ioport from the checkpoint\n" ); xc_set_hvm_param(xch, dom,
HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1801
Quoted 6 lines
tools/libxc/xenctrl.h +0
-0@@ -1801,6 +1801,48 @@ void xc_clear_last_error(xc_interface *xch); int xc_set_hvm_param(xc_interface *handle, domid_t dom, int param,unsigned long value);
tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1802
Quoted 1 line
tools/libxc/xenctrl.h +0
-0int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param,
Quoted 8 lines
unsigned long *value);
tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1806
Quoted 4 lines
tools/libxc/xenctrl.h +3
-0+/* +* IOREQ server API +*/ Hopefully xen/include/public has the associated docs for what all these functions do.
Not yet. Do think this would best handled in a header or in some markdown in docs/misc?
Paul
Quoted 2 lines
Ian.
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 29 lines · Paul Durrant
Quoted 29 lines
-----Original Message-----
From: Ian Campbell
Sent: 07 April 2014 16:58
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 5/8] ioreq-server: add support for multiple serversQuoted 20 lines · Paul Durrant
The previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change the API.
Quoted 5 lines
Quoted 3 lines
A pool of 8 implies 4 servers with a buffered and unbuffered page each? Or later on some combination of servers using both or one or the other?
Yes, it seems like enough room for now.
What I was asking is can I have 3 servers with both buffered and unbuffered plus 2 with only unbuffered, for a total of 8 pages?
Quoted 17 lines
[snip]
Quoted 8 lines
Review int xc_domain_restore(xc_interface *xch, int
Quoted 1 line
(quoted diff) +0
-0@@ -1748,6 +1770,11 @@ int xc_domain_restore(xc_interface *xch, int
io_fd,uint32_tdom,tools/libxc/xc_domain_restore.c int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
Quoted 6 lines
tools/libxc/xc_domain_restore.c +3
-0if (pagebuf.viridian !=0 )xc_set_hvm_param (xch, dom,HVM_PARAM_VIRIDIAN ,1 ); +xc_set_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , + pagebuf.ioreq_server_pfn); + xc_set_hvm_param(xch, dom,Quoted 7 lines
HVM_PARAM_NR_IOREQ_SERVER_PAGES,tools/libxc/xc_domain_restore.c int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, · line 1776
Quoted 1 line
tools/libxc/xc_domain_restore.c +1
-0+ pagebuf.nr_ioreq_server_pages);When migrating into this from the previous version of Xen both of these will be zero. Does that do the right thing? I didn't see any special handling on the hypervisor side. In fact it looks like it will EINVAL.
Quoted 4 lines
Yes, it will be EINVAL which is why the return code is deliberately not checked. I can special-case if you think that would be clearer, or stick '(void)' in front of these calls to show the return code is being deliberately ignored.
At the very least the behaviour needs to be written down somewhere.
But I think being explicit in the restore code about these cases would be clearer than relying on EINVAL from the hypervisor, i.e. remember if you saw that chunk or not and either make the call or not.
As for not checking the return code -- what if it fails for some other reason. perhaps the migration stream is corrupt?
How does everything agree on the location of the fallback ioreq PFN in this case since it isn't set here?
Quoted 21 lines
Quoted 21 lines
tools/libxc/xc_domain_restore.c int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
Quoted 5 lines
tools/libxc/xc_domain_restore.c +1
-0+if (pagebuf.acpi_ioport_location ==1 ) {DBGPRINTF ("Use new firmware ioport from the checkpoint\n" ); xc_set_hvm_param(xch, dom,
HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1801
Quoted 6 lines
tools/libxc/xenctrl.h +0
-0@@ -1801,6 +1801,48 @@ void xc_clear_last_error(xc_interface *xch); int xc_set_hvm_param(xc_interface *handle, domid_t dom, int param,unsigned long value);
tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1802
Quoted 1 line
tools/libxc/xenctrl.h +0
-0int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param,unsigned long *value);
Quoted 4 lines
tools/libxc/xenctrl.h +3
-0+/* +* IOREQ server API +*/
Quoted 5 lines
Quoted 2 lines
Hopefully xen/include/public has the associated docs for what all these functions do.
Not yet. Do think this would best handled in a header or in some markdown in docs/misc?
For hypercalls in the headers is best, they will be exported into the docs subtree by the build. See
http://xenbits.xen.org/docs/unstable/hypercall/x86_64/index.html.
Ian.
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 39 lines
-----Original Message-----
From: Ian Campbell
Sent: 08 April 2014 09:41
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 5/8] ioreq-server: add support for multiple serversQuoted 6 lines · Paul Durrant
Quoted 6 lines
-----Original Message-----
From: Ian Campbell
Sent: 07 April 2014 16:58
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 5/8] ioreq-server: add support for multipleservers
Quoted 18 lines
Quoted 18 lines · Paul Durrant
Quoted 16 lines
The previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change
the
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
API.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
A pool of 8 implies 4 servers with a buffered and unbuffered page each? Or later on some combination of servers using both or one or the other?
Yes, it seems like enough room for now.
What I was asking is can I have 3 servers with both buffered and unbuffered plus 2 with only unbuffered, for a total of 8 pages?
Yes.
Quoted 22 lines
Quoted 17 lines
[snip]
Quoted 8 lines
Review int xc_domain_restore(xc_interface *xch, int
Quoted 1 line
(quoted diff) +0
-0@@ -1748,6 +1770,11 @@ int xc_domain_restore(xc_interface *xch, int
io_fd,uint32_tdom,tools/libxc/xc_domain_restore.c int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
Quoted 6 lines
tools/libxc/xc_domain_restore.c +3
-0if (pagebuf.viridian !=0 )xc_set_hvm_param (xch, dom,HVM_PARAM_VIRIDIAN ,1 ); +xc_set_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , + pagebuf.ioreq_server_pfn); + xc_set_hvm_param(xch, dom,Quoted 7 lines
HVM_PARAM_NR_IOREQ_SERVER_PAGES,tools/libxc/xc_domain_restore.c int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, · line 1776
Quoted 1 line
tools/libxc/xc_domain_restore.c +1
-0+ pagebuf.nr_ioreq_server_pages);When migrating into this from the previous version of Xen both of these will be zero. Does that do the right thing? I didn't see any special handling on the hypervisor side. In fact it looks like it will EINVAL.
Quoted 4 lines
Yes, it will be EINVAL which is why the return code is deliberately not checked. I can special-case if you think that would be clearer, or stick '(void)' in front of these calls to show the return code is being deliberately ignored.
Quoted 9 lines
At the very least the behaviour needs to be written down somewhere.
But I think being explicit in the restore code about these cases would be clearer than relying on EINVAL from the hypervisor, i.e. remember if you saw that chunk or not and either make the call or not.
As for not checking the return code -- what if it fails for some other reason. perhaps the migration stream is corrupt?
EPERM is the only other possible failure, and that shouldn't happen for a legit domain restore. I'll avoid making the call if the save record is not there though, as you suggest.
Quoted 3 lines
How does everything agree on the location of the fallback ioreq PFN in this case since it isn't set here?
The QEMU PFNs don't move, so no change there. If the params aren't set properly then secondary servers cannot be created after migration.
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines
tools/libxc/xc_domain_restore.c int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
Quoted 5 lines
tools/libxc/xc_domain_restore.c +1
-0+if (pagebuf.acpi_ioport_location ==1 ) {DBGPRINTF ("Use new firmware ioport from the checkpoint\n" ); xc_set_hvm_param(xch, dom,
HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);Quoted 8 lines
Quoted 8 lines
tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1801
Quoted 6 lines
tools/libxc/xenctrl.h +0
-0@@ -1801,6 +1801,48 @@ void xc_clear_last_error(xc_interface *xch); int xc_set_hvm_param(xc_interface *handle, domid_t dom, int param,unsigned long value);
Quoted 1 line
tools/libxc/xenctrl.h +0
-0int xc_get_hvm_param(xc_interface *handle, domid_t dom, intparam,
Quoted 9 lines
Quoted 8 lines
unsigned long *value);
tools/libxc/xenctrl.h void xc_clear_last_error(xc_interface *xch); · line 1806
Quoted 4 lines
tools/libxc/xenctrl.h +3
-0+/* +* IOREQ server API +*/ Hopefully xen/include/public has the associated docs for what all these functions do.
Quoted 7 lines
Quoted 2 lines
Not yet. Do think this would best handled in a header or in some markdown in docs/misc?
For hypercalls in the headers is best, they will be exported into the docs subtree by the build. See
http://xenbits.xen.org/docs/unstable/hypercall/x86_64/index.html.
Ok. Ta,
Paul
Quoted 1 line
Ian.
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
In reply to Paul DurrantQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
Ah, here is the answer to the question I raised on patch 6 - somehow I managed to look at them in wrong order. Nevertheless, and also in the context of the discussion we had with Stefano yesterday, we may want/need to think of a way to allow pages to be trackable without being mapped in the physmap.
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 81
Quoted 7 lines
xen/include/asm-x86/hvm/domain.h +3
-0@@ -60,11 +76,27 @@ struct hvm_ioreq_server {/* Lock to serialize access to buffered ioreq ring */ spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn; +struct list_head mmio_range_list; +struct list_head portio_range_list; +struct list_head pcidev_list;
Wouldn't these better be range sets? I realize this might conflict with the RCU manipulation of the entries, but perhaps the rangesets could get their interface extended if this is strictly a requirement (otoh hand I can't see why you couldn't get away with "normal" freeing, since changes to these lists shouldn't be frequent, and hence not be performance critical).
Also, I didn't see a limit being enforced on the number of elements that can be added to these lists, yet allowing this to be unlimited is a latent security issue.
Quoted 7 lines
xen/include/asm-x86/hvm/domain.h +6
-0struct hvm_domain { +/* Guest page range used for non-default ioreq servers */ +unsigned long ioreq_gmfn_base; +unsigned int ioreq_gmfn_count; +unsigned long ioreq_gmfn_mask; + +/* Lock protects all other values in the following block */
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 99
Quoted 10 lines
xen/include/asm-x86/hvm/domain.h +8
-1spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +ioservid_t ioreq_server_id; +struct list_head ioreq_server_list; +unsigned int ioreq_server_count; +struct hvm_ioreq_server *default_ioreq_server; + +/* Cached CF8 for guest PCI config cycles */ +uint32_t pci_cf8; +spinlock_t pci_lock;
Please consider padding when adding new fields here - try grouping 64-bit quantities together rather than alternating between 32- and 64-bit ones.
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, · line 231
Quoted 8 lines
xen/include/asm-x86/hvm/hvm.h +1
-1@@ -228,7 +228,8 @@ int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, struct page_info **_page, void **_va);void destroy_ring_for_helper (void **_va,struct page_info *page); -bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *p); +bool_t hvm_send_assist_req (struct vcpu *v,ioreq_t *p);
Any reason you couldn't avoid adding the const in one of the earlier patches?
Quoted 5 lines
xen/include/asm-x86/hvm/hvm.h +5
-0+#define HVMOP_map_io_range_to_ioreq_server 19 +struct xen_hvm_map_io_range_to_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +int is_mmio;/* IN - MMIO or port IO? */
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d, unsigned long gmfn,
Quoted 10 lines
xen/include/asm-x86/hvm/hvm.h +10
-0+uint64_aligned_t start, end;/* IN - inclusive start and end of range */ +}; +typedef struct xen_hvm_map_io_range_to_ioreq_server xen_hvm_map_io_range_to_ioreq_server_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_map_io_range_to_ioreq_server_t); + +#define HVMOP_unmap_io_range_from_ioreq_server 20 +struct xen_hvm_unmap_io_range_from_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +uint8_t is_mmio;/* IN - MMIO or port IO? */
Please use uint8_t above too, and move the field ahead of "id" for better packing. I'm also not sure the "is_" prefix is really useful here. And for this to be usable with other architectures that may have address spaces other than memory and I/O ports it would seem desirable to not consider this a boolean, but an enumerator. In the end a third address space could immediately be PCI space, thus eliminating the need for the two special ops below. I.e. this could follow more closely ACPI's address space handling - there's nothing inherently wrong with an MSR based I/O interface for example.
Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +4
-0+#define HVMOP_map_pcidev_to_ioreq_server 21 +struct xen_hvm_map_pcidev_to_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */
xen/include/asm-x86/hvm/hvm.h
Quoted 10 lines
xen/include/asm-x86/hvm/hvm.h +10
-0+uint16_t bdf;/* IN - PCI bus/dev/func */ +}; +typedef struct xen_hvm_map_pcidev_to_ioreq_server xen_hvm_map_pcidev_to_ioreq_server_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_map_pcidev_to_ioreq_server_t); + +#define HVMOP_unmap_pcidev_from_ioreq_server 22 +struct xen_hvm_unmap_pcidev_from_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +uint16_t bdf;/* IN - PCI bus/dev/func */
Both of these need a PCI segment/domain added. Also what's the point of having two identical structures of map and unmap?
Jan
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
Quoted 5 lines
Ah, here is the answer to the question I raised on patch 6 - somehow I managed to look at them in wrong order. Nevertheless, and also in the context of the discussion we had with Stefano yesterday, we may want/need to think of a way to allow pages to be trackable without being mapped in the physmap.
Is what is wanted a new XENMAPSPACE which could be used via xen_add_to_physmap_batch to map foreign_dom.idx where idx for that mapspace is the ioreq page index rather than a gfn?
Ian.
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 09.04.14 at 14:49, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
Quoted 5 lines
Ah, here is the answer to the question I raised on patch 6 - somehow I managed to look at them in wrong order. Nevertheless, and also in the context of the discussion we had with Stefano yesterday, we may want/need to think of a way to allow pages to be trackable without being mapped in the physmap.
Quoted 3 lines
Is what is wanted a new XENMAPSPACE which could be used via
xen_add_to_physmap_batchto map foreign_dom.idx where idx for that mapspace is the ioreq page index rather than a gfn?
Something along those lines at least; the precise one you talk about would help the other (qemu) issue - we'd really need a "free floating" map space, with indexes assigned as they get removed from physmap or allocated without putting them into the physmap.
Jan
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
In reply to Jan BeulichQuoted 16 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 April 2014 13:43
To: Paul Durrant
Cc: Ian Campbell; Ian Jackson; Stefano Stabellini; [email protected]
Subject: Re: [PATCH v4 5/8] ioreq-server: add support for multiple serversQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
Quoted 6 lines
Ah, here is the answer to the question I raised on patch 6 - somehow I managed to look at them in wrong order. Nevertheless, and also in the context of the discussion we had with Stefano yesterday, we may want/need to think of a way to allow pages to be trackable without being mapped in the physmap.
Possibly. That would be rather a large amount of scope-creep to these patches though.
Quoted 6 lines
Quoted 6 lines
xen/include/asm-x86/hvm/domain.h +2
-0@@ -60,11 +76,27 @@ struct hvm_ioreq_server {/* Lock to serialize access to buffered ioreq ring */ spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn; +struct list_head mmio_range_list; +struct list_head portio_range_list;
Quoted 9 lines
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 81
Quoted 1 line
xen/include/asm-x86/hvm/domain.h +1
-0+struct list_head pcidev_list;Wouldn't these better be range sets? I realize this might conflict with the RCU manipulation of the entries, but perhaps the rangesets could get their interface extended if this is strictly a requirement (otoh hand I can't see why you couldn't get away with "normal" freeing, since changes to these lists shouldn't be frequent, and hence not be performance critical).
The lists are accessed without lock by a vcpu requesting emulation so they need to be RCU. I'll look at the range set code and see if that is feasible.
Quoted 4 lines
Also, I didn't see a limit being enforced on the number of elements that can be added to these lists, yet allowing this to be unlimited is a latent security issue.
Guest domains cannot add to the lists, only the emulating domain, but if that is unprivileged then, yes, that is a security issue.
Quoted 13 lines
Quoted 13 lines
xen/include/asm-x86/hvm/domain.h +10
-1struct hvm_domain { +/* Guest page range used for non-default ioreq servers */ +unsigned long ioreq_gmfn_base; +unsigned int ioreq_gmfn_count; +unsigned long ioreq_gmfn_mask; + +/* Lock protects all other values in the following block */ spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +ioservid_t ioreq_server_id; +struct list_head ioreq_server_list; +unsigned int ioreq_server_count; +struct hvm_ioreq_server *default_ioreq_server;
Quoted 8 lines
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 99
Quoted 4 lines
xen/include/asm-x86/hvm/domain.h +4
-0+ +/* Cached CF8 for guest PCI config cycles */ +uint32_t pci_cf8; +spinlock_t pci_lock;Please consider padding when adding new fields here - try grouping 64-bit quantities together rather than alternating between 32- and 64-bit ones.
Why do we need to care about padding? Re-ordering for efficiency of space is reasonable.
Quoted 5 lines
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d,
Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +0
-0@@ -228,7 +228,8 @@ int prepare_ring_for_helper(struct domain *d,unsigned long gmfn,
Quoted 9 lines
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, · line 231
Quoted 5 lines
xen/include/asm-x86/hvm/hvm.h +1
-1struct page_info **_page, void **_va);void destroy_ring_for_helper (void **_va,struct page_info *page); -bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *p); +bool_t hvm_send_assist_req (struct vcpu *v,ioreq_t *p);Any reason you couldn't avoid adding the const in one of the earlier patches?
You asked for it in a previous review. I'm happy to lose the const again.
Quoted 13 lines
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d, · line 235
Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +4
-0+#define HVMOP_map_io_range_to_ioreq_server 19 +struct xen_hvm_map_io_range_to_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from
HVMOP_register_ioreq_server*/xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d,
Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +4
-0+int is_mmio;/* IN - MMIO or port IO? */ +uint64_aligned_t start, end;/* IN - inclusive start and end of range */ +}; +typedef struct xen_hvm_map_io_range_to_ioreq_server
xen_hvm_map_io_range_to_ioreq_server_t;Quoted 1 line
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_map_io_range_to_ioreq_server_ t);
Quoted 9 lines
xen/include/asm-x86/hvm/hvm.h
Quoted 6 lines
xen/include/asm-x86/hvm/hvm.h +6
-0+ +#define HVMOP_unmap_io_range_from_ioreq_server 20 +struct xen_hvm_unmap_io_range_from_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +uint8_t is_mmio;/* IN - MMIO or port IO? */ Please use
uint8_tabove too, and move the field ahead of "id" for better packing. I'm also not sure the "is_" prefix is really useful here.
Ok.
Quoted 3 lines
And for this to be usable with other architectures that may have address spaces other than memory and I/O ports it would seem desirable to not consider this a boolean, but an enumerator.
Maybe it would be better to consolidate io ranges and pci devs then and the existing ioreq type values in the interface. I.e:
#define IOREQ_TYPE_PIO 0 /* pio */ #define IOREQ_TYPE_COPY 1 /* mmio ops */ #define IOREQ_TYPE_PCI_CONFIG 2 /* pci config ops */
Quoted 6 lines
In the
end a third address space could immediately be PCI space, thus eliminating the need for the two special ops below. I.e. this could follow more closely ACPI's address space handling - there's nothing inherently wrong with an MSR based I/O interface for example.
Ah, I see you had the same thought :-)
Quoted 10 lines
xen/include/asm-x86/hvm/hvm.h
Quoted 7 lines
xen/include/asm-x86/hvm/hvm.h +7
-0+#define HVMOP_map_pcidev_to_ioreq_server 21 +struct xen_hvm_map_pcidev_to_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +uint16_t bdf;/* IN - PCI bus/dev/func */ +}; +typedef struct xen_hvm_map_pcidev_to_ioreq_server
xen_hvm_map_pcidev_to_ioreq_server_t;Quoted 1 line
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_map_pcidev_to_ioreq_server_t);
Quoted 8 lines
xen/include/asm-x86/hvm/hvm.h
Quoted 6 lines
xen/include/asm-x86/hvm/hvm.h +6
-0+ +#define HVMOP_unmap_pcidev_from_ioreq_server 22 +struct xen_hvm_unmap_pcidev_from_ioreq_server { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +uint16_t bdf;/* IN - PCI bus/dev/func */ Both of these need a PCI segment/domain added.
Ok.
Quoted 3 lines
Also what's the
point of having two identical structures of map and unmap?
Good point. I'll collapse them down.
Paul
Quoted 1 line
Jan
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 10 lines
Quoted 7 lines
Quoted 1 line · On 09.04.14 at 15:32, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Also, I didn't see a limit being enforced on the number of elements that can be added to these lists, yet allowing this to be unlimited is a latent security issue.
Guest domains cannot add to the lists, only the emulating domain, but if that is unprivileged then, yes, that is a security issue.
And hence it needs to be fixed, or the operation added to the list of disaggregation-unsafe ones (which XSA-77 added). I'd clearly favor the former...
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
struct
hvm_domain{xen/include/asm-x86/hvm/domain.h +10
-1+/* Guest page range used for non-default ioreq servers */ +unsigned long ioreq_gmfn_base; +unsigned int ioreq_gmfn_count; +unsigned long ioreq_gmfn_mask; + +/* Lock protects all other values in the following block */ spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +ioservid_t ioreq_server_id; +struct list_head ioreq_server_list; +unsigned int ioreq_server_count; +struct hvm_ioreq_server *default_ioreq_server;Quoted 8 lines
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 99
Quoted 4 lines
xen/include/asm-x86/hvm/domain.h +4
-0+ +/* Cached CF8 for guest PCI config cycles */ +uint32_t pci_cf8; +spinlock_t pci_lock;Please consider padding when adding new fields here - try grouping 64-bit quantities together rather than alternating between 32- and 64-bit ones.
Quoted 2 lines
Why do we need to care about padding? Re-ordering for efficiency of space is reasonable.
That's what I meant - try to avoid unnecessary padding.
Quoted 7 lines
Quoted 7 lines
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d,
Quoted 3 lines
xen/include/asm-x86/hvm/hvm.h +0
-0@@ -228,7 +228,8 @@ int prepare_ring_for_helper(struct domain *d,unsigned long gmfn,
Quoted 3 lines
xen/include/asm-x86/hvm/hvm.h +0
-0struct page_info **_page, void **_va);void destroy_ring_for_helper (void **_va,struct page_info *page);
Quoted 8 lines
Quoted 6 lines
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, · line 231
Quoted 2 lines
xen/include/asm-x86/hvm/hvm.h +1
-1-bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *p); +bool_t hvm_send_assist_req (struct vcpu *v,ioreq_t *p);Any reason you couldn't avoid adding the const in one of the earlier patches?
You asked for it in a previous review. I'm happy to lose the const again.
If it doesn't persist through the series, there's little point in adding it.
Quoted 9 lines
Quoted 3 lines
And for this to be usable with other architectures that may have address spaces other than memory and I/O ports it would seem desirable to not consider this a boolean, but an enumerator.
Maybe it would be better to consolidate io ranges and pci devs then and the existing ioreq type values in the interface. I.e:
#define
IOREQ_TYPE_PIO0 /* pio */
#defineIOREQ_TYPE_COPY1 /* mmio ops */
Right, except that "COPY" is sort of odd here - why not "MMIO"?
Jan
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
Quoted 72 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 April 2014 14:47
To: Paul Durrant
Cc: Ian Campbell; Ian Jackson; Stefano Stabellini; [email protected]
Subject: RE: [PATCH v4 5/8] ioreq-server: add support for multiple serversQuoted 10 lines
Quoted 7 lines
Quoted 1 line · On 09.04.14 at 15:32, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Also, I didn't see a limit being enforced on the number of elements that can be added to these lists, yet allowing this to be unlimited is a latent security issue.
Guest domains cannot add to the lists, only the emulating domain, but if that is unprivileged then, yes, that is a security issue.
And hence it needs to be fixed, or the operation added to the list of disaggregation-unsafe ones (which XSA-77 added). I'd clearly favor the former...
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
struct
hvm_domain{xen/include/asm-x86/hvm/domain.h +10
-1+/* Guest page range used for non-default ioreq servers */ +unsigned long ioreq_gmfn_base; +unsigned int ioreq_gmfn_count; +unsigned long ioreq_gmfn_mask; + +/* Lock protects all other values in the following block */ spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +ioservid_t ioreq_server_id; +struct list_head ioreq_server_list; +unsigned int ioreq_server_count; +struct hvm_ioreq_server *default_ioreq_server;Quoted 8 lines
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 99
Quoted 4 lines
xen/include/asm-x86/hvm/domain.h +4
-0+ +/* Cached CF8 for guest PCI config cycles */ +uint32_t pci_cf8; +spinlock_t pci_lock;Please consider padding when adding new fields here - try grouping 64-bit quantities together rather than alternating between 32- and 64-bit ones.
Quoted 1 line
Why do we need to care about padding? Re-ordering for efficiency of
space is
Quoted 1 line
reasonable.
That's what I meant - try to avoid unnecessary padding.
Quoted 7 lines
Quoted 7 lines
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d,
Quoted 3 lines
xen/include/asm-x86/hvm/hvm.h +0
-0@@ -228,7 +228,8 @@ int prepare_ring_for_helper(struct domain *d,unsigned long gmfn,
Quoted 3 lines
xen/include/asm-x86/hvm/hvm.h +0
-0struct page_info **_page, void **_va);void destroy_ring_for_helper (void **_va,struct page_info *page);Quoted 8 lines
Quoted 6 lines
xen/include/asm-x86/hvm/hvm.h int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, · line 231
Quoted 2 lines
xen/include/asm-x86/hvm/hvm.h +1
-1-bool_t hvm_send_assist_req (struct vcpu *v,const ioreq_t *p); +bool_t hvm_send_assist_req (struct vcpu *v,ioreq_t *p);Any reason you couldn't avoid adding the const in one of the earlier patches?
You asked for it in a previous review. I'm happy to lose the const again.
If it doesn't persist through the series, there's little point in adding it.
Quoted 4 lines
Quoted 3 lines
And for this to be usable with other architectures that may have address spaces other than memory and I/O ports it would seem desirable to not consider this a boolean, but an enumerator.
Quoted 9 lines
Quoted 1 line
Maybe it would be better to consolidate io ranges and pci devs then and
the
Quoted 4 lines
existing ioreq type values in the interface. I.e:
#define
IOREQ_TYPE_PIO0 /* pio */
#defineIOREQ_TYPE_COPY1 /* mmio ops */Right, except that "COPY" is sort of odd here - why not "MMIO"?
Good question. Historical I imagine. I prefer the term MMIO but changing the ioreq header would probably break many things so I's aim to #include it and then do something like
#define RANGE_TYPE_PORTIO (IOREQ_TYPE_PIO)
#define RANGE_TYPE_MMIO (IOREQ_TYPE_COPY)
Etc.
Paul
Quoted 1 line
Jan
Re: [PATCH v4 5/8] ioreq-server: add support for multiple servers
In reply to Jan BeulichQuoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 7 lines
Quoted 1 line · On 09.04.14 at 15:32, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Also, I didn't see a limit being enforced on the number of elements that can be added to these lists, yet allowing this to be unlimited is a latent security issue.
Quoted 6 lines
Quoted 2 lines
Guest domains cannot add to the lists, only the emulating domain, but if that is unprivileged then, yes, that is a security issue.
And hence it needs to be fixed, or the operation added to the list of disaggregation-unsafe ones (which XSA-77 added). I'd clearly favor the former...
and I will require it.
Quoting from the changelog of the XSA-77 patch:
It is expected that these lists will be whittled away as each interface is audited for safety.
New interfaces should be expected to be safe when introduced (IOW the list should never be expanded).
Ian.
PATCH v4 6/8 ioreq-server: remove p2m entries when server is enabled
In reply to Paul DurrantFor secondary servers, add a hvm op to enable/disable the server. The server will not accept IO until it is enabled and the act of enabling the server removes its pages from the guest p2m, thus preventing the guest from directly mapping the pages and synthesizing ioreqs.
--- tools/libxc/xc_domain.c | 24 ++++++++ tools/libxc/xenctrl.h | 5 ++ xen/arch/x86/hvm/hvm.c | 115 +++++++++++++++++++++++++++++++++++++- xen/include/asm-x86/hvm/domain.h | 1 + xen/include/public/hvm/hvm_op.h | 33 +++++++---- 5 files changed, 164 insertions(+), 14 deletions(-)
tools/libxc/xc_domain.c +24 -0
@@ -1459,6 +1459,30 @@ int xc_hvm_destroy_ioreq_server(xc_interface *xch,return rc; } +int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_set_ioreq_server_state_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_set_ioreq_server_state; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->enabled = enabled; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +} +int xc_domain_setdebugging (xc_interface *xch,uint32_t domid,unsigned int enable)
tools/libxc/xenctrl.h +5 -0
@@ -1843,6 +1843,11 @@ int xc_hvm_destroy_ioreq_server(xc_interface *xch,domid_t domid, ioservid_t id); +int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled); +/* HVM guest pass-through */ int xc_assign_device(xc_interface *xch, uint32_t domid,
xen/arch/x86/hvm/hvm.c +113 -2
176 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +1 -0
@@ -79,6 +79,7 @@ struct hvm_ioreq_server {struct list_head mmio_range_list;struct list_head portio_range_list;struct list_head pcidev_list; +bool_t enabled; };struct hvm_domain {
xen/include/public/hvm/hvm_op.h +21 -12
@@ -296,10 +296,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);#define HVMOP_map_io_range_to_ioreq_server 19struct xen_hvm_map_io_range_to_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ -int is_mmio;/* IN - MMIO or port IO? */ -uint64_aligned_t start, end;/* IN - inclusive start and end of range */ +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +int is_mmio;/* IN - MMIO or port IO? */ +uint64_aligned_t start, end;/* IN - inclusive start and end of range */ };typedef struct xen_hvm_map_io_range_to_ioreq_server xen_hvm_map_io_range_to_ioreq_server_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_map_io_range_to_ioreq_server_t);
@@ -316,30 +316,39 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_unmap_io_range_from_ioreq_server_t);#define HVMOP_map_pcidev_to_ioreq_server 21struct xen_hvm_map_pcidev_to_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ -uint16_t bdf;/* IN - PCI bus/dev/func */ +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +uint16_t bdf;/* IN - PCI bus/dev/func */ };typedef struct xen_hvm_map_pcidev_to_ioreq_server xen_hvm_map_pcidev_to_ioreq_server_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_map_pcidev_to_ioreq_server_t);#define HVMOP_unmap_pcidev_from_ioreq_server 22struct xen_hvm_unmap_pcidev_from_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ -uint16_t bdf;/* IN - PCI bus/dev/func */ +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +uint16_t bdf;/* IN - PCI bus/dev/func */ };typedef struct xen_hvm_unmap_pcidev_from_ioreq_server xen_hvm_unmap_pcidev_from_ioreq_server_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_unmap_pcidev_from_ioreq_server_t);#define HVMOP_destroy_ioreq_server 23struct xen_hvm_destroy_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* IN - server id */ +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - server id */ };typedef struct xen_hvm_destroy_ioreq_server xen_hvm_destroy_ioreq_server_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_destroy_ioreq_server_t); +#define HVMOP_set_ioreq_server_state 24 +struct xen_hvm_set_ioreq_server_state { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - server id */ +uint8_t enabled;/* IN - enabled? */ +}; +typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_state_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_ioreq_server_state_t); +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
Signature · 1 line
1.7.10.4
Re: [PATCH v4 6/8] ioreq-server: remove p2m entries when server is enabled
Quoted 39 lines · Paul Durrant
For secondary servers, add a hvm op to enable/disable the server. The server will not accept IO until it is enabled and the act of enabling the server removes its pages from the guest p2m, thus preventing the guest from directly mapping the pages and synthesizing ioreqs.
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>--- tools/libxc/xc_domain.c | 24 ++++++++ tools/libxc/xenctrl.h | 5 ++ xen/arch/x86/hvm/hvm.c | 115 +++++++++++++++++++++++++++++++++++++- xen/include/asm-x86/hvm/domain.h | 1 + xen/include/public/hvm/hvm_op.h | 33 +++++++---- 5 files changed, 164 insertions(+), 14 deletions(-)tools/libxc/xc_domain.c +13
-0@@ -1459,6 +1459,30 @@ int xc_hvm_destroy_ioreq_server(xc_interface *xch,return rc; } +int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_set_ioreq_server_state_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; +
tools/libxc/xc_domain.c int xc_hvm_destroy_ioreq_server(xc_interface *xch, · line 1484
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+ hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_set_ioreq_server_state; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->enabled = enabled; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +}
Newlines for clarity please.
I'm not really looking at the actual interface here. I'm assuming they are a pretty straight exposure of the underlying hypercall and relying on the hypervisor guys to agree that is a sane interface.
Quoted 6 lines
xen/include/public/hvm/hvm_op.h +0
-0@@ -296,10 +296,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);
xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t); · line 302
Quoted 10 lines
xen/include/public/hvm/hvm_op.h +4
-4#define HVMOP_map_io_range_to_ioreq_server 19struct xen_hvm_map_io_range_to_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ -int is_mmio;/* IN - MMIO or port IO? */ -uint64_aligned_t start, end;/* IN - inclusive start and end of range */ +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server */ +int is_mmio;/* IN - MMIO or port IO? */ +uint64_aligned_t start, end;/* IN - inclusive start and end of range */
There seems to be a lot of gratuitous whitespace changes in this patch. Shouldn't most of these be folded into the previous patch which introduced things so that happens with the correct indentation?
Ian.
Re: [PATCH v4 6/8] ioreq-server: remove p2m entries when server is enabled
Quoted 56 lines
-----Original Message-----
From: Ian Campbell
Sent: 07 April 2014 17:01
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 6/8] ioreq-server: remove p2m entries when server is enabledQuoted 3 lines · Paul Durrant
For secondary servers, add a hvm op to enable/disable the server. The server will not accept IO until it is enabled and the act of enabling the server removes its pages from the guest p2m, thus preventing the
guest
Quoted 11 lines
from directly mapping the pages and synthesizing ioreqs.
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>--- tools/libxc/xc_domain.c | 24 ++++++++ tools/libxc/xenctrl.h | 5 ++ xen/arch/x86/hvm/hvm.c | 115+++++++++++++++++++++++++++++++++++++-
tools/libxc/xc_domain.c int xc_hvm_destroy_ioreq_server(xc_interface
Quoted 9 lines
xen/include/asm-x86/hvm/domain.h | 1 + xen/include/public/hvm/hvm_op.h | 33 +++++++---- 5 files changed, 164 insertions(+), 14 deletions(-)tools/libxc/xc_domain.c +0
-0@@ -1459,6 +1459,30 @@ int xc_hvm_destroy_ioreq_server(xc_interface*xch,
tools/libxc/xc_domain.c int xc_hvm_destroy_ioreq_server(xc_interface *xch,
Quoted 10 lines
tools/libxc/xc_domain.c +7
-0return rc; } +int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled) +{ +DECLARE_HYPERCALL ; + DECLARE_HYPERCALL_BUFFER(xen_hvm_set_ioreq_server_state_t,arg);
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_set_ioreq_server_state; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid;
Quoted 9 lines
tools/libxc/xc_domain.c int xc_hvm_destroy_ioreq_server(xc_interface *xch, · line 1484
Quoted 6 lines
tools/libxc/xc_domain.c +6
-0+ arg->id = id; + arg->enabled = enabled; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +}Newlines for clarity please.
Sure.
Quoted 20 lines
I'm not really looking at the actual interface here. I'm assuming they are a pretty straight exposure of the underlying hypercall and relying on the hypervisor guys to agree that is a sane interface.
Review
Quoted 1 line
(quoted diff) +0
-0
b/xen/include/public/hvm/hvm_op.hxen/include/public/hvm/hvm_op.h
Quoted 4 lines
index c6ceea5..a39290e 100644
xen/include/public/hvm/hvm_op.h +0
-0@@ -296,10 +296,10 @@
DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);
Quoted 5 lines
xen/include/public/hvm/hvm_op.h +0
-2#define HVMOP_map_io_range_to_ioreq_server 19struct xen_hvm_map_io_range_to_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* IN - handle from
HVMOP_register_ioreq_server*/xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);
Quoted 4 lines
xen/include/public/hvm/hvm_op.h +2
-2-int is_mmio;/* IN - MMIO or port IO? */ -uint64_aligned_t start, end;/* IN - inclusive start and end of range */ +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - handle from HVMOP_register_ioreq_server
Quoted 8 lines
*/
xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t); · line 302
Quoted 2 lines
xen/include/public/hvm/hvm_op.h +2
-0+int is_mmio;/* IN - MMIO or port IO? */ +uint64_aligned_t start, end;/* IN - inclusive start and end of range */ There seems to be a lot of gratuitous whitespace changes in this patch. Shouldn't most of these be folded into the previous patch which introduced things so that happens with the correct indentation?
Indeed they should. Emacs must have been playing tricks on me.
Paul
Re: [PATCH v4 6/8] ioreq-server: remove p2m entries when server is enabled
In reply to Paul DurrantQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
For secondary servers, add a hvm op to enable/disable the server. The server will not accept IO until it is enabled and the act of enabling the server removes its pages from the guest p2m, thus preventing the guest from directly mapping the pages and synthesizing ioreqs.
So why do these pages get put into the physmap in the first place?
Quoted 9 lines
tools/libxc/xc_domain.c +9
-0+int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_set_ioreq_server_state_t, arg); +int rc; +
tools/libxc/xc_domain.c int xc_hvm_destroy_ioreq_server(xc_interface *xch, · line 1480
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+ arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_set_ioreq_server_state; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->enabled = enabled;
Truncating int to uint8_t.
xen/arch/x86/hvm/hvm.c static void hvm_destroy_ioreq_server(struct domain *d, ioservid_t id) · line 1038
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +1
-1@@ -996,7 +1035,7 @@ static void hvm_destroy_ioreq_server(struct domain *d, ioservid_t id) --d->arch.hvm_domain.ioreq_server_count;list_del_init (&s->list_entry); - +
Stray white space cleanup (should be done right in the patch adding that code).
Quoted 9 lines
xen/arch/x86/hvm/hvm.c +9
-0+static int hvmop_set_ioreq_server_state ( +XEN_GUEST_HANDLE_PARAM (xen_hvm_set_ioreq_server_state_t) uop) +{ +xen_hvm_set_ioreq_server_state_t op; +struct domain *d; +int rc; + +if (copy_from_guest (&op, uop,1 ) ) +return -EFAULT ;
xen/arch/x86/hvm/hvm.c static int hvmop_unmap_pcidev_from_ioreq_server( · line 5427
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+ + rc =rcu_lock_remote_domain_by_id (op.domid, &d); +if ( rc !=0 ) +return rc; + + rc = -EINVAL ; +if ( !is_hvm_domain (d) ) + goto out; + + rc =hvm_set_ioreq_server_state (d, op.id, op.enabled);
So you're converting uint8_t to bool_t here, which presently seems to do what you want. But I think you'd be better of using !! here.
Also, you're pretty consistently naming the field/variable "enabled" rather than "enable", despite it being a transition you're invoking rather than obtaining state.
Jan
Re: [PATCH v4 6/8] ioreq-server: remove p2m entries when server is enabled
Quoted 66 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 April 2014 13:21
To: Paul Durrant
Cc: Ian Campbell; Ian Jackson; Stefano Stabellini; [email protected]
Subject: Re: [PATCH v4 6/8] ioreq-server: remove p2m entries when server is enabledQuoted 4 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
For secondary servers, add a hvm op to enable/disable the server. The server will not accept IO until it is enabled and the act of enabling the server removes its pages from the guest p2m, thus preventing the
guest
Quoted 1 line
from directly mapping the pages and synthesizing ioreqs.
So why do these pages get put into the physmap in the first place?
tools/libxc/xc_domain.c int xc_hvm_destroy_ioreq_server(xc_interface *xch,
Quoted 7 lines
tools/libxc/xc_domain.c +7
-0+int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled) +{ +DECLARE_HYPERCALL ; + DECLARE_HYPERCALL_BUFFER(xen_hvm_set_ioreq_server_state_t,arg);
tools/libxc/xc_domain.c int xc_hvm_destroy_ioreq_server(xc_interface *xch, · line 1480
Quoted 12 lines
tools/libxc/xc_domain.c +12
-0+int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_set_ioreq_server_state; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->id = id; + arg->enabled = enabled;Truncating int to
uint8_t.Review static void hvm_destroy_ioreq_server(struct
Quoted 1 line
(quoted diff) +0
-0@@ -996,7 +1035,7 @@ static void hvm_destroy_ioreq_server(structdomain *d,
ioservid_tid)xen/arch/x86/hvm/hvm.c static void hvm_destroy_ioreq_server(struct domain *d, ioservid_t id) · line 1038
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1
-1--d->arch.hvm_domain.ioreq_server_count;list_del_init (&s->list_entry); - +Stray white space cleanup (should be done right in the patch adding that code).
Review static void hvm_destroy_ioreq_server(struct · line 1039
Quoted 2 lines
(quoted diff) +2
-0+static int hvmop_set_ioreq_server_state( + XEN_GUEST_HANDLE_PARAM(xen_hvm_set_ioreq_server_state_t)uop)
Quoted 12 lines
xen/arch/x86/hvm/hvm.c +12
-0+{ +xen_hvm_set_ioreq_server_state_t op; +struct domain *d; +int rc; + +if (copy_from_guest (&op, uop,1 ) ) +return -EFAULT ; + + rc =rcu_lock_remote_domain_by_id (op.domid, &d); +if ( rc !=0 ) +return rc; +
Quoted 9 lines
xen/arch/x86/hvm/hvm.c static int hvmop_unmap_pcidev_from_ioreq_server( · line 5427
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +5
-0+ rc = -EINVAL ; +if ( !is_hvm_domain (d) ) + goto out; + + rc =hvm_set_ioreq_server_state (d, op.id, op.enabled);So you're converting
uint8_ttobool_there, which presently seems to do what you want. But I think you'd be better of using !! here.
Ok.
Quoted 4 lines
Also, you're pretty consistently naming the field/variable "enabled" rather than "enable", despite it being a transition you're invoking rather than obtaining state.
Yes, because I'm setting whether the server state is 'enabled' or not. The value of the boolean is the end state not the transition, so it's correct to use the adjective rather than the verb.
Paul
Quoted 1 line
Jan
Re: [PATCH v4 6/8] ioreq-server: remove p2m entries when server is enabled
Quoted 9 lines
Quoted 5 lines
Quoted 1 line · On 09.04.14 at 15:36, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Also, you're pretty consistently naming the field/variable "enabled" rather than "enable", despite it being a transition you're invoking rather than obtaining state.Yes, because I'm setting whether the server state is 'enabled' or not. The value of the boolean is the end state not the transition, so it's correct to use the adjective rather than the verb.
Hmm, that's not my way of thinking with operations like this. To me, the operation is to enable (or disable) the server, not to set its state to enabled (or disabled). But yes, one may view it your way too, even if I would think that's not commonly done (and I think I saw "enable"s too somewhere in the series, and maybe even in the same patch, so I'd be inclined to ask for consistency even if our ways of thinking of these operations differ).
Jan
PATCH v4 7/8 ioreq-server: make buffered ioreq handling optional
In reply to Paul DurrantSome emulators will only register regions that require non-buffered access. (In practice the only region that a guest uses buffered access for today is the VGA aperture from 0xa0000-0xbffff). This patch therefore makes allocation of the buffered ioreq page and event channel optional for secondary ioreq servers.
If a guest attempts buffered access to an ioreq server that does not support it, the access will be handled via the normal synchronous path.
--- tools/libxc/xc_domain.c | 2 ++ tools/libxc/xenctrl.h | 1 + xen/arch/x86/hvm/hvm.c | 74 +++++++++++++++++++++++++++------------ xen/include/public/hvm/hvm_op.h | 5 +-- 4 files changed, 58 insertions(+), 24 deletions(-)
tools/libxc/xc_domain.c +2 -0
@@ -1286,6 +1286,7 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned longint xc_hvm_create_ioreq_server (xc_interface *xch,domid_t domid, +int handle_bufioreq,ioservid_t *id) {DECLARE_HYPERCALL ;
@@ -1300,6 +1301,7 @@ int xc_hvm_create_ioreq_server(xc_interface *xch, hypercall.arg[0 ] = HVMOP_create_ioreq_server; hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); arg->domid = domid; + arg->handle_bufioreq = handle_bufioreq; rc =do_xen_hypercall (xch, &hypercall); *id = arg->id;xc_hypercall_buffer_free (xch, arg);
tools/libxc/xenctrl.h +1 -0
@@ -1807,6 +1807,7 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned longint xc_hvm_create_ioreq_server (xc_interface *xch,domid_t domid, +int handle_bufioreq,ioservid_t *id); int xc_hvm_get_ioreq_server_info(xc_interface *xch,
xen/arch/x86/hvm/hvm.c +52 -22
192 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +3 -2
@@ -277,8 +277,9 @@ DEFINE_XEN_GUEST_HANDLE(ioservid_t);#define HVMOP_create_ioreq_server 17struct xen_hvm_create_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* OUT - server id */ +domid_t domid;/* IN - domain to be serviced */ +uint8_t handle_bufioreq;/* IN - should server handle buffered ioreqs */ +ioservid_t id;/* OUT - server id */ };typedef struct xen_hvm_create_ioreq_server xen_hvm_create_ioreq_server_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_create_ioreq_server_t);
Signature · 1 line
1.7.10.4
Re: [PATCH v4 7/8] ioreq-server: make buffered ioreq handling optional
Quoted 8 lines · Paul Durrant
Some emulators will only register regions that require non-buffered access. (In practice the only region that a guest uses buffered access for today is the VGA aperture from 0xa0000-0xbffff). This patch therefore makes allocation of the buffered ioreq page and event channel optional for secondary ioreq servers.
If a guest attempts buffered access to an ioreq server that does not support it, the access will be handled via the normal synchronous path.
In terms of the guest PFN space do the magic PFNs get packed together or are there holes? (Mostly just curious...)
Re: [PATCH v4 7/8] ioreq-server: make buffered ioreq handling optional
Quoted 15 lines
-----Original Message-----
From: Ian Campbell
Sent: 07 April 2014 17:07
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 7/8] ioreq-server: make buffered ioreq handling optionalQuoted 6 lines · Paul Durrant
Some emulators will only register regions that require non-buffered access. (In practice the only region that a guest uses buffered access for today is the VGA aperture from 0xa0000-0xbffff). This patch therefore makes allocation of the buffered ioreq page and event channel optional for secondary ioreq servers.
Quoted 6 lines
Quoted 2 lines
If a guest attempts buffered access to an ioreq server that does not support it, the access will be handled via the normal synchronous path.
In terms of the guest PFN space do the magic PFNs get packed together or are there holes? (Mostly just curious...)
There can be holes. The allocator is just a dead-simple bitmap test-and-set/clear so which actual PFNs get assigned to which ioreq server depends on the sequence of creation/destruction.
Paul
PATCH v4 8/8 ioreq-server: bring the PCI hotplug controller implementation into Xen
In reply to Paul DurrantBecause we may now have more than one emulator, the implementation of the PCI hotplug controller needs to be done by Xen. Happily the code is very short and simple and it also removes the need for a different ACPI DSDT when using different variants of QEMU.
As a precaution, we obscure the IO ranges used by QEMU traditional's gpe and hotplug controller implementations to avoid the possibility of it raising an SCI which will never be cleared.
VMs started on an older host and then migrated in will not use the in-Xen controller as the AML may still point at QEMU traditional's hotplug controller implementation. This means hotplug ops will fail with EOPNOTSUPP and it is up to the caller to decide whether this is a problem or not. libxl will ignore EOPNOTSUPP as it is always hotplugging via QEMU so it does not matter whether it is Xen or QEMU providing the implementation.
--- tools/firmware/hvmloader/acpi/mk_dsdt.c | 191 +++++-------------------- tools/libxc/xc_domain.c | 24 ++++ tools/libxc/xenctrl.h | 9 ++ tools/libxl/libxl_pci.c | 15 ++ xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hotplug.c | 231 +++++++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 40 ++++++ xen/include/asm-x86/hvm/domain.h | 11 ++ xen/include/asm-x86/hvm/io.h | 8 +- xen/include/public/hvm/hvm_op.h | 9 ++ xen/include/public/hvm/ioreq.h | 4 + 11 files changed, 387 insertions(+), 156 deletions(-) create mode 100644 xen/arch/x86/hvm/hotplug.c
tools/firmware/hvmloader/acpi/mk_dsdt.c +36 -155
@@ -8,11 +8,6 @@static unsigned int indent_level; -typedef enum dm_version { -QEMU_XEN_TRADITIONAL , -QEMU_XEN , -}dm_version ; -static void indent (void ) {unsigned int i;
@@ -58,28 +53,6 @@ static void pop_block(void)printf ("}\n" ); } -static void pci_hotplug_notify (unsigned int slt) -{ -stmt ("Notify" ,"\\_SB.PCI0.S%02X, EVT" , slt); -} - -static void decision_tree ( -unsigned int s,unsigned int e,char *var,void (*leaf)(unsigned int )) -{ -if ( s == (e-1 ) ) - { - (*leaf)(s); -return ; - } - -push_block ("If" ,"And(%s, 0x%02x)" , var, (e-s)/2 ); -decision_tree ((s+e)/2 , e, var, leaf); -pop_block (); -push_block ("Else" ,NULL ); -decision_tree (s, (s+e)/2 , var, leaf); -pop_block (); -} -static struct option options[] = { {"maxcpu" ,1 ,0 ,'c' }, {"dm-version" ,1 ,0 ,'q' },
@@ -89,7 +62,6 @@ static struct option options[] = {int main (int argc,char **argv) {unsigned int slot, dev, intx, link, cpu, max_cpus =HVM_MAX_VCPUS ; -dm_version dm_version =QEMU_XEN_TRADITIONAL ;for ( ; ; ) {
@@ -116,14 +88,7 @@ int main(int argc, char **argv)break ; }case 'q' : -if (strcmp (optarg,"qemu-xen" ) ==0 ) { - dm_version =QEMU_XEN ; - }else if (strcmp (optarg,"qemu-xen-traditional" ) ==0 ) { - dm_version =QEMU_XEN_TRADITIONAL ; - }else { -fprintf (stderr,"Unknown device model version `%s'.\n" , optarg); -return -1 ; - } +/* qemu version - no longer used */ break ;default :return -1 ;
@@ -222,11 +187,8 @@ int main(int argc, char **argv)/* Define GPE control method. */ push_block ("Scope" ,"\\_GPE" ); -if (dm_version ==QEMU_XEN_TRADITIONAL ) { -push_block ("Method" ,"_L02" ); - }else { -push_block ("Method" ,"_E02" ); - } +push_block ("Method" ,"_L02" ); +stmt ("Return" ,"\\_SB.PRSC()" );pop_block ();pop_block ();
@@ -237,23 +199,17 @@ int main(int argc, char **argv)push_block ("Scope" ,"\\_SB.PCI0" );/* -* Reserve the IO port ranges [0x10c0, 0x1101] and [0xb044, 0xb047]. -* Or else, for a hotplugged-in device, the port IO BAR assigned -* by guest OS may conflict with the ranges here. +* Reserve the IO port ranges used by PCI hotplug controller or else, +* for a hotplugged-in device, the port IO BAR assigned by guest OS may +* conflict with the ranges here. */ push_block ("Device" ,"HP0" ); {stmt ("Name" ,"_HID, EISAID(\"PNP0C02\")" ); -if (dm_version ==QEMU_XEN_TRADITIONAL ) { -stmt ("Name" ,"_CRS, ResourceTemplate() {" -" IO (Decode16, 0x10c0, 0x10c0, 0x00, 0x82)" -" IO (Decode16, 0xb044, 0xb044, 0x00, 0x04)" -"}" ); - }else { -stmt ("Name" ,"_CRS, ResourceTemplate() {" -" IO (Decode16, 0xae00, 0xae00, 0x00, 0x10)" -" IO (Decode16, 0xb044, 0xb044, 0x00, 0x04)" -"}" ); - } +stmt ("Name" ,"_CRS, ResourceTemplate() {" +" IO (Decode16, 0x10c0, 0x10c0, 0x00, 0x82)" +" IO (Decode16, 0xb044, 0xb044, 0x00, 0x04)" +" IO (Decode16, 0xae00, 0xae00, 0x00, 0x10)" +"}" ); }pop_block ();/*** PCI-ISA link definitions ***/
@@ -322,64 +278,21 @@ int main(int argc, char **argv) dev, intx, ((dev*4+dev/8+intx)&31)+16);printf ("})\n" ); -/* -* Each PCI hotplug slot needs at least two methods to handle -* the ACPI event: -* _EJ0: eject a device -* _STA: return a device's status, e.g. enabled or removed -* -* Eject button would generate a general-purpose event, then the -* control method for this event uses Notify() to inform OSPM which -* action happened and on which device. -* -* Pls. refer "6.3 Device Insertion, Removal, and Status Objects" -* in ACPI spec 3.0b for details. -* -* QEMU provides a simple hotplug controller with some I/O to handle -* the hotplug action and status, which is beyond the ACPI scope. -*/ -if (dm_version ==QEMU_XEN_TRADITIONAL ) { -for ( slot =0 ; slot <0x100 ; slot++ ) - { -push_block ("Device" ,"S%02X" , slot); -/* _ADR == dev:fn (16:16) */ -stmt ("Name" ,"_ADR, 0x%08x" , ((slot & ~7 ) <<13 ) | (slot &7 )); -/* _SUN == dev */ -stmt ("Name" ,"_SUN, 0x%08x" , slot >>3 ); -push_block ("Method" ,"_EJ0, 1" ); -stmt ("Store" ,"0x%02x, \\_GPE.DPT1" , slot); -stmt ("Store" ,"0x88, \\_GPE.DPT2" ); -stmt ("Store" ,"0x%02x, \\_GPE.PH%02X" ,/* eject */ - (slot &1 ) ?0x10 :0x01 , slot & ~1 ); -pop_block (); -push_block ("Method" ,"_STA, 0" ); -stmt ("Store" ,"0x%02x, \\_GPE.DPT1" , slot); -stmt ("Store" ,"0x89, \\_GPE.DPT2" ); -if ( slot &1 ) -stmt ("ShiftRight" ,"0x4, \\_GPE.PH%02X, Local1" , slot & ~1 ); -else -stmt ("And" ,"\\_GPE.PH%02X, 0x0f, Local1" , slot & ~1 ); -stmt ("Return" ,"Local1" );/* IN status as the _STA */ -pop_block (); -pop_block (); - } - }else { -stmt ("OperationRegion" ,"SEJ, SystemIO, 0xae08, 0x04" ); -push_block ("Field" ,"SEJ, DWordAcc, NoLock, WriteAsZeros" ); -indent ();printf ("B0EJ, 32,\n" ); -pop_block (); +stmt ("OperationRegion" ,"SEJ, SystemIO, 0xae08, 0x04" ); +push_block ("Field" ,"SEJ, DWordAcc, NoLock, WriteAsZeros" ); +indent ();printf ("B0EJ, 32,\n" ); +pop_block (); -/* hotplug_slot */ -for (slot =1 ; slot <=31 ; slot++) { -push_block ("Device" ,"S%i" , slot); { -stmt ("Name" ,"_ADR, %#06x0000" , slot); -push_block ("Method" ,"_EJ0,1" ); { -stmt ("Store" ,"ShiftLeft(1, %#06x), B0EJ" , slot); -stmt ("Return" ,"0x0" ); - }pop_block (); -stmt ("Name" ,"_SUN, %i" , slot); +/* hotplug_slot */ +for (slot =1 ; slot <=31 ; slot++) { +push_block ("Device" ,"S%i" , slot); { +stmt ("Name" ,"_ADR, %#06x0000" , slot); +push_block ("Method" ,"_EJ0,1" ); { +stmt ("Store" ,"ShiftLeft(1, %#06x), B0EJ" , slot); +stmt ("Return" ,"0x0" ); }pop_block (); - } +stmt ("Name" ,"_SUN, %i" , slot); + }pop_block (); }pop_block ();
@@ -389,26 +302,11 @@ int main(int argc, char **argv)/**** GPE start ****/ push_block ("Scope" ,"\\_GPE" ); -if (dm_version ==QEMU_XEN_TRADITIONAL ) { -stmt ("OperationRegion" ,"PHP, SystemIO, 0x10c0, 0x82" ); - -push_block ("Field" ,"PHP, ByteAcc, NoLock, Preserve" ); -indent ();printf ("PSTA, 8,\n" );/* hotplug controller event reg */ -indent ();printf ("PSTB, 8,\n" );/* hotplug controller slot reg */ -for ( slot =0 ; slot <0x100 ; slot +=2 ) - { -indent (); -/* Each hotplug control register manages a pair of pci functions. */ -printf ("PH%02X, 8,\n" , slot); - } -pop_block (); - }else { -stmt ("OperationRegion" ,"PCST, SystemIO, 0xae00, 0x08" ); -push_block ("Field" ,"PCST, DWordAcc, NoLock, WriteAsZeros" ); -indent ();printf ("PCIU, 32,\n" ); -indent ();printf ("PCID, 32,\n" ); -pop_block (); - } +stmt ("OperationRegion" ,"PCST, SystemIO, 0xae00, 0x08" ); +push_block ("Field" ,"PCST, DWordAcc, NoLock, WriteAsZeros" ); +indent ();printf ("PCIU, 32,\n" ); +indent ();printf ("PCID, 32,\n" ); +pop_block ();stmt ("OperationRegion" ,"DG1, SystemIO, 0xb044, 0x04" );
@@ -416,33 +314,16 @@ int main(int argc, char **argv)indent ();printf ("DPT1, 8, DPT2, 8\n" );pop_block (); -if (dm_version ==QEMU_XEN_TRADITIONAL ) { -push_block ("Method" ,"_L03, 0, Serialized" ); -/* Detect slot and event (remove/add). */ -stmt ("Name" ,"SLT, 0x0" ); -stmt ("Name" ,"EVT, 0x0" ); -stmt ("Store" ,"PSTA, Local1" ); -stmt ("And" ,"Local1, 0xf, EVT" ); -stmt ("Store" ,"PSTB, Local1" );/* XXX: Store (PSTB, SLT) ? */ -stmt ("And" ,"Local1, 0xff, SLT" ); -/* Debug */ -stmt ("Store" ,"SLT, DPT1" ); -stmt ("Store" ,"EVT, DPT2" ); -/* Decision tree */ -decision_tree (0x00 ,0x100 ,"SLT" , pci_hotplug_notify); +push_block ("Method" ,"_E01" ); +for (slot =1 ; slot <=31 ; slot++) { +push_block ("If" ,"And(PCIU, ShiftLeft(1, %i))" , slot); +stmt ("Notify" ,"\\_SB.PCI0.S%i, 1" , slot);pop_block (); - }else { -push_block ("Method" ,"_E01" ); -for (slot =1 ; slot <=31 ; slot++) { -push_block ("If" ,"And(PCIU, ShiftLeft(1, %i))" , slot); -stmt ("Notify" ,"\\_SB.PCI0.S%i, 1" , slot); -pop_block (); -push_block ("If" ,"And(PCID, ShiftLeft(1, %i))" , slot); -stmt ("Notify" ,"\\_SB.PCI0.S%i, 3" , slot); -pop_block (); - } +push_block ("If" ,"And(PCID, ShiftLeft(1, %i))" , slot); +stmt ("Notify" ,"\\_SB.PCI0.S%i, 3" , slot);pop_block (); } +pop_block ();pop_block ();/**** GPE end ****/
tools/libxc/xc_domain.c +24 -0
@@ -1485,6 +1485,30 @@ int xc_hvm_set_ioreq_server_state(xc_interface *xch,return rc; } +int xc_hvm_pci_hotplug (xc_interface *xch, +domid_t domid, +uint32_t slot, +int enable) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_pci_hotplug_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_pci_hotplug; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->slot = slot; + arg->enable = enable; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc; +} +int xc_domain_setdebugging (xc_interface *xch,uint32_t domid,unsigned int enable)
tools/libxc/xenctrl.h +9 -0
@@ -1849,6 +1849,15 @@ int xc_hvm_set_ioreq_server_state(xc_interface *xch,ioservid_t id, int enabled); +/* +* Hotplug controller API +*/ + +int xc_hvm_pci_hotplug (xc_interface *xch, +domid_t domid, +uint32_t slot, +int enable); +/* HVM guest pass-through */ int xc_assign_device(xc_interface *xch, uint32_t domid,
tools/libxl/libxl_pci.c +15 -0
@@ -867,6 +867,13 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i }if ( rc )return ERROR_FAIL ; + + rc =xc_hvm_pci_hotplug (ctx->xch, domid, pcidev->dev,1 ); +if (rc <0 && errno !=EOPNOTSUPP ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"Error: xc_hvm_pci_hotplug enable failed" ); +return ERROR_FAIL ; + } +break ;case LIBXL_DOMAIN_TYPE_PV : {
@@ -1188,6 +1195,14 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, NULL, NULL, NULL) < 0) goto out_fail; + rc =xc_hvm_pci_hotplug (ctx->xch, domid, pcidev->dev,0 ); +if (rc <0 && errno !=EOPNOTSUPP ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR , +"Error: xc_hvm_pci_hotplug disable failed" ); + rc =ERROR_FAIL ; + goto out_fail; + } +switch (libxl__device_model_version_running (gc, domid)) {case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : rc =qemu_pci_remove_xenstore (gc, domid, pcidev, force);
xen/arch/x86/hvm/Makefile +1 -0
@@ -3,6 +3,7 @@ subdir-y += vmx obj-y += asid.o obj-y += emulate.o +obj-y += hotplug.o obj-y += hpet.o obj-y += hvm.o obj-y += i8254.o
xen/arch/x86/hvm/hotplug.c new file +231 -0
231 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +40 -0
@@ -1670,6 +1670,7 @@ void hvm_domain_destroy(struct domain *d)return ; hvm_funcs.domain_destroy (d); +gpe_deinit (d);rtc_deinit (d);stdvga_deinit (d);vioapic_deinit (d);
@@ -5487,6 +5488,31 @@ static int hvmop_destroy_ioreq_server(return rc; } +static int hvmop_pci_hotplug ( +XEN_GUEST_HANDLE_PARAM (xen_hvm_pci_hotplug_t) uop) +{ +xen_hvm_pci_hotplug_t op; +struct domain *d; +int rc; + +if (copy_from_guest (&op, uop,1 ) ) +return -EFAULT ; + + rc =rcu_lock_remote_domain_by_id (op.domid, &d); +if ( rc !=0 ) +return rc; + + rc = -EINVAL ; +if ( !is_hvm_domain (d) ) + goto out; + + rc =pci_hotplug (d, op.slot, op.enable); + +out: +rcu_unlock_domain (d); +return rc; +} +long do_hvm_op (unsigned long op,XEN_GUEST_HANDLE_PARAM (void ) arg) {
@@ -5535,6 +5561,11 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) guest_handle_cast(arg, xen_hvm_destroy_ioreq_server_t));break ; +case HVMOP_pci_hotplug: + rc =hvmop_pci_hotplug ( +guest_handle_cast (arg, xen_hvm_pci_hotplug_t)); +break ; +case HVMOP_set_param:case HVMOP_get_param: {
@@ -5714,6 +5745,15 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } d->arch.hvm_domain.ioreq_gmfn_count = a.value; + +/* +* Since secondary emulators are now possible, enable +* the PCI hotplug controller. +*/ + rc =gpe_init (d); +if ( rc == -EEXIST ) + rc =0 ; +break ; }
xen/include/asm-x86/hvm/domain.h +11 -0
@@ -82,6 +82,15 @@ struct hvm_ioreq_server {bool_t enabled; }; +struct hvm_hotplug { +uint8_t *gpe_sts; +uint8_t *gpe_en; + +/* PCI hotplug */ +uint32_t slot_up; +uint32_t slot_down; +}; +struct hvm_domain {/* Guest page range used for non-default ioreq servers */ unsigned long ioreq_gmfn_base;
@@ -99,6 +108,8 @@ struct hvm_domain {uint32_t pci_cf8;spinlock_t pci_lock; +struct hvm_hotplug hotplug; +struct pl_time pl_time;struct hvm_io_handler *io_handler;
xen/include/asm-x86/hvm/io.h +7 -1
@@ -25,7 +25,7 @@#include <public/hvm/ioreq.h> #include <public/event_channel.h> -#define MAX_IO_HANDLER 16 +#define MAX_IO_HANDLER 32#define HVM_PORTIO 0#define HVM_BUFFERED_IO 2
@@ -142,5 +142,11 @@ void stdvga_init(struct domain *d);void stdvga_deinit (struct domain *d);extern void hvm_dpci_msi_eoi (struct domain *d,int vector); + +int gpe_init (struct domain *d); +void gpe_deinit (struct domain *d); + +int pci_hotplug (struct domain *d,int slot,bool_t enable); +#endif /* __ASM_X86_HVM_IO_H__ */
xen/include/public/hvm/hvm_op.h +9 -0
@@ -350,6 +350,15 @@ struct xen_hvm_set_ioreq_server_state {typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_state_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_ioreq_server_state_t); +#define HVMOP_pci_hotplug 25 +struct xen_hvm_pci_hotplug { +domid_t domid;/* IN - domain to be serviced */ +uint8_t enable;/* IN - enable or disable? */ +uint32_t slot;/* IN - slot to enable/disable */ +}; +typedef struct xen_hvm_pci_hotplug xen_hvm_pci_hotplug_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_pci_hotplug_t); +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
xen/include/public/hvm/ioreq.h +4 -0
@@ -94,6 +94,8 @@ typedef struct buffered_iopage buffered_iopage_t;#define ACPI_PM_TMR_BLK_ADDRESS_V0 (ACPI_PM1A_EVT_BLK_ADDRESS_V0 + 0x08)#define ACPI_GPE0_BLK_ADDRESS_V0 (ACPI_PM_TMR_BLK_ADDRESS_V0 + 0x20)#define ACPI_GPE0_BLK_LEN_V0 0x08 +#define ACPI_PCI_HOTPLUG_ADDRESS_V0 0x10c0 +#define ACPI_PCI_HOTPLUG_LEN_V0 0x82/* NR_PHP_SLOT_REG in piix4acpi.c */ /* Version 1: Locations preferred by modern Qemu. */ #define ACPI_PM1A_EVT_BLK_ADDRESS_V1 0xb000
@@ -101,6 +103,8 @@ typedef struct buffered_iopage buffered_iopage_t;#define ACPI_PM_TMR_BLK_ADDRESS_V1 (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + 0x08)#define ACPI_GPE0_BLK_ADDRESS_V1 0xafe0#define ACPI_GPE0_BLK_LEN_V1 0x04 +#define ACPI_PCI_HOTPLUG_ADDRESS_V1 0xae00 +#define ACPI_PCI_HOTPLUG_LEN_V1 0x10/* Compatibility definitions for the default location (version 0). */ #define ACPI_PM1A_EVT_BLK_ADDRESS ACPI_PM1A_EVT_BLK_ADDRESS_V0
Signature · 1 line
1.7.10.4
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 9 lines · Paul Durrant
Because we may now have more than one emulator, the implementation of the PCI hotplug controller needs to be done by Xen. Happily the code is very short and simple and it also removes the need for a different ACPI DSDT when using different variants of QEMU.
As a precaution, we obscure the IO ranges used by QEMU traditional's gpe and hotplug controller implementations to avoid the possibility of it raising an SCI which will never be cleared.
Quoted 6 lines
VMs started on an older host and then migrated in will not use the in-Xen controller as the AML may still point at QEMU traditional's hotplug controller implementation. This means hotplug ops will fail with EOPNOTSUPP and it is up to the caller to decide whether this is a problem or not. libxl will ignore EOPNOTSUPP as it is always hotplugging via QEMU so it does not matter whether it is Xen or QEMU providing the implementation.
I don't follow the second half of this paragraph.
If it is always hotplugging via qemu where does it see EOPNOTSUPP from?
Also, if you are obscuring those regions now how does it continue to work?
Quoted 23 lines
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>--- tools/firmware/hvmloader/acpi/mk_dsdt.c | 191 +++++-------------------- tools/libxc/xc_domain.c | 24 ++++ tools/libxc/xenctrl.h | 9 ++ tools/libxl/libxl_pci.c | 15 ++ xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hotplug.c | 231 +++++++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 40 ++++++ xen/include/asm-x86/hvm/domain.h | 11 ++ xen/include/asm-x86/hvm/io.h | 8 +- xen/include/public/hvm/hvm_op.h | 9 ++ xen/include/public/hvm/ioreq.h | 4 + 11 files changed, 387 insertions(+), 156 deletions(-) create mode 100644 xen/arch/x86/hvm/hotplug.ctools/firmware/hvmloader/acpi/mk_dsdt.c +0
-0@@ -116,14 +88,7 @@ int main(int argc, char **argv)break ; }
tools/firmware/hvmloader/acpi/mk_dsdt.c int main(int argc, char **argv) · line 91
Quoted 10 lines
tools/firmware/hvmloader/acpi/mk_dsdt.c +1
-8case 'q' : -if (strcmp (optarg,"qemu-xen" ) ==0 ) { - dm_version =QEMU_XEN ; - }else if (strcmp (optarg,"qemu-xen-traditional" ) ==0 ) { - dm_version =QEMU_XEN_TRADITIONAL ; - }else { -fprintf (stderr,"Unknown device model version `%s'.\n" , optarg); -return -1 ; - } +/* qemu version - no longer used */
No need to keep this sort of legacy stuff in tools used solely by the build system. All uses of this option should be removed and it should be an error to use it.
Quoted 20 lines
tools/libxc/xc_domain.c +12
-0@@ -1485,6 +1485,30 @@ int xc_hvm_set_ioreq_server_state(xc_interface *xch,return rc; } +int xc_hvm_pci_hotplug (xc_interface *xch, +domid_t domid, +uint32_t slot, +int enable) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_pci_hotplug_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ;
tools/libxc/xc_domain.c int xc_hvm_set_ioreq_server_state(xc_interface *xch, · line 1509
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+ + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_pci_hotplug; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domid = domid; + arg->slot = slot; + arg->enable = enable; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc;
Newlines for clarity please.
tools/libxc/xenctrl.h int xc_hvm_set_ioreq_server_state(xc_interface *xch, · line 1855
Quoted 12 lines
tools/libxc/xenctrl.h +4
-0@@ -1849,6 +1849,15 @@ int xc_hvm_set_ioreq_server_state(xc_interface *xch,ioservid_t id, int enabled); +/* +* Hotplug controller API +*/ +
According to the commit message the error codes from this function have some pretty interesting semantics which should be documented IMHO. Either here or in xen/include/public.
Quoted 13 lines
tools/libxc/xenctrl.h +5
-0+int xc_hvm_pci_hotplug (xc_interface *xch, +domid_t domid, +uint32_t slot, +int enable); +/* HVM guest pass-through */ int xc_assign_device(xc_interface *xch, uint32_t domid,tools/libxl/libxl_pci.c +0
-0
tools/libxl/libxl_pci.c static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i · line 871
Quoted 5 lines
tools/libxl/libxl_pci.c +2
-0@@ -867,6 +867,13 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i }if ( rc )return ERROR_FAIL ; + + rc =xc_hvm_pci_hotplug (ctx->xch, domid, pcidev->dev,1 );
CTX->xch is somewhat preferred for new code.
tools/libxl/libxl_pci.c static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i · line 873
Quoted 2 lines
tools/libxl/libxl_pci.c +2
-0+if (rc <0 && errno !=EOPNOTSUPP ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"Error: xc_hvm_pci_hotplug enable failed" );
You can use the LOGE macro to shorten this line.
Hrm, so I didn't see anything on the restore side which handles the registration or not of the thing which would lead to EOPNOTSUPP vs success on a guest started on an older Xen. How does all that actually hang together?
Ian.
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 22 lines
-----Original Message-----
From: Ian Campbell
Sent: 07 April 2014 17:14
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into XenQuoted 1 line · Paul Durrant
Because we may now have more than one emulator, the implementation
of the
Quoted 11 lines
PCI hotplug controller needs to be done by Xen. Happily the code is very short and simple and it also removes the need for a different ACPI DSDT when using different variants of QEMU.
As a precaution, we obscure the IO ranges used by QEMU traditional's gpe and hotplug controller implementations to avoid the possibility of it raising an SCI which will never be cleared.
VMs started on an older host and then migrated in will not use the in-Xen controller as the AML may still point at QEMU traditional's hotplug controller implementation. This means hotplug ops will fail with
Quoted 9 lines
EOPNOTSUPP
Quoted 3 lines
and it is up to the caller to decide whether this is a problem or not. libxl will ignore EOPNOTSUPP as it is always hotplugging via QEMU so it does not matter whether it is Xen or QEMU providing the implementation.
I don't follow the second half of this paragraph.
If it is always hotplugging via qemu where does it see EOPNOTSUPP from?
Sorry, I should have said hotplug ops via libxc.
Quoted 3 lines
Also, if you are obscuring those regions now how does it continue to work?
We only obscure the old regions if we create the in-xen hotplug controller. This doesn't happen for migrated-in guests.
Quoted 30 lines
Quoted 5 lines
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>Quoted 7 lines
--- tools/firmware/hvmloader/acpi/mk_dsdt.c | 191 +++++-------------------- tools/libxc/xc_domain.c | 24 ++++ tools/libxc/xenctrl.h | 9 ++ tools/libxl/libxl_pci.c | 15 ++ xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hotplug.c | 231+++++++++++++++++++++++++++++++
Quoted 17 lines
xen/arch/x86/hvm/hvm.c | 40 ++++++ xen/include/asm-x86/hvm/domain.h | 11 ++ xen/include/asm-x86/hvm/io.h | 8 +- xen/include/public/hvm/hvm_op.h | 9 ++ xen/include/public/hvm/ioreq.h | 4 + 11 files changed, 387 insertions(+), 156 deletions(-) create mode 100644 xen/arch/x86/hvm/hotplug.ctools/firmware/hvmloader/acpi/mk_dsdt.c +0
-5@@ -116,14 +88,7 @@ int main(int argc, char **argv)break ; }case 'q' : -if (strcmp (optarg,"qemu-xen" ) ==0 ) { - dm_version =QEMU_XEN ; - }else if (strcmp (optarg,"qemu-xen-traditional" ) ==0 ) { - dm_version =QEMU_XEN_TRADITIONAL ; - }else {
Quoted 9 lines
tools/firmware/hvmloader/acpi/mk_dsdt.c int main(int argc, char **argv) · line 91
Quoted 4 lines
tools/firmware/hvmloader/acpi/mk_dsdt.c +1
-3-fprintf (stderr,"Unknown device model version `%s'.\n" , optarg); -return -1 ; - } +/* qemu version - no longer used */ No need to keep this sort of legacy stuff in tools used solely by the build system. All uses of this option should be removed and it should be an error to use it.
Ok.
Quoted 25 lines
tools/libxc/xc_domain.c int
Quoted 5 lines
tools/libxc/xc_domain.c +0
-0@@ -1485,6 +1485,30 @@ intxc_hvm_set_ioreq_server_state(xc_interface *xch,
Quoted 19 lines
tools/libxc/xc_domain.c +16
-0return rc; } +int xc_hvm_pci_hotplug (xc_interface *xch, +domid_t domid, +uint32_t slot, +int enable) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_pci_hotplug_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_pci_hotplug; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg);
Quoted 8 lines
tools/libxc/xc_domain.c int xc_hvm_set_ioreq_server_state(xc_interface *xch, · line 1509
Quoted 6 lines
tools/libxc/xc_domain.c +6
-0+ arg->domid = domid; + arg->slot = slot; + arg->enable = enable; + rc =do_xen_hypercall (xch, &hypercall); +xc_hypercall_buffer_free (xch, arg); +return rc;Newlines for clarity please.
Ok.
Quoted 10 lines
tools/libxc/xenctrl.h int
Quoted 6 lines
tools/libxc/xenctrl.h +0
-0@@ -1849,6 +1849,15 @@ intxc_hvm_set_ioreq_server_state(xc_interface *xch,
Quoted 3 lines
tools/libxc/xenctrl.h +0
-0ioservid_t id, int enabled);
Quoted 9 lines
tools/libxc/xenctrl.h int xc_hvm_set_ioreq_server_state(xc_interface *xch, · line 1855
Quoted 4 lines
tools/libxc/xenctrl.h +4
-0+/* +* Hotplug controller API +*/ +According to the commit message the error codes from this function have some pretty interesting semantics which should be documented IMHO. Either here or in xen/include/public.
Well, the fact that the hotplug controller is not necessarily created (and thus functions may return with errno==EOPNOTSUPP) is worth mentioning, so I'll add a comment here.
Quoted 14 lines
tools/libxl/libxl_pci.c static int do_pci_add(libxl__gc *gc, uint32_t
Quoted 13 lines
tools/libxc/xenctrl.h +5
-0+int xc_hvm_pci_hotplug (xc_interface *xch, +domid_t domid, +uint32_t slot, +int enable); +/* HVM guest pass-through */ int xc_assign_device(xc_interface *xch, uint32_t domid,tools/libxl/libxl_pci.c +0
-0@@ -867,6 +867,13 @@ static int do_pci_add(libxl__gc *gc, uint32_tdomid,
libxl_device_pci*pcidev, i
Quoted 8 lines
tools/libxl/libxl_pci.c static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i · line 871
Quoted 5 lines
tools/libxl/libxl_pci.c +2
-0}if ( rc )return ERROR_FAIL ; + + rc =xc_hvm_pci_hotplug (ctx->xch, domid, pcidev->dev,1 );
CTX->xchis somewhat preferred for new code.
Ok.
Quoted 6 lines
tools/libxl/libxl_pci.c static int do_pci_add(libxl__gc *gc, uint32_t · line 873
Quoted 2 lines
tools/libxl/libxl_pci.c +2
-0+if (rc <0 && errno !=EOPNOTSUPP ) { + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Error:
xc_hvm_pci_hotplugenable failed");You can use the LOGE macro to shorten this line.
Ok.
Quoted 5 lines
Hrm, so I didn't see anything on the restore side which handles the registration or not of the thing which would lead to EOPNOTSUPP vs success on a guest started on an older Xen. How does all that actually hang together?
If the guest was started on an older xen then HVM_PARAM_NR_IOREQ_SERVER_PAGES would not have been set, so when xc_domain_restore runs it would find no corresponding save record. Thus that param would not be set on restore and hence the controller would not be created. I could add another hvm op to make hotplug controller creation explicit if you like, but it seemed like rather a lot of extra code.
Paul
Quoted 1 line
Ian.
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 6 lines · Paul Durrant
Quoted 3 lines
Also, if you are obscuring those regions now how does it continue to work?
We only obscure the old regions if we create the in-xen hotplug controller. This doesn't happen for migrated-in guests.
I presume it does happen for migrated in guests from new Xen with this support?
Quoted 6 lines
Quoted 5 lines
Hrm, so I didn't see anything on the restore side which handles the registration or not of the thing which would lead to EOPNOTSUPP vs success on a guest started on an older Xen. How does all that actually hang together?
Quoted 7 lines
If the guest was started on an older xen then
HVM_PARAM_NR_IOREQ_SERVER_PAGESwould not have been set, so whenxc_domain_restoreruns it would find no corresponding save record. Thus that param would not be set on restore and hence the controller would not be created. I could add another hvm op to make hotplug controller creation explicit if you like, but it seemed like rather a lot of extra code.
I think what wasn't obvious was that the use of the ioreq server interfaces also implicitly causes the hotplug controller to be enabled within Xen instead of elsewhere. I can see the chain of events which leads to this now that it has been pointed out, and with that I can see where the commit message implies it, but I think it could do with being made explicit.
Ian.
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 14 lines
-----Original Message-----
From: Ian Campbell
Sent: 08 April 2014 09:45
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into XenQuoted 4 lines · Paul Durrant
Quoted 3 lines
Also, if you are obscuring those regions now how does it continue to work?
Quoted 5 lines
Quoted 2 lines
We only obscure the old regions if we create the in-xen hotplug controller. This doesn't happen for migrated-in guests.
I presume it does happen for migrated in guests from new Xen with this support?
Sorry, yes. I meant migrated-in guests from old xen; I'll fix the text.
Quoted 16 lines
Quoted 9 lines
Quoted 6 lines
Hrm, so I didn't see anything on the restore side which handles the registration or not of the thing which would lead to EOPNOTSUPP vs success on a guest started on an older Xen. How does all that actually hang together?
If the guest was started on an older xen then
HVM_PARAM_NR_IOREQ_SERVER_PAGESwould not have been set, sowhen
Quoted 5 lines
xc_domain_restoreruns it would find no corresponding save record. Thus that param would not be set on restore and hence the controller would not be created. I could add another hvm op to make hotplug controller creation explicit if you like, but it seemed like rather a lot of extra code.
Quoted 7 lines
I think what wasn't obvious was that the use of the ioreq server interfaces also implicitly causes the hotplug controller to be enabled within Xen instead of elsewhere. I can see the chain of events which leads to this now that it has been pointed out, and with that I can see where the commit message implies it, but I think it could do with being made explicit.
Ok. I can shortcut some code-churn by using an HVM param (e.g. setting it to non-zero creates the controller) or would you prefer a new HVMOP?
Paul
Quoted 1 line
Ian.
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 46 lines · Paul Durrant
Quoted 14 lines
-----Original Message-----
From: Ian Campbell
Sent: 08 April 2014 09:45
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into XenQuoted 4 lines · Paul Durrant
Quoted 3 lines
Also, if you are obscuring those regions now how does it continue to work?
Quoted 5 lines
Quoted 2 lines
We only obscure the old regions if we create the in-xen hotplug controller. This doesn't happen for migrated-in guests.
I presume it does happen for migrated in guests from new Xen with this support?
Sorry, yes. I meant migrated-in guests from old xen; I'll fix the text.
Quoted 16 lines
Quoted 9 lines
Quoted 6 lines
Hrm, so I didn't see anything on the restore side which handles the registration or not of the thing which would lead to EOPNOTSUPP vs success on a guest started on an older Xen. How does all that actually hang together?
If the guest was started on an older xen then
HVM_PARAM_NR_IOREQ_SERVER_PAGESwould not have been set, sowhen
Quoted 5 lines
xc_domain_restoreruns it would find no corresponding save record. Thus that param would not be set on restore and hence the controller would not be created. I could add another hvm op to make hotplug controller creation explicit if you like, but it seemed like rather a lot of extra code.Quoted 7 lines
I think what wasn't obvious was that the use of the ioreq server interfaces also implicitly causes the hotplug controller to be enabled within Xen instead of elsewhere. I can see the chain of events which leads to this now that it has been pointed out, and with that I can see where the commit message implies it, but I think it could do with being made explicit.
Quoted 3 lines
Ok. I can shortcut some code-churn by using an HVM param (e.g. setting it to non-zero creates the controller) or would you prefer a new HVMOP?
Sorry, I meant explicit in the docs/comments etc, I don't think an explicit HVPOP is necessarily worth it (although the hypervisor side people may disagree and I wouldn't object to adding it).
It's possible that just making the support for migration from older Xen's more explicit in the restore code as we were discussing on another and having a suitable comment at that point will be sufficient.
e.g.
/* If we are migrating from blah then register the blah blah,
* this will also enable the in-Xen hotplug controller. etc etc
* If we are migrating from an older Xen then this chunk won't
* be present and the hotplug controller is provided by qemu
* (sometimes?) and the ioreq pfns are ... */
if (we got the new chunk)
{
xc_hvm_whatever(...)
}
(fill in the details ;-))
Ian.
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 60 lines
-----Original Message-----
From: Ian Campbell
Sent: 08 April 2014 09:57
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into XenQuoted 14 lines · Paul Durrant
Quoted 14 lines
-----Original Message-----
From: Ian Campbell
Sent: 08 April 2014 09:45
To: Paul Durrant
Cc: [email protected]; Ian Jackson; Stefano Stabellini; Jan Beulich
Subject: Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into XenQuoted 4 lines · Paul Durrant
Quoted 3 lines
Also, if you are obscuring those regions now how does it continue to work?
Quoted 17 lines
Quoted 5 lines
Quoted 2 lines
We only obscure the old regions if we create the in-xen hotplug controller. This doesn't happen for migrated-in guests.
I presume it does happen for migrated in guests from new Xen with this support?
Sorry, yes. I meant migrated-in guests from old xen; I'll fix the text.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Hrm, so I didn't see anything on the restore side which handles the registration or not of the thing which would lead to EOPNOTSUPP vs success on a guest started on an older Xen. How does all that actually hang together?
If the guest was started on an older xen then
HVM_PARAM_NR_IOREQ_SERVER_PAGESwould not have been set,so
Quoted 15 lines
Quoted 7 lines
when
Quoted 5 lines
xc_domain_restoreruns it would find no corresponding save record. Thus that param would not be set on restore and hence the controller would not be created. I could add another hvm op to make hotplug controller creation explicit if you like, but it seemed like rather a lot of extra code.Quoted 7 lines
I think what wasn't obvious was that the use of the ioreq server interfaces also implicitly causes the hotplug controller to be enabled within Xen instead of elsewhere. I can see the chain of events which leads to this now that it has been pointed out, and with that I can see where the commit message implies it, but I think it could do with being made explicit.
Quoted 3 lines
Ok. I can shortcut some code-churn by using an HVM param (e.g. setting it to non-zero creates the controller) or would you prefer a new HVMOP?
Quoted 8 lines
Sorry, I meant explicit in the docs/comments etc, I don't think an explicit HVPOP is necessarily worth it (although the hypervisor side people may disagree and I wouldn't object to adding it).
It's possible that just making the support for migration from older Xen's more explicit in the restore code as we were discussing on another and having a suitable comment at that point will be sufficient.
Ok. I'll do that then :-)
Paul
Quoted 15 lines
e.g.
/* If we are migrating from blah then register the blah blah,
* this will also enable the in-Xen hotplug controller. etc etc
* If we are migrating from an older Xen then this chunk won't
* be present and the hotplug controller is provided by qemu
* (sometimes?) and the ioreq pfns are ... */
if (we got the new chunk)
{
xc_hvm_whatever(...)
}(fill in the details ;-))
Ian.
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
In reply to Paul Durrantxen/arch/x86/hvm/hotplug.c line 58
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hotplug.c new file +8
-0+static int handle_gpe_io ( +int dir,uint32_t port,uint32_t bytes,uint32_t *val) +{ +struct vcpu *v = current; +struct domain *d = v->domain; +struct hvm_hotplug *hp = &d->arch.hvm_domain.hotplug; + +if ( bytes !=1 )
Is this really a valid restriction?
xen/arch/x86/hvm/hotplug.c line 188
Quoted 11 lines
xen/arch/x86/hvm/hotplug.c new file +11
-0+int gpe_init (struct domain *d) +{ +struct hvm_hotplug *hp = &d->arch.hvm_domain.hotplug; + + hp->gpe_sts =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_sts ==NULL ) + goto fail1; + + hp->gpe_en =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_en ==NULL ) + goto fail2;
I'd like to ask (also elsewhere in this series) to try to limit the number of "goto"s to the absolute minimum required to help code readability. There's no need for them here: Allocate both blocks, then check both pointers, and if either is NULL free them both in a single error path.
Jan
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 9 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 April 2014 14:34
To: Paul Durrant
Cc: Ian Campbell; Ian Jackson; Stefano Stabellini; [email protected]
Subject: Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into XenQuoted 1 line
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
Quoted 11 lines
xen/arch/x86/hvm/hotplug.c line 58
Quoted 8 lines
xen/arch/x86/hvm/hotplug.c new file +8
-0+static int handle_gpe_io ( +int dir,uint32_t port,uint32_t bytes,uint32_t *val) +{ +struct vcpu *v = current; +struct domain *d = v->domain; +struct hvm_hotplug *hp = &d->arch.hvm_domain.hotplug; + +if ( bytes !=1 )Is this really a valid restriction?
Hmm, I believe so but I guess it would be more pragmatic to handle word and double-word access too.
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/hvm/hotplug.c new file +6
-0+int gpe_init (struct domain *d) +{ +struct hvm_hotplug *hp = &d->arch.hvm_domain.hotplug; + + hp->gpe_sts =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_sts ==NULL )
Quoted 8 lines
xen/arch/x86/hvm/hotplug.c line 188
Quoted 5 lines
xen/arch/x86/hvm/hotplug.c new file +5
-0+ goto fail1; + + hp->gpe_en =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_en ==NULL ) + goto fail2;I'd like to ask (also elsewhere in this series) to try to limit the number of "goto"s to the absolute minimum required to help code readability.
Personally I find using forward jumps to fail labels the most readable form of error exit - I wish they were used more widely.
Quoted 3 lines
There's no need for them here: Allocate both blocks, then check both pointers, and if either is NULL free them both in a single error path.
I'll alloc a single array and carve it in half.
Paul
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 18 lines
Quoted 17 lines
Quoted 1 line · On 09.04.14 at 15:42, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
xen/arch/x86/hvm/hotplug.c line 188
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hotplug.c new file +11
-0+int gpe_init (struct domain *d) +{ +struct hvm_hotplug *hp = &d->arch.hvm_domain.hotplug; + + hp->gpe_sts =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_sts ==NULL ) + goto fail1; + + hp->gpe_en =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_en ==NULL ) + goto fail2;I'd like to ask (also elsewhere in this series) to try to limit the number of "goto"s to the absolute minimum required to help code readability.
Quoted 2 lines
Personally I find using forward jumps to fail labels the most readable form of error exit - I wish they were used more widely.
Interesting - almost everyone/-thing involved in educating me in programming skills recommended to try to get away without goto altogether, unless programming Fortran, Basic or some such.
Jan
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 26 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 April 2014 14:54
To: Paul Durrant
Cc: Ian Campbell; Ian Jackson; Stefano Stabellini; [email protected]
Subject: RE: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into XenQuoted 18 lines
Quoted 17 lines
Quoted 1 line · On 09.04.14 at 15:42, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
xen/arch/x86/hvm/hotplug.c line 188
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 02.04.14 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/hotplug.c new file +11
-0+int gpe_init (struct domain *d) +{ +struct hvm_hotplug *hp = &d->arch.hvm_domain.hotplug; + + hp->gpe_sts =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_sts ==NULL ) + goto fail1; + + hp->gpe_en =xzalloc_array (uint8_t,ACPI_GPE0_BLK_LEN_V1 /2 ); +if ( hp->gpe_en ==NULL ) + goto fail2;I'd like to ask (also elsewhere in this series) to try to limit the number of "goto"s to the absolute minimum required to help code readability.
Quoted 7 lines
Quoted 2 lines
Personally I find using forward jumps to fail labels the most readable form of error exit - I wish they were used more widely.
Interesting - almost everyone/-thing involved in educating me in programming skills recommended to try to get away without goto altogether, unless programming Fortran, Basic or some such.
In my case it comes from programming for SPARC where forward branches were (are?) statically predicted untaken, so much better to code your error path as a single forward branch. Don't have to worry about such things for x86, but I'm used to reading code that looks like that :-/
Paul
Quoted 1 line
Jan
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 11 lines
Quoted 10 lines
Quoted 1 line · On 09.04.14 at 16:25, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 09.04.14 at 15:42, <[email protected]> wrote:
Personally I find using forward jumps to fail labels the most readable form of error exit - I wish they were used more widely.
Interesting - almost everyone/-thing involved in educating me in programming skills recommended to try to get away without goto altogether, unless programming Fortran, Basic or some such.
Quoted 4 lines
In my case it comes from programming for SPARC where forward branches were (are?) statically predicted untaken, so much better to code your error path as a single forward branch. Don't have to worry about such things for x86, but I'm used to reading code that looks like that :-/
The static prediction rules are similar on x86, but there's no guarantee that what is a forward branch at the source level would end up being one in the translated code. That's what we've got likely()/unlikely() for.
Jan
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
In reply to Jan BeulichJan Beulich writes ("RE: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen"):
Quoted 7 lines · On 09.04.14 at 15:42, <[email protected]> wrote:
Quoted 2 lines
Personally I find using forward jumps to fail labels the most readable form of error exit - I wish they were used more widely.
Interesting - almost everyone/-thing involved in educating me in programming skills recommended to try to get away without goto altogether, unless programming Fortran, Basic or some such.
I think the hatred of goto is a "lie to children". It is easy to misuse goto and make spaghetti.
My view is that use of goto should normally be restricted to certain very specific patterns. Examples:
* Providing a uniform cleanup path (eg error exit) from a function
* "goto continue_foobar" or "goto break_foobar" for emulating "continue" or "break" on an outer loop from within an inner loop
* Usages embedded in structural macros
Certainly goto should not be used if another control construct can do the job (without excessive circumlocution or repetition). In libxl we have a few "goto retry_transaction" which I think should be abolished. IME goto should not be used to construct loops.
But goto _should_ be used to avoid repetition. The exit path pattern is a particularly good example. In functions which use this pattern:
- all variables which refer to resources are initialised to "unallocated" (0, -1, whatever) at declaration
- there is only one use of "return"
- the return is preceded by a single copy of the cleanup for all the allocated resources
The result is that it is difficult to accidentally leak or double-free resources. Failure to initialise one of the resource variables to "empty" is normally detected by the compiler.
In this pattern the label should have a conventional name. In libxl we use "out".
Ian.
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.04.14 at 16:59, <[email protected]> wrote:
Jan Beulich writes ("RE: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen"):
Quoted 4 lines · On 09.04.14 at 15:42, <[email protected]> wrote:
Quoted 2 lines
Personally I find using forward jumps to fail labels the most readable form of error exit - I wish they were used more widely.
Quoted 6 lines
Quoted 3 lines
Interesting - almost everyone/-thing involved in educating me in programming skills recommended to try to get away without goto altogether, unless programming Fortran, Basic or some such.
I think the hatred of goto is a "lie to children". It is easy to misuse goto and make spaghetti.
Right, and when I see goto I unconditionally see spaghetti (which in many cases I'm right with, but I learned to accept cases where otherwise e.g. deep indentation would make code hard to read/ follow).
Jan
Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen
In reply to Ian JacksonQuoted 11 lines · Ian Jackson
Jan Beulich writes ("RE: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen"):
Quoted 7 lines · On 09.04.14 at 15:42, <[email protected]> wrote:
Quoted 2 lines
Personally I find using forward jumps to fail labels the most readable form of error exit - I wish they were used more widely.
Interesting - almost everyone/-thing involved in educating me in programming skills recommended to try to get away without goto altogether, unless programming Fortran, Basic or some such.
I think the hatred of goto is a "lie to children". It is easy to misuse goto and make spaghetti.
I read the original "Goto Considered Harmful" paper many years ago, and the vast majority of the objections are handled in a modern language like C.
break, contine, and switch statement are all just very specific versions of "goto". But it's not possible (nor desirable) for a language to implement all uses of "goto"; Ian mentions some other uses below. In this case, cleaning up partial acquisition of resources (e.g., a malloc failure after several malloc successes) is a very common and well understood idiom in OS design.
-George