qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Harsh Prateek Bora <harshpb@linux.ibm.com>
To: npiggin@gmail.com, qemu-ppc@nongnu.org
Cc: qemu-devel@nongnu.org, clegoate@redhat.com, mikey@neuling.org,
	amachhiw@linux.vnet.ibm.com, vaibhav@linux.ibm.com,
	sbhat@linux.ibm.com, danielhb413@gmail.com
Subject: [PATCH v3 07/15] spapr: nested: Introduce H_GUEST_[CREATE|DELETE] hcalls.
Date: Thu, 18 Jan 2024 10:54:30 +0530	[thread overview]
Message-ID: <20240118052438.1475437-8-harshpb@linux.ibm.com> (raw)
In-Reply-To: <20240118052438.1475437-1-harshpb@linux.ibm.com>

Introduce the nested PAPR hcalls:
    - H_GUEST_CREATE which is used to create and allocate resources for
nested guest being created.
    - H_GUEST_DELETE which is used to delete and deallocate resources
for the nested guest being deleted. It also supports deleting all nested
guests at once using a deleteAll flag.

[amachhiw: set capabilities check for no guests created before calling]

Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Amit Machhiwal <amachhiw@linux.vnet.ibm.com>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
 include/hw/ppc/spapr.h        |   4 +-
 include/hw/ppc/spapr_nested.h |   7 +++
 hw/ppc/spapr_nested.c         | 106 ++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 5e0939fcc0..5a001a7c00 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -586,8 +586,10 @@ struct SpaprMachineState {
 #define H_WATCHDOG              0x45C
 #define H_GUEST_GET_CAPABILITIES 0x460
 #define H_GUEST_SET_CAPABILITIES 0x464
+#define H_GUEST_CREATE           0x470
+#define H_GUEST_DELETE           0x488
 
-#define MAX_HCALL_OPCODE         H_GUEST_SET_CAPABILITIES
+#define MAX_HCALL_OPCODE         H_GUEST_DELETE
 
 /* The hcalls above are standardized in PAPR and implemented by pHyp
  * as well.
diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h
index ea617c4710..a01f8e37ab 100644
--- a/include/hw/ppc/spapr_nested.h
+++ b/include/hw/ppc/spapr_nested.h
@@ -10,8 +10,13 @@ typedef struct SpaprMachineStateNested {
 #define NESTED_API_KVM_HV  1
     bool capabilities_set;
     uint32_t pvr_base;
+    GHashTable *guests;
 } SpaprMachineStateNested;
 
+typedef struct SpaprMachineStateNestedGuest {
+    uint32_t pvr_logical;
+} SpaprMachineStateNestedGuest;
+
 /* Nested PAPR API related macros */
 #define H_GUEST_CAPABILITIES_COPY_MEM 0x8000000000000000
 #define H_GUEST_CAPABILITIES_P9_MODE  0x4000000000000000
@@ -21,6 +26,8 @@ typedef struct SpaprMachineStateNested {
 #define H_GUEST_CAP_COPY_MEM_BMAP     0
 #define H_GUEST_CAP_P9_MODE_BMAP      1
 #define H_GUEST_CAP_P10_MODE_BMAP     2
+#define PAPR_NESTED_GUEST_MAX         4096
+#define H_GUEST_DELETE_ALL_FLAG       0x8000000000000000ULL
 
 /*
  * Register state for entering a nested guest with H_ENTER_NESTED.
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index d29224c3c9..1e620ef2fb 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -474,6 +474,11 @@ static target_ulong h_guest_set_capabilities(PowerPCCPU *cpu,
         return H_P2; /* isn't supported */
     }
 
+    /* Confirm there are no guests created yet */
+    if (spapr->nested.guests) {
+        return H_STATE;
+    }
+
     /* If there are no capabilities configured, set the R5 to the index of
      * the first supported Power Processor Mode
      */
@@ -514,6 +519,105 @@ static target_ulong h_guest_set_capabilities(PowerPCCPU *cpu,
     }
 }
 
