All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: Avi Kivity <avi@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	qemu-devel <qemu-devel@nongnu.org>,
	Anthony Liguori <aliguori@us.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: Re: [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Date: Sat, 10 Dec 2011 16:58:38 +0100	[thread overview]
Message-ID: <4EE381AE.6060702@web.de> (raw)
In-Reply-To: <CAAu8pHs5bJD2zqRdoXmdR0NW3AAZpuhm7Rn3ea8VytjX_Hu8tw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4101 bytes --]

On 2011-12-10 16:40, Blue Swirl wrote:
> On Fri, Dec 9, 2011 at 07:52, Jan Kiszka <jan.kiszka@siemens.com> wrote:
>> On 2011-12-09 08:45, Jan Kiszka wrote:
>>> On 2011-12-08 22:16, Blue Swirl wrote:
>>>> On Thu, Dec 8, 2011 at 11:52, Jan Kiszka <jan.kiszka@siemens.com> wrote:
>>>>> This introduces the alternative APIC backend which makes use of KVM's
>>>>> in-kernel device model. External NMI injection via LINT1 is emulated by
>>>>> checking the current state of the in-kernel APIC, only injecting a NMI
>>>>> into the VCPU if LINT1 is unmasked and configured to DM_NMI.
>>>>>
>>>>> MSI is not yet supported, so we disable this when the in-kernel model is
>>>>> in use.
>>>>>
>>>>> CC: Lai Jiangshan <laijs@cn.fujitsu.com>
>>>>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>>>>> ---
>>>>>  Makefile.target   |    2 +-
>>>>>  hw/kvm/apic.c     |  154 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>>>  hw/pc.c           |   15 ++++--
>>>>>  kvm.h             |    3 +
>>>>>  target-i386/kvm.c |    8 +++
>>>>>  5 files changed, 176 insertions(+), 6 deletions(-)
>>>>>  create mode 100644 hw/kvm/apic.c
>>>>>
>>>>> diff --git a/Makefile.target b/Makefile.target
>>>>> index b549988..76de485 100644
>>>>> --- a/Makefile.target
>>>>> +++ b/Makefile.target
>>>>> @@ -236,7 +236,7 @@ obj-i386-y += vmport.o
>>>>>  obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
>>>>>  obj-i386-y += debugcon.o multiboot.o
>>>>>  obj-i386-y += pc_piix.o
>>>>> -obj-i386-$(CONFIG_KVM) += kvm/clock.o
>>>>> +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o
>>>>>  obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
>>>>>
>>>>>  # shared objects
>>>>> diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c
>>>>> new file mode 100644
>>>>> index 0000000..3924f9e
>>>>> --- /dev/null
>>>>> +++ b/hw/kvm/apic.c
>>>>> @@ -0,0 +1,154 @@
>>>>> +/*
>>>>> + * KVM in-kernel APIC support
>>>>> + *
>>>>> + * Copyright (c) 2011 Siemens AG
>>>>> + *
>>>>> + * Authors:
>>>>> + *  Jan Kiszka          <jan.kiszka@siemens.com>
>>>>> + *
>>>>> + * This work is licensed under the terms of the GNU GPL version 2.
>>>>> + * See the COPYING file in the top-level directory.
>>>>> + */
>>>>> +#include "hw/apic_internal.h"
>>>>> +#include "kvm.h"
>>>>> +
>>>>> +static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
>>>>> +                                   int reg_id, uint32_t val)
>>>>> +{
>>>>> +    *((uint32_t *)(kapic->regs + (reg_id << 4))) = val;
>>>>> +}
>>>>> +
>>>>> +static inline uint32_t kvm_apic_get_reg(struct kvm_lapic_state *kapic,
>>>>> +                                       int reg_id)
>>>>> +{
>>>>> +    return *((uint32_t *)(kapic->regs + (reg_id << 4)));
>>>>> +}
>>>>> +
>>>>> +int kvm_put_apic(CPUState *env)
>>>>> +{
>>>>> +    APICState *s = DO_UPCAST(APICState, busdev.qdev, env->apic_state);
>>>>
>>>> Please pass APICState instead of CPUState.
>>>
>>> DeviceState, I suppose. Yes, makes more sense, update will follow.
>>
>> On second look: no, I'll keep it as is. All kvm_get/put_* helpers have
>> this kind of signature, i.e. are working against env.
> 
> There's kvm_get_supported_msrs for example.
> 
>> kvm_get/put_apic
>> just happens to be implemented outside of target-i386/kvm.c. And they
>> require both APIC and CPUState anyway, so it makes no difference.
> 
> It does, passing CPUState violates layering. Please split the
> functions so that the ioctl calls which need CPUState go to kvm.c. For
> example, the functions in kvm/apic.c could just perform copying from
> kvm_lapic_state fields to APICstate fields and vice versa.

That's a good idea.

> 
> The KVM interface by the way does not look so clever. Why isn't there
> just an array of 32 bit fields so the casts can be avoided? Perhaps
> APICState should be (later) changed to match KVM version so that the
> structure can be passed directly without copying.

Wouldn't that complicate the use in the user space model again? At least
for registers that are used with both backends.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Jan Kiszka <jan.kiszka@web.de>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>, Avi Kivity <avi@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Date: Sat, 10 Dec 2011 16:58:38 +0100	[thread overview]
Message-ID: <4EE381AE.6060702@web.de> (raw)
In-Reply-To: <CAAu8pHs5bJD2zqRdoXmdR0NW3AAZpuhm7Rn3ea8VytjX_Hu8tw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4101 bytes --]

