PAPR hash page table resizing
v2 cover PAPR hash page table resizing
This series implements the host / qemu side to allow hash page table (HPT) resizing for PAPR (pseries machine type) guests. This is a proposed extension to the PAPR spec. It also requires awareness on the guest side, which I've posted a series for today.
This applies on top of my ppc-for-2.6 branch.
Changes from RFCv1:
* Limit the guest's HPT to one order larger than we'd usually give them
* Size initial HPT for initial rather than maximum memory for guests that are HPT resize aware
David Gibson (6):
pseries: Simplify handling of the hash page table fd
pseries: Move hash page table allocation to reset time
pseries: Stubs for HPT resizing
pseries: Implement HPT resizing
pseries: Enable HPT resizing for 2.6
pseries: Use smaller default hash page tables when guest can resize
hw/ppc/spapr.c | 278 +++++++++++++++++++---------------- hw/ppc/spapr_hcall.c | 375 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 20 ++- target-ppc/mmu-hash64.h | 4 + trace-events | 2 + 5 files changed, 553 insertions(+), 126 deletions(-)
Signature · 1 line
2.5.0
RFC v2 1/6 pseries: Simplify handling of the hash page table fd
When migrating the 'pseries' machine type with KVM, we use a special fd to access the hash page table stored within KVM. Usually, this fd is opened at the beginning of migration, and kept open until the migration is complete.
However, if there is a guest reset during the migration, the fd can become stale and we need to re-open it. At the moment we use an 'htab_fd_stale' flag in sPAPRMachineState to signal this, which is checked in the migration iterators.
But that's rather ugly. It's simpler to just close and invalidate the fd on reset, and lazily re-open it in migration if necessary. This patch implements that change.
This requires a small addition to the machine state's instance_init, so that htab_fd is initialized to -1 (telling the migration code it needs to open it) instead of 0, which could be a valid fd.
--- hw/ppc/spapr.c | 86 ++++++++++++++++++++++++-------------------------- include/hw/ppc/spapr.h | 1 - 2 files changed, 41 insertions(+), 46 deletions(-)
hw/ppc/spapr.c +41 -45
@@ -1023,6 +1023,32 @@ static void emulate_spapr_hypercall(PowerPCCPU *cpu)#define CLEAN_HPTE (_hpte) ((*(uint64_t *)(_hpte)) &= tswap64(~HPTE64_V_HPTE_DIRTY))#define DIRTY_HPTE (_hpte) ((*(uint64_t *)(_hpte)) |= tswap64(HPTE64_V_HPTE_DIRTY)) +/* +* Get the fd to access the kernel htab, re-opening it if necessary +*/ +static int get_htab_fd (sPAPRMachineState *spapr) +{ +if (spapr->htab_fd >=0 ) { +return spapr->htab_fd; + } + + spapr->htab_fd =kvmppc_get_htab_fd (false); +if (spapr->htab_fd <0 ) { +error_report ("Unable to open fd for reading hash table from KVM: %s" , +strerror (errno)); + } + +return spapr->htab_fd; +} + +static void close_htab_fd (sPAPRMachineState *spapr) +{ +if (spapr->htab_fd >=0 ) { +close (spapr->htab_fd); + } + spapr->htab_fd =-1 ; +} +static void spapr_alloc_htab (sPAPRMachineState *spapr) {long shift;
@@ -1084,10 +1110,7 @@ static void spapr_reset_htab(sPAPRMachineState *spapr)error_setg (&error_abort,"Requested HTAB allocation failed during reset" ); } -/* Tell readers to update their file descriptor */ -if (spapr->htab_fd >=0 ) { - spapr->htab_fd_stale = true; - } +close_htab_fd (spapr); }else {memset (spapr->htab,0 ,HTAB_SIZE (spapr));
@@ -1120,28 +1143,6 @@ static int find_unknown_sysbus_device(SysBusDevice *sbdev, void *opaque)return 0 ; } -/* -* A guest reset will cause spapr->htab_fd to become stale if being used. -* Reopen the file descriptor to make sure the whole HTAB is properly read. -*/ -static int spapr_check_htab_fd (sPAPRMachineState *spapr) -{ -int rc =0 ; - -if (spapr->htab_fd_stale) { -close (spapr->htab_fd); - spapr->htab_fd =kvmppc_get_htab_fd (false); -if (spapr->htab_fd <0 ) { -error_report ("Unable to open fd for reading hash table from KVM: " -"%s" ,strerror (errno)); - rc =-1 ; - } - spapr->htab_fd_stale = false; - } - -return rc; -} -static void ppc_spapr_reset (void ) {sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());
@@ -1312,14 +1313,6 @@ static int htab_save_setup(QEMUFile *f, void *opaque) spapr->htab_first_pass = true; }else {assert (kvm_enabled ()); - - spapr->htab_fd =kvmppc_get_htab_fd (false); - spapr->htab_fd_stale = false; -if (spapr->htab_fd <0 ) { -fprintf (stderr,"Unable to open fd for reading hash table from KVM: %s\n" , -strerror (errno)); -return -1 ; - } }
@@ -1459,6 +1452,7 @@ static int htab_save_later_pass(QEMUFile *f, sPAPRMachineState *spapr,static int htab_save_iterate (QEMUFile *f,void *opaque) {sPAPRMachineState *spapr = opaque; +int fd;int rc =0 ;/* Iteration header */
@@ -1467,13 +1461,12 @@ static int htab_save_iterate(QEMUFile *f, void *opaque)if (!spapr->htab) {assert (kvm_enabled ()); - rc =spapr_check_htab_fd (spapr); -if (rc <0 ) { -return rc; + fd =get_htab_fd (spapr); +if (fd <0 ) { +return fd; } - rc =kvmppc_save_htab (f, spapr->htab_fd, -MAX_KVM_BUF_SIZE ,MAX_ITERATION_NS ); + rc =kvmppc_save_htab (f, fd,MAX_KVM_BUF_SIZE ,MAX_ITERATION_NS );if (rc <0 ) {return rc; }
@@ -1494,6 +1487,7 @@ static int htab_save_iterate(QEMUFile *f, void *opaque)static int htab_save_complete (QEMUFile *f,void *opaque) {sPAPRMachineState *spapr = opaque; +int fd;/* Iteration header */ qemu_put_be32 (f,0 );
@@ -1503,17 +1497,16 @@ static int htab_save_complete(QEMUFile *f, void *opaque)assert (kvm_enabled ()); - rc =spapr_check_htab_fd (spapr); -if (rc <0 ) { -return rc; + fd =get_htab_fd (spapr); +if (fd <0 ) { +return fd; } - rc =kvmppc_save_htab (f, spapr->htab_fd,MAX_KVM_BUF_SIZE ,-1 ); + rc =kvmppc_save_htab (f, fd,MAX_KVM_BUF_SIZE ,-1 );if (rc <0 ) {return rc; } -close (spapr->htab_fd); - spapr->htab_fd =-1 ; +close_htab_fd (spapr); }else {htab_save_later_pass (f, spapr,-1 ); }
@@ -2124,6 +2117,9 @@ static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp)static void spapr_machine_initfn (Object *obj) { +sPAPRMachineState *spapr =SPAPR_MACHINE (obj); + + spapr->htab_fd =-1 ;object_property_add_str (obj,"kvm-type" , spapr_get_kvm_type, spapr_set_kvm_type,NULL ); object_property_set_description(obj, "kvm-type",
include/hw/ppc/spapr.h +0 -1
@@ -72,7 +72,6 @@ struct sPAPRMachineState {int htab_save_index;bool htab_first_pass;int htab_fd; -bool htab_fd_stale;/* RTAS state */ QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list;
Signature · 1 line
2.5.0
RFC v2 2/6 pseries: Move hash page table allocation to reset time
In reply to David GibsonAt the moment the size of the hash page table (HPT) is fixed based on the maximum memory allowed to the guest. As such, we allocate the table during machine construction, and just clear it at reset.
However, we're planning to implement a PAPR extension allowing the hash page table to be resized at runtime. This will mean that on reset we want to revert it to the default size. It also means that when migrating, we need to make sure the destination allocates an HPT of size matching the host, since the guest could have changed it before the migration.
This patch replaces the spapr_alloc_htab() and spapr_reset_htab() functions with a new spapr_reallocate_hpt() function. This is called at reset and inbound migration only, not during machine init any more.
In addition, we add a new helper to compute the recommended hash table size for a given RAM size. We export this as well as spapr_reallocate_hpt(), since we'll be needing them elsewhere in future.
--- hw/ppc/spapr.c | 151 ++++++++++++++++++++++--------------------------- include/hw/ppc/spapr.h | 3 + 2 files changed, 71 insertions(+), 83 deletions(-)
hw/ppc/spapr.c +68 -83
@@ -1049,81 +1049,67 @@ static void close_htab_fd(sPAPRMachineState *spapr) spapr->htab_fd =-1 ; } -static void spapr_alloc_htab (sPAPRMachineState *spapr) -{ -long shift; -int index; - -/* allocate hash page table. For now we always make this 16mb, -* later we should probably make it scale to the size of guest -* RAM */ - - shift =kvmppc_reset_htab (spapr->htab_shift); -if (shift <0 ) { -/* -* For HV KVM, host kernel will return -ENOMEM when requested -* HTAB size can't be allocated. -*/ -error_setg (&error_abort,"Failed to allocate HTAB of requested size, try with smaller maxmem" ); - }else if (shift >0 ) { -/* -* Kernel handles htab, we don't need to allocate one -* -* Older kernels can fall back to lower HTAB shift values, -* but we don't allow booting of such guests. -*/ -if (shift != spapr->htab_shift) { -error_setg (&error_abort,"Failed to allocate HTAB of requested size, try with smaller maxmem" ); +int spapr_hpt_shift_for_ramsize (uint64_t ramsize) +{ +int shift; + +/* We aim for a hash table of size 1/128 the size of RAM (rounded +* up). The PAPR recommendation is actually 1/64 of RAM size, but +* that's much more than is needed for Linux guests */ + shift =ctz64 (pow2ceil (ramsize)) -7 ; + shift =MAX (shift,18 );/* Minimum architected size */ + shift =MIN (shift,46 );/* Maximum architected size */ +return shift; +} + +void spapr_reallocate_hpt (sPAPRMachineState *spapr,int shift,Error **errp) +{ +long rc; + +/* Clean up any HPT info from a previous boot */ +g_free (spapr->htab); + spapr->htab =NULL ; + spapr->htab_shift =0 ; +close_htab_fd (spapr); + + rc =kvmppc_reset_htab (shift); +if (rc <0 ) { +/* kernel-side HPT needed, but couldn't allocate one */ +error_setg_errno (errp, errno, +"Failed to allocate KVM HPT of order %d (try smaller maxmem?)" , + shift); +/* This is almost certainly fatal, but if the caller really +* wants to carry on with shift == 0, it's welcome to try */ + }else if (rc >0 ) { +/* kernel-side HPT allocated */ +if (rc != shift) { +error_setg (errp, +"Requested order %d HPT, but kernel allocated order %ld (try smaller maxmem?)" , + shift, rc); } spapr->htab_shift = shift; kvmppc_kern_htab = true; }else { -/* Allocate htab */ - spapr->htab =qemu_memalign (HTAB_SIZE (spapr),HTAB_SIZE (spapr)); - -/* And clear it */ -memset (spapr->htab,0 ,HTAB_SIZE (spapr)); - -for (index =0 ; index <HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 ; index++) { -DIRTY_HPTE (HPTE (spapr->htab, index)); - } - } -} - -/* -* Clear HTAB entries during reset. -* -* If host kernel has allocated HTAB, KVM_PPC_ALLOCATE_HTAB ioctl is -* used to clear HTAB. Otherwise QEMU-allocated HTAB is cleared manually. -*/ -static void spapr_reset_htab (sPAPRMachineState *spapr) -{ -long shift; -int index; +/* kernel-side HPT not needed, allocate in userspace instead */ +size_t size =1ULL << shift; +int i; - shift =kvmppc_reset_htab (spapr->htab_shift); -if (shift <0 ) { -error_setg (&error_abort,"Failed to reset HTAB" ); - }else if (shift >0 ) { -if (shift != spapr->htab_shift) { -error_setg (&error_abort,"Requested HTAB allocation failed during reset" ); + spapr->htab =qemu_memalign (size, size); +if (!spapr->htab) { +error_setg_errno (errp, errno, +"Could not allocate HPT of order %d" , shift); +return ; } -close_htab_fd (spapr); - }else { -memset (spapr->htab,0 ,HTAB_SIZE (spapr)); +memset (spapr->htab,0 , size); + spapr->htab_shift = shift; + kvmppc_kern_htab = false; -for (index =0 ; index <HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 ; index++) { -DIRTY_HPTE (HPTE (spapr->htab, index)); +for (i =0 ; i < size /HASH_PTE_SIZE_64 ; i++) { +DIRTY_HPTE (HPTE (spapr->htab, i)); } } - -/* Update the RMA size if necessary */ -if (spapr->vrma_adjust) { - spapr->rma_size =kvmppc_rma_size (spapr_node0_size (), - spapr->htab_shift); - } }static int find_unknown_sysbus_device (SysBusDevice *sbdev,void *opaque)
@@ -1145,15 +1131,24 @@ static int find_unknown_sysbus_device(SysBusDevice *sbdev, void *opaque)static void ppc_spapr_reset (void ) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +MachineState *machine =MACHINE (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (machine);PowerPCCPU *first_ppc_cpu;uint32_t rtas_limit;/* Check for unknown sysbus devices */ foreach_dynamic_sysbus_device (find_unknown_sysbus_device,NULL ); -/* Reset the hash table & recalc the RMA */ -spapr_reset_htab (spapr); +/* Allocate and/or reset the hash page table */ +spapr_reallocate_hpt (spapr, +spapr_hpt_shift_for_ramsize (machine->maxram_size), + &error_fatal); + +/* Update the RMA size if necessary */ +if (spapr->vrma_adjust) { + spapr->rma_size =kvmppc_rma_size (spapr_node0_size (), + spapr->htab_shift); + }qemu_devices_reset ();
@@ -1533,10 +1528,12 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id) section_hdr =qemu_get_be32 (f);if (section_hdr) { -/* First section, just the hash shift */ -if (spapr->htab_shift != section_hdr) { -error_report ("htab_shift mismatch: source %d target %d" , - section_hdr, spapr->htab_shift); +Error *local_err; + +/* First section gives the htab size */ +spapr_reallocate_hpt (spapr, section_hdr, &local_err); +if (local_err) { +error_report_err (local_err);return -EINVAL ; }return 0 ;
@@ -1789,18 +1786,6 @@ static void ppc_spapr_init(MachineState *machine)/* Setup a load limit for the ramdisk leaving room for SLOF and FDT */ load_limit =MIN (spapr->rma_size,RTAS_MAX_ADDR ) -FW_OVERHEAD ; -/* We aim for a hash table of size 1/128 the size of RAM. The -* normal rule of thumb is 1/64 the size of RAM, but that's much -* more than needed for the Linux guests we support. */ - spapr->htab_shift =18 ;/* Minimum architected size */ -while (spapr->htab_shift <=46 ) { -if ((1ULL << (spapr->htab_shift +7 )) >= machine->maxram_size) { -break ; - } - spapr->htab_shift++; - } -spapr_alloc_htab (spapr); -/* Set up Interrupt Controller before we create the VCPUs */ spapr->icp = xics_system_init(machine, DIV_ROUND_UP(max_cpus * kvmppc_smt_threads(),
include/hw/ppc/spapr.h +3 -0
@@ -373,6 +373,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,int spapr_allocate_irq (int hint,bool lsi);int spapr_allocate_irq_block (int num,bool lsi,bool msi); +int spapr_hpt_shift_for_ramsize (uint64_t ramsize); +void spapr_reallocate_hpt (sPAPRMachineState *spapr,int shift,Error **errp); +/* ibm,set-eeh-option */ #define RTAS_EEH_DISABLE 0#define RTAS_EEH_ENABLE 1
Signature · 1 line
2.5.0
RFC v2 3/6 pseries: Stubs for HPT resizing
In reply to David GibsonThis 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.
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 | 40 ++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_hcall.c | 37 +++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 11 ++++++++++- trace-events | 2 ++ 4 files changed, 89 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +40 -0
@@ -317,6 +317,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,const char *kernel_cmdline, uint32_t epow_irq) { + sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());void *fdt;uint32_t start_prop =cpu_to_be32 (initrd_base);uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size);
@@ -336,6 +337,9 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,add_str (hypertas,"hcall-splpar" );add_str (hypertas,"hcall-bulk" );add_str (hypertas,"hcall-set-mode" ); +if (spapr->resize_hpt !=SPAPR_RESIZE_HPT_DISABLED ) { +add_str (hypertas,"hcall-hpt-resize" ); + }add_str (qemu_hypertas,"hcall-memop1" ); fdt =g_malloc0 (FDT_MAX_SIZE );
@@ -2100,6 +2104,36 @@ static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp) spapr->kvm_type =g_strdup (value); } +static char *spapr_get_resize_hpt (Object *obj,Error **errp) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (obj); + +switch (spapr->resize_hpt) { +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,"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);
@@ -2110,6 +2144,12 @@ static void spapr_machine_initfn(Object *obj)object_property_set_description (obj,"kvm-type" ,"Specifies the KVM virtualization mode (HV, PR)" ,NULL ); + +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)
hw/ppc/spapr_hcall.c +37 -0
@@ -331,6 +331,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_dabr (PowerPCCPU *cpu,sPAPRMachineState *spapr,target_ulong opcode,target_ulong *args) {
@@ -989,6 +1021,11 @@ static void hypercall_register_types(void)/* hcall-bulk */ spapr_register_hypercall (H_BULK_REMOVE , h_bulk_remove); +/* hcall-hpt-resize */ +spapr_register_hypercall (KVMPPC_H_RESIZE_HPT_PREPARE , + h_resize_hpt_prepare); +spapr_register_hypercall (KVMPPC_H_RESIZE_HPT_COMMIT , h_resize_hpt_commit); +/* hcall-dabr */ spapr_register_hypercall (H_SET_DABR , h_set_dabr);
include/hw/ppc/spapr.h +10 -1
@@ -42,6 +42,12 @@ struct sPAPRMachineClass {/** * sPAPRMachineState: */ +typedef enum { +SPAPR_RESIZE_HPT_DISABLED =0 , +SPAPR_RESIZE_HPT_ENABLED , +SPAPR_RESIZE_HPT_REQUIRED , +}sPAPRResizeHPT ; +struct sPAPRMachineState {/*< private >*/ MachineState parent_obj;
@@ -52,6 +58,7 @@ struct sPAPRMachineState {XICSState *icp;DeviceState *rtc; +sPAPRResizeHPT resize_hpt;void *htab;uint32_t htab_shift;hwaddr rma_size;
@@ -351,7 +358,9 @@ struct sPAPRMachineState {#define KVMPPC_H_LOGICAL_MEMOP (KVMPPC_HCALL_BASE + 0x1)/* Client Architecture support */ #define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2) -#define KVMPPC_HCALL_MAX KVMPPC_H_CAS +#define KVMPPC_H_RESIZE_HPT_PREPARE (KVMPPC_HCALL_BASE + 0x3) +#define KVMPPC_H_RESIZE_HPT_COMMIT (KVMPPC_HCALL_BASE + 0x4) +#define KVMPPC_HCALL_MAX KVMPPC_H_RESIZE_HPT_COMMIT typedef struct sPAPRDeviceTreeUpdateHeader { uint32_t version_id;
trace-events +2 -0
@@ -1403,6 +1403,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 cpu_match, uint32_t new_pvr, uint64_t pcr) "current=%x, cpu_match=%u, new=%x, compat flags=%"PRIx64 +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
Signature · 1 line
2.5.0
RFC v2 4/6 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 | 2 - hw/ppc/spapr_hcall.c | 316 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 5 + target-ppc/mmu-hash64.h | 4 + 4 files changed, 322 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +0 -2
@@ -90,8 +90,6 @@#define PHANDLE_XICP 0x00001111 -#define HTAB_SIZE (spapr) (1ULL << ((spapr)->htab_shift)) -static XICSState *try_create_xics (const char *type,int nr_servers,int nr_irqs,Error **errp) {
hw/ppc/spapr_hcall.c +313 -3
350 lines not on this page · raw message
include/hw/ppc/spapr.h +5 -0
@@ -12,6 +12,7 @@ struct sPAPRPHBState;struct sPAPRNVRAM ;typedef struct sPAPRConfigureConnectorState sPAPRConfigureConnectorState ;typedef struct sPAPREventLogEntry sPAPREventLogEntry ; +typedef struct sPAPRPendingHPT sPAPRPendingHPT ;#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL#define SPAPR_ENTRY_POINT 0x100
@@ -61,6 +62,8 @@ struct sPAPRMachineState {sPAPRResizeHPT resize_hpt;void *htab;uint32_t htab_shift; +sPAPRPendingHPT *pending_hpt;/* in-progress resize */ +hwaddr rma_size;int vrma_adjust;hwaddr fdt_addr, rtas_addr;
@@ -640,4 +643,6 @@ int spapr_rng_populate_dt(void *fdt);*/ #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008 +#define HTAB_SIZE (spapr) (1ULL << ((spapr)->htab_shift)) +#endif /* !defined (__HW_SPAPR_H__) */
target-ppc/mmu-hash64.h +4 -0
@@ -59,11 +59,15 @@ unsigned ppc_hash64_hpte_page_shift_noslb(PowerPCCPU *cpu,#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)) & 0xffffffffffffff80ULL)) +#define HPTE64_V_BOLTED 0x0000000000000010ULL#define HPTE64_V_LARGE 0x0000000000000004ULL#define HPTE64_V_SECONDARY 0x0000000000000002ULL#define HPTE64_V_VALID 0x0000000000000001ULL
Signature · 1 line
2.5.0
RFC v2 5/6 pseries: Enable HPT resizing for 2.6
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 qemu-2.6, but leaves it disabled (by default) for older machine types.
--- hw/ppc/spapr.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/ppc/spapr.c +9 -0
@@ -2137,12 +2137,17 @@ static void spapr_machine_initfn(Object *obj)sPAPRMachineState *spapr =SPAPR_MACHINE (obj); spapr->htab_fd =-1 ; +object_property_add_str (obj,"kvm-type" , spapr_get_kvm_type, spapr_set_kvm_type,NULL );object_property_set_description (obj,"kvm-type" ,"Specifies the KVM virtualization mode (HV, PR)" ,NULL ); +if (!kvm_enabled ()) { +/* No KVM implementation of HPT resizing yet */ + spapr->resize_hpt =SPAPR_RESIZE_HPT_ENABLED ; + }object_property_add_str (obj,"resize-hpt" , spapr_get_resize_hpt, spapr_set_resize_hpt,NULL ); object_property_set_description(obj, "resize-hpt",
@@ -2412,6 +2417,10 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", true);static void spapr_machine_2_5_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + +spapr_machine_2_6_instance_options (machine); + spapr->resize_hpt =SPAPR_RESIZE_HPT_DISABLED ; }static void spapr_machine_2_5_class_options (MachineClass *mc)
Signature · 1 line
2.5.0
RFC v2 6/6 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 | 10 +++++++--- hw/ppc/spapr_hcall.c | 28 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-)
hw/ppc/spapr.c +7 -3
@@ -1137,14 +1137,18 @@ static void ppc_spapr_reset(void)sPAPRMachineState *spapr =SPAPR_MACHINE (machine);PowerPCCPU *first_ppc_cpu;uint32_t rtas_limit; +int hpt_shift;/* Check for unknown sysbus devices */ foreach_dynamic_sysbus_device (find_unknown_sysbus_device,NULL );/* Allocate and/or reset the hash page table */ -spapr_reallocate_hpt (spapr, -spapr_hpt_shift_for_ramsize (machine->maxram_size), - &error_fatal); +if (spapr->resize_hpt ==SPAPR_RESIZE_HPT_DISABLED ) { + hpt_shift =spapr_hpt_shift_for_ramsize (machine->maxram_size); + }else { + hpt_shift =spapr_hpt_shift_for_ramsize (machine->ram_size); + } +spapr_reallocate_hpt (spapr, hpt_shift, &error_fatal);/* Update the RMA size if necessary */ if (spapr->vrma_adjust) {
hw/ppc/spapr_hcall.c +27 -1
@@ -1160,12 +1160,14 @@ static void do_set_compat(void *arg) ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0)#define OV5_DRCONF_MEMORY 0x20 +#define OV5_HPT_RESIZE 0x80static target_ulong h_client_architecture_support (PowerPCCPU *cpu_,sPAPRMachineState *spapr,target_ulong opcode,target_ulong *args) { +MachineState *machine =MACHINE (spapr);target_ulong list =ppc64_phys_to_real (args[0 ]);target_ulong ov_table, ov5;PowerPCCPUClass *pcc_ =POWERPC_CPU_GET_CLASS (cpu_);
@@ -1175,7 +1177,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,unsigned compat_lvl =0 , cpu_version =0 ;unsigned max_lvl =get_compat_level (cpu_->max_compat);int counter; -char ov5_byte2; +char ov5_byte2, ov5_byte8;/* Parse PVR list */ for (counter =0 ; counter <512 ; ++counter) {
@@ -1265,6 +1267,30 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_, memory_update = true; } + ov5_byte8 =ldub_phys (&address_space_memory, ov5 +8 ); +if (!(ov5_byte8 &OV5_HPT_RESIZE )) { +int maxshift =spapr_hpt_shift_for_ramsize (machine->maxram_size); + +if (spapr->resize_hpt ==SPAPR_RESIZE_HPT_REQUIRED ) { +error_report ( +"h_client_architecture_support: Guest doesn't support HPT resizing with resize-hpt=required" ); +exit (1 ); + } + +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) { +run_on_cpu (cs, pivot_hpt, cs); + } + cpu_update = true; + } + } +if (spapr_h_cas_compose_response (spapr, args[1 ], args[2 ], cpu_update, memory_update)) {qemu_system_reset_request ();
Signature · 1 line
2.5.0