From nobody Thu May 2 17:35:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150529955191516.378417010210114; Wed, 13 Sep 2017 03:45:51 -0700 (PDT) Received: from localhost ([::1]:41496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds5B1-0004K0-7X for importer@patchew.org; Wed, 13 Sep 2017 06:45:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds56d-0000KI-Fs for qemu-devel@nongnu.org; Wed, 13 Sep 2017 06:41:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ds56Z-0004Qp-G9 for qemu-devel@nongnu.org; Wed, 13 Sep 2017 06:41:19 -0400 Received: from 4.mo2.mail-out.ovh.net ([87.98.172.75]:57807) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ds56Z-0004PD-6y for qemu-devel@nongnu.org; Wed, 13 Sep 2017 06:41:15 -0400 Received: from player770.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id ACC95A9602 for ; Wed, 13 Sep 2017 12:41:12 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player770.ha.ovh.net (Postfix) with ESMTPA id 3D63E3C008B; Wed, 13 Sep 2017 12:41:07 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 13 Sep 2017 12:41:07 +0200 Message-ID: <150529882490.818.398056435765712294.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 812899735725578579 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrgeeggdefgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.172.75 Subject: [Qemu-devel] [PATCH] spapr: fix the value of SDR1 in kvmppc_put_books_sregs() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, Sam Bobroff , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When running with KVM PR, if a new HPT is allocated we need to inform KVM about the HPT address and size. This is currently done by hacking the value of SDR1 and pushing it to KVM in several places. Also, migration breaks the guest since it is very unlikely the HPT has the same address in source and destination, but we push the incoming value of SDR1 to KVM anyway. This patch introduces a new virtual hypervisor hook so that the spapr code can provide the correct value of SDR1 to be pushed to KVM each time kvmppc_put_books_sregs() is called. It allows to get rid of all the hacking in the spapr/kvmppc code and it fixes migration of nested KVM PR. Suggested-by: David Gibson Signed-off-by: Greg Kurz --- Unfortunately, this doesn't fix migration when using KVM PR on baremetal. I get tons of instruction emulation errors in the console when the guest resumes execution at the destination: [ 833.585957] Couldn't emulate instruction 0x00000000 (op 0 xop 0) [ 833.586818] kvmppc_exit_pr_progint: emulation at 60000000600e5bfc failed (00000000) [ 833.674684] Couldn't emulate instruction 0x00000000 (op 0 xop 0) [ 833.675370] kvmppc_exit_pr_progint: emulation at 60000000600e5bfc failed (00000000) [ 833.676297] Couldn't emulate instruction 0x00000000 (op 0 xop 0) I still don't know what's happening here but I guess this is an issue in KVM. hw/ppc/spapr.c | 13 +++++++++++++ hw/ppc/spapr_cpu_core.c | 15 --------------- hw/ppc/spapr_hcall.c | 14 -------------- target/ppc/cpu.h | 2 ++ target/ppc/kvm.c | 30 +++++------------------------- target/ppc/kvm_ppc.h | 6 ------ 6 files changed, 20 insertions(+), 60 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f680f28a15ea..7e7ae585a1b6 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1239,6 +1239,18 @@ static hwaddr spapr_hpt_mask(PPCVirtualHypervisor *v= hyp) return HTAB_SIZE(spapr) / HASH_PTEG_SIZE_64 - 1; } =20 +static void spapr_encode_hpt_for_kvm_pr(PPCVirtualHypervisor *vhyp, + target_ulong *hpt) +{ + sPAPRMachineState *spapr =3D SPAPR_MACHINE(vhyp); + + assert(kvm_enabled()); + + if (spapr->htab) { + *hpt =3D (target_ulong)(uintptr_t)spapr->htab | (spapr->htab_shift= - 18); + } +} + static const ppc_hash_pte64_t *spapr_map_hptes(PPCVirtualHypervisor *vhyp, hwaddr ptex, int n) { @@ -3603,6 +3615,7 @@ static void spapr_machine_class_init(ObjectClass *oc,= void *data) vhc->unmap_hptes =3D spapr_unmap_hptes; vhc->store_hpte =3D spapr_store_hpte; vhc->get_patbe =3D spapr_get_patbe; + vhc->encode_hpt_for_kvm_pr =3D spapr_encode_hpt_for_kvm_pr; xic->ics_get =3D spapr_ics_get; xic->ics_resend =3D spapr_ics_resend; xic->icp_get =3D spapr_icp_get; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index c08ee7571a50..c20b5c64b045 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -73,7 +73,6 @@ void spapr_cpu_parse_features(sPAPRMachineState *spapr) =20 static void spapr_cpu_reset(void *opaque) { - sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); PowerPCCPU *cpu =3D opaque; CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; @@ -86,20 +85,6 @@ static void spapr_cpu_reset(void *opaque) cs->halted =3D 1; =20 env->spr[SPR_HIOR] =3D 0; - - /* - * This is a hack for the benefit of KVM PR - it abuses the SDR1 - * slot in kvm_sregs to communicate the userspace address of the - * HPT - */ - if (kvm_enabled()) { - env->spr[SPR_SDR1] =3D (target_ulong)(uintptr_t)spapr->htab - | (spapr->htab_shift - 18); - if (kvmppc_put_books_sregs(cpu) < 0) { - error_report("Unable to update SDR1 in KVM"); - exit(1); - } - } } =20 static void spapr_cpu_destroy(PowerPCCPU *cpu) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 57bb411394ed..840abff0e371 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -732,14 +732,6 @@ static target_ulong h_resize_hpt_commit(PowerPCCPU *cp= u, qemu_vfree(spapr->htab); spapr->htab =3D pending->hpt; spapr->htab_shift =3D pending->shift; - - if (kvm_enabled()) { - /* For KVM PR, update the HPT pointer */ - target_ulong sdr1 =3D (target_ulong)(uintptr_t)spapr->htab - | (spapr->htab_shift - 18); - kvmppc_update_sdr1(sdr1); - } - pending->hpt =3D NULL; /* so it's not free()d */ } =20 @@ -1564,12 +1556,6 @@ static target_ulong h_client_architecture_support(Po= werPCCPU *cpu, * the point this is called, nothing should have been * entered into the existing HPT */ spapr_reallocate_hpt(spapr, maxshift, &error_fatal); - if (kvm_enabled()) { - /* For KVM PR, update the HPT pointer */ - target_ulong sdr1 =3D (target_ulong)(uintptr_t)spapr->htab - | (spapr->htab_shift - 18); - kvmppc_update_sdr1(sdr1); - } } } =20 diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index c9d3ffa89bcb..12e0b6e74876 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1243,6 +1243,8 @@ struct PPCVirtualHypervisorClass { void (*store_hpte)(PPCVirtualHypervisor *vhyp, hwaddr ptex, uint64_t pte0, uint64_t pte1); uint64_t (*get_patbe)(PPCVirtualHypervisor *vhyp); + void (*encode_hpt_for_kvm_pr)(PPCVirtualHypervisor *vhyp, + target_ulong *hpt); }; =20 #define TYPE_PPC_VIRTUAL_HYPERVISOR "ppc-virtual-hypervisor" diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 6442dfcb95b3..8edc05fc6a83 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -941,7 +941,11 @@ int kvmppc_put_books_sregs(PowerPCCPU *cpu) =20 sregs.pvr =3D env->spr[SPR_PVR]; =20 - sregs.u.s.sdr1 =3D env->spr[SPR_SDR1]; + if (cpu->vhyp) { + PPCVirtualHypervisorClass *vhc =3D + PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); + vhc->encode_hpt_for_kvm_pr(cpu->vhyp, &sregs.u.s.sdr1); + } =20 /* Sync SLB */ #ifdef TARGET_PPC64 @@ -2806,30 +2810,6 @@ int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target= _ulong flags, int shift) return kvm_vm_ioctl(cs->kvm_state, KVM_PPC_RESIZE_HPT_COMMIT, &rhpt); } =20 -static void kvmppc_pivot_hpt_cpu(CPUState *cs, run_on_cpu_data arg) -{ - target_ulong sdr1 =3D arg.target_ptr; - PowerPCCPU *cpu =3D POWERPC_CPU(cs); - CPUPPCState *env =3D &cpu->env; - - /* This is just for the benefit of PR KVM */ - cpu_synchronize_state(cs); - env->spr[SPR_SDR1] =3D sdr1; - if (kvmppc_put_books_sregs(cpu) < 0) { - error_report("Unable to update SDR1 in KVM"); - exit(1); - } -} - -void kvmppc_update_sdr1(target_ulong sdr1) -{ - CPUState *cs; - - CPU_FOREACH(cs) { - run_on_cpu(cs, kvmppc_pivot_hpt_cpu, RUN_ON_CPU_TARGET_PTR(sdr1)); - } -} - /* * This is a helper function to detect a post migration scenario * in which a guest, running as KVM-HV, freezes in cpu_post_load because diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index f780e6ec7b72..21571edd7910 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -68,7 +68,6 @@ PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void); void kvmppc_check_papr_resize_hpt(Error **errp); int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, target_ulong flags, int shi= ft); int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulong flags, int shif= t); -void kvmppc_update_sdr1(target_ulong sdr1); bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu); =20 bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path); @@ -331,11 +330,6 @@ static inline int kvmppc_resize_hpt_commit(PowerPCCPU = *cpu, return -ENOSYS; } =20 -static inline void kvmppc_update_sdr1(target_ulong sdr1) -{ - abort(); -} - #endif =20 #ifndef CONFIG_KVM