Skip to contentSkip to conversation

Draft implementation of HPT resizing (qemu side)

RFC In review David Gibson 4 participants 12 messages Jan 18, 2016 – Jan 30, 2016

lore
Share & tools
lore
#0 lore raw

cover Draft implementation of HPT resizing (qemu side)

Here is a draft qemu implementation of my proposed PAPR extension for allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

* KVM host side implementation

* PAPR standardization

[1] http://thread.gmane.org/gmane.linux.ports.ppc.embedded/90392

David Gibson (3):
pseries: Stub hypercalls for HPT resizing
pseries: Implement HPT resizing
pseries: Advertise HPT resize capability

 hw/ppc/spapr.c          |   5 +-
 hw/ppc/spapr_hcall.c    | 331 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h  |   9 +-
 target-ppc/mmu-hash64.h |   4 +
 trace-events            |   2 +
 5 files changed, 348 insertions(+), 3 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

RFC 1/3 pseries: Stub hypercalls 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.

---
 hw/ppc/spapr_hcall.c   | 29 +++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h |  4 +++-
 trace-events           |  2 ++
 3 files changed, 34 insertions(+), 1 deletion(-)
hw/ppc/spapr_hcall.c +29 -0
index 1a1bea8..01c034c 100644
@@ -316,6 +316,30 @@ 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];
+
+    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];
+
+    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)
 {
@@ -974,6 +998,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 +3 -1
index 53af76a..028afc9 100644
@@ -352,7 +352,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
index 934a7b6..f0d6e49 100644
@@ -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
#2 lore raw

RFC 2/3 pseries: Implement HPT resizing

In reply to David Gibson

This 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    | 308 +++++++++++++++++++++++++++++++++++++++++++++++-
 include/hw/ppc/spapr.h  |   5 +
 target-ppc/mmu-hash64.h |   4 +
 4 files changed, 314 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +0 -2
index 50e5a26..e26baca 100644
@@ -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 +305 -3

334 lines not on this page · raw message

include/hw/ppc/spapr.h +5 -0
index 028afc9..02cb950 100644
@@ -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
@@ -54,6 +55,8 @@ struct sPAPRMachineState {
 
     void *htab;
     uint32_t htab_shift;
+    sPAPRPendingHPT *pending_hpt; /* in-progress resize */
+
     hwaddr rma_size;
     int vrma_adjust;
     hwaddr fdt_addr, rtas_addr;
@@ -649,4 +652,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
index 1b1695b..6038fd2 100644
@@ -58,11 +58,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
#3 lore raw

RFC 3/3 pseries: Advertise HPT resize capability

In reply to David Gibson

This 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 | 3 +++
 1 file changed, 3 insertions(+)
hw/ppc/spapr.c +3 -0
index e26baca..1147382 100644
@@ -334,6 +334,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 (!kvm_enabled()) { /* Not implemented in KVM yet */
+        add_str(hypertas, "hcall-hpt-resize");
+    }
     add_str(qemu_hypertas, "hcall-memop1");
 
     fdt = g_malloc0(FDT_MAX_SIZE);
Signature · 1 line
2.5.0
#4 lore raw
In reply to David Gibson

On Mon, Jan 18, 2016 at 04:44:38PM +1100, David Gibson wrote:
1;2802;0c> Here is a draft qemu implementation of my proposed PAPR extension for

Quoted 12 lines

allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

Quoted 6 lines

* KVM host side implementation

* PAPR standardization

[1] http://thread.gmane.org/gmane.linux.ports.ppc.embedded/90392

Sorry, forgot to mention that this series applies on top of my page size handling cleanup series posted recently.

Quoted 13 lines

David Gibson (3):
pseries: Stub hypercalls for HPT resizing
pseries: Implement HPT resizing
pseries: Advertise HPT resize capability

 hw/ppc/spapr.c          |   5 +-
 hw/ppc/spapr_hcall.c    | 331 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h  |   9 +-
 target-ppc/mmu-hash64.h |   4 +
 trace-events            |   2 +
 5 files changed, 348 insertions(+), 3 deletions(-)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw
In reply to David Gibson
Quoted 10 lines · David Gibson

Here is a draft qemu implementation of my proposed PAPR extension for allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

Quoted 6 lines

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

* KVM host side implementation

* PAPR standardization

So with the current patchset (QEMU and guest kernel changes), I should be able to change the HTAB size of a PR guest right ? I see the below failure though:

[root@localhost ~]# cat /sys/kernel/debug/powerpc/pft-size 24
[root@localhost ~]# echo 26 > /sys/kernel/debug/powerpc/pft-size

[   65.996845] lpar: Attempting to resize HPT to shift 26
[   65.996845] lpar: Attempting to resize HPT to shift 26
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)

PR guest just hangs here while I see tons of below messages in the 1st level guest:

KVM can't copy data from 0x3fff99e91400!
...
Couldn't emulate instruction 0x00000000 (op 0 xop 0)
kvmppc_handle_exit_pr: emulation at 700 failed (00000000)

Regards,
Bharata.

#6 lore raw
Quoted 14 lines · Bharata B Rao
Quoted 13 lines · David Gibson

Here is a draft qemu implementation of my proposed PAPR extension for allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

Quoted 7 lines
Quoted 3 lines

* KVM host side implementation

* PAPR standardization

So with the current patchset (QEMU and guest kernel changes), I should be able to change the HTAB size of a PR guest right ? I see the below failure though:

Uh.. to be honest I haven't really considered the KVM case at all. I'm kind of surprised it didn't just refuse to do anything.

Quoted 8 lines

[root@localhost ~]# cat /sys/kernel/debug/powerpc/pft-size 24
[root@localhost ~]# echo 26 > /sys/kernel/debug/powerpc/pft-size

[   65.996845] lpar: Attempting to resize HPT to shift 26
[   65.996845] lpar: Attempting to resize HPT to shift 26
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)
Quoted 7 lines

