Skip to content

Commit

Permalink
spapr: nested: register nested-hv api hcalls only for cap-nested-hv
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
  • Loading branch information
Harsh Prateek Bora authored and npiggin committed Mar 12, 2024
1 parent 868cb6b commit 6026fdb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions hw/ppc/spapr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,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() &&
Expand Down
24 changes: 22 additions & 2 deletions hw/ppc/spapr_hcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
25 changes: 23 additions & 2 deletions hw/ppc/spapr_nested.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 */
}
Expand Down
4 changes: 4 additions & 0 deletions include/hw/ppc/spapr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 */
1 change: 0 additions & 1 deletion include/hw/ppc/spapr_nested.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 6026fdb

Please sign in to comment.