pseries: migration and QOM support
cover pseries: migration and QOM support
This series is based on Alexey's series:
spapr: migration, pci, msi, power8
Which in turn was based on work by David Gibson.
I've removed the bits not related to migration and made the following changes:
1) QOMify TCE tables and XICS
2) Do everything in terms of VMStateDescriptions
3) Fix endianness problem with TCE table translation
a) Drop the VMSTATE_DIVIDE thing in the process
I've tested this with a TCG pseries guest on an x86_64 host.
Regards,
Anthony Liguori
PATCH 1/11 target-ppc: Convert ppc cpu savevm to VMStateDescription
From: Alexey Kardashevskiy <[email protected]>
The savevm code for the powerpc cpu emulation is currently based around the old register_savevm() rather than register_vmstate() method. It's also rather broken, missing some important state on some CPU models.
This patch completely rewrites the savevm for target-ppc, using the new VMStateDescription approach. Exactly what needs to be saved in what configurations has been more carefully examined, too. This introduces a new version (5) of the cpu save format. The old load function is retained to support version 4 images.
--- target-ppc/cpu-qom.h | 4 + target-ppc/cpu.h | 8 +- target-ppc/machine.c | 531 ++++++++++++++++++++++++++++++++++++-------- target-ppc/translate_init.c | 2 + 4 files changed, 452 insertions(+), 93 deletions(-)
target-ppc/cpu-qom.h +4 -0
@@ -106,4 +106,8 @@ void ppc_cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,void ppc_cpu_dump_statistics (CPUState *cpu,FILE *f,fprintf_function cpu_fprintf,int flags); +#ifndef CONFIG_USER_ONLY +extern const struct VMStateDescription vmstate_ppc_cpu; +#endif +#endif
target-ppc/cpu.h +3 -5
@@ -948,7 +948,7 @@ struct CPUPPCState {#if defined(TARGET_PPC64 )/* PowerPC 64 SLB area */ ppc_slb_t slb[64 ]; -int slb_nr; +int32_t slb_nr;#endif /* segment registers */ hwaddr htab_base;
@@ -957,11 +957,11 @@ struct CPUPPCState {/* externally stored hash table */ uint8_t *external_htab;/* BATs */ -int nb_BATs; +uint32_t nb_BATs;target_ulong DBAT [2 ][8 ];target_ulong IBAT [2 ][8 ];/* PowerPC TLB registers (for 4xx, e500 and 60x software driven TLBs) */ -int nb_tlb;/* Total number of TLB */ +int32_t nb_tlb;/* Total number of TLB */ int tlb_per_way;/* Speed-up helper: used to avoid divisions at run time */ int nb_ways;/* Number of ways in the TLB set */ int last_way;/* Last used way used to allocate TLB in a LRU way */
@@ -1176,8 +1176,6 @@ static inline CPUPPCState *cpu_init(const char *cpu_model)#define cpu_signal_handler cpu_ppc_signal_handler#define cpu_list ppc_cpu_list -#define CPU_SAVE_VERSION 4 -/* MMU modes definitions */ #define MMU_MODE0_SUFFIX _user#define MMU_MODE1_SUFFIX _kernel
target-ppc/machine.c +443 -88
542 lines not on this page · raw message
target-ppc/translate_init.c +2 -0
@@ -8449,6 +8449,8 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) cc->do_interrupt = ppc_cpu_do_interrupt; cc->dump_state = ppc_cpu_dump_state; cc->dump_statistics = ppc_cpu_dump_statistics; + +cpu_class_set_vmsd (cc, &vmstate_ppc_cpu); }static const TypeInfo ppc_cpu_type_info = {
Signature · 1 line
1.8.0
PATCH 2/11 pseries: savevm support for VIO devices
In reply to Anthony LiguoriFrom: David Gibson <[email protected]>
This patch adds helpers to allow PAPR VIO devices to save state common to all VIO devices during savevm.
--- hw/ppc/spapr_vio.c | 20 ++++++++++++++++++++ include/hw/ppc/spapr_vio.h | 5 +++++ 2 files changed, 25 insertions(+)
hw/ppc/spapr_vio.c +20 -0
@@ -542,6 +542,26 @@ static const TypeInfo spapr_vio_bridge_info = { .class_init = spapr_vio_bridge_class_init, }; +const VMStateDescription vmstate_spapr_vio = { + .name ="spapr_vio" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +/* Sanity check */ +VMSTATE_UINT32_EQUAL (reg, VIOsPAPRDevice), +VMSTATE_UINT32_EQUAL (irq, VIOsPAPRDevice), + +/* General VIO device state */ +VMSTATE_UINTTL (signal_state, VIOsPAPRDevice), +VMSTATE_UINT64 (crq.qladdr, VIOsPAPRDevice), +VMSTATE_UINT32 (crq.qsize, VIOsPAPRDevice), +VMSTATE_UINT32 (crq.qnext, VIOsPAPRDevice), + +VMSTATE_END_OF_LIST () + }, +}; +static void vio_spapr_device_class_init (ObjectClass *klass,void *data) {DeviceClass *k =DEVICE_CLASS (klass);
include/hw/ppc/spapr_vio.h +5 -0
@@ -134,4 +134,9 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus);void spapr_vio_quiesce (void ); +extern const VMStateDescription vmstate_spapr_vio; + +#define VMSTATE_SPAPR_VIO (_f, _s) \ + VMSTATE_STRUCT(_f, _s, 0, vmstate_spapr_vio, VIOsPAPRDevice) +#endif /* _HW_SPAPR_VIO_H */
Signature · 1 line
1.8.0
PATCH 3/11 pseries: savevm support for PAPR VIO logical lan
In reply to Anthony LiguoriFrom: David Gibson <[email protected]>
This patch adds the necessary VMStateDescription information to support savevm/loadvm for the spapr_llan (PAPR logical lan) device.
--- hw/net/spapr_llan.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
hw/net/spapr_llan.c +22 -2
@@ -81,9 +81,9 @@ typedef struct VIOsPAPRVLANDevice {VIOsPAPRDevice sdev;NICConf nicconf;NICState *nic; -int isopen; +bool isopen;target_ulong buf_list; -int add_buf_ptr, use_buf_ptr, rx_bufs; +uint32_t add_buf_ptr, use_buf_ptr, rx_bufs;target_ulong rxq_ptr; } VIOsPAPRVLANDevice;
@@ -500,6 +500,25 @@ static Property spapr_vlan_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static const VMStateDescription vmstate_spapr_llan = { + .name ="spapr_llan" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_SPAPR_VIO (sdev, VIOsPAPRVLANDevice), +/* LLAN state */ +VMSTATE_BOOL (isopen, VIOsPAPRVLANDevice), +VMSTATE_UINTTL (buf_list, VIOsPAPRVLANDevice), +VMSTATE_UINT32 (add_buf_ptr, VIOsPAPRVLANDevice), +VMSTATE_UINT32 (use_buf_ptr, VIOsPAPRVLANDevice), +VMSTATE_UINT32 (rx_bufs, VIOsPAPRVLANDevice), +VMSTATE_UINTTL (rxq_ptr, VIOsPAPRVLANDevice), + +VMSTATE_END_OF_LIST () + }, +}; +static void spapr_vlan_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -514,6 +533,7 @@ static void spapr_vlan_class_init(ObjectClass *klass, void *data) k->signal_mask =0x1 ; dc->props = spapr_vlan_properties; k->rtce_window_size =0x10000000 ; + dc->vmsd = &vmstate_spapr_llan; }static const TypeInfo spapr_vlan_info = {
Signature · 1 line
1.8.0
PATCH 4/11 pseries: savevm support for PAPR VIO logical tty
In reply to Anthony LiguoriFrom: David Gibson <[email protected]>
This patch adds the necessary VMStateDescription information to support savevm/loadvm for the spapr_tty (PAPR logical serial) device.
--- hw/char/spapr_vty.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
hw/char/spapr_vty.c +16 -0
@@ -142,6 +142,21 @@ static Property spapr_vty_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static const VMStateDescription vmstate_spapr_vty = { + .name ="spapr_vty" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_SPAPR_VIO (sdev, VIOsPAPRVTYDevice), + +VMSTATE_UINT32 (in, VIOsPAPRVTYDevice), +VMSTATE_UINT32 (out, VIOsPAPRVTYDevice), +VMSTATE_BUFFER (buf, VIOsPAPRVTYDevice), +VMSTATE_END_OF_LIST () + }, +}; +static void spapr_vty_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -152,6 +167,7 @@ static void spapr_vty_class_init(ObjectClass *klass, void *data) k->dt_type ="serial" ; k->dt_compatible ="hvterm1" ; dc->props = spapr_vty_properties; + dc->vmsd = &vmstate_spapr_vty; }static const TypeInfo spapr_vty_info = {
Signature · 1 line
1.8.0
PATCH 5/11 spapr-tce: make sPAPRTCETable a proper device
In reply to Anthony LiguoriModel TCE tables as a device that's hooked up as a child object to the owner. Besides the code cleanup, we get a few nice benefits:
1) free actually works now (it was dead code before)
2) the TCE information is visible in the device tree
3) we can expose table information as properties such that if we change the window_size, we can use globals to keep migration working.
--- hw/ppc/spapr.c | 3 - hw/ppc/spapr_iommu.c | 145 ++++++++++++++++++++++++++++++++----------------- hw/ppc/spapr_pci.c | 2 +- hw/ppc/spapr_vio.c | 2 +- include/hw/ppc/spapr.h | 23 +++++--- 5 files changed, 114 insertions(+), 61 deletions(-)
hw/ppc/spapr.c +0 -3
@@ -848,9 +848,6 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)/* Set up EPOW events infrastructure */ spapr_events_init (spapr); -/* Set up IOMMU */ -spapr_iommu_init (); -/* Set up VIO bus */ spapr->vio_bus =spapr_vio_bus_init ();
hw/ppc/spapr_iommu.c +96 -49
223 lines not on this page · raw message
hw/ppc/spapr_pci.c +1 -1
@@ -682,7 +682,7 @@ static void spapr_phb_reset(DeviceState *qdev)sPAPRPHBState *sphb =SPAPR_PCI_HOST_BRIDGE (s);/* Reset the IOMMU state */ -spapr_tce_reset (sphb->tcet); +device_reset (DEVICE (sphb->tcet)); }static Property spapr_phb_properties[] = {
hw/ppc/spapr_vio.c +1 -1
@@ -316,7 +316,7 @@ int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq)static void spapr_vio_quiesce_one (VIOsPAPRDevice *dev) {if (dev->tcet) { -spapr_tce_reset (dev->tcet); +device_reset (DEVICE (dev->tcet)); }free_crq (dev); }
include/hw/ppc/spapr.h +16 -7
@@ -334,10 +334,6 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,#define SPAPR_TCE_PAGE_SIZE (1ULL << SPAPR_TCE_PAGE_SHIFT)#define SPAPR_TCE_PAGE_MASK (SPAPR_TCE_PAGE_SIZE - 1) -typedef struct sPAPRTCE { -uint64_t tce; -}sPAPRTCE ; -#define SPAPR_VIO_BASE_LIOBN 0x00000000#define SPAPR_PCI_BASE_LIOBN 0x80000000
@@ -345,14 +341,27 @@ typedef struct sPAPRTCE {typedef struct sPAPRTCETable sPAPRTCETable ; -void spapr_iommu_init (void ); +#define TYPE_SPAPR_TCE_TABLE "spapr-tce-table" +#define SPAPR_TCE_TABLE (obj) \ + OBJECT_CHECK(sPAPRTCETable, (obj), TYPE_SPAPR_TCE_TABLE) + +struct sPAPRTCETable { +DeviceState parent; +uint32_t liobn; +uint32_t window_size; +uint32_t nb_table; +uint64_t *table; +bool bypass; +int fd; +MemoryRegion iommu; +QLIST_ENTRY (sPAPRTCETable) list; +}; +void spapr_events_init (sPAPREnvironment *spapr);void spapr_events_fdt_skel (void *fdt,uint32_t epow_irq);sPAPRTCETable *spapr_tce_new_table (DeviceState *owner,uint32_t liobn,size_t window_size);MemoryRegion *spapr_tce_get_iommu (sPAPRTCETable *tcet); -void spapr_tce_free (sPAPRTCETable *tcet); -void spapr_tce_reset (sPAPRTCETable *tcet);void spapr_tce_set_bypass (sPAPRTCETable *tcet,bool bypass);int spapr_dma_dt (void *fdt,int node_off,const char *propname,uint32_t liobn,uint64_t window,uint32_t size);
Signature · 1 line
1.8.0
PATCH 1/1 ppc kvm: fix to compile
--- target-ppc/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target-ppc/kvm.c +2 -2
@@ -1628,7 +1628,7 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd)return NULL ; } - len = (window_size /SPAPR_TCE_PAGE_SIZE ) *sizeof (sPAPRTCE); + len = (window_size /SPAPR_TCE_PAGE_SIZE ) *sizeof (uint64_t );/* FIXME: round this up to page size */ table =mmap (NULL , len,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );
@@ -1651,7 +1651,7 @@ int kvmppc_remove_spapr_tce(void *table, int fd, uint32_t window_size)return -1 ; } - len = (window_size /SPAPR_TCE_PAGE_SIZE )*sizeof (sPAPRTCE); + len = (window_size /SPAPR_TCE_PAGE_SIZE )*sizeof (uint64_t );if ((munmap (table, len) <0 ) || (close (fd) <0 )) { fprintf(stderr, "KVM: Unexpected error removing TCE table: %s",
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH] ppc kvm: fix to compile
Quoted 27 lines · Alexey Kardashevskiy
Signed-off-by Alexey Kardashevskiy <[email protected]>--- target-ppc/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target-ppc/kvm.c +2
-2@@ -1628,7 +1628,7 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd)return NULL ; } - len = (window_size /SPAPR_TCE_PAGE_SIZE ) *sizeof (sPAPRTCE); + len = (window_size /SPAPR_TCE_PAGE_SIZE ) *sizeof (uint64_t );/* FIXME: round this up to page size */ table =mmap (NULL , len,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );@@ -1651,7 +1651,7 @@ int kvmppc_remove_spapr_tce(void *table, int fd, uint32_t window_size)return -1 ; } - len = (window_size /SPAPR_TCE_PAGE_SIZE )*sizeof (sPAPRTCE); + len = (window_size /SPAPR_TCE_PAGE_SIZE )*sizeof (uint64_t );if ((munmap (table, len) <0 ) || (close (fd) <0 )) { fprintf(stderr, "KVM: Unexpected error removing TCE table:
Quoted 1 line
%s",
Thanks, I'm running on x86 so this code didn't get built for me.
Regards,
Anthony Liguori
Quoted 2 lines
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH] ppc kvm: fix to compile
In reply to Alexey KardashevskiyQuoted 1 line · Alexey Kardashevskiy
Signed-off-by Alexey Kardashevskiy <[email protected]>
Why? sPAPRTCE is a typedef struct that's defined in include/hw/ppc/spapr.h which is included from target-ppc/kvm.c. So it should work just fine.
Alex
Quoted 29 lines
---
target-ppc/kvm.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)target-ppc/kvm.c +2
-2@@ -1628,7 +1628,7 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd)return NULL ; } - len = (window_size /SPAPR_TCE_PAGE_SIZE ) *sizeof (sPAPRTCE); + len = (window_size /SPAPR_TCE_PAGE_SIZE ) *sizeof (uint64_t );/* FIXME: round this up to page size */ table =mmap (NULL , len,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );@@ -1651,7 +1651,7 @@ int kvmppc_remove_spapr_tce(void *table, int fd, uint32_t window_size)return -1 ; } - len = (window_size /SPAPR_TCE_PAGE_SIZE )*sizeof (sPAPRTCE); + len = (window_size /SPAPR_TCE_PAGE_SIZE )*sizeof (uint64_t );if ((munmap (table, len) <0 ) || (close (fd) <0 )) { fprintf(stderr, "KVM: Unexpected error removing TCE table: %s",Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [Qemu-ppc] [PATCH] ppc kvm: fix to compile
Quoted 6 lines · Alexander Graf
Quoted 1 line · Alexey Kardashevskiy
Signed-off-by Alexey Kardashevskiy <[email protected]>Why? sPAPRTCE is a typedef struct that's defined in
include/hw/ppc/spapr.hwhich is included fromtarget-ppc/kvm.c. So it should work just fine.
Ah, my mailer screwed up threading. This is in reply to Anthony's cleanups?
Alex
Re: [Qemu-devel] [Qemu-ppc] [PATCH] ppc kvm: fix to compile
Quoted 11 lines · Alexander Graf
Quoted 6 lines · Alexander Graf
Quoted 1 line · Alexey Kardashevskiy
Signed-off-by Alexey Kardashevskiy <[email protected]>Why? sPAPRTCE is a typedef struct that's defined in
include/hw/ppc/spapr.hwhich is included fromtarget-ppc/kvm.c. So it should work just fine.Ah, my mailer screwed up threading. This is in reply to Anthony's cleanups?
Yes. He removed the struct.
Signature · 1 line
Alexey
Re: [Qemu-devel] [PATCH 05/11] spapr-tce: make sPAPRTCETable a proper device
In reply to Anthony LiguoriQuoted 159 lines · Anthony Liguori
Model TCE tables as a device that's hooked up as a child object to the owner. Besides the code cleanup, we get a few nice benefits:
1) free actually works now (it was dead code before)
2) the TCE information is visible in the device tree
3) we can expose table information as properties such that if we change the
window_size, we can use globals to keep migration working.Signed-off-by David Gibson <[email protected]>[dwg: pseries: savevm support for PAPR TCE tables]Signed-off-by Anthony Liguori <[email protected]>--- hw/ppc/spapr.c | 3 - hw/ppc/spapr_iommu.c | 145 ++++++++++++++++++++++++++++++++----------------- hw/ppc/spapr_pci.c | 2 +- hw/ppc/spapr_vio.c | 2 +- include/hw/ppc/spapr.h | 23 +++++--- 5 files changed, 114 insertions(+), 61 deletions(-)hw/ppc/spapr.c +0
-3@@ -848,9 +848,6 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)/* Set up EPOW events infrastructure */ spapr_events_init (spapr); -/* Set up IOMMU */ -spapr_iommu_init (); -/* Set up VIO bus */ spapr->vio_bus =spapr_vio_bus_init ();hw/ppc/spapr_iommu.c +46
-33@@ -36,17 +36,6 @@ enum sPAPRTCEAccess {SPAPR_TCE_RW =3 , }; -struct sPAPRTCETable { -uint32_t liobn; -uint32_t window_size; -sPAPRTCE *table; -bool bypass; -int fd; -MemoryRegion iommu; -QLIST_ENTRY (sPAPRTCETable) list; -}; - - QLIST_HEAD(spapr_tce_tables, sPAPRTCETable) spapr_tce_tables;static sPAPRTCETable *spapr_tce_find_by_liobn (uint32_t liobn)@@ -96,7 +85,7 @@ static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr)return (IOMMUTLBEntry ) { .perm =IOMMU_NONE }; } - tce = tcet->table[addr >>SPAPR_TCE_PAGE_SHIFT ].tce; + tce = tcet->table[addr >>SPAPR_TCE_PAGE_SHIFT ];#ifdef DEBUG_TCE fprintf(stderr, " -> *paddr=0x%llx, *len=0x%llx\n",@@ -112,37 +101,51 @@ static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr) }; } +static int spapr_tce_table_pre_load (void *opaque) +{ +sPAPRTCETable *tcet =SPAPR_TCE_TABLE (opaque); + + tcet->nb_table = tcet->window_size >>SPAPR_TCE_PAGE_SHIFT ; + +return 0 ; +} + +static const VMStateDescription vmstate_spapr_tce_table = { + .name ="spapr_iommu" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .pre_load = spapr_tce_table_pre_load, + .fields = (VMStateField []) { +/* Sanity check */ +VMSTATE_UINT32_EQUAL (liobn, sPAPRTCETable), +VMSTATE_UINT32_EQUAL (window_size, sPAPRTCETable), + +/* IOMMU state */ +VMSTATE_BOOL (bypass, sPAPRTCETable), +VMSTATE_VARRAY_UINT32 (table, sPAPRTCETable, nb_table,0 , vmstate_info_uint64, uint64_t), + +VMSTATE_END_OF_LIST () + }, +}; +static MemoryRegionIOMMUOps spapr_iommu_ops = { .translate = spapr_tce_translate_iommu, }; -sPAPRTCETable *spapr_tce_new_table (DeviceState *owner,uint32_t liobn,size_t window_size) +static int spapr_tce_table_realize (DeviceState *dev) { -sPAPRTCETable *tcet; - -if (spapr_tce_find_by_liobn (liobn)) { -fprintf (stderr,"Attempted to create TCE table with duplicate" -" LIOBN 0x%x\n" , liobn); -return NULL ; - } - -if (!window_size) { -return NULL ; - } - - tcet =g_malloc0 (sizeof (*tcet)); - tcet->liobn = liobn; - tcet->window_size = window_size; +sPAPRTCETable *tcet =SPAPR_TCE_TABLE (dev);if (kvm_enabled ()) { - tcet->table =kvmppc_create_spapr_tce (liobn, - window_size, + tcet->table =kvmppc_create_spapr_tce (tcet->liobn, + tcet->window_size, &tcet->fd); }if (!tcet->table) { -size_t table_size = (window_size >>SPAPR_TCE_PAGE_SHIFT ) - *sizeof (sPAPRTCE); +size_t table_size = (tcet->window_size >>SPAPR_TCE_PAGE_SHIFT ) + *sizeof (uint64_t ); tcet->table =g_malloc0 (table_size); }@@ -151,16 +154,43 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn, size_t wi "table @ %p, fd=%d\n", tcet, liobn, tcet->table, tcet->fd);#endif -memory_region_init_iommu (&tcet->iommu,OBJECT (owner), &spapr_iommu_ops, +memory_region_init_iommu (&tcet->iommu,OBJECT (dev), &spapr_iommu_ops,"iommu-spapr" ,UINT64_MAX );QLIST_INSERT_HEAD (&spapr_tce_tables, tcet, list); +return 0 ; +} + +sPAPRTCETable *spapr_tce_new_table (DeviceState *owner,uint32_t liobn,size_t window_size) +{ +sPAPRTCETable *tcet; + +if (spapr_tce_find_by_liobn (liobn)) { +fprintf (stderr,"Attempted to create TCE table with duplicate" +" LIOBN 0x%x\n" , liobn);
hw/ppc/spapr_iommu.c sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn, size_t wi · line 181
Quoted 10 lines
hw/ppc/spapr_iommu.c +10
-0+return NULL ; + } + +if (!window_size) { +return NULL ; + } + + tcet =SPAPR_TCE_TABLE (object_new (TYPE_SPAPR_TCE_TABLE )); + tcet->liobn = liobn; + tcet->window_size = window_size;
I am trying to understand the QOM. How do you understand what initialization should go to .realize and what should stay in spapr_tce_new_table?
In this particular case having the .realize implementation does not make much sense to me. If you made .liobn and .window_size members of sPAPRTCETable then it would be ok but you did not. What do I miss? Thanks.
Signature · 1 line
Alexey
Re: [Qemu-devel] [PATCH 05/11] spapr-tce: make sPAPRTCETable a proper device
Quoted 168 lines · Alexey Kardashevskiy
Quoted 167 lines · Anthony Liguori
Model TCE tables as a device that's hooked up as a child object to the owner. Besides the code cleanup, we get a few nice benefits:
1) free actually works now (it was dead code before)
2) the TCE information is visible in the device tree
3) we can expose table information as properties such that if we change the
window_size, we can use globals to keep migration working.Signed-off-by David Gibson <[email protected]>[dwg: pseries: savevm support for PAPR TCE tables]Signed-off-by Anthony Liguori <[email protected]>--- hw/ppc/spapr.c | 3 - hw/ppc/spapr_iommu.c | 145 ++++++++++++++++++++++++++++++++----------------- hw/ppc/spapr_pci.c | 2 +- hw/ppc/spapr_vio.c | 2 +- include/hw/ppc/spapr.h | 23 +++++--- 5 files changed, 114 insertions(+), 61 deletions(-)hw/ppc/spapr.c +0
-3@@ -848,9 +848,6 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)/* Set up EPOW events infrastructure */ spapr_events_init (spapr); -/* Set up IOMMU */ -spapr_iommu_init (); -/* Set up VIO bus */ spapr->vio_bus =spapr_vio_bus_init ();hw/ppc/spapr_iommu.c +54
-33@@ -36,17 +36,6 @@ enum sPAPRTCEAccess {SPAPR_TCE_RW =3 , }; -struct sPAPRTCETable { -uint32_t liobn; -uint32_t window_size; -sPAPRTCE *table; -bool bypass; -int fd; -MemoryRegion iommu; -QLIST_ENTRY (sPAPRTCETable) list; -}; - - QLIST_HEAD(spapr_tce_tables, sPAPRTCETable) spapr_tce_tables;static sPAPRTCETable *spapr_tce_find_by_liobn (uint32_t liobn)@@ -96,7 +85,7 @@ static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr)return (IOMMUTLBEntry ) { .perm =IOMMU_NONE }; } - tce = tcet->table[addr >>SPAPR_TCE_PAGE_SHIFT ].tce; + tce = tcet->table[addr >>SPAPR_TCE_PAGE_SHIFT ];#ifdef DEBUG_TCE fprintf(stderr, " -> *paddr=0x%llx, *len=0x%llx\n",@@ -112,37 +101,51 @@ static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr) }; } +static int spapr_tce_table_pre_load (void *opaque) +{ +sPAPRTCETable *tcet =SPAPR_TCE_TABLE (opaque); + + tcet->nb_table = tcet->window_size >>SPAPR_TCE_PAGE_SHIFT ; + +return 0 ; +} + +static const VMStateDescription vmstate_spapr_tce_table = { + .name ="spapr_iommu" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .pre_load = spapr_tce_table_pre_load, + .fields = (VMStateField []) { +/* Sanity check */ +VMSTATE_UINT32_EQUAL (liobn, sPAPRTCETable), +VMSTATE_UINT32_EQUAL (window_size, sPAPRTCETable), + +/* IOMMU state */ +VMSTATE_BOOL (bypass, sPAPRTCETable), +VMSTATE_VARRAY_UINT32 (table, sPAPRTCETable, nb_table,0 , vmstate_info_uint64, uint64_t), + +VMSTATE_END_OF_LIST () + }, +}; +static MemoryRegionIOMMUOps spapr_iommu_ops = { .translate = spapr_tce_translate_iommu, }; -sPAPRTCETable *spapr_tce_new_table (DeviceState *owner,uint32_t liobn,size_t window_size) +static int spapr_tce_table_realize (DeviceState *dev) { -sPAPRTCETable *tcet; - -if (spapr_tce_find_by_liobn (liobn)) { -fprintf (stderr,"Attempted to create TCE table with duplicate" -" LIOBN 0x%x\n" , liobn); -return NULL ; - } - -if (!window_size) { -return NULL ; - } - - tcet =g_malloc0 (sizeof (*tcet)); - tcet->liobn = liobn; - tcet->window_size = window_size; +sPAPRTCETable *tcet =SPAPR_TCE_TABLE (dev);if (kvm_enabled ()) { - tcet->table =kvmppc_create_spapr_tce (liobn, - window_size, + tcet->table =kvmppc_create_spapr_tce (tcet->liobn, + tcet->window_size, &tcet->fd); }if (!tcet->table) { -size_t table_size = (window_size >>SPAPR_TCE_PAGE_SHIFT ) - *sizeof (sPAPRTCE); +size_t table_size = (tcet->window_size >>SPAPR_TCE_PAGE_SHIFT ) + *sizeof (uint64_t ); tcet->table =g_malloc0 (table_size); }@@ -151,16 +154,43 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn, size_t wi "table @ %p, fd=%d\n", tcet, liobn, tcet->table, tcet->fd);#endif -memory_region_init_iommu (&tcet->iommu,OBJECT (owner), &spapr_iommu_ops, +memory_region_init_iommu (&tcet->iommu,OBJECT (dev), &spapr_iommu_ops,"iommu-spapr" ,UINT64_MAX );QLIST_INSERT_HEAD (&spapr_tce_tables, tcet, list); +return 0 ; +} + +sPAPRTCETable *spapr_tce_new_table (DeviceState *owner,uint32_t liobn,size_t window_size) +{ +sPAPRTCETable *tcet; + +if (spapr_tce_find_by_liobn (liobn)) { +fprintf (stderr,"Attempted to create TCE table with duplicate" +" LIOBN 0x%x\n" , liobn); +return NULL ; + } + +if (!window_size) { +return NULL ; + } + + tcet =SPAPR_TCE_TABLE (object_new (TYPE_SPAPR_TCE_TABLE ));
Quoted 8 lines
hw/ppc/spapr_iommu.c sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn, size_t wi · line 181
Quoted 2 lines
hw/ppc/spapr_iommu.c +2
-0+ tcet->liobn = liobn; + tcet->window_size = window_size;I am trying to understand the QOM. How do you understand what initialization should go to .realize and what should stay in
spapr_tce_new_table?
Really nothing should be in spapr_tce_new_table(). It should strictly
be an helper function to create a device and set properties (via qdev_prop_set..). We really should make liobn and window_size proper properties.
Regards,
Anthony Liguori
Quoted 13 lines
In this particular case having the .realize implementation does not make much sense to me. If you made .liobn and .window_size members of sPAPRTCETable then it would be ok but you did not. What do I miss? Thanks.
Signature · 1 line
Alexey
PATCH 6/11 pseries: rework PAPR virtual SCSI
In reply to Anthony LiguoriFrom: Alexey Kardashevskiy <[email protected]>
The patch reimplements handling of indirect requests in order to simplify upcoming live migration support.
- all pointers (except SCSIRequest*) were replaces with integer indexes and offsets;
- DMA'ed srp_direct_buf kept untouched (ie. BE format);
- vscsi_fetch_desc() is added, now it is the only place where descriptors are fetched and byteswapped;
- vscsi_req struct fields converted to migration-friendly types;
- many dprintf()'s fixed.
This also removed an unused field 'lun' from the spapr_vscsi device which is assigned, but never used. So, remove it.
---
Changes:
2013/08/07:
* fixed handling of indirect requests with an additional table descriptor
--- hw/scsi/spapr_vscsi.c | 223 +++++++++++++++++++++++++++++--------------------- 1 file changed, 130 insertions(+), 93 deletions(-)
hw/scsi/spapr_vscsi.c +130 -93
@@ -75,20 +75,19 @@ typedef struct vscsi_req {/* SCSI request tracking */ SCSIRequest *sreq;uint32_t qtag;/* qemu tag != srp tag */ -int lun; -int active; -long data_len; -int writing; -int senselen; +bool active; +uint32_t data_len; +bool writing; +uint32_t senselen;uint8_t sense[SCSI_SENSE_BUF_SIZE ];/* RDMA related bits */ uint8_t dma_fmt; -struct srp_direct_buf ext_desc; -struct srp_direct_buf *cur_desc; -struct srp_indirect_buf *ind_desc; -int local_desc; -int total_desc; +uint16_t local_desc; +uint16_t total_desc; +uint16_t cdb_offset; +uint16_t cur_desc_num; +uint16_t cur_desc_offset; } vscsi_req;#define TYPE_VIO_SPAPR_VSCSI_DEVICE "spapr-vscsi"
@@ -264,93 +263,138 @@ static int vscsi_send_rsp(VSCSIState *s, vscsi_req *req,return 0 ; } -static inline void vscsi_swap_desc (struct srp_direct_buf *desc) +static inline struct srp_direct_buf vscsi_swap_desc (struct srp_direct_buf desc) { - desc->va =be64_to_cpu (desc->va); - desc->len =be32_to_cpu (desc->len); + desc.va =be64_to_cpu (desc.va); + desc.len =be32_to_cpu (desc.len); +return desc; +} + +static int vscsi_fetch_desc (VSCSIState *s,struct vscsi_req *req, +unsigned n,unsigned buf_offset, +struct srp_direct_buf *ret) +{ +struct srp_cmd *cmd = &req->iu.srp.cmd; + +switch (req->dma_fmt) { +case SRP_NO_DATA_DESC : { +dprintf ("VSCSI: no data descriptor\n" ); +return 0 ; + } +case SRP_DATA_DESC_DIRECT : { +memcpy (ret, cmd->add_data + req->cdb_offset,sizeof (*ret)); +assert (req->cur_desc_num ==0 ); +dprintf ("VSCSI: direct segment\n" ); +break ; + } +case SRP_DATA_DESC_INDIRECT : { +struct srp_indirect_buf *tmp = (struct srp_indirect_buf *) + (cmd->add_data + req->cdb_offset); +if (n < req->local_desc) { + *ret = tmp->desc_list[n]; +dprintf ("VSCSI: indirect segment local tag=0x%x desc#%d/%d\n" , + req->qtag, n, req->local_desc); + + }else if (n < req->total_desc) { +int rc; +struct srp_direct_buf tbl_desc =vscsi_swap_desc (tmp->table_desc); +unsigned desc_offset = n *sizeof (struct srp_direct_buf ); + +if (desc_offset >= tbl_desc.len) { +dprintf ("VSCSI: #%d is ouf of range (%d bytes)\n" , + n, desc_offset); +return -1 ; + } + rc =spapr_vio_dma_read (&s->vdev, tbl_desc.va + desc_offset, + ret,sizeof (struct srp_direct_buf )); +if (rc) { +dprintf ("VSCSI: spapr_vio_dma_read -> %d reading ext_desc\n" , + rc); +return -1 ; + } +dprintf ("VSCSI: indirect segment ext. tag=0x%x desc#%d/%d { va=%" PRIx64" len=%x }\n" , + req->qtag, n, req->total_desc, tbl_desc.va, tbl_desc.len); + }else { +dprintf ("VSCSI: Out of descriptors !\n" ); +return 0 ; + } +break ; + } +default : +fprintf (stderr,"VSCSI: Unknown format %x\n" , req->dma_fmt); +return -1 ; + } + + *ret =vscsi_swap_desc (*ret); +if (buf_offset > ret->len) { +dprintf (" offset=%x is out of a descriptor #%d boundary=%x\n" , + buf_offset, req->cur_desc_num, ret->len); +return -1 ; + } + ret->va += buf_offset; + ret->len -= buf_offset; + +dprintf (" cur=%d offs=%x ret { va=%" PRIx64" len=%x }\n" , + req->cur_desc_num, req->cur_desc_offset, ret->va, ret->len); + +return ret->len ?1 :0 ; }static int vscsi_srp_direct_data (VSCSIState *s,vscsi_req *req,uint8_t *buf,uint32_t len) { -struct srp_direct_buf *md = req->cur_desc; +struct srp_direct_buf md;uint32_t llen;int rc =0 ; -dprintf ("VSCSI: direct segment 0x%x bytes, va=0x%llx desc len=0x%x\n" , - len, (unsigned long long )md->va, md->len); + rc =vscsi_fetch_desc (s, req, req->cur_desc_num, req->cur_desc_offset, &md); +if (rc <0 ) { +return -1 ; + }else if (rc ==0 ) { +return 0 ; + } - llen =MIN (len, md->len); + llen =MIN (len, md.len);if (llen) {if (req->writing) {/* writing = to device = reading from memory */ - rc =spapr_vio_dma_read (&s->vdev, md->va, buf, llen); + rc =spapr_vio_dma_read (&s->vdev, md.va, buf, llen); }else { - rc =spapr_vio_dma_write (&s->vdev, md->va, buf, llen); + rc =spapr_vio_dma_write (&s->vdev, md.va, buf, llen); } } - md->len -= llen; - md->va += llen;if (rc) {return -1 ; } + req->cur_desc_offset += llen; +return llen; }static int vscsi_srp_indirect_data (VSCSIState *s,vscsi_req *req,uint8_t *buf,uint32_t len) { -struct srp_direct_buf *td = &req->ind_desc->table_desc; -struct srp_direct_buf *md = req->cur_desc; +struct srp_direct_buf md;int rc =0 ;uint32_t llen, total =0 ; -dprintf ("VSCSI: indirect segment 0x%x bytes, td va=0x%llx len=0x%x\n" , - len, (unsigned long long )td->va, td->len); +dprintf ("VSCSI: indirect segment 0x%x bytes\n" , len);/* While we have data ... */ while (len) { -/* If we have a descriptor but it's empty, go fetch a new one */ -if (md && md->len ==0 ) { -/* More local available, use one */ -if (req->local_desc) { - md = ++req->cur_desc; - --req->local_desc; - --req->total_desc; - td->va +=sizeof (struct srp_direct_buf ); - }else { - md = req->cur_desc =NULL ; - } - } -/* No descriptor at hand, fetch one */ -if (!md) { -if (!req->total_desc) { -dprintf ("VSCSI: Out of descriptors !\n" ); -break ; - } - md = req->cur_desc = &req->ext_desc; -dprintf ("VSCSI: Reading desc from 0x%llx\n" , - (unsigned long long )td->va); - rc =spapr_vio_dma_read (&s->vdev, td->va, md, -sizeof (struct srp_direct_buf )); -if (rc) { -dprintf ("VSCSI: spapr_vio_dma_read -> %d reading ext_desc\n" , - rc); -break ; - } -vscsi_swap_desc (md); - td->va +=sizeof (struct srp_direct_buf ); - --req->total_desc; + rc =vscsi_fetch_desc (s, req, req->cur_desc_num, req->cur_desc_offset, &md); +if (rc <0 ) { +return -1 ; + }else if (rc ==0 ) { +break ; } -dprintf ("VSCSI: [desc va=0x%llx,len=0x%x] remaining=0x%x\n" , - (unsigned long long )md->va, md->len, len);/* Perform transfer */ - llen =MIN (len, md->len); + llen =MIN (len, md.len);if (req->writing) {/* writing = to device = reading from memory */ - rc =spapr_vio_dma_read (&s->vdev, md->va, buf, llen); + rc =spapr_vio_dma_read (&s->vdev, md.va, buf, llen); }else { - rc =spapr_vio_dma_write (&s->vdev, md->va, buf, llen); + rc =spapr_vio_dma_write (&s->vdev, md.va, buf, llen); }if (rc) {dprintf ("VSCSI: spapr_vio_dma_r/w(%d) -> %d\n" , req->writing, rc);
@@ -361,10 +405,18 @@ static int vscsi_srp_indirect_data(VSCSIState *s, vscsi_req *req, len -= llen; buf += llen; + total += llen; - md->va += llen; - md->len -= llen; + +/* Update current position in the current descriptor */ + req->cur_desc_offset += llen; +if (md.len == llen) { +/* Go to the next descriptor if the current one finished */ + ++req->cur_desc_num; + req->cur_desc_offset =0 ; + } } +return rc ?-1 : total; }
@@ -412,14 +464,13 @@ static int data_out_desc_size(struct srp_cmd *cmd)static int vscsi_preprocess_desc (vscsi_req *req) {struct srp_cmd *cmd = &req->iu.srp.cmd; -int offset, i; - offset = cmd->add_cdb_len & ~3 ; + req->cdb_offset = cmd->add_cdb_len & ~3 ;if (req->writing) { req->dma_fmt = cmd->buf_fmt >>4 ; }else { - offset +=data_out_desc_size (cmd); + req->cdb_offset +=data_out_desc_size (cmd); req->dma_fmt = cmd->buf_fmt & ((1U <<4 ) -1 ); }
@@ -427,31 +478,18 @@ static int vscsi_preprocess_desc(vscsi_req *req)case SRP_NO_DATA_DESC :break ;case SRP_DATA_DESC_DIRECT : - req->cur_desc = (struct srp_direct_buf *)(cmd->add_data + offset); req->total_desc = req->local_desc =1 ; -vscsi_swap_desc (req->cur_desc); -dprintf ("VSCSI: using direct RDMA %s, 0x%x bytes MD: 0x%llx\n" , - req->writing ?"write" :"read" , - req->cur_desc->len, (unsigned long long )req->cur_desc->va);break ; -case SRP_DATA_DESC_INDIRECT : - req->ind_desc = (struct srp_indirect_buf *)(cmd->add_data + offset); -vscsi_swap_desc (&req->ind_desc->table_desc); - req->total_desc = req->ind_desc->table_desc.len / -sizeof (struct srp_direct_buf ); +case SRP_DATA_DESC_INDIRECT : { +struct srp_indirect_buf *ind_tmp = (struct srp_indirect_buf *) + (cmd->add_data + req->cdb_offset); + + req->total_desc =be32_to_cpu (ind_tmp->table_desc.len) / +sizeof (struct srp_direct_buf ); req->local_desc = req->writing ? cmd->data_out_desc_cnt : - cmd->data_in_desc_cnt; -for (i =0 ; i < req->local_desc; i++) { -vscsi_swap_desc (&req->ind_desc->desc_list[i]); - } - req->cur_desc = req->local_desc ? &req->ind_desc->desc_list[0 ] :NULL ; -dprintf ("VSCSI: using indirect RDMA %s, 0x%x bytes %d descs " -"(%d local) VA: 0x%llx\n" , - req->writing ?"read" :"write" , -be32_to_cpu (req->ind_desc->len), - req->total_desc, req->local_desc, - (unsigned long long )req->ind_desc->table_desc.va); + cmd->data_in_desc_cnt;break ; + }default :fprintf (stderr,"vscsi_preprocess_desc: Unknown format %x\n" , req->dma_fmt);
@@ -499,8 +537,8 @@ static void vscsi_command_complete(SCSIRequest *sreq, uint32_t status, size_t revscsi_req *req = sreq->hba_private;int32_t res_in =0 , res_out =0 ; -dprintf ("VSCSI: SCSI cmd complete, r=0x%x tag=0x%x status=0x%x, req=%p\n" , - reason, sreq->tag, status, req); +dprintf ("VSCSI: SCSI cmd complete, tag=0x%x status=0x%x, req=%p\n" , + sreq->tag, status, req);if (req ==NULL ) {fprintf (stderr,"VSCSI: Can't find request for tag 0x%x\n" , sreq->tag);return ;
@@ -509,7 +547,7 @@ static void vscsi_command_complete(SCSIRequest *sreq, uint32_t status, size_t reif (status ==CHECK_CONDITION ) { req->senselen =scsi_req_get_sense (req->sreq, req->sense,sizeof (req->sense)); -dprintf ("VSCSI: Sense data, %d bytes:\n" , len); +dprintf ("VSCSI: Sense data, %d bytes:\n" , req->senselen);dprintf (" %02x %02x %02x %02x %02x %02x %02x %02x\n" , req->sense[0 ], req->sense[1 ], req->sense[2 ], req->sense[3 ], req->sense[4 ], req->sense[5 ], req->sense[6 ], req->sense[7 ]);
@@ -621,12 +659,11 @@ static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req) }return 1 ; } - req->lun = lun; req->sreq =scsi_req_new (sdev, req->qtag, lun, srp->cmd.cdb, req); n =scsi_req_enqueue (req->sreq); -dprintf ("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\n" , - req->qtag, srp->cmd.cdb[0 ], id, lun, n); +dprintf ("VSCSI: Queued command tag 0x%x CMD 0x%x LUN %d ret: %d\n" , + req->qtag, srp->cmd.cdb[0 ], lun, n);if (n) {/* Transfer direction must be set before preprocessing the
Signature · 1 line
1.8.0
PATCH 7/11 pseries: savevm support for PAPR virtual SCSI
In reply to Anthony LiguoriFrom: David Gibson <[email protected]>
This patch adds the necessary support for saving the state of the PAPR VIO virtual SCSI device. This also saves and restores active SCSI requests.
--- hw/scsi/spapr_vscsi.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-)
hw/scsi/spapr_vscsi.c +81 -1
@@ -578,6 +578,69 @@ static void vscsi_request_cancelled(SCSIRequest *sreq)vscsi_put_req (req); } +static const VMStateDescription vmstate_spapr_vscsi_req = { + .name ="spapr_vscsi_req" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_BUFFER (crq.raw, vscsi_req), +VMSTATE_BUFFER (iu.srp.reserved, vscsi_req), +VMSTATE_UINT32 (qtag, vscsi_req), +VMSTATE_BOOL (active, vscsi_req), +VMSTATE_UINT32 (data_len, vscsi_req), +VMSTATE_BOOL (writing, vscsi_req), +VMSTATE_UINT32 (senselen, vscsi_req), +VMSTATE_BUFFER (sense, vscsi_req), +VMSTATE_UINT8 (dma_fmt, vscsi_req), +VMSTATE_UINT16 (local_desc, vscsi_req), +VMSTATE_UINT16 (total_desc, vscsi_req), +VMSTATE_UINT16 (cdb_offset, vscsi_req), +/*Restart SCSI request from the beginning for now */ +/*VMSTATE_UINT16(cur_desc_num, vscsi_req), +VMSTATE_UINT16(cur_desc_offset, vscsi_req),*/ +VMSTATE_END_OF_LIST () + }, +}; + +static void vscsi_save_request (QEMUFile *f,SCSIRequest *sreq) +{ +vscsi_req *req = sreq->hba_private; +assert (req->active); + +vmstate_save_state (f, &vmstate_spapr_vscsi_req, req); + +dprintf ("VSCSI: saving tag=%u, current desc#%d, offset=%x\n" , + req->qtag, req->cur_desc_num, req->cur_desc_offset); +} + +static void *vscsi_load_request (QEMUFile *f,SCSIRequest *sreq) +{ +SCSIBus *bus = sreq->bus; +VSCSIState *s =VIO_SPAPR_VSCSI_DEVICE (bus->qbus.parent); +vscsi_req *req; +int rc; + +assert (sreq->tag <VSCSI_REQ_LIMIT ); + req = &s->reqs[sreq->tag]; +assert (!req->active); + +memset (req,0 ,sizeof (*req)); + rc =vmstate_load_state (f, &vmstate_spapr_vscsi_req, req,1 ); +if (rc) { +fprintf (stderr,"VSCSI: failed loading request tag#%u\n" , sreq->tag); +return NULL ; + } +assert (req->active); + + req->sreq =scsi_req_ref (sreq); + +dprintf ("VSCSI: restoring tag=%u, current desc#%d, offset=%x\n" , + req->qtag, req->cur_desc_num, req->cur_desc_offset); + +return req; +} +static void vscsi_process_login (VSCSIState *s,vscsi_req *req) {union viosrp_iu *iu = &req->iu;
@@ -932,7 +995,9 @@ static const struct SCSIBusInfo vscsi_scsi_info = { .transfer_data = vscsi_transfer_data, .complete = vscsi_command_complete, - .cancel = vscsi_request_cancelled + .cancel = vscsi_request_cancelled, + .save_request = vscsi_save_request, + .load_request = vscsi_load_request, };static void spapr_vscsi_reset (VIOsPAPRDevice *dev)
@@ -991,6 +1056,20 @@ static Property spapr_vscsi_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static const VMStateDescription vmstate_spapr_vscsi = { + .name ="spapr_vscsi" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_SPAPR_VIO (vdev, VSCSIState), +/* VSCSI state */ +/* ???? */ + +VMSTATE_END_OF_LIST () + }, +}; +static void spapr_vscsi_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -1005,6 +1084,7 @@ static void spapr_vscsi_class_init(ObjectClass *klass, void *data) k->signal_mask =0x00000001 ; dc->props = spapr_vscsi_properties; k->rtce_window_size =0x10000000 ; + dc->vmsd = &vmstate_spapr_vscsi; }static const TypeInfo spapr_vscsi_info = {
Signature · 1 line
1.8.0
PATCH 8/11 pseries: savevm support for pseries machine
In reply to Anthony LiguoriFrom: David Gibson <[email protected]>
This adds the necessary pieces to implement savevm / migration for the pseries machine. The most complex part here is migrating the hash table - for the paravirtualized pseries machine the guest's hash page table is not stored within guest memory, but externally and the guest accesses it via hypercalls.
This patch uses a hypervisor reserved bit of the HPTE as a dirty bit (tracking changes to the HPTE itself, not the page it references). This is used to implement a live migration style incremental save and restore of the hash table contents.
Normally a hash table is 16MB but it can get bigger depending on how much RAM the guest has. Due to its nature, updates to it are random so the live migration style is used for it.
In addition it adds VMStateDescription information to save and restore the (few) remaining pieces of state information needed by the pseries machine.
---
Changes:
2013/09/07:
* added a comment about HPT size and migration style choice
--- hw/ppc/spapr.c | 269 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_hcall.c | 8 +- include/hw/ppc/spapr.h | 12 ++- 3 files changed, 281 insertions(+), 8 deletions(-)
hw/ppc/spapr.c +268 -1
@@ -32,6 +32,7 @@#include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "kvm_ppc.h" +#include "mmu-hash64.h" #include "hw/boards.h" #include "hw/ppc/ppc.h"
@@ -666,7 +667,7 @@ static void spapr_cpu_reset(void *opaque) env->spr[SPR_HIOR ] =0 ; - env->external_htab = spapr->htab; + env->external_htab = (uint8_t *)spapr->htab; env->htab_base =-1 ; env->htab_mask =HTAB_SIZE (spapr) -1 ; env->spr[SPR_SDR1] = (target_ulong)(uintptr_t)spapr->htab |
@@ -710,6 +711,268 @@ static int spapr_vga_init(PCIBus *pci_bus) } } +static const VMStateDescription vmstate_spapr = { + .name ="spapr" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (next_irq, sPAPREnvironment), + +/* RTC offset */ +VMSTATE_UINT64 (rtc_offset, sPAPREnvironment), + +VMSTATE_END_OF_LIST () + }, +}; + +#define HPTE (_table, _i) (void *)(((uint64_t *)(_table)) + ((_i) * 2)) +#define HPTE_VALID (_hpte) (tswap64(*((uint64_t *)(_hpte))) & HPTE64_V_VALID) +#define HPTE_DIRTY (_hpte) (tswap64(*((uint64_t *)(_hpte))) & HPTE64_V_HPTE_DIRTY) +#define CLEAN_HPTE (_hpte) ((*(uint64_t *)(_hpte)) &= tswap64(~HPTE64_V_HPTE_DIRTY)) + +static int htab_save_setup (QEMUFile *f,void *opaque) +{ +sPAPREnvironment *spapr = opaque; + + spapr->htab_save_index =0 ; + spapr->htab_first_pass = true; + +/* "Iteration" header */ +qemu_put_be32 (f, spapr->htab_shift); + +return 0 ; +} + +#define MAX_ITERATION_NS 5000000/* 5 ms */ + +static void htab_save_first_pass (QEMUFile *f,sPAPREnvironment *spapr, +int64_t max_ns) +{ +int htabslots =HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 ; +int index = spapr->htab_save_index; +int64_t starttime =qemu_get_clock_ns (rt_clock); + +assert (spapr->htab_first_pass); + +do { +int chunkstart; + +/* Consume invalid HPTEs */ +while ((index < htabslots) + && !HPTE_VALID (HPTE (spapr->htab, index))) { + index++; +CLEAN_HPTE (HPTE (spapr->htab, index)); + } + +/* Consume valid HPTEs */ + chunkstart = index; +while ((index < htabslots) + &&HPTE_VALID (HPTE (spapr->htab, index))) { + index++; +CLEAN_HPTE (HPTE (spapr->htab, index)); + } + +if (index > chunkstart) { +int n_valid = index - chunkstart; + +qemu_put_be32 (f, chunkstart); +qemu_put_be16 (f, n_valid); +qemu_put_be16 (f,0 ); +qemu_put_buffer (f,HPTE (spapr->htab, chunkstart), +HASH_PTE_SIZE_64 * n_valid); + +if ((qemu_get_clock_ns (rt_clock) - starttime) > max_ns) { +break ; + } + } + }while ((index < htabslots) && !qemu_file_rate_limit (f)); + +if (index >= htabslots) { +assert (index == htabslots); + index =0 ; + spapr->htab_first_pass = false; + } + spapr->htab_save_index = index; +} + +static bool htab_save_later_pass (QEMUFile *f,sPAPREnvironment *spapr, +int64_t max_ns) +{ +bool final = max_ns <0 ; +int htabslots =HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 ; +int examined =0 , sent =0 ; +int index = spapr->htab_save_index; +int64_t starttime =qemu_get_clock_ns (rt_clock); + +assert (!spapr->htab_first_pass); + +do { +int chunkstart, invalidstart; + +/* Consume non-dirty HPTEs */ +while ((index < htabslots) + && !HPTE_DIRTY (HPTE (spapr->htab, index))) { + index++; + examined++; + } + + chunkstart = index; +/* Consume valid dirty HPTEs */ +while ((index < htabslots) + &&HPTE_DIRTY (HPTE (spapr->htab, index)) + &&HPTE_VALID (HPTE (spapr->htab, index))) { +CLEAN_HPTE (HPTE (spapr->htab, index)); + index++; + examined++; + } + + invalidstart = index; +/* Consume invalid dirty HPTEs */ +while ((index < htabslots) + &&HPTE_DIRTY (HPTE (spapr->htab, index)) + && !HPTE_VALID (HPTE (spapr->htab, index))) { +CLEAN_HPTE (HPTE (spapr->htab, index)); + index++; + examined++; + } + +if (index > chunkstart) { +int n_valid = invalidstart - chunkstart; +int n_invalid = index - invalidstart; + +qemu_put_be32 (f, chunkstart); +qemu_put_be16 (f, n_valid); +qemu_put_be16 (f, n_invalid); +qemu_put_buffer (f,HPTE (spapr->htab, chunkstart), +HASH_PTE_SIZE_64 * n_valid); + sent += index - chunkstart; + +if (!final && (qemu_get_clock_ns (rt_clock) - starttime) > max_ns) { +break ; + } + } + +if (examined >= htabslots) { +break ; + } + +if (index >= htabslots) { +assert (index == htabslots); + index =0 ; + } + }while ((examined < htabslots) && (!qemu_file_rate_limit (f) || final)); + +if (index >= htabslots) { +assert (index == htabslots); + index =0 ; + } + + spapr->htab_save_index = index; + +return (examined >= htabslots) && (sent ==0 ); +} + +static int htab_save_iterate (QEMUFile *f,void *opaque) +{ +sPAPREnvironment *spapr = opaque; +bool nothingleft = false;; + +/* Iteration header */ +qemu_put_be32 (f,0 ); + +if (spapr->htab_first_pass) { +htab_save_first_pass (f, spapr,MAX_ITERATION_NS ); + }else { + nothingleft =htab_save_later_pass (f, spapr,MAX_ITERATION_NS ); + } + +/* End marker */ +qemu_put_be32 (f,0 ); +qemu_put_be16 (f,0 ); +qemu_put_be16 (f,0 ); + +return nothingleft ?1 :0 ; +} + +static int htab_save_complete (QEMUFile *f,void *opaque) +{ +sPAPREnvironment *spapr = opaque; + +/* Iteration header */ +qemu_put_be32 (f,0 ); + +htab_save_later_pass (f, spapr,-1 ); + +/* End marker */ +qemu_put_be32 (f,0 ); +qemu_put_be16 (f,0 ); +qemu_put_be16 (f,0 ); + +return 0 ; +} + +static int htab_load (QEMUFile *f,void *opaque,int version_id) +{ +sPAPREnvironment *spapr = opaque; +uint32_t section_hdr; + +if (version_id <1 || version_id >1 ) { +fprintf (stderr,"htab_load() bad version\n" ); +return -EINVAL ; + } + + section_hdr =qemu_get_be32 (f); + +if (section_hdr) { +/* First section, just the hash shift */ +if (spapr->htab_shift != section_hdr) { +return -EINVAL ; + } +return 0 ; + } + +while (true) { +uint32_t index; +uint16_t n_valid, n_invalid; + + index =qemu_get_be32 (f); + n_valid =qemu_get_be16 (f); + n_invalid =qemu_get_be16 (f); + +if ((index ==0 ) && (n_valid ==0 ) && (n_invalid ==0 )) { +/* End of Stream */ +break ; + } + +if ((index + n_valid + n_invalid) >= + (HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 )) { +/* Bad index in stream */ +fprintf (stderr,"htab_load() bad index %d (%hd+%hd entries) " +"in htab stream\n" , index, n_valid, n_invalid); +return -EINVAL ; + } + +if (n_valid) { +qemu_get_buffer (f,HPTE (spapr->htab, index), +HASH_PTE_SIZE_64 * n_valid); + } +if (n_invalid) { +memset (HPTE (spapr->htab, index + n_valid),0 , +HASH_PTE_SIZE_64 * n_invalid); + } + } + +return 0 ; +} + +static SaveVMHandlers savevm_htab_handlers = { + .save_live_setup = htab_save_setup, + .save_live_iterate = htab_save_iterate, + .save_live_complete = htab_save_complete, + .load_state = htab_load, +}; +/* pSeries LPAR / sPAPR hardware init */ static void ppc_spapr_init (QEMUMachineInitArgs *args) {
@@ -950,6 +1213,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args) spapr->entry_point =0x100 ; +vmstate_register (NULL ,0 , &vmstate_spapr, spapr); +register_savevm_live (NULL ,"spapr/htab" ,-1 ,1 , + &savevm_htab_handlers, spapr); +/* Prepare the device tree */ spapr->fdt_skel = spapr_create_fdt_skel(cpu_model, initrd_base, initrd_size,
hw/ppc/spapr_hcall.c +4 -4
@@ -115,7 +115,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr, }ppc_hash64_store_hpte1 (env, hpte, ptel);/* eieio(); FIXME: need some sort of barrier for smp? */ -ppc_hash64_store_hpte0 (env, hpte, pteh); +ppc_hash64_store_hpte0 (env, hpte, pteh |HPTE64_V_HPTE_DIRTY ); args[0 ] = pte_index + i;return H_SUCCESS ;
@@ -152,7 +152,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex, } *vp = v; *rp = r; -ppc_hash64_store_hpte0 (env, hpte,0 ); +ppc_hash64_store_hpte0 (env, hpte,HPTE64_V_HPTE_DIRTY ); rb =compute_tlbie_rb (v, r, ptex);ppc_tlb_invalidate_one (env, rb);return REMOVE_SUCCESS ;
@@ -282,11 +282,11 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr, r |= (flags <<48 ) &HPTE64_R_KEY_HI ; r |= flags & (HPTE64_R_PP |HPTE64_R_N |HPTE64_R_KEY_LO ); rb =compute_tlbie_rb (v, r, pte_index); -ppc_hash64_store_hpte0 (env, hpte, v & ~HPTE64_V_VALID ); +ppc_hash64_store_hpte0 (env, hpte, (v & ~HPTE64_V_VALID ) |HPTE64_V_HPTE_DIRTY );ppc_tlb_invalidate_one (env, rb);ppc_hash64_store_hpte1 (env, hpte, r);/* Don't need a memory barrier, due to qemu's global lock */ -ppc_hash64_store_hpte0 (env, hpte, v); +ppc_hash64_store_hpte0 (env, hpte, v |HPTE64_V_HPTE_DIRTY );return H_SUCCESS ; }
include/hw/ppc/spapr.h +9 -3
@@ -9,6 +9,8 @@ struct sPAPRPHBState;struct sPAPRNVRAM ;struct icp_state ; +#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL + typedef struct sPAPREnvironment { struct VIOsPAPRBus *vio_bus; QLIST_HEAD(, sPAPRPHBState) phbs;
@@ -17,20 +19,24 @@ typedef struct sPAPREnvironment {hwaddr ram_limit;void *htab; -long htab_shift; +uint32_t htab_shift;hwaddr rma_size;int vrma_adjust;hwaddr fdt_addr, rtas_addr;long rtas_size;void *fdt_skel;target_ulong entry_point; -int next_irq; -int rtc_offset; +uint32_t next_irq; +uint64_t rtc_offset;char *cpu_model;bool has_graphics;uint32_t epow_irq;Notifier epow_notifier; + +/* Migration state */ +int htab_save_index; +bool htab_first_pass; } sPAPREnvironment;#define H_SUCCESS 0
Signature · 1 line
1.8.0
PATCH 9/11 pseries: savevm support for PCI host bridge
In reply to Anthony LiguoriFrom: David Gibson <[email protected]>
This adds the necessary support for saving the state of the PAPR virtual PCI host bridge (or host bridges).
--- hw/ppc/spapr_pci.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci-host/spapr.h | 6 +++--- 2 files changed, 52 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +49 -0
@@ -699,6 +699,54 @@ static Property spapr_phb_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static const VMStateDescription vmstate_spapr_pci_lsi = { + .name ="spapr_pci/lsi" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { + VMSTATE_UINT32_EQUAL(irq, struct spapr_pci_lsi), + +VMSTATE_END_OF_LIST () + }, +}; + +static const VMStateDescription vmstate_spapr_pci_msi = { + .name ="spapr_pci/lsi" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { + VMSTATE_UINT32(config_addr, struct spapr_pci_msi), + VMSTATE_UINT32(irq, struct spapr_pci_msi), + VMSTATE_UINT32(nvec, struct spapr_pci_msi), + +VMSTATE_END_OF_LIST () + }, +}; + +static const VMStateDescription vmstate_spapr_pci = { + .name ="spapr_pci" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64_EQUAL (buid, sPAPRPHBState), +VMSTATE_UINT32_EQUAL (dma_liobn, sPAPRPHBState), +VMSTATE_UINT64_EQUAL (mem_win_addr, sPAPRPHBState), +VMSTATE_UINT64_EQUAL (mem_win_size, sPAPRPHBState), +VMSTATE_UINT64_EQUAL (io_win_addr, sPAPRPHBState), +VMSTATE_UINT64_EQUAL (io_win_size, sPAPRPHBState), +VMSTATE_UINT64_EQUAL (msi_win_addr, sPAPRPHBState), +VMSTATE_STRUCT_ARRAY (lsi_table, sPAPRPHBState,PCI_NUM_PINS ,0 , + vmstate_spapr_pci_lsi, struct spapr_pci_lsi), +VMSTATE_STRUCT_ARRAY (msi_table, sPAPRPHBState,SPAPR_MSIX_MAX_DEVS ,0 , + vmstate_spapr_pci_msi, struct spapr_pci_msi), + +VMSTATE_END_OF_LIST () + }, +}; +static const char *spapr_phb_root_bus_path (PCIHostState *host_bridge,PCIBus *rootbus) {
@@ -717,6 +765,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data) sdc->init = spapr_phb_init; dc->props = spapr_phb_properties; dc->reset = spapr_phb_reset; + dc->vmsd = &vmstate_spapr_pci; }static const TypeInfo spapr_phb_info = {
include/hw/pci-host/spapr.h +3 -3
@@ -52,14 +52,14 @@ typedef struct sPAPRPHBState {sPAPRTCETable *tcet;AddressSpace iommu_as; -struct { +struct spapr_pci_lsi {uint32_t irq; } lsi_table[PCI_NUM_PINS ]; -struct { +struct spapr_pci_msi {uint32_t config_addr;uint32_t irq; -int nvec; +uint32_t nvec; } msi_table[SPAPR_MSIX_MAX_DEVS ];QLIST_ENTRY (sPAPRPHBState) list;
Signature · 1 line
1.8.0
PATCH 10/11 pseries: savevm support with KVM
In reply to Anthony LiguoriFrom: Alexey Kardashevskiy <[email protected]>
At present, the savevm / migration support for the pseries machine will not work when KVM is enabled. That's because KVM manages the guest's hash page table in the host kernel, so qemu has no visibility of it. This patch fixes this by using new kernel interfaces to extract and reinsert the guest's hash table during the migration process.
--- hw/ppc/spapr.c | 106 +++++++++++++++++++++++++++++++++++++++---------- include/hw/ppc/spapr.h | 1 + target-ppc/kvm.c | 69 ++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 22 ++++++++++ 4 files changed, 176 insertions(+), 22 deletions(-)
hw/ppc/spapr.c +84 -22
@@ -735,17 +735,27 @@ static int htab_save_setup(QEMUFile *f, void *opaque) {sPAPREnvironment *spapr = opaque; - spapr->htab_save_index =0 ; - spapr->htab_first_pass = true; -/* "Iteration" header */ qemu_put_be32 (f, spapr->htab_shift); +if (spapr->htab) { + spapr->htab_save_index =0 ; + spapr->htab_first_pass = true; + }else { +assert (kvm_enabled ()); + + spapr->htab_fd =kvmppc_get_htab_fd (false); +if (spapr->htab_fd <0 ) { +fprintf (stderr,"Unable to open fd for reading hash table from KVM: %s\n" , +strerror (errno)); +return -1 ; + } + } + +return 0 ; } -#define MAX_ITERATION_NS 5000000/* 5 ms */ -static void htab_save_first_pass (QEMUFile *f,sPAPREnvironment *spapr,int64_t max_ns) {
@@ -796,8 +806,8 @@ static void htab_save_first_pass(QEMUFile *f, sPAPREnvironment *spapr, spapr->htab_save_index = index; } -static bool htab_save_later_pass (QEMUFile *f,sPAPREnvironment *spapr, -int64_t max_ns) +static int htab_save_later_pass (QEMUFile *f,sPAPREnvironment *spapr, +int64_t max_ns) {bool final = max_ns <0 ;int htabslots =HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 ;
@@ -870,21 +880,32 @@ static bool htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr, spapr->htab_save_index = index; -return (examined >= htabslots) && (sent ==0 ); +return (examined >= htabslots) && (sent ==0 ) ?1 :0 ; } +#define MAX_ITERATION_NS 5000000/* 5 ms */ +#define MAX_KVM_BUF_SIZE 2048 +static int htab_save_iterate (QEMUFile *f,void *opaque) {sPAPREnvironment *spapr = opaque; -bool nothingleft = false;; +int rc =0 ;/* Iteration header */ qemu_put_be32 (f,0 ); -if (spapr->htab_first_pass) { +if (!spapr->htab) { +assert (kvm_enabled ()); + + rc =kvmppc_save_htab (f, spapr->htab_fd, +MAX_KVM_BUF_SIZE ,MAX_ITERATION_NS ); +if (rc <0 ) { +return rc; + } + }else if (spapr->htab_first_pass) {htab_save_first_pass (f, spapr,MAX_ITERATION_NS ); }else { - nothingleft =htab_save_later_pass (f, spapr,MAX_ITERATION_NS ); + rc =htab_save_later_pass (f, spapr,MAX_ITERATION_NS ); }/* End marker */
@@ -892,7 +913,7 @@ static int htab_save_iterate(QEMUFile *f, void *opaque)qemu_put_be16 (f,0 );qemu_put_be16 (f,0 ); -return nothingleft ?1 :0 ; +return rc; }static int htab_save_complete (QEMUFile *f,void *opaque)
@@ -902,7 +923,20 @@ static int htab_save_complete(QEMUFile *f, void *opaque)/* Iteration header */ qemu_put_be32 (f,0 ); -htab_save_later_pass (f, spapr,-1 ); +if (!spapr->htab) { +int rc; + +assert (kvm_enabled ()); + + rc =kvmppc_save_htab (f, spapr->htab_fd,MAX_KVM_BUF_SIZE ,-1 ); +if (rc <0 ) { +return rc; + } +close (spapr->htab_fd); + spapr->htab_fd =-1 ; + }else { +htab_save_later_pass (f, spapr,-1 ); + }/* End marker */ qemu_put_be32 (f,0 );
@@ -916,6 +950,7 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id) {sPAPREnvironment *spapr = opaque;uint32_t section_hdr; +int fd =-1 ;if (version_id <1 || version_id >1 ) {fprintf (stderr,"htab_load() bad version\n" );
@@ -932,6 +967,16 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } +if (!spapr->htab) { +assert (kvm_enabled ()); + + fd =kvmppc_get_htab_fd (true); +if (fd <0 ) { +fprintf (stderr,"Unable to open fd to restore KVM hash table: %s\n" , +strerror (errno)); + } + } +while (true) {uint32_t index;uint16_t n_valid, n_invalid;
@@ -945,24 +990,41 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id)break ; } -if ((index + n_valid + n_invalid) >= +if ((index + n_valid + n_invalid) > (HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 )) {/* Bad index in stream */ fprintf (stderr,"htab_load() bad index %d (%hd+%hd entries) " -"in htab stream\n" , index, n_valid, n_invalid); +"in htab stream (htab_shift=%d)\n" , index, n_valid, n_invalid, + spapr->htab_shift);return -EINVAL ; } -if (n_valid) { -qemu_get_buffer (f,HPTE (spapr->htab, index), -HASH_PTE_SIZE_64 * n_valid); - } -if (n_invalid) { -memset (HPTE (spapr->htab, index + n_valid),0 , -HASH_PTE_SIZE_64 * n_invalid); +if (spapr->htab) { +if (n_valid) { +qemu_get_buffer (f,HPTE (spapr->htab, index), +HASH_PTE_SIZE_64 * n_valid); + } +if (n_invalid) { +memset (HPTE (spapr->htab, index + n_valid),0 , +HASH_PTE_SIZE_64 * n_invalid); + } + }else { +int rc; + +assert (fd >=0 ); + + rc =kvmppc_load_htab_chunk (f, fd, index, n_valid, n_invalid); +if (rc <0 ) { +return rc; + } } } +if (!spapr->htab) { +assert (fd >=0 ); +close (fd); + } +return 0 ; }
include/hw/ppc/spapr.h +1 -0
@@ -37,6 +37,7 @@ typedef struct sPAPREnvironment {/* Migration state */ int htab_save_index;bool htab_first_pass; +int htab_fd; } sPAPREnvironment;#define H_SUCCESS 0
target-ppc/kvm.c +69 -0
87 lines not on this page · raw message
target-ppc/kvm_ppc.h +22 -0
@@ -38,6 +38,10 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);#endif /* !CONFIG_USER_ONLY */ int kvmppc_fixup_cpu (PowerPCCPU *cpu);bool kvmppc_has_cap_epr (void ); +int kvmppc_get_htab_fd (bool write); +int kvmppc_save_htab (QEMUFile *f,int fd,size_t bufsize,int64_t max_ns); +int kvmppc_load_htab_chunk (QEMUFile *f,int fd,uint32_t index, +uint16_t n_valid,uint16_t n_invalid);#else
@@ -159,6 +163,24 @@ static inline bool kvmppc_has_cap_epr(void) {return false; } + +static inline int kvmppc_get_htab_fd (bool write) +{ +return -1 ; +} + +static inline int kvmppc_save_htab (QEMUFile *f,int fd,size_t bufsize, +int64_t max_ns) +{ +abort (); +} + +static inline int kvmppc_load_htab_chunk (QEMUFile *f,int fd,uint32_t index, +uint16_t n_valid,uint16_t n_invalid) +{ +abort (); +} +#endif #ifndef CONFIG_KVM
Signature · 1 line
1.8.0
PATCH 11/11 xics: rename types to be sane and follow coding style
In reply to Anthony LiguoriQuoted 1 line
From Ben:
Basically, in HW the layout of the interrupt network is:
- One ICP per processor thread (the "presenter"). This contains the
registers to fetch a pending interrupt (ack), EOI, and control the processor priority.
- One ICS per logical source of interrupts (ie, one per PCI host
bridge, and a few others here or there). This contains the per-interrupt source configuration (target processor(s), priority, mask) and the per-interrupt internal state.
Under PAPR, there is a single "virtual" ICS ... somewhat (it's a bit oddball what pHyp does here, arguably there are two but we can ignore that distinction). There is no register level access. A pair of firmware (RTAS) calls is used to configure each virtual interrupt.
So our model here is somewhat the same. We have one ICS in the emulated XICS which arguably *is* the emulated XICS, there's no point making it a separate "device", that would just be gross, and each VCPU has an associated ICP.
Yet we call the "XICS" struct icp_state and then the ICPs 'struct icp_server_state'. It's particularly confusing when all of the functions have xics_prefixes yet take *icp arguments.
Rename:
struct icp_state -> XICSState
struct icp_server_state -> ICPState
struct ics_state -> ICSState
struct ics_irq_state -> ICSIRQState
--- hw/intc/xics.c | 345 +++++++++++++++++++++++++++++++++---------------- hw/ppc/spapr.c | 28 ++++ include/hw/ppc/spapr.h | 3 +- include/hw/ppc/xics.h | 74 ++++++++++- 4 files changed, 330 insertions(+), 120 deletions(-)
hw/intc/xics.c +233 -112
@@ -34,34 +34,19 @@* ICP: Presentation layer */ -struct icp_server_state { -uint32_t xirr; -uint8_t pending_priority; -uint8_t mfrr; -qemu_irq output; -}; -#define XISR_MASK 0x00ffffff#define CPPR_MASK 0xff000000#define XISR (ss) (((ss)->xirr) & XISR_MASK)#define CPPR (ss) (((ss)->xirr) >> 24) -struct ics_state ; - -struct icp_state { -long nr_servers; -struct icp_server_state *ss; -struct ics_state *ics; -}; - -static void ics_reject (struct ics_state *ics,int nr); -static void ics_resend (struct ics_state *ics); -static void ics_eoi (struct ics_state *ics,int nr); +static void ics_reject (ICSState *ics,int nr); +static void ics_resend (ICSState *ics); +static void ics_eoi (ICSState *ics,int nr); -static void icp_check_ipi (struct icp_state *icp,int server) +static void icp_check_ipi (XICSState *icp,int server) { -struct icp_server_state *ss = icp->ss + server; +ICPState *ss = icp->ss + server;if (XISR (ss) && (ss->pending_priority <= ss->mfrr)) {return ;
@@ -78,9 +63,9 @@ static void icp_check_ipi(struct icp_state *icp, int server)qemu_irq_raise (ss->output); } -static void icp_resend (struct icp_state *icp,int server) +static void icp_resend (XICSState *icp,int server) { -struct icp_server_state *ss = icp->ss + server; +ICPState *ss = icp->ss + server;if (ss->mfrr <CPPR (ss)) {icp_check_ipi (icp, server);
@@ -88,9 +73,9 @@ static void icp_resend(struct icp_state *icp, int server)ics_resend (icp->ics); } -static void icp_set_cppr (struct icp_state *icp,int server,uint8_t cppr) +static void icp_set_cppr (XICSState *icp,int server,uint8_t cppr) { -struct icp_server_state *ss = icp->ss + server; +ICPState *ss = icp->ss + server;uint8_t old_cppr;uint32_t old_xisr;
@@ -112,9 +97,9 @@ static void icp_set_cppr(struct icp_state *icp, int server, uint8_t cppr) } } -static void icp_set_mfrr (struct icp_state *icp,int server,uint8_t mfrr) +static void icp_set_mfrr (XICSState *icp,int server,uint8_t mfrr) { -struct icp_server_state *ss = icp->ss + server; +ICPState *ss = icp->ss + server; ss->mfrr = mfrr;if (mfrr <CPPR (ss)) {
@@ -122,7 +107,7 @@ static void icp_set_mfrr(struct icp_state *icp, int server, uint8_t mfrr) } } -static uint32_t icp_accept (struct icp_server_state *ss) +static uint32_t icp_accept (ICPState *ss) {uint32_t xirr = ss->xirr;
@@ -135,9 +120,9 @@ static uint32_t icp_accept(struct icp_server_state *ss)return xirr; } -static void icp_eoi (struct icp_state *icp,int server,uint32_t xirr) +static void icp_eoi (XICSState *icp,int server,uint32_t xirr) { -struct icp_server_state *ss = icp->ss + server; +ICPState *ss = icp->ss + server;/* Send EOI -> ICS */ ss->xirr = (ss->xirr & ~CPPR_MASK ) | (xirr &CPPR_MASK );
@@ -148,9 +133,9 @@ static void icp_eoi(struct icp_state *icp, int server, uint32_t xirr) } } -static void icp_irq (struct icp_state *icp,int server,int nr,uint8_t priority) +static void icp_irq (XICSState *icp,int server,int nr,uint8_t priority) { -struct icp_server_state *ss = icp->ss + server; +ICPState *ss = icp->ss + server;trace_xics_icp_irq (server, nr, priority);
@@ -168,39 +153,59 @@ static void icp_irq(struct icp_state *icp, int server, int nr, uint8_t priority) } } -/* -* ICS: Source layer -*/ - -struct ics_irq_state { -int server; -uint8_t priority; -uint8_t saved_priority; -#define XICS_STATUS_ASSERTED 0x1 -#define XICS_STATUS_SENT 0x2 -#define XICS_STATUS_REJECTED 0x4 -#define XICS_STATUS_MASKED_PENDING 0x8 -uint8_t status; +static const VMStateDescription vmstate_icp_server = { + .name ="icp/server" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +/* Sanity check */ +VMSTATE_UINT32 (xirr, ICPState), +VMSTATE_UINT8 (pending_priority, ICPState), +VMSTATE_UINT8 (mfrr, ICPState), +VMSTATE_END_OF_LIST () + }, }; -struct ics_state { -int nr_irqs; -int offset; -qemu_irq *qirqs; -bool *islsi; -struct ics_irq_state *irqs; -struct icp_state *icp; +static void icp_reset (DeviceState *dev) +{ +ICPState *icp =ICP (dev); + + icp->xirr =0 ; + icp->pending_priority =0xff ; + icp->mfrr =0xff ; + +/* Make all outputs are deasserted */ +qemu_set_irq (icp->output,0 ); +} + +static void icp_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = icp_reset; + dc->vmsd = &vmstate_icp_server; +} + +static TypeInfo icp_info = { + .name =TYPE_ICP , + .parent =TYPE_DEVICE , + .instance_size =sizeof (ICPState), + .class_init = icp_class_init, }; -static int ics_valid_irq (struct ics_state *ics,uint32_t nr) +/* +* ICS: Source layer +*/ +static int ics_valid_irq (ICSState *ics,uint32_t nr) {return (nr >= ics->offset) && (nr < (ics->offset + ics->nr_irqs)); } -static void resend_msi (struct ics_state *ics,int srcno) +static void resend_msi (ICSState *ics,int srcno) { -struct ics_irq_state *irq = ics->irqs + srcno; +ICSIRQState *irq = ics->irqs + srcno;/* FIXME: filter by server#? */ if (irq->status &XICS_STATUS_REJECTED ) {
@@ -212,9 +217,9 @@ static void resend_msi(struct ics_state *ics, int srcno) } } -static void resend_lsi (struct ics_state *ics,int srcno) +static void resend_lsi (ICSState *ics,int srcno) { -struct ics_irq_state *irq = ics->irqs + srcno; +ICSIRQState *irq = ics->irqs + srcno;if ((irq->priority !=0xff ) && (irq->status & XICS_STATUS_ASSERTED)
@@ -224,9 +229,9 @@ static void resend_lsi(struct ics_state *ics, int srcno) } } -static void set_irq_msi (struct ics_state *ics,int srcno,int val) +static void set_irq_msi (ICSState *ics,int srcno,int val) { -struct ics_irq_state *irq = ics->irqs + srcno; +ICSIRQState *irq = ics->irqs + srcno;trace_xics_set_irq_msi (srcno, srcno + ics->offset);
@@ -240,9 +245,9 @@ static void set_irq_msi(struct ics_state *ics, int srcno, int val) } } -static void set_irq_lsi (struct ics_state *ics,int srcno,int val) +static void set_irq_lsi (ICSState *ics,int srcno,int val) { -struct ics_irq_state *irq = ics->irqs + srcno; +ICSIRQState *irq = ics->irqs + srcno;trace_xics_set_irq_lsi (srcno, srcno + ics->offset);if (val) {
@@ -255,7 +260,7 @@ static void set_irq_lsi(struct ics_state *ics, int srcno, int val)static void ics_set_irq (void *opaque,int srcno,int val) { -struct ics_state *ics = (struct ics_state *)opaque; +ICSState *ics = (ICSState *)opaque;if (ics->islsi[srcno]) {set_irq_lsi (ics, srcno, val);
@@ -264,9 +269,9 @@ static void ics_set_irq(void *opaque, int srcno, int val) } } -static void write_xive_msi (struct ics_state *ics,int srcno) +static void write_xive_msi (ICSState *ics,int srcno) { -struct ics_irq_state *irq = ics->irqs + srcno; +ICSIRQState *irq = ics->irqs + srcno;if (!(irq->status &XICS_STATUS_MASKED_PENDING ) || (irq->priority ==0xff )) {
@@ -277,16 +282,16 @@ static void write_xive_msi(struct ics_state *ics, int srcno)icp_irq (ics->icp, irq->server, srcno + ics->offset, irq->priority); } -static void write_xive_lsi (struct ics_state *ics,int srcno) +static void write_xive_lsi (ICSState *ics,int srcno) {resend_lsi (ics, srcno); } -static void ics_write_xive (struct ics_state *ics,int nr,int server, +static void ics_write_xive (ICSState *ics,int nr,int server,uint8_t priority,uint8_t saved_priority) {int srcno = nr - ics->offset; -struct ics_irq_state *irq = ics->irqs + srcno; +ICSIRQState *irq = ics->irqs + srcno; irq->server = server; irq->priority = priority;
@@ -301,16 +306,16 @@ static void ics_write_xive(struct ics_state *ics, int nr, int server, } } -static void ics_reject (struct ics_state *ics,int nr) +static void ics_reject (ICSState *ics,int nr) { -struct ics_irq_state *irq = ics->irqs + nr - ics->offset; +ICSIRQState *irq = ics->irqs + nr - ics->offset;trace_xics_ics_reject (nr, nr - ics->offset); irq->status |=XICS_STATUS_REJECTED ;/* Irrelevant but harmless for LSI */ irq->status &= ~XICS_STATUS_SENT ;/* Irrelevant but harmless for MSI */ } -static void ics_resend (struct ics_state *ics) +static void ics_resend (ICSState *ics) {int i;
@@ -324,10 +329,10 @@ static void ics_resend(struct ics_state *ics) } } -static void ics_eoi (struct ics_state *ics,int nr) +static void ics_eoi (ICSState *ics,int nr) {int srcno = nr - ics->offset; -struct ics_irq_state *irq = ics->irqs + srcno; +ICSIRQState *irq = ics->irqs + srcno;trace_xics_ics_eoi (nr);
@@ -336,11 +341,92 @@ static void ics_eoi(struct ics_state *ics, int nr) } } +static void ics_reset (DeviceState *dev) +{ +ICSState *ics =ICS (dev); +int i; + +memset (ics->irqs,0 ,sizeof (ICSIRQState) * ics->nr_irqs); +for (i =0 ; i < ics->nr_irqs; i++) { + ics->irqs[i].priority =0xff ; + ics->irqs[i].saved_priority =0xff ; + } +} + +static int ics_post_load (void *opaque,int version_id) +{ +int i; +ICSState *ics = opaque; + +for (i =0 ; i < ics->icp->nr_servers; i++) { +icp_resend (ics->icp, i); + } + +return 0 ; +} + +static const VMStateDescription vmstate_ics_irq = { + .name ="ics/irq" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (server, ICSIRQState), +VMSTATE_UINT8 (priority, ICSIRQState), +VMSTATE_UINT8 (saved_priority, ICSIRQState), +VMSTATE_UINT8 (status, ICSIRQState), +VMSTATE_END_OF_LIST () + }, +}; + +static const VMStateDescription vmstate_ics = { + .name ="ics" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .post_load = ics_post_load, + .fields = (VMStateField []) { +/* Sanity check */ +VMSTATE_UINT32_EQUAL (nr_irqs, ICSState), + +VMSTATE_STRUCT_VARRAY_POINTER_UINT32 (irqs, ICSState, nr_irqs, + vmstate_ics_irq, ICSIRQState), +VMSTATE_END_OF_LIST () + }, +}; + +static int ics_realize (DeviceState *dev) +{ +ICSState *ics =ICS (dev); + + ics->irqs =g_malloc0 (ics->nr_irqs *sizeof (ICSIRQState)); + ics->islsi =g_malloc0 (ics->nr_irqs *sizeof (bool )); + ics->qirqs =qemu_allocate_irqs (ics_set_irq, ics, ics->nr_irqs); + +return 0 ; +} + +static void ics_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->init = ics_realize; + dc->vmsd = &vmstate_ics; + dc->reset = ics_reset; +} + +static TypeInfo ics_info = { + .name =TYPE_ICS , + .parent =TYPE_DEVICE , + .instance_size =sizeof (ICSState), + .class_init = ics_class_init, +}; +/* * Exported functions */ -qemu_irq xics_get_qirq (struct icp_state *icp,int irq) +qemu_irq xics_get_qirq (XICSState *icp,int irq) {if (!ics_valid_irq (icp->ics, irq)) {return NULL ;
@@ -349,13 +435,17 @@ qemu_irq xics_get_qirq(struct icp_state *icp, int irq)return icp->ics->qirqs[irq - icp->ics->offset]; } -void xics_set_irq_type (struct icp_state *icp,int irq,bool lsi) +void xics_set_irq_type (XICSState *icp,int irq,bool lsi) {assert (ics_valid_irq (icp->ics, irq)); icp->ics->islsi[irq - icp->ics->offset] = lsi; } +/* +* Guest interfaces +*/ +static target_ulong h_cppr (PowerPCCPU *cpu,sPAPREnvironment *spapr,target_ulong opcode,target_ulong *args) {
@@ -405,7 +495,7 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPREnvironment *spapr, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { - struct ics_state *ics = spapr->icp->ics; + ICSState *ics = spapr->icp->ics;uint32_t nr, server, priority;if ((nargs !=3 ) || (nret !=1 )) {
@@ -433,7 +523,7 @@ static void rtas_get_xive(PowerPCCPU *cpu, sPAPREnvironment *spapr, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { - struct ics_state *ics = spapr->icp->ics; + ICSState *ics = spapr->icp->ics;uint32_t nr;if ((nargs !=1 ) || (nret !=3 )) {
@@ -458,7 +548,7 @@ static void rtas_int_off(PowerPCCPU *cpu, sPAPREnvironment *spapr, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { - struct ics_state *ics = spapr->icp->ics; + ICSState *ics = spapr->icp->ics;uint32_t nr;if ((nargs !=1 ) || (nret !=1 )) {
@@ -484,7 +574,7 @@ static void rtas_int_on(PowerPCCPU *cpu, sPAPREnvironment *spapr, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { - struct ics_state *ics = spapr->icp->ics; + ICSState *ics = spapr->icp->ics;uint32_t nr;if ((nargs !=1 ) || (nret !=1 )) {
@@ -506,32 +596,27 @@ static void rtas_int_on(PowerPCCPU *cpu, sPAPREnvironment *spapr,rtas_st (rets,0 ,0 );/* Success */ } -static void xics_reset (void *opaque) +/* +* XICS +*/ + +static void xics_reset (DeviceState *d) { -struct icp_state *icp = (struct icp_state *)opaque; -struct ics_state *ics = icp->ics; +XICSState *icp =XICS (d);int i;for (i =0 ; i < icp->nr_servers; i++) { - icp->ss[i].xirr =0 ; - icp->ss[i].pending_priority =0xff ; - icp->ss[i].mfrr =0xff ; -/* Make all outputs are deasserted */ -qemu_set_irq (icp->ss[i].output,0 ); +device_reset (DEVICE (&icp->ss[i])); } -memset (ics->irqs,0 ,sizeof (struct ics_irq_state ) * ics->nr_irqs); -for (i =0 ; i < ics->nr_irqs; i++) { - ics->irqs[i].priority =0xff ; - ics->irqs[i].saved_priority =0xff ; - } +device_reset (DEVICE (icp->ics)); } -void xics_cpu_setup (struct icp_state *icp,PowerPCCPU *cpu) +void xics_cpu_setup (XICSState *icp,PowerPCCPU *cpu) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -struct icp_server_state *ss = &icp->ss[cs->cpu_index]; +ICPState *ss = &icp->ss[cs->cpu_index];assert (cs->cpu_index < icp->nr_servers);
@@ -551,37 +636,73 @@ void xics_cpu_setup(struct icp_state *icp, PowerPCCPU *cpu) } } -struct icp_state *xics_system_init (int nr_servers,int nr_irqs) +static void xics_realize (DeviceState *dev,Error **errp) { -struct icp_state *icp; -struct ics_state *ics; - - icp =g_malloc0 (sizeof (*icp)); - icp->nr_servers = nr_servers; - icp->ss =g_malloc0 (icp->nr_servers*sizeof (struct icp_server_state )); +XICSState *icp =XICS (dev); +ICSState *ics = icp->ics; +int i; - ics =g_malloc0 (sizeof (*ics)); - ics->nr_irqs = nr_irqs; + ics->nr_irqs = icp->nr_irqs; ics->offset =XICS_IRQ_BASE ; - ics->irqs =g_malloc0 (nr_irqs *sizeof (struct ics_irq_state )); - ics->islsi =g_malloc0 (nr_irqs *sizeof (bool )); - - icp->ics = ics; ics->icp = icp; +qdev_init_nofail (DEVICE (ics)); - ics->qirqs =qemu_allocate_irqs (ics_set_irq, ics, nr_irqs); + icp->ss =g_malloc0 (icp->nr_servers*sizeof (ICPState)); +for (i =0 ; i < icp->nr_servers; i++) { +char buffer[32 ]; +object_initialize (&icp->ss[i],TYPE_ICP ); +snprintf (buffer,sizeof (buffer),"icp[%d]" , i); +object_property_add_child (OBJECT (icp), buffer,OBJECT (&icp->ss[i]),NULL ); +qdev_init_nofail (DEVICE (&icp->ss[i])); + } +} -spapr_register_hypercall (H_CPPR , h_cppr); -spapr_register_hypercall (H_IPI , h_ipi); -spapr_register_hypercall (H_XIRR , h_xirr); -spapr_register_hypercall (H_EOI , h_eoi); +static void xics_initfn (Object *obj) +{ +XICSState *xics =XICS (obj); + + xics->ics =ICS (object_new (TYPE_ICS )); +object_property_add_child (obj,"ics" ,OBJECT (xics->ics),NULL ); +} + +static Property xics_properties[] = { +DEFINE_PROP_UINT32 ("nr_servers" , XICSState, nr_servers,-1 ), +DEFINE_PROP_UINT32 ("nr_irqs" , XICSState, nr_irqs,-1 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void xics_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = xics_realize; + dc->props = xics_properties; + dc->reset = xics_reset;spapr_rtas_register ("ibm,set-xive" , rtas_set_xive);spapr_rtas_register ("ibm,get-xive" , rtas_get_xive);spapr_rtas_register ("ibm,int-off" , rtas_int_off);spapr_rtas_register ("ibm,int-on" , rtas_int_on); -qemu_register_reset (xics_reset, icp); +spapr_register_hypercall (H_CPPR , h_cppr); +spapr_register_hypercall (H_IPI , h_ipi); +spapr_register_hypercall (H_XIRR , h_xirr); +spapr_register_hypercall (H_EOI , h_eoi); +} + +static const TypeInfo xics_info = { + .name =TYPE_XICS , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XICSState), + .class_init = xics_class_init, + .instance_init = xics_initfn, +}; -return icp; +static void xics_register_types (void ) +{ +type_register_static (&xics_info); +type_register_static (&ics_info); +type_register_static (&icp_info); } + +type_init (xics_register_types)
hw/ppc/spapr.c +28 -0
@@ -129,6 +129,34 @@ int spapr_allocate_irq_block(int num, bool lsi)return first; } +static XICSState *try_create_xics (const char *type,int nr_servers, +int nr_irqs) +{ +DeviceState *dev; + + dev =qdev_create (NULL , type); +qdev_prop_set_uint32 (dev,"nr_servers" , nr_servers); +qdev_prop_set_uint32 (dev,"nr_irqs" , nr_irqs); +if (qdev_init (dev) <0 ) { +return NULL ; + } + +return XICS (dev); +} + +static XICSState *xics_system_init (int nr_servers,int nr_irqs) +{ +XICSState *icp =NULL ; + + icp =try_create_xics (TYPE_XICS , nr_servers, nr_irqs); +if (!icp) { +perror ("Failed to create XICS\n" ); +abort (); + } + +return icp; +} +static int spapr_fixup_cpu_dt (void *fdt,sPAPREnvironment *spapr) {int ret =0 , offset;
include/hw/ppc/spapr.h +1 -2
@@ -7,7 +7,6 @@struct VIOsPAPRBus ;struct sPAPRPHBState ;struct sPAPRNVRAM ; -struct icp_state ;#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL
@@ -15,7 +14,7 @@ typedef struct sPAPREnvironment {struct VIOsPAPRBus *vio_bus; QLIST_HEAD(, sPAPRPHBState) phbs;struct sPAPRNVRAM *nvram; -struct icp_state *icp; +XICSState *icp;hwaddr ram_limit;void *htab;
include/hw/ppc/xics.h +68 -6
83 lines not on this page · raw message
Signature · 1 line
1.8.0
Quoted 9 lines · Anthony Liguori
This series is based on Alexey's series:
spapr: migration, pci, msi, power8
Which in turn was based on work by David Gibson.
I've removed the bits not related to migration and made the following changes:
Quoted 8 lines
1) QOMify TCE tables and XICS
2) Do everything in terms of VMStateDescriptions
3) Fix endianness problem with TCE table translation
a) Drop theVMSTATE_DIVIDEthing in the processI've tested this with a TCG pseries guest on an
x86_64host.
It did not compile (fixed, patch is posted) and it fails to migrate with enabled KVM. Don't know why yet, will have a look tomorrow.
Signature · 1 line
Alexey
Quoted 14 lines · Alexey Kardashevskiy
Quoted 13 lines · Anthony Liguori
This series is based on Alexey's series:
spapr: migration, pci, msi, power8
Which in turn was based on work by David Gibson.
I've removed the bits not related to migration and made the following changes:
1) QOMify TCE tables and XICS
2) Do everything in terms of VMStateDescriptions
Quoted 8 lines
Quoted 4 lines
3) Fix endianness problem with TCE table translation
a) Drop theVMSTATE_DIVIDEthing in the processI've tested this with a TCG pseries guest on an
x86_64host.It did not compile (fixed, patch is posted) and it fails to migrate with enabled KVM.
With in-kernel XICS? That's not in this series..
Regards,
Anthony Liguori
Quoted 5 lines
Don't know why yet, will have a look tomorrow.
Signature · 1 line
Alexey
Quoted 19 lines · Anthony Liguori
Quoted 17 lines · Alexey Kardashevskiy
Quoted 16 lines · Anthony Liguori
This series is based on Alexey's series:
spapr: migration, pci, msi, power8
Which in turn was based on work by David Gibson.
I've removed the bits not related to migration and made the following changes:
1) QOMify TCE tables and XICS
2) Do everything in terms of VMStateDescriptions
3) Fix endianness problem with TCE table translation
a) Drop theVMSTATE_DIVIDEthing in the process
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I've tested this with a TCG pseries guest on an
x86_64host.It did not compile (fixed, patch is posted) and it fails to migrate with enabled KVM.
With in-kernel XICS? That's not in this series..
No, as is, without any of my patches. I suspect rather HPTE than XICS though.
Signature · 1 line
Alexey
Quoted 23 lines · Alexey Kardashevskiy
Quoted 22 lines · Anthony Liguori
Quoted 20 lines · Alexey Kardashevskiy
Quoted 17 lines · Anthony Liguori
This series is based on Alexey's series:
spapr: migration, pci, msi, power8
Which in turn was based on work by David Gibson.
I've removed the bits not related to migration and made the following changes:
1) QOMify TCE tables and XICS
2) Do everything in terms of VMStateDescriptions
3) Fix endianness problem with TCE table translation
a) Drop theVMSTATE_DIVIDEthing in the processI've tested this with a TCG pseries guest on an
x86_64host.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
It did not compile (fixed, patch is posted) and it fails to migrate with enabled KVM.
With in-kernel XICS? That's not in this series..
No, as is, without any of my patches. I suspect rather HPTE than XICS though.
I was wrong. vmstate_spapr_tce_table is broken :)
Signature · 1 line
Alexey
Quoted 24 lines · Alexey Kardashevskiy
Quoted 23 lines · Alexey Kardashevskiy
Quoted 22 lines · Anthony Liguori
Quoted 20 lines · Alexey Kardashevskiy
Quoted 17 lines · Anthony Liguori
This series is based on Alexey's series:
spapr: migration, pci, msi, power8
Which in turn was based on work by David Gibson.
I've removed the bits not related to migration and made the following changes:
1) QOMify TCE tables and XICS
2) Do everything in terms of VMStateDescriptions
3) Fix endianness problem with TCE table translation
a) Drop theVMSTATE_DIVIDEthing in the processI've tested this with a TCG pseries guest on an
x86_64host.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
It did not compile (fixed, patch is posted) and it fails to migrate with enabled KVM.
With in-kernel XICS? That's not in this series..
No, as is, without any of my patches. I suspect rather HPTE than XICS though.
I was wrong.
vmstate_spapr_tce_tableis broken :)
Here it is:
hw/ppc/spapr_iommu.c +1 -0
@@ -148,6 +148,7 @@ static int spapr_tce_table_realize(DeviceState *dev) *sizeof (uint64_t ); tcet->table =g_malloc0 (table_size); } + tcet->nb_table = tcet->window_size >>SPAPR_TCE_PAGE_SHIFT ;#ifdef DEBUG_TCE fprintf(stderr, "spapr_iommu: New TCE table @ %p, liobn=0x%x, "
Honestly, I liked David's approach more when we did not need any extra parameter to sync :(
Signature · 1 line
Alexey
Quoted 41 lines · Alexey Kardashevskiy
Quoted 24 lines · Alexey Kardashevskiy
Quoted 23 lines · Alexey Kardashevskiy
Quoted 22 lines · Anthony Liguori
Quoted 20 lines · Alexey Kardashevskiy
Quoted 17 lines · Anthony Liguori
This series is based on Alexey's series:
spapr: migration, pci, msi, power8
Which in turn was based on work by David Gibson.
I've removed the bits not related to migration and made the following changes:
1) QOMify TCE tables and XICS
2) Do everything in terms of VMStateDescriptions
3) Fix endianness problem with TCE table translation
a) Drop theVMSTATE_DIVIDEthing in the processI've tested this with a TCG pseries guest on an
x86_64host.Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
It did not compile (fixed, patch is posted) and it fails to migrate with enabled KVM.
With in-kernel XICS? That's not in this series..
No, as is, without any of my patches. I suspect rather HPTE than XICS though.
I was wrong.
vmstate_spapr_tce_tableis broken :)Here it is:
hw/ppc/spapr_iommu.c +0
-0
hw/ppc/spapr_iommu.c static int spapr_tce_table_realize(DeviceState *dev) · line 151
Quoted 4 lines
hw/ppc/spapr_iommu.c +1
-0@@ -148,6 +148,7 @@ static int spapr_tce_table_realize(DeviceState *dev) *sizeof (uint64_t ); tcet->table =g_malloc0 (table_size); } + tcet->nb_table = tcet->window_size >>SPAPR_TCE_PAGE_SHIFT ;
Ah, right, pre_load isn't enough :-/ Sorry about that. Thanks for digging in to this.
Quoted 7 lines
hw/ppc/spapr_iommu.c +0
-0#ifdef DEBUG_TCE fprintf(stderr, "spapr_iommu: New TCE table @ %p, liobn=0x%x, "Honestly, I liked David's approach more when we did not need any extra parameter to sync :(
I resisted the urge to refactor but I'm confident that nb_table will end up with nicer code.
The 'tcet->window_size >> SPAPR_TCE_PAGE_SHIFT' is used all over the place. It's not very clear without carefully thinking about it that the table size == the number of pages in the window.
Regards,
Anthony Liguori
Quoted 5 lines
Signature · 2 lines
-- Alexey