ioreq-server: handle the lack of a default emulator properly
PATCH v2 1/1 ioreq-server: handle the lack of a default emulator properly
I started porting QEMU over to use the new ioreq server API and hit a problem with PCI bus enumeration. Because, with my patches, QEMU only registers to handle config space accesses for the PCI device it implements all other attempts by the guest to access 0xcfc go nowhere and this was causing the vcpu to wedge up because nothing was completing the I/O.
This patch introduces an I/O completion handler into the hypervisor for the case where no ioreq server matches a particular request. Read requests are completed with 0xf's in the data buffer, writes and all other I/O req types are ignored.
---
v2: - First non-RFC submission
- Removed warning on unemulated MMIO accesses
xen/arch/x86/hvm/hvm.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +32 -3
@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,if (list_empty (&d->arch.hvm_domain.ioreq_server.list) )return NULL ; -if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || - (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return d->arch.hvm_domain.default_ioreq_server; cf8 = d->arch.hvm_domain.pci_cf8;
@@ -2618,12 +2617,42 @@ bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s,return 0 ; } +static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + { +if ( !p->data_is_ptr ) + p->data = ~0ul ; +else + { +int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; + +for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size); + } + } +/* FALLTHRU */ +default : + p->state =STATE_IORESP_READY ; +hvm_io_assist (p); +break ; + } + +return 1 ; +} +bool_t hvm_send_assist_req (ioreq_t *p) {struct hvm_ioreq_server *s =hvm_select_ioreq_server (current->domain, p);if ( !s ) -return 0 ; +return hvm_complete_assist_req (p);return hvm_send_assist_req_to_ioreq_server (s, p); }
Signature · 1 line
1.7.10.4
Quoted 47 lines · Paul Durrant
I started porting QEMU over to use the new ioreq server API and hit a problem with PCI bus enumeration. Because, with my patches, QEMU only registers to handle config space accesses for the PCI device it implements all other attempts by the guest to access
0xcfcgo nowhere and this was causing the vcpu to wedge up because nothing was completing the I/O.This patch introduces an I/O completion handler into the hypervisor for the case where no ioreq server matches a particular request. Read requests are completed with 0xf's in the data buffer, writes and all other I/O req types are ignored.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>---
v2: - First non-RFC submission
- Removed warning on unemulated MMIO accessesxen/arch/x86/hvm/hvm.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)xen/arch/x86/hvm/hvm.c +9
-2@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,if (list_empty (&d->arch.hvm_domain.ioreq_server.list) )return NULL ; -if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || - (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return d->arch.hvm_domain.default_ioreq_server; cf8 = d->arch.hvm_domain.pci_cf8;@@ -2618,12 +2617,42 @@ bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s,return 0 ; } +static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + {
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2637
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+if ( !p->data_is_ptr ) + p->data = ~0ul ; +else + { +int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; + +for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size);
This is surely bogus for an ins which crosses a page boundary?
~Andrew
Quoted 22 lines
xen/arch/x86/hvm/hvm.c +13
-1+ } + } +/* FALLTHRU */ +default : + p->state =STATE_IORESP_READY ; +hvm_io_assist (p); +break ; + } + +return 1 ; +} +bool_t hvm_send_assist_req (ioreq_t *p) {struct hvm_ioreq_server *s =hvm_select_ioreq_server (current->domain, p);if ( !s ) -return 0 ; +return hvm_complete_assist_req (p);return hvm_send_assist_req_to_ioreq_server (s, p); }
Quoted 64 lines
-----Original Message-----
From: Andrew Cooper
Sent: 29 September 2014 11:59
To: Paul Durrant; [email protected]
Cc: Keir (Xen.org); Jan Beulich
Subject: Re: [Xen-devel] [PATCH v2 for 4.5] ioreq-server: handle the lack of a default emulator properlyQuoted 8 lines · Paul Durrant
I started porting QEMU over to use the new ioreq server API and hit a problem with PCI bus enumeration. Because, with my patches, QEMU only registers to handle config space accesses for the PCI device it implements all other attempts by the guest to access
0xcfcgo nowhere and this was causing the vcpu to wedge up because nothing was completing the I/O.This patch introduces an I/O completion handler into the hypervisor for the case where no ioreq server matches a particular request. Read requests
are
Quoted 11 lines
completed with 0xf's in the data buffer, writes and all other I/O req types are ignored.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>---
v2: - First non-RFC submission
- Removed warning on unemulated MMIO accessesxen/arch/x86/hvm/hvm.c | 35 ++++++++++++++++++++++++++++++++---
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server
Quoted 7 lines
1 file changed, 32 insertions(+), 3 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server*hvm_select_ioreq_server(struct domain *d,
xen/arch/x86/hvm/hvm.c bool_t
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-2if (list_empty (&d->arch.hvm_domain.ioreq_server.list) )return NULL ; -if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || - (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return d->arch.hvm_domain.default_ioreq_server; cf8 = d->arch.hvm_domain.pci_cf8;@@ -2618,12 +2617,42 @@ bool_thvm_send_assist_req_to_ioreq_server(struct
hvm_ioreq_server*s,Quoted 15 lines
xen/arch/x86/hvm/hvm.c +12
-0return 0 ; } +static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + { +if ( !p->data_is_ptr ) + p->data = ~0ul ; +else + {
Quoted 9 lines
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2637
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; + +for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size);This is surely bogus for an
inswhich crosses a page boundary?
hvmemul_do_io() is only given a guest physical address and a size, so handling of page boundary conditions must be done at a higher level.
Paul
Quoted 26 lines
~Andrew
Quoted 23 lines
xen/arch/x86/hvm/hvm.c +13
-1+ } + } +/* FALLTHRU */ +default : + p->state =STATE_IORESP_READY ; +hvm_io_assist (p); +break ; + } + +return 1 ; +} +bool_t hvm_send_assist_req (ioreq_t *p) {struct hvm_ioreq_server *s =hvm_select_ioreq_server (current- domain, p);if ( !s ) -return 0 ; +return hvm_complete_assist_req (p);return hvm_send_assist_req_to_ioreq_server (s, p);}
Quoted 55 lines
Quoted 1 line
Quoted 1 line · On 29.09.14 at 12:59, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server
Quoted 26 lines · Paul Durrant
I started porting QEMU over to use the new ioreq server API and hit a problem with PCI bus enumeration. Because, with my patches, QEMU only registers to handle config space accesses for the PCI device it implements all other attempts by the guest to access
0xcfcgo nowhere and this was causing the vcpu to wedge up because nothing was completing the I/O.This patch introduces an I/O completion handler into the hypervisor for the case where no ioreq server matches a particular request. Read requests are completed with 0xf's in the data buffer, writes and all other I/O req types are ignored.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>---
v2: - First non-RFC submission
- Removed warning on unemulated MMIO accessesxen/arch/x86/hvm/hvm.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server*hvm_select_ioreq_server(struct domain *d,
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-2if (list_empty (&d->arch.hvm_domain.ioreq_server.list) )return NULL ; -if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || - (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return d->arch.hvm_domain.default_ioreq_server; cf8 = d->arch.hvm_domain.pci_cf8;@@ -2618,12 +2617,42 @@ bool_t hvm_send_assist_req_to_ioreq_server(struct
hvm_ioreq_server*s,Quoted 15 lines
xen/arch/x86/hvm/hvm.c +12
-0return 0 ; } +static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + { +if ( !p->data_is_ptr ) + p->data = ~0ul ; +else + {
Quoted 8 lines
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2637
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; + +for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size);This is surely bogus for an
inswhich crosses a page boundary?
Crossing page boundaries gets dealt with up the call stack in hvmemul_linear_to_phys(), namely the path exiting with X86EMUL_UNHANDLEABLE when done == 0.
Jan
Quoted 62 lines · Jan Beulich
Quoted 54 lines
Quoted 1 line
Quoted 1 line · On 29.09.14 at 12:59, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server
Quoted 26 lines · Paul Durrant
I started porting QEMU over to use the new ioreq server API and hit a problem with PCI bus enumeration. Because, with my patches, QEMU only registers to handle config space accesses for the PCI device it implements all other attempts by the guest to access
0xcfcgo nowhere and this was causing the vcpu to wedge up because nothing was completing the I/O.This patch introduces an I/O completion handler into the hypervisor for the case where no ioreq server matches a particular request. Read requests are completed with 0xf's in the data buffer, writes and all other I/O req types are ignored.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>---
v2: - First non-RFC submission
- Removed warning on unemulated MMIO accessesxen/arch/x86/hvm/hvm.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server*hvm_select_ioreq_server(struct domain *d,
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-2if (list_empty (&d->arch.hvm_domain.ioreq_server.list) )return NULL ; -if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || - (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return d->arch.hvm_domain.default_ioreq_server; cf8 = d->arch.hvm_domain.pci_cf8;@@ -2618,12 +2617,42 @@ bool_t hvm_send_assist_req_to_ioreq_server(struct
hvm_ioreq_server*s,Quoted 14 lines
xen/arch/x86/hvm/hvm.c +11
-0return 0 ; } +static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + { +if ( !p->data_is_ptr ) + p->data = ~0ul ; +else Quoted 8 lines
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2637
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +7
-0+ { +int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; + +for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size);This is surely bogus for an
inswhich crosses a page boundary?
Quoted 6 lines
Crossing page boundaries gets dealt with up the call stack in
hvmemul_linear_to_phys(), namely the path exiting withX86EMUL_UNHANDLEABLEwhen done == 0.Jan
Paul also pointed this out in person, which indicates that hvm_copy_to_guest_phys() is indeed correct in this case.
Therefore it is fine, but only because the caller guarentees that "p->data + sign * i * p->size" does not cross a page boundary.
However, what I cant spot is any logic which copes with addr not being aligned with bytes_per_rep. This appears to be valid in x86, and would constitute an individual repetition accessing two pages.
~Andrew
Quoted 71 lines
Quoted 1 line
Quoted 1 line · On 29.09.14 at 14:51, <[email protected]> wrote:
Quoted 62 lines · Jan Beulich
Quoted 54 lines
Quoted 1 line
Quoted 1 line · On 29.09.14 at 12:59, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server
Quoted 26 lines · Paul Durrant
I started porting QEMU over to use the new ioreq server API and hit a problem with PCI bus enumeration. Because, with my patches, QEMU only registers to handle config space accesses for the PCI device it implements all other attempts by the guest to access
0xcfcgo nowhere and this was causing the vcpu to wedge up because nothing was completing the I/O.This patch introduces an I/O completion handler into the hypervisor for the case where no ioreq server matches a particular request. Read requests are completed with 0xf's in the data buffer, writes and all other I/O req types are ignored.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>---
v2: - First non-RFC submission
- Removed warning on unemulated MMIO accessesxen/arch/x86/hvm/hvm.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server*hvm_select_ioreq_server(struct domain *d,
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-2if (list_empty (&d->arch.hvm_domain.ioreq_server.list) )return NULL ; -if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || - (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return d->arch.hvm_domain.default_ioreq_server; cf8 = d->arch.hvm_domain.pci_cf8;@@ -2618,12 +2617,42 @@ bool_t hvm_send_assist_req_to_ioreq_server(struct
hvm_ioreq_server*s,Quoted 14 lines
xen/arch/x86/hvm/hvm.c +11
-0return 0 ; } +static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + { +if ( !p->data_is_ptr ) + p->data = ~0ul ; +else Quoted 8 lines
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2637
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +7
-0+ { +int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; + +for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size);This is surely bogus for an
inswhich crosses a page boundary?Quoted 3 lines
Crossing page boundaries gets dealt with up the call stack in
hvmemul_linear_to_phys(), namely the path exiting withX86EMUL_UNHANDLEABLEwhen done == 0.Paul also pointed this out in person, which indicates that
hvm_copy_to_guest_phys()is indeed correct in this case.
Quoted 7 lines
Therefore it is fine, but only because the caller guarentees that "
p->data+ sign * i *p->size" does not cross a page boundary.However, what I cant spot is any logic which copes with addr not being aligned with
bytes_per_rep. This appears to be valid in x86, and would constitute an individual repetition accessing two pages.
Just go to the place in the code I pointed you to above - that case is being taken care of afaict.
Jan
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 29.09.14 at 12:21, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +8
-0+static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + {
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2637
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+if ( !p->data_is_ptr ) + p->data = ~0ul ; +else + { +int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; + +for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size);
It's not clear which code you cloned this from - these constructs did all get replaced by commit f21399e148 ("x86/HVM: properly handle backward string instruction emulation "), and hence this new addition has to follow suit.
Jan
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +11
-0+ } + } +/* FALLTHRU */ +default : + p->state =STATE_IORESP_READY ; +hvm_io_assist (p); +break ; + } + +return 1 ; +}
Quoted 25 lines
-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Jan Beulich
Sent: 30 September 2014 10:04
To: Paul Durrant
Cc: Keir (Xen.org); [email protected]
Subject: Re: [Xen-devel] [PATCH v2 for 4.5] ioreq-server: handle the lack of a default emulator properlyQuoted 16 lines
Quoted 1 line
Quoted 1 line · On 29.09.14 at 12:21, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +15
-0+static bool_t hvm_complete_assist_req (ioreq_t *p) +{ +switch (p->type) + { +case IOREQ_TYPE_COPY : +case IOREQ_TYPE_PIO : +if ( p->dir ==IOREQ_READ ) + { +if ( !p->data_is_ptr ) + p->data = ~0ul ; +else + { +int i, sign = p->df ?-1 :1 ; +uint32_t data = ~0 ; +
Quoted 9 lines
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2637
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +3
-0+for ( i =0 ; i < p->count; i++ ) +hvm_copy_to_guest_phys (p->data + sign * i * p->size, &data, + p->size);It's not clear which code you cloned this from - these constructs did all get replaced by commit
f21399e148("x86/HVM: properly handle backward string instruction emulation "), and hence this new addition has to follow suit.
Ok. It was some old code I had lying around. I'll have a look at that commit.
Paul
Quoted 20 lines
Jan
xen/arch/x86/hvm/hvm.c bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s, · line 2648
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +11
-0+ } + } +/* FALLTHRU */ +default : + p->state =STATE_IORESP_READY ; +hvm_io_assist (p); +break ; + } + +return 1 ; +}_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel