[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 32/38] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall.
From: |
Nicholas Piggin |
Subject: |
[PULL 32/38] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall. |
Date: |
Wed, 13 Mar 2024 02:58:43 +1000 |
From: Harsh Prateek Bora <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.
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
hw/ppc/spapr_nested.c | 62 +++++++++++++++++++++++++++++++++++
include/hw/ppc/spapr.h | 2 ++
include/hw/ppc/spapr_nested.h | 8 +++++
3 files changed, 72 insertions(+)
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index 1f6eb68b93..72bf3dc6d4 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,
@@ -525,6 +536,7 @@ static void
destroy_guest_helper(gpointer value)
{
struct SpaprMachineStateNestedGuest *guest = value;
+ g_free(guest->vcpus);
g_free(guest);
}
@@ -620,6 +632,54 @@ 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 " TARGET_FMT_ld " already in use.",
+ 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);
@@ -644,6 +704,7 @@ void spapr_register_nested_papr(void)
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)
@@ -652,6 +713,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
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,
--
2.42.0
- [PULL 14/38] docs/system/ppc: Document running Linux on AmigaNG machines, (continued)
- [PULL 14/38] docs/system/ppc: Document running Linux on AmigaNG machines, Nicholas Piggin, 2024/03/12
- [PULL 17/38] ppc/pnv: Improve pervasive topology calculation for big-core, Nicholas Piggin, 2024/03/12
- [PULL 12/38] MAINTAINERS: Remove myself as reviewer from PPC, Nicholas Piggin, 2024/03/12
- [PULL 15/38] target/ppc: Move add and subf type fixed-point arithmetic instructions to decodetree, Nicholas Piggin, 2024/03/12
- [PULL 21/38] target/ppc: Clean up ifdefs in excp_helper.c, part 1, Nicholas Piggin, 2024/03/12
- [PULL 19/38] target/ppc: Readability improvements in exception handlers, Nicholas Piggin, 2024/03/12
- [PULL 20/38] target/ppc: Add gen_exception_err_nip() function, Nicholas Piggin, 2024/03/12
- [PULL 16/38] target/ppc: Add power10 pmu SPRs, Nicholas Piggin, 2024/03/12
- [PULL 18/38] target/ppc: Use env_cpu for cpu_abort in excp_helper, Nicholas Piggin, 2024/03/12
- [PULL 22/38] target/ppc: Clean up ifdefs in excp_helper.c, part 2, Nicholas Piggin, 2024/03/12
- [PULL 32/38] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall.,
Nicholas Piggin <=
- [PULL 24/38] target/ppc: Remove interrupt handler wrapper functions, Nicholas Piggin, 2024/03/12
- [PULL 25/38] spapr: nested: register nested-hv api hcalls only for cap-nested-hv, Nicholas Piggin, 2024/03/12
- [PULL 23/38] target/ppc: Clean up ifdefs in excp_helper.c, part 3, Nicholas Piggin, 2024/03/12
- [PULL 26/38] spapr: nested: move nested part of spapr_get_pate into spapr_nested.c, Nicholas Piggin, 2024/03/12
- [PULL 29/38] spapr: nested: Document Nested PAPR API, Nicholas Piggin, 2024/03/12
- [PULL 28/38] spapr: nested: keep nested-hv related code restricted to its API., Nicholas Piggin, 2024/03/12
- [PULL 30/38] spapr: nested: Introduce H_GUEST_[GET|SET]_CAPABILITIES hcalls., Nicholas Piggin, 2024/03/12
- [PULL 34/38] spapr: nested: Initialize the GSB elements lookup table., Nicholas Piggin, 2024/03/12
- [PULL 27/38] spapr: nested: Introduce SpaprMachineStateNested to store related info., Nicholas Piggin, 2024/03/12
- [PULL 31/38] spapr: nested: Introduce H_GUEST_[CREATE|DELETE] hcalls., Nicholas Piggin, 2024/03/12