HPT resizing for pseries guests (qemu part)
v7 cover HPT resizing for pseries guests (qemu part)
This series implements the host side of the PAPR ACR to allow runtime resizing of the Hashed Page Table (HPT) for pseries guests. Exercising this feature requires a guest OS which is also aware of it. Patches to implement the guest side in Linux are upstream as of v4.11.
Availability of the feature is controlled by a new 'resize-hpt' machine option: it can be set to "disabled", "enabled" or "required". The last means that qemu will refuse to boot a guest which is not aware of the HPT resizing feature (it will instead quit during feature negotiation). This is potentially useful because guests which don't support resizing will need an HPT sized for their maximum possible RAM, which can be very wasteful of host resources.
This implementation will work for both TCG and KVM guests. HV KVM requires support in the host kernel which is also included in v4.11.
Changes since v6:
* Rebase for current tree
* Adjustments to fail gracefully for POWER9 RPT guests
Changes since v5:
* Rebase for qemu-2.10
* Kernel patches now merged
* Removed an unnecessary and possibly dangerous assert()
Changes since v4 (misposted as v3):
* More minor revisions based on review comments
* Altered to use new simpler encoding of kernel capability
Changes since v3:
* Assorted minor revisions based on review
* Added KVM support (PR and HV)
Changes since v2:
* Some clearer comments based on review
* Some minor cleanups based on review
David Gibson (5):
pseries: Stubs for HPT resizing
pseries: Implement HPT resizing
pseries: Enable HPT resizing for 2.10
pseries: Use smaller default hash page tables when guest can resize
pseries: Allow HPT resizing with KVM
hw/ppc/spapr.c | 103 ++++++++++- hw/ppc/spapr_hcall.c | 439 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/trace-events | 2 + include/hw/ppc/spapr.h | 19 ++ include/hw/ppc/spapr_ovec.h | 1 + target/ppc/kvm.c | 76 ++++++++ target/ppc/kvm_ppc.h | 26 +++ target/ppc/mmu-hash64.h | 4 + 8 files changed, 662 insertions(+), 8 deletions(-)
Signature · 1 line
2.9.4
PATCH v7 1/5 pseries: Stubs for HPT resizing
This introduces stub implementations of the H_RESIZE_HPT_PREPARE and H_RESIZE_HPT_COMMIT hypercalls which we hope to add in a PAPR extension to allow run time resizing of a guest's hash page table. It also adds a new machine property for controlling whether this new facility is available.
For now we only allow resizing with TCG, allowing it with KVM will require kernel changes as well.
Finally, it adds a new string to the hypertas property in the device tree, advertising to the guest the availability of the HPT resizing hypercalls. This is a tentative suggested value, and would need to be standardized by PAPR before being merged.
--- hw/ppc/spapr.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_hcall.c | 36 ++++++++++++++++++++++++ hw/ppc/trace-events | 2 ++ include/hw/ppc/spapr.h | 11 ++++++++ target/ppc/kvm.c | 13 +++++++++ target/ppc/kvm_ppc.h | 5 ++++ 6 files changed, 142 insertions(+)
hw/ppc/spapr.c +75 -0
@@ -874,6 +874,11 @@ static void spapr_dt_rtas(sPAPRMachineState *spapr, void *fdt)if (!kvm_enabled () ||kvmppc_spapr_use_multitce ()) {add_str (hypertas,"hcall-multi-tce" ); } + +if (spapr->resize_hpt !=SPAPR_RESIZE_HPT_DISABLED ) { +add_str (hypertas,"hcall-hpt-resize" ); + } +_FDT (fdt_setprop (fdt, rtas,"ibm,hypertas-functions" , hypertas->str, hypertas->len));g_string_free (hypertas, TRUE);
@@ -2148,12 +2153,41 @@ static void ppc_spapr_init(MachineState *machine)hwaddr node0_size =spapr_node0_size ();long load_limit, fw_size;char *filename; +Error *resize_hpt_err =NULL ; msi_nonbroken = true;QLIST_INIT (&spapr->phbs);QTAILQ_INIT (&spapr->pending_dimm_unplugs); +/* Check HPT resizing availability */ +kvmppc_check_papr_resize_hpt (&resize_hpt_err); +if (spapr->resize_hpt ==SPAPR_RESIZE_HPT_DEFAULT ) { +/* +* If the user explicitly requested a mode we should either +* supply it, or fail completely (which we do below). But if +* it's not set explicitly, we reset our mode to something +* that works +*/ +if (resize_hpt_err) { + spapr->resize_hpt =SPAPR_RESIZE_HPT_DISABLED ; +error_free (resize_hpt_err); + resize_hpt_err =NULL ; + }else { + spapr->resize_hpt = smc->resize_hpt_default; + } + } + +assert (spapr->resize_hpt !=SPAPR_RESIZE_HPT_DEFAULT ); + +if ((spapr->resize_hpt !=SPAPR_RESIZE_HPT_DISABLED ) && resize_hpt_err) { +/* +* User requested HPT resize, but this host can't supply it. Bail out +*/ +error_report_err (resize_hpt_err); +exit (1 ); + } +/* Allocate RMA if necessary */ rma_alloc_size =kvmppc_alloc_rma (&rma);
@@ -2579,6 +2613,40 @@ static void spapr_set_modern_hotplug_events(Object *obj, bool value, spapr->use_hotplug_event_source = value; } +static char *spapr_get_resize_hpt (Object *obj,Error **errp) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (obj); + +switch (spapr->resize_hpt) { +case SPAPR_RESIZE_HPT_DEFAULT : +return g_strdup ("default" ); +case SPAPR_RESIZE_HPT_DISABLED : +return g_strdup ("disabled" ); +case SPAPR_RESIZE_HPT_ENABLED : +return g_strdup ("enabled" ); +case SPAPR_RESIZE_HPT_REQUIRED : +return g_strdup ("required" ); + } +assert (0 ); +} + +static void spapr_set_resize_hpt (Object *obj,const char *value,Error **errp) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (obj); + +if (strcmp (value,"default" ) ==0 ) { + spapr->resize_hpt =SPAPR_RESIZE_HPT_DEFAULT ; + }else if (strcmp (value,"disabled" ) ==0 ) { + spapr->resize_hpt =SPAPR_RESIZE_HPT_DISABLED ; + }else if (strcmp (value,"enabled" ) ==0 ) { + spapr->resize_hpt =SPAPR_RESIZE_HPT_ENABLED ; + }else if (strcmp (value,"required" ) ==0 ) { + spapr->resize_hpt =SPAPR_RESIZE_HPT_REQUIRED ; + }else { +error_setg (errp,"Bad value for \"resize-hpt\" property" ); + } +} +static void spapr_machine_initfn (Object *obj) {sPAPRMachineState *spapr =SPAPR_MACHINE (obj);
@@ -2603,6 +2671,12 @@ static void spapr_machine_initfn(Object *obj)ppc_compat_add_property (obj,"max-cpu-compat" , &spapr->max_compat_pvr,"Maximum permitted CPU compatibility mode" , &error_fatal); + +object_property_add_str (obj,"resize-hpt" , + spapr_get_resize_hpt, spapr_set_resize_hpt,NULL ); +object_property_set_description (obj,"resize-hpt" , +"Resizing of the Hash Page Table (enabled, disabled, required)" , +NULL ); }static void spapr_machine_finalizefn (Object *obj)
@@ -3397,6 +3471,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->dr_lmb_enabled = true; smc->tcg_default_cpu ="POWER8" ; mc->has_hotpluggable_cpus = true; + smc->resize_hpt_default =SPAPR_RESIZE_HPT_DISABLED ; fwc->get_dev_path = spapr_get_fw_dev_path; nc->nmi_monitor_handler = spapr_nmi; smc->phb_placement = spapr_phb_placement;
hw/ppc/spapr_hcall.c +36 -0
@@ -354,6 +354,38 @@ static target_ulong h_read(PowerPCCPU *cpu, sPAPRMachineState *spapr,return H_SUCCESS ; } +static target_ulong h_resize_hpt_prepare (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong flags = args[0 ]; +target_ulong shift = args[1 ]; + +if (spapr->resize_hpt ==SPAPR_RESIZE_HPT_DISABLED ) { +return H_AUTHORITY ; + } + +trace_spapr_h_resize_hpt_prepare (flags, shift); +return H_HARDWARE ; +} + +static target_ulong h_resize_hpt_commit (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong flags = args[0 ]; +target_ulong shift = args[1 ]; + +if (spapr->resize_hpt ==SPAPR_RESIZE_HPT_DISABLED ) { +return H_AUTHORITY ; + } + +trace_spapr_h_resize_hpt_commit (flags, shift); +return H_HARDWARE ; +} +static target_ulong h_set_sprg0 (PowerPCCPU *cpu,sPAPRMachineState *spapr,target_ulong opcode,target_ulong *args) {
@@ -1246,6 +1278,10 @@ static void hypercall_register_types(void)/* hcall-bulk */ spapr_register_hypercall (H_BULK_REMOVE , h_bulk_remove); +/* hcall-hpt-resize */ +spapr_register_hypercall (H_RESIZE_HPT_PREPARE , h_resize_hpt_prepare); +spapr_register_hypercall (H_RESIZE_HPT_COMMIT , h_resize_hpt_commit); +/* hcall-splpar */ spapr_register_hypercall (H_REGISTER_VPA , h_register_vpa);spapr_register_hypercall (H_CEDE , h_cede);
hw/ppc/trace-events +2 -0
@@ -16,6 +16,8 @@ spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes" # hw/ppc/spapr_hcall.c spapr_cas_pvr_try(uint32_t pvr) "%x" spapr_cas_pvr(uint32_t cur_pvr, bool explicit_match, uint32_t new_pvr) "current=%x, explicit_match=%u, new=%x" +spapr_h_resize_hpt_prepare(uint64_t flags, uint64_t shift) "flags=0x%"PRIx64", shift=%"PRIu64 +spapr_h_resize_hpt_commit(uint64_t flags, uint64_t shift) "flags=0x%"PRIx64", shift=%"PRIu64 # hw/ppc/spapr_iommu.c spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64
include/hw/ppc/spapr.h +11 -0
@@ -42,6 +42,13 @@ typedef struct sPAPRMachineClass sPAPRMachineClass;#define SPAPR_MACHINE_CLASS (klass) \ OBJECT_CLASS_CHECK(sPAPRMachineClass, klass, TYPE_SPAPR_MACHINE) +typedef enum { +SPAPR_RESIZE_HPT_DEFAULT =0 , +SPAPR_RESIZE_HPT_DISABLED , +SPAPR_RESIZE_HPT_ENABLED , +SPAPR_RESIZE_HPT_REQUIRED , +}sPAPRResizeHPT ; +/** * sPAPRMachineClass: */
@@ -58,6 +65,7 @@ struct sPAPRMachineClass { uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64, unsigned n_dma, uint32_t *liobns, Error **errp); +sPAPRResizeHPT resize_hpt_default; };/**
@@ -73,6 +81,7 @@ struct sPAPRMachineState {ICSState *ics;sPAPRRTCState rtc; +sPAPRResizeHPT resize_hpt;void *htab;uint32_t htab_shift;uint64_t patb_entry;/* Process tbl registed in H_REGISTER_PROCESS_TABLE */
@@ -367,6 +376,8 @@ struct sPAPRMachineState {#define H_XIRR_X 0x2FC#define H_RANDOM 0x300#define H_SET_MODE 0x31C +#define H_RESIZE_HPT_PREPARE 0x36C +#define H_RESIZE_HPT_COMMIT 0x370#define H_CLEAN_SLB 0x374#define H_INVALIDATE_PID 0x378#define H_REGISTER_PROC_TBL 0x37C
target/ppc/kvm.c +13 -0
@@ -22,6 +22,7 @@#include <linux/kvm.h> #include "qemu-common.h" +#include "qapi/error.h" #include "qemu/error-report.h" #include "cpu.h" #include "cpu-models.h"
@@ -2709,3 +2710,15 @@ int kvmppc_enable_hwrng(void)return kvmppc_enable_hcall (kvm_state,H_RANDOM ); } + +void kvmppc_check_papr_resize_hpt (Error **errp) +{ +if (!kvm_enabled ()) { +return ; + } + +/* TODO: Check for resize-capable KVM implementations */ + +error_setg (errp, +"Hash page table resizing not available with this KVM version" ); +}
target/ppc/kvm_ppc.h +5 -0
@@ -63,6 +63,7 @@ bool kvmppc_has_cap_mmu_hash_v3(void);int kvmppc_enable_hwrng (void );int kvmppc_put_books_sregs (PowerPCCPU *cpu);PowerPCCPUClass *kvm_ppc_get_host_cpu_class (void ); +void kvmppc_check_papr_resize_hpt (Error **errp);bool kvmppc_is_mem_backend_page_size_ok (const char *obj_path);
@@ -297,6 +298,10 @@ static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) return NULL; } +static inline void kvmppc_check_papr_resize_hpt (Error **errp) +{ +return ; +}#endif #ifndef CONFIG_KVM
Signature · 1 line
2.9.4
PATCH v7 2/5 pseries: Implement HPT resizing
In reply to David GibsonThis patch implements hypercalls allowing a PAPR guest to resize its own hash page table. This will eventually allow for more flexible memory hotplug.
The implementation is partially asynchronous, handled in a special thread running the hpt_prepare_thread() function. The state of a pending resize is stored in SPAPR_MACHINE->pending_hpt.
The H_RESIZE_HPT_PREPARE hypercall will kick off creation of a new HPT, or, if one is already in progress, monitor it for completion. If there is an existing HPT resize in progress that doesn't match the size specified in the call, it will cancel it, replacing it with a new one matching the given size.
The H_RESIZE_HPT_COMMIT completes transition to a resized HPT, and can only be called successfully once H_RESIZE_HPT_PREPARE has successfully completed initialization of a new HPT. The guest must ensure that there are no concurrent accesses to the existing HPT while this is called (this effectively means stop_machine() for Linux guests).
For now H_RESIZE_HPT_COMMIT goes through the whole old HPT, rehashing each HPTE into the new HPT. This can have quite high latency, but it seems to be of the order of typical migration downtime latencies for HPTs of size up to ~2GiB (which would be used in a 256GiB guest).
In future we probably want to move more of the rehashing to the "prepare" phase, by having H_ENTER and other hcalls update both current and pending HPTs. That's a project for another day, but should be possible without any changes to the guest interface.
--- hw/ppc/spapr.c | 4 +- hw/ppc/spapr_hcall.c | 314 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 6 + target/ppc/mmu-hash64.h | 4 + 4 files changed, 322 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +1 -3
@@ -98,8 +98,6 @@#define PHANDLE_XICP 0x00001111 -#define HTAB_SIZE (spapr) (1ULL << ((spapr)->htab_shift)) -static ICSState *spapr_ics_create (sPAPRMachineState *spapr,const char *type_ics,int nr_irqs,Error **errp)
@@ -1269,7 +1267,7 @@ static void spapr_store_hpte(PPCVirtualHypervisor *vhyp, hwaddr ptex, } } -static int spapr_hpt_shift_for_ramsize (uint64_t ramsize) +int spapr_hpt_shift_for_ramsize (uint64_t ramsize) {int shift;
hw/ppc/spapr_hcall.c +311 -3
350 lines not on this page · raw message
include/hw/ppc/spapr.h +6 -0
@@ -13,6 +13,7 @@ struct sPAPRPHBState;struct sPAPRNVRAM ;typedef struct sPAPREventLogEntry sPAPREventLogEntry ;typedef struct sPAPREventSource sPAPREventSource ; +typedef struct sPAPRPendingHPT sPAPRPendingHPT ;#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL#define SPAPR_ENTRY_POINT 0x100
@@ -85,6 +86,8 @@ struct sPAPRMachineState {void *htab;uint32_t htab_shift;uint64_t patb_entry;/* Process tbl registed in H_REGISTER_PROCESS_TABLE */ +sPAPRPendingHPT *pending_hpt;/* in-progress resize */ +hwaddr rma_size;int vrma_adjust;ssize_t rtas_size;
@@ -651,6 +654,7 @@ void spapr_hotplug_req_add_by_count_indexed(sPAPRDRConnectorType drc_type,void spapr_hotplug_req_remove_by_count_indexed (sPAPRDRConnectorType drc_type,uint32_t count,uint32_t index);void spapr_cpu_parse_features (sPAPRMachineState *spapr); +int spapr_hpt_shift_for_ramsize (uint64_t ramsize);/* CPU and LMB DRC release callbacks. */ void spapr_core_release (DeviceState *dev);
@@ -691,4 +695,6 @@ int spapr_rng_populate_dt(void *fdt);void spapr_do_system_reset_on_cpu (CPUState *cs,run_on_cpu_data arg); +#define HTAB_SIZE (spapr) (1ULL << ((spapr)->htab_shift)) +#endif /* HW_SPAPR_H */
target/ppc/mmu-hash64.h +4 -0
@@ -63,11 +63,15 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define HASH_PTE_SIZE_64 16#define HASH_PTEG_SIZE_64 (HASH_PTE_SIZE_64 * HPTES_PER_GROUP) +#define HPTE64_V_SSIZE SLB_VSID_B +#define HPTE64_V_SSIZE_256M SLB_VSID_B_256M +#define HPTE64_V_SSIZE_1T SLB_VSID_B_1T#define HPTE64_V_SSIZE_SHIFT 62#define HPTE64_V_AVPN_SHIFT 7#define HPTE64_V_AVPN 0x3fffffffffffff80ULL#define HPTE64_V_AVPN_VAL (x) (((x) & HPTE64_V_AVPN) >> HPTE64_V_AVPN_SHIFT)#define HPTE64_V_COMPARE (x, y) (!(((x) ^ (y)) & 0xffffffffffffff83ULL)) +#define HPTE64_V_BOLTED 0x0000000000000010ULL#define HPTE64_V_LARGE 0x0000000000000004ULL#define HPTE64_V_SECONDARY 0x0000000000000002ULL#define HPTE64_V_VALID 0x0000000000000001ULL
Signature · 1 line
2.9.4
PATCH v7 3/5 pseries: Enable HPT resizing for 2.10
In reply to David GibsonWe've now implemented a PAPR extensions which allows PAPR guests (i.e. "pseries" machine type) to resize their hash page table during runtime.
However, that extension is only enabled if explicitly chosen on the command line. This patch enables it by default for spapr-2.10, but leaves it disabled (by default) for older machine types.
--- hw/ppc/spapr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +2 -1
@@ -3469,7 +3469,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->dr_lmb_enabled = true; smc->tcg_default_cpu ="POWER8" ; mc->has_hotpluggable_cpus = true; - smc->resize_hpt_default =SPAPR_RESIZE_HPT_DISABLED ; + smc->resize_hpt_default =SPAPR_RESIZE_HPT_ENABLED ; fwc->get_dev_path = spapr_get_fw_dev_path; nc->nmi_monitor_handler = spapr_nmi; smc->phb_placement = spapr_phb_placement;
@@ -3576,6 +3576,7 @@ static void spapr_machine_2_9_class_options(MachineClass *mc)SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_9 ); mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram; smc->pre_2_10_has_unused_icps = true; + smc->resize_hpt_default =SPAPR_RESIZE_HPT_DISABLED ; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);
Signature · 1 line
2.9.4
PATCH v7 4/5 pseries: Use smaller default hash page tables when guest can resize
In reply to David GibsonWe've now implemented a PAPR extension allowing PAPR guest to resize their hash page table (HPT) during runtime.
This patch makes use of that facility to allocate smaller HPTs by default. Specifically when a guest is aware of the HPT resize facility, qemu sizes the HPT to the initial memory size, rather than the maximum memory size on the assumption that the guest will resize its HPT if necessary for hot plugged memory.
When the initial memory size is much smaller than the maximum memory size (a common configuration with e.g. oVirt / RHEV) then this can save significant memory on the HPT.
If the guest does *not* advertise HPT resize awareness when it makes the ibm,client-architecture-support call, qemu resizes the HPT for maxmimum memory size (unless it's been configured not to allow such guests at all).
For now we make that reallocation assuming the guest has not yet used the HPT at all. That's true in practice, but not, strictly, an architectural or PAPR requirement. If we need to in future we can fix this by having the client-architecture-support call reboot the guest with the revised HPT size (the client-architecture-support call is explicitly permitted to trigger a reboot in this way).
--- hw/ppc/spapr.c | 23 ++++++++++++++++++----- hw/ppc/spapr_hcall.c | 29 +++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_ovec.h | 1 + 4 files changed, 50 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +18 -5
@@ -1288,8 +1288,8 @@ void spapr_free_hpt(sPAPRMachineState *spapr)close_htab_fd (spapr); } -static void spapr_reallocate_hpt (sPAPRMachineState *spapr,int shift, -Error **errp) +void spapr_reallocate_hpt (sPAPRMachineState *spapr,int shift, +Error **errp) {long rc;
@@ -1337,9 +1337,17 @@ static void spapr_reallocate_hpt(sPAPRMachineState *spapr, int shift,void spapr_setup_hpt_and_vrma (sPAPRMachineState *spapr) { -spapr_reallocate_hpt (spapr, -spapr_hpt_shift_for_ramsize (MACHINE (spapr)->maxram_size), - &error_fatal); +int hpt_shift; + +if ((spapr->resize_hpt ==SPAPR_RESIZE_HPT_DISABLED ) + || (spapr->cas_reboot + && !spapr_ovec_test (spapr->ov5_cas,OV5_HPT_RESIZE ))) { + hpt_shift =spapr_hpt_shift_for_ramsize (MACHINE (spapr)->maxram_size); + }else { + hpt_shift =spapr_hpt_shift_for_ramsize (MACHINE (spapr)->ram_size); + } +spapr_reallocate_hpt (spapr, hpt_shift, &error_fatal); +if (spapr->vrma_adjust) { spapr->rma_size =kvmppc_rma_size (spapr_node0_size (), spapr->htab_shift);
@@ -2254,6 +2262,11 @@ static void ppc_spapr_init(MachineState *machine)spapr_ovec_set (spapr->ov5,OV5_HP_EVT ); } +/* advertise support for HPT resizing */ +if (spapr->resize_hpt !=SPAPR_RESIZE_HPT_DISABLED ) { +spapr_ovec_set (spapr->ov5,OV5_HPT_RESIZE ); + } +/* init CPUs */ if (machine->cpu_model ==NULL ) { machine->cpu_model =kvm_enabled () ?"host" : smc->tcg_default_cpu;
hw/ppc/spapr_hcall.c +29 -0
@@ -1473,6 +1473,35 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, guest_radix =spapr_ovec_test (ov5_guest,OV5_MMU_RADIX_300 );spapr_ovec_clear (ov5_guest,OV5_MMU_RADIX_300 ); +/* +* HPT resizing is a bit of a special case, because when enabled +* we assume an HPT guest will support it until it says it +* doesn't, instead of assuming it won't support it until it says +* it does. Strictly speaking that approach could break for +* guests which don't make a CAS call, but those are so old we +* don't care about them. Without that assumption we'd have to +* make at least a temporary allocation of an HPT sized for max +* memory, which could be impossibly difficult under KVM HV if +* maxram is large. +*/ +if (!guest_radix && !spapr_ovec_test (ov5_guest,OV5_HPT_RESIZE )) { +int maxshift =spapr_hpt_shift_for_ramsize (MACHINE (spapr)->maxram_size); + +if (spapr->resize_hpt ==SPAPR_RESIZE_HPT_REQUIRED ) { +error_report ( +"h_client_architecture_support: Guest doesn't support HPT resizing, but resize-hpt=required" ); +exit (1 ); + } + +if (spapr->htab_shift < maxshift) { +/* Guest doesn't know about HPT resizing, so we +* pre-emptively resize for the maximum permitted RAM. At +* the point this is called, nothing should have been +* entered into the existing HPT */ +spapr_reallocate_hpt (spapr, maxshift, &error_fatal); + } + } +/* NOTE: there are actually a number of ov5 bits where input from the * guest is always zero, and the platform/QEMU enables them independently * of guest input. To model these properly we'd want some sort of mask,
include/hw/ppc/spapr.h +2 -0
@@ -655,6 +655,8 @@ void spapr_hotplug_req_remove_by_count_indexed(sPAPRDRConnectorType drc_type, uint32_t count, uint32_t index);void spapr_cpu_parse_features (sPAPRMachineState *spapr);int spapr_hpt_shift_for_ramsize (uint64_t ramsize); +void spapr_reallocate_hpt (sPAPRMachineState *spapr,int shift, +Error **errp);/* CPU and LMB DRC release callbacks. */ void spapr_core_release (DeviceState *dev);
include/hw/ppc/spapr_ovec.h +1 -0
@@ -50,6 +50,7 @@ typedef struct sPAPROptionVector sPAPROptionVector;#define OV5_DRCONF_MEMORY OV_BIT(2, 2)#define OV5_FORM1_AFFINITY OV_BIT(5, 0)#define OV5_HP_EVT OV_BIT(6, 5) +#define OV5_HPT_RESIZE OV_BIT(6, 7)#define OV5_XIVE_EXPLOIT OV_BIT(23, 7)/* ISA 3.00 MMU features: */
Signature · 1 line
2.9.4
PATCH v7 5/5 pseries: Allow HPT resizing with KVM
In reply to David GibsonSo far, qemu implements the PAPR Hash Page Table (HPT) resizing extension with TCG. The same implementation will work with KVM PR, but we don't currently allow that. For KVM HV we can only implement resizing with the assistance of the host kernel, which needs a new capability and ioctl()s.
This patch adds support for testing the new KVM capability and implementing the resize in terms of KVM facilities when necessary. If we're running on a kernel which doesn't have the new capability flag at all, we fall back to testing for PR vs. HV KVM using the same hack that we already use in a number of places for older kernels.
--- hw/ppc/spapr_hcall.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ target/ppc/kvm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++-- target/ppc/kvm_ppc.h | 21 ++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-)
hw/ppc/spapr_hcall.c +66 -0
@@ -426,6 +426,44 @@ static void cancel_hpt_prepare(sPAPRMachineState *spapr)free_pending_hpt (pending); } +/* Convert a return code from the KVM ioctl()s implementing resize HPT +* into a PAPR hypercall return code */ +static target_ulong resize_hpt_convert_rc (int ret) +{ +if (ret >=100000 ) { +return H_LONG_BUSY_ORDER_100_SEC ; + }else if (ret >=10000 ) { +return H_LONG_BUSY_ORDER_10_SEC ; + }else if (ret >=1000 ) { +return H_LONG_BUSY_ORDER_1_SEC ; + }else if (ret >=100 ) { +return H_LONG_BUSY_ORDER_100_MSEC ; + }else if (ret >=10 ) { +return H_LONG_BUSY_ORDER_10_MSEC ; + }else if (ret >0 ) { +return H_LONG_BUSY_ORDER_1_MSEC ; + } + +switch (ret) { +case 0 : +return H_SUCCESS ; +case -EPERM : +return H_AUTHORITY ; +case -EINVAL : +return H_PARAMETER ; +case -ENXIO : +return H_CLOSED ; +case -ENOSPC : +return H_PTEG_FULL ; +case -EBUSY : +return H_BUSY ; +case -ENOMEM : +return H_NO_MEM ; +default : +return H_HARDWARE ; + } +} + static target_ulong h_resize_hpt_prepare(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode,
@@ -435,6 +473,7 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *cpu,int shift = args[1 ];sPAPRPendingHPT *pending = spapr->pending_hpt;uint64_t current_ram_size =MACHINE (spapr)->ram_size; +int rc;if (spapr->resize_hpt ==SPAPR_RESIZE_HPT_DISABLED ) {return H_AUTHORITY ;
@@ -464,6 +503,11 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *cpu,return H_RESOURCE ; } + rc =kvmppc_resize_hpt_prepare (cpu, flags, shift); +if (rc != -ENOSYS ) { +return resize_hpt_convert_rc (rc); + } +if (pending) {/* something already in progress */ if (pending->shift == shift) {
@@ -659,6 +703,11 @@ static target_ulong h_resize_hpt_commit(PowerPCCPU *cpu,trace_spapr_h_resize_hpt_commit (flags, shift); + rc =kvmppc_resize_hpt_commit (cpu, flags, shift); +if (rc != -ENOSYS ) { +return resize_hpt_convert_rc (rc); + } +if (flags !=0 ) {return H_PARAMETER ; }
@@ -684,6 +733,13 @@ static target_ulong h_resize_hpt_commit(PowerPCCPU *cpu, spapr->htab = pending->hpt; spapr->htab_shift = pending->shift; +if (kvm_enabled ()) { +/* For KVM PR, update the HPT pointer */ +target_ulong sdr1 = (target_ulong )(uintptr_t )spapr->htab + | (spapr->htab_shift -18 ); +kvmppc_update_sdr1 (sdr1); + } + pending->hpt =NULL ;/* so it's not free()d */ }
@@ -1494,11 +1550,21 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, }if (spapr->htab_shift < maxshift) { +CPUState *cs; +/* Guest doesn't know about HPT resizing, so we * pre-emptively resize for the maximum permitted RAM. At * the point this is called, nothing should have been * entered into the existing HPT */ spapr_reallocate_hpt (spapr, maxshift, &error_fatal); +CPU_FOREACH (cs) { +if (kvm_enabled ()) { +/* For KVM PR, update the HPT pointer */ +target_ulong sdr1 = (target_ulong )(uintptr_t )spapr->htab + | (spapr->htab_shift -18 ); +kvmppc_update_sdr1 (sdr1); + } + } } }
target/ppc/kvm.c +65 -2
88 lines not on this page · raw message
target/ppc/kvm_ppc.h +21 -0
@@ -64,6 +64,9 @@ int kvmppc_enable_hwrng(void);int kvmppc_put_books_sregs (PowerPCCPU *cpu);PowerPCCPUClass *kvm_ppc_get_host_cpu_class (void );void kvmppc_check_papr_resize_hpt (Error **errp); +int kvmppc_resize_hpt_prepare (PowerPCCPU *cpu,target_ulong flags,int shift); +int kvmppc_resize_hpt_commit (PowerPCCPU *cpu,target_ulong flags,int shift); +void kvmppc_update_sdr1 (target_ulong sdr1);bool kvmppc_is_mem_backend_page_size_ok (const char *obj_path);
@@ -302,6 +305,24 @@ static inline void kvmppc_check_papr_resize_hpt(Error **errp) {return ; } + +static inline int kvmppc_resize_hpt_prepare (PowerPCCPU *cpu, +target_ulong flags,int shift) +{ +return -ENOSYS ; +} + +static inline int kvmppc_resize_hpt_commit (PowerPCCPU *cpu, +target_ulong flags,int shift) +{ +return -ENOSYS ; +} + +static inline void kvmppc_update_sdr1 (target_ulong sdr1) +{ +abort (); +} +#endif #ifndef CONFIG_KVM
Signature · 1 line
2.9.4