PR guest just hangs here while I see tons of below messages in the 1st level guest:

KVM can't copy data from 0x3fff99e91400!
...
Couldn't emulate instruction 0x00000000 (op 0 xop 0)
kvmppc_handle_exit_pr: emulation at 700 failed (00000000)

Hm, not sure why that's happening. At first I thought it was because we weren't updating SDR1 with the address of the new htab, but that's actually in there. Maybe the KVM PR code isn't rereading it after initial VM startup.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw
Quoted 35 lines · David Gibson
Quoted 14 lines · Bharata B Rao
Quoted 13 lines · David Gibson

Here is a draft qemu implementation of my proposed PAPR extension for allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

Quoted 6 lines
Quoted 3 lines

* KVM host side implementation

* PAPR standardization

So with the current patchset (QEMU and guest kernel changes), I should be able to change the HTAB size of a PR guest right ? I see the below failure though:

Uh.. to be honest I haven't really considered the KVM case at all. I'm kind of surprised it didn't just refuse to do anything.

Quoted 11 lines

[root@localhost ~]# cat /sys/kernel/debug/powerpc/pft-size 24
[root@localhost ~]# echo 26 > /sys/kernel/debug/powerpc/pft-size

[   65.996845] lpar: Attempting to resize HPT to shift 26
[   65.996845] lpar: Attempting to resize HPT to shift 26
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)

PR guest just hangs here while I see tons of below messages in the 1st level guest:

Quoted 8 lines
Quoted 4 lines

KVM can't copy data from 0x3fff99e91400!
...
Couldn't emulate instruction 0x00000000 (op 0 xop 0)
kvmppc_handle_exit_pr: emulation at 700 failed (00000000)

Hm, not sure why that's happening. At first I thought it was because we weren't updating SDR1 with the address of the new htab, but that's actually in there. Maybe the KVM PR code isn't rereading it after initial VM startup.

The KVM PR code doesn't care - it just rereads SDR1 on every pteg lookup ;). There's no caching at all.

