All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Glauber Costa <glommer@redhat.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH v2 3/9] provide in-kernel ioapic
Date: Thu, 08 Oct 2009 13:46:25 +0200	[thread overview]
Message-ID: <4ACDD111.6050904@siemens.com> (raw)
In-Reply-To: <1254953315-5761-4-git-send-email-glommer@redhat.com>

Glauber Costa wrote:
> This patch provides kvm with an in-kernel ioapic. We are currently not enabling it.
> The code is heavily based on what's in qemu-kvm.git.
> 
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> ---
>  hw/ioapic.c |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  kvm-all.c   |   20 ++++++++++++++
>  kvm.h       |    4 +++
>  3 files changed, 107 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/ioapic.c b/hw/ioapic.c
> index d475654..d6a9dac 100644
> --- a/hw/ioapic.c
> +++ b/hw/ioapic.c
> @@ -24,6 +24,7 @@
>  #include "pc.h"
>  #include "qemu-timer.h"
>  #include "host-utils.h"
> +#include "kvm.h"
>  
>  //#define DEBUG_IOAPIC
>  
> @@ -193,6 +194,79 @@ static void ioapic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t va
>      }
>  }
>  
> +static int kvm_kernel_ioapic_load_from_user(IOAPICState *s)
> +{
> +    int r = 0;
> +#if defined(KVM_CAP_IRQCHIP) && defined(TARGET_I386)

Hmm, here we additionally depend on TARGET_I386...

> +    struct kvm_irqchip chip;
> +    struct kvm_ioapic_state *kioapic;
> +    int i;
> +
> +    if (!(kvm_enabled() && kvm_irqchip_in_kernel()))
> +        return 0;
> +
> +    chip.chip_id = KVM_IRQCHIP_IOAPIC;
> +    kioapic = &chip.chip.ioapic;
> +
> +    kioapic->id = s->id;
> +    kioapic->ioregsel = s->ioregsel;
> +    kioapic->base_address = IOAPIC_DEFAULT_BASE_ADDRESS;
> +    kioapic->irr = s->irr;
> +    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
> +        kioapic->redirtbl[i].bits = s->ioredtbl[i];
> +    }
> +
> +    r = kvm_set_irqchip(&chip);
> +#endif
> +    return r;
> +}
> +
> +static void kvm_kernel_ioapic_save_to_user(IOAPICState *s)
> +{
> +#if defined(KVM_CAP_IRQCHIP) && defined(TARGET_I386)
> +    struct kvm_irqchip chip;
> +    struct kvm_ioapic_state *kioapic;
> +    int i;
> +
> +    if (!(kvm_enabled() && kvm_irqchip_in_kernel()))
> +        return;
> +    chip.chip_id = KVM_IRQCHIP_IOAPIC;
> +    kvm_get_irqchip(&chip);
> +    kioapic = &chip.chip.ioapic;
> +
> +    s->id = kioapic->id;
> +    s->ioregsel = kioapic->ioregsel;
> +    s->irr = kioapic->irr;
> +    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
> +        s->ioredtbl[i] = kioapic->redirtbl[i].bits;
> +    }
> +#endif
> +}
> +
> +static void ioapic_pre_save(void *opaque)
> +{
> +    IOAPICState *s = (void *)opaque;
> +
> +    kvm_kernel_ioapic_save_to_user(s);
> +}
> +
> +static int ioapic_pre_load(void *opaque)
> +{
> +    IOAPICState *s = opaque;
> +
> +    /* in case we are doing version 1, we just set these to sane values */
> +    s->irr = 0;
> +    return 0;
> +}
> +
> +static int ioapic_post_load(void *opaque, int version_id)
> +{
> +    IOAPICState *s = opaque;
> +
> +    return kvm_kernel_ioapic_load_from_user(s);
> +}
> +
> +
>  static const VMStateDescription vmstate_ioapic = {
>      .name = "ioapic",
>      .version_id = 2,
> @@ -205,7 +279,10 @@ static const VMStateDescription vmstate_ioapic = {
>          VMSTATE_UINT32_V(irr, IOAPICState, 2),
>          VMSTATE_UINT64_ARRAY(ioredtbl, IOAPICState, IOAPIC_NUM_PINS),
>          VMSTATE_END_OF_LIST()
> -    }
> +    },
> +    .pre_load = ioapic_pre_load,
> +    .post_load = ioapic_post_load,
> +    .pre_save = ioapic_pre_save,
>  };
>  
>  static void ioapic_reset(void *opaque)
> @@ -217,6 +294,11 @@ static void ioapic_reset(void *opaque)
>      s->base_address = IOAPIC_DEFAULT_BASE_ADDRESS;
>      for(i = 0; i < IOAPIC_NUM_PINS; i++)
>          s->ioredtbl[i] = 1 << 16; /* mask LVT */
> +#ifdef KVM_CAP_IRQCHIP

