Received: from eggs.gnu.org ([2001:4830:134:3::10]:44716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1Gie-0004yd-Ab for qemu-devel@nongnu.org; Fri, 13 May 2016 13:17:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1GiZ-0008RZ-4A for qemu-devel@nongnu.org; Fri, 13 May 2016 13:17:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54731) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1GiY-0008RO-Ru for qemu-devel@nongnu.org; Fri, 13 May 2016 13:17:39 -0400 Date: Fri, 13 May 2016 14:17:34 -0300 From: Eduardo Habkost Message-ID: <20160513171734.GO4457@thinpad.lan.raisama.net> References: <1462568028-31037-1-git-send-email-rkrcmar@redhat.com> <1462568028-31037-2-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1462568028-31037-2-git-send-email-rkrcmar@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/4] apic: add deliver_msi to APICCommonClass List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Radim =?utf-8?B?S3LEjW3DocWZ?= Cc: qemu-devel@nongnu.org, Paolo Bonzini , "Lan, Tianyu" , Igor Mammedov , Jan Kiszka , Peter Xu , Richard Henderson On Fri, May 06, 2016 at 10:53:45PM +0200, Radim Kr=C4=8Dm=C3=A1=C5=99 wro= te: > The only way to send interrupts from outside of APIC devices is to use > the MSI-inspired memory mapped interface. The interface is not > sufficient because interrupt remapping in extended mode can exceed 8 bi= t > destination ids. >=20 > The proper way to deliver interrupts would be to design a bus (QPI), bu= t > that is a big undertaking. Real IR unit stores excessive bits in the > high work of MSI address register, which would be bit [63:40] in memory > address space, so I was considering two options: > - a new special address space for APIC to handle MSI-compatible writes > - one callback to the APIC class that delivers extended MSIs >=20 > This patch uses latter option, because it was easier for me, but I thin= k > the former one could be a tad nicer. >=20 > Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 Reviewed-by: Eduardo Habkost But I have a suggestion below: > --- > hw/i386/kvm/apic.c | 21 ++++++++++++++------- > hw/i386/xen/xen_apic.c | 7 +++++++ > hw/intc/apic.c | 7 +++++++ > include/hw/i386/apic_internal.h | 5 +++++ > 4 files changed, 33 insertions(+), 7 deletions(-) >=20 > diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c > index 3c7c8fa00709..7881f13abb96 100644 > --- a/hw/i386/kvm/apic.c > +++ b/hw/i386/kvm/apic.c > @@ -147,6 +147,17 @@ static void kvm_apic_external_nmi(APICCommonState = *s) > run_on_cpu(CPU(s->cpu), do_inject_external_nmi, s); > } > =20 > +static void kvm_deliver_msi(MSIMessage *msg) > +{ > + int ret; > + > + ret =3D kvm_irqchip_send_msi(kvm_state, *msg); > + if (ret < 0) { > + fprintf(stderr, "KVM: injection failed, MSI lost (%s)\n", > + strerror(-ret)); > + } > +} > + > static uint64_t kvm_apic_mem_read(void *opaque, hwaddr addr, > unsigned size) > { > @@ -157,13 +168,7 @@ static void kvm_apic_mem_write(void *opaque, hwadd= r addr, > uint64_t data, unsigned size) > { > MSIMessage msg =3D { .address =3D addr, .data =3D data }; > - int ret; > - > - ret =3D kvm_irqchip_send_msi(kvm_state, msg); > - if (ret < 0) { > - fprintf(stderr, "KVM: injection failed, MSI lost (%s)\n", > - strerror(-ret)); > - } > + kvm_deliver_msi(&msg); > } You could call APICCommonClass::deliver_msi() here. Then (in a follow-up patch?) both kvm_apic_mem_write() and xen_apic_mem_write() could be replaced by a common function like: void apic_msi_write(void *opaque, hwaddr addr, uint64_t data, unsigned = size) { APICommonState *s =3D opaque; APICCommonClass *k =3D APIC_COMMON_GET_CLASS(s); MSIMessage msg =3D { .address =3D addr, .data =3D data }; k->deliver_msi(&msg); } (apic_mem_writel() is more complex, but maybe it could call the common function instead of calling apic_send_msi() directly) > =20 > static const MemoryRegionOps kvm_apic_io_ops =3D { > @@ -202,6 +207,8 @@ static void kvm_apic_class_init(ObjectClass *klass,= void *data) > k->enable_tpr_reporting =3D kvm_apic_enable_tpr_reporting; > k->vapic_base_update =3D kvm_apic_vapic_base_update; > k->external_nmi =3D kvm_apic_external_nmi; > + > + k->deliver_msi =3D kvm_deliver_msi; > } > =20 > static const TypeInfo kvm_apic_info =3D { > diff --git a/hw/i386/xen/xen_apic.c b/hw/i386/xen/xen_apic.c > index 21d68ee04b0a..0f34f63d449d 100644 > --- a/hw/i386/xen/xen_apic.c > +++ b/hw/i386/xen/xen_apic.c > @@ -68,6 +68,11 @@ static void xen_apic_external_nmi(APICCommonState *s= ) > { > } > =20 > +static void xen_deliver_msi(MSIMessage *msi) > +{ > + xen_hvm_inject_msi(msi->address, msi->data); > +} > + > static void xen_apic_class_init(ObjectClass *klass, void *data) > { > APICCommonClass *k =3D APIC_COMMON_CLASS(klass); > @@ -78,6 +83,8 @@ static void xen_apic_class_init(ObjectClass *klass, v= oid *data) > k->get_tpr =3D xen_apic_get_tpr; > k->vapic_base_update =3D xen_apic_vapic_base_update; > k->external_nmi =3D xen_apic_external_nmi; > + > + k->deliver_msi =3D xen_deliver_msi; > } > =20 > static const TypeInfo xen_apic_info =3D { > diff --git a/hw/intc/apic.c b/hw/intc/apic.c > index 28c2ea540608..b893942c6e73 100644 > --- a/hw/intc/apic.c > +++ b/hw/intc/apic.c > @@ -877,6 +877,11 @@ static void apic_realize(DeviceState *dev, Error *= *errp) > msi_nonbroken =3D true; > } > =20 > +static void apic_deliver_msi(MSIMessage *msi) > +{ > + apic_send_msi(msi->address, msi->data); > +} > + > static void apic_class_init(ObjectClass *klass, void *data) > { > APICCommonClass *k =3D APIC_COMMON_CLASS(klass); > @@ -889,6 +894,8 @@ static void apic_class_init(ObjectClass *klass, voi= d *data) > k->external_nmi =3D apic_external_nmi; > k->pre_save =3D apic_pre_save; > k->post_load =3D apic_post_load; > + > + k->deliver_msi =3D apic_deliver_msi; > } > =20 > static const TypeInfo apic_info =3D { > diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_int= ernal.h > index 74fe935e8eab..227ef30c5027 100644 > --- a/include/hw/i386/apic_internal.h > +++ b/include/hw/i386/apic_internal.h > @@ -146,6 +146,11 @@ typedef struct APICCommonClass > void (*pre_save)(APICCommonState *s); > void (*post_load)(APICCommonState *s); > void (*reset)(APICCommonState *s); > + > + /* deliver_msi emulates an APIC bus and its proper place would be = in a new > + * device, but it's convenient to have it here for now. > + */ > + void (*deliver_msi)(MSIMessage *msi); > } APICCommonClass; > =20 > struct APICCommonState { > --=20 > 2.8.2 >=20 --=20 Eduardo