All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, David Gibson <david@gibson.dropbear.id.au>,
	Suraj Jitindar Singh <sjitindarsingh@gmail.com>,
	Thomas Huth <thuth@redhat.com>
Subject: [Qemu-devel] [PATCH 2/4] spapr: introduce a helper to compute the address of the HPT
Date: Mon, 04 Sep 2017 23:47:05 +0200	[thread overview]
Message-ID: <150456162500.17000.8195671755736683016.stgit@bahia.lan> (raw)
In-Reply-To: <150456160452.17000.3290192176290246589.stgit@bahia.lan>

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 <groug@kaod.org>
---
 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 *vhyp, hwaddr ptex,
     }
 }
 
+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] = (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 = spapr_get_hpt_pointer(spapr);
+        if (sdr1) {
+            env->spr[SPR_SDR1] = 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 *cpu,
 
         if (kvm_enabled()) {
             /* For KVM PR, update the HPT pointer */
-            target_ulong sdr1 = (target_ulong)(uintptr_t)spapr->htab
-                | (spapr->htab_shift - 18);
-            kvmppc_update_sdr1(sdr1);
+            target_ulong sdr1 = spapr_get_hpt_pointer(spapr);
+            if (sdr1) {
+                kvmppc_update_sdr1(sdr1);
+            }
         }
 
         pending->hpt = NULL; /* so it's not free()d */
@@ -1566,9 +1567,10 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
             spapr_reallocate_hpt(spapr, maxshift, &error_fatal);
             if (kvm_enabled()) {
                 /* For KVM PR, update the HPT pointer */
-                target_ulong sdr1 = (target_ulong)(uintptr_t)spapr->htab
-                    | (spapr->htab_shift - 18);
-                kvmppc_update_sdr1(sdr1);
+                target_ulong sdr1 = 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);
 
+target_ulong spapr_get_hpt_pointer(sPAPRMachineState *spapr);
 #endif /* HW_SPAPR_H */

  parent reply	other threads:[~2017-09-04 21:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 21:46 [Qemu-devel] [PATCH 0/4] ppc: fix migration with KVM PR (nested) Greg Kurz
2017-09-04 21:46 ` [Qemu-devel] [PATCH 1/4] spapr: only update SDR1 once per-cpu during CAS Greg Kurz
2017-09-10  1:58   ` David Gibson
2017-09-04 21:47 ` Greg Kurz [this message]
2017-09-10  3:41   ` [Qemu-devel] [PATCH 2/4] spapr: introduce a helper to compute the address of the HPT David Gibson
2017-09-11 12:04     ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2017-09-11 12:50       ` David Gibson
2017-09-11 13:54         ` Greg Kurz
2017-09-04 21:47 ` [Qemu-devel] [PATCH 3/4] ppc: kvm: introduce a helper to update SDR1 for a single CPU Greg Kurz
2017-09-10  3:56   ` David Gibson
2017-09-04 21:47 ` [Qemu-devel] [PATCH 4/4] ppc: kvm: update HPT pointer in KVM PR after migration Greg Kurz
2017-09-05 14:36 ` [Qemu-devel] [Qemu-ppc] [PATCH 0/4] ppc: fix migration with KVM PR (nested) Greg Kurz

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=150456162500.17000.8195671755736683016.stgit@bahia.lan \
    --to=groug@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=sjitindarsingh@gmail.com \
    --cc=thuth@redhat.com \
    /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.