ppc-for-2.10 queue 20170714
The following changes since commit 49bcce4b9c11759678fd223aefb48691c4959d4f:
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-07-12' into staging (2017-07-13 16:56:06 +0100)
are available in the git repository at:
git://github.com/dgibson/qemu.git tags/ppc-for-2.10-20170714
for you to fetch changes up to e11134d2ac7744569d7c387102368c507d340c30:
pseries: Allow HPT resizing with KVM (2017-07-14 09:28:30 +1000)
----------------------------------------------------------------
ppc patch queue 2017-07-14
Two major batches in this set, rather than the usual collection of assorted fixes.
* More DRC cleanup. This gets the state management into a state which should fix many of the hotplug+migration problems we've had. Plus it gets the migration stream format into something well defined and pretty minimal which we can reasonably support into the future.
* Hashed Page Table resizing. It's been a while since this was posted, but it's been through several previous rounds of review. The kernel parts (both guest and host) are merged in 4.11, so this is the only remaining piece left to allow resizing of the HPT in a running guest.
There are also a handful of unrelated fixes.
----------------------------------------------------------------
Alexey Kardashevskiy (1):
ppc/pnv: Remove unused XICSState reference
Daniel Henrique Barboza (1):
spapr: migrate pending_events of spapr state
David Gibson (14):
spapr: Minor cleanups to events handling
spapr: Remove 'awaiting_allocation' DRC flag
spapr: Simplify unplug path
spapr: Abort on delete failure in spapr_drc_release()
spapr: Refactor spapr_drc_detach()
spapr: Cleanups relating to DRC awaiting_release field
spapr: Consolidate DRC state variables
spapr: Remove sPAPRConfigureConnectorState sub-structure
spapr: Implement DR-indicator for physical DRCs only
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
Greg Kurz (1):
spapr: fix potential memory leak in spapr_core_plug()
Laurent Vivier (1):
spapr: Treat devices added before inbound migration as coldplugged
hw/ppc/spapr.c | 235 ++++++++++++++++-------- hw/ppc/spapr_drc.c | 401 ++++++++++++++++++++++------------------ hw/ppc/spapr_events.c | 98 +++++----- hw/ppc/spapr_hcall.c | 439 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_pci.c | 17 +- hw/ppc/trace-events | 5 +- include/hw/ppc/pnv_psi.h | 2 - include/hw/ppc/spapr.h | 24 ++- include/hw/ppc/spapr_drc.h | 74 +++++--- include/hw/ppc/spapr_ovec.h | 1 + target/ppc/kvm.c | 76 ++++++++ target/ppc/kvm_ppc.h | 26 +++ target/ppc/mmu-hash64.h | 4 + 13 files changed, 1056 insertions(+), 346 deletions(-)
[Qemu-devel] [PULL 02/18] spapr: Minor cleanups to events handling
The rtas_error_log structure is marked packed, which strongly suggests its precise layout is important to match an external interface. Along with that one could expect it to have a fixed endianness to match the same interface. That used to be the case - matching the layout of PAPR RTAS event format and requiring BE fields.
Now, however, it's only used embedded within sPAPREventLogEntry with the fields in native order, since they're processed internally.
Clear that up by removing the nested structure in sPAPREventLogEntry. struct rtas_error_log is moved back to spapr_events.c where it is used as a temporary to help convert the fields in sPAPREventLogEntry to the correct in memory format when delivering an event to the guest.
--- hw/ppc/spapr.c | 6 +++--- hw/ppc/spapr_events.c | 45 ++++++++++++++++++++++----------------------- include/hw/ppc/spapr.h | 6 +----- 3 files changed, 26 insertions(+), 31 deletions(-)
hw/ppc/spapr.c +3 -3
@@ -1528,10 +1528,10 @@ static const VMStateDescription vmstate_spapr_event_entry = { .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField []) { -VMSTATE_UINT32 (header.summary, sPAPREventLogEntry), -VMSTATE_UINT32 (header.extended_length, sPAPREventLogEntry), +VMSTATE_UINT32 (summary, sPAPREventLogEntry), +VMSTATE_UINT32 (extended_length, sPAPREventLogEntry),VMSTATE_VBUFFER_ALLOC_UINT32 (extended_log, sPAPREventLogEntry,0 , -NULL , header.extended_length), +NULL , extended_length),VMSTATE_END_OF_LIST () }, };
hw/ppc/spapr_events.c +22 -23
121 lines not on this page · raw message
include/hw/ppc/spapr.h +1 -5
@@ -601,13 +601,9 @@ struct sPAPRTCETable {sPAPRTCETable *spapr_tce_find_by_liobn (target_ulong liobn); -struct rtas_error_log { +struct sPAPREventLogEntry {uint32_t summary;uint32_t extended_length; -}QEMU_PACKED ; - -struct sPAPREventLogEntry { -struct rtas_error_log header;void *extended_log;QTAILQ_ENTRY (sPAPREventLogEntry) next; };
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 04/18] spapr: Remove 'awaiting_allocation' DRC flag
In reply to David GibsonThe awaiting_allocation flag in the DRC was introduced by aab9913 "spapr_drc: Prevent detach racing against attach for CPU DR", allegedly to prevent a guest crash on racing attach and detach. Except.. information from the BZ actually suggests a qemu crash, not a guest crash. And there shouldn't be a problem here anyway: if the guest has already moved the DRC away from UNUSABLE state, the detach would already be deferred, and if it hadn't it should be safe to detach it (the guest should fail gracefully when it attempts to change the allocation state).
I think this was probably just a bandaid for some other problem in the state management. So, remove awaiting_allocation and associated code.
--- hw/ppc/spapr_drc.c | 25 +++---------------------- include/hw/ppc/spapr_drc.h | 1 - 2 files changed, 3 insertions(+), 23 deletions(-)
hw/ppc/spapr_drc.c +3 -22
@@ -170,19 +170,13 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc)if (!drc->dev) {return RTAS_OUT_NO_SUCH_INDICATOR ; } -if (drc->awaiting_release && drc->awaiting_allocation) { -/* kernel is acknowledging a previous hotplug event -* while we are already removing it. -* it's safe to ignore awaiting_allocation here since we know the -* situation is predicated on the guest either already having done -* so (boot-time hotplug), or never being able to acquire in the -* first place (hotplug followed by immediate unplug). -*/ +if (drc->awaiting_release) { +/* Don't allow the guest to move a device away from UNUSABLE +* state when we want to unplug it */ return RTAS_OUT_NO_SUCH_INDICATOR ; } drc->allocation_state =SPAPR_DR_ALLOCATION_STATE_USABLE ; - drc->awaiting_allocation = false;return RTAS_OUT_SUCCESS ; }
@@ -357,10 +351,6 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, drc->fdt = fdt; drc->fdt_start_offset = fdt_start_offset; -if (spapr_drc_type (drc) !=SPAPR_DR_CONNECTOR_TYPE_PCI ) { - drc->awaiting_allocation = true; - } - object_property_add_link(OBJECT(drc), "device", object_get_typename(OBJECT(drc->dev)), (Object **)(&drc->dev),
@@ -398,12 +388,6 @@ void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp)return ; } -if (drc->awaiting_allocation) { - drc->awaiting_release = true; -trace_spapr_drc_awaiting_allocation (spapr_drc_index (drc)); -return ; - } -spapr_drc_release (drc); }
@@ -426,8 +410,6 @@ void spapr_drc_reset(sPAPRDRConnector *drc)spapr_drc_release (drc); } - drc->awaiting_allocation = false; -if (drc->dev) {/* A device present at reset is coldplugged */ drc->isolation_state =SPAPR_DR_ISOLATION_STATE_UNISOLATED ;
@@ -493,7 +475,6 @@ static const VMStateDescription vmstate_spapr_drc = {VMSTATE_UINT32 (dr_indicator, sPAPRDRConnector),VMSTATE_BOOL (configured, sPAPRDRConnector),VMSTATE_BOOL (awaiting_release, sPAPRDRConnector), -VMSTATE_BOOL (awaiting_allocation, sPAPRDRConnector), VMSTATE_END_OF_LIST() } };
include/hw/ppc/spapr_drc.h +0 -1
@@ -200,7 +200,6 @@ typedef struct sPAPRDRConnector {sPAPRConfigureConnectorState *ccs;bool awaiting_release; -bool awaiting_allocation;/* device pointer, via link property */ DeviceState *dev;
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 12/18] spapr: fix potential memory leak in spapr_core_plug()
In reply to David GibsonFrom: Greg Kurz <[email protected]>
Since commit 5c1da81215c7 ("spapr: Remove unnecessary differences between hotplug and coldplug paths"), the CPU DT for the DRC is always allocated. This causes a memory leak for pseries-2.6 and older machine types, that don't support CPU hotplug and don't allocate DRCs for CPUs.
--- hw/ppc/spapr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/ppc/spapr.c +5 -4
@@ -2974,8 +2974,6 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,CPUState *cs =CPU (core->threads);sPAPRDRConnector *drc;Error *local_err =NULL ; -void *fdt =NULL ; -int fdt_offset =0 ;int smt =kvmppc_smt_threads ();CPUArchId *core_slot;int index;
@@ -2991,9 +2989,12 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,g_assert (drc || !mc->has_hotpluggable_cpus); - fdt =spapr_populate_hotplug_cpu_dt (cs, &fdt_offset, spapr); -if (drc) { +void *fdt; +int fdt_offset; + + fdt =spapr_populate_hotplug_cpu_dt (cs, &fdt_offset, spapr); +spapr_drc_attach (drc, dev, fdt, fdt_offset, &local_err);if (local_err) {g_free (fdt);
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 03/18] spapr: Treat devices added before inbound migration as coldplugged
In reply to David GibsonFrom: Laurent Vivier <[email protected]>
When migrating a guest which has already had devices hotplugged, libvirt typically starts the destination qemu with -incoming defer, adds those hotplugged devices with qmp, then initiates the incoming migration.
This causes problems for the management of spapr DRC state. Because the device is treated as hotplugged, it goes into a DRC state for a device immediately after it's plugged, but before the guest has acknowledged its presence. However, chances are the guest on the source machine *has* acknowledged the device's presence and configured it.
If the source has fully configured the device, then DRC state won't be sent in the migration stream: for maximum migration compatibility with earlier versions we don't migrate DRCs in coldplug-equivalent state. That means that the DRC effectively changes state over the migrate, causing problems later on.
In addition, logging hotplug events for these devices isn't what we want because a) those events should already have been issued on the source host and b) the event queue should get wiped out by the incoming state anyway.
In short, what we really want is to treat devices added before an incoming migration as if they were coldplugged.
To do this, we first add a spapr_drc_hotplugged() helper which determines if the device is hotplugged in the sense relevant for DRC state management. We only send hotplug events when this is true. Second, when we add a device which isn't hotplugged in this sense, we force a reset of the DRC state - this ensures the DRC is in a coldplug-equivalent state (there isn't usually a system reset between these device adds and the incoming migration).
This is based on an earlier patch by Laurent Vivier, cleaned up and extended.
--- hw/ppc/spapr.c | 24 ++++++++++++++++-------- hw/ppc/spapr_drc.c | 9 ++++++--- hw/ppc/spapr_pci.c | 4 +++- include/hw/ppc/spapr_drc.h | 8 ++++++++ 4 files changed, 33 insertions(+), 12 deletions(-)
hw/ppc/spapr.c +16 -8
@@ -2636,6 +2636,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,int i, fdt_offset, fdt_size;void *fdt;uint64_t addr = addr_start; +bool hotplugged =spapr_drc_hotplugged (dev);Error *local_err =NULL ;for (i =0 ; i < nr_lmbs; i++) {
@@ -2659,12 +2660,15 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,error_propagate (errp, local_err);return ; } +if (!hotplugged) { +spapr_drc_reset (drc); + } addr +=SPAPR_MEMORY_BLOCK_SIZE ; }/* send hotplug notification to the * guest only in case of hotplugged memory */ -if (dev->hotplugged) { +if (hotplugged) {if (dedicated_hp_event_source) { drc =spapr_drc_by_id (TYPE_SPAPR_DRC_LMB , addr_start /SPAPR_MEMORY_BLOCK_SIZE );
@@ -2998,6 +3002,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,int smt =kvmppc_smt_threads ();CPUArchId *core_slot;int index; +bool hotplugged =spapr_drc_hotplugged (dev); core_slot =spapr_find_cpu_slot (MACHINE (hotplug_dev), cc->core_id, &index);if (!core_slot) {
@@ -3018,15 +3023,18 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,error_propagate (errp, local_err);return ; } - } -if (dev->hotplugged) { -/* -* Send hotplug notification interrupt to the guest only in case -* of hotplugged CPUs. -*/ -spapr_hotplug_req_add_by_index (drc); +if (hotplugged) { +/* +* Send hotplug notification interrupt to the guest only +* in case of hotplugged CPUs. +*/ +spapr_hotplug_req_add_by_index (drc); + }else { +spapr_drc_reset (drc); + } } + core_slot->cpu =OBJECT (dev);if (smc->pre_2_10_has_unused_icps) {
hw/ppc/spapr_drc.c +6 -3
@@ -412,10 +412,8 @@ static bool release_pending(sPAPRDRConnector *drc)return drc->awaiting_release; } -static void drc_reset (void *opaque) +void spapr_drc_reset (sPAPRDRConnector *drc) { -sPAPRDRConnector *drc =SPAPR_DR_CONNECTOR (opaque); -trace_spapr_drc_reset (spapr_drc_index (drc));g_free (drc->ccs);
@@ -447,6 +445,11 @@ static void drc_reset(void *opaque) } } +static void drc_reset (void *opaque) +{ +spapr_drc_reset (SPAPR_DR_CONNECTOR (opaque)); +} +static bool spapr_drc_needed (void *opaque) {sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque;
hw/ppc/spapr_pci.c +3 -1
@@ -1443,7 +1443,9 @@ static void spapr_pci_plug(HotplugHandler *plug_handler,/* If this is function 0, signal hotplug for all the device functions. * Otherwise defer sending the hotplug event. */ -if (plugged_dev->hotplugged &&PCI_FUNC (pdev->devfn) ==0 ) { +if (!spapr_drc_hotplugged (plugged_dev)) { +spapr_drc_reset (drc); + }else if (PCI_FUNC (pdev->devfn) ==0 ) {int i;for (i =0 ; i <8 ; i++) {
include/hw/ppc/spapr_drc.h +8 -0
@@ -15,6 +15,7 @@#include <libfdt.h> #include "qom/object.h" +#include "sysemu/sysemu.h" #include "hw/qdev.h" #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
@@ -223,6 +224,13 @@ typedef struct sPAPRDRConnectorClass {bool (*release_pending)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass; +static inline bool spapr_drc_hotplugged (DeviceState *dev) +{ +return dev->hotplugged && !runstate_check (RUN_STATE_INMIGRATE ); +} + +void spapr_drc_reset (sPAPRDRConnector *drc); +uint32_t spapr_drc_index (sPAPRDRConnector *drc);sPAPRDRConnectorType spapr_drc_type (sPAPRDRConnector *drc);
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 06/18] spapr: Abort on delete failure in spapr_drc_release()
In reply to David GibsonWe currently ignore errors from the object_property_del() in spapr_drc_release(). But the only way that could fail is if the property doesn't exist, in which case it's a bug that we're in spapr_drc_release() at all. So change from ignoring to abort()ing on errors.
--- hw/ppc/spapr_drc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_drc.c +1 -1
@@ -367,7 +367,7 @@ static void spapr_drc_release(sPAPRDRConnector *drc)g_free (drc->fdt); drc->fdt =NULL ; drc->fdt_start_offset =0 ; -object_property_del (OBJECT (drc),"device" ,NULL ); +object_property_del (OBJECT (drc),"device" , &error_abort); drc->dev =NULL ; }
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 01/18] spapr: migrate pending_events of spapr state
In reply to David GibsonFrom: Daniel Henrique Barboza <[email protected]>
In racing situations between hotplug events and migration operation, a rtas hotplug event could have not yet be delivered to the source guest when migration is started. In this case the pending_events of spapr state need be transmitted to the target so that the hotplug event can be finished on the target.
To achieve the minimal VMSD possible to migrate the pending_events list, this patch makes the changes in spapr_events.c:
- 'log_type' of sPAPREventLogEntry struct deleted. This information can be derived by inspecting the rtas_error_log summary field. A new function called 'spapr_event_log_entry_type' was added to retrieve the type of a given sPAPREventLogEntry.
- sPAPREventLogEntry, epow_log_full and hp_log_full were redesigned. The only data we're going to migrate in the VMSD is the event log data itself, which can be divided in two parts: a rtas_error_log header and an extended event log field. The rtas_error_log header contains information about the size of the extended log field, which can be used inside VMSD as the size parameter of the VBUFFER_ALOC field that will store it. To allow this use, the header.extended_length field must be exposed inline to the VMSD instead of embedded into a 'data' field that holds everything. With this in mind, the following changes were done:
* a new 'header' field was added to sPAPREventLogEntry. This field holds a
a struct rtas_error_log inline.
* the declaration of the 'rtas_error_log' struct was moved to spapr.h
to be visible to the VMSD macros.
* 'data' field of sPAPREventLogEntry was renamed to 'extended_log' and
now holds only the contents of the extended event log.
* 'struct rtas_error_log hdr' were taken away from both epow_log_full
and hp_log_full. This information is now available at the header field of sPAPREventLogEntry.
* epow_log_full and hp_log_full were renamed to epow_extended_log andhp_extended_log respectively. This rename makes it clearer to understand the new purpose of both structures: hold the information of an extended event log field.
* spapr_powerdown_req and spapr_hotplug_req_event now creates a
sPAPREventLogEntry structure that contains the full rtas log entry.
* rtas_event_log_queue and rtas_event_log_dequeue now receives a
sPAPREventLogEntry pointer as a parameter instead of a void pointer.
- the endianess of the sPAPREventLogEntry header is now native instead of be32. We can use the fields in native endianess internally and write them in be32 in the guest physical memory inside 'check_exception'. This allows the VMSD inside spapr.c to read the correct size of the entended_log field.
- inside spapr.c, pending_events is put in a subsection in the spapr state VMSD to make sure migration across different versions is not broken.
A small change in rtas_event_log_queue and rtas_event_log_dequeue were also
made: instead of calling qdev_get_machine(), both functions now receive a pointer to the sPAPRMachineState. This pointer is already available in the callers of these functions and we don't need to waste resources calling qdev() again.
--- hw/ppc/spapr.c | 32 ++++++++++++++++ hw/ppc/spapr_events.c | 99 +++++++++++++++++++++++++++----------------------- include/hw/ppc/spapr.h | 9 ++++- 3 files changed, 92 insertions(+), 48 deletions(-)
hw/ppc/spapr.c +32 -0
@@ -1517,6 +1517,37 @@ static bool version_before_3(void *opaque, int version_id)return version_id <3 ; } +static bool spapr_pending_events_needed (void *opaque) +{ +sPAPRMachineState *spapr = (sPAPRMachineState *)opaque; +return !QTAILQ_EMPTY (&spapr->pending_events); +} + +static const VMStateDescription vmstate_spapr_event_entry = { + .name ="spapr_event_log_entry" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (header.summary, sPAPREventLogEntry), +VMSTATE_UINT32 (header.extended_length, sPAPREventLogEntry), +VMSTATE_VBUFFER_ALLOC_UINT32 (extended_log, sPAPREventLogEntry,0 , +NULL , header.extended_length), +VMSTATE_END_OF_LIST () + }, +}; + +static const VMStateDescription vmstate_spapr_pending_events = { + .name ="spapr_pending_events" , + .version_id =1 , + .minimum_version_id =1 , + .needed = spapr_pending_events_needed, + .fields = (VMStateField []) { +VMSTATE_QTAILQ_V (pending_events, sPAPRMachineState,1 , + vmstate_spapr_event_entry, sPAPREventLogEntry, next), +VMSTATE_END_OF_LIST () + }, +}; +static bool spapr_ov5_cas_needed (void *opaque) {sPAPRMachineState *spapr = opaque;
@@ -1615,6 +1646,7 @@ static const VMStateDescription vmstate_spapr = { .subsections = (const VMStateDescription*[]) { &vmstate_spapr_ov5_cas, &vmstate_spapr_patb_entry, + &vmstate_spapr_pending_events,NULL } };
hw/ppc/spapr_events.c +53 -46
217 lines not on this page · raw message
include/hw/ppc/spapr.h +7 -2
@@ -601,9 +601,14 @@ struct sPAPRTCETable {sPAPRTCETable *spapr_tce_find_by_liobn (target_ulong liobn); +struct rtas_error_log { +uint32_t summary; +uint32_t extended_length; +}QEMU_PACKED ; +struct sPAPREventLogEntry { -int log_type; -void *data; +struct rtas_error_log header; +void *extended_log;QTAILQ_ENTRY (sPAPREventLogEntry) next; };
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 05/18] spapr: Simplify unplug path
In reply to David Gibsonspapr_lmb_release() and spapr_core_release() call hotplug_handler_unplug() which after a bunch of indirection calls spapr_memory_unplug() or spapr_core_unplug(). But we already know which is the appropriate thing to call here, so we can just fold it directly into the release function.
Once that's done, there's no need for an hc->unplug method in the spapr machine at all: since we also have an hc->unplug_request method, the hotplug core will never use ->unplug.
--- hw/ppc/spapr.c | 56 ++++++++------------------------------------------------ 1 file changed, 8 insertions(+), 48 deletions(-)
hw/ppc/spapr.c +8 -48
@@ -2816,8 +2816,10 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_state(sPAPRMachineState *ms,/* Callback to be called during DRC release. */ void spapr_lmb_release (DeviceState *dev) { -HotplugHandler *hotplug_ctrl =qdev_get_hotplug_handler (dev); -sPAPRMachineState *spapr =SPAPR_MACHINE (hotplug_ctrl); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_hotplug_handler (dev)); +PCDIMMDevice *dimm =PC_DIMM (dev); +PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); +MemoryRegion *mr = ddc->get_memory_region (dimm);sPAPRDIMMState *ds =spapr_pending_dimm_unplugs_find (spapr,PC_DIMM (dev));/* This information will get lost if a migration occurs
@@ -2838,18 +2840,7 @@ void spapr_lmb_release(DeviceState *dev)* Now that all the LMBs have been removed by the guest, call the * pc-dimm unplug handler to cleanup up the pc-dimm device. */ -hotplug_handler_unplug (hotplug_ctrl, dev, &error_abort); -} - -static void spapr_memory_unplug (HotplugHandler *hotplug_dev,DeviceState *dev, -Error **errp) -{ -sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev); -PCDIMMDevice *dimm =PC_DIMM (dev); -PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); -MemoryRegion *mr = ddc->get_memory_region (dimm); - -pc_dimm_memory_unplug (dev, &ms->hotplug_memory, mr); +pc_dimm_memory_unplug (dev, &spapr->hotplug_memory, mr);object_unparent (OBJECT (dev)); }
@@ -2918,10 +2909,10 @@ static void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset,return fdt; } -static void spapr_core_unplug (HotplugHandler *hotplug_dev,DeviceState *dev, -Error **errp) +/* Callback to be called during DRC release. */ +void spapr_core_release (DeviceState *dev) { -MachineState *ms =MACHINE (qdev_get_machine ()); +MachineState *ms =MACHINE (qdev_get_hotplug_handler (dev));sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (ms);CPUCore *cc =CPU_CORE (dev);CPUArchId *core_slot =spapr_find_cpu_slot (ms, cc->core_id,NULL );
@@ -2945,15 +2936,6 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,object_unparent (OBJECT (dev)); } -/* Callback to be called during DRC release. */ -void spapr_core_release (DeviceState *dev) -{ -HotplugHandler *hotplug_ctrl; - - hotplug_ctrl =qdev_get_hotplug_handler (dev); -hotplug_handler_unplug (hotplug_ctrl, dev, &error_abort); -} -static void spapr_core_unplug_request (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp)
@@ -3159,27 +3141,6 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, } } -static void spapr_machine_device_unplug (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -sPAPRMachineState *sms =SPAPR_MACHINE (qdev_get_machine ()); -MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); - -if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -if (spapr_ovec_test (sms->ov5_cas,OV5_HP_EVT )) { -spapr_memory_unplug (hotplug_dev, dev, errp); - }else { -error_setg (errp,"Memory hot unplug not supported for this guest" ); - } - }else if (object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) { -if (!mc->has_hotpluggable_cpus) { -error_setg (errp,"CPU hot unplug not supported on this machine" ); -return ; - } -spapr_core_unplug (hotplug_dev, dev, errp); - } -} -static void spapr_machine_device_unplug_request (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -3397,7 +3358,6 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->get_hotplug_handler = spapr_get_hotplug_handler; hc->pre_plug = spapr_machine_device_pre_plug; hc->plug = spapr_machine_device_plug; - hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_instance_props = spapr_cpu_index_to_props; mc->possible_cpu_arch_ids = spapr_possible_cpu_arch_ids; hc->unplug_request = spapr_machine_device_unplug_request;
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 07/18] spapr: Refactor spapr_drc_detach()
In reply to David GibsonThis function has two unused parameters - remove them.
It also sets awaiting_release on all paths, except one. On that path setting it is harmless, since it will be immediately cleared by spapr_drc_release(). So factor it out of the if statements.
--- hw/ppc/spapr.c | 11 +++-------- hw/ppc/spapr_drc.c | 12 ++++++------ hw/ppc/spapr_pci.c | 7 +------ include/hw/ppc/spapr_drc.h | 2 +- 4 files changed, 11 insertions(+), 21 deletions(-)
hw/ppc/spapr.c +3 -8
@@ -2654,7 +2654,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size, addr -=SPAPR_MEMORY_BLOCK_SIZE ; drc =spapr_drc_by_id (TYPE_SPAPR_DRC_LMB , addr /SPAPR_MEMORY_BLOCK_SIZE ); -spapr_drc_detach (drc, dev,NULL ); +spapr_drc_detach (drc); }g_free (fdt);error_propagate (errp, local_err);
@@ -2876,7 +2876,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev, addr / SPAPR_MEMORY_BLOCK_SIZE);g_assert (drc); -spapr_drc_detach (drc, dev, errp); +spapr_drc_detach (drc); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }
@@ -2942,7 +2942,6 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, {int index;sPAPRDRConnector *drc; -Error *local_err =NULL ;CPUCore *cc =CPU_CORE (dev);int smt =kvmppc_smt_threads ();
@@ -2959,11 +2958,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, drc =spapr_drc_by_id (TYPE_SPAPR_DRC_CPU , index * smt);g_assert (drc); -spapr_drc_detach (drc, dev, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } +spapr_drc_detach (drc);spapr_hotplug_req_remove_by_index (drc); }
hw/ppc/spapr_drc.c +6 -6
@@ -70,7 +70,7 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *drc)uint32_t drc_index =spapr_drc_index (drc);if (drc->configured) {trace_spapr_drc_set_isolation_state_finalizing (drc_index); -spapr_drc_detach (drc,DEVICE (drc->dev),NULL ); +spapr_drc_detach (drc); }else {trace_spapr_drc_set_isolation_state_deferring (drc_index); }
@@ -134,7 +134,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *drc)uint32_t drc_index =spapr_drc_index (drc);if (drc->configured) {trace_spapr_drc_set_isolation_state_finalizing (drc_index); -spapr_drc_detach (drc,DEVICE (drc->dev),NULL ); +spapr_drc_detach (drc); }else {trace_spapr_drc_set_isolation_state_deferring (drc_index); }
@@ -187,7 +187,7 @@ static uint32_t drc_set_unusable(sPAPRDRConnector *drc)if (drc->awaiting_release) {uint32_t drc_index =spapr_drc_index (drc);trace_spapr_drc_set_allocation_state_finalizing (drc_index); -spapr_drc_detach (drc,DEVICE (drc->dev),NULL ); +spapr_drc_detach (drc); }return RTAS_OUT_SUCCESS ;
@@ -371,20 +371,20 @@ static void spapr_drc_release(sPAPRDRConnector *drc) drc->dev =NULL ; } -void spapr_drc_detach (sPAPRDRConnector *drc,DeviceState *d,Error **errp) +void spapr_drc_detach (sPAPRDRConnector *drc) {trace_spapr_drc_detach (spapr_drc_index (drc)); + drc->awaiting_release = true; +if (drc->isolation_state !=SPAPR_DR_ISOLATION_STATE_ISOLATED ) {trace_spapr_drc_awaiting_isolated (spapr_drc_index (drc)); - drc->awaiting_release = true;return ; }if (spapr_drc_type (drc) !=SPAPR_DR_CONNECTOR_TYPE_PCI && drc->allocation_state !=SPAPR_DR_ALLOCATION_STATE_UNUSABLE ) {trace_spapr_drc_awaiting_unusable (spapr_drc_index (drc)); - drc->awaiting_release = true;return ; }
hw/ppc/spapr_pci.c +1 -6
@@ -1478,7 +1478,6 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,PCIDevice *pdev =PCI_DEVICE (plugged_dev);sPAPRDRConnectorClass *drck;sPAPRDRConnector *drc =spapr_phb_get_pci_drc (phb, pdev); -Error *local_err =NULL ;if (!phb->dr_enabled) { error_setg(errp, QERR_BUS_NO_HOTPLUG,
@@ -1516,11 +1515,7 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, } } -spapr_drc_detach (drc,DEVICE (pdev), &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } +spapr_drc_detach (drc);/* if this isn't func 0, defer unplug event. otherwise signal removal * for all present functions
include/hw/ppc/spapr_drc.h +1 -1
@@ -242,6 +242,6 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,void spapr_drc_attach (sPAPRDRConnector *drc,DeviceState *d,void *fdt,int fdt_start_offset,Error **errp); -void spapr_drc_detach (sPAPRDRConnector *drc,DeviceState *d,Error **errp); +void spapr_drc_detach (sPAPRDRConnector *drc);#endif /* HW_SPAPR_DRC_H */
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 08/18] spapr: Cleanups relating to DRC awaiting_release field
In reply to David Gibson'awaiting_release' indicates that the host has requested an unplug of the device attached to the DRC, but the guest has not (yet) put the device into a state where it is safe to complete removal.
1. Rename it to 'unplug_requested' which to me at least is clearer
2. Remove the ->release_pending() method used to check this from outside spapr_drc.c. The method only plausibly has one implementation, so use a plain function (spapr_drc_unplug_requested()) instead.
3. Remove it from the migration stream. Attempting to migrate mid-unplug is broken not just for spapr - in general management has no good way to determine if the device should be present on the destination or not. So, until that's fixed, there's no point adding extra things to the stream.
--- hw/ppc/spapr_drc.c | 26 +++++++++----------------- hw/ppc/spapr_pci.c | 6 ++---- include/hw/ppc/spapr_drc.h | 11 ++++++----- 3 files changed, 17 insertions(+), 26 deletions(-)
hw/ppc/spapr_drc.c +9 -17
@@ -66,7 +66,7 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *drc)* configured state, as suggested by the state diagram from PAPR+ * 2.7, 13.4 */ -if (drc->awaiting_release) { +if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);if (drc->configured) {trace_spapr_drc_set_isolation_state_finalizing (drc_index);
@@ -116,7 +116,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *drc)* actually being unplugged, fail the isolation request here. */ if (spapr_drc_type (drc) ==SPAPR_DR_CONNECTOR_TYPE_LMB - && !drc->awaiting_release) { + && !drc->unplug_requested) {return RTAS_OUT_HW_ERROR ; }
@@ -130,7 +130,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *drc)* configured state, as suggested by the state diagram from PAPR+ * 2.7, 13.4 */ -if (drc->awaiting_release) { +if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);if (drc->configured) {trace_spapr_drc_set_isolation_state_finalizing (drc_index);
@@ -170,7 +170,7 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc)if (!drc->dev) {return RTAS_OUT_NO_SUCH_INDICATOR ; } -if (drc->awaiting_release) { +if (drc->unplug_requested) {/* Don't allow the guest to move a device away from UNUSABLE * state when we want to unplug it */ return RTAS_OUT_NO_SUCH_INDICATOR ;
@@ -184,7 +184,7 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc)static uint32_t drc_set_unusable (sPAPRDRConnector *drc) { drc->allocation_state =SPAPR_DR_ALLOCATION_STATE_UNUSABLE ; -if (drc->awaiting_release) { +if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);trace_spapr_drc_set_allocation_state_finalizing (drc_index);spapr_drc_detach (drc);
@@ -363,7 +363,7 @@ static void spapr_drc_release(sPAPRDRConnector *drc) drck->release (drc->dev); - drc->awaiting_release = false; + drc->unplug_requested = false;g_free (drc->fdt); drc->fdt =NULL ; drc->fdt_start_offset =0 ;
@@ -375,7 +375,7 @@ void spapr_drc_detach(sPAPRDRConnector *drc) {trace_spapr_drc_detach (spapr_drc_index (drc)); - drc->awaiting_release = true; + drc->unplug_requested = true;if (drc->isolation_state !=SPAPR_DR_ISOLATION_STATE_ISOLATED ) {trace_spapr_drc_awaiting_isolated (spapr_drc_index (drc));
@@ -391,11 +391,6 @@ void spapr_drc_detach(sPAPRDRConnector *drc)spapr_drc_release (drc); } -static bool release_pending (sPAPRDRConnector *drc) -{ -return drc->awaiting_release; -} -void spapr_drc_reset (sPAPRDRConnector *drc) {trace_spapr_drc_reset (spapr_drc_index (drc));
@@ -406,7 +401,7 @@ void spapr_drc_reset(sPAPRDRConnector *drc)/* immediately upon reset we can safely assume DRCs whose devices * are pending removal can be safely removed. */ -if (drc->awaiting_release) { +if (drc->unplug_requested) {spapr_drc_release (drc); }
@@ -454,7 +449,7 @@ static bool spapr_drc_needed(void *opaque)case SPAPR_DR_CONNECTOR_TYPE_LMB : rc = !((drc->isolation_state ==SPAPR_DR_ISOLATION_STATE_UNISOLATED ) && (drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_USABLE ) && - drc->configured && !drc->awaiting_release); + drc->configured);break ;case SPAPR_DR_CONNECTOR_TYPE_PHB :case SPAPR_DR_CONNECTOR_TYPE_VIO :
@@ -474,7 +469,6 @@ static const VMStateDescription vmstate_spapr_drc = {VMSTATE_UINT32 (allocation_state, sPAPRDRConnector),VMSTATE_UINT32 (dr_indicator, sPAPRDRConnector),VMSTATE_BOOL (configured, sPAPRDRConnector), -VMSTATE_BOOL (awaiting_release, sPAPRDRConnector), VMSTATE_END_OF_LIST() } };
@@ -565,11 +559,9 @@ static void spapr_dr_connector_instance_init(Object *obj)static void spapr_dr_connector_class_init (ObjectClass *k,void *data) {DeviceClass *dk =DEVICE_CLASS (k); -sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_CLASS (k); dk->realize = realize; dk->unrealize = unrealize; - drck->release_pending = release_pending;/* * Reason: it crashes FIXME find and document the real reason */
hw/ppc/spapr_pci.c +2 -4
@@ -1476,7 +1476,6 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, {sPAPRPHBState *phb =SPAPR_PCI_HOST_BRIDGE (DEVICE (plug_handler));PCIDevice *pdev =PCI_DEVICE (plugged_dev); -sPAPRDRConnectorClass *drck;sPAPRDRConnector *drc =spapr_phb_get_pci_drc (phb, pdev);if (!phb->dr_enabled) {
@@ -1488,8 +1487,7 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,g_assert (drc);g_assert (drc->dev == plugged_dev); - drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); -if (!drck->release_pending (drc)) { +if (!spapr_drc_unplug_requested (drc)) {PCIBus *bus =PCI_BUS (qdev_get_parent_bus (DEVICE (pdev)));uint32_t slotnr =PCI_SLOT (pdev->devfn);sPAPRDRConnector *func_drc;
@@ -1505,7 +1503,7 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, func_drck =SPAPR_DR_CONNECTOR_GET_CLASS (func_drc); state = func_drck->dr_entity_sense (func_drc);if (state ==SPAPR_DR_ENTITY_SENSE_PRESENT - && !func_drck->release_pending (func_drc)) { + && !spapr_drc_unplug_requested (func_drc)) { error_setg(errp, "PCI: slot %d, function %d still present. " "Must unplug all non-0 functions first.",
include/hw/ppc/spapr_drc.h +6 -5
@@ -199,10 +199,9 @@ typedef struct sPAPRDRConnector {bool configured;sPAPRConfigureConnectorState *ccs; -bool awaiting_release; -/* device pointer, via link property */ DeviceState *dev; +bool unplug_requested; } sPAPRDRConnector; typedef struct sPAPRDRConnectorClass {
@@ -218,9 +217,6 @@ typedef struct sPAPRDRConnectorClass {uint32_t (*isolate)(sPAPRDRConnector *drc);uint32_t (*unisolate)(sPAPRDRConnector *drc);void (*release)(DeviceState *dev); - -/* QEMU interfaces for managing hotplug operations */ -bool (*release_pending)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass;static inline bool spapr_drc_hotplugged (DeviceState *dev)
@@ -244,4 +240,9 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, int fdt_start_offset, Error **errp);void spapr_drc_detach (sPAPRDRConnector *drc); +static inline bool spapr_drc_unplug_requested (sPAPRDRConnector *drc) +{ +return drc->unplug_requested; +} +#endif /* HW_SPAPR_DRC_H */
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 10/18] spapr: Remove sPAPRConfigureConnectorState sub-structure
In reply to David GibsonMost of the time, the state of a DRC object is contained in the single 'state' variable. However, during the transition from UNISOLATE to CONFIGURED state requires multiple calls to the ibm,configure-connector RTAS call to retrieve the device tree for the attached device. We need some extra state to keep track of where we're up to in delivering the device tree information to the guest.
Currently that extra state is in a sPAPRConfigureConnectorState substructure which is only allocated when we're in the middle of the configure connector process. That sounds like a good idea, but the extra state is only two integers - on many platforms that will take up the same room as the (maybe NULL) ccs pointer even before malloc() overhead. Plus it's another object whose lifetime we need to manage. In short, it's not worth it.
So, fold the sPAPRConfigureConnectorState substructure directly into the DRC object.
Previously the structure was allocated lazily when the configure-connector call discovers it's not there. Now, we need to initialize the subfields pre-emptively, as soon as we enter UNISOLATE state.
Although it's not strictly necessary (the field values should only ever be consulted when in UNISOLATE state), we try to keep them at -1 when in other states, as a debugging aid.
--- hw/ppc/spapr_drc.c | 56 +++++++++++++++------------------------------- include/hw/ppc/spapr_drc.h | 16 +++++-------- 2 files changed, 24 insertions(+), 48 deletions(-)
hw/ppc/spapr_drc.c +18 -38
@@ -59,14 +59,6 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *drc)g_assert_not_reached (); } -/* if the guest is configuring a device attached to this DRC, we -* should reset the configuration state at this point since it may -* no longer be reliable (guest released device and needs to start -* over, or unplug occurred so the FDT is no longer valid) -*/ -g_free (drc->ccs); - drc->ccs =NULL ; - drc->state =SPAPR_DRC_STATE_PHYSICAL_POWERON ;if (drc->unplug_requested) {
@@ -99,6 +91,8 @@ static uint32_t drc_unisolate_physical(sPAPRDRConnector *drc) } drc->state =SPAPR_DRC_STATE_PHYSICAL_UNISOLATE ; + drc->ccs_offset = drc->fdt_start_offset; + drc->ccs_depth =0 ;return RTAS_OUT_SUCCESS ; }
@@ -117,14 +111,6 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *drc)g_assert_not_reached (); } -/* if the guest is configuring a device attached to this DRC, we -* should reset the configuration state at this point since it may -* no longer be reliable (guest released device and needs to start -* over, or unplug occurred so the FDT is no longer valid) -*/ -g_free (drc->ccs); - drc->ccs =NULL ; -/* * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't * belong to a DIMM device that is marked for removal.
@@ -176,6 +162,9 @@ static uint32_t drc_unisolate_logical(sPAPRDRConnector *drc)g_assert (drc->dev); drc->state =SPAPR_DRC_STATE_LOGICAL_UNISOLATE ; + drc->ccs_offset = drc->fdt_start_offset; + drc->ccs_depth =0 ; +return RTAS_OUT_SUCCESS ; }
@@ -441,9 +430,6 @@ void spapr_drc_reset(sPAPRDRConnector *drc)trace_spapr_drc_reset (spapr_drc_index (drc)); -g_free (drc->ccs); - drc->ccs =NULL ; -/* immediately upon reset we can safely assume DRCs whose devices * are pending removal can be safely removed. */
@@ -457,6 +443,9 @@ void spapr_drc_reset(sPAPRDRConnector *drc) }else { drc->state = drck->empty_state; } + + drc->ccs_offset =-1 ; + drc->ccs_depth =-1 ; }static void drc_reset (void *opaque)
@@ -1010,7 +999,6 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,uint32_t drc_index;sPAPRDRConnector *drc;sPAPRDRConnectorClass *drck; -sPAPRConfigureConnectorState *ccs;sPAPRDRCCResponse resp =SPAPR_DR_CC_RESPONSE_CONTINUE ;int rc;
@@ -1040,25 +1028,18 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu, drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - ccs = drc->ccs; -if (!ccs) { - ccs =g_new0 (sPAPRConfigureConnectorState,1 ); - ccs->fdt_offset = drc->fdt_start_offset; - drc->ccs = ccs; - } - do { uint32_t tag; const char *name; const struct fdt_property *prop; int fdt_offset_next, prop_len; - tag = fdt_next_tag(drc->fdt, ccs->fdt_offset, &fdt_offset_next); + tag = fdt_next_tag(drc->fdt, drc->ccs_offset, &fdt_offset_next); switch (tag) { case FDT_BEGIN_NODE: - ccs->fdt_depth++; - name = fdt_get_name(drc->fdt, ccs->fdt_offset, NULL); + drc->ccs_depth++; + name = fdt_get_name(drc->fdt, drc->ccs_offset, NULL); /* provide the name of the next OF node */ wa_offset = CC_VAL_DATA_OFFSET;
@@ -1067,23 +1048,22 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu, resp =SPAPR_DR_CC_RESPONSE_NEXT_CHILD ;break ;case FDT_END_NODE : - ccs->fdt_depth--; -if (ccs->fdt_depth ==0 ) { + drc->ccs_depth--; +if (drc->ccs_depth ==0 ) {uint32_t drc_index =spapr_drc_index (drc);/* done sending the device tree, move to configured state */ trace_spapr_drc_set_configured (drc_index); drc->state = drck->ready_state; -g_free (ccs); - drc->ccs =NULL ; - ccs =NULL ; + drc->ccs_offset =-1 ; + drc->ccs_depth =-1 ; resp =SPAPR_DR_CC_RESPONSE_SUCCESS ; }else { resp =SPAPR_DR_CC_RESPONSE_PREV_PARENT ; }break ;case FDT_PROP : - prop =fdt_get_property_by_offset (drc->fdt, ccs->fdt_offset, + prop =fdt_get_property_by_offset (drc->fdt, drc->ccs_offset, &prop_len); name =fdt_string (drc->fdt,fdt32_to_cpu (prop->nameoff));
@@ -1108,8 +1088,8 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,/* keep seeking for an actionable tag */ break ; } -if (ccs) { - ccs->fdt_offset = fdt_offset_next; +if (drc->ccs_offset >=0 ) { + drc->ccs_offset = fdt_offset_next; } }while (resp ==SPAPR_DR_CC_RESPONSE_CONTINUE );
include/hw/ppc/spapr_drc.h +6 -10
@@ -191,12 +191,6 @@ typedef enum {SPAPR_DRC_STATE_PHYSICAL_CONFIGURED =8 , } sPAPRDRCState; -/* rtas-configure-connector state */ -typedef struct sPAPRConfigureConnectorState { -int fdt_offset; -int fdt_depth; -}sPAPRConfigureConnectorState ; - typedef struct sPAPRDRConnector { /*< private >*/ DeviceState parent;
@@ -209,14 +203,16 @@ typedef struct sPAPRDRConnector {uint32_t state; -/* configure-connector state */ -void *fdt; -int fdt_start_offset; -sPAPRConfigureConnectorState *ccs; +/* RTAS ibm,configure-connector state */ +/* (only valid in UNISOLATE state) */ +int ccs_offset; +int ccs_depth;/* device pointer, via link property */ DeviceState *dev;bool unplug_requested; +void *fdt; +int fdt_start_offset; } sPAPRDRConnector; typedef struct sPAPRDRConnectorClass {
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 13/18] ppc/pnv: Remove unused XICSState reference
In reply to David GibsonFrom: Alexey Kardashevskiy <[email protected]>
e6f7e110ee70 "ppc/xics: remove the XICSState classes" got rid of XICSState, this is just an leftover.
--- include/hw/ppc/pnv_psi.h | 2 -- 1 file changed, 2 deletions(-)
include/hw/ppc/pnv_psi.h +0 -2
@@ -28,8 +28,6 @@#define PSIHB_XSCOM_MAX 0x20 -typedef struct XICSState XICSState ; - typedef struct PnvPsi { SysBusDevice parent;
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 16/18] 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
@@ -3433,7 +3433,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;
@@ -3540,6 +3540,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.13.0
[Qemu-devel] [PULL 18/18] 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.13.0
[Qemu-devel] [PULL 11/18] spapr: Implement DR-indicator for physical DRCs only
In reply to David GibsonAccording to PAPR, the DR-indicator should only be valid for physical DRCs, not logical DRCs. At the moment we implement it for all DRCs, so restrict it to physical ones only.
We move the state to the physical DRC subclass, which means adding some QOM boilerplate to handle the newly distinct type.
--- hw/ppc/spapr_drc.c | 68 ++++++++++++++++++++++++++++++++++++++++++---- include/hw/ppc/spapr_drc.h | 13 ++++++--- 2 files changed, 72 insertions(+), 9 deletions(-)
hw/ppc/spapr_drc.c +63 -5
@@ -478,7 +478,6 @@ static const VMStateDescription vmstate_spapr_drc = { .needed = spapr_drc_needed, .fields = (VMStateField []) {VMSTATE_UINT32 (state, sPAPRDRConnector), -VMSTATE_UINT32 (dr_indicator, sPAPRDRConnector),VMSTATE_END_OF_LIST () } };
@@ -575,10 +574,63 @@ static void spapr_dr_connector_class_init(ObjectClass *k, void *data) dk->user_creatable = false; } +static bool drc_physical_needed (void *opaque) +{ +sPAPRDRCPhysical *drcp = (sPAPRDRCPhysical *)opaque; +sPAPRDRConnector *drc =SPAPR_DR_CONNECTOR (drcp); + +if ((drc->dev && (drcp->dr_indicator ==SPAPR_DR_INDICATOR_ACTIVE )) + || (!drc->dev && (drcp->dr_indicator ==SPAPR_DR_INDICATOR_INACTIVE ))) { +return false; + } +return true; +} + +static const VMStateDescription vmstate_spapr_drc_physical = { + .name ="spapr_drc" , + .version_id =1 , + .minimum_version_id =1 , + .needed = drc_physical_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32 (dr_indicator, sPAPRDRCPhysical), +VMSTATE_END_OF_LIST () + } +}; + +static void drc_physical_reset (void *opaque) +{ +sPAPRDRConnector *drc =SPAPR_DR_CONNECTOR (opaque); +sPAPRDRCPhysical *drcp =SPAPR_DRC_PHYSICAL (drc); + +if (drc->dev) { + drcp->dr_indicator =SPAPR_DR_INDICATOR_ACTIVE ; + }else { + drcp->dr_indicator =SPAPR_DR_INDICATOR_INACTIVE ; + } +} + +static void realize_physical (DeviceState *d,Error **errp) +{ +sPAPRDRCPhysical *drcp =SPAPR_DRC_PHYSICAL (d); +Error *local_err =NULL ; + +realize (d, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +vmstate_register (DEVICE (drcp),spapr_drc_index (SPAPR_DR_CONNECTOR (drcp)), + &vmstate_spapr_drc_physical, drcp); +qemu_register_reset (drc_physical_reset, drcp); +} +static void spapr_drc_physical_class_init (ObjectClass *k,void *data) { +DeviceClass *dk =DEVICE_CLASS (k);sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_CLASS (k); + dk->realize = realize_physical; drck->dr_entity_sense = physical_entity_sense; drck->isolate = drc_isolate_physical; drck->unisolate = drc_unisolate_physical;
@@ -640,7 +692,7 @@ static const TypeInfo spapr_dr_connector_info = {static const TypeInfo spapr_drc_physical_info = { .name =TYPE_SPAPR_DRC_PHYSICAL , .parent =TYPE_SPAPR_DR_CONNECTOR , - .instance_size =sizeof (sPAPRDRConnector), + .instance_size =sizeof (sPAPRDRCPhysical), .class_init = spapr_drc_physical_class_init, .abstract = true, };
@@ -883,12 +935,18 @@ static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state) {sPAPRDRConnector *drc =spapr_drc_by_index (idx); -if (!drc) { -return RTAS_OUT_PARAM_ERROR ; +if (!drc || !object_dynamic_cast (OBJECT (drc),TYPE_SPAPR_DRC_PHYSICAL )) { +return RTAS_OUT_NO_SUCH_INDICATOR ; + } +if ((state !=SPAPR_DR_INDICATOR_INACTIVE ) + && (state !=SPAPR_DR_INDICATOR_ACTIVE ) + && (state !=SPAPR_DR_INDICATOR_IDENTIFY ) + && (state !=SPAPR_DR_INDICATOR_ACTION )) { +return RTAS_OUT_PARAM_ERROR ;/* bad state parameter */ }trace_spapr_drc_set_dr_indicator (idx, state); - drc->dr_indicator = state; +SPAPR_DRC_PHYSICAL (drc)->dr_indicator = state;return RTAS_OUT_SUCCESS ; }
include/hw/ppc/spapr_drc.h +9 -4
@@ -33,7 +33,7 @@#define SPAPR_DRC_PHYSICAL_CLASS (klass) \ OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \ TYPE_SPAPR_DRC_PHYSICAL) -#define SPAPR_DRC_PHYSICAL (obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ +#define SPAPR_DRC_PHYSICAL (obj) OBJECT_CHECK(sPAPRDRCPhysical, (obj), \ TYPE_SPAPR_DRC_PHYSICAL)#define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical"
@@ -198,9 +198,6 @@ typedef struct sPAPRDRConnector {uint32_t id;Object *owner; -/* DR-indicator */ -uint32_t dr_indicator; -uint32_t state;/* RTAS ibm,configure-connector state */
@@ -232,6 +229,14 @@ typedef struct sPAPRDRConnectorClass {void (*release)(DeviceState *dev); } sPAPRDRConnectorClass; +typedef struct sPAPRDRCPhysical { +/*< private >*/ +sPAPRDRConnector parent; + +/* DR-indicator */ +uint32_t dr_indicator; +}sPAPRDRCPhysical ; +static inline bool spapr_drc_hotplugged (DeviceState *dev) {return dev->hotplugged && !runstate_check (RUN_STATE_INMIGRATE );
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 09/18] spapr: Consolidate DRC state variables
In reply to David GibsonEach DRC has three fields describing its state: isolation_state, allocation_state and configured. At first this seems like a reasonable representation, since its based directly on the PAPR defined isolation-state and allocation-state indicators. However:
* Only a few combinations of the two fields' values are permitted
* allocation_state isn't used at all for physical DRCs
* The indicators are write only so they don't really have a well defined current value independent of each other
This replaces these variables with a single state variable, whose names and numbers are based on the diagram in LoPAPR section 13.4. Along with this we add code to check the current state on various operations and make sure the requested transition is permitted.
Strictly speaking, this makes guest visible changes to behaviour (since we probably allowed some transitions we shouldn't have before). However, a hypothetical guest broken by that wasn't PAPR compliant, and probably wouldn't have worked under PowerVM.
--- hw/ppc/spapr_drc.c | 225 +++++++++++++++++++++++++-------------------- hw/ppc/trace-events | 3 +- include/hw/ppc/spapr_drc.h | 25 ++++- 3 files changed, 145 insertions(+), 108 deletions(-)
hw/ppc/spapr_drc.c +123 -102
@@ -48,6 +48,17 @@ uint32_t spapr_drc_index(sPAPRDRConnector *drc)static uint32_t drc_isolate_physical (sPAPRDRConnector *drc) { +switch (drc->state) { +case SPAPR_DRC_STATE_PHYSICAL_POWERON : +return RTAS_OUT_SUCCESS ;/* Nothing to do */ +case SPAPR_DRC_STATE_PHYSICAL_CONFIGURED : +break ;/* see below */ +case SPAPR_DRC_STATE_PHYSICAL_UNISOLATE : +return RTAS_OUT_PARAM_ERROR ;/* not allowed */ +default : +g_assert_not_reached (); + } +/* if the guest is configuring a device attached to this DRC, we * should reset the configuration state at this point since it may * no longer be reliable (guest released device and needs to start
@@ -56,32 +67,29 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *drc)g_free (drc->ccs); drc->ccs =NULL ; - drc->isolation_state =SPAPR_DR_ISOLATION_STATE_ISOLATED ; + drc->state =SPAPR_DRC_STATE_PHYSICAL_POWERON ; -/* if we're awaiting release, but still in an unconfigured state, -* it's likely the guest is still in the process of configuring -* the device and is transitioning the devices to an ISOLATED -* state as a part of that process. so we only complete the -* removal when this transition happens for a device in a -* configured state, as suggested by the state diagram from PAPR+ -* 2.7, 13.4 -*/ if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc); -if (drc->configured) { -trace_spapr_drc_set_isolation_state_finalizing (drc_index); -spapr_drc_detach (drc); - }else { -trace_spapr_drc_set_isolation_state_deferring (drc_index); - } +trace_spapr_drc_set_isolation_state_finalizing (drc_index); +spapr_drc_detach (drc); } - drc->configured = false;return RTAS_OUT_SUCCESS ; }static uint32_t drc_unisolate_physical (sPAPRDRConnector *drc) { +switch (drc->state) { +case SPAPR_DRC_STATE_PHYSICAL_UNISOLATE : +case SPAPR_DRC_STATE_PHYSICAL_CONFIGURED : +return RTAS_OUT_SUCCESS ;/* Nothing to do */ +case SPAPR_DRC_STATE_PHYSICAL_POWERON : +break ;/* see below */ +default : +g_assert_not_reached (); + } +/* cannot unisolate a non-existent resource, and, or resources * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, * 13.5.3.5)
@@ -90,13 +98,25 @@ static uint32_t drc_unisolate_physical(sPAPRDRConnector *drc)return RTAS_OUT_NO_SUCH_INDICATOR ; } - drc->isolation_state =SPAPR_DR_ISOLATION_STATE_UNISOLATED ; + drc->state =SPAPR_DRC_STATE_PHYSICAL_UNISOLATE ;return RTAS_OUT_SUCCESS ; }static uint32_t drc_isolate_logical (sPAPRDRConnector *drc) { +switch (drc->state) { +case SPAPR_DRC_STATE_LOGICAL_AVAILABLE : +case SPAPR_DRC_STATE_LOGICAL_UNUSABLE : +return RTAS_OUT_SUCCESS ;/* Nothing to do */ +case SPAPR_DRC_STATE_LOGICAL_CONFIGURED : +break ;/* see below */ +case SPAPR_DRC_STATE_LOGICAL_UNISOLATE : +return RTAS_OUT_PARAM_ERROR ;/* not allowed */ +default : +g_assert_not_reached (); + } +/* if the guest is configuring a device attached to this DRC, we * should reset the configuration state at this point since it may * no longer be reliable (guest released device and needs to start
@@ -120,7 +140,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *drc)return RTAS_OUT_HW_ERROR ; } - drc->isolation_state =SPAPR_DR_ISOLATION_STATE_ISOLATED ; + drc->state =SPAPR_DRC_STATE_LOGICAL_AVAILABLE ;/* if we're awaiting release, but still in an unconfigured state, * it's likely the guest is still in the process of configuring
@@ -132,36 +152,46 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *drc)*/ if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc); -if (drc->configured) { -trace_spapr_drc_set_isolation_state_finalizing (drc_index); -spapr_drc_detach (drc); - }else { -trace_spapr_drc_set_isolation_state_deferring (drc_index); - } +trace_spapr_drc_set_isolation_state_finalizing (drc_index); +spapr_drc_detach (drc); } - drc->configured = false; -return RTAS_OUT_SUCCESS ; }static uint32_t drc_unisolate_logical (sPAPRDRConnector *drc) { -/* cannot unisolate a non-existent resource, and, or resources -* which are in an 'UNUSABLE' allocation state. (PAPR 2.7, -* 13.5.3.5) -*/ -if (!drc->dev || - drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_UNUSABLE ) { -return RTAS_OUT_NO_SUCH_INDICATOR ; +switch (drc->state) { +case SPAPR_DRC_STATE_LOGICAL_UNISOLATE : +case SPAPR_DRC_STATE_LOGICAL_CONFIGURED : +return RTAS_OUT_SUCCESS ;/* Nothing to do */ +case SPAPR_DRC_STATE_LOGICAL_AVAILABLE : +break ;/* see below */ +case SPAPR_DRC_STATE_LOGICAL_UNUSABLE : +return RTAS_OUT_NO_SUCH_INDICATOR ;/* not allowed */ +default : +g_assert_not_reached (); } - drc->isolation_state =SPAPR_DR_ISOLATION_STATE_UNISOLATED ; +/* Move to AVAILABLE state should have ensured device was present */ +g_assert (drc->dev); + drc->state =SPAPR_DRC_STATE_LOGICAL_UNISOLATE ;return RTAS_OUT_SUCCESS ; }static uint32_t drc_set_usable (sPAPRDRConnector *drc) { +switch (drc->state) { +case SPAPR_DRC_STATE_LOGICAL_AVAILABLE : +case SPAPR_DRC_STATE_LOGICAL_UNISOLATE : +case SPAPR_DRC_STATE_LOGICAL_CONFIGURED : +return RTAS_OUT_SUCCESS ;/* Nothing to do */ +case SPAPR_DRC_STATE_LOGICAL_UNUSABLE : +break ;/* see below */ +default : +g_assert_not_reached (); + } +/* if there's no resource/device associated with the DRC, there's * no way for us to put it in an allocation state consistent with * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should
@@ -176,14 +206,26 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc)return RTAS_OUT_NO_SUCH_INDICATOR ; } - drc->allocation_state =SPAPR_DR_ALLOCATION_STATE_USABLE ; + drc->state =SPAPR_DRC_STATE_LOGICAL_AVAILABLE ;return RTAS_OUT_SUCCESS ; }static uint32_t drc_set_unusable (sPAPRDRConnector *drc) { - drc->allocation_state =SPAPR_DR_ALLOCATION_STATE_UNUSABLE ; +switch (drc->state) { +case SPAPR_DRC_STATE_LOGICAL_UNUSABLE : +return RTAS_OUT_SUCCESS ;/* Nothing to do */ +case SPAPR_DRC_STATE_LOGICAL_AVAILABLE : +break ;/* see below */ +case SPAPR_DRC_STATE_LOGICAL_UNISOLATE : +case SPAPR_DRC_STATE_LOGICAL_CONFIGURED : +return RTAS_OUT_NO_SUCH_INDICATOR ;/* not allowed */ +default : +g_assert_not_reached (); + } + + drc->state =SPAPR_DRC_STATE_LOGICAL_UNUSABLE ;if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);trace_spapr_drc_set_allocation_state_finalizing (drc_index);
@@ -241,11 +283,16 @@ static sPAPRDREntitySense physical_entity_sense(sPAPRDRConnector *drc)static sPAPRDREntitySense logical_entity_sense (sPAPRDRConnector *drc) { -if (drc->dev - && (drc->allocation_state !=SPAPR_DR_ALLOCATION_STATE_UNUSABLE )) { -return SPAPR_DR_ENTITY_SENSE_PRESENT ; - }else { +switch (drc->state) { +case SPAPR_DRC_STATE_LOGICAL_UNUSABLE :return SPAPR_DR_ENTITY_SENSE_UNUSABLE ; +case SPAPR_DRC_STATE_LOGICAL_AVAILABLE : +case SPAPR_DRC_STATE_LOGICAL_UNISOLATE : +case SPAPR_DRC_STATE_LOGICAL_CONFIGURED : +g_assert (drc->dev); +return SPAPR_DR_ENTITY_SENSE_PRESENT ; +default : +g_assert_not_reached (); } }
@@ -338,13 +385,12 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, {trace_spapr_drc_attach (spapr_drc_index (drc)); -if (drc->isolation_state !=SPAPR_DR_ISOLATION_STATE_ISOLATED ) { +if (drc->dev) {error_setg (errp,"an attached device is still awaiting release" );return ; } -if (spapr_drc_type (drc) ==SPAPR_DR_CONNECTOR_TYPE_PCI ) { -g_assert (drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_USABLE ); - } +g_assert ((drc->state ==SPAPR_DRC_STATE_LOGICAL_UNUSABLE ) + || (drc->state ==SPAPR_DRC_STATE_PHYSICAL_POWERON ));g_assert (fdt); drc->dev = d;
@@ -373,18 +419,16 @@ static void spapr_drc_release(sPAPRDRConnector *drc)void spapr_drc_detach (sPAPRDRConnector *drc) { +sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); +trace_spapr_drc_detach (spapr_drc_index (drc)); - drc->unplug_requested = true; +g_assert (drc->dev); -if (drc->isolation_state !=SPAPR_DR_ISOLATION_STATE_ISOLATED ) { -trace_spapr_drc_awaiting_isolated (spapr_drc_index (drc)); -return ; - } + drc->unplug_requested = true; -if (spapr_drc_type (drc) !=SPAPR_DR_CONNECTOR_TYPE_PCI && - drc->allocation_state !=SPAPR_DR_ALLOCATION_STATE_UNUSABLE ) { -trace_spapr_drc_awaiting_unusable (spapr_drc_index (drc)); +if (drc->state != drck->empty_state) { +trace_spapr_drc_awaiting_quiesce (spapr_drc_index (drc));return ; }
@@ -393,6 +437,8 @@ void spapr_drc_detach(sPAPRDRConnector *drc)void spapr_drc_reset (sPAPRDRConnector *drc) { +sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); +trace_spapr_drc_reset (spapr_drc_index (drc));g_free (drc->ccs);
@@ -406,19 +452,10 @@ void spapr_drc_reset(sPAPRDRConnector *drc) }if (drc->dev) { -/* A device present at reset is coldplugged */ - drc->isolation_state =SPAPR_DR_ISOLATION_STATE_UNISOLATED ; -if (spapr_drc_type (drc) !=SPAPR_DR_CONNECTOR_TYPE_PCI ) { - drc->allocation_state =SPAPR_DR_ALLOCATION_STATE_USABLE ; - } - drc->dr_indicator =SPAPR_DR_INDICATOR_ACTIVE ; +/* A device present at reset is ready to go, same as coldplugged */ + drc->state = drck->ready_state; }else { -/* Otherwise device is absent, but might be hotplugged */ - drc->isolation_state =SPAPR_DR_ISOLATION_STATE_ISOLATED ; -if (spapr_drc_type (drc) !=SPAPR_DR_CONNECTOR_TYPE_PCI ) { - drc->allocation_state =SPAPR_DR_ALLOCATION_STATE_UNUSABLE ; - } - drc->dr_indicator =SPAPR_DR_INDICATOR_INACTIVE ; + drc->state = drck->empty_state; } }
@@ -431,7 +468,6 @@ static bool spapr_drc_needed(void *opaque) {sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque;sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); -bool rc = false;sPAPRDREntitySense value = drck->dr_entity_sense (drc);/* If no dev is plugged in there is no need to migrate the DRC state */
@@ -440,23 +476,10 @@ static bool spapr_drc_needed(void *opaque) }/* -* If there is dev plugged in, we need to migrate the DRC state when -* it is different from cold-plugged state -*/ -switch (spapr_drc_type (drc)) { -case SPAPR_DR_CONNECTOR_TYPE_PCI : -case SPAPR_DR_CONNECTOR_TYPE_CPU : -case SPAPR_DR_CONNECTOR_TYPE_LMB : - rc = !((drc->isolation_state ==SPAPR_DR_ISOLATION_STATE_UNISOLATED ) && - (drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_USABLE ) && - drc->configured); -break ; -case SPAPR_DR_CONNECTOR_TYPE_PHB : -case SPAPR_DR_CONNECTOR_TYPE_VIO : -default : -g_assert_not_reached (); - } -return rc; +* We need to migrate the state if it's not equal to the expected +* long-term state, which is the same as the coldplugged initial +* state */ +return (drc->state != drck->ready_state); }static const VMStateDescription vmstate_spapr_drc = {
@@ -465,10 +488,8 @@ static const VMStateDescription vmstate_spapr_drc = { .minimum_version_id = 1, .needed = spapr_drc_needed, .fields = (VMStateField []) { -VMSTATE_UINT32 (isolation_state, sPAPRDRConnector), -VMSTATE_UINT32 (allocation_state, sPAPRDRConnector), +VMSTATE_UINT32 (state, sPAPRDRConnector),VMSTATE_UINT32 (dr_indicator, sPAPRDRConnector), -VMSTATE_BOOL (configured, sPAPRDRConnector),VMSTATE_END_OF_LIST () } };
@@ -537,23 +558,20 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type,object_property_set_bool (OBJECT (drc), true,"realized" ,NULL );g_free (prop_name); -/* PCI slot always start in a USABLE state, and stay there */ -if (spapr_drc_type (drc) ==SPAPR_DR_CONNECTOR_TYPE_PCI ) { - drc->allocation_state =SPAPR_DR_ALLOCATION_STATE_USABLE ; - } -return drc; }static void spapr_dr_connector_instance_init (Object *obj) {sPAPRDRConnector *drc =SPAPR_DR_CONNECTOR (obj); +sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc);object_property_add_uint32_ptr (obj,"id" , &drc->id,NULL );object_property_add (obj,"index" ,"uint32" , prop_get_index,NULL ,NULL ,NULL ,NULL );object_property_add (obj,"fdt" ,"struct" , prop_get_fdt,NULL ,NULL ,NULL ,NULL ); + drc->state = drck->empty_state; }static void spapr_dr_connector_class_init (ObjectClass *k,void *data)
@@ -575,6 +593,8 @@ static void spapr_drc_physical_class_init(ObjectClass *k, void *data) drck->dr_entity_sense = physical_entity_sense; drck->isolate = drc_isolate_physical; drck->unisolate = drc_unisolate_physical; + drck->ready_state =SPAPR_DRC_STATE_PHYSICAL_CONFIGURED ; + drck->empty_state =SPAPR_DRC_STATE_PHYSICAL_POWERON ; }static void spapr_drc_logical_class_init (ObjectClass *k,void *data)
@@ -584,6 +604,8 @@ static void spapr_drc_logical_class_init(ObjectClass *k, void *data) drck->dr_entity_sense = logical_entity_sense; drck->isolate = drc_isolate_logical; drck->unisolate = drc_unisolate_logical; + drck->ready_state =SPAPR_DRC_STATE_LOGICAL_CONFIGURED ; + drck->empty_state =SPAPR_DRC_STATE_LOGICAL_UNUSABLE ; }static void spapr_drc_cpu_class_init (ObjectClass *k,void *data)
@@ -987,6 +1009,7 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,uint64_t wa_offset;uint32_t drc_index;sPAPRDRConnector *drc; +sPAPRDRConnectorClass *drck;sPAPRConfigureConnectorState *ccs;sPAPRDRCCResponse resp =SPAPR_DR_CC_RESPONSE_CONTINUE ;int rc;
@@ -1006,12 +1029,17 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu, goto out; } -if (!drc->fdt) { -trace_spapr_rtas_ibm_configure_connector_missing_fdt (drc_index); +if ((drc->state !=SPAPR_DRC_STATE_LOGICAL_UNISOLATE ) + && (drc->state !=SPAPR_DRC_STATE_PHYSICAL_UNISOLATE )) { +/* Need to unisolate the device before configuring */ rc =SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE ; goto out; } +g_assert (drc->fdt); + + drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + ccs = drc->ccs;if (!ccs) { ccs =g_new0 (sPAPRConfigureConnectorState,1 );
@@ -1041,18 +1069,11 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,case FDT_END_NODE : ccs->fdt_depth--;if (ccs->fdt_depth ==0 ) { -sPAPRDRIsolationState state = drc->isolation_state;uint32_t drc_index =spapr_drc_index (drc); -/* done sending the device tree, don't need to track -* the state anymore -*/ + +/* done sending the device tree, move to configured state */ trace_spapr_drc_set_configured (drc_index); -if (state ==SPAPR_DR_ISOLATION_STATE_UNISOLATED ) { - drc->configured = true; - }else { -/* guest should be not configuring an isolated device */ -trace_spapr_drc_set_configured_skipping (drc_index); - } + drc->state = drck->ready_state;g_free (ccs); drc->ccs =NULL ; ccs =NULL ;
hw/ppc/trace-events +1 -2
@@ -46,8 +46,7 @@ spapr_drc_set_configured(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_configured_skipping(uint32_t index) "drc: 0x%"PRIx32", isolated device" spapr_drc_attach(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_detach(uint32_t index) "drc: 0x%"PRIx32 -spapr_drc_awaiting_isolated(uint32_t index) "drc: 0x%"PRIx32 -spapr_drc_awaiting_unusable(uint32_t index) "drc: 0x%"PRIx32 +spapr_drc_awaiting_quiesce(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_awaiting_allocation(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_reset(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_realize(uint32_t index) "drc: 0x%"PRIx32
include/hw/ppc/spapr_drc.h +21 -4
@@ -173,6 +173,24 @@ typedef enum {SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE =-9003 , } sPAPRDRCCResponse; +typedef enum { +/* +* Values come from Fig. 12 in LoPAPR section 13.4 +* +* These are exposed in the migration stream, so don't change +* them. +*/ +SPAPR_DRC_STATE_INVALID =0 , +SPAPR_DRC_STATE_LOGICAL_UNUSABLE =1 , +SPAPR_DRC_STATE_LOGICAL_AVAILABLE =2 , +SPAPR_DRC_STATE_LOGICAL_UNISOLATE =3 , +SPAPR_DRC_STATE_LOGICAL_CONFIGURED =4 , +SPAPR_DRC_STATE_PHYSICAL_AVAILABLE =5 , +SPAPR_DRC_STATE_PHYSICAL_POWERON =6 , +SPAPR_DRC_STATE_PHYSICAL_UNISOLATE =7 , +SPAPR_DRC_STATE_PHYSICAL_CONFIGURED =8 , +}sPAPRDRCState ; +/* rtas-configure-connector state */ typedef struct sPAPRConfigureConnectorState { int fdt_offset;
@@ -189,14 +207,11 @@ typedef struct sPAPRDRConnector {/* DR-indicator */ uint32_t dr_indicator; -/* sensor/indicator states */ -uint32_t isolation_state; -uint32_t allocation_state; +uint32_t state;/* configure-connector state */ void *fdt;int fdt_start_offset; -bool configured;sPAPRConfigureConnectorState *ccs;/* device pointer, via link property */
@@ -207,6 +222,8 @@ typedef struct sPAPRDRConnector { typedef struct sPAPRDRConnectorClass { /*< private >*/ DeviceClass parent; + sPAPRDRCState empty_state; + sPAPRDRCState ready_state; /*< public >*/ sPAPRDRConnectorTypeShift typeshift;
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 14/18] 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.
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)
@@ -3361,6 +3435,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.13.0
[Qemu-devel] [PULL 15/18] 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.13.0
[Qemu-devel] [PULL 17/18] 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.13.0
Quoted 24 lines · David Gibson
The following changes since commit
49bcce4b9c11759678fd223aefb48691c4959d4f:Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-07-12' into staging (2017-07-13 16:56:06 +0100)
are available in the git repository at:
git://github.com/dgibson/qemu.gittags/ppc-for-2.10-20170714for you to fetch changes up to
e11134d2ac7744569d7c387102368c507d340c30:pseries: Allow HPT resizing with KVM (2017-07-14 09:28:30 +1000)
----------------------------------------------------------------
ppc patch queue 2017-07-14Two major batches in this set, rather than the usual collection of assorted fixes.
* More DRC cleanup. This gets the state management into a state which should fix many of the hotplug+migration problems we've had. Plus it gets the migration stream format into something well defined and pretty minimal which we can reasonably support into the future.
Quoted 7 lines
* Hashed Page Table resizing. It's been a while since this was posted, but it's been through several previous rounds of review. The kernel parts (both guest and host) are merged in 4.11, so this is the only remaining piece left to allow resizing of the HPT in a running guest.
There are also a handful of unrelated fixes.
I see Alex Graf's update to the e500 u-boot image didn't make it in to this -- are you planning to send that separately or should I pick it up directly? (I definitely would like to see that in the 2.10 release, because it fixes a problem where our u-boot sources are (a) very old and (b) not even the version corresponding to the binary blob we ship...)
thanks
-- PMM
Quoted 31 lines · Peter Maydell
Quoted 30 lines · David Gibson
The following changes since commit
49bcce4b9c11759678fd223aefb48691c4959d4f:Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-07-12' into staging (2017-07-13 16:56:06 +0100)
are available in the git repository at:
git://github.com/dgibson/qemu.gittags/ppc-for-2.10-20170714for you to fetch changes up to
e11134d2ac7744569d7c387102368c507d340c30:pseries: Allow HPT resizing with KVM (2017-07-14 09:28:30 +1000)
----------------------------------------------------------------
ppc patch queue 2017-07-14Two major batches in this set, rather than the usual collection of assorted fixes.
* More DRC cleanup. This gets the state management into a state which should fix many of the hotplug+migration problems we've had. Plus it gets the migration stream format into something well defined and pretty minimal which we can reasonably support into the future.
* Hashed Page Table resizing. It's been a while since this was posted, but it's been through several previous rounds of review. The kernel parts (both guest and host) are merged in 4.11, so this is the only remaining piece left to allow resizing of the HPT in a running guest.
Quoted 8 lines
Quoted 1 line
There are also a handful of unrelated fixes.
I see Alex Graf's update to the e500 u-boot image didn't make it in to this -- are you planning to send that separately or should I pick it up directly? (I definitely would like to see that in the 2.10 release, because it fixes a problem where our u-boot sources are (a) very old and (b) not even the version corresponding to the binary blob we ship...)
Oh, I didn't spot that one. Can you take it directly?
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
Quoted 24 lines · David Gibson
The following changes since commit
49bcce4b9c11759678fd223aefb48691c4959d4f:Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-07-12' into staging (2017-07-13 16:56:06 +0100)
are available in the git repository at:
git://github.com/dgibson/qemu.gittags/ppc-for-2.10-20170714for you to fetch changes up to
e11134d2ac7744569d7c387102368c507d340c30:pseries: Allow HPT resizing with KVM (2017-07-14 09:28:30 +1000)
----------------------------------------------------------------
ppc patch queue 2017-07-14Two major batches in this set, rather than the usual collection of assorted fixes.
* More DRC cleanup. This gets the state management into a state which should fix many of the hotplug+migration problems we've had. Plus it gets the migration stream format into something well defined and pretty minimal which we can reasonably support into the future.
Quoted 7 lines
* Hashed Page Table resizing. It's been a while since this was posted, but it's been through several previous rounds of review. The kernel parts (both guest and host) are merged in 4.11, so this is the only remaining piece left to allow resizing of the HPT in a running guest.
There are also a handful of unrelated fixes.
Hi. I'm afraid this fails to build on the w32 compiler:
CC ppc64-softmmu/hw/ppc/spapr.o/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c: In function ‘spapr_get_resize_hpt’:/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c:2642:1: error:
control reaches end of non-void functio
n [-Werror=return-type]
}
^
The compiler is confused (it doesn't realise that "assert(0)" cannot return), but you can make it happier like this:
hw/ppc/spapr.c +0 -0
@@ -2638,7 +2638,7 @@ static char *spapr_get_resize_hpt(Object *obj,
Error **errp)
case SPAPR_RESIZE_HPT_REQUIRED:
return g_strdup("required");
}- assert(0);
+ g_assert_not_reached();
}
static void spapr_set_resize_hpt(Object *obj, const char *value, Error **errp)
I think g_assert_not_reached() is easier to read anyway; I always have to think for a moment about whether assert(0) or assert(1) is the "always assert" condition...
thanks
-- PMM
Quoted 33 lines · Peter Maydell
Quoted 24 lines · David Gibson
The following changes since commit
49bcce4b9c11759678fd223aefb48691c4959d4f:Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-07-12' into staging (2017-07-13 16:56:06 +0100)
are available in the git repository at:
git://github.com/dgibson/qemu.gittags/ppc-for-2.10-20170714for you to fetch changes up to
e11134d2ac7744569d7c387102368c507d340c30:pseries: Allow HPT resizing with KVM (2017-07-14 09:28:30 +1000)
----------------------------------------------------------------
ppc patch queue 2017-07-14Two major batches in this set, rather than the usual collection of assorted fixes.
* More DRC cleanup. This gets the state management into a state which should fix many of the hotplug+migration problems we've had. Plus it gets the migration stream format into something well defined and pretty minimal which we can reasonably support into the future.
Quoted 7 lines
* Hashed Page Table resizing. It's been a while since this was posted, but it's been through several previous rounds of review. The kernel parts (both guest and host) are merged in 4.11, so this is the only remaining piece left to allow resizing of the HPT in a running guest.
There are also a handful of unrelated fixes.
Quoted 8 lines
Hi. I'm afraid this fails to build on the w32 compiler:
CCppc64-softmmu/hw/ppc/spapr.o/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c: In function ‘spapr_get_resize_hpt’:/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c:2642:1: error:
control reaches end of non-void functio
n [-Werror=return-type]
}
Drat. Is there an easy way to test compile for w32?
Quoted 21 lines
^
The compiler is confused (it doesn't realise that "assert(0)" cannot return), but you can make it happier like this:
hw/ppc/spapr.c +1
-1@@ -2638,7 +2638,7 @@ static char *spapr_get_resize_hpt(Object *obj, Error **errp)case SPAPR_RESIZE_HPT_REQUIRED :return g_strdup ("required" ); } -assert (0 ); +g_assert_not_reached (); }static void
spapr_set_resize_hpt(Object *obj, const char *value, Error **errp)
Quoted 3 lines
I think
g_assert_not_reached()is easier to read anyway; I always have to think for a moment about whether assert(0) or assert(1) is the "always assert" condition...
Yes, seems good. Should I resend, or will you adjust in place?
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
Quoted 11 lines · David Gibson
Quoted 8 lines · Peter Maydell
Hi. I'm afraid this fails to build on the w32 compiler:
CCppc64-softmmu/hw/ppc/spapr.o/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c: In function ‘spapr_get_resize_hpt’:/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c:2642:1: error:
control reaches end of non-void functio
n [-Werror=return-type]
}Drat. Is there an easy way to test compile for w32?
I have a cross-compiler set up on an Ubuntu host; you can do it on Redhat hosts too; instructions on the wiki somewhere I think.
In this case I think you're either getting caught by the age of the compiler or because this set of w32 headers have a bug where assert() doesn't get marked as fatal somehow, so it might or might not manifest on other w32 cross build setups.
Quoted 1 line
Yes, seems good. Should I resend, or will you adjust in place?
You'll need to resend -- I can't modify signed pull reqs.
thanks
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 10 lines · David Gibson
Quoted 8 lines · Peter Maydell
Hi. I'm afraid this fails to build on the w32 compiler:
CCppc64-softmmu/hw/ppc/spapr.o/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c: In function ‘spapr_get_resize_hpt’:/home/petmay01/linaro/qemu-for-merges/hw/ppc/spapr.c:2642:1: error:
control reaches end of non-void functio
n [-Werror=return-type]
}
Quoted 5 lines
Quoted 1 line
Drat. Is there an easy way to test compile for w32?
I have a cross-compiler set up on an Ubuntu host; you can do it on Redhat hosts too; instructions on the wiki somewhere I think.
Ah, thanks, found them.
Quoted 5 lines
In this case I think you're either getting caught by the age of the compiler or because this set of w32 headers have a bug where
assert()doesn't get marked as fatal somehow, so it might or might not manifest on other w32 cross build setups.
Ah, right.
Quoted 3 lines
Quoted 1 line
Yes, seems good. Should I resend, or will you adjust in place?
You'll need to resend -- I can't modify signed pull reqs.
Ah, yes of course.
I've also realised one of the patches breaks make check on Travis OSX builds for reasons I haven't quite fathomed yet. Investigating.
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