+static void
+destroy_guest_helper(gpointer value)
+{
+    struct SpaprMachineStateNestedGuest *guest = value;
+    g_free(guest);
+}
+
+static target_ulong h_guest_create(PowerPCCPU *cpu,
+                                   SpaprMachineState *spapr,
+                                   target_ulong opcode,
+                                   target_ulong *args)
+{
+    CPUPPCState *env = &cpu->env;
+    target_ulong flags = args[0];
+    target_ulong continue_token = args[1];
+    uint64_t guestid;
+    int nguests = 0;
+    struct SpaprMachineStateNestedGuest *guest;
+
+    if (flags) { /* don't handle any flags for now */
+        return H_UNSUPPORTED_FLAG;
+    }
+
+    if (continue_token != -1) {
+        return H_P2;
+    }
+
+    if (!spapr->nested.capabilities_set) {
+        return H_STATE;
+    }
+
+    if (!spapr->nested.guests) {
+        spapr->nested.guests = g_hash_table_new_full(NULL,
+                                                     NULL,
+                                                     NULL,
+                                                     destroy_guest_helper);
+    }
+
+    nguests = g_hash_table_size(spapr->nested.guests);
+
+    if (nguests == PAPR_NESTED_GUEST_MAX) {
+        return H_NO_MEM;
+    }
+
+    /* Lookup for available guestid */
+    for (guestid = 1; guestid < PAPR_NESTED_GUEST_MAX; guestid++) {
+        if (!(g_hash_table_lookup(spapr->nested.guests,
+                                  GINT_TO_POINTER(guestid)))) {
+            break;
+        }
+    }
+
+    if (guestid == PAPR_NESTED_GUEST_MAX) {
+        return H_NO_MEM;
+    }
+
+    guest = g_try_new0(struct SpaprMachineStateNestedGuest, 1);
+    if (!guest) {
+        return H_NO_MEM;
+    }
+
+    guest->pvr_logical = spapr->nested.pvr_base;
+    g_hash_table_insert(spapr->nested.guests, GINT_TO_POINTER(guestid), guest);
+    env->gpr[4] = guestid;
+
+    return H_SUCCESS;
+}
+
+static target_ulong h_guest_delete(PowerPCCPU *cpu,
+                                   SpaprMachineState *spapr,
+                                   target_ulong opcode,
+                                   target_ulong *args)
+{
+    target_ulong flags = args[0];
+    target_ulong guestid = args[1];
+    struct SpaprMachineStateNestedGuest *guest;
+
+    /*
+     * handle flag deleteAllGuests, if set:
+     * guestid is ignored and all guests are deleted
+     *
+     */
+    if (flags & ~H_GUEST_DELETE_ALL_FLAG) {
+        return H_UNSUPPORTED_FLAG; /* other flag bits reserved */
+    } else if (flags & H_GUEST_DELETE_ALL_FLAG) {
+        g_hash_table_destroy(spapr->nested.guests);
+        return H_SUCCESS;
+    }
+
+    guest = g_hash_table_lookup(spapr->nested.guests, GINT_TO_POINTER(guestid));
+    if (!guest) {
+        return H_P2;
+    }
+
+    g_hash_table_remove(spapr->nested.guests, GINT_TO_POINTER(guestid));
+
+    return H_SUCCESS;
+}
+
 void spapr_register_nested_hv(void)
 {
     spapr_register_hypercall(KVMPPC_H_SET_PARTITION_TABLE, h_set_ptbl);
@@ -526,6 +630,8 @@ void spapr_register_nested_papr(void)
 {
     spapr_register_hypercall(H_GUEST_GET_CAPABILITIES, h_guest_get_capabilities);
     spapr_register_hypercall(H_GUEST_SET_CAPABILITIES, h_guest_set_capabilities);
+    spapr_register_hypercall(H_GUEST_CREATE          , h_guest_create);
+    spapr_register_hypercall(H_GUEST_DELETE          , h_guest_delete);
 }
 
 #else
-- 
2.39.3



  parent reply	other threads:[~2024-01-18  5:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18  5:24 [PATCH v3 00/15] Nested PAPR API (KVM on PowerVM) Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 01/15] spapr: nested: register nested-hv api hcalls only for cap-nested-hv Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 02/15] spapr: nested: move nested part of spapr_get_pate into spapr_nested.c Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 03/15] spapr: nested: Introduce SpaprMachineStateNested to store related info Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 04/15] spapr: nested: keep nested-hv related code restricted to its API Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 05/15] spapr: nested: Document Nested PAPR API Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 06/15] spapr: nested: Introduce H_GUEST_[GET|SET]_CAPABILITIES hcalls Harsh Prateek Bora
2024-01-18  5:24 ` Harsh Prateek Bora [this message]
2024-01-18  5:24 ` [PATCH v3 08/15] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 09/15] spapr: nested: Extend nested_ppc_state for nested PAPR API Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 10/15] spapr: nested: Initialize the GSB elements lookup table Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 11/15] spapr: nested: Introduce H_GUEST_[GET|SET]_STATE hcalls Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 12/15] spapr: nested: Use correct source for parttbl info for nested PAPR API Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 13/15] spapr: nested: Introduce H_GUEST_RUN_VCPU hcall Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 14/15] spapr: nested: Introduce cap-nested-papr for Nested PAPR API Harsh Prateek Bora
2024-01-18  5:24 ` [PATCH v3 15/15] spapr: nested: Set the PCR when logical PVR is set Harsh Prateek Bora

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=20240118052438.1475437-8-harshpb@linux.ibm.com \
    --to=harshpb@linux.ibm.com \
    --cc=amachhiw@linux.vnet.ibm.com \
    --cc=clegoate@redhat.com \
    --cc=danielhb413@gmail.com \
    --cc=mikey@neuling.org \
    --cc=npiggin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=sbhat@linux.ibm.com \
    --cc=vaibhav@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).