Of course, the guest needs to invalidate all pending tlb entries if they're now invalid.

Does this work on real hardware? Say, a G5?

Alex

#8 lore raw
Quoted 2 lines · Alexander Graf

Does this work on real hardware? Say, a G5?

Do you mean, could a bare-metal kernel change its hashed page table? It could - it would have to allocate a new table, copy over the bolted mappings (at least), switch to real mode, change SDR1, switch back to virtual mode.

Paul.

#9 lore raw
In reply to Alexander Graf
Quoted 42 lines · Alexander Graf
Quoted 39 lines · David Gibson
Quoted 14 lines · Bharata B Rao
Quoted 13 lines · David Gibson

Here is a draft qemu implementation of my proposed PAPR extension for allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

Quoted 6 lines
Quoted 3 lines

* KVM host side implementation

* PAPR standardization

So with the current patchset (QEMU and guest kernel changes), I should be able to change the HTAB size of a PR guest right ? I see the below failure though:

Uh.. to be honest I haven't really considered the KVM case at all. I'm kind of surprised it didn't just refuse to do anything.

Quoted 15 lines

[root@localhost ~]# cat /sys/kernel/debug/powerpc/pft-size 24
[root@localhost ~]# echo 26 > /sys/kernel/debug/powerpc/pft-size

[   65.996845] lpar: Attempting to resize HPT to shift 26
[   65.996845] lpar: Attempting to resize HPT to shift 26
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)

PR guest just hangs here while I see tons of below messages in the 1st level guest:

KVM can't copy data from 0x3fff99e91400!
...
Couldn't emulate instruction 0x00000000 (op 0 xop 0)
kvmppc_handle_exit_pr: emulation at 700 failed (00000000)

Quoted 7 lines
Quoted 4 lines

Hm, not sure why that's happening. At first I thought it was because we weren't updating SDR1 with the address of the new htab, but that's actually in there. Maybe the KVM PR code isn't rereading it after initial VM startup.

The KVM PR code doesn't care - it just rereads SDR1 on every pteg lookup ;). There's no caching at all.

Ok, no idea why it's not working then. I'll investigate when I get a chance.

Quoted 4 lines

Of course, the guest needs to invalidate all pending tlb entries if they're now invalid.

Does this work on real hardware? Say, a G5?

As Paulus says it would be possible to do HPT resizing on real hardware, but the implementation I've done is specific to PAPR. And obviously qemu wouldn't be relevant to that case.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#10 lore raw
Quoted 57 lines

Am 29.01.2016 um 04:47 schrieb David Gibson <[email protected]>:

Quoted 43 lines · Alexander Graf
Quoted 42 lines · David Gibson
Quoted 15 lines · Bharata B Rao
Quoted 14 lines · David Gibson

Here is a draft qemu implementation of my proposed PAPR extension for allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

Quoted 6 lines
Quoted 3 lines

* KVM host side implementation

* PAPR standardization

So with the current patchset (QEMU and guest kernel changes), I should be able to change the HTAB size of a PR guest right ? I see the below failure though:

Uh.. to be honest I haven't really considered the KVM case at all. I'm kind of surprised it didn't just refuse to do anything.

Quoted 15 lines

[root@localhost ~]# cat /sys/kernel/debug/powerpc/pft-size 24
[root@localhost ~]# echo 26 > /sys/kernel/debug/powerpc/pft-size

[   65.996845] lpar: Attempting to resize HPT to shift 26
[   65.996845] lpar: Attempting to resize HPT to shift 26
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)

PR guest just hangs here while I see tons of below messages in the 1st level guest:

KVM can't copy data from 0x3fff99e91400!
...
Couldn't emulate instruction 0x00000000 (op 0 xop 0)
kvmppc_handle_exit_pr: emulation at 700 failed (00000000)

Quoted 7 lines
Quoted 4 lines

Hm, not sure why that's happening. At first I thought it was because we weren't updating SDR1 with the address of the new htab, but that's actually in there. Maybe the KVM PR code isn't rereading it after initial VM startup.