On 2011-12-10 16:40, Blue Swirl wrote:
> On Fri, Dec 9, 2011 at 07:52, Jan Kiszka <jan.kiszka@siemens.com> wrote:
>> On 2011-12-09 08:45, Jan Kiszka wrote:
>>> On 2011-12-08 22:16, Blue Swirl wrote:
>>>> On Thu, Dec 8, 2011 at 11:52, Jan Kiszka <jan.kiszka@siemens.com> wrote:
>>>>> This introduces the alternative APIC backend which makes use of KVM's
>>>>> in-kernel device model. External NMI injection via LINT1 is emulated by
>>>>> checking the current state of the in-kernel APIC, only injecting a NMI
>>>>> into the VCPU if LINT1 is unmasked and configured to DM_NMI.
>>>>>
>>>>> MSI is not yet supported, so we disable this when the in-kernel model is
>>>>> in use.
>>>>>
>>>>> CC: Lai Jiangshan <laijs@cn.fujitsu.com>
>>>>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>>>>> ---
>>>>>  Makefile.target   |    2 +-
>>>>>  hw/kvm/apic.c     |  154 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>>>  hw/pc.c           |   15 ++++--
>>>>>  kvm.h             |    3 +
>>>>>  target-i386/kvm.c |    8 +++
>>>>>  5 files changed, 176 insertions(+), 6 deletions(-)
>>>>>  create mode 100644 hw/kvm/apic.c
>>>>>
>>>>> diff --git a/Makefile.target b/Makefile.target
>>>>> index b549988..76de485 100644
>>>>> --- a/Makefile.target
>>>>> +++ b/Makefile.target
>>>>> @@ -236,7 +236,7 @@ obj-i386-y += vmport.o
>>>>>  obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
>>>>>  obj-i386-y += debugcon.o multiboot.o
>>>>>  obj-i386-y += pc_piix.o
>>>>> -obj-i386-$(CONFIG_KVM) += kvm/clock.o
>>>>> +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o
>>>>>  obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
>>>>>
>>>>>  # shared objects
>>>>> diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c
>>>>> new file mode 100644
>>>>> index 0000000..3924f9e
>>>>> --- /dev/null
>>>>> +++ b/hw/kvm/apic.c
>>>>> @@ -0,0 +1,154 @@
>>>>> +/*
>>>>> + * KVM in-kernel APIC support
>>>>> + *
>>>>> + * Copyright (c) 2011 Siemens AG
>>>>> + *
>>>>> + * Authors:
>>>>> + *  Jan Kiszka          <jan.kiszka@siemens.com>
>>>>> + *
>>>>> + * This work is licensed under the terms of the GNU GPL version 2.
>>>>> + * See the COPYING file in the top-level directory.
>>>>> + */
>>>>> +#include "hw/apic_internal.h"
>>>>> +#include "kvm.h"
>>>>> +
>>>>> +static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
>>>>> +                                   int reg_id, uint32_t val)
>>>>> +{
>>>>> +    *((uint32_t *)(kapic->regs + (reg_id << 4))) = val;
>>>>> +}
>>>>> +
>>>>> +static inline uint32_t kvm_apic_get_reg(struct kvm_lapic_state *kapic,
>>>>> +                                       int reg_id)
>>>>> +{
>>>>> +    return *((uint32_t *)(kapic->regs + (reg_id << 4)));
>>>>> +}
>>>>> +
>>>>> +int kvm_put_apic(CPUState *env)
>>>>> +{
>>>>> +    APICState *s = DO_UPCAST(APICState, busdev.qdev, env->apic_state);
>>>>
>>>> Please pass APICState instead of CPUState.
>>>
>>> DeviceState, I suppose. Yes, makes more sense, update will follow.
>>
>> On second look: no, I'll keep it as is. All kvm_get/put_* helpers have
>> this kind of signature, i.e. are working against env.
> 
> There's kvm_get_supported_msrs for example.
> 
>> kvm_get/put_apic
>> just happens to be implemented outside of target-i386/kvm.c. And they
>> require both APIC and CPUState anyway, so it makes no difference.
> 
> It does, passing CPUState violates layering. Please split the
> functions so that the ioctl calls which need CPUState go to kvm.c. For
> example, the functions in kvm/apic.c could just perform copying from
> kvm_lapic_state fields to APICstate fields and vice versa.

That's a good idea.

> 
> The KVM interface by the way does not look so clever. Why isn't there
> just an array of 32 bit fields so the casts can be avoided? Perhaps
> APICState should be (later) changed to match KVM version so that the
> structure can be passed directly without copying.

Wouldn't that complicate the use in the user space model again? At least
for registers that are used with both backends.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

  reply	other threads:[~2011-12-10 15:58 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-08 11:52 [PATCH v4 00/15] uq/master: Introduce basic irqchip support Jan Kiszka
2011-12-08 11:52 ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 01/15] msi: Generalize msix_supported to msi_supported Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 02/15] kvm: Move kvmclock into hw/kvm folder Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 03/15] apic: Stop timer on reset Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 04/15] apic: Inject external NMI events via LINT1 Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 05/15] apic: Introduce backend/frontend infrastructure for KVM reuse Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 06/15] apic: Open-code timer save/restore Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 07/15] i8259: Introduce backend/frontend infrastructure for KVM reuse Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 08/15] ioapic: " Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 09/15] memory: Introduce memory_region_init_reservation Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 10/15] kvm: Introduce core services for in-kernel irqchip support Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 11/15] kvm: x86: Establish IRQ0 override control Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 21:16   ` Blue Swirl
2011-12-08 21:16     ` [Qemu-devel] " Blue Swirl
2011-12-09  7:45     ` Jan Kiszka
2011-12-09  7:45       ` [Qemu-devel] " Jan Kiszka
2011-12-09  7:52       ` Jan Kiszka
2011-12-09  7:52         ` [Qemu-devel] " Jan Kiszka
2011-12-10 15:40         ` Blue Swirl
2011-12-10 15:40           ` [Qemu-devel] " Blue Swirl
2011-12-10 15:58           ` Jan Kiszka [this message]
2011-12-10 15:58             ` Jan Kiszka
2011-12-10 16:11             ` Blue Swirl
2011-12-10 16:11               ` [Qemu-devel] " Blue Swirl
2011-12-08 11:52 ` [PATCH v4 13/15] kvm: x86: Add user space part for in-kernel i8259 Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 14/15] kvm: x86: Add user space part for in-kernel IOAPIC Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 11:52 ` [PATCH v4 15/15] kvm: Arm in-kernel irqchip support Jan Kiszka
2011-12-08 11:52   ` [Qemu-devel] " Jan Kiszka
2011-12-08 21:25 ` [PATCH v4 00/15] uq/master: Introduce basic " Blue Swirl
2011-12-08 21:25   ` [Qemu-devel] " Blue Swirl
2011-12-09  7:40   ` Jan Kiszka
2011-12-09  7:40     ` [Qemu-devel] " Jan Kiszka
2011-12-12 16:37 ` Marcelo Tosatti
2011-12-12 16:37   ` [Qemu-devel] " Marcelo Tosatti
2011-12-12 16:51   ` Jan Kiszka
2011-12-12 16:51     ` [Qemu-devel] " Jan Kiszka
2011-12-12 17:37     ` Avi Kivity
2011-12-12 17:37       ` [Qemu-devel] " Avi Kivity
2011-12-12 17:42       ` Jan Kiszka
2011-12-12 17:42         ` [Qemu-devel] " Jan Kiszka
2011-12-12 17:59         ` Avi Kivity
2011-12-12 17:59           ` [Qemu-devel] " Avi Kivity
2011-12-15 10:33     ` Jan Kiszka
2011-12-15 10:33       ` [Qemu-devel] " Jan Kiszka
2011-12-15 11:54       ` Avi Kivity
2011-12-15 11:54         ` [Qemu-devel] " Avi Kivity
2011-12-15 11:59         ` Jan Kiszka
2011-12-15 11:59           ` [Qemu-devel] " Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EE381AE.6060702@web.de \
    --to=jan.kiszka@web.de \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.