From nobody Tue Feb 10 06:43:57 2026 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 */