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 01/14] spapr: nested: register nested-hv api hcalls only for cap-nested-hv
Date: Fri, 8 Mar 2024 16:49:27 +0530 [thread overview]
Message-ID: <20240308111940.1617660-2-harshpb@linux.ibm.com> (raw)
In-Reply-To: <20240308111940.1617660-1-harshpb@linux.ibm.com>
Since cap-nested-hv is an optional capability, it makes sense to register
api specfic hcalls only when respective capability is enabled. This
requires to introduce a new API to unregister hypercalls to maintain
sanity across guest reboot since caps are re-applied across reboots and
re-registeration of hypercalls would hit assert otherwise.
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
include/hw/ppc/spapr.h | 4 ++++
include/hw/ppc/spapr_nested.h | 1 -
hw/ppc/spapr.c | 1 +
hw/ppc/spapr_hcall.c | 24 ++++++++++++++++++++++--
hw/ppc/spapr_nested.c | 25 +++++++++++++++++++++++--
5 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 5b5ba9ef77..78a736297b 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -631,6 +631,7 @@ typedef target_ulong (*spapr_hcall_fn)(PowerPCCPU *cpu, SpaprMachineState *sm,
target_ulong *args);
void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
+void spapr_unregister_hypercall(target_ulong opcode);
target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
target_ulong *args);
@@ -1028,5 +1029,8 @@ void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt);
/* H_WATCHDOG */
void spapr_watchdog_init(SpaprMachineState *spapr);
+void spapr_register_nested_hv(void);
+void spapr_unregister_nested_hv(void);
+void spapr_nested_reset(SpaprMachineState *spapr);
#endif /* HW_SPAPR_H */
diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h
index d312a5d61d..09d95182b2 100644
--- a/include/hw/ppc/spapr_nested.h
+++ b/include/hw/ppc/spapr_nested.h
@@ -95,7 +95,6 @@ struct nested_ppc_state {
int64_t tb_offset;
};
-void spapr_register_nested(void);
void spapr_exit_nested(PowerPCCPU *cpu, int excp);
#endif /* HW_SPAPR_NESTED_H */
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 55263f0815..0d3c740c5b 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1689,6 +1689,7 @@ static void spapr_machine_reset(MachineState *machine, ShutdownCause reason)
pef_kvm_reset(machine->cgs, &error_fatal);
spapr_caps_apply(spapr);
+ spapr_nested_reset(spapr);
first_ppc_cpu = POWERPC_CPU(first_cpu);
if (kvm_enabled() && kvmppc_has_cap_mmu_radix() &&
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 75c2d12978..5e1d020e3d 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -1525,6 +1525,28 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn)
*slot = fn;
}
+void spapr_unregister_hypercall(target_ulong opcode)
+{
+ spapr_hcall_fn *slot;
+
+ if (opcode <= MAX_HCALL_OPCODE) {
+ assert((opcode & 0x3) == 0);
+
+ slot = &papr_hypercall_table[opcode / 4];
+ } else if (opcode >= SVM_HCALL_BASE && opcode <= SVM_HCALL_MAX) {
+ /* we only have SVM-related hcall numbers assigned in multiples of 4 */
+ assert((opcode & 0x3) == 0);
+
+ slot = &svm_hypercall_table[(opcode - SVM_HCALL_BASE) / 4];
+ } else {
+ assert((opcode >= KVMPPC_HCALL_BASE) && (opcode <= KVMPPC_HCALL_MAX));
+
+ slot = &kvmppc_hypercall_table[opcode - KVMPPC_HCALL_BASE];
+ }
+
+ *slot = NULL;
+}
+
target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
target_ulong *args)
{
@@ -1638,8 +1660,6 @@ static void hypercall_register_types(void)
spapr_register_hypercall(KVMPPC_H_CAS, h_client_architecture_support);
spapr_register_hypercall(KVMPPC_H_UPDATE_DT, h_update_dt);
-
- spapr_register_nested();
}
type_init(hypercall_register_types)
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index 121aa96ddc..8e0ee0d22f 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -7,6 +7,14 @@
#include "hw/ppc/spapr_cpu_core.h"
#include "hw/ppc/spapr_nested.h"
+void spapr_nested_reset(SpaprMachineState *spapr)
+{
+ if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV)) {
+ spapr_unregister_nested_hv();
+ spapr_register_nested_hv();
+ }
+}
+
#ifdef CONFIG_TCG
#define PRTS_MASK 0x1f
@@ -375,20 +383,33 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp)
address_space_unmap(CPU(cpu)->as, regs, len, len, true);
}
-void spapr_register_nested(void)
+void spapr_register_nested_hv(void)
{
spapr_register_hypercall(KVMPPC_H_SET_PARTITION_TABLE, h_set_ptbl);
spapr_register_hypercall(KVMPPC_H_ENTER_NESTED, h_enter_nested);
spapr_register_hypercall(KVMPPC_H_TLB_INVALIDATE, h_tlb_invalidate);
spapr_register_hypercall(KVMPPC_H_COPY_TOFROM_GUEST, h_copy_tofrom_guest);
}
+
+void spapr_unregister_nested_hv(void)
+{
+ spapr_unregister_hypercall(KVMPPC_H_SET_PARTITION_TABLE);
+ spapr_unregister_hypercall(KVMPPC_H_ENTER_NESTED);
+ spapr_unregister_hypercall(KVMPPC_H_TLB_INVALIDATE);
+ spapr_unregister_hypercall(KVMPPC_H_COPY_TOFROM_GUEST);
+}
#else
void spapr_exit_nested(PowerPCCPU *cpu, int excp)
{
g_assert_not_reached();
}
-void spapr_register_nested(void)
+void spapr_register_nested_hv(void)
+{
+ /* DO NOTHING */
+}
+
+void spapr_unregister_nested_hv(void)
{
/* DO NOTHING */
}
--
2.39.3
next prev parent reply other threads:[~2024-03-08 11:23 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 ` Harsh Prateek Bora [this message]
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 ` [PATCH v5 08/14] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall Harsh Prateek Bora
2024-03-12 11:30 ` 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-2-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).