ioreq-server: handle the lack of a default emulator properly
RFC PATCH 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.
---
This fix should probably go in 4.5 but this patch is RFC for the moment because of uncertainty about what to do for unemulated MMIO accesses. Originally I forced a domain crash in this case, but hvmloader actually hit the crash because the code that deals with building the ACPI TPM info reads from 0xFED40F00 looking for a signature value and there is nothing backing this access in my configuration. So, the question is whether to whitelist this access in some way or make building that table optional in some way so that it is only invoked if an emulated TPM is definitely present.
xen/arch/x86/hvm/hvm.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +38 -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,48 @@ 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 : +gdprintk (XENLOG_WARNING ,"unemulated MMIO (%s %d bytes @ %lx) %u reps\n" , + (p->dir ==IOREQ_READ ) ?"read" :"write" , + p->size, + p->addr, + p->count); +/* FALLTHRU */ +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 10 lines
Quoted 1 line
Quoted 1 line · On 26.09.14 at 17:31, <[email protected]> wrote:
This fix should probably go in 4.5 but this patch is RFC for the moment because of uncertainty about what to do for unemulated MMIO accesses. Originally I forced a domain crash in this case, but hvmloader actually hit the crash because the code that deals with building the ACPI TPM info reads from
0xFED40F00looking for a signature value and there is nothing backing this access in my configuration. So, the question is whether to whitelist this access in some way or make building that table optional in some way so that it is only invoked if an emulated TPM is definitely present.
I think in the sense of acting like real hardware, having a definite point to complete such I/O is quite desirable, as opposed to killing the guest.
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, · line 2389
Quoted 9 lines
xen/arch/x86/hvm/hvm.c +1
-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 )
I'm having some trouble understanding the reason for this change.
Jan
Quoted 19 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2014 17:23
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH RFC] ioreq-server: handle the lack of a default emulator properlyQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.09.14 at 17:31, <[email protected]> wrote:
This fix should probably go in 4.5 but this patch is RFC for the moment because of uncertainty about what to do for unemulated MMIO accesses. Originally I forced a domain crash in this case, but hvmloader actually hit the crash because the code that deals with building the ACPI TPM info reads from
0xFED40F00looking for a signature value and there is nothing backing this access in my configuration. So, the question is whether to whitelist this access in some way or make building that table optional in some way so that it is only invoked if an emulated TPM is definitely present.
Quoted 3 lines
I think in the sense of acting like real hardware, having a definite point to complete such I/O is quite desirable, as opposed to killing the guest.
Ok. The doubt was around the fact that on bare metal an unhandled MMIO would normally cause an MCE (by way of a bus error).
Quoted 5 lines
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server*hvm_select_ioreq_server(struct domain *d,
Quoted 9 lines
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, · line 2389
Quoted 6 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 )I'm having some trouble understanding the reason for this change.
The implication that list_is_singular -> 'singular ioreq server is default' is wrong; it was an 'optimization' too far. Now that I have QEMU ported, in my tests it is the only emulator but it is not a default emulator (because it registers explicit ranges).
Paul
Quoted 1 line
Jan
Quoted 20 lines
Quoted 20 lines
Quoted 1 line · On 29.09.14 at 10:59, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2014 17:23
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH RFC] ioreq-server: handle the lack of a default emulator properlyQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.09.14 at 17:31, <[email protected]> wrote:
This fix should probably go in 4.5 but this patch is RFC for the moment because of uncertainty about what to do for unemulated MMIO accesses. Originally I forced a domain crash in this case, but hvmloader actually hit the crash because the code that deals with building the ACPI TPM info reads from
0xFED40F00looking for a signature value and there is nothing backing this access in my configuration. So, the question is whether to whitelist this access in some way or make building that table optional in some way so that it is only invoked if an emulated TPM is definitely present.
Quoted 6 lines
Quoted 3 lines
I think in the sense of acting like real hardware, having a definite point to complete such I/O is quite desirable, as opposed to killing the guest.
Ok. The doubt was around the fact that on bare metal an unhandled MMIO would normally cause an MCE (by way of a bus error).
Hmm, no, I don't think so, particularly on x86: Together with the chipset, all transactions should have an instance completing them. And I don't think MCEs would be the way to signal failure thereof. All this may be different on other architectures, but x86's heritage is that you can access any "unused" memory location without causing the machine to lock up (other than e.g. on ia64).
Quoted 11 lines
Quoted 11 lines
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -2386,8 +2386,7 @@ static struct hvm_ioreq_server*hvm_select_ioreq_server(struct domain *d,
Quoted 6 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 )
Quoted 7 lines
Quoted 2 lines
I'm having some trouble understanding the reason for this change.
The implication that
list_is_singular-> 'singular ioreq server is default' is wrong; it was an 'optimization' too far. Now that I have QEMU ported, in my tests it is the only emulator but it is not a default emulator (because it registers explicit ranges).
Ah, that makes sense of course. In which case I'm fine with the patch as is.
Jan
Quoted 36 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 29 September 2014 10:28
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: RE: [PATCH RFC] ioreq-server: handle the lack of a default emulator properlyQuoted 7 lines
Quoted 7 lines
Quoted 1 line · On 29.09.14 at 10:59, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2014 17:23
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH RFC] ioreq-server: handle the lack of a defaultemulator
Quoted 5 lines
Quoted 5 lines
properly
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.09.14 at 17:31, <[email protected]> wrote:
This fix should probably go in 4.5 but this patch is RFC for the moment because of uncertainty about what to do for unemulated MMIO
accesses.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Originally I forced a domain crash in this case, but hvmloader actually hit the crash because the code that deals with building the ACPI TPM info reads from
0xFED40F00looking for a signature value and there is nothing backing this access in my configuration. So, the question is whether to whitelist this access in some way or make building that table optional in some way so that it is only invoked if an emulated TPM is definitely present.Quoted 5 lines
Quoted 3 lines
I think in the sense of acting like real hardware, having a definite point to complete such I/O is quite desirable, as opposed to killing the guest.
Ok. The doubt was around the fact that on bare metal an unhandled MMIO
would
Quoted 9 lines
Quoted 1 line
normally cause an MCE (by way of a bus error).
Hmm, no, I don't think so, particularly on x86: Together with the chipset, all transactions should have an instance completing them. And I don't think MCEs would be the way to signal failure thereof. All this may be different on other architectures, but x86's heritage is that you can access any "unused" memory location without causing the machine to lock up (other than e.g. on ia64).
Ok, I'll drop the warning printk then.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
xen/arch/x86/hvm/hvm.c static struct hvm_ioreq_server
Quoted 3 lines
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 static struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, · line 2389
Quoted 6 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 )I'm having some trouble understanding the reason for this change.
Quoted 9 lines
Quoted 2 lines
The implication that
list_is_singular-> 'singular ioreq server is default' is wrong; it was an 'optimization' too far. Now that I have QEMU ported, inmy
Quoted 2 lines
tests it is the only emulator but it is not a default emulator (because it registers explicit ranges).
Ah, that makes sense of course. In which case I'm fine with the patch as is.
Cool. I'll resubmit non-RFC without the printk.
Thanks,
Paul
Quoted 1 line
Jan