All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/5] target-ppc: Synchronize VPA state with KVM
Date: Fri, 15 Mar 2013 13:22:08 +0100	[thread overview]
Message-ID: <43A59AA0-E31D-42D5-88EC-19D370A4D235@suse.de> (raw)
In-Reply-To: <1363226008-26639-2-git-send-email-david@gibson.dropbear.id.au>


On 14.03.2013, at 02:53, David Gibson wrote:

> For PAPR guests, KVM tracks the various areas registered with the
> H_REGISTER_VPA hypercall.  For full emulation, of course, these are tracked
> within qemu.  At present these values are not synchronized.  This is a
> problem for reset (qemu's reset of the VPA address is not pushed to KVM)
> and will also be a problem for savevm / migration.
> 
> The kernel now supports accessing the VPA state via the ONE_REG interface,
> this patch adds code to qemu to use that interface to keep the qemu and
> KVM ideas of the VPA state synchronized.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> target-ppc/kvm.c |  121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 121 insertions(+)
> 
> diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
> index 67f3f42..f5710b7 100644
> --- a/target-ppc/kvm.c
> +++ b/target-ppc/kvm.c
> @@ -63,6 +63,7 @@ static int cap_ppc_rma;
> static int cap_spapr_tce;
> static int cap_hior;
> static int cap_one_reg;
> +static int cap_papr;
> 
> /* XXX We have a race condition where we actually have a level triggered
>  *     interrupt, but the infrastructure can't expose that yet, so the guest
> @@ -95,6 +96,8 @@ int kvm_arch_init(KVMState *s)
>     cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE);
>     cap_one_reg = kvm_check_extension(s, KVM_CAP_ONE_REG);
>     cap_hior = kvm_check_extension(s, KVM_CAP_PPC_HIOR);
> +    /* Note: we don't set cap_papr here, because this capability is
> +     * only activated after this by kvmppc_set_papr() */
> 
>     if (!cap_interrupt_level) {
>         fprintf(stderr, "KVM: Couldn't find level irq capability. Expect the "
> @@ -652,6 +655,103 @@ static int kvm_get_fp(CPUState *cs)
>     return 0;
> }
> 
> +#if defined(TARGET_PPC64)
> +static int kvm_get_vpa(CPUState *cs)
> +{
> +    PowerPCCPU *cpu = POWERPC_CPU(cs);
> +    CPUPPCState *env = &cpu->env;
> +    struct kvm_one_reg reg;
> +    int ret;
> +
> +    reg.id = KVM_REG_PPC_VPA_ADDR;
> +    reg.addr = (uintptr_t)&env->vpa_addr;
> +    ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
> +    if (ret < 0) {
> +        dprintf("Unable to get VPA address from KVM: %s\n", strerror(errno));
> +        return ret;
> +    }
> +
> +    assert((uintptr_t)&env->slb_shadow_size
> +           == ((uintptr_t)&env->slb_shadow_addr + 8));
> +    reg.id = KVM_REG_PPC_VPA_SLB;
> +    reg.addr = (uintptr_t)&env->slb_shadow_addr;
> +    ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
> +    if (ret < 0) {
> +        dprintf("Unable to get SLB shadow state from KVM: %s\n",
> +                strerror(errno));
> +        return ret;
> +    }
> +
> +    assert((uintptr_t)&env->dtl_size == ((uintptr_t)&env->dtl_addr + 8));
> +    reg.id = KVM_REG_PPC_VPA_DTL;
> +    reg.addr = (uintptr_t)&env->dtl_addr;
> +    ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
> +    if (ret < 0) {
> +        dprintf("Unable to get dispatch trace log state from KVM: %s\n",
> +                strerror(errno));
> +        return ret;
> +    }
> +
> +    return 0;
> +}
> +
> +static int kvm_put_vpa(CPUState *cs)
> +{
> +    PowerPCCPU *cpu = POWERPC_CPU(cs);
> +    CPUPPCState *env = &cpu->env;
> +    struct kvm_one_reg reg;
> +    int ret;
> +
> +    /* SLB shadow or DTL can't be registered unless a master VPA is
> +     * registered.  That means when restoring state, if a VPA *is*
> +     * registered, we need to set that up first.  If not, we need to
> +     * deregister the others before deregistering the master VPA */
> +    assert(env->vpa_addr || !(env->slb_shadow_addr || env->dtl_addr));
> +
> +    if (env->vpa_addr) {
> +        reg.id = KVM_REG_PPC_VPA_ADDR;
> +        reg.addr = (uintptr_t)&env->vpa_addr;
> +        ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
> +        if (ret < 0) {
> +            dprintf("Unable to set VPA address to KVM: %s\n", strerror(errno));
> +            return ret;
> +        }
> +    }
> +
> +    assert((uintptr_t)&env->slb_shadow_size
> +           == ((uintptr_t)&env->slb_shadow_addr + 8));
> +    reg.id = KVM_REG_PPC_VPA_SLB;
> +    reg.addr = (uintptr_t)&env->slb_shadow_addr;
> +    ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
> +    if (ret < 0) {
> +        dprintf("Unable to set SLB shadow state to KVM: %s\n", strerror(errno));
> +        return ret;
> +    }
> +
> +    assert((uintptr_t)&env->dtl_size == ((uintptr_t)&env->dtl_addr + 8));
> +    reg.id = KVM_REG_PPC_VPA_DTL;
> +    reg.addr = (uintptr_t)&env->dtl_addr;
> +    ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
> +    if (ret < 0) {
> +        dprintf("Unable to set dispatch trace log state to KVM: %s\n",
> +                strerror(errno));
> +        return ret;
> +    }
> +
> +    if (!env->vpa_addr) {
> +        reg.id = KVM_REG_PPC_VPA_ADDR;
> +        reg.addr = (uintptr_t)&env->vpa_addr;
> +        ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
> +        if (ret < 0) {
> +            dprintf("Unable to set VPA address to KVM: %s\n", strerror(errno));
> +            return ret;
> +        }
> +    }
> +
> +    return 0;
> +}
> +#endif /* TARGET_PPC64 */
> +
> int kvm_arch_put_registers(CPUState *cs, int level)
> {
>     PowerPCCPU *cpu = POWERPC_CPU(cs);
> @@ -752,6 +852,14 @@ int kvm_arch_put_registers(CPUState *cs, int level)
>                 kvm_put_one_spr(cs, id, i);
>             }
>         }
> +
> +#ifdef TARGET_PPC64
> +        if (cap_papr) {
> +            if (kvm_put_vpa(cs) < 0) {
> +                dprintf("Warning: Unable to set VPA information to KVM\n");
> +            }
> +        }
> +#endif /* TARGET_PPC64 */
>     }
> 
>     return ret;
> @@ -953,6 +1061,15 @@ int kvm_arch_get_registers(CPUState *cs)
>                 kvm_get_one_spr(cs, id, i);
>             }
>         }
> +
> +#ifdef TARGET_PPC64
> +        if (cap_papr) {
> +            if (kvm_get_vpa(cs) < 0) {
> +                fprintf(stderr,
> +                        "Warning: Unable to get VPA information from KVM\n");

This will give odd warnings on old HV KVM systems and PR KVM, no?


Alex

> +            }
> +        }
> +#endif
>     }
> 
>     return 0;
> @@ -1299,6 +1416,10 @@ void kvmppc_set_papr(PowerPCCPU *cpu)
>     if (ret) {
>         cpu_abort(env, "This KVM version does not support PAPR\n");
>     }
> +
> +    /* Update the capability flag so we sync the right information
> +     * with kvm */
> +    cap_papr = 1;
> }
> 
> void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
> -- 
> 1.7.10.4
> 

  reply	other threads:[~2013-03-15 12:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-14  1:53 [Qemu-devel] [0/5] Assorted pending pseries machine patches David Gibson
2013-03-14  1:53 ` [Qemu-devel] [PATCH 1/5] target-ppc: Synchronize VPA state with KVM David Gibson
2013-03-15 12:22   ` Alexander Graf [this message]
2013-04-08  5:01     ` [Qemu-devel] [Qemu-ppc] " David Gibson
2013-03-14  1:53 ` [Qemu-devel] [PATCH 2/5] pseries: Remove "busname" property for PCI host bridge David Gibson
2013-03-15 12:39   ` Alexander Graf
2013-03-14  1:53 ` [Qemu-devel] [PATCH 3/5] pseries: Fixes and enhancements to L1 cache properties David Gibson
2013-03-15 12:27   ` Alexander Graf
2013-03-16  7:10     ` [Qemu-devel] [Qemu-ppc] " David Gibson
2013-03-18 11:10       ` Andreas Färber
2013-03-19  0:52         ` David Gibson
2013-03-18 10:54     ` [Qemu-devel] " Andreas Färber
2013-03-18 11:05       ` Alexander Graf
2013-03-19 11:06         ` Andreas Färber
2013-03-19 11:09           ` Alexander Graf
2013-03-19 11:16             ` Andreas Färber
2013-03-19 11:37               ` Alexander Graf
2013-03-19  1:00       ` [Qemu-devel] [Qemu-ppc] " David Gibson
2013-03-19 10:10         ` Alexander Graf
2013-03-14  1:53 ` [Qemu-devel] [PATCH 4/5] target-ppc: Remove CONFIG_PSERIES dependency in kvm.c David Gibson
2013-03-15 12:39   ` Alexander Graf
2013-03-14  1:53 ` [Qemu-devel] [PATCH 5/5] pseries: Move XICS initialization before cpu initialization David Gibson
2013-03-15 12:33   ` Alexander Graf
2013-03-16  3:14     ` Benjamin Herrenschmidt
2013-03-16  5:33       ` Alexander Graf
2013-03-16  5:41         ` Benjamin Herrenschmidt
2013-03-16  6:07           ` Alexander Graf
2013-03-18  2:55     ` [Qemu-devel] [Qemu-ppc] " David Gibson
2013-03-18  3:12       ` Alexander Graf
2013-03-18  3:38         ` David Gibson
2013-03-21 10:01           ` Alexander Graf

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=43A59AA0-E31D-42D5-88EC-19D370A4D235@suse.de \
    --to=agraf@suse.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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.