The KVM PR code doesn't care - it just rereads SDR1 on every pteg lookup ;). There's no caching at all.

Ok, no idea why it's not working then. I'll investigate when I get a chance.

Quoted 8 lines
Quoted 4 lines

Of course, the guest needs to invalidate all pending tlb entries if they're now invalid.

Does this work on real hardware? Say, a G5?

As Paulus says it would be possible to do HPT resizing on real hardware, but the implementation I've done is specific to PAPR. And obviously qemu wouldn't be relevant to that case.

So why make it specific to papr? Wouldn't it make sense to have it as a (ppc) generic interface in Linux?

For the PR PAPR case, QEMU allocates the HTAB, so it needs to make sure it pushes the changed address as new fake SDR1 value into kvm when it changes.

Alex

#11 lore raw
Quoted 60 lines · Alexander Graf
Quoted 60 lines

Am 29.01.2016 um 04:47 schrieb David Gibson <[email protected]>:

Quoted 43 lines · Alexander Graf
Quoted 42 lines · David Gibson
Quoted 15 lines · Bharata B Rao
Quoted 14 lines · David Gibson

Here is a draft qemu implementation of my proposed PAPR extension for allowing runtime resizing of a KVM/ppc64 guest's hash page table. That in turn will allow for more flexible memory hotplug.

This should work with the guest kernel side patches I also posted recently [1].

Still required to make this into a full implementation:
* Guest needs to auto-resize HPT on memory hotplug events

* qemu needs to allocate HPT size based on current rather than maximum memory if the guest is HPT resize aware

Quoted 6 lines
Quoted 3 lines

* KVM host side implementation

* PAPR standardization

So with the current patchset (QEMU and guest kernel changes), I should be able to change the HTAB size of a PR guest right ? I see the below failure though:

Uh.. to be honest I haven't really considered the KVM case at all. I'm kind of surprised it didn't just refuse to do anything.

Quoted 15 lines

[root@localhost ~]# cat /sys/kernel/debug/powerpc/pft-size 24
[root@localhost ~]# echo 26 > /sys/kernel/debug/powerpc/pft-size

[   65.996845] lpar: Attempting to resize HPT to shift 26
[   65.996845] lpar: Attempting to resize HPT to shift 26
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)
[   66.113596] lpar: HPT resize to shift 26 complete (109 ms / 6 ms)

PR guest just hangs here while I see tons of below messages in the 1st level guest:

KVM can't copy data from 0x3fff99e91400!
...
Couldn't emulate instruction 0x00000000 (op 0 xop 0)
kvmppc_handle_exit_pr: emulation at 700 failed (00000000)

Quoted 7 lines
Quoted 4 lines

Hm, not sure why that's happening. At first I thought it was because we weren't updating SDR1 with the address of the new htab, but that's actually in there. Maybe the KVM PR code isn't rereading it after initial VM startup.

The KVM PR code doesn't care - it just rereads SDR1 on every pteg lookup ;). There's no caching at all.

Ok, no idea why it's not working then. I'll investigate when I get a chance.

Quoted 3 lines

Of course, the guest needs to invalidate all pending tlb entries if they're now invalid.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Does this work on real hardware? Say, a G5?

As Paulus says it would be possible to do HPT resizing on real hardware, but the implementation I've done is specific to PAPR. And obviously qemu wouldn't be relevant to that case.

So why make it specific to papr? Wouldn't it make sense to have it as a (ppc) generic interface in Linux?

Well, I sort of did, in that I added a ppc_md call for it. I just haven't implemented it for anything other than PAPR yet - the PAPR implementation is quite different from what the native one would be, since the hypervisor needs to handle the rehashing.

Quoted 3 lines

For the PR PAPR case, QEMU allocates the HTAB, so it needs to make sure it pushes the changed address as new fake SDR1 value into kvm when it changes.

Yes, I'm doing that - have a look at the qemu series. Not 100% sure it's correct, since I haven't debugged with PR KVM yet.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson