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: clg@kaod.org, mikey@neuling.org, amachhiw@linux.vnet.ibm.com,
	vaibhav@linux.ibm.com, sbhat@linux.ibm.com,
	danielhb413@gmail.com, qemu-devel@nongnu.org
Subject: [PATCH v5 08/14] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall.
Date: Fri,  8 Mar 2024 16:49:34 +0530	[thread overview]
Message-ID: <20240308111940.1617660-9-harshpb@linux.ibm.com> (raw)
In-Reply-To: <20240308111940.1617660-1-harshpb@linux.ibm.com>

Introduce the nested PAPR hcall H_GUEST_CREATE_VCPU which is used to
create and initialize the specified VCPU resource for the previously
created guest. Each guest can have multiple VCPUs upto max 2048.
All VCPUs for a guest gets deallocated on guest delete.

Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
 include/hw/ppc/spapr.h        |  2 ++
 include/hw/ppc/spapr_nested.h |  8 +++++
 hw/ppc/spapr_nested.c         | 61 +++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)

diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 13416fc3d7..070135793a 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -365,6 +365,7 @@ struct SpaprMachineState {
 #define H_UNSUPPORTED     -67
 #define H_OVERLAP         -68
 #define H_STATE           -75
+#define H_IN_USE          -77
 #define H_UNSUPPORTED_FLAG -256
 #define H_MULTI_THREADS_ACTIVE -9005
 
@@ -587,6 +588,7 @@ struct SpaprMachineState {
 #define H_GUEST_GET_CAPABILITIES 0x460
 #define H_GUEST_SET_CAPABILITIES 0x464
 #define H_GUEST_CREATE           0x470
+#define H_GUEST_CREATE_VCPU      0x474
 #define H_GUEST_DELETE           0x488
 
 #define MAX_HCALL_OPCODE         H_GUEST_DELETE
diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h
index 56d43e540b..2ac3076fac 100644
--- a/include/hw/ppc/spapr_nested.h
+++ b/include/hw/ppc/spapr_nested.h
@@ -14,6 +14,8 @@ typedef struct SpaprMachineStateNested {
 
 typedef struct SpaprMachineStateNestedGuest {
     uint32_t pvr_logical;
+    unsigned long nr_vcpus;
+    struct SpaprMachineStateNestedGuestVcpu *vcpus;
 } SpaprMachineStateNestedGuest;
 
 /* Nested PAPR API related macros */
@@ -27,6 +29,7 @@ typedef struct SpaprMachineStateNestedGuest {
 #define H_GUEST_CAP_P10_MODE_BMAP     2
 #define PAPR_NESTED_GUEST_MAX         4096
 #define H_GUEST_DELETE_ALL_FLAG       0x8000000000000000ULL
+#define PAPR_NESTED_GUEST_VCPU_MAX    2048
 
 /*
  * Register state for entering a nested guest with H_ENTER_NESTED.
@@ -120,6 +123,11 @@ struct nested_ppc_state {
     int64_t tb_offset;
 };
 
+typedef struct SpaprMachineStateNestedGuestVcpu {
+    bool enabled;
+    struct nested_ppc_state state;
+} SpaprMachineStateNestedGuestVcpu;
+
 void spapr_exit_nested(PowerPCCPU *cpu, int excp);
 typedef struct SpaprMachineState SpaprMachineState;
 bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index 13674c0857..4c0e2e91e1 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -8,6 +8,7 @@
 #include "hw/ppc/spapr_nested.h"
 #include "mmu-book3s-v3.h"
 #include "cpu-models.h"
+#include "qemu/log.h"
 
 void spapr_nested_reset(SpaprMachineState *spapr)
 {
@@ -434,6 +435,16 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp)
     }
 }
 
+static
+SpaprMachineStateNestedGuest *spapr_get_nested_guest(SpaprMachineState *spapr,
+                                                     target_ulong guestid)
+{
+    SpaprMachineStateNestedGuest *guest;
+
+    guest = g_hash_table_lookup(spapr->nested.guests, GINT_TO_POINTER(guestid));
+    return guest;
+}
+
 static target_ulong h_guest_get_capabilities(PowerPCCPU *cpu,
                                              SpaprMachineState *spapr,
                                              target_ulong opcode,
@@ -524,6 +535,7 @@ static void
 destroy_guest_helper(gpointer value)
 {
     struct SpaprMachineStateNestedGuest *guest = value;
+    g_free(guest->vcpus);
     g_free(guest);
 }
 
@@ -619,6 +631,53 @@ static target_ulong h_guest_delete(PowerPCCPU *cpu,
     return H_SUCCESS;
 }
 
+static target_ulong h_guest_create_vcpu(PowerPCCPU *cpu,
+                                        SpaprMachineState *spapr,
+                                        target_ulong opcode,
+                                        target_ulong *args)
+{
+    target_ulong flags = args[0];
+    target_ulong guestid = args[1];
+    target_ulong vcpuid = args[2];
+    SpaprMachineStateNestedGuest *guest;
+
+    if (flags) { /* don't handle any flags for now */
+        return H_UNSUPPORTED_FLAG;
+    }
+
+    guest = spapr_get_nested_guest(spapr, guestid);
+    if (!guest) {
+        return H_P2;
+    }
+
+    if (vcpuid < guest->nr_vcpus) {
+        qemu_log_mask(LOG_UNIMP, "vcpuid %ld already in use, return.", vcpuid);
+        return H_IN_USE;
+    }
+    /* linear vcpuid allocation only */
+    assert(vcpuid == guest->nr_vcpus);
+
+    if (guest->nr_vcpus >= PAPR_NESTED_GUEST_VCPU_MAX) {
+        return H_P3;
+    }
+
+    SpaprMachineStateNestedGuestVcpu *vcpus, *curr_vcpu;
+    vcpus = g_try_renew(struct SpaprMachineStateNestedGuestVcpu,
+                        guest->vcpus,
+                        guest->nr_vcpus + 1);
+    if (!vcpus) {
+        return H_NO_MEM;
+    }
+    guest->vcpus = vcpus;
+    curr_vcpu = &vcpus[guest->nr_vcpus];
+    memset(curr_vcpu, 0, sizeof(SpaprMachineStateNestedGuestVcpu));
+
+    curr_vcpu->enabled = true;
+    guest->nr_vcpus++;
+
+    return H_SUCCESS;
+}
+
 void spapr_register_nested_hv(void)
 {
     spapr_register_hypercall(KVMPPC_H_SET_PARTITION_TABLE, h_set_ptbl);
@@ -641,6 +700,7 @@ void spapr_register_nested_papr(void)
     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);
+    spapr_register_hypercall(H_GUEST_CREATE_VCPU     , h_guest_create_vcpu);
 }
 
 void spapr_unregister_nested_papr(void)
@@ -649,6 +709,7 @@ void spapr_unregister_nested_papr(void)
     spapr_unregister_hypercall(H_GUEST_SET_CAPABILITIES);
     spapr_unregister_hypercall(H_GUEST_CREATE);
     spapr_unregister_hypercall(H_GUEST_DELETE);
+    spapr_unregister_hypercall(H_GUEST_CREATE_VCPU);
 }
 
 #else
-- 
2.39.3



  parent reply	other threads:[~2024-03-08 11:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 11:19 [PATCH v5 00/14] Nested PAPR API (KVM on PowerVM) Harsh Prateek Bora
2024-03-08 11:19 ` [PATCH v5 01/14] spapr: nested: register nested-hv api hcalls only for cap-nested-hv Harsh Prateek Bora
2024-03-08 11:19 ` [PATCH v5 02/14] spapr: nested: move nested part of spapr_get_pate into spapr_nested.c Harsh Prateek Bora
2024-03-08 11:19 ` [PATCH v5 03/14] spapr: nested: Introduce SpaprMachineStateNested to store related info Harsh Prateek Bora
2024-03-08 11:19 ` [PATCH v5 04/14] spapr: nested: keep nested-hv related code restricted to its API Harsh Prateek Bora
2024-03-12 11:30   ` Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 05/14] spapr: nested: Document Nested PAPR API Harsh Prateek Bora
2024-03-12 11:30   ` Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 06/14] spapr: nested: Introduce H_GUEST_[GET|SET]_CAPABILITIES hcalls Harsh Prateek Bora
2024-03-12 11:30   ` Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 07/14] spapr: nested: Introduce H_GUEST_[CREATE|DELETE] hcalls Harsh Prateek Bora
2024-03-12 11:30   ` Nicholas Piggin
2024-03-08 11:19 ` Harsh Prateek Bora [this message]
2024-03-12 11:30   ` [PATCH v5 08/14] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 09/14] spapr: nested: Extend nested_ppc_state for nested PAPR API Harsh Prateek Bora
2024-03-12 11:37   ` Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 10/14] spapr: nested: Initialize the GSB elements lookup table Harsh Prateek Bora
2024-03-12 11:38   ` Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 11/14] spapr: nested: Introduce H_GUEST_[GET|SET]_STATE hcalls Harsh Prateek Bora
2024-03-12 11:38   ` Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 12/14] spapr: nested: Use correct source for parttbl info for nested PAPR API Harsh Prateek Bora
2024-03-12 11:41   ` Nicholas Piggin
2024-03-12 11:58     ` Harsh Prateek Bora
2024-03-08 11:19 ` [PATCH v5 13/14] spapr: nested: Introduce H_GUEST_RUN_VCPU hcall Harsh Prateek Bora
2024-03-12 11:42   ` Nicholas Piggin
2024-03-08 11:19 ` [PATCH v5 14/14] spapr: nested: Introduce cap-nested-papr for Nested PAPR API Harsh Prateek Bora
2024-03-12 11:45   ` Nicholas Piggin
2024-03-12 11:51   ` Nicholas Piggin
2024-03-12 12:11     ` Harsh Prateek Bora
2024-03-12 12:46       ` Nicholas Piggin
2024-03-12 12:47       ` Harsh Prateek Bora
2024-03-12 12:51         ` Harsh Prateek Bora
2024-03-12 13:18           ` Harsh Prateek Bora
2024-03-12  5:52 ` [PATCH v5 00/14] Nested PAPR API (KVM on PowerVM) Nicholas Piggin

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=20240308111940.1617660-9-harshpb@linux.ibm.com \
    --to=harshpb@linux.ibm.com \
    --cc=amachhiw@linux.vnet.ibm.com \
    --cc=clg@kaod.org \
    --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).