... but here only KVM_CAP_IRQCHIP suffices?

> +    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
> +        kvm_kernel_ioapic_load_from_user(s);
> +    }
> +#endif

Independent of this, both kvm_irqchip_in_kernel() and
kvm_kernel_ioapic_load_from_user() should also be defined for the
!KVM_CAP_IRQCHIP case to avoid #ifdefs here and in many other places
this series touches.

>  }
>  
>  static CPUReadMemoryFunc * const ioapic_mem_read[3] = {
> diff --git a/kvm-all.c b/kvm-all.c
> index 48ae26c..d795285 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -411,6 +411,26 @@ int kvm_check_extension(KVMState *s, unsigned int extension)
>      return ret;
>  }
>  
> +#ifdef KVM_CAP_IRQCHIP

Again, only KVM_CAP_IRQCHIP - what is the actually required dependency?

> +int kvm_set_irqchip(struct kvm_irqchip *chip)
> +{
> +    if (!kvm_state->irqchip_in_kernel) {
> +        return 0;
> +    }
> +
> +    return kvm_vm_ioctl(kvm_state, KVM_SET_IRQCHIP, chip);
> +}
> +
> +int kvm_get_irqchip(struct kvm_irqchip *chip)
> +{
> +    if (!kvm_state->irqchip_in_kernel) {
> +        return 0;
> +    }
> +
> +    return kvm_vm_ioctl(kvm_state, KVM_GET_IRQCHIP, chip);
> +}
> +#endif
> +
>  int kvm_init(int smp_cpus)
>  {
>      static const char upgrade_note[] =
> diff --git a/kvm.h b/kvm.h
> index e7d5beb..8d4afa0 100644
> --- a/kvm.h
> +++ b/kvm.h
> @@ -16,6 +16,7 @@
>  
>  #include "config.h"
>  #include "qemu-queue.h"
> +#include <linux/kvm.h>
>  
>  #ifdef CONFIG_KVM
>  extern int kvm_allowed;
> @@ -63,6 +64,9 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap);
>  int kvm_pit_in_kernel(void);
>  int kvm_irqchip_in_kernel(void);
>  
> +int kvm_set_irqchip(struct kvm_irqchip *chip);
> +int kvm_get_irqchip(struct kvm_irqchip *chip);
> +
>  /* internal API */
>  
>  struct KVMState;

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

  parent reply	other threads:[~2009-10-08 11:46 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-07 22:08 [Qemu-devel] [PATCH v2] Add in-kernel irqchip Glauber Costa
2009-10-07 22:08 ` [Qemu-devel] [PATCH v2 1/9] add base-addr field to io apic state Glauber Costa
2009-10-07 22:08   ` [Qemu-devel] [PATCH v2 2/9] Save missing fields in VMState Glauber Costa
2009-10-07 22:08     ` [Qemu-devel] [PATCH v2 3/9] provide in-kernel ioapic Glauber Costa
2009-10-07 22:08       ` [Qemu-devel] [PATCH v2 4/9] provide in-kernel apic Glauber Costa
2009-10-07 22:08         ` [Qemu-devel] [PATCH v2 5/9] provide apic_set_irq_delivered Glauber Costa
2009-10-07 22:08           ` [Qemu-devel] [PATCH v2 6/9] provide in-kernel i8259 chip Glauber Costa
2009-10-07 22:08             ` [Qemu-devel] [PATCH v2 7/9] initialize " Glauber Costa
2009-10-07 22:08               ` [Qemu-devel] [PATCH v2 8/9] Initialize in-kernel irqchip Glauber Costa
2009-10-07 22:08                 ` [Qemu-devel] [PATCH v2 9/9] Add -kvm option Glauber Costa
2009-10-07 23:00                   ` [Qemu-devel] " Anthony Liguori
2009-10-07 23:14                     ` Glauber Costa
2009-10-07 23:28                       ` Anthony Liguori
2009-10-12 11:58                         ` Gerd Hoffmann
2009-10-12 14:04                           ` Anthony Liguori
2009-10-12 15:34                             ` Gerd Hoffmann
2009-10-12 16:31                               ` Anthony Liguori
2009-10-13  8:05                                 ` Gerd Hoffmann
2009-10-13 15:33                                   ` Anthony Liguori
2009-10-13 19:26                                     ` Markus Armbruster
2009-10-13 20:43                                       ` Anthony Liguori
2009-10-14  8:08                                         ` Gerd Hoffmann
2009-10-13 15:36                                   ` Anthony Liguori
2009-10-13 22:57                                     ` Jamie Lokier
2009-10-08 14:07                     ` Avi Kivity
2009-10-08 14:23                       ` Anthony Liguori
2009-10-08 14:30                         ` Avi Kivity
2009-10-08 14:33                           ` Anthony Liguori
2009-10-08 14:41                             ` Avi Kivity
2009-10-08 14:56                               ` Anthony Liguori
2009-10-08 15:05                                 ` Avi Kivity
2009-10-08 15:14                                   ` Anthony Liguori
2009-10-12 11:15                                     ` Gerd Hoffmann
2009-10-08 14:34                           ` Gleb Natapov
2009-10-08 12:02               ` [Qemu-devel] Re: [PATCH v2 7/9] initialize i8259 chip Jan Kiszka
2009-10-08 13:55         ` [PATCH v2 4/9] provide in-kernel apic Anthony Liguori
2009-10-08 13:55           ` [Qemu-devel] " Anthony Liguori
2009-10-08 14:09           ` Avi Kivity
2009-10-08 14:09             ` [Qemu-devel] " Avi Kivity
2009-10-08 14:22             ` Glauber Costa
2009-10-09 10:06               ` Jamie Lokier
2009-10-09 10:06                 ` [Qemu-devel] " Jamie Lokier
2009-10-09 14:30                 ` Glauber Costa
2009-10-09 14:30                   ` [Qemu-devel] " Glauber Costa
2009-10-09 16:48                   ` Jamie Lokier
2009-10-09 16:48                     ` Jamie Lokier
2009-10-09 18:06                     ` Glauber Costa
2009-10-09 18:06                       ` [Qemu-devel] " Glauber Costa
2009-10-09 19:49                     ` Anthony Liguori
2009-10-09 19:49                       ` Anthony Liguori
2009-10-11  9:10                       ` Avi Kivity
2009-10-11  9:10                         ` [Qemu-devel] " Avi Kivity
2009-10-12 13:41                         ` Anthony Liguori
2009-10-12 13:41                           ` Anthony Liguori
2009-10-08 14:26             ` Anthony Liguori
2009-10-08 14:26               ` Anthony Liguori
2009-10-08 14:31               ` Avi Kivity
2009-10-08 14:31                 ` Avi Kivity
2009-10-08 14:39                 ` Anthony Liguori
2009-10-08 14:46                   ` Glauber Costa
2009-10-08 14:46                     ` Glauber Costa
2009-10-08 14:44                 ` Glauber Costa
2009-10-08 14:44                   ` Glauber Costa
2009-10-08 11:46       ` Jan Kiszka [this message]
2009-10-08 13:49       ` [PATCH v2 3/9] provide in-kernel ioapic Anthony Liguori
2009-10-08 13:49         ` [Qemu-devel] " Anthony Liguori
2009-10-08 13:54         ` Avi Kivity
2009-10-08 13:54           ` [Qemu-devel] " Avi Kivity
2009-10-08 15:53           ` Jan Kiszka
2009-10-08 15:53             ` [Qemu-devel] " Jan Kiszka
2009-10-08 16:07           ` Jamie Lokier
2009-10-08 16:07             ` Jamie Lokier
2009-10-08 16:12             ` Anthony Liguori
2009-10-08 16:12               ` Anthony Liguori
2009-10-08 16:17             ` Avi Kivity
2009-10-08 16:17               ` Avi Kivity
2009-10-08 16:22               ` Gleb Natapov
2009-10-08 16:22                 ` Gleb Natapov
2009-10-08 16:29                 ` Avi Kivity
2009-10-08 16:29                   ` Avi Kivity
2009-10-08 16:34                   ` Gleb Natapov
2009-10-08 16:34                     ` Gleb Natapov
2009-10-08 16:42                     ` Avi Kivity
2009-10-08 16:42                       ` Avi Kivity
2009-10-08 17:11                       ` Gleb Natapov
2009-10-08 17:11                         ` Gleb Natapov
2009-10-09 10:02                         ` Jamie Lokier
2009-10-09 10:02                           ` [Qemu-devel] " Jamie Lokier
2009-10-09 12:02                           ` Gleb Natapov
2009-10-09 12:02                             ` Gleb Natapov
2009-10-09 14:32                 ` Glauber Costa
2009-10-09 14:32                   ` [Qemu-devel] " Glauber Costa
2009-10-09 16:49                   ` Jamie Lokier
2009-10-09 16:49                     ` Jamie Lokier
2009-10-09 19:55                     ` Juan Quintela
2009-10-09 21:34                       ` Glauber Costa
2009-10-09 21:34                         ` [Qemu-devel] " Glauber Costa
2009-10-12 13:20                       ` Anthony Liguori
2009-10-12 13:20                         ` [Qemu-devel] " Anthony Liguori
2009-10-12 14:18                         ` Jamie Lokier
2009-10-12 14:18                           ` [Qemu-devel] " Jamie Lokier
2009-10-12 14:49                           ` Anthony Liguori
2009-10-12 14:49                             ` [Qemu-devel] " Anthony Liguori

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=4ACDD111.6050904@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=aliguori@us.ibm.com \
    --cc=glommer@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.