From nobody Mon May 6 21:41:39 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 150456185123661.090903739401256; Mon, 4 Sep 2017 14:50:51 -0700 (PDT) Received: from localhost ([::1]:55819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozGc-0006R0-0E for importer@patchew.org; Mon, 04 Sep 2017 17:50:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozD2-0003jn-8T for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dozCx-0002u5-LE for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:08 -0400 Received: from 10.mo178.mail-out.ovh.net ([46.105.76.150]:38929) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dozCx-0002t7-Ep for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:03 -0400 Received: from player728.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id F3D394AE24 for ; Mon, 4 Sep 2017 23:46:59 +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 player728.ha.ovh.net (Postfix) with ESMTPA id A9BD354006C; Mon, 4 Sep 2017 23:46:55 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 04 Sep 2017 23:46:55 +0200 Message-ID: <150456161545.17000.9223127644314285105.stgit@bahia.lan> In-Reply-To: <150456160452.17000.3290192176290246589.stgit@bahia.lan> References: <150456160452.17000.3290192176290246589.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: 14542967625193134386 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrvdejgddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.76.150 Subject: [Qemu-devel] [PATCH 1/4] spapr: only update SDR1 once per-cpu during CAS 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: Thomas Huth , qemu-ppc@nongnu.org, Suraj Jitindar Singh , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Commit b55d295e3ec9 added the possibility to support HPT resizing with KVM. In the case of PR, we need to pass the userspace address of the HPT to KVM using the SDR1 slot. This is handled by kvmppc_update_sdr1() which uses CPU_FOREACH() to update all CPUs. It is hence not needed to call kvmppc_update_sdr1() for each CPU. Signed-off-by: Greg Kurz --- hw/ppc/spapr_hcall.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 8b3c0e17e75c..6ab8c188f381 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1559,20 +1559,16 @@ static target_ulong h_client_architecture_support(P= owerPCCPU *cpu, } =20 if (spapr->htab_shift < maxshift) { - CPUState *cs; - /* Guest doesn't know about HPT resizing, so we * pre-emptively resize for the maximum permitted RAM. At * the point this is called, nothing should have been * entered into the existing HPT */ spapr_reallocate_hpt(spapr, maxshift, &error_fatal); - CPU_FOREACH(cs) { - 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); - } + 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); } } } From nobody Mon May 6 21:41:39 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 1504561761733162.4318671166419; Mon, 4 Sep 2017 14:49:21 -0700 (PDT) Received: from localhost ([::1]:55807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozFA-000522-MV for importer@patchew.org; Mon, 04 Sep 2017 17:49:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozD9-0003pk-Hd for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dozD4-0002yy-R1 for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:15 -0400 Received: from 4.mo178.mail-out.ovh.net ([46.105.49.171]:37341) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dozD4-0002yA-KL for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:10 -0400 Received: from player728.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id 85A0151124 for ; Mon, 4 Sep 2017 23:47:09 +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 player728.ha.ovh.net (Postfix) with ESMTPA id 3B20654006C; Mon, 4 Sep 2017 23:47:05 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 04 Sep 2017 23:47:05 +0200 Message-ID: <150456162500.17000.8195671755736683016.stgit@bahia.lan> In-Reply-To: <150456160452.17000.3290192176290246589.stgit@bahia.lan> References: <150456160452.17000.3290192176290246589.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: 14545782372532394290 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrvdejgddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.49.171 Subject: [Qemu-devel] [PATCH 2/4] spapr: introduce a helper to compute the address of the HPT 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: Thomas Huth , qemu-ppc@nongnu.org, Suraj Jitindar Singh , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The formula used to compute the address of the HPT allocated by QEMU is open-coded in several places. This patch moves the magic to a dedicated helper. While here, we also patch the callers to only pass the address to KVM if we indeed have a userland HPT (ie, KVM PR). Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 9 +++++++++ hw/ppc/spapr_cpu_core.c | 12 +++++++----- hw/ppc/spapr_hcall.c | 14 ++++++++------ include/hw/ppc/spapr.h | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index caffa1276328..bf24c26b756d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1290,6 +1290,15 @@ static void spapr_store_hpte(PPCVirtualHypervisor *v= hyp, hwaddr ptex, } } =20 +target_ulong spapr_get_hpt_pointer(sPAPRMachineState *spapr) +{ + if (!spapr->htab) { + return 0; + } + + return (target_ulong)(uintptr_t)spapr->htab | (spapr->htab_shift - 18); +} + int spapr_hpt_shift_for_ramsize(uint64_t ramsize) { int shift; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 85037ef71e27..581eb4d92de9 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -93,11 +93,13 @@ static void spapr_cpu_reset(void *opaque) * 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); + target_ulong sdr1 =3D spapr_get_hpt_pointer(spapr); + if (sdr1) { + env->spr[SPR_SDR1] =3D sdr1; + if (kvmppc_put_books_sregs(cpu) < 0) { + error_report("Unable to update SDR1 in KVM"); + exit(1); + } } } } diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 6ab8c188f381..06059b44ab40 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -735,9 +735,10 @@ static target_ulong h_resize_hpt_commit(PowerPCCPU *cp= u, =20 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); + target_ulong sdr1 =3D spapr_get_hpt_pointer(spapr); + if (sdr1) { + kvmppc_update_sdr1(sdr1); + } } =20 pending->hpt =3D NULL; /* so it's not free()d */ @@ -1566,9 +1567,10 @@ static target_ulong h_client_architecture_support(Po= werPCCPU *cpu, 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); + target_ulong sdr1 =3D spapr_get_hpt_pointer(spapr); + if (sdr1) { + kvmppc_update_sdr1(sdr1); + } } } } diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index c1b365f56431..a1f5edc15018 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -709,4 +709,5 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_= cpu_data arg); int spapr_vcpu_id(PowerPCCPU *cpu); PowerPCCPU *spapr_find_cpu(int vcpu_id); =20 +target_ulong spapr_get_hpt_pointer(sPAPRMachineState *spapr); #endif /* HW_SPAPR_H */ From nobody Mon May 6 21:41:39 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 1504561754213210.03522158734563; Mon, 4 Sep 2017 14:49:14 -0700 (PDT) Received: from localhost ([::1]:55806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozF3-0004ww-5s for importer@patchew.org; Mon, 04 Sep 2017 17:49:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozDK-0003uN-Ie for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dozDE-00037a-Hi for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:26 -0400 Received: from 4.mo178.mail-out.ovh.net ([46.105.49.171]:32921) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dozDE-00036Y-A7 for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:20 -0400 Received: from player728.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id 30B1351124 for ; Mon, 4 Sep 2017 23:47:19 +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 player728.ha.ovh.net (Postfix) with ESMTPA id C54AB54006C; Mon, 4 Sep 2017 23:47:14 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 04 Sep 2017 23:47:14 +0200 Message-ID: <150456163456.17000.11736294199857677034.stgit@bahia.lan> In-Reply-To: <150456160452.17000.3290192176290246589.stgit@bahia.lan> References: <150456160452.17000.3290192176290246589.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: 14548597123388053810 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrvdejgddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.49.171 Subject: [Qemu-devel] [PATCH 3/4] ppc: kvm: introduce a helper to update SDR1 for a single CPU 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: Thomas Huth , qemu-ppc@nongnu.org, Suraj Jitindar Singh , 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, we hijack the SDR1 slot to pass the address of the HPT allocated by QEMU to KVM. On pseries virtual machines, we have to do this when the guest calls the KVMPPC_H_CAS or the H_RESIZE_HPT_COMMIT hypercalls. This is currently handled by kvmppc_update_sdr1() which updates SDR1 for all CPUs. But we also need to update SDR1 at machine reset, and this is currently open-coded in spapr_cpu_reset() on a per-CPU basis. This patch renames kvmppc_update_sdr1() to kvmppc_update_sdr1_all() and reuses the kvmppc_update_sdr1() function name to update a single CPU, like we already do with in the CPU compat mode code. It finally converts the sPAPR code to use the all CPUs or single CPU helpers where appropriate. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 6 +----- hw/ppc/spapr_hcall.c | 4 ++-- target/ppc/kvm.c | 12 ++++++++---- target/ppc/kvm_ppc.h | 3 ++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 581eb4d92de9..da81688b0f4d 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -95,11 +95,7 @@ static void spapr_cpu_reset(void *opaque) if (kvm_enabled()) { target_ulong sdr1 =3D spapr_get_hpt_pointer(spapr); if (sdr1) { - env->spr[SPR_SDR1] =3D sdr1; - if (kvmppc_put_books_sregs(cpu) < 0) { - error_report("Unable to update SDR1 in KVM"); - exit(1); - } + kvmppc_update_sdr1(cpu, sdr1); } } } diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 06059b44ab40..e090b69efe7f 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -737,7 +737,7 @@ static target_ulong h_resize_hpt_commit(PowerPCCPU *cpu, /* For KVM PR, update the HPT pointer */ target_ulong sdr1 =3D spapr_get_hpt_pointer(spapr); if (sdr1) { - kvmppc_update_sdr1(sdr1); + kvmppc_update_sdr1_all(sdr1); } } =20 @@ -1569,7 +1569,7 @@ static target_ulong h_client_architecture_support(Pow= erPCCPU *cpu, /* For KVM PR, update the HPT pointer */ target_ulong sdr1 =3D spapr_get_hpt_pointer(spapr); if (sdr1) { - kvmppc_update_sdr1(sdr1); + kvmppc_update_sdr1_all(sdr1); } } } diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 6442dfcb95b3..e69366968f15 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2806,10 +2806,9 @@ 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) +void kvmppc_update_sdr1(PowerPCCPU *cpu, target_ulong sdr1) { - target_ulong sdr1 =3D arg.target_ptr; - PowerPCCPU *cpu =3D POWERPC_CPU(cs); + CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; =20 /* This is just for the benefit of PR KVM */ @@ -2821,7 +2820,12 @@ static void kvmppc_pivot_hpt_cpu(CPUState *cs, run_o= n_cpu_data arg) } } =20 -void kvmppc_update_sdr1(target_ulong sdr1) +static void kvmppc_pivot_hpt_cpu(CPUState *cs, run_on_cpu_data arg) +{ + kvmppc_update_sdr1(POWERPC_CPU(cs), arg.target_ptr); +} + +void kvmppc_update_sdr1_all(target_ulong sdr1) { CPUState *cs; =20 diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index f780e6ec7b72..9524a7a0c21c 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -68,7 +68,8 @@ 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); +void kvmppc_update_sdr1(PowerPCCPU *cpu, target_ulong sdr1); +void kvmppc_update_sdr1_all(target_ulong sdr1); bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu); =20 bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path); From nobody Mon May 6 21:41:39 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 150456189221748.01084271806906; Mon, 4 Sep 2017 14:51:32 -0700 (PDT) Received: from localhost ([::1]:55821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozHF-0006wZ-Cv for importer@patchew.org; Mon, 04 Sep 2017 17:51:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dozDT-00040q-2d for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dozDO-0003DF-9U for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:35 -0400 Received: from 3.mo178.mail-out.ovh.net ([46.105.44.197]:59569) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dozDO-0003C9-3L for qemu-devel@nongnu.org; Mon, 04 Sep 2017 17:47:30 -0400 Received: from player728.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id BE85A512D6 for ; Mon, 4 Sep 2017 23:47:28 +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 player728.ha.ovh.net (Postfix) with ESMTPA id 77275540079; Mon, 4 Sep 2017 23:47:24 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 04 Sep 2017 23:47:24 +0200 Message-ID: <150456164425.17000.14656319266821117631.stgit@bahia.lan> In-Reply-To: <150456160452.17000.3290192176290246589.stgit@bahia.lan> References: <150456160452.17000.3290192176290246589.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: 14551130398363523378 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrvdejgddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.44.197 Subject: [Qemu-devel] [PATCH 4/4] ppc: kvm: update HPT pointer in KVM PR after migration 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: Thomas Huth , qemu-ppc@nongnu.org, Suraj Jitindar Singh , 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, a pseries machine needs to allocate an HPT in userspace and pass its address to KVM. This is done by hijacking the SDR1 slot. It is very likely that the destination QEMU will allocate the HPT at a different address, ie, the SDR1 value we get from the migration stream is wrong and the guest ends up badly broken. Let's fix this by re-computing the appropriate value for SDR1 and pushing it to KVM at CPU post load. This is achieved by extending the PPC virtual hypervisor interface. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 6 ++++++ target/ppc/cpu.h | 1 + target/ppc/machine.c | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index bf24c26b756d..11c65563bb6e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1299,6 +1299,11 @@ target_ulong spapr_get_hpt_pointer(sPAPRMachineState= *spapr) return (target_ulong)(uintptr_t)spapr->htab | (spapr->htab_shift - 18); } =20 +static target_ulong get_spapr_hpt_pointer(PPCVirtualHypervisor *vhyp) +{ + return spapr_get_hpt_pointer(SPAPR_MACHINE(vhyp)); +} + int spapr_hpt_shift_for_ramsize(uint64_t ramsize) { int shift; @@ -3613,6 +3618,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->get_hpt_pointer =3D get_spapr_hpt_pointer; xic->ics_get =3D spapr_ics_get; xic->ics_resend =3D spapr_ics_resend; xic->icp_get =3D spapr_icp_get; diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index c9d3ffa89bcb..bb1d61c9358c 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1243,6 +1243,7 @@ struct PPCVirtualHypervisorClass { void (*store_hpte)(PPCVirtualHypervisor *vhyp, hwaddr ptex, uint64_t pte0, uint64_t pte1); uint64_t (*get_patbe)(PPCVirtualHypervisor *vhyp); + target_ulong (*get_hpt_pointer)(PPCVirtualHypervisor *vhyp); }; =20 #define TYPE_PPC_VIRTUAL_HYPERVISOR "ppc-virtual-hypervisor" diff --git a/target/ppc/machine.c b/target/ppc/machine.c index e36b7100cb66..6ec4b3214a2d 100644 --- a/target/ppc/machine.c +++ b/target/ppc/machine.c @@ -294,6 +294,13 @@ static int cpu_post_load(void *opaque, int version_id) =20 if (!cpu->vhyp) { ppc_store_sdr1(env, env->spr[SPR_SDR1]); + } else if (kvm_enabled()) { + PPCVirtualHypervisorClass *vhc =3D + PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); + target_ulong sdr1 =3D vhc->get_hpt_pointer(cpu->vhyp); + if (sdr1) { + kvmppc_update_sdr1(cpu, sdr1); + } } =20 /* Invalidate all msr bits except MSR_TGPR/MSR_HVB before restoring */