All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/11] pending s390 patches part 1
@ 2017-07-12 12:57 Christian Borntraeger
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management Christian Borntraeger
                   ` (11 more replies)
  0 siblings, 12 replies; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Christian Borntraeger

here is the first bunch on patches for s390:

- Some more PCI changes
- storage attribute migration (migration of CMMA state)
- cpu model cleanups and preparations

part 2 will follow shortly (sorry for the delay - process reasons ;-)).

In addition to that I plan to have the migration rework from Halil
and Thomas network boot.


Christian Borntraeger (1):
  linux-headers: update to 4.13-rc0

Claudio Imbrenda (2):
  s390x/migration: Storage attributes device
  s390x/migration: Monitor commands for storage attributes

Fei Li (3):
  s390x: add flags field for registering I/O adapter
  s390x/flic: introduce modify_ais_mode callback
  s390x/sic: realize SIC handling

Janosch Frank (1):
  s390x/kvm: Rework cmma management

Jason J. Herne (2):
  s390x/cpumodel: clean up spacing and comments
  s390x/cpumodel: provide compat handling for new cpu features

Yi Min Zhao (2):
  s390x/flic: introduce inject_airq callback
  s390x/css: update css_adapter_interrupt

 hmp-commands-info.hx                               |  16 +
 hmp-commands.hx                                    |  16 +
 hw/intc/s390_flic.c                                |  66 +++-
 hw/intc/s390_flic_kvm.c                            |  57 ++-
 hw/intc/trace-events                               |   4 +
 hw/s390x/Makefile.objs                             |   2 +
 hw/s390x/css-bridge.c                              |   2 +-
 hw/s390x/css.c                                     |  52 ++-
 hw/s390x/s390-pci-bus.c                            |   5 +-
 hw/s390x/s390-stattrib-kvm.c                       | 178 +++++++++
 hw/s390x/s390-stattrib.c                           | 410 +++++++++++++++++++++
 hw/s390x/s390-virtio-ccw.c                         |  10 +-
 hw/s390x/trace-events                              |   1 +
 hw/s390x/virtio-ccw.c                              |   2 +-
 include/hw/s390x/css.h                             |  12 +-
 include/hw/s390x/s390_flic.h                       |  13 +-
 include/hw/s390x/storage-attributes.h              |  72 ++++
 include/standard-headers/asm-x86/hyperv.h          |  21 +-
 include/standard-headers/linux/input-event-codes.h |   1 +
 include/standard-headers/linux/pci_regs.h          |   1 +
 linux-headers/asm-arm/kvm.h                        |   8 +
 linux-headers/asm-arm64/kvm.h                      |   3 +
 linux-headers/asm-powerpc/kvm.h                    |   6 +
 linux-headers/asm-s390/kvm.h                       |  12 +
 linux-headers/linux/kvm.h                          |  35 ++
 monitor.c                                          |   1 +
 target/s390x/cpu.h                                 |   1 +
 target/s390x/cpu_features.c                        |   3 +
 target/s390x/cpu_features_def.h                    |  35 ++
 target/s390x/cpu_models.c                          |  26 ++
 target/s390x/cpu_models.h                          |   2 +
 target/s390x/gen-features.c                        |  58 ++-
 target/s390x/kvm.c                                 |  42 ++-
 33 files changed, 1135 insertions(+), 38 deletions(-)
 create mode 100644 hw/s390x/s390-stattrib-kvm.c
 create mode 100644 hw/s390x/s390-stattrib.c
 create mode 100644 include/hw/s390x/storage-attributes.h

-- 
2.7.4

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 13:49   ` Cornelia Huck
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 02/11] linux-headers: update to 4.13-rc0 Christian Borntraeger
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Janosch Frank,
	Christian Borntraeger

From: Janosch Frank <frankja@linux.vnet.ibm.com>

Let's keep track of cmma enablement and move the mem_path check into
the actual enablement. This now also warns users that do not use
cpu-models about disabled cmma when using huge pages.

Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 target/s390x/cpu.h |  1 +
 target/s390x/kvm.c | 26 +++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
index bdb9bdb..8ab75c0 100644
--- a/target/s390x/cpu.h
+++ b/target/s390x/cpu.h
@@ -1158,6 +1158,7 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,
                                     int vq, bool assign);
 int kvm_s390_cpu_restart(S390CPU *cpu);
 int kvm_s390_get_memslot_count(KVMState *s);
+int kvm_s390_cmma_active(void);
 void kvm_s390_cmma_reset(void);
 int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
 void kvm_s390_reset_vcpu(S390CPU *cpu);
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index a3d0019..7a2a7c0 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -140,6 +140,8 @@ static int cap_mem_op;
 static int cap_s390_irq;
 static int cap_ri;
 
+static int active_cmma;
+
 static void *legacy_s390_alloc(size_t size, uint64_t *align);
 
 static int kvm_s390_query_mem_limit(KVMState *s, uint64_t *memory_limit)
@@ -177,6 +179,11 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
     return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
 }
 
+int kvm_s390_cmma_active(void)
+{
+    return active_cmma;
+}
+
 static bool kvm_s390_cmma_available(void)
 {
     static bool initialized, value;
@@ -197,7 +204,7 @@ void kvm_s390_cmma_reset(void)
         .attr = KVM_S390_VM_MEM_CLR_CMMA,
     };
 
-    if (mem_path || !kvm_s390_cmma_available()) {
+    if (!kvm_s390_cmma_active()) {
         return;
     }
 
@@ -213,7 +220,13 @@ static void kvm_s390_enable_cmma(void)
         .attr = KVM_S390_VM_MEM_ENABLE_CMMA,
     };
 
+    if (mem_path) {
+        error_report("Warning: CMM will not be enabled because it is not "
+                     "compatible to hugetlbfs.");
+        return;
+    }
     rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+    active_cmma = !rc;
     trace_kvm_enable_cmma(rc);
 }
 
@@ -2641,7 +2654,7 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
 
     if (!model) {
         /* compatibility handling if cpu models are disabled */
-        if (kvm_s390_cmma_available() && !mem_path) {
+        if (kvm_s390_cmma_available()) {
             kvm_s390_enable_cmma();
         }
         return;
@@ -2672,13 +2685,8 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
         error_setg(errp, "KVM: Error configuring CPU subfunctions: %d", rc);
         return;
     }
-    /* enable CMM via CMMA - disable on hugetlbfs */
+    /* enable CMM via CMMA */
     if (test_bit(S390_FEAT_CMM, model->features)) {
-        if (mem_path) {
-            error_report("Warning: CMM will not be enabled because it is not "
-                         "compatible to hugetlbfs.");
-        } else {
-            kvm_s390_enable_cmma();
-        }
+        kvm_s390_enable_cmma();
     }
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 02/11] linux-headers: update to 4.13-rc0
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device Christian Borntraeger
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Christian Borntraeger

commit af3c8d98508d37541d4bf57f13a984a7f73a328c
    Merge tag 'drm-for-v4.13' of git://people.freedesktop.org/~airlied/linux

will be replaced with a header-sync against v4.13-rc1

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 include/standard-headers/asm-x86/hyperv.h          | 21 +++++++------
 include/standard-headers/linux/input-event-codes.h |  1 +
 include/standard-headers/linux/pci_regs.h          |  1 +
 linux-headers/asm-arm/kvm.h                        |  8 +++++
 linux-headers/asm-arm64/kvm.h                      |  3 ++
 linux-headers/asm-powerpc/kvm.h                    |  6 ++++
 linux-headers/asm-s390/kvm.h                       | 12 ++++++++
 linux-headers/linux/kvm.h                          | 35 ++++++++++++++++++++++
 8 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/include/standard-headers/asm-x86/hyperv.h b/include/standard-headers/asm-x86/hyperv.h
index d0c6e0a..fac7651 100644
--- a/include/standard-headers/asm-x86/hyperv.h
+++ b/include/standard-headers/asm-x86/hyperv.h
@@ -34,16 +34,10 @@
 #define HV_X64_MSR_REFERENCE_TSC		0x40000021
 
 /*
- * There is a single feature flag that signifies the presence of the MSR
- * that can be used to retrieve both the local APIC Timer frequency as
- * well as the TSC frequency.
+ * There is a single feature flag that signifies if the partition has access
+ * to MSRs with local APIC and TSC frequencies.
  */
-
-/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */
-#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 << 11)
-
-/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */
-#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 << 11)
+#define HV_X64_ACCESS_FREQUENCY_MSRS		(1 << 11)
 
 /*
  * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM
@@ -73,6 +67,9 @@
   */
 #define HV_X64_MSR_STAT_PAGES_AVAILABLE		(1 << 8)
 
+/* Frequency MSRs available */
+#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE	(1 << 8)
+
 /* Crash MSR available */
 #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE (1 << 10)
 
@@ -153,6 +150,12 @@
 #define HV_X64_DEPRECATING_AEOI_RECOMMENDED	(1 << 9)
 
 /*
+ * HV_VP_SET available
+ */
+#define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED	(1 << 11)
+
+
+/*
  * Crash notification flag.
  */
 #define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
diff --git a/include/standard-headers/linux/input-event-codes.h b/include/standard-headers/linux/input-event-codes.h
index 29d463a..2fa0f4e 100644
--- a/include/standard-headers/linux/input-event-codes.h
+++ b/include/standard-headers/linux/input-event-codes.h
@@ -600,6 +600,7 @@
 #define KEY_APPSELECT		0x244	/* AL Select Task/Application */
 #define KEY_SCREENSAVER		0x245	/* AL Screen Saver */
 #define KEY_VOICECOMMAND		0x246	/* Listening Voice Command */
+#define KEY_ASSISTANT		0x247	/* AL Context-aware desktop assistant */
 
 #define KEY_BRIGHTNESS_MIN		0x250	/* Set Brightness to Minimum */
 #define KEY_BRIGHTNESS_MAX		0x251	/* Set Brightness to Maximum */
diff --git a/include/standard-headers/linux/pci_regs.h b/include/standard-headers/linux/pci_regs.h
index d56bb00..c22d3eb 100644
--- a/include/standard-headers/linux/pci_regs.h
+++ b/include/standard-headers/linux/pci_regs.h
@@ -517,6 +517,7 @@
 #define  PCI_EXP_LNKCAP_SLS	0x0000000f /* Supported Link Speeds */
 #define  PCI_EXP_LNKCAP_SLS_2_5GB 0x00000001 /* LNKCAP2 SLS Vector bit 0 */
 #define  PCI_EXP_LNKCAP_SLS_5_0GB 0x00000002 /* LNKCAP2 SLS Vector bit 1 */
+#define  PCI_EXP_LNKCAP_SLS_8_0GB 0x00000003 /* LNKCAP2 SLS Vector bit 2 */
 #define  PCI_EXP_LNKCAP_MLW	0x000003f0 /* Maximum Link Width */
 #define  PCI_EXP_LNKCAP_ASPMS	0x00000c00 /* ASPM Support */
 #define  PCI_EXP_LNKCAP_L0SEL	0x00007000 /* L0s Exit Latency */
diff --git a/linux-headers/asm-arm/kvm.h b/linux-headers/asm-arm/kvm.h
index 7258a00..fa9fae8 100644
--- a/linux-headers/asm-arm/kvm.h
+++ b/linux-headers/asm-arm/kvm.h
@@ -203,6 +203,14 @@ struct kvm_arch_memory_slot {
 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff
 #define VGIC_LEVEL_INFO_LINE_LEVEL	0
 
+/* Device Control API on vcpu fd */
+#define KVM_ARM_VCPU_PMU_V3_CTRL	0
+#define   KVM_ARM_VCPU_PMU_V3_IRQ	0
+#define   KVM_ARM_VCPU_PMU_V3_INIT	1
+#define KVM_ARM_VCPU_TIMER_CTRL		1
+#define   KVM_ARM_VCPU_TIMER_IRQ_VTIMER		0
+#define   KVM_ARM_VCPU_TIMER_IRQ_PTIMER		1
+
 #define   KVM_DEV_ARM_VGIC_CTRL_INIT		0
 #define   KVM_DEV_ARM_ITS_SAVE_TABLES		1
 #define   KVM_DEV_ARM_ITS_RESTORE_TABLES	2
diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h
index 31bb1dd..d254700 100644
--- a/linux-headers/asm-arm64/kvm.h
+++ b/linux-headers/asm-arm64/kvm.h
@@ -232,6 +232,9 @@ struct kvm_arch_memory_slot {
 #define KVM_ARM_VCPU_PMU_V3_CTRL	0
 #define   KVM_ARM_VCPU_PMU_V3_IRQ	0
 #define   KVM_ARM_VCPU_PMU_V3_INIT	1
+#define KVM_ARM_VCPU_TIMER_CTRL		1
+#define   KVM_ARM_VCPU_TIMER_IRQ_VTIMER		0
+#define   KVM_ARM_VCPU_TIMER_IRQ_PTIMER		1
 
 /* KVM_IRQ_LINE irq field index values */
 #define KVM_ARM_IRQ_TYPE_SHIFT		24
diff --git a/linux-headers/asm-powerpc/kvm.h b/linux-headers/asm-powerpc/kvm.h
index 07fbeb9..8cf8f0c 100644
--- a/linux-headers/asm-powerpc/kvm.h
+++ b/linux-headers/asm-powerpc/kvm.h
@@ -60,6 +60,12 @@ struct kvm_regs {
 
 #define KVM_SREGS_E_FSL_PIDn	(1 << 0) /* PID1/PID2 */
 
+/* flags for kvm_run.flags */
+#define KVM_RUN_PPC_NMI_DISP_MASK		(3 << 0)
+#define   KVM_RUN_PPC_NMI_DISP_FULLY_RECOV	(1 << 0)
+#define   KVM_RUN_PPC_NMI_DISP_LIMITED_RECOV	(2 << 0)
+#define   KVM_RUN_PPC_NMI_DISP_NOT_RECOV	(3 << 0)
+
 /*
  * Feature bits indicate which sections of the sregs struct are valid,
  * both in KVM_GET_SREGS and KVM_SET_SREGS.  On KVM_SET_SREGS, registers
diff --git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
index 243f195..8387d71 100644
--- a/linux-headers/asm-s390/kvm.h
+++ b/linux-headers/asm-s390/kvm.h
@@ -28,6 +28,7 @@
 #define KVM_DEV_FLIC_CLEAR_IO_IRQ	8
 #define KVM_DEV_FLIC_AISM		9
 #define KVM_DEV_FLIC_AIRQ_INJECT	10
+#define KVM_DEV_FLIC_AISM_ALL		11
 /*
  * We can have up to 4*64k pending subchannels + 8 adapter interrupts,
  * as well as up  to ASYNC_PF_PER_VCPU*KVM_MAX_VCPUS pfault done interrupts.
@@ -53,6 +54,11 @@ struct kvm_s390_ais_req {
 	__u16 mode;
 };
 
+struct kvm_s390_ais_all {
+	__u8 simm;
+	__u8 nimm;
+};
+
 #define KVM_S390_IO_ADAPTER_MASK 1
 #define KVM_S390_IO_ADAPTER_MAP 2
 #define KVM_S390_IO_ADAPTER_UNMAP 3
@@ -70,6 +76,7 @@ struct kvm_s390_io_adapter_req {
 #define KVM_S390_VM_TOD			1
 #define KVM_S390_VM_CRYPTO		2
 #define KVM_S390_VM_CPU_MODEL		3
+#define KVM_S390_VM_MIGRATION		4
 
 /* kvm attributes for mem_ctrl */
 #define KVM_S390_VM_MEM_ENABLE_CMMA	0
@@ -151,6 +158,11 @@ struct kvm_s390_vm_cpu_subfunc {
 #define KVM_S390_VM_CRYPTO_DISABLE_AES_KW	2
 #define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW	3
 
+/* kvm attributes for migration mode */
+#define KVM_S390_VM_MIGRATION_STOP	0
+#define KVM_S390_VM_MIGRATION_START	1
+#define KVM_S390_VM_MIGRATION_STATUS	2
+
 /* for KVM_GET_REGS and KVM_SET_REGS */
 struct kvm_regs {
 	/* general purpose regs for s390 */
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index d2892da..43e2d82 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -155,6 +155,35 @@ struct kvm_s390_skeys {
 	__u32 reserved[9];
 };
 
+#define KVM_S390_CMMA_PEEK (1 << 0)
+
+/**
+ * kvm_s390_cmma_log - Used for CMMA migration.
+ *
+ * Used both for input and output.
+ *
+ * @start_gfn: Guest page number to start from.
+ * @count: Size of the result buffer.
+ * @flags: Control operation mode via KVM_S390_CMMA_* flags
+ * @remaining: Used with KVM_S390_GET_CMMA_BITS. Indicates how many dirty
+ *             pages are still remaining.
+ * @mask: Used with KVM_S390_SET_CMMA_BITS. Bitmap of bits to actually set
+ *        in the PGSTE.
+ * @values: Pointer to the values buffer.
+ *
+ * Used in KVM_S390_{G,S}ET_CMMA_BITS ioctls.
+ */
+struct kvm_s390_cmma_log {
+	__u64 start_gfn;
+	__u32 count;
+	__u32 flags;
+	union {
+		__u64 remaining;
+		__u64 mask;
+	};
+	__u64 values;
+};
+
 struct kvm_hyperv_exit {
 #define KVM_EXIT_HYPERV_SYNIC          1
 #define KVM_EXIT_HYPERV_HCALL          2
@@ -895,6 +924,9 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_SPAPR_TCE_VFIO 142
 #define KVM_CAP_X86_GUEST_MWAIT 143
 #define KVM_CAP_ARM_USER_IRQ 144
+#define KVM_CAP_S390_CMMA_MIGRATION 145
+#define KVM_CAP_PPC_FWNMI 146
+#define KVM_CAP_PPC_SMT_POSSIBLE 147
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1318,6 +1350,9 @@ struct kvm_s390_ucas_mapping {
 #define KVM_S390_GET_IRQ_STATE	  _IOW(KVMIO, 0xb6, struct kvm_s390_irq_state)
 /* Available with KVM_CAP_X86_SMM */
 #define KVM_SMI                   _IO(KVMIO,   0xb7)
+/* Available with KVM_CAP_S390_CMMA_MIGRATION */
+#define KVM_S390_GET_CMMA_BITS      _IOW(KVMIO, 0xb8, struct kvm_s390_cmma_log)
+#define KVM_S390_SET_CMMA_BITS      _IOW(KVMIO, 0xb9, struct kvm_s390_cmma_log)
 
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU	(1 << 0)
 #define KVM_DEV_ASSIGN_PCI_2_3		(1 << 1)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management Christian Borntraeger
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 02/11] linux-headers: update to 4.13-rc0 Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 14:09   ` Thomas Huth
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 04/11] s390x/migration: Monitor commands for storage attributes Christian Borntraeger
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck,
	Claudio Imbrenda, Christian Borntraeger

From: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>

Storage attributes device, like we have for storage keys.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hw/s390x/Makefile.objs                |   2 +
 hw/s390x/s390-stattrib-kvm.c          | 178 +++++++++++++++++
 hw/s390x/s390-stattrib.c              | 348 ++++++++++++++++++++++++++++++++++
 hw/s390x/s390-virtio-ccw.c            |  10 +-
 include/hw/s390x/storage-attributes.h |  68 +++++++
 5 files changed, 605 insertions(+), 1 deletion(-)
 create mode 100644 hw/s390x/s390-stattrib-kvm.c
 create mode 100644 hw/s390x/s390-stattrib.c
 create mode 100644 include/hw/s390x/storage-attributes.h

diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index a8e5575..b2aade2 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -13,5 +13,7 @@ obj-y += css-bridge.o
 obj-y += ccw-device.o
 obj-y += s390-pci-bus.o s390-pci-inst.o
 obj-y += s390-skeys.o
+obj-y += s390-stattrib.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
+obj-$(CONFIG_KVM) += s390-stattrib-kvm.o
 obj-y += s390-ccw.o
diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
new file mode 100644
index 0000000..2e7f144
--- /dev/null
+++ b/hw/s390x/s390-stattrib-kvm.c
@@ -0,0 +1,178 @@
+/*
+ * s390 storage attributes device -- KVM object
+ *
+ * Copyright 2016 IBM Corp.
+ * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/boards.h"
+#include "qmp-commands.h"
+#include "migration/qemu-file.h"
+#include "hw/s390x/storage-attributes.h"
+#include "qemu/error-report.h"
+#include "sysemu/kvm.h"
+#include "exec/ram_addr.h"
+#include "cpu.h"
+
+static void kvm_s390_stattrib_instance_init(Object *obj)
+{
+    KVMS390StAttribState *sas = KVM_S390_STATTRIB(obj);
+
+    sas->still_dirty = 0;
+}
+
+static int kvm_s390_stattrib_read_helper(S390StAttribState *sa,
+                                        uint64_t *start_gfn,
+                                        uint32_t count,
+                                        uint8_t *values,
+                                        uint32_t flags)
+{
+    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
+    int r;
+    struct kvm_s390_cmma_log clog = {
+        .values = (uint64_t)values,
+        .start_gfn = *start_gfn,
+        .count = count,
+        .flags = flags,
+    };
+
+    r = kvm_vm_ioctl(kvm_state, KVM_S390_GET_CMMA_BITS, &clog);
+    if (r < 0) {
+        error_report("Error: %s", strerror(-r));
+        return r;
+    }
+
+    *start_gfn = clog.start_gfn;
+    sas->still_dirty = clog.remaining;
+    return clog.count;
+}
+
+static int kvm_s390_stattrib_get_stattr(S390StAttribState *sa,
+                                        uint64_t *start_gfn,
+                                        uint32_t count,
+                                        uint8_t *values)
+{
+    return kvm_s390_stattrib_read_helper(sa, start_gfn, count, values, 0);
+}
+
+static int kvm_s390_stattrib_peek_stattr(S390StAttribState *sa,
+                                         uint64_t start_gfn,
+                                         uint32_t count,
+                                         uint8_t *values)
+{
+    return kvm_s390_stattrib_read_helper(sa, &start_gfn, count, values,
+                                         KVM_S390_CMMA_PEEK);
+}
+
+static int kvm_s390_stattrib_set_stattr(S390StAttribState *sa,
+                                        uint64_t start_gfn,
+                                        uint32_t count,
+                                        uint8_t *values)
+{
+    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
+    MachineState *machine = MACHINE(qdev_get_machine());
+    unsigned long max = machine->maxram_size / TARGET_PAGE_SIZE;
+
+    if (start_gfn + count > max) {
+        error_report("Error: invalid address.");
+        return -1;
+    }
+    if (!sas->incoming_buffer) {
+        sas->incoming_buffer = g_malloc0(max);
+    }
+
+    memcpy(sas->incoming_buffer + start_gfn, values, count);
+
+    return 0;
+}
+
+static void kvm_s390_stattrib_synchronize(S390StAttribState *sa)
+{
+    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
+    MachineState *machine = MACHINE(qdev_get_machine());
+    unsigned long max = machine->maxram_size / TARGET_PAGE_SIZE;
+    unsigned long cx, len = 1 << 19;
+    int r;
+    struct kvm_s390_cmma_log clog = {
+        .flags = 0,
+        .mask = ~0ULL,
+    };
+
+    if (sas->incoming_buffer) {
+        for (cx = 0; cx + len <= max; cx += len) {
+            clog.start_gfn = cx;
+            clog.count = len;
+            clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
+            r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
+            if (r) {
+                return;
+            }
+        }
+        if (cx < max) {
+            clog.start_gfn = cx;
+            clog.count = max - cx;
+            clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
+            r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
+        }
+        g_free(sas->incoming_buffer);
+        sas->incoming_buffer = NULL;
+    }
+}
+
+static int kvm_s390_stattrib_set_migrationmode(S390StAttribState *sa, bool val)
+{
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_MIGRATION,
+        .attr = val,
+        .addr = 0,
+    };
+    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+}
+
+static long long kvm_s390_stattrib_get_dirtycount(S390StAttribState *sa)
+{
+    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
+    uint8_t val[8];
+
+    kvm_s390_stattrib_peek_stattr(sa, 0, 1, val);
+    return sas->still_dirty;
+}
+
+static int kvm_s390_stattrib_get_active(S390StAttribState *sa)
+{
+    return kvm_s390_cmma_active() && sa->migration_enabled;
+}
+
+static void kvm_s390_stattrib_class_init(ObjectClass *oc, void *data)
+{
+    S390StAttribClass *sac = S390_STATTRIB_CLASS(oc);
+
+    sac->get_stattr = kvm_s390_stattrib_get_stattr;
+    sac->peek_stattr = kvm_s390_stattrib_peek_stattr;
+    sac->set_stattr = kvm_s390_stattrib_set_stattr;
+    sac->set_migrationmode = kvm_s390_stattrib_set_migrationmode;
+    sac->get_dirtycount = kvm_s390_stattrib_get_dirtycount;
+    sac->synchronize = kvm_s390_stattrib_synchronize;
+    sac->get_active = kvm_s390_stattrib_get_active;
+}
+
+static const TypeInfo kvm_s390_stattrib_info = {
+    .name          = TYPE_KVM_S390_STATTRIB,
+    .parent        = TYPE_S390_STATTRIB,
+    .instance_init = kvm_s390_stattrib_instance_init,
+    .instance_size = sizeof(KVMS390StAttribState),
+    .class_init    = kvm_s390_stattrib_class_init,
+    .class_size    = sizeof(S390StAttribClass),
+};
+
+static void kvm_s390_stattrib_register_types(void)
+{
+    type_register_static(&kvm_s390_stattrib_info);
+}
+
+type_init(kvm_s390_stattrib_register_types)
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
new file mode 100644
index 0000000..eb41fe9
--- /dev/null
+++ b/hw/s390x/s390-stattrib.c
@@ -0,0 +1,348 @@
+/*
+ * s390 storage attributes device
+ *
+ * Copyright 2016 IBM Corp.
+ * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/boards.h"
+#include "migration/qemu-file.h"
+#include "migration/register.h"
+#include "hw/s390x/storage-attributes.h"
+#include "qemu/error-report.h"
+#include "sysemu/kvm.h"
+#include "exec/ram_addr.h"
+#include "qapi/error.h"
+
+#define CMMA_BLOCK_SIZE  (1 << 10)
+
+#define STATTR_FLAG_EOS     0x01ULL
+#define STATTR_FLAG_MORE    0x02ULL
+#define STATTR_FLAG_ERROR   0x04ULL
+#define STATTR_FLAG_DONE    0x08ULL
+
+void s390_stattrib_init(void)
+{
+    Object *obj;
+
+#ifdef CONFIG_KVM
+    if (kvm_enabled() &&
+            kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
+        obj = object_new(TYPE_KVM_S390_STATTRIB);
+    } else {
+        obj = object_new(TYPE_QEMU_S390_STATTRIB);
+    }
+#else
+    obj = object_new(TYPE_QEMU_S390_STATTRIB);
+#endif
+
+    object_property_add_child(qdev_get_machine(), TYPE_S390_STATTRIB,
+                              obj, NULL);
+    object_unref(obj);
+
+    qdev_init_nofail(DEVICE(obj));
+}
+
+/* Migration support: */
+
+static int cmma_load(QEMUFile *f, void *opaque, int version_id)
+{
+    S390StAttribState *sas = S390_STATTRIB(opaque);
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    uint64_t count, cur_gfn;
+    int flags, ret = 0;
+    ram_addr_t addr;
+    uint8_t *buf;
+
+    while (!ret) {
+        addr = qemu_get_be64(f);
+        flags = addr & ~TARGET_PAGE_MASK;
+        addr &= TARGET_PAGE_MASK;
+
+        switch (flags) {
+        case STATTR_FLAG_MORE: {
+            cur_gfn = addr / TARGET_PAGE_SIZE;
+            count = qemu_get_be64(f);
+            buf = g_try_malloc(count);
+            if (!buf) {
+                error_report("cmma_load could not allocate memory");
+                ret = -ENOMEM;
+                break;
+            }
+
+            qemu_get_buffer(f, buf, count);
+            ret = sac->set_stattr(sas, cur_gfn, count, buf);
+            if (ret < 0) {
+                error_report("Error %d while setting storage attributes", ret);
+            }
+            g_free(buf);
+            break;
+        }
+        case STATTR_FLAG_ERROR: {
+            error_report("Storage attributes data is incomplete");
+            ret = -EINVAL;
+            break;
+        }
+        case STATTR_FLAG_DONE:
+            /* This is after the last pre-copied value has been sent, nothing
+             * more will be sent after this. Pre-copy has finished, and we
+             * are done flushing all the remaining values. Now the target
+             * system is about to take over. We synchronize the buffer to
+             * apply the actual correct values where needed.
+             */
+             sac->synchronize(sas);
+            break;
+        case STATTR_FLAG_EOS:
+            /* Normal exit */
+            return 0;
+        default:
+            error_report("Unexpected storage attribute flag data: %#x", flags);
+            ret = -EINVAL;
+        }
+    }
+
+    return ret;
+}
+
+static int cmma_save_setup(QEMUFile *f, void *opaque)
+{
+    S390StAttribState *sas = S390_STATTRIB(opaque);
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    int res;
+    /*
+     * Signal that we want to start a migration, thus needing PGSTE dirty
+     * tracking.
+     */
+    res = sac->set_migrationmode(sas, 1);
+    if (res) {
+        return res;
+    }
+    qemu_put_be64(f, STATTR_FLAG_EOS);
+    return 0;
+}
+
+static void cmma_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,
+                             uint64_t *non_postcopiable_pending,
+                             uint64_t *postcopiable_pending)
+{
+    S390StAttribState *sas = S390_STATTRIB(opaque);
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    long long res = sac->get_dirtycount(sas);
+
+    if (res >= 0) {
+        *non_postcopiable_pending += res;
+    }
+}
+
+static int cmma_save(QEMUFile *f, void *opaque, int final)
+{
+    S390StAttribState *sas = S390_STATTRIB(opaque);
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    uint8_t *buf;
+    int r, cx, reallen = 0, ret = 0;
+    uint32_t buflen = 1 << 19;   /* 512kB cover 2GB of guest memory */
+    uint64_t start_gfn = sas->migration_cur_gfn;
+
+    buf = g_try_malloc(buflen);
+    if (!buf) {
+        error_report("Could not allocate memory to save storage attributes");
+        return -ENOMEM;
+    }
+
+    while (final ? 1 : qemu_file_rate_limit(f) == 0) {
+        reallen = sac->get_stattr(sas, &start_gfn, buflen, buf);
+        if (reallen < 0) {
+            g_free(buf);
+            return reallen;
+        }
+
+        ret = 1;
+        if (0 == reallen) {
+            break;
+        }
+        qemu_put_be64(f, (start_gfn << TARGET_PAGE_BITS) | STATTR_FLAG_MORE);
+        qemu_put_be64(f, reallen);
+        for (cx = 0; cx < reallen; cx++) {
+            qemu_put_byte(f, buf[cx]);
+        }
+        if (!sac->get_dirtycount(sas)) {
+            break;
+        }
+    }
+
+    sas->migration_cur_gfn = start_gfn + reallen;
+    g_free(buf);
+    if (final) {
+        qemu_put_be64(f, STATTR_FLAG_DONE);
+    }
+    qemu_put_be64(f, STATTR_FLAG_EOS);
+
+    r = qemu_file_get_error(f);
+    if (r < 0) {
+        return r;
+    }
+
+    return ret;
+}
+
+static int cmma_save_iterate(QEMUFile *f, void *opaque)
+{
+    return cmma_save(f, opaque, 0);
+}
+
+static int cmma_save_complete(QEMUFile *f, void *opaque)
+{
+    return cmma_save(f, opaque, 1);
+}
+
+static void cmma_save_cleanup(void *opaque)
+{
+    S390StAttribState *sas = S390_STATTRIB(opaque);
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    sac->set_migrationmode(sas, 0);
+}
+
+static bool cmma_active(void *opaque)
+{
+    S390StAttribState *sas = S390_STATTRIB(opaque);
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    return sac->get_active(sas);
+}
+
+/* QEMU object: */
+
+static void qemu_s390_stattrib_instance_init(Object *obj)
+{
+}
+
+static int qemu_s390_peek_stattr_stub(S390StAttribState *sa, uint64_t start_gfn,
+                                     uint32_t count, uint8_t *values)
+{
+    return 0;
+}
+static void qemu_s390_synchronize_stub(S390StAttribState *sa)
+{
+}
+static int qemu_s390_get_stattr_stub(S390StAttribState *sa, uint64_t *start_gfn,
+                                     uint32_t count, uint8_t *values)
+{
+    return 0;
+}
+static long long qemu_s390_get_dirtycount_stub(S390StAttribState *sa)
+{
+    return 0;
+}
+static int qemu_s390_set_migrationmode_stub(S390StAttribState *sa, bool value)
+{
+    return 0;
+}
+
+static int qemu_s390_get_active(S390StAttribState *sa)
+{
+    return sa->migration_enabled;
+}
+
+static void qemu_s390_stattrib_class_init(ObjectClass *oc, void *data)
+{
+    S390StAttribClass *sa_cl = S390_STATTRIB_CLASS(oc);
+
+    sa_cl->synchronize = qemu_s390_synchronize_stub;
+    sa_cl->get_stattr = qemu_s390_get_stattr_stub;
+    sa_cl->set_stattr = qemu_s390_peek_stattr_stub;
+    sa_cl->peek_stattr = qemu_s390_peek_stattr_stub;
+    sa_cl->set_migrationmode = qemu_s390_set_migrationmode_stub;
+    sa_cl->get_dirtycount = qemu_s390_get_dirtycount_stub;
+    sa_cl->get_active = qemu_s390_get_active;
+}
+
+static const TypeInfo qemu_s390_stattrib_info = {
+    .name          = TYPE_QEMU_S390_STATTRIB,
+    .parent        = TYPE_S390_STATTRIB,
+    .instance_init = qemu_s390_stattrib_instance_init,
+    .instance_size = sizeof(QEMUS390StAttribState),
+    .class_init    = qemu_s390_stattrib_class_init,
+    .class_size    = sizeof(S390StAttribClass),
+};
+
+/* Generic abstract object: */
+
+static void s390_stattrib_realize(DeviceState *dev, Error **errp)
+{
+    bool ambiguous = false;
+
+    object_resolve_path_type("", TYPE_S390_STATTRIB, &ambiguous);
+    if (ambiguous) {
+        error_setg(errp, "storage_attributes device already exists");
+    }
+}
+
+static void s390_stattrib_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->hotpluggable = false;
+    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+    dc->realize = s390_stattrib_realize;
+}
+
+static inline bool s390_stattrib_get_migration_enabled(Object *obj, Error **e)
+{
+    S390StAttribState *s = S390_STATTRIB(obj);
+
+    return s->migration_enabled;
+}
+
+static inline void s390_stattrib_set_migration_enabled(Object *obj, bool value,
+                                            Error **errp)
+{
+    S390StAttribState *s = S390_STATTRIB(obj);
+
+    s->migration_enabled = value;
+}
+
+static void s390_stattrib_instance_init(Object *obj)
+{
+    S390StAttribState *sas = S390_STATTRIB(obj);
+    SaveVMHandlers *ops;
+
+    /* ops will always be freed by qemu when unregistering */
+    ops = g_new0(SaveVMHandlers, 1);
+
+    ops->save_setup = cmma_save_setup;
+    ops->save_live_iterate = cmma_save_iterate;
+    ops->save_live_complete_precopy = cmma_save_complete;
+    ops->save_live_pending = cmma_save_pending;
+    ops->save_cleanup = cmma_save_cleanup;
+    ops->load_state = cmma_load;
+    ops->is_active = cmma_active;
+    register_savevm_live(NULL, TYPE_S390_STATTRIB, 0, 0, ops, sas);
+
+    object_property_add_bool(obj, "migration-enabled",
+                             s390_stattrib_get_migration_enabled,
+                             s390_stattrib_set_migration_enabled, NULL);
+    object_property_set_bool(obj, true, "migration-enabled", NULL);
+    sas->migration_cur_gfn = 0;
+}
+
+static const TypeInfo s390_stattrib_info = {
+    .name          = TYPE_S390_STATTRIB,
+    .parent        = TYPE_DEVICE,
+    .instance_init = s390_stattrib_instance_init,
+    .instance_size = sizeof(S390StAttribState),
+    .class_init    = s390_stattrib_class_init,
+    .class_size    = sizeof(S390StAttribClass),
+    .abstract      = true,
+};
+
+static void s390_stattrib_register_types(void)
+{
+    type_register_static(&s390_stattrib_info);
+    type_register_static(&qemu_s390_stattrib_info);
+}
+
+type_init(s390_stattrib_register_types)
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 41ca666..0c8f758 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -24,6 +24,7 @@
 #include "qemu/config-file.h"
 #include "s390-pci-bus.h"
 #include "hw/s390x/storage-keys.h"
+#include "hw/s390x/storage-attributes.h"
 #include "hw/compat.h"
 #include "ipl.h"
 #include "hw/s390x/s390-virtio-ccw.h"
@@ -103,6 +104,8 @@ void s390_memory_init(ram_addr_t mem_size)
 
     /* Initialize storage key device */
     s390_skeys_init();
+    /* Initialize storage attributes device */
+    s390_stattrib_init();
 }
 
 static SaveVMHandlers savevm_gtod = {
@@ -406,7 +409,12 @@ static const TypeInfo ccw_machine_info = {
     type_init(ccw_machine_register_##suffix)
 
 #define CCW_COMPAT_2_9 \
-        HW_COMPAT_2_9
+        HW_COMPAT_2_9 \
+        {\
+            .driver   = TYPE_S390_STATTRIB,\
+            .property = "migration-enabled",\
+            .value    = "off",\
+        },
 
 #define CCW_COMPAT_2_8 \
         HW_COMPAT_2_8 \
diff --git a/include/hw/s390x/storage-attributes.h b/include/hw/s390x/storage-attributes.h
new file mode 100644
index 0000000..161440b
--- /dev/null
+++ b/include/hw/s390x/storage-attributes.h
@@ -0,0 +1,68 @@
+/*
+ * s390 storage attributes device
+ *
+ * Copyright 2016 IBM Corp.
+ * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef S390_STORAGE_ATTRIBUTES_H
+#define S390_STORAGE_ATTRIBUTES_H
+
+#include <hw/qdev.h>
+
+#define TYPE_S390_STATTRIB "s390-storage_attributes"
+#define TYPE_QEMU_S390_STATTRIB "s390-storage_attributes-qemu"
+#define TYPE_KVM_S390_STATTRIB "s390-storage_attributes-kvm"
+
+#define S390_STATTRIB(obj) \
+    OBJECT_CHECK(S390StAttribState, (obj), TYPE_S390_STATTRIB)
+
+typedef struct S390StAttribState {
+    DeviceState parent_obj;
+    uint64_t migration_cur_gfn;
+    bool migration_enabled;
+} S390StAttribState;
+
+#define S390_STATTRIB_CLASS(klass) \
+    OBJECT_CLASS_CHECK(S390StAttribClass, (klass), TYPE_S390_STATTRIB)
+#define S390_STATTRIB_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(S390StAttribClass, (obj), TYPE_S390_STATTRIB)
+
+typedef struct S390StAttribClass {
+    DeviceClass parent_class;
+    /* Return value: < 0 on error, or new count */
+    int (*get_stattr)(S390StAttribState *sa, uint64_t *start_gfn,
+                      uint32_t count, uint8_t *values);
+    int (*peek_stattr)(S390StAttribState *sa, uint64_t start_gfn,
+                       uint32_t count, uint8_t *values);
+    int (*set_stattr)(S390StAttribState *sa, uint64_t start_gfn,
+                      uint32_t count, uint8_t *values);
+    void (*synchronize)(S390StAttribState *sa);
+    int (*set_migrationmode)(S390StAttribState *sa, bool value);
+    int (*get_active)(S390StAttribState *sa);
+    long long (*get_dirtycount)(S390StAttribState *sa);
+} S390StAttribClass;
+
+#define QEMU_S390_STATTRIB(obj) \
+    OBJECT_CHECK(QEMUS390StAttribState, (obj), TYPE_QEMU_S390_STATTRIB)
+
+typedef struct QEMUS390StAttribState {
+    S390StAttribState parent_obj;
+} QEMUS390StAttribState;
+
+#define KVM_S390_STATTRIB(obj) \
+    OBJECT_CHECK(KVMS390StAttribState, (obj), TYPE_KVM_S390_STATTRIB)
+
+typedef struct KVMS390StAttribState {
+    S390StAttribState parent_obj;
+    uint64_t still_dirty;
+    uint8_t *incoming_buffer;
+} KVMS390StAttribState;
+
+void s390_stattrib_init(void);
+
+#endif /* S390_STORAGE_ATTRIBUTES_H */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 04/11] s390x/migration: Monitor commands for storage attributes
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (2 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 05/11] s390x/cpumodel: clean up spacing and comments Christian Borntraeger
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck,
	Claudio Imbrenda, Christian Borntraeger

From: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>

Add an "info" monitor command to non-destructively inspect the state of
the storage attributes of the guest, and a normal command to toggle
migration mode (useful for debugging).

Signed-off-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hmp-commands-info.hx                  | 16 +++++++++
 hmp-commands.hx                       | 16 +++++++++
 hw/s390x/s390-stattrib.c              | 62 +++++++++++++++++++++++++++++++++++
 include/hw/s390x/storage-attributes.h |  4 +++
 monitor.c                             |  1 +
 5 files changed, 99 insertions(+)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 07500ef..d9df238 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -777,6 +777,22 @@ STEXI
 Display the value of a storage key (s390 only)
 ETEXI
 
+#if defined(TARGET_S390X)
+    {
+        .name       = "cmma",
+        .args_type  = "addr:l,count:l?",
+        .params     = "address [count]",
+        .help       = "Display the values of the CMMA storage attributes for a range of pages",
+        .cmd        = hmp_info_cmma,
+    },
+#endif
+
+STEXI
+@item info cmma @var{address}
+@findex cmma
+Display the values of the CMMA storage attributes for a range of pages (s390 only)
+ETEXI
+
     {
         .name       = "dump",
         .args_type  = "",
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 275ccdf..eec9cc2 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1153,6 +1153,22 @@ STEXI
 Save guest storage keys to a file.
 ETEXI
 
+#if defined(TARGET_S390X)
+    {
+        .name       = "migration_mode",
+        .args_type  = "mode:i",
+        .params     = "mode",
+        .help       = "Enables or disables migration mode\n",
+        .cmd        = hmp_migrationmode,
+    },
+#endif
+
+STEXI
+@item migration_mode @var{mode}
+@findex migration_mode
+Enables or disables migration mode.
+ETEXI
+
     {
         .name       = "snapshot_blkdev",
         .args_type  = "reuse:-n,device:B,snapshot-file:s?,format:s?",
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index eb41fe9..0729882 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -11,6 +11,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/boards.h"
+#include "qmp-commands.h"
 #include "migration/qemu-file.h"
 #include "migration/register.h"
 #include "hw/s390x/storage-attributes.h"
@@ -26,6 +27,15 @@
 #define STATTR_FLAG_ERROR   0x04ULL
 #define STATTR_FLAG_DONE    0x08ULL
 
+static S390StAttribState *s390_get_stattrib_device(void)
+{
+    S390StAttribState *sas;
+
+    sas = S390_STATTRIB(object_resolve_path_type("", TYPE_S390_STATTRIB, NULL));
+    assert(sas);
+    return sas;
+}
+
 void s390_stattrib_init(void)
 {
     Object *obj;
@@ -48,6 +58,58 @@ void s390_stattrib_init(void)
     qdev_init_nofail(DEVICE(obj));
 }
 
+/* Console commands: */
+
+void hmp_migrationmode(Monitor *mon, const QDict *qdict)
+{
+    S390StAttribState *sas = s390_get_stattrib_device();
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    uint64_t what = qdict_get_int(qdict, "mode");
+    int r;
+
+    r = sac->set_migrationmode(sas, what);
+    if (r < 0) {
+        monitor_printf(mon, "Error: %s", strerror(-r));
+    }
+}
+
+void hmp_info_cmma(Monitor *mon, const QDict *qdict)
+{
+    S390StAttribState *sas = s390_get_stattrib_device();
+    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+    uint64_t addr = qdict_get_int(qdict, "addr");
+    uint64_t buflen = qdict_get_try_int(qdict, "count", 8);
+    uint8_t *vals;
+    int cx, len;
+
+    vals = g_try_malloc(buflen);
+    if (!vals) {
+        monitor_printf(mon, "Error: %s\n", strerror(errno));
+        return;
+    }
+
+    len = sac->peek_stattr(sas, addr / TARGET_PAGE_SIZE, buflen, vals);
+    if (len < 0) {
+        monitor_printf(mon, "Error: %s", strerror(-len));
+        goto out;
+    }
+
+    monitor_printf(mon, "  CMMA attributes, "
+                   "pages %" PRIu64 "+%d (0x%" PRIx64 "):\n",
+                   addr / TARGET_PAGE_SIZE, len, addr & ~TARGET_PAGE_MASK);
+    for (cx = 0; cx < len; cx++) {
+        if (cx % 8 == 7) {
+            monitor_printf(mon, "%02x\n", vals[cx]);
+        } else {
+            monitor_printf(mon, "%02x", vals[cx]);
+        }
+    }
+    monitor_printf(mon, "\n");
+
+out:
+    g_free(vals);
+}
+
 /* Migration support: */
 
 static int cmma_load(QEMUFile *f, void *opaque, int version_id)
diff --git a/include/hw/s390x/storage-attributes.h b/include/hw/s390x/storage-attributes.h
index 161440b..ccf4aa1 100644
--- a/include/hw/s390x/storage-attributes.h
+++ b/include/hw/s390x/storage-attributes.h
@@ -13,6 +13,7 @@
 #define S390_STORAGE_ATTRIBUTES_H
 
 #include <hw/qdev.h>
+#include "monitor/monitor.h"
 
 #define TYPE_S390_STATTRIB "s390-storage_attributes"
 #define TYPE_QEMU_S390_STATTRIB "s390-storage_attributes-qemu"
@@ -65,4 +66,7 @@ typedef struct KVMS390StAttribState {
 
 void s390_stattrib_init(void);
 
+void hmp_info_cmma(Monitor *mon, const QDict *qdict);
+void hmp_migrationmode(Monitor *mon, const QDict *qdict);
+
 #endif /* S390_STORAGE_ATTRIBUTES_H */
diff --git a/monitor.c b/monitor.c
index d8ac20f..8e084f5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -81,6 +81,7 @@
 
 #if defined(TARGET_S390X)
 #include "hw/s390x/storage-keys.h"
+#include "hw/s390x/storage-attributes.h"
 #endif
 
 /*
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 05/11] s390x/cpumodel: clean up spacing and comments
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (3 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 04/11] s390x/migration: Monitor commands for storage attributes Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 06/11] s390x/cpumodel: provide compat handling for new cpu features Christian Borntraeger
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Jason J. Herne,
	Christian Borntraeger

From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>

Clean up spacing and add comments to clarify difference between base, full and
default models.

Not having spacing around the model definitions in gen-features.c is
particularly frustrating as the reader tends to misinterpret which model they
are looking at or editing.

Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 target/s390x/cpu_features.c     |  3 +++
 target/s390x/cpu_features_def.h | 35 +++++++++++++++++++++++++
 target/s390x/gen-features.c     | 58 ++++++++++++++++++++++++++++++++++++++---
 3 files changed, 93 insertions(+), 3 deletions(-)

diff --git a/target/s390x/cpu_features.c b/target/s390x/cpu_features.c
index 42fd9d7..0436dc2 100644
--- a/target/s390x/cpu_features.c
+++ b/target/s390x/cpu_features.c
@@ -83,9 +83,11 @@ static const S390FeatDef s390_features[] = {
     FEAT_INIT("dfppc", S390_FEAT_TYPE_STFL, 80, "Decimal-floating-point packed-conversion facility"),
     FEAT_INIT("vx", S390_FEAT_TYPE_STFL, 129, "Vector facility"),
 
+    /* SCLP SCCB Byte 80 - 98  (bit numbers relative to byte-80) */
     FEAT_INIT("gsls", S390_FEAT_TYPE_SCLP_CONF_CHAR, 40, "SIE: Guest-storage-limit-suppression facility"),
     FEAT_INIT("esop", S390_FEAT_TYPE_SCLP_CONF_CHAR, 46, "Enhanced-suppression-on-protection facility"),
 
+    /* SCLP SCCB Byte 116 - 119 (bit numbers relative to byte-116) */
     FEAT_INIT("64bscao", S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 0, "SIE: 64-bit-SCAO facility"),
     FEAT_INIT("cmma", S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 1, "SIE: Collaborative-memory-management assist"),
     FEAT_INIT("pfmfi", S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 9, "SIE: PFMF interpretation facility"),
@@ -183,6 +185,7 @@ static const S390FeatDef s390_features[] = {
     FEAT_INIT("kimd-sha-256", S390_FEAT_TYPE_KIMD, 2, "KIMD SHA-256"),
     FEAT_INIT("kimd-sha-512", S390_FEAT_TYPE_KIMD, 3, "KIMD SHA-512"),
     FEAT_INIT("kimd-ghash", S390_FEAT_TYPE_KIMD, 65, "KIMD GHASH"),
+
     FEAT_INIT("klmd-sha-1", S390_FEAT_TYPE_KLMD, 1, "KLMD SHA-1"),
     FEAT_INIT("klmd-sha-256", S390_FEAT_TYPE_KLMD, 2, "KLMD SHA-256"),
     FEAT_INIT("klmd-sha-512", S390_FEAT_TYPE_KLMD, 3, "KLMD SHA-512"),
diff --git a/target/s390x/cpu_features_def.h b/target/s390x/cpu_features_def.h
index aa5ab8d..f5bb7ed 100644
--- a/target/s390x/cpu_features_def.h
+++ b/target/s390x/cpu_features_def.h
@@ -15,6 +15,7 @@
 #define TARGET_S390X_CPU_FEATURES_DEF_H
 
 typedef enum {
+    /* Stfle */
     S390_FEAT_ESAN3 = 0,
     S390_FEAT_ZARCH,
     S390_FEAT_DAT_ENH,
@@ -72,12 +73,18 @@ typedef enum {
     S390_FEAT_EDAT_2,
     S390_FEAT_DFP_PACKED_CONVERSION,
     S390_FEAT_VECTOR,
+
+    /* Sclp Conf Char */
     S390_FEAT_SIE_GSLS,
     S390_FEAT_ESOP,
+
+    /* Sclp Conf Char Ext */
     S390_FEAT_SIE_64BSCAO,
     S390_FEAT_SIE_CMMA,
     S390_FEAT_SIE_PFMFI,
     S390_FEAT_SIE_IBS,
+
+    /* Sclp Cpu */
     S390_FEAT_SIE_F2,
     S390_FEAT_SIE_SKEY,
     S390_FEAT_SIE_GPERE,
@@ -85,8 +92,12 @@ typedef enum {
     S390_FEAT_SIE_SIGPIF,
     S390_FEAT_SIE_IB,
     S390_FEAT_SIE_CEI,
+
+    /* Misc */
     S390_FEAT_DAT_ENH_2,
     S390_FEAT_CMM,
+
+    /* PLO */
     S390_FEAT_PLO_CL,
     S390_FEAT_PLO_CLG,
     S390_FEAT_PLO_CLGR,
@@ -111,6 +122,8 @@ typedef enum {
     S390_FEAT_PLO_CSTSTG,
     S390_FEAT_PLO_CSTSTGR,
     S390_FEAT_PLO_CSTSTX,
+
+    /* PTFF */
     S390_FEAT_PTFF_QTO,
     S390_FEAT_PTFF_QSI,
     S390_FEAT_PTFF_QPT,
@@ -118,6 +131,8 @@ typedef enum {
     S390_FEAT_PTFF_QTOU,
     S390_FEAT_PTFF_STO,
     S390_FEAT_PTFF_STOU,
+
+    /* KMAC */
     S390_FEAT_KMAC_DEA,
     S390_FEAT_KMAC_TDEA_128,
     S390_FEAT_KMAC_TDEA_192,
@@ -130,6 +145,8 @@ typedef enum {
     S390_FEAT_KMAC_EAES_128,
     S390_FEAT_KMAC_EAES_192,
     S390_FEAT_KMAC_EAES_256,
+
+    /* KMC */
     S390_FEAT_KMC_DEA,
     S390_FEAT_KMC_TDEA_128,
     S390_FEAT_KMC_TDEA_192,
@@ -143,6 +160,8 @@ typedef enum {
     S390_FEAT_KMC_EAES_192,
     S390_FEAT_KMC_EAES_256,
     S390_FEAT_KMC_PRNG,
+
+    /* KM */
     S390_FEAT_KM_DEA,
     S390_FEAT_KM_TDEA_128,
     S390_FEAT_KM_TDEA_192,
@@ -159,19 +178,27 @@ typedef enum {
     S390_FEAT_KM_XTS_AES_256,
     S390_FEAT_KM_XTS_EAES_128,
     S390_FEAT_KM_XTS_EAES_256,
+
+    /* KIMD */
     S390_FEAT_KIMD_SHA_1,
     S390_FEAT_KIMD_SHA_256,
     S390_FEAT_KIMD_SHA_512,
     S390_FEAT_KIMD_GHASH,
+
+    /* KLMD */
     S390_FEAT_KLMD_SHA_1,
     S390_FEAT_KLMD_SHA_256,
     S390_FEAT_KLMD_SHA_512,
+
+    /* PCKMO */
     S390_FEAT_PCKMO_EDEA,
     S390_FEAT_PCKMO_ETDEA_128,
     S390_FEAT_PCKMO_ETDEA_256,
     S390_FEAT_PCKMO_AES_128,
     S390_FEAT_PCKMO_AES_192,
     S390_FEAT_PCKMO_AES_256,
+
+    /* KMCTR */
     S390_FEAT_KMCTR_DEA,
     S390_FEAT_KMCTR_TDEA_128,
     S390_FEAT_KMCTR_TDEA_192,
@@ -184,6 +211,8 @@ typedef enum {
     S390_FEAT_KMCTR_EAES_128,
     S390_FEAT_KMCTR_EAES_192,
     S390_FEAT_KMCTR_EAES_256,
+
+    /* KMF */
     S390_FEAT_KMF_DEA,
     S390_FEAT_KMF_TDEA_128,
     S390_FEAT_KMF_TDEA_192,
@@ -196,6 +225,8 @@ typedef enum {
     S390_FEAT_KMF_EAES_128,
     S390_FEAT_KMF_EAES_192,
     S390_FEAT_KMF_EAES_256,
+
+    /* KMO */
     S390_FEAT_KMO_DEA,
     S390_FEAT_KMO_TDEA_128,
     S390_FEAT_KMO_TDEA_192,
@@ -208,6 +239,8 @@ typedef enum {
     S390_FEAT_KMO_EAES_128,
     S390_FEAT_KMO_EAES_192,
     S390_FEAT_KMO_EAES_256,
+
+    /* PCC */
     S390_FEAT_PCC_CMAC_DEA,
     S390_FEAT_PCC_CMAC_TDEA_128,
     S390_FEAT_PCC_CMAC_TDEA_192,
@@ -224,6 +257,8 @@ typedef enum {
     S390_FEAT_PCC_XTS_AES_256,
     S390_FEAT_PCC_XTS_EAES_128,
     S390_FEAT_PCC_XTS_EAES_256,
+
+    /* PPNO */
     S390_FEAT_PPNO_SHA_512_DRNG,
     S390_FEAT_MAX,
 } S390Feat;
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index e674738..8ca2b47 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -211,14 +211,20 @@ static uint16_t group_MSA_EXT_5[] = {
     S390_FEAT_GROUP_MSA_EXT_5,
 };
 
-/* base features in order of release */
+/* Base features (in order of release)
+ * Only non-hypervisor managed features belong here.
+ * Base feature sets are static meaning they do not change in future QEMU
+ * releases.
+ */
 static uint16_t base_GEN7_GA1[] = {
     S390_FEAT_GROUP_PLO,
     S390_FEAT_ESAN3,
     S390_FEAT_ZARCH,
 };
+
 #define base_GEN7_GA2 EmptyFeat
 #define base_GEN7_GA3 EmptyFeat
+
 static uint16_t base_GEN8_GA1[] = {
     S390_FEAT_DAT_ENH,
     S390_FEAT_EXTENDED_TRANSLATION_2,
@@ -227,10 +233,12 @@ static uint16_t base_GEN8_GA1[] = {
     S390_FEAT_LONG_DISPLACEMENT_FAST,
     S390_FEAT_HFP_MADDSUB,
 };
+
 #define base_GEN8_GA2 EmptyFeat
 #define base_GEN8_GA3 EmptyFeat
 #define base_GEN8_GA4 EmptyFeat
 #define base_GEN8_GA5 EmptyFeat
+
 static uint16_t base_GEN9_GA1[] = {
     S390_FEAT_IDTE_SEGMENT,
     S390_FEAT_ASN_LX_REUSE,
@@ -245,8 +253,10 @@ static uint16_t base_GEN9_GA1[] = {
     S390_FEAT_ETF3_ENH,
     S390_FEAT_DAT_ENH_2,
 };
+
 #define base_GEN9_GA2 EmptyFeat
 #define base_GEN9_GA3 EmptyFeat
+
 static uint16_t base_GEN10_GA1[] = {
     S390_FEAT_CONDITIONAL_SSKE,
     S390_FEAT_PARSING_ENH,
@@ -263,6 +273,7 @@ static uint16_t base_GEN10_GA1[] = {
 };
 #define base_GEN10_GA2 EmptyFeat
 #define base_GEN10_GA3 EmptyFeat
+
 static uint16_t base_GEN11_GA1[] = {
     S390_FEAT_NONQ_KEY_SETTING,
     S390_FEAT_ENHANCED_MONITOR,
@@ -272,21 +283,30 @@ static uint16_t base_GEN11_GA1[] = {
     S390_FEAT_CMPSC_ENH,
     S390_FEAT_INTERLOCKED_ACCESS_2,
 };
+
 #define base_GEN11_GA2 EmptyFeat
+
 static uint16_t base_GEN12_GA1[] = {
     S390_FEAT_DFP_ZONED_CONVERSION,
     S390_FEAT_STFLE_49,
     S390_FEAT_LOCAL_TLB_CLEARING,
 };
+
 #define base_GEN12_GA2 EmptyFeat
+
 static uint16_t base_GEN13_GA1[] = {
     S390_FEAT_STFLE_53,
     S390_FEAT_DFP_PACKED_CONVERSION,
     S390_FEAT_GROUP_GEN13_PTFF,
 };
+
 #define base_GEN13_GA2 EmptyFeat
 
-/* full features differing to the base in order of release */
+/* Full features (in order of release)
+ * Automatically includes corresponding base features.
+ * Full features are all features this hardware supports even if kvm/QEMU do not
+ * support these features yet.
+ */
 static uint16_t full_GEN7_GA1[] = {
     S390_FEAT_SIE_F2,
     S390_FEAT_SIE_SKEY,
@@ -294,30 +314,38 @@ static uint16_t full_GEN7_GA1[] = {
     S390_FEAT_SIE_IB,
     S390_FEAT_SIE_CEI,
 };
+
 static uint16_t full_GEN7_GA2[] = {
     S390_FEAT_EXTENDED_TRANSLATION_2,
 };
+
 static uint16_t full_GEN7_GA3[] = {
     S390_FEAT_LONG_DISPLACEMENT,
     S390_FEAT_SIE_SIIF,
 };
+
 static uint16_t full_GEN8_GA1[] = {
     S390_FEAT_SIE_GSLS,
     S390_FEAT_SIE_64BSCAO,
 };
+
 #define full_GEN8_GA2 EmptyFeat
+
 static uint16_t full_GEN8_GA3[] = {
     S390_FEAT_ASN_LX_REUSE,
     S390_FEAT_EXTENDED_TRANSLATION_3,
 };
+
 #define full_GEN8_GA4 EmptyFeat
 #define full_GEN8_GA5 EmptyFeat
+
 static uint16_t full_GEN9_GA1[] = {
     S390_FEAT_STORE_HYPERVISOR_INFO,
     S390_FEAT_GROUP_MSA_EXT_1,
     S390_FEAT_CMM,
     S390_FEAT_SIE_CMMA,
 };
+
 static uint16_t full_GEN9_GA2[] = {
     S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
     S390_FEAT_EXTRACT_CPU_TIME,
@@ -325,10 +353,12 @@ static uint16_t full_GEN9_GA2[] = {
     S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
     S390_FEAT_DFP,
 };
+
 static uint16_t full_GEN9_GA3[] = {
     S390_FEAT_CONDITIONAL_SSKE,
     S390_FEAT_PFPO,
 };
+
 static uint16_t full_GEN10_GA1[] = {
     S390_FEAT_EDAT,
     S390_FEAT_CONFIGURATION_TOPOLOGY,
@@ -337,34 +367,46 @@ static uint16_t full_GEN10_GA1[] = {
     S390_FEAT_SIE_PFMFI,
     S390_FEAT_SIE_SIGPIF,
 };
+
 static uint16_t full_GEN10_GA2[] = {
     S390_FEAT_SET_PROGRAM_PARAMETERS,
     S390_FEAT_SIE_IBS,
 };
+
 static uint16_t full_GEN10_GA3[] = {
     S390_FEAT_GROUP_MSA_EXT_3,
 };
+
 static uint16_t full_GEN11_GA1[] = {
     S390_FEAT_IPTE_RANGE,
     S390_FEAT_ACCESS_EXCEPTION_FS_INDICATION,
     S390_FEAT_GROUP_MSA_EXT_4,
 };
+
 #define full_GEN11_GA2 EmptyFeat
+
 static uint16_t full_GEN12_GA1[] = {
     S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE,
     S390_FEAT_TRANSACTIONAL_EXE,
     S390_FEAT_RUNTIME_INSTRUMENTATION,
     S390_FEAT_EDAT_2,
 };
+
 static uint16_t full_GEN12_GA2[] = {
     S390_FEAT_GROUP_MSA_EXT_5,
 };
+
 static uint16_t full_GEN13_GA1[] = {
     S390_FEAT_VECTOR,
 };
+
 #define full_GEN13_GA2 EmptyFeat
 
-/* default features differing to the base in order of release */
+/* Default features (in order of release)
+ * Automatically includes corresponding base features.
+ * Default features are all features this version of QEMU supports for this
+ * hardware model. Default feature sets can grow with new QEMU releases.
+ */
 #define default_GEN7_GA1 EmptyFeat
 #define default_GEN7_GA2 EmptyFeat
 #define default_GEN7_GA3 EmptyFeat
@@ -373,37 +415,47 @@ static uint16_t full_GEN13_GA1[] = {
 #define default_GEN8_GA3 EmptyFeat
 #define default_GEN8_GA4 EmptyFeat
 #define default_GEN8_GA5 EmptyFeat
+
 static uint16_t default_GEN9_GA1[] = {
     S390_FEAT_STORE_HYPERVISOR_INFO,
     S390_FEAT_GROUP_MSA_EXT_1,
     S390_FEAT_CMM,
 };
+
 #define default_GEN9_GA2 EmptyFeat
 #define default_GEN9_GA3 EmptyFeat
+
 static uint16_t default_GEN10_GA1[] = {
     S390_FEAT_EDAT,
     S390_FEAT_GROUP_MSA_EXT_2,
 };
+
 #define default_GEN10_GA2 EmptyFeat
 #define default_GEN10_GA3 EmptyFeat
+
 static uint16_t default_GEN11_GA1[] = {
     S390_FEAT_GROUP_MSA_EXT_3,
     S390_FEAT_IPTE_RANGE,
     S390_FEAT_ACCESS_EXCEPTION_FS_INDICATION,
     S390_FEAT_GROUP_MSA_EXT_4,
 };
+
 #define default_GEN11_GA2 EmptyFeat
+
 static uint16_t default_GEN12_GA1[] = {
     S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE,
     S390_FEAT_TRANSACTIONAL_EXE,
     S390_FEAT_RUNTIME_INSTRUMENTATION,
     S390_FEAT_EDAT_2,
 };
+
 #define default_GEN12_GA2 EmptyFeat
+
 static uint16_t default_GEN13_GA1[] = {
     S390_FEAT_GROUP_MSA_EXT_5,
     S390_FEAT_VECTOR,
 };
+
 #define default_GEN13_GA2 EmptyFeat
 
 /****** END FEATURE DEFS ******/
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 06/11] s390x/cpumodel: provide compat handling for new cpu features
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (4 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 05/11] s390x/cpumodel: clean up spacing and comments Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 14:51   ` Cornelia Huck
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 07/11] s390x: add flags field for registering I/O adapter Christian Borntraeger
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Jason J. Herne,
	Christian Borntraeger

From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>

Provide a mechanism to disable features in compatibility machines.

Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 target/s390x/cpu_models.c | 26 ++++++++++++++++++++++++++
 target/s390x/cpu_models.h |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 7cb55dc..fd3f459 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -77,6 +77,32 @@ static S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
 };
 
+void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat)
+{
+    const S390CPUDef *def;
+
+    def = s390_find_cpu_def(0, gen, ec_ga, NULL);
+    clear_bit(feat, (unsigned long *)&def->default_feat);
+}
+
+void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat)
+{
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
+        const S390CPUDef *def = &s390_cpu_defs[i];
+
+        if (def->gen < gen) {
+            continue;
+        }
+        if (def->gen == gen && def->ec_ga < ec_ga) {
+            continue;
+        }
+
+        clear_bit(feat, (unsigned long *)&def->default_feat);
+    }
+}
+
 uint32_t s390_get_hmfai(void)
 {
     static S390CPU *cpu;
diff --git a/target/s390x/cpu_models.h b/target/s390x/cpu_models.h
index d41f8d6..c0bee15 100644
--- a/target/s390x/cpu_models.h
+++ b/target/s390x/cpu_models.h
@@ -72,6 +72,8 @@ typedef struct S390CPUModel {
 #define ibc_gen(x)        (x == 0 ? 0 : ((x >> 4) + S390_GEN_Z10))
 #define ibc_ec_ga(x)      (x & 0xf)
 
+void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat);
+void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat);
 uint32_t s390_get_hmfai(void);
 uint8_t s390_get_mha_pow(void);
 uint32_t s390_get_ibc_val(void);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 07/11] s390x: add flags field for registering I/O adapter
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (5 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 06/11] s390x/cpumodel: provide compat handling for new cpu features Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 15:00   ` Cornelia Huck
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback Christian Borntraeger
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Fei Li,
	Christian Borntraeger

From: Fei Li <sherrylf@linux.vnet.ibm.com>

Introduce a new 'flags' field to IoAdapter to contain further
characteristics of the adapter, like whether the adapter is subject to
adapter-interruption suppression.

For the kvm case, pass this value in the 'flags' field when
registering an adapter.

Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hw/intc/s390_flic.c          | 2 +-
 hw/intc/s390_flic_kvm.c      | 3 ++-
 hw/s390x/css-bridge.c        | 2 +-
 hw/s390x/css.c               | 8 ++++++--
 hw/s390x/s390-pci-bus.c      | 3 ++-
 include/hw/s390x/css.h       | 8 +++++++-
 include/hw/s390x/s390_flic.h | 2 +-
 7 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/hw/intc/s390_flic.c b/hw/intc/s390_flic.c
index 837158b..d3938b3 100644
--- a/hw/intc/s390_flic.c
+++ b/hw/intc/s390_flic.c
@@ -48,7 +48,7 @@ void s390_flic_init(void)
 
 static int qemu_s390_register_io_adapter(S390FLICState *fs, uint32_t id,
                                          uint8_t isc, bool swap,
-                                         bool is_maskable)
+                                         bool is_maskable, uint8_t flags)
 {
     /* nothing to do */
     return 0;
diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
index 0bcd49f..15ff534 100644
--- a/hw/intc/s390_flic_kvm.c
+++ b/hw/intc/s390_flic_kvm.c
@@ -186,13 +186,14 @@ static int __get_all_irqs(KVMS390FLICState *flic,
 
 static int kvm_s390_register_io_adapter(S390FLICState *fs, uint32_t id,
                                         uint8_t isc, bool swap,
-                                        bool is_maskable)
+                                        bool is_maskable, uint8_t flags)
 {
     struct kvm_s390_io_adapter adapter = {
         .id = id,
         .isc = isc,
         .maskable = is_maskable,
         .swap = swap,
+        .flags = flags,
     };
     KVMS390FLICState *flic = KVM_S390_FLIC(fs);
     int r;
diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
index 823747f..c4a9735 100644
--- a/hw/s390x/css-bridge.c
+++ b/hw/s390x/css-bridge.c
@@ -110,7 +110,7 @@ VirtualCssBus *virtual_css_bus_init(void)
     qbus_set_hotplug_handler(bus, dev, &error_abort);
 
     css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
-                             &error_abort);
+                             0, &error_abort);
 
     return cbus;
  }
diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index d67fffa..1fcbc84 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -225,6 +225,7 @@ typedef struct IoAdapter {
     uint32_t id;
     uint8_t type;
     uint8_t isc;
+    uint8_t flags;
 } IoAdapter;
 
 typedef struct ChannelSubSys {
@@ -392,10 +393,12 @@ uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc)
  *
  * @swap: an indication if byte swap is needed.
  * @maskable: an indication if the adapter is subject to the mask operation.
+ * @flags: further characteristics of the adapter.
+ *         e.g. suppressible, an indication if the adapter is subject to AIS.
  * @errp: location to store error information.
  */
 void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
-                              Error **errp)
+                              uint8_t flags, Error **errp)
 {
     uint32_t id;
     int ret, isc;
@@ -413,12 +416,13 @@ void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
 
     for (isc = 0; isc <= MAX_ISC; isc++) {
         id = (type << 3) | isc;
-        ret = fsc->register_io_adapter(fs, id, isc, swap, maskable);
+        ret = fsc->register_io_adapter(fs, id, isc, swap, maskable, flags);
         if (ret == 0) {
             adapter = g_new0(IoAdapter, 1);
             adapter->id = id;
             adapter->isc = isc;
             adapter->type = type;
+            adapter->flags = flags;
             channel_subsys.io_adapters[type][isc] = adapter;
         } else {
             error_setg_errno(errp, -ret, "Unexpected error %d when "
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 5651483..b9603e7 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -582,7 +582,8 @@ static int s390_pcihost_init(SysBusDevice *dev)
     QTAILQ_INIT(&s->pending_sei);
     QTAILQ_INIT(&s->zpci_devs);
 
-    css_register_io_adapters(CSS_IO_ADAPTER_PCI, true, false, &error_abort);
+    css_register_io_adapters(CSS_IO_ADAPTER_PCI, true, false,
+                             S390_ADAPTER_SUPPRESSIBLE, &error_abort);
 
     return 0;
 }
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index eb0e26f..e028960 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -167,7 +167,13 @@ typedef enum {
 
 uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
 void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
-                              Error **errp);
+                              uint8_t flags, Error **errp);
+
+#ifndef CONFIG_KVM
+#define S390_ADAPTER_SUPPRESSIBLE 0x01
+#else
+#define S390_ADAPTER_SUPPRESSIBLE KVM_S390_ADAPTER_SUPPRESSIBLE
+#endif
 
 #ifndef CONFIG_USER_ONLY
 SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid,
diff --git a/include/hw/s390x/s390_flic.h b/include/hw/s390x/s390_flic.h
index caa6fc6..d4145ad 100644
--- a/include/hw/s390x/s390_flic.h
+++ b/include/hw/s390x/s390_flic.h
@@ -56,7 +56,7 @@ typedef struct S390FLICStateClass {
     DeviceClass parent_class;
 
     int (*register_io_adapter)(S390FLICState *fs, uint32_t id, uint8_t isc,
-                               bool swap, bool maskable);
+                               bool swap, bool maskable, uint8_t flags);
     int (*io_adapter_map)(S390FLICState *fs, uint32_t id, uint64_t map_addr,
                           bool do_map);
     int (*add_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (6 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 07/11] s390x: add flags field for registering I/O adapter Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 15:07   ` Cornelia Huck
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 09/11] s390x/flic: introduce inject_airq callback Christian Borntraeger
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Fei Li,
	Yi Min Zhao, Christian Borntraeger

From: Fei Li <sherrylf@linux.vnet.ibm.com>

In order to emulate the adapter interruption suppression (AIS)
facility properly, the guest needs to be able to modify the AIS mask.
Interrupt suppression will be handled via the flic (for kvm, via a
recently introduced kernel backend; for !kvm, in the flic code), so
let's introduce a method to change the mode via the flic interface.

Co-authored-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hw/intc/s390_flic.c          | 37 ++++++++++++++++++++++++++++++++++++-
 hw/intc/s390_flic_kvm.c      | 36 ++++++++++++++++++++++++++++++++++++
 include/hw/s390x/s390_flic.h |  9 ++++++++-
 3 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/hw/intc/s390_flic.c b/hw/intc/s390_flic.c
index d3938b3..ce7f355 100644
--- a/hw/intc/s390_flic.c
+++ b/hw/intc/s390_flic.c
@@ -79,15 +79,47 @@ static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id,
     return -ENOSYS;
 }
 
+static int qemu_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
+                                     uint16_t mode)
+{
+    QEMUS390FLICState *flic  = QEMU_S390_FLIC(fs);
+
+    switch (mode) {
+    case SIC_IRQ_MODE_ALL:
+        flic->simm &= ~AIS_MODE_MASK(isc);
+        flic->nimm &= ~AIS_MODE_MASK(isc);
+        break;
+    case SIC_IRQ_MODE_SINGLE:
+        flic->simm |= AIS_MODE_MASK(isc);
+        flic->nimm &= ~AIS_MODE_MASK(isc);
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static void qemu_s390_flic_reset(DeviceState *dev)
+{
+    QEMUS390FLICState *flic = QEMU_S390_FLIC(dev);
+
+    flic->simm = 0;
+    flic->nimm = 0;
+}
+
 static void qemu_s390_flic_class_init(ObjectClass *oc, void *data)
 {
+    DeviceClass *dc = DEVICE_CLASS(oc);
     S390FLICStateClass *fsc = S390_FLIC_COMMON_CLASS(oc);
 
+    dc->reset = qemu_s390_flic_reset;
     fsc->register_io_adapter = qemu_s390_register_io_adapter;
     fsc->io_adapter_map = qemu_s390_io_adapter_map;
     fsc->add_adapter_routes = qemu_s390_add_adapter_routes;
     fsc->release_adapter_routes = qemu_s390_release_adapter_routes;
     fsc->clear_io_irq = qemu_s390_clear_io_flic;
+    fsc->modify_ais_mode = qemu_s390_modify_ais_mode;
 }
 
 static Property s390_flic_common_properties[] = {
@@ -98,12 +130,15 @@ static Property s390_flic_common_properties[] = {
 
 static void s390_flic_common_realize(DeviceState *dev, Error **errp)
 {
-    uint32_t max_batch = S390_FLIC_COMMON(dev)->adapter_routes_max_batch;
+    S390FLICState *fs = S390_FLIC_COMMON(dev);
+    uint32_t max_batch = fs->adapter_routes_max_batch;
 
     if (max_batch > ADAPTER_ROUTES_MAX_GSI) {
         error_setg(errp, "flic property adapter_routes_max_batch too big"
                    " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
     }
+
+    fs->ais_supported = true;
 }
 
 static void s390_flic_class_init(ObjectClass *oc, void *data)
diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
index 15ff534..55aa35f 100644
--- a/hw/intc/s390_flic_kvm.c
+++ b/hw/intc/s390_flic_kvm.c
@@ -20,6 +20,7 @@
 #include "sysemu/kvm.h"
 #include "hw/s390x/s390_flic.h"
 #include "hw/s390x/adapter.h"
+#include "hw/s390x/css.h"
 #include "trace.h"
 
 #define FLIC_SAVE_INITIAL_SIZE getpagesize()
@@ -149,6 +150,26 @@ static int kvm_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id,
     return rc ? -errno : 0;
 }
 
+static int kvm_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
+                                    uint16_t mode)
+{
+    KVMS390FLICState *flic = KVM_S390_FLIC(fs);
+    struct kvm_s390_ais_req req = {
+        .isc = isc,
+        .mode = mode,
+    };
+    struct kvm_device_attr attr = {
+        .group = KVM_DEV_FLIC_AISM,
+        .addr = (uint64_t)&req,
+    };
+
+    if (!fs->ais_supported) {
+        return -ENOSYS;
+    }
+
+    return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
+}
+
 /**
  * __get_all_irqs - store all pending irqs in buffer
  * @flic: pointer to flic device state
@@ -406,6 +427,7 @@ typedef struct KVMS390FLICStateClass {
 
 static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
 {
+    S390FLICState *fs = S390_FLIC_COMMON(dev);
     KVMS390FLICState *flic_state = KVM_S390_FLIC(dev);
     struct kvm_create_device cd = {0};
     struct kvm_device_attr test_attr = {0};
@@ -438,6 +460,7 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
     flic_state->clear_io_supported = !ioctl(flic_state->fd,
                                             KVM_HAS_DEVICE_ATTR, test_attr);
 
+    fs->ais_supported = false;
     return;
 fail:
     error_propagate(errp, errp_local);
@@ -446,10 +469,12 @@ fail:
 static void kvm_s390_flic_reset(DeviceState *dev)
 {
     KVMS390FLICState *flic = KVM_S390_FLIC(dev);
+    S390FLICState *fs = S390_FLIC_COMMON(dev);
     struct kvm_device_attr attr = {
         .group = KVM_DEV_FLIC_CLEAR_IRQS,
     };
     int rc = 0;
+    uint8_t isc;
 
     if (flic->fd == -1) {
         return;
@@ -457,6 +482,16 @@ static void kvm_s390_flic_reset(DeviceState *dev)
 
     flic_disable_wait_pfault(flic);
 
+    if (fs->ais_supported) {
+        for (isc = 0; isc <= MAX_ISC; isc++) {
+            rc = kvm_s390_modify_ais_mode(fs, isc, SIC_IRQ_MODE_ALL);
+            if (rc) {
+                error_report("Failed to reset ais mode for isc %d: %s",
+                             isc, strerror(-rc));
+            }
+        }
+    }
+
     rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr);
     if (rc) {
         trace_flic_reset_failed(errno);
@@ -479,6 +514,7 @@ static void kvm_s390_flic_class_init(ObjectClass *oc, void *data)
     fsc->add_adapter_routes = kvm_s390_add_adapter_routes;
     fsc->release_adapter_routes = kvm_s390_release_adapter_routes;
     fsc->clear_io_irq = kvm_s390_clear_io_flic;
+    fsc->modify_ais_mode = kvm_s390_modify_ais_mode;
 }
 
 static const TypeInfo kvm_s390_flic_info = {
diff --git a/include/hw/s390x/s390_flic.h b/include/hw/s390x/s390_flic.h
index d4145ad..f500184 100644
--- a/include/hw/s390x/s390_flic.h
+++ b/include/hw/s390x/s390_flic.h
@@ -44,7 +44,7 @@ typedef struct S390FLICState {
     SysBusDevice parent_obj;
     /* to limit AdapterRoutes.num_routes for compat */
     uint32_t adapter_routes_max_batch;
-
+    bool ais_supported;
 } S390FLICState;
 
 #define S390_FLIC_COMMON_CLASS(klass) \
@@ -63,6 +63,7 @@ typedef struct S390FLICStateClass {
     void (*release_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
     int (*clear_io_irq)(S390FLICState *fs, uint16_t subchannel_id,
                         uint16_t subchannel_nr);
+    int (*modify_ais_mode)(S390FLICState *fs, uint8_t isc, uint16_t mode);
 } S390FLICStateClass;
 
 #define TYPE_KVM_S390_FLIC "s390-flic-kvm"
@@ -73,8 +74,14 @@ typedef struct S390FLICStateClass {
 #define QEMU_S390_FLIC(obj) \
     OBJECT_CHECK(QEMUS390FLICState, (obj), TYPE_QEMU_S390_FLIC)
 
+#define SIC_IRQ_MODE_ALL 0
+#define SIC_IRQ_MODE_SINGLE 1
+#define AIS_MODE_MASK(isc) (0x80 >> isc)
+
 typedef struct QEMUS390FLICState {
     S390FLICState parent_obj;
+    uint8_t simm;
+    uint8_t nimm;
 } QEMUS390FLICState;
 
 void s390_flic_init(void);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 09/11] s390x/flic: introduce inject_airq callback
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (7 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 15:12   ` Cornelia Huck
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling Christian Borntraeger
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Yi Min Zhao,
	Fei Li, Christian Borntraeger

From: Yi Min Zhao <zyimin@linux.vnet.ibm.com>

Let's introduce a specialized way to inject adapter interrupts that,
unlike the common interrupt injection method, allows to take the
characteristics of the adapter into account.

For adapters subject to AIS facility:
- for non-kvm case, we handle the suppression for a given ISC in QEMU.
- for kvm case, we pass adapter id to kvm to do airq injection.

Add add tracepoint for suppressed airq and suppressing airq.

Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hw/intc/s390_flic.c          | 27 +++++++++++++++++++++++++++
 hw/intc/s390_flic_kvm.c      | 18 ++++++++++++++++++
 hw/intc/trace-events         |  4 ++++
 include/hw/s390x/s390_flic.h |  2 ++
 4 files changed, 51 insertions(+)

diff --git a/hw/intc/s390_flic.c b/hw/intc/s390_flic.c
index ce7f355..efcb1dd 100644
--- a/hw/intc/s390_flic.c
+++ b/hw/intc/s390_flic.c
@@ -13,8 +13,11 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
 #include "hw/sysbus.h"
+#include "hw/s390x/ioinst.h"
 #include "hw/s390x/s390_flic.h"
+#include "hw/s390x/css.h"
 #include "trace.h"
+#include "cpu.h"
 #include "hw/qdev.h"
 #include "qapi/error.h"
 #include "hw/s390x/s390-virtio-ccw.h"
@@ -100,6 +103,29 @@ static int qemu_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
     return 0;
 }
 
+static int qemu_s390_inject_airq(S390FLICState *fs, uint8_t type,
+                                 uint8_t isc, uint8_t flags)
+{
+    QEMUS390FLICState *flic = QEMU_S390_FLIC(fs);
+    bool flag = flags & S390_ADAPTER_SUPPRESSIBLE;
+    uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
+
+    if (flag && (flic->nimm & AIS_MODE_MASK(isc))) {
+        trace_qemu_s390_airq_suppressed(type, isc);
+        return 0;
+    }
+
+    s390_io_interrupt(0, 0, 0, io_int_word);
+
+    if (flag && (flic->simm & AIS_MODE_MASK(isc))) {
+        flic->nimm |= AIS_MODE_MASK(isc);
+        trace_qemu_s390_suppress_airq(isc, "Single-Interruption Mode",
+                                      "NO-Interruptions Mode");
+    }
+
+    return 0;
+}
+
 static void qemu_s390_flic_reset(DeviceState *dev)
 {
     QEMUS390FLICState *flic = QEMU_S390_FLIC(dev);
@@ -120,6 +146,7 @@ static void qemu_s390_flic_class_init(ObjectClass *oc, void *data)
     fsc->release_adapter_routes = qemu_s390_release_adapter_routes;
     fsc->clear_io_irq = qemu_s390_clear_io_flic;
     fsc->modify_ais_mode = qemu_s390_modify_ais_mode;
+    fsc->inject_airq = qemu_s390_inject_airq;
 }
 
 static Property s390_flic_common_properties[] = {
diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
index 55aa35f..a587ace 100644
--- a/hw/intc/s390_flic_kvm.c
+++ b/hw/intc/s390_flic_kvm.c
@@ -170,6 +170,23 @@ static int kvm_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
     return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
 }
 
+static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type,
+                                uint8_t isc, uint8_t flags)
+{
+    KVMS390FLICState *flic = KVM_S390_FLIC(fs);
+    uint32_t id = css_get_adapter_id(type, isc);
+    struct kvm_device_attr attr = {
+        .group = KVM_DEV_FLIC_AIRQ_INJECT,
+        .attr = id,
+    };
+
+    if (!fs->ais_supported) {
+        return -ENOSYS;
+    }
+
+    return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
+}
+
 /**
  * __get_all_irqs - store all pending irqs in buffer
  * @flic: pointer to flic device state
@@ -515,6 +532,7 @@ static void kvm_s390_flic_class_init(ObjectClass *oc, void *data)
     fsc->release_adapter_routes = kvm_s390_release_adapter_routes;
     fsc->clear_io_irq = kvm_s390_clear_io_flic;
     fsc->modify_ais_mode = kvm_s390_modify_ais_mode;
+    fsc->inject_airq = kvm_s390_inject_airq;
 }
 
 static const TypeInfo kvm_s390_flic_info = {
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 729c128..c586714 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -73,6 +73,10 @@ flic_create_device(int err) "flic: create device failed %d"
 flic_no_device_api(int err) "flic: no Device Contral API support %d"
 flic_reset_failed(int err) "flic: reset failed %d"
 
+# hw/intc/s390_flic.c
+qemu_s390_airq_suppressed(uint8_t type, uint8_t isc) "flic: adapter I/O interrupt suppressed (type %x isc %x)"
+qemu_s390_suppress_airq(uint8_t isc, const char *from, const char *to) "flic: for isc %x, suppress airq by modifying ais mode from %s to %s"
+
 # hw/intc/aspeed_vic.c
 aspeed_vic_set_irq(int irq, int level) "Enabling IRQ %d: %d"
 aspeed_vic_update_fiq(int flags) "Raising FIQ: %d"
diff --git a/include/hw/s390x/s390_flic.h b/include/hw/s390x/s390_flic.h
index f500184..2f173d9 100644
--- a/include/hw/s390x/s390_flic.h
+++ b/include/hw/s390x/s390_flic.h
@@ -64,6 +64,8 @@ typedef struct S390FLICStateClass {
     int (*clear_io_irq)(S390FLICState *fs, uint16_t subchannel_id,
                         uint16_t subchannel_nr);
     int (*modify_ais_mode)(S390FLICState *fs, uint8_t isc, uint16_t mode);
+    int (*inject_airq)(S390FLICState *fs, uint8_t type, uint8_t isc,
+                       uint8_t flags);
 } S390FLICStateClass;
 
 #define TYPE_KVM_S390_FLIC "s390-flic-kvm"
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (8 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 09/11] s390x/flic: introduce inject_airq callback Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 13:40   ` Thomas Huth
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt Christian Borntraeger
  2017-07-12 13:31 ` [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Cornelia Huck
  11 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Fei Li,
	Yi Min Zhao, Christian Borntraeger

From: Fei Li <sherrylf@linux.vnet.ibm.com>

Currently, we do nothing for the SIC instruction, but we need to
implement it properly. Let's add proper handling in the backend code.

Co-authored-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hw/s390x/css.c         | 26 ++++++++++++++++++++++++++
 hw/s390x/trace-events  |  1 +
 include/hw/s390x/css.h |  2 ++
 target/s390x/kvm.c     | 16 +++++++++++++++-
 4 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 1fcbc84..7b82176 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -521,6 +521,32 @@ void css_conditional_io_interrupt(SubchDev *sch)
     }
 }
 
+int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode)
+{
+    S390FLICState *fs = s390_get_flic();
+    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
+    int r;
+
+    if (env->psw.mask & PSW_MASK_PSTATE) {
+        r = -PGM_PRIVILEGED;
+        goto out;
+    }
+
+    trace_css_do_sic(mode, isc);
+    switch (mode) {
+    case SIC_IRQ_MODE_ALL:
+    case SIC_IRQ_MODE_SINGLE:
+        break;
+    default:
+        r = -PGM_OPERAND;
+        goto out;
+    }
+
+    r = fsc->modify_ais_mode(fs, isc, mode) ? -PGM_OPERATION : 0;
+out:
+    return r;
+}
+
 void css_adapter_interrupt(uint8_t isc)
 {
     uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
diff --git a/hw/s390x/trace-events b/hw/s390x/trace-events
index 84ea964..f07e974 100644
--- a/hw/s390x/trace-events
+++ b/hw/s390x/trace-events
@@ -8,6 +8,7 @@ css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x
 css_assign_subch(const char *do_assign, uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno) "CSS: %s %x.%x.%04x (devno %04x)"
 css_io_interrupt(int cssid, int ssid, int schid, uint32_t intparm, uint8_t isc, const char *conditional) "CSS: I/O interrupt on sch %x.%x.%04x (intparm %08x, isc %x) %s"
 css_adapter_interrupt(uint8_t isc) "CSS: adapter I/O interrupt (isc %x)"
+css_do_sic(uint16_t mode, uint8_t isc) "CSS: set interruption mode %x on isc %x"
 
 # hw/s390x/virtio-ccw.c
 virtio_ccw_interpret_ccw(int cssid, int ssid, int schid, int cmd_code) "VIRTIO-CCW: %x.%x.%04x: interpret command %x"
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index e028960..5ee6d52 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -12,6 +12,7 @@
 #ifndef CSS_H
 #define CSS_H
 
+#include "cpu.h"
 #include "hw/s390x/adapter.h"
 #include "hw/s390x/s390_flic.h"
 #include "hw/s390x/ioinst.h"
@@ -165,6 +166,7 @@ typedef enum {
     CSS_IO_ADAPTER_TYPE_NUMS,
 } CssIoAdapterType;
 
+int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode);
 uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
 void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
                               uint8_t flags, Error **errp);
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index 7a2a7c0..78ebe83 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -1206,7 +1206,21 @@ static int kvm_stpcifc_service_call(S390CPU *cpu, struct kvm_run *run)
 
 static int kvm_sic_service_call(S390CPU *cpu, struct kvm_run *run)
 {
-    /* NOOP */
+    CPUS390XState *env = &cpu->env;
+    uint8_t r1 = (run->s390_sieic.ipa & 0x00f0) >> 4;
+    uint8_t r3 = run->s390_sieic.ipa & 0x000f;
+    uint8_t isc;
+    uint16_t mode;
+    int r;
+
+    cpu_synchronize_state(CPU(cpu));
+    mode = env->regs[r1] & 0xffff;
+    isc = (env->regs[r3] >> 27) & 0x7;
+    r = css_do_sic(env, isc, mode);
+    if (r) {
+        enter_pgmcheck(cpu, -r);
+    }
+
     return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (9 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling Christian Borntraeger
@ 2017-07-12 12:57 ` Christian Borntraeger
  2017-07-12 14:26   ` Thomas Huth
  2017-07-13  8:46   ` Cornelia Huck
  2017-07-12 13:31 ` [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Cornelia Huck
  11 siblings, 2 replies; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-12 12:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Graf, Richard Henderson, Cornelia Huck, Yi Min Zhao,
	Fei Li, Christian Borntraeger

From: Yi Min Zhao <zyimin@linux.vnet.ibm.com>

Let's use the new inject_airq callback of flic to inject adapter
interrupts. For kvm case, if the kernel flic doesn't support the new
interface, the irq routine remains unchanged. For non-kvm case,
qemu-flic handles the suppression process.

Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hw/s390x/css.c          | 18 ++++++++++++++++--
 hw/s390x/s390-pci-bus.c |  2 +-
 hw/s390x/virtio-ccw.c   |  2 +-
 include/hw/s390x/css.h  |  2 +-
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 7b82176..ee4ebbf 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -547,12 +547,26 @@ out:
     return r;
 }
 
-void css_adapter_interrupt(uint8_t isc)
+void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
 {
+    S390FLICState *fs = s390_get_flic();
+    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
     uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
+    IoAdapter *adapter = channel_subsys.io_adapters[type][isc];
+
+    if (!adapter) {
+        return;
+    }
 
     trace_css_adapter_interrupt(isc);
-    s390_io_interrupt(0, 0, 0, io_int_word);
+    if (fs->ais_supported) {
+        if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
+            fprintf(stderr, "Failed to inject airq with AIS supported\n");
+            exit(1);
+        }
+    } else {
+        s390_io_interrupt(0, 0, 0, io_int_word);
+    }
 }
 
 static void sch_handle_clear_func(SubchDev *sch)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index b9603e7..2de4435 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -504,7 +504,7 @@ static void s390_msi_ctrl_write(void *opaque, hwaddr addr, uint64_t data,
                    0x80 >> ((ind_bit + vec) % 8));
     if (!set_ind_atomic(pbdev->routes.adapter.summary_addr + sum_bit / 8,
                                        0x80 >> (sum_bit % 8))) {
-        css_adapter_interrupt(pbdev->isc);
+        css_adapter_interrupt(CSS_IO_ADAPTER_PCI, pbdev->isc);
     }
 }
 
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index e18fd26..5afd9bb 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -1074,7 +1074,7 @@ static void virtio_ccw_notify(DeviceState *d, uint16_t vector)
                                   0x80 >> ((ind_bit + vector) % 8));
             if (!virtio_set_ind_atomic(sch, dev->summary_indicator->addr,
                                        0x01)) {
-                css_adapter_interrupt(dev->thinint_isc);
+                css_adapter_interrupt(CSS_IO_ADAPTER_VIRTIO, dev->thinint_isc);
             }
         } else {
             indicators = address_space_ldq(&address_space_memory,
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index 5ee6d52..dd36d39 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -155,7 +155,6 @@ void css_generate_sch_crws(uint8_t cssid, uint8_t ssid, uint16_t schid,
 void css_generate_chp_crws(uint8_t cssid, uint8_t chpid);
 void css_generate_css_crws(uint8_t cssid);
 void css_clear_sei_pending(void);
-void css_adapter_interrupt(uint8_t isc);
 int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data);
 int do_subchannel_work_virtual(SubchDev *sub, ORB *orb);
 int do_subchannel_work_passthrough(SubchDev *sub, ORB *orb);
@@ -166,6 +165,7 @@ typedef enum {
     CSS_IO_ADAPTER_TYPE_NUMS,
 } CssIoAdapterType;
 
+void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc);
 int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode);
 uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
 void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 00/11] pending s390 patches part 1
  2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
                   ` (10 preceding siblings ...)
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt Christian Borntraeger
@ 2017-07-12 13:31 ` Cornelia Huck
  11 siblings, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-12 13:31 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: qemu-devel, Alexander Graf, Richard Henderson

On Wed, 12 Jul 2017 14:57:34 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> here is the first bunch on patches for s390:
> 
> - Some more PCI changes
> - storage attribute migration (migration of CMMA state)
> - cpu model cleanups and preparations
> 
> part 2 will follow shortly (sorry for the delay - process reasons ;-)).
> 
> In addition to that I plan to have the migration rework from Halil
> and Thomas network boot.

2.10 will really be a huge update for s390x :)

> 
> 
> Christian Borntraeger (1):
>   linux-headers: update to 4.13-rc0
> 
> Claudio Imbrenda (2):
>   s390x/migration: Storage attributes device
>   s390x/migration: Monitor commands for storage attributes
> 
> Fei Li (3):
>   s390x: add flags field for registering I/O adapter
>   s390x/flic: introduce modify_ais_mode callback
>   s390x/sic: realize SIC handling
> 
> Janosch Frank (1):
>   s390x/kvm: Rework cmma management
> 
> Jason J. Herne (2):
>   s390x/cpumodel: clean up spacing and comments
>   s390x/cpumodel: provide compat handling for new cpu features
> 
> Yi Min Zhao (2):
>   s390x/flic: introduce inject_airq callback
>   s390x/css: update css_adapter_interrupt
> 
>  hmp-commands-info.hx                               |  16 +
>  hmp-commands.hx                                    |  16 +
>  hw/intc/s390_flic.c                                |  66 +++-
>  hw/intc/s390_flic_kvm.c                            |  57 ++-
>  hw/intc/trace-events                               |   4 +
>  hw/s390x/Makefile.objs                             |   2 +
>  hw/s390x/css-bridge.c                              |   2 +-
>  hw/s390x/css.c                                     |  52 ++-
>  hw/s390x/s390-pci-bus.c                            |   5 +-
>  hw/s390x/s390-stattrib-kvm.c                       | 178 +++++++++
>  hw/s390x/s390-stattrib.c                           | 410 +++++++++++++++++++++
>  hw/s390x/s390-virtio-ccw.c                         |  10 +-
>  hw/s390x/trace-events                              |   1 +
>  hw/s390x/virtio-ccw.c                              |   2 +-
>  include/hw/s390x/css.h                             |  12 +-
>  include/hw/s390x/s390_flic.h                       |  13 +-
>  include/hw/s390x/storage-attributes.h              |  72 ++++
>  include/standard-headers/asm-x86/hyperv.h          |  21 +-
>  include/standard-headers/linux/input-event-codes.h |   1 +
>  include/standard-headers/linux/pci_regs.h          |   1 +
>  linux-headers/asm-arm/kvm.h                        |   8 +
>  linux-headers/asm-arm64/kvm.h                      |   3 +
>  linux-headers/asm-powerpc/kvm.h                    |   6 +
>  linux-headers/asm-s390/kvm.h                       |  12 +
>  linux-headers/linux/kvm.h                          |  35 ++
>  monitor.c                                          |   1 +
>  target/s390x/cpu.h                                 |   1 +
>  target/s390x/cpu_features.c                        |   3 +
>  target/s390x/cpu_features_def.h                    |  35 ++
>  target/s390x/cpu_models.c                          |  26 ++
>  target/s390x/cpu_models.h                          |   2 +
>  target/s390x/gen-features.c                        |  58 ++-
>  target/s390x/kvm.c                                 |  42 ++-
>  33 files changed, 1135 insertions(+), 38 deletions(-)
>  create mode 100644 hw/s390x/s390-stattrib-kvm.c
>  create mode 100644 hw/s390x/s390-stattrib.c
>  create mode 100644 include/hw/s390x/storage-attributes.h
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling Christian Borntraeger
@ 2017-07-12 13:40   ` Thomas Huth
  2017-07-12 15:40     ` Cornelia Huck
  0 siblings, 1 reply; 34+ messages in thread
From: Thomas Huth @ 2017-07-12 13:40 UTC (permalink / raw)
  To: Christian Borntraeger, qemu-devel
  Cc: Yi Min Zhao, Cornelia Huck, Alexander Graf, Fei Li, Richard Henderson

On 12.07.2017 14:57, Christian Borntraeger wrote:
> From: Fei Li <sherrylf@linux.vnet.ibm.com>
> 
> Currently, we do nothing for the SIC instruction, but we need to
> implement it properly. Let's add proper handling in the backend code.
> 
> Co-authored-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  hw/s390x/css.c         | 26 ++++++++++++++++++++++++++
>  hw/s390x/trace-events  |  1 +
>  include/hw/s390x/css.h |  2 ++
>  target/s390x/kvm.c     | 16 +++++++++++++++-
>  4 files changed, 44 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/s390x/css.c b/hw/s390x/css.c
> index 1fcbc84..7b82176 100644
> --- a/hw/s390x/css.c
> +++ b/hw/s390x/css.c
> @@ -521,6 +521,32 @@ void css_conditional_io_interrupt(SubchDev *sch)
>      }
>  }
>  
> +int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode)
> +{
> +    S390FLICState *fs = s390_get_flic();
> +    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
> +    int r;
> +
> +    if (env->psw.mask & PSW_MASK_PSTATE) {
> +        r = -PGM_PRIVILEGED;
> +        goto out;

Why not simply:

           return -PGM_PRIVILEGED;

?

Same for the other goto below ... and then you also do not need the "r"
variable anymore.

> +    }
> +
> +    trace_css_do_sic(mode, isc);
> +    switch (mode) {
> +    case SIC_IRQ_MODE_ALL:
> +    case SIC_IRQ_MODE_SINGLE:
> +        break;
> +    default:
> +        r = -PGM_OPERAND;
> +        goto out;
> +    }
> +
> +    r = fsc->modify_ais_mode(fs, isc, mode) ? -PGM_OPERATION : 0;
> +out:
> +    return r;
> +}
> +
>  void css_adapter_interrupt(uint8_t isc)
>  {
>      uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
> diff --git a/hw/s390x/trace-events b/hw/s390x/trace-events
> index 84ea964..f07e974 100644
> --- a/hw/s390x/trace-events
> +++ b/hw/s390x/trace-events
> @@ -8,6 +8,7 @@ css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x
>  css_assign_subch(const char *do_assign, uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno) "CSS: %s %x.%x.%04x (devno %04x)"
>  css_io_interrupt(int cssid, int ssid, int schid, uint32_t intparm, uint8_t isc, const char *conditional) "CSS: I/O interrupt on sch %x.%x.%04x (intparm %08x, isc %x) %s"
>  css_adapter_interrupt(uint8_t isc) "CSS: adapter I/O interrupt (isc %x)"
> +css_do_sic(uint16_t mode, uint8_t isc) "CSS: set interruption mode %x on isc %x"
>  
>  # hw/s390x/virtio-ccw.c
>  virtio_ccw_interpret_ccw(int cssid, int ssid, int schid, int cmd_code) "VIRTIO-CCW: %x.%x.%04x: interpret command %x"
> diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
> index e028960..5ee6d52 100644
> --- a/include/hw/s390x/css.h
> +++ b/include/hw/s390x/css.h
> @@ -12,6 +12,7 @@
>  #ifndef CSS_H
>  #define CSS_H
>  
> +#include "cpu.h"

Not sure, but it's a little bit strange that the channel sub-system now
depends on the CPU ... maybe the check for problem state should rather
be done in kvm.c instead?
Or should css_do_sic() rather reside in s390-pci-inst.c or in ioinst.c
instead?

>  #include "hw/s390x/adapter.h"
>  #include "hw/s390x/s390_flic.h"
>  #include "hw/s390x/ioinst.h"
> @@ -165,6 +166,7 @@ typedef enum {
>      CSS_IO_ADAPTER_TYPE_NUMS,
>  } CssIoAdapterType;
>  
> +int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode);
>  uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
>  void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
>                                uint8_t flags, Error **errp);
> diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
> index 7a2a7c0..78ebe83 100644
> --- a/target/s390x/kvm.c
> +++ b/target/s390x/kvm.c
> @@ -1206,7 +1206,21 @@ static int kvm_stpcifc_service_call(S390CPU *cpu, struct kvm_run *run)
>  
>  static int kvm_sic_service_call(S390CPU *cpu, struct kvm_run *run)
>  {
> -    /* NOOP */
> +    CPUS390XState *env = &cpu->env;
> +    uint8_t r1 = (run->s390_sieic.ipa & 0x00f0) >> 4;
> +    uint8_t r3 = run->s390_sieic.ipa & 0x000f;
> +    uint8_t isc;
> +    uint16_t mode;
> +    int r;
> +
> +    cpu_synchronize_state(CPU(cpu));
> +    mode = env->regs[r1] & 0xffff;
> +    isc = (env->regs[r3] >> 27) & 0x7;
> +    r = css_do_sic(env, isc, mode);
> +    if (r) {
> +        enter_pgmcheck(cpu, -r);
> +    }
> +
>      return 0;
>  }

 Thomas

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management Christian Borntraeger
@ 2017-07-12 13:49   ` Cornelia Huck
  2017-07-13  5:37     ` Janosch Frank
  0 siblings, 1 reply; 34+ messages in thread
From: Cornelia Huck @ 2017-07-12 13:49 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Janosch Frank

On Wed, 12 Jul 2017 14:57:35 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> From: Janosch Frank <frankja@linux.vnet.ibm.com>
> 
> Let's keep track of cmma enablement and move the mem_path check into
> the actual enablement. This now also warns users that do not use
> cpu-models about disabled cmma when using huge pages.
> 
> Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  target/s390x/cpu.h |  1 +
>  target/s390x/kvm.c | 26 +++++++++++++++++---------
>  2 files changed, 18 insertions(+), 9 deletions(-)

> @@ -177,6 +179,11 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
>      return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
>  }
>  
> +int kvm_s390_cmma_active(void)
> +{
> +    return active_cmma;
> +}

This is rather "has cmma ever been enabled"...

> +
>  static bool kvm_s390_cmma_available(void)
>  {
>      static bool initialized, value;
> @@ -197,7 +204,7 @@ void kvm_s390_cmma_reset(void)
>          .attr = KVM_S390_VM_MEM_CLR_CMMA,
>      };
>  
> -    if (mem_path || !kvm_s390_cmma_available()) {
> +    if (!kvm_s390_cmma_active()) {
>          return;
>      }

...as you don't clear it on reset, right?

Confused me a bit at first, but

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device Christian Borntraeger
@ 2017-07-12 14:09   ` Thomas Huth
  2017-07-13  7:11     ` Christian Borntraeger
  0 siblings, 1 reply; 34+ messages in thread
From: Thomas Huth @ 2017-07-12 14:09 UTC (permalink / raw)
  To: Christian Borntraeger, qemu-devel
  Cc: Claudio Imbrenda, Cornelia Huck, Alexander Graf, Richard Henderson

On 12.07.2017 14:57, Christian Borntraeger wrote:
> From: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
> 
> Storage attributes device, like we have for storage keys.
> 
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
[...]
> diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
> new file mode 100644
> index 0000000..2e7f144
> --- /dev/null
> +++ b/hw/s390x/s390-stattrib-kvm.c
> @@ -0,0 +1,178 @@
> +/*
> + * s390 storage attributes device -- KVM object
> + *
> + * Copyright 2016 IBM Corp.
> + * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or (at
> + * your option) any later version. See the COPYING file in the top-level
> + * directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "hw/boards.h"
> +#include "qmp-commands.h"

Why do you need qmp-commands.h here?

> +#include "migration/qemu-file.h"
> +#include "hw/s390x/storage-attributes.h"
> +#include "qemu/error-report.h"
> +#include "sysemu/kvm.h"
> +#include "exec/ram_addr.h"
> +#include "cpu.h"
> +
> +static void kvm_s390_stattrib_instance_init(Object *obj)
> +{
> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(obj);
> +
> +    sas->still_dirty = 0;
> +}
> +
> +static int kvm_s390_stattrib_read_helper(S390StAttribState *sa,
> +                                        uint64_t *start_gfn,
> +                                        uint32_t count,
> +                                        uint8_t *values,
> +                                        uint32_t flags)

Indentation seems to be off by 1 ----------^

> +{
> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
> +    int r;
> +    struct kvm_s390_cmma_log clog = {
> +        .values = (uint64_t)values,
> +        .start_gfn = *start_gfn,
> +        .count = count,
> +        .flags = flags,
> +    };
> +
> +    r = kvm_vm_ioctl(kvm_state, KVM_S390_GET_CMMA_BITS, &clog);
> +    if (r < 0) {
> +        error_report("Error: %s", strerror(-r));

Please avoid "Error:" ... there is currently a patch series on the
qemu-devel mailing list which will likely add an "error: " prefix for
all error_reports()s automatically. So please use a better error message
here instead, e.g. something like "KVM_S390_GET_CMMA_BITS ioctl failed".

> +        return r;
> +    }
> +
> +    *start_gfn = clog.start_gfn;
> +    sas->still_dirty = clog.remaining;
> +    return clog.count;
> +}
> +
> +static int kvm_s390_stattrib_get_stattr(S390StAttribState *sa,
> +                                        uint64_t *start_gfn,
> +                                        uint32_t count,
> +                                        uint8_t *values)
> +{
> +    return kvm_s390_stattrib_read_helper(sa, start_gfn, count, values, 0);
> +}
> +
> +static int kvm_s390_stattrib_peek_stattr(S390StAttribState *sa,
> +                                         uint64_t start_gfn,
> +                                         uint32_t count,
> +                                         uint8_t *values)
> +{
> +    return kvm_s390_stattrib_read_helper(sa, &start_gfn, count, values,
> +                                         KVM_S390_CMMA_PEEK);
> +}
> +
> +static int kvm_s390_stattrib_set_stattr(S390StAttribState *sa,
> +                                        uint64_t start_gfn,
> +                                        uint32_t count,
> +                                        uint8_t *values)
> +{
> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
> +    MachineState *machine = MACHINE(qdev_get_machine());
> +    unsigned long max = machine->maxram_size / TARGET_PAGE_SIZE;
> +
> +    if (start_gfn + count > max) {
> +        error_report("Error: invalid address.");

dito - please use a better error message.

> +        return -1;
> +    }
> +    if (!sas->incoming_buffer) {
> +        sas->incoming_buffer = g_malloc0(max);
> +    }
> +
> +    memcpy(sas->incoming_buffer + start_gfn, values, count);
> +
> +    return 0;
> +}
> +
> +static void kvm_s390_stattrib_synchronize(S390StAttribState *sa)
> +{
> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
> +    MachineState *machine = MACHINE(qdev_get_machine());
> +    unsigned long max = machine->maxram_size / TARGET_PAGE_SIZE;
> +    unsigned long cx, len = 1 << 19;
> +    int r;
> +    struct kvm_s390_cmma_log clog = {
> +        .flags = 0,
> +        .mask = ~0ULL,
> +    };
> +
> +    if (sas->incoming_buffer) {
> +        for (cx = 0; cx + len <= max; cx += len) {
> +            clog.start_gfn = cx;
> +            clog.count = len;
> +            clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
> +            r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
> +            if (r) {
> +                return;

So if the ioctl failed, it will go completely unnoticed? Sounds like
this could result in hard-to-debug situations, so maybe add an error
message here?

> +            }
> +        }
> +        if (cx < max) {
> +            clog.start_gfn = cx;
> +            clog.count = max - cx;
> +            clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
> +            r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);

check r for error?

> +        }
> +        g_free(sas->incoming_buffer);
> +        sas->incoming_buffer = NULL;
> +    }
> +}
> +
> +static int kvm_s390_stattrib_set_migrationmode(S390StAttribState *sa, bool val)
> +{
> +    struct kvm_device_attr attr = {
> +        .group = KVM_S390_VM_MIGRATION,
> +        .attr = val,
> +        .addr = 0,
> +    };
> +    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
> +}
> +
> +static long long kvm_s390_stattrib_get_dirtycount(S390StAttribState *sa)
> +{
> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
> +    uint8_t val[8];
> +
> +    kvm_s390_stattrib_peek_stattr(sa, 0, 1, val);
> +    return sas->still_dirty;
> +}
> +
> +static int kvm_s390_stattrib_get_active(S390StAttribState *sa)
> +{
> +    return kvm_s390_cmma_active() && sa->migration_enabled;
> +}
> +
> +static void kvm_s390_stattrib_class_init(ObjectClass *oc, void *data)
> +{
> +    S390StAttribClass *sac = S390_STATTRIB_CLASS(oc);
> +
> +    sac->get_stattr = kvm_s390_stattrib_get_stattr;
> +    sac->peek_stattr = kvm_s390_stattrib_peek_stattr;
> +    sac->set_stattr = kvm_s390_stattrib_set_stattr;
> +    sac->set_migrationmode = kvm_s390_stattrib_set_migrationmode;
> +    sac->get_dirtycount = kvm_s390_stattrib_get_dirtycount;
> +    sac->synchronize = kvm_s390_stattrib_synchronize;
> +    sac->get_active = kvm_s390_stattrib_get_active;
> +}
> +
> +static const TypeInfo kvm_s390_stattrib_info = {
> +    .name          = TYPE_KVM_S390_STATTRIB,
> +    .parent        = TYPE_S390_STATTRIB,
> +    .instance_init = kvm_s390_stattrib_instance_init,
> +    .instance_size = sizeof(KVMS390StAttribState),
> +    .class_init    = kvm_s390_stattrib_class_init,
> +    .class_size    = sizeof(S390StAttribClass),
> +};
> +
> +static void kvm_s390_stattrib_register_types(void)
> +{
> +    type_register_static(&kvm_s390_stattrib_info);
> +}
> +
> +type_init(kvm_s390_stattrib_register_types)
> diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
> new file mode 100644
> index 0000000..eb41fe9
> --- /dev/null
> +++ b/hw/s390x/s390-stattrib.c
> @@ -0,0 +1,348 @@
> +/*
> + * s390 storage attributes device
> + *
> + * Copyright 2016 IBM Corp.
> + * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or (at
> + * your option) any later version. See the COPYING file in the top-level
> + * directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "hw/boards.h"
> +#include "migration/qemu-file.h"
> +#include "migration/register.h"
> +#include "hw/s390x/storage-attributes.h"
> +#include "qemu/error-report.h"
> +#include "sysemu/kvm.h"
> +#include "exec/ram_addr.h"
> +#include "qapi/error.h"
> +
> +#define CMMA_BLOCK_SIZE  (1 << 10)
> +
> +#define STATTR_FLAG_EOS     0x01ULL
> +#define STATTR_FLAG_MORE    0x02ULL
> +#define STATTR_FLAG_ERROR   0x04ULL
> +#define STATTR_FLAG_DONE    0x08ULL
> +
> +void s390_stattrib_init(void)
> +{
> +    Object *obj;
> +
> +#ifdef CONFIG_KVM
> +    if (kvm_enabled() &&
> +            kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
> +        obj = object_new(TYPE_KVM_S390_STATTRIB);
> +    } else {
> +        obj = object_new(TYPE_QEMU_S390_STATTRIB);
> +    }
> +#else
> +    obj = object_new(TYPE_QEMU_S390_STATTRIB);
> +#endif

Could you maybe do something similar as in s390_flic_init() to avoid the
#ifdefs here?

> +    object_property_add_child(qdev_get_machine(), TYPE_S390_STATTRIB,
> +                              obj, NULL);
> +    object_unref(obj);
> +
> +    qdev_init_nofail(DEVICE(obj));
> +}
[...]
> +static int cmma_save(QEMUFile *f, void *opaque, int final)
> +{
> +    S390StAttribState *sas = S390_STATTRIB(opaque);
> +    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
> +    uint8_t *buf;
> +    int r, cx, reallen = 0, ret = 0;
> +    uint32_t buflen = 1 << 19;   /* 512kB cover 2GB of guest memory */
> +    uint64_t start_gfn = sas->migration_cur_gfn;
> +
> +    buf = g_try_malloc(buflen);
> +    if (!buf) {
> +        error_report("Could not allocate memory to save storage attributes");
> +        return -ENOMEM;
> +    }
> +
> +    while (final ? 1 : qemu_file_rate_limit(f) == 0) {
> +        reallen = sac->get_stattr(sas, &start_gfn, buflen, buf);
> +        if (reallen < 0) {
> +            g_free(buf);
> +            return reallen;
> +        }
> +
> +        ret = 1;
> +        if (0 == reallen) {

Please, no Yoda conditions. See CODING_STYLE file.

> +            break;
> +        }
> +        qemu_put_be64(f, (start_gfn << TARGET_PAGE_BITS) | STATTR_FLAG_MORE);
> +        qemu_put_be64(f, reallen);
> +        for (cx = 0; cx < reallen; cx++) {
> +            qemu_put_byte(f, buf[cx]);
> +        }
> +        if (!sac->get_dirtycount(sas)) {
> +            break;
> +        }
> +    }
> +
> +    sas->migration_cur_gfn = start_gfn + reallen;
> +    g_free(buf);
> +    if (final) {
> +        qemu_put_be64(f, STATTR_FLAG_DONE);
> +    }
> +    qemu_put_be64(f, STATTR_FLAG_EOS);
> +
> +    r = qemu_file_get_error(f);
> +    if (r < 0) {
> +        return r;
> +    }
> +
> +    return ret;
> +}
[...]

 Thomas

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt Christian Borntraeger
@ 2017-07-12 14:26   ` Thomas Huth
  2017-07-13  8:08     ` Christian Borntraeger
  2017-07-13  8:46   ` Cornelia Huck
  1 sibling, 1 reply; 34+ messages in thread
From: Thomas Huth @ 2017-07-12 14:26 UTC (permalink / raw)
  To: Christian Borntraeger, qemu-devel
  Cc: Yi Min Zhao, Cornelia Huck, Alexander Graf, Fei Li, Richard Henderson

On 12.07.2017 14:57, Christian Borntraeger wrote:
> From: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> 
> Let's use the new inject_airq callback of flic to inject adapter
> interrupts. For kvm case, if the kernel flic doesn't support the new
> interface, the irq routine remains unchanged. For non-kvm case,
> qemu-flic handles the suppression process.
> 
> Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  hw/s390x/css.c          | 18 ++++++++++++++++--
>  hw/s390x/s390-pci-bus.c |  2 +-
>  hw/s390x/virtio-ccw.c   |  2 +-
>  include/hw/s390x/css.h  |  2 +-
>  4 files changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/s390x/css.c b/hw/s390x/css.c
> index 7b82176..ee4ebbf 100644
> --- a/hw/s390x/css.c
> +++ b/hw/s390x/css.c
> @@ -547,12 +547,26 @@ out:
>      return r;
>  }
>  
> -void css_adapter_interrupt(uint8_t isc)
> +void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
>  {
> +    S390FLICState *fs = s390_get_flic();
> +    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
>      uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
> +    IoAdapter *adapter = channel_subsys.io_adapters[type][isc];
> +
> +    if (!adapter) {
> +        return;
> +    }
>  
>      trace_css_adapter_interrupt(isc);
> -    s390_io_interrupt(0, 0, 0, io_int_word);
> +    if (fs->ais_supported) {
> +        if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
> +            fprintf(stderr, "Failed to inject airq with AIS supported\n");

Use error_report() instead?

> +            exit(1);
> +        }
> +    } else {
> +        s390_io_interrupt(0, 0, 0, io_int_word);
> +    }
>  }

 Thomas

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 06/11] s390x/cpumodel: provide compat handling for new cpu features
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 06/11] s390x/cpumodel: provide compat handling for new cpu features Christian Borntraeger
@ 2017-07-12 14:51   ` Cornelia Huck
  0 siblings, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-12 14:51 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Jason J. Herne

On Wed, 12 Jul 2017 14:57:40 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>
> 
> Provide a mechanism to disable features in compatibility machines.

User to come in the next batch of patches?

> 
> Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
> Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  target/s390x/cpu_models.c | 26 ++++++++++++++++++++++++++
>  target/s390x/cpu_models.h |  2 ++
>  2 files changed, 28 insertions(+)

Acked-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 07/11] s390x: add flags field for registering I/O adapter
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 07/11] s390x: add flags field for registering I/O adapter Christian Borntraeger
@ 2017-07-12 15:00   ` Cornelia Huck
  0 siblings, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-12 15:00 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Fei Li

On Wed, 12 Jul 2017 14:57:41 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> From: Fei Li <sherrylf@linux.vnet.ibm.com>
> 
> Introduce a new 'flags' field to IoAdapter to contain further
> characteristics of the adapter, like whether the adapter is subject to
> adapter-interruption suppression.
> 
> For the kvm case, pass this value in the 'flags' field when
> registering an adapter.
> 
> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  hw/intc/s390_flic.c          | 2 +-
>  hw/intc/s390_flic_kvm.c      | 3 ++-
>  hw/s390x/css-bridge.c        | 2 +-
>  hw/s390x/css.c               | 8 ++++++--
>  hw/s390x/s390-pci-bus.c      | 3 ++-
>  include/hw/s390x/css.h       | 8 +++++++-
>  include/hw/s390x/s390_flic.h | 2 +-
>  7 files changed, 20 insertions(+), 8 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback Christian Borntraeger
@ 2017-07-12 15:07   ` Cornelia Huck
  2017-07-13  7:12     ` Christian Borntraeger
  0 siblings, 1 reply; 34+ messages in thread
From: Cornelia Huck @ 2017-07-12 15:07 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Fei Li, Yi Min Zhao

On Wed, 12 Jul 2017 14:57:42 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> From: Fei Li <sherrylf@linux.vnet.ibm.com>
> 
> In order to emulate the adapter interruption suppression (AIS)
> facility properly, the guest needs to be able to modify the AIS mask.
> Interrupt suppression will be handled via the flic (for kvm, via a
> recently introduced kernel backend; for !kvm, in the flic code), so
> let's introduce a method to change the mode via the flic interface.
> 
> Co-authored-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  hw/intc/s390_flic.c          | 37 ++++++++++++++++++++++++++++++++++++-
>  hw/intc/s390_flic_kvm.c      | 36 ++++++++++++++++++++++++++++++++++++
>  include/hw/s390x/s390_flic.h |  9 ++++++++-
>  3 files changed, 80 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/intc/s390_flic.c b/hw/intc/s390_flic.c
> index d3938b3..ce7f355 100644
> --- a/hw/intc/s390_flic.c
> +++ b/hw/intc/s390_flic.c
> @@ -79,15 +79,47 @@ static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id,
>      return -ENOSYS;
>  }
>  
> +static int qemu_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
> +                                     uint16_t mode)
> +{
> +    QEMUS390FLICState *flic  = QEMU_S390_FLIC(fs);
> +
> +    switch (mode) {
> +    case SIC_IRQ_MODE_ALL:
> +        flic->simm &= ~AIS_MODE_MASK(isc);
> +        flic->nimm &= ~AIS_MODE_MASK(isc);
> +        break;
> +    case SIC_IRQ_MODE_SINGLE:
> +        flic->simm |= AIS_MODE_MASK(isc);
> +        flic->nimm &= ~AIS_MODE_MASK(isc);

Can we have some documentation about the meaning of simm/nimm in qemu?
The one from the patch description of the respective kernel patch would
be fine.

> +        break;
> +    default:
> +        return -EINVAL;
> +    }
> +
> +    return 0;
> +}
> +
>

(...)

> @@ -406,6 +427,7 @@ typedef struct KVMS390FLICStateClass {
>  
>  static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
>  {
> +    S390FLICState *fs = S390_FLIC_COMMON(dev);
>      KVMS390FLICState *flic_state = KVM_S390_FLIC(dev);
>      struct kvm_create_device cd = {0};
>      struct kvm_device_attr test_attr = {0};
> @@ -438,6 +460,7 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
>      flic_state->clear_io_supported = !ioctl(flic_state->fd,
>                                              KVM_HAS_DEVICE_ATTR, test_attr);
>  
> +    fs->ais_supported = false;

The patch actually enabling this for kvm is in the next batch of
patches, I assume?

>      return;
>  fail:
>      error_propagate(errp, errp_local);

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 09/11] s390x/flic: introduce inject_airq callback
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 09/11] s390x/flic: introduce inject_airq callback Christian Borntraeger
@ 2017-07-12 15:12   ` Cornelia Huck
  0 siblings, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-12 15:12 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Yi Min Zhao, Fei Li

On Wed, 12 Jul 2017 14:57:43 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> From: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> 
> Let's introduce a specialized way to inject adapter interrupts that,
> unlike the common interrupt injection method, allows to take the
> characteristics of the adapter into account.
> 
> For adapters subject to AIS facility:
> - for non-kvm case, we handle the suppression for a given ISC in QEMU.
> - for kvm case, we pass adapter id to kvm to do airq injection.
> 
> Add add tracepoint for suppressed airq and suppressing airq.

s/Add add tracepoint/Add tracepoints/

> 
> Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  hw/intc/s390_flic.c          | 27 +++++++++++++++++++++++++++
>  hw/intc/s390_flic_kvm.c      | 18 ++++++++++++++++++
>  hw/intc/trace-events         |  4 ++++
>  include/hw/s390x/s390_flic.h |  2 ++
>  4 files changed, 51 insertions(+)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling
  2017-07-12 13:40   ` Thomas Huth
@ 2017-07-12 15:40     ` Cornelia Huck
  0 siblings, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-12 15:40 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Christian Borntraeger, qemu-devel, Yi Min Zhao, Alexander Graf,
	Fei Li, Richard Henderson

On Wed, 12 Jul 2017 15:40:02 +0200
Thomas Huth <thuth@redhat.com> wrote:

> On 12.07.2017 14:57, Christian Borntraeger wrote:
> > From: Fei Li <sherrylf@linux.vnet.ibm.com>
> > 
> > Currently, we do nothing for the SIC instruction, but we need to
> > implement it properly. Let's add proper handling in the backend code.
> > 
> > Co-authored-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> > Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> > Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
> > Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> > ---
> >  hw/s390x/css.c         | 26 ++++++++++++++++++++++++++
> >  hw/s390x/trace-events  |  1 +
> >  include/hw/s390x/css.h |  2 ++
> >  target/s390x/kvm.c     | 16 +++++++++++++++-
> >  4 files changed, 44 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/s390x/css.c b/hw/s390x/css.c
> > index 1fcbc84..7b82176 100644
> > --- a/hw/s390x/css.c
> > +++ b/hw/s390x/css.c
> > @@ -521,6 +521,32 @@ void css_conditional_io_interrupt(SubchDev *sch)
> >      }
> >  }
> >  
> > +int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode)
> > +{
> > +    S390FLICState *fs = s390_get_flic();
> > +    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
> > +    int r;
> > +
> > +    if (env->psw.mask & PSW_MASK_PSTATE) {
> > +        r = -PGM_PRIVILEGED;
> > +        goto out;  
> 
> Why not simply:
> 
>            return -PGM_PRIVILEGED;
> 
> ?
> 
> Same for the other goto below ... and then you also do not need the "r"
> variable anymore.

I'm slightly in favour of the single exit style.

> 
> > +    }
> > +
> > +    trace_css_do_sic(mode, isc);
> > +    switch (mode) {
> > +    case SIC_IRQ_MODE_ALL:
> > +    case SIC_IRQ_MODE_SINGLE:
> > +        break;
> > +    default:
> > +        r = -PGM_OPERAND;
> > +        goto out;
> > +    }
> > +
> > +    r = fsc->modify_ais_mode(fs, isc, mode) ? -PGM_OPERATION : 0;
> > +out:
> > +    return r;
> > +}
> > +
> >  void css_adapter_interrupt(uint8_t isc)
> >  {
> >      uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;

(...)

> > diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
> > index e028960..5ee6d52 100644
> > --- a/include/hw/s390x/css.h
> > +++ b/include/hw/s390x/css.h
> > @@ -12,6 +12,7 @@
> >  #ifndef CSS_H
> >  #define CSS_H
> >  
> > +#include "cpu.h"  
> 
> Not sure, but it's a little bit strange that the channel sub-system now
> depends on the CPU ... maybe the check for problem state should rather
> be done in kvm.c instead?

This would mean that tcg would need to duplicate those checks should we
want to wire it up in the future. (FWIW, the sclp backend code in
hw/s390x/sclp.c also does the respective checks, probably for exactly
that reason.)

> Or should css_do_sic() rather reside in s390-pci-inst.c or in ioinst.c
> instead?

s390-pci-inst.c is only a good choice if we are sure that sic will be
applicable for pci only even in the future - and I don't think we can
be. (The ais stuff is tied to the adapter, who knows which adapter
types may arrive in the future...)

I/O interrupt injection is currently triggered from the css code (where
it belongs IMO), so I think the code should stay where it is now.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management
  2017-07-12 13:49   ` Cornelia Huck
@ 2017-07-13  5:37     ` Janosch Frank
  0 siblings, 0 replies; 34+ messages in thread
From: Janosch Frank @ 2017-07-13  5:37 UTC (permalink / raw)
  To: Cornelia Huck, Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 1708 bytes --]

On 12.07.2017 15:49, Cornelia Huck wrote:
> On Wed, 12 Jul 2017 14:57:35 +0200
> Christian Borntraeger <borntraeger@de.ibm.com> wrote:
> 
>> From: Janosch Frank <frankja@linux.vnet.ibm.com>
>>
>> Let's keep track of cmma enablement and move the mem_path check into
>> the actual enablement. This now also warns users that do not use
>> cpu-models about disabled cmma when using huge pages.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>> ---
>>  target/s390x/cpu.h |  1 +
>>  target/s390x/kvm.c | 26 +++++++++++++++++---------
>>  2 files changed, 18 insertions(+), 9 deletions(-)
> 
>> @@ -177,6 +179,11 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
>>      return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
>>  }
>>  
>> +int kvm_s390_cmma_active(void)
>> +{
>> +    return active_cmma;
>> +}
> 
> This is rather "has cmma ever been enabled"...
> 
>> +
>>  static bool kvm_s390_cmma_available(void)
>>  {
>>      static bool initialized, value;
>> @@ -197,7 +204,7 @@ void kvm_s390_cmma_reset(void)
>>          .attr = KVM_S390_VM_MEM_CLR_CMMA,
>>      };
>>  
>> -    if (mem_path || !kvm_s390_cmma_available()) {
>> +    if (!kvm_s390_cmma_active()) {
>>          return;
>>      }
> 
> ...as you don't clear it on reset, right?

I guess you mean KVM_S390_VM_MEM_CLR_CMMA, yes that only
manipulates/clears the PGSTE values but can not disable the cmma
facility. Disabling that on a running VM would be "interesting" at best.

> 
> Confused me a bit at first, but
> 
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>

Thanks!



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device
  2017-07-12 14:09   ` Thomas Huth
@ 2017-07-13  7:11     ` Christian Borntraeger
  2017-07-13  7:32       ` Cornelia Huck
  2017-07-13  7:35       ` Thomas Huth
  0 siblings, 2 replies; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-13  7:11 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Claudio Imbrenda, Cornelia Huck, Alexander Graf, Richard Henderson

Thanks for the review, all valid. Claudio has provided me the following fixup.

I plan to fold that in the base patch (retest pending).

Christian


---
 hw/s390x/s390-stattrib-kvm.c          | 26 +++++++++++++++++++-------
 hw/s390x/s390-stattrib.c              | 12 +++---------
 include/hw/s390x/storage-attributes.h |  9 +++++++++
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
index 2e7f144..2ab3060 100644
--- a/hw/s390x/s390-stattrib-kvm.c
+++ b/hw/s390x/s390-stattrib-kvm.c
@@ -11,7 +11,6 @@

 #include "qemu/osdep.h"
 #include "hw/boards.h"
-#include "qmp-commands.h"
 #include "migration/qemu-file.h"
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
@@ -19,6 +18,15 @@
 #include "exec/ram_addr.h"
 #include "cpu.h"

+Object *kvm_s390_stattrib_create(void)
+{
+    if (kvm_enabled() &&
+                kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
+        return object_new(TYPE_KVM_S390_STATTRIB);
+    }
+    return object_new(TYPE_QEMU_S390_STATTRIB);
+}
+
 static void kvm_s390_stattrib_instance_init(Object *obj)
 {
     KVMS390StAttribState *sas = KVM_S390_STATTRIB(obj);
@@ -27,10 +35,10 @@ static void kvm_s390_stattrib_instance_init(Object *obj)
 }

 static int kvm_s390_stattrib_read_helper(S390StAttribState *sa,
-                                        uint64_t *start_gfn,
-                                        uint32_t count,
-                                        uint8_t *values,
-                                        uint32_t flags)
+                                         uint64_t *start_gfn,
+                                         uint32_t count,
+                                         uint8_t *values,
+                                         uint32_t flags)
 {
     KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
     int r;
@@ -43,7 +51,7 @@ static int kvm_s390_stattrib_read_helper(S390StAttribState *sa,

     r = kvm_vm_ioctl(kvm_state, KVM_S390_GET_CMMA_BITS, &clog);
     if (r < 0) {
-        error_report("Error: %s", strerror(-r));
+        error_report("KVM_S390_GET_CMMA_BITS failed: %s", strerror(-r));
         return r;
     }

@@ -79,7 +87,7 @@ static int kvm_s390_stattrib_set_stattr(S390StAttribState *sa,
     unsigned long max = machine->maxram_size / TARGET_PAGE_SIZE;

     if (start_gfn + count > max) {
-        error_report("Error: invalid address.");
+        error_report("Out of memory bounds when setting storage attributes");
         return -1;
     }
     if (!sas->incoming_buffer) {
@@ -110,6 +118,7 @@ static void kvm_s390_stattrib_synchronize(S390StAttribState *sa)
             clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
             r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
             if (r) {
+                error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror(-r));
                 return;
             }
         }
@@ -118,6 +127,9 @@ static void kvm_s390_stattrib_synchronize(S390StAttribState *sa)
             clog.count = max - cx;
             clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
             r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
+            if (r) {
+                error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror(-r));
+            }
         }
         g_free(sas->incoming_buffer);
         sas->incoming_buffer = NULL;
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index b9533b4..bac9aea 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -40,16 +40,10 @@ void s390_stattrib_init(void)
 {
     Object *obj;

-#ifdef CONFIG_KVM
-    if (kvm_enabled() &&
-            kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
-        obj = object_new(TYPE_KVM_S390_STATTRIB);
-    } else {
+    obj = kvm_s390_stattrib_create();
+    if (!obj) {
         obj = object_new(TYPE_QEMU_S390_STATTRIB);
     }
-#else
-    obj = object_new(TYPE_QEMU_S390_STATTRIB);
-#endif

     object_property_add_child(qdev_get_machine(), TYPE_S390_STATTRIB,
                               obj, NULL);
@@ -224,7 +218,7 @@ static int cmma_save(QEMUFile *f, void *opaque, int final)
         }

         ret = 1;
-        if (0 == reallen) {
+        if (!reallen) {
             break;
         }
         qemu_put_be64(f, (start_gfn << TARGET_PAGE_BITS) | STATTR_FLAG_MORE);
diff --git a/include/hw/s390x/storage-attributes.h b/include/hw/s390x/storage-attributes.h
index ccf4aa1..9be954d 100644
--- a/include/hw/s390x/storage-attributes.h
+++ b/include/hw/s390x/storage-attributes.h
@@ -66,6 +66,15 @@ typedef struct KVMS390StAttribState {

 void s390_stattrib_init(void);

+#ifdef CONFIG_KVM
+Object *kvm_s390_stattrib_create(void);
+#else
+static inline Object *kvm_s390_stattrib_create(void)
+{
+    return NULL;
+}
+#endif
+
 void hmp_info_cmma(Monitor *mon, const QDict *qdict);
 void hmp_migrationmode(Monitor *mon, const QDict *qdict);


On 07/12/2017 04:09 PM, Thomas Huth wrote:
> On 12.07.2017 14:57, Christian Borntraeger wrote:
>> From: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
>>
>> Storage attributes device, like we have for storage keys.
>>
>> Signed-off-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>> ---
> [...]
>> diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
>> new file mode 100644
>> index 0000000..2e7f144
>> --- /dev/null
>> +++ b/hw/s390x/s390-stattrib-kvm.c
>> @@ -0,0 +1,178 @@
>> +/*
>> + * s390 storage attributes device -- KVM object
>> + *
>> + * Copyright 2016 IBM Corp.
>> + * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or (at
>> + * your option) any later version. See the COPYING file in the top-level
>> + * directory.
>> + */
>> +
>> +#include "qemu/osdep.h"
>> +#include "hw/boards.h"
>> +#include "qmp-commands.h"
> 
> Why do you need qmp-commands.h here?
> 
>> +#include "migration/qemu-file.h"
>> +#include "hw/s390x/storage-attributes.h"
>> +#include "qemu/error-report.h"
>> +#include "sysemu/kvm.h"
>> +#include "exec/ram_addr.h"
>> +#include "cpu.h"
>> +
>> +static void kvm_s390_stattrib_instance_init(Object *obj)
>> +{
>> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(obj);
>> +
>> +    sas->still_dirty = 0;
>> +}
>> +
>> +static int kvm_s390_stattrib_read_helper(S390StAttribState *sa,
>> +                                        uint64_t *start_gfn,
>> +                                        uint32_t count,
>> +                                        uint8_t *values,
>> +                                        uint32_t flags)
> 
> Indentation seems to be off by 1 ----------^
> 
>> +{
>> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
>> +    int r;
>> +    struct kvm_s390_cmma_log clog = {
>> +        .values = (uint64_t)values,
>> +        .start_gfn = *start_gfn,
>> +        .count = count,
>> +        .flags = flags,
>> +    };
>> +
>> +    r = kvm_vm_ioctl(kvm_state, KVM_S390_GET_CMMA_BITS, &clog);
>> +    if (r < 0) {
>> +        error_report("Error: %s", strerror(-r));
> 
> Please avoid "Error:" ... there is currently a patch series on the
> qemu-devel mailing list which will likely add an "error: " prefix for
> all error_reports()s automatically. So please use a better error message
> here instead, e.g. something like "KVM_S390_GET_CMMA_BITS ioctl failed".
> 
>> +        return r;
>> +    }
>> +
>> +    *start_gfn = clog.start_gfn;
>> +    sas->still_dirty = clog.remaining;
>> +    return clog.count;
>> +}
>> +
>> +static int kvm_s390_stattrib_get_stattr(S390StAttribState *sa,
>> +                                        uint64_t *start_gfn,
>> +                                        uint32_t count,
>> +                                        uint8_t *values)
>> +{
>> +    return kvm_s390_stattrib_read_helper(sa, start_gfn, count, values, 0);
>> +}
>> +
>> +static int kvm_s390_stattrib_peek_stattr(S390StAttribState *sa,
>> +                                         uint64_t start_gfn,
>> +                                         uint32_t count,
>> +                                         uint8_t *values)
>> +{
>> +    return kvm_s390_stattrib_read_helper(sa, &start_gfn, count, values,
>> +                                         KVM_S390_CMMA_PEEK);
>> +}
>> +
>> +static int kvm_s390_stattrib_set_stattr(S390StAttribState *sa,
>> +                                        uint64_t start_gfn,
>> +                                        uint32_t count,
>> +                                        uint8_t *values)
>> +{
>> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
>> +    MachineState *machine = MACHINE(qdev_get_machine());
>> +    unsigned long max = machine->maxram_size / TARGET_PAGE_SIZE;
>> +
>> +    if (start_gfn + count > max) {
>> +        error_report("Error: invalid address.");
> 
> dito - please use a better error message.
> 
>> +        return -1;
>> +    }
>> +    if (!sas->incoming_buffer) {
>> +        sas->incoming_buffer = g_malloc0(max);
>> +    }
>> +
>> +    memcpy(sas->incoming_buffer + start_gfn, values, count);
>> +
>> +    return 0;
>> +}
>> +
>> +static void kvm_s390_stattrib_synchronize(S390StAttribState *sa)
>> +{
>> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
>> +    MachineState *machine = MACHINE(qdev_get_machine());
>> +    unsigned long max = machine->maxram_size / TARGET_PAGE_SIZE;
>> +    unsigned long cx, len = 1 << 19;
>> +    int r;
>> +    struct kvm_s390_cmma_log clog = {
>> +        .flags = 0,
>> +        .mask = ~0ULL,
>> +    };
>> +
>> +    if (sas->incoming_buffer) {
>> +        for (cx = 0; cx + len <= max; cx += len) {
>> +            clog.start_gfn = cx;
>> +            clog.count = len;
>> +            clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
>> +            r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
>> +            if (r) {
>> +                return;
> 
> So if the ioctl failed, it will go completely unnoticed? Sounds like
> this could result in hard-to-debug situations, so maybe add an error
> message here?
> 
>> +            }
>> +        }
>> +        if (cx < max) {
>> +            clog.start_gfn = cx;
>> +            clog.count = max - cx;
>> +            clog.values = (uint64_t)(sas->incoming_buffer + cx * len);
>> +            r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
> 
> check r for error?
> 
>> +        }
>> +        g_free(sas->incoming_buffer);
>> +        sas->incoming_buffer = NULL;
>> +    }
>> +}
>> +
>> +static int kvm_s390_stattrib_set_migrationmode(S390StAttribState *sa, bool val)
>> +{
>> +    struct kvm_device_attr attr = {
>> +        .group = KVM_S390_VM_MIGRATION,
>> +        .attr = val,
>> +        .addr = 0,
>> +    };
>> +    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
>> +}
>> +
>> +static long long kvm_s390_stattrib_get_dirtycount(S390StAttribState *sa)
>> +{
>> +    KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
>> +    uint8_t val[8];
>> +
>> +    kvm_s390_stattrib_peek_stattr(sa, 0, 1, val);
>> +    return sas->still_dirty;
>> +}
>> +
>> +static int kvm_s390_stattrib_get_active(S390StAttribState *sa)
>> +{
>> +    return kvm_s390_cmma_active() && sa->migration_enabled;
>> +}
>> +
>> +static void kvm_s390_stattrib_class_init(ObjectClass *oc, void *data)
>> +{
>> +    S390StAttribClass *sac = S390_STATTRIB_CLASS(oc);
>> +
>> +    sac->get_stattr = kvm_s390_stattrib_get_stattr;
>> +    sac->peek_stattr = kvm_s390_stattrib_peek_stattr;
>> +    sac->set_stattr = kvm_s390_stattrib_set_stattr;
>> +    sac->set_migrationmode = kvm_s390_stattrib_set_migrationmode;
>> +    sac->get_dirtycount = kvm_s390_stattrib_get_dirtycount;
>> +    sac->synchronize = kvm_s390_stattrib_synchronize;
>> +    sac->get_active = kvm_s390_stattrib_get_active;
>> +}
>> +
>> +static const TypeInfo kvm_s390_stattrib_info = {
>> +    .name          = TYPE_KVM_S390_STATTRIB,
>> +    .parent        = TYPE_S390_STATTRIB,
>> +    .instance_init = kvm_s390_stattrib_instance_init,
>> +    .instance_size = sizeof(KVMS390StAttribState),
>> +    .class_init    = kvm_s390_stattrib_class_init,
>> +    .class_size    = sizeof(S390StAttribClass),
>> +};
>> +
>> +static void kvm_s390_stattrib_register_types(void)
>> +{
>> +    type_register_static(&kvm_s390_stattrib_info);
>> +}
>> +
>> +type_init(kvm_s390_stattrib_register_types)
>> diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
>> new file mode 100644
>> index 0000000..eb41fe9
>> --- /dev/null
>> +++ b/hw/s390x/s390-stattrib.c
>> @@ -0,0 +1,348 @@
>> +/*
>> + * s390 storage attributes device
>> + *
>> + * Copyright 2016 IBM Corp.
>> + * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or (at
>> + * your option) any later version. See the COPYING file in the top-level
>> + * directory.
>> + */
>> +
>> +#include "qemu/osdep.h"
>> +#include "hw/boards.h"
>> +#include "migration/qemu-file.h"
>> +#include "migration/register.h"
>> +#include "hw/s390x/storage-attributes.h"
>> +#include "qemu/error-report.h"
>> +#include "sysemu/kvm.h"
>> +#include "exec/ram_addr.h"
>> +#include "qapi/error.h"
>> +
>> +#define CMMA_BLOCK_SIZE  (1 << 10)
>> +
>> +#define STATTR_FLAG_EOS     0x01ULL
>> +#define STATTR_FLAG_MORE    0x02ULL
>> +#define STATTR_FLAG_ERROR   0x04ULL
>> +#define STATTR_FLAG_DONE    0x08ULL
>> +
>> +void s390_stattrib_init(void)
>> +{
>> +    Object *obj;
>> +
>> +#ifdef CONFIG_KVM
>> +    if (kvm_enabled() &&
>> +            kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
>> +        obj = object_new(TYPE_KVM_S390_STATTRIB);
>> +    } else {
>> +        obj = object_new(TYPE_QEMU_S390_STATTRIB);
>> +    }
>> +#else
>> +    obj = object_new(TYPE_QEMU_S390_STATTRIB);
>> +#endif
> 
> Could you maybe do something similar as in s390_flic_init() to avoid the
> #ifdefs here?
> 
>> +    object_property_add_child(qdev_get_machine(), TYPE_S390_STATTRIB,
>> +                              obj, NULL);
>> +    object_unref(obj);
>> +
>> +    qdev_init_nofail(DEVICE(obj));
>> +}
> [...]
>> +static int cmma_save(QEMUFile *f, void *opaque, int final)
>> +{
>> +    S390StAttribState *sas = S390_STATTRIB(opaque);
>> +    S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
>> +    uint8_t *buf;
>> +    int r, cx, reallen = 0, ret = 0;
>> +    uint32_t buflen = 1 << 19;   /* 512kB cover 2GB of guest memory */
>> +    uint64_t start_gfn = sas->migration_cur_gfn;
>> +
>> +    buf = g_try_malloc(buflen);
>> +    if (!buf) {
>> +        error_report("Could not allocate memory to save storage attributes");
>> +        return -ENOMEM;
>> +    }
>> +
>> +    while (final ? 1 : qemu_file_rate_limit(f) == 0) {
>> +        reallen = sac->get_stattr(sas, &start_gfn, buflen, buf);
>> +        if (reallen < 0) {
>> +            g_free(buf);
>> +            return reallen;
>> +        }
>> +
>> +        ret = 1;
>> +        if (0 == reallen) {
> 
> Please, no Yoda conditions. See CODING_STYLE file.
> 
>> +            break;
>> +        }
>> +        qemu_put_be64(f, (start_gfn << TARGET_PAGE_BITS) | STATTR_FLAG_MORE);
>> +        qemu_put_be64(f, reallen);
>> +        for (cx = 0; cx < reallen; cx++) {
>> +            qemu_put_byte(f, buf[cx]);
>> +        }
>> +        if (!sac->get_dirtycount(sas)) {
>> +            break;
>> +        }
>> +    }
>> +
>> +    sas->migration_cur_gfn = start_gfn + reallen;
>> +    g_free(buf);
>> +    if (final) {
>> +        qemu_put_be64(f, STATTR_FLAG_DONE);
>> +    }
>> +    qemu_put_be64(f, STATTR_FLAG_EOS);
>> +
>> +    r = qemu_file_get_error(f);
>> +    if (r < 0) {
>> +        return r;
>> +    }
>> +
>> +    return ret;
>> +}
> [...]
> 
>  Thomas
> 
> 

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback
  2017-07-12 15:07   ` Cornelia Huck
@ 2017-07-13  7:12     ` Christian Borntraeger
  2017-07-13  7:27       ` Cornelia Huck
  0 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-13  7:12 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Fei Li, Yi Min Zhao

On 07/12/2017 05:07 PM, Cornelia Huck wrote:
>> +
>> +    switch (mode) {
>> +    case SIC_IRQ_MODE_ALL:
>> +        flic->simm &= ~AIS_MODE_MASK(isc);
>> +        flic->nimm &= ~AIS_MODE_MASK(isc);
>> +        break;
>> +    case SIC_IRQ_MODE_SINGLE:
>> +        flic->simm |= AIS_MODE_MASK(isc);
>> +        flic->nimm &= ~AIS_MODE_MASK(isc);
> 
> Can we have some documentation about the meaning of simm/nimm in qemu?
> The one from the patch description of the respective kernel patch would
> be fine.

Do you want to have that description as part of the patch description or
somewhere in the docs folder or somewhere in the code?


> 
>> +        break;
>> +    default:
>> +        return -EINVAL;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>>
> 
> (...)
> 
>> @@ -406,6 +427,7 @@ typedef struct KVMS390FLICStateClass {
>>  
>>  static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
>>  {
>> +    S390FLICState *fs = S390_FLIC_COMMON(dev);
>>      KVMS390FLICState *flic_state = KVM_S390_FLIC(dev);
>>      struct kvm_create_device cd = {0};
>>      struct kvm_device_attr test_attr = {0};
>> @@ -438,6 +460,7 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
>>      flic_state->clear_io_supported = !ioctl(flic_state->fd,
>>                                              KVM_HAS_DEVICE_ATTR, test_attr);
>>  
>> +    fs->ais_supported = false;
> 
> The patch actually enabling this for kvm is in the next batch of
> patches, I assume?


yes, will hopefully come today.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback
  2017-07-13  7:12     ` Christian Borntraeger
@ 2017-07-13  7:27       ` Cornelia Huck
  2017-07-13  7:35         ` Christian Borntraeger
  0 siblings, 1 reply; 34+ messages in thread
From: Cornelia Huck @ 2017-07-13  7:27 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Fei Li, Yi Min Zhao

On Thu, 13 Jul 2017 09:12:50 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> On 07/12/2017 05:07 PM, Cornelia Huck wrote:
> >> +
> >> +    switch (mode) {
> >> +    case SIC_IRQ_MODE_ALL:
> >> +        flic->simm &= ~AIS_MODE_MASK(isc);
> >> +        flic->nimm &= ~AIS_MODE_MASK(isc);
> >> +        break;
> >> +    case SIC_IRQ_MODE_SINGLE:
> >> +        flic->simm |= AIS_MODE_MASK(isc);
> >> +        flic->nimm &= ~AIS_MODE_MASK(isc);  
> > 
> > Can we have some documentation about the meaning of simm/nimm in qemu?
> > The one from the patch description of the respective kernel patch would
> > be fine.  
> 
> Do you want to have that description as part of the patch description or
> somewhere in the docs folder or somewhere in the code?

A comment near the definition of simm/nimm would be nice. Or in the
commit message, as for the kernel.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device
  2017-07-13  7:11     ` Christian Borntraeger
@ 2017-07-13  7:32       ` Cornelia Huck
  2017-07-13  7:35       ` Thomas Huth
  1 sibling, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-13  7:32 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Thomas Huth, qemu-devel, Claudio Imbrenda, Alexander Graf,
	Richard Henderson

On Thu, 13 Jul 2017 09:11:34 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> Thanks for the review, all valid. Claudio has provided me the following fixup.
> 
> I plan to fold that in the base patch (retest pending).

Looks good to me, and I have no further comments beyond those by Thomas.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback
  2017-07-13  7:27       ` Cornelia Huck
@ 2017-07-13  7:35         ` Christian Borntraeger
  2017-07-13  7:47           ` Cornelia Huck
  0 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-13  7:35 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Fei Li, Yi Min Zhao

On 07/13/2017 09:27 AM, Cornelia Huck wrote:
> On Thu, 13 Jul 2017 09:12:50 +0200
> Christian Borntraeger <borntraeger@de.ibm.com> wrote:
> 
>> On 07/12/2017 05:07 PM, Cornelia Huck wrote:
>>>> +
>>>> +    switch (mode) {
>>>> +    case SIC_IRQ_MODE_ALL:
>>>> +        flic->simm &= ~AIS_MODE_MASK(isc);
>>>> +        flic->nimm &= ~AIS_MODE_MASK(isc);
>>>> +        break;
>>>> +    case SIC_IRQ_MODE_SINGLE:
>>>> +        flic->simm |= AIS_MODE_MASK(isc);
>>>> +        flic->nimm &= ~AIS_MODE_MASK(isc);  
>>>
>>> Can we have some documentation about the meaning of simm/nimm in qemu?
>>> The one from the patch description of the respective kernel patch would
>>> be fine.  
>>
>> Do you want to have that description as part of the patch description or
>> somewhere in the docs folder or somewhere in the code?
> 
> A comment near the definition of simm/nimm would be nice. Or in the
> commit message, as for the kernel.
> 

I  think I will just add this to the commit message:

We introduce the 'simm' and 'nimm' fields to QEMUS390FLICState
to store interruption modes for each ISC. Each bit in 'simm' and
'nimm' targets to one ISC, and collaboratively indicate three modes:
ALL-Interruptions, SINGLE-Interruption and NO-Interruptions. This
interface can initiate most transitions between the states; transition
from SINGLE-Interruption to NO-Interruptions via adapter interrupt
injection will be introduced in a following patch. The meaningful
combinations are as follows:
    
    interruption mode | simm bit | nimm bit
    ------------------|----------|----------
             ALL      |    0     |     0
           SINGLE     |    1     |     0
             NO       |    1     |     1
    

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device
  2017-07-13  7:11     ` Christian Borntraeger
  2017-07-13  7:32       ` Cornelia Huck
@ 2017-07-13  7:35       ` Thomas Huth
  2017-07-13  7:45         ` Christian Borntraeger
  1 sibling, 1 reply; 34+ messages in thread
From: Thomas Huth @ 2017-07-13  7:35 UTC (permalink / raw)
  To: Christian Borntraeger, qemu-devel
  Cc: Claudio Imbrenda, Cornelia Huck, Alexander Graf, Richard Henderson

On 13.07.2017 09:11, Christian Borntraeger wrote:
> Thanks for the review, all valid. Claudio has provided me the following fixup.
> 
> I plan to fold that in the base patch (retest pending).
> 
> Christian
> 
> 
> ---
>  hw/s390x/s390-stattrib-kvm.c          | 26 +++++++++++++++++++-------
>  hw/s390x/s390-stattrib.c              | 12 +++---------
>  include/hw/s390x/storage-attributes.h |  9 +++++++++
>  3 files changed, 31 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
> index 2e7f144..2ab3060 100644
> --- a/hw/s390x/s390-stattrib-kvm.c
> +++ b/hw/s390x/s390-stattrib-kvm.c
> @@ -11,7 +11,6 @@
> 
>  #include "qemu/osdep.h"
>  #include "hw/boards.h"
> -#include "qmp-commands.h"
>  #include "migration/qemu-file.h"
>  #include "hw/s390x/storage-attributes.h"
>  #include "qemu/error-report.h"
> @@ -19,6 +18,15 @@
>  #include "exec/ram_addr.h"
>  #include "cpu.h"
> 
> +Object *kvm_s390_stattrib_create(void)
> +{
> +    if (kvm_enabled() &&
> +                kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
> +        return object_new(TYPE_KVM_S390_STATTRIB);
> +    }
> +    return object_new(TYPE_QEMU_S390_STATTRIB);
> +}

I think you could also return NULL here instead of
object_new(TYPE_QEMU_S390_STATTRIB) since ...

> diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
> index b9533b4..bac9aea 100644
> --- a/hw/s390x/s390-stattrib.c
> +++ b/hw/s390x/s390-stattrib.c
> @@ -40,16 +40,10 @@ void s390_stattrib_init(void)
>  {
>      Object *obj;
> 
> -#ifdef CONFIG_KVM
> -    if (kvm_enabled() &&
> -            kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
> -        obj = object_new(TYPE_KVM_S390_STATTRIB);
> -    } else {
> +    obj = kvm_s390_stattrib_create();
> +    if (!obj) {
>          obj = object_new(TYPE_QEMU_S390_STATTRIB);
>      }

... the object will be created here, too.

 Thomas

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device
  2017-07-13  7:35       ` Thomas Huth
@ 2017-07-13  7:45         ` Christian Borntraeger
  0 siblings, 0 replies; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-13  7:45 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Claudio Imbrenda, Cornelia Huck, Alexander Graf, Richard Henderson

On 07/13/2017 09:35 AM, Thomas Huth wrote:
> On 13.07.2017 09:11, Christian Borntraeger wrote:
>> Thanks for the review, all valid. Claudio has provided me the following fixup.
>>
>> I plan to fold that in the base patch (retest pending).
>>
>> Christian
>>
>>
>> ---
>>  hw/s390x/s390-stattrib-kvm.c          | 26 +++++++++++++++++++-------
>>  hw/s390x/s390-stattrib.c              | 12 +++---------
>>  include/hw/s390x/storage-attributes.h |  9 +++++++++
>>  3 files changed, 31 insertions(+), 16 deletions(-)
>>
>> diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
>> index 2e7f144..2ab3060 100644
>> --- a/hw/s390x/s390-stattrib-kvm.c
>> +++ b/hw/s390x/s390-stattrib-kvm.c
>> @@ -11,7 +11,6 @@
>>
>>  #include "qemu/osdep.h"
>>  #include "hw/boards.h"
>> -#include "qmp-commands.h"
>>  #include "migration/qemu-file.h"
>>  #include "hw/s390x/storage-attributes.h"
>>  #include "qemu/error-report.h"
>> @@ -19,6 +18,15 @@
>>  #include "exec/ram_addr.h"
>>  #include "cpu.h"
>>
>> +Object *kvm_s390_stattrib_create(void)
>> +{
>> +    if (kvm_enabled() &&
>> +                kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
>> +        return object_new(TYPE_KVM_S390_STATTRIB);
>> +    }
>> +    return object_new(TYPE_QEMU_S390_STATTRIB);
>> +}
> 
> I think you could also return NULL here instead of
> object_new(TYPE_QEMU_S390_STATTRIB) since ...

Yes, I like return NULL better so that we do not create the QEMU one
in *kvm.c. Will also fixup. thanks
> 
>> diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
>> index b9533b4..bac9aea 100644
>> --- a/hw/s390x/s390-stattrib.c
>> +++ b/hw/s390x/s390-stattrib.c
>> @@ -40,16 +40,10 @@ void s390_stattrib_init(void)
>>  {
>>      Object *obj;
>>
>> -#ifdef CONFIG_KVM
>> -    if (kvm_enabled() &&
>> -            kvm_check_extension(kvm_state, KVM_CAP_S390_CMMA_MIGRATION)) {
>> -        obj = object_new(TYPE_KVM_S390_STATTRIB);
>> -    } else {
>> +    obj = kvm_s390_stattrib_create();
>> +    if (!obj) {
>>          obj = object_new(TYPE_QEMU_S390_STATTRIB);
>>      }
> 
> ... the object will be created here, too.
> 
>  Thomas
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback
  2017-07-13  7:35         ` Christian Borntraeger
@ 2017-07-13  7:47           ` Cornelia Huck
  0 siblings, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-13  7:47 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Fei Li, Yi Min Zhao

On Thu, 13 Jul 2017 09:35:16 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> On 07/13/2017 09:27 AM, Cornelia Huck wrote:
> > On Thu, 13 Jul 2017 09:12:50 +0200
> > Christian Borntraeger <borntraeger@de.ibm.com> wrote:
> >   
> >> On 07/12/2017 05:07 PM, Cornelia Huck wrote:  
> >>>> +
> >>>> +    switch (mode) {
> >>>> +    case SIC_IRQ_MODE_ALL:
> >>>> +        flic->simm &= ~AIS_MODE_MASK(isc);
> >>>> +        flic->nimm &= ~AIS_MODE_MASK(isc);
> >>>> +        break;
> >>>> +    case SIC_IRQ_MODE_SINGLE:
> >>>> +        flic->simm |= AIS_MODE_MASK(isc);
> >>>> +        flic->nimm &= ~AIS_MODE_MASK(isc);    
> >>>
> >>> Can we have some documentation about the meaning of simm/nimm in qemu?
> >>> The one from the patch description of the respective kernel patch would
> >>> be fine.    
> >>
> >> Do you want to have that description as part of the patch description or
> >> somewhere in the docs folder or somewhere in the code?  
> > 
> > A comment near the definition of simm/nimm would be nice. Or in the
> > commit message, as for the kernel.
> >   
> 
> I  think I will just add this to the commit message:
> 
> We introduce the 'simm' and 'nimm' fields to QEMUS390FLICState
> to store interruption modes for each ISC. Each bit in 'simm' and
> 'nimm' targets to one ISC, and collaboratively indicate three modes:

s/targets to one/targets one/

> ALL-Interruptions, SINGLE-Interruption and NO-Interruptions. This
> interface can initiate most transitions between the states; transition
> from SINGLE-Interruption to NO-Interruptions via adapter interrupt
> injection will be introduced in a following patch. The meaningful
> combinations are as follows:
>     
>     interruption mode | simm bit | nimm bit
>     ------------------|----------|----------
>              ALL      |    0     |     0
>            SINGLE     |    1     |     0
>              NO       |    1     |     1
>     
> 
> 

Sounds good.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt
  2017-07-12 14:26   ` Thomas Huth
@ 2017-07-13  8:08     ` Christian Borntraeger
  2017-07-13  8:18       ` Thomas Huth
  0 siblings, 1 reply; 34+ messages in thread
From: Christian Borntraeger @ 2017-07-13  8:08 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Yi Min Zhao, Cornelia Huck, Alexander Graf, Fei Li, Richard Henderson

On 07/12/2017 04:26 PM, Thomas Huth wrote:
> On 12.07.2017 14:57, Christian Borntraeger wrote:
>> From: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
>>
>> Let's use the new inject_airq callback of flic to inject adapter
>> interrupts. For kvm case, if the kernel flic doesn't support the new
>> interface, the irq routine remains unchanged. For non-kvm case,
>> qemu-flic handles the suppression process.
>>
>> Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
>> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>> ---
>>  hw/s390x/css.c          | 18 ++++++++++++++++--
>>  hw/s390x/s390-pci-bus.c |  2 +-
>>  hw/s390x/virtio-ccw.c   |  2 +-
>>  include/hw/s390x/css.h  |  2 +-
>>  4 files changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/s390x/css.c b/hw/s390x/css.c
>> index 7b82176..ee4ebbf 100644
>> --- a/hw/s390x/css.c
>> +++ b/hw/s390x/css.c
>> @@ -547,12 +547,26 @@ out:
>>      return r;
>>  }
>>  
>> -void css_adapter_interrupt(uint8_t isc)
>> +void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
>>  {
>> +    S390FLICState *fs = s390_get_flic();
>> +    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
>>      uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
>> +    IoAdapter *adapter = channel_subsys.io_adapters[type][isc];
>> +
>> +    if (!adapter) {
>> +        return;
>> +    }
>>  
>>      trace_css_adapter_interrupt(isc);
>> -    s390_io_interrupt(0, 0, 0, io_int_word);
>> +    if (fs->ais_supported) {
>> +        if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
>> +            fprintf(stderr, "Failed to inject airq with AIS supported\n");
> 
> Use error_report() instead?

something like this on top?

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 3d28caa..997815c 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -674,7 +674,7 @@ void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
     trace_css_adapter_interrupt(isc);
     if (fs->ais_supported) {
         if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
-            fprintf(stderr, "Failed to inject airq with AIS supported\n");
+            error_report("Failed to inject airq with AIS supported");
             exit(1);
         }
     } else {

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt
  2017-07-13  8:08     ` Christian Borntraeger
@ 2017-07-13  8:18       ` Thomas Huth
  0 siblings, 0 replies; 34+ messages in thread
From: Thomas Huth @ 2017-07-13  8:18 UTC (permalink / raw)
  To: Christian Borntraeger, qemu-devel
  Cc: Yi Min Zhao, Cornelia Huck, Alexander Graf, Fei Li, Richard Henderson

On 13.07.2017 10:08, Christian Borntraeger wrote:
> On 07/12/2017 04:26 PM, Thomas Huth wrote:
>> On 12.07.2017 14:57, Christian Borntraeger wrote:
>>> From: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
>>>
>>> Let's use the new inject_airq callback of flic to inject adapter
>>> interrupts. For kvm case, if the kernel flic doesn't support the new
>>> interface, the irq routine remains unchanged. For non-kvm case,
>>> qemu-flic handles the suppression process.
>>>
>>> Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
>>> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
>>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>>> ---
>>>  hw/s390x/css.c          | 18 ++++++++++++++++--
>>>  hw/s390x/s390-pci-bus.c |  2 +-
>>>  hw/s390x/virtio-ccw.c   |  2 +-
>>>  include/hw/s390x/css.h  |  2 +-
>>>  4 files changed, 19 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/hw/s390x/css.c b/hw/s390x/css.c
>>> index 7b82176..ee4ebbf 100644
>>> --- a/hw/s390x/css.c
>>> +++ b/hw/s390x/css.c
>>> @@ -547,12 +547,26 @@ out:
>>>      return r;
>>>  }
>>>  
>>> -void css_adapter_interrupt(uint8_t isc)
>>> +void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
>>>  {
>>> +    S390FLICState *fs = s390_get_flic();
>>> +    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
>>>      uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
>>> +    IoAdapter *adapter = channel_subsys.io_adapters[type][isc];
>>> +
>>> +    if (!adapter) {
>>> +        return;
>>> +    }
>>>  
>>>      trace_css_adapter_interrupt(isc);
>>> -    s390_io_interrupt(0, 0, 0, io_int_word);
>>> +    if (fs->ais_supported) {
>>> +        if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
>>> +            fprintf(stderr, "Failed to inject airq with AIS supported\n");
>>
>> Use error_report() instead?
> 
> something like this on top?
> 
> diff --git a/hw/s390x/css.c b/hw/s390x/css.c
> index 3d28caa..997815c 100644
> --- a/hw/s390x/css.c
> +++ b/hw/s390x/css.c
> @@ -674,7 +674,7 @@ void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
>      trace_css_adapter_interrupt(isc);
>      if (fs->ais_supported) {
>          if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
> -            fprintf(stderr, "Failed to inject airq with AIS supported\n");
> +            error_report("Failed to inject airq with AIS supported");
>              exit(1);
>          }
>      } else {

Yes, that looks fine. Alternatively, this could maybe be a g_assert()
instead? ... but then you don't get the nice error message anymore, so I
think error_report + exit is OK here.

 Thomas

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt
  2017-07-12 12:57 ` [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt Christian Borntraeger
  2017-07-12 14:26   ` Thomas Huth
@ 2017-07-13  8:46   ` Cornelia Huck
  1 sibling, 0 replies; 34+ messages in thread
From: Cornelia Huck @ 2017-07-13  8:46 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: qemu-devel, Alexander Graf, Richard Henderson, Yi Min Zhao, Fei Li

On Wed, 12 Jul 2017 14:57:45 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> From: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> 
> Let's use the new inject_airq callback of flic to inject adapter
> interrupts. For kvm case, if the kernel flic doesn't support the new
> interface, the irq routine remains unchanged. For non-kvm case,
> qemu-flic handles the suppression process.
> 
> Signed-off-by: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
> Signed-off-by: Fei Li <sherrylf@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  hw/s390x/css.c          | 18 ++++++++++++++++--
>  hw/s390x/s390-pci-bus.c |  2 +-
>  hw/s390x/virtio-ccw.c   |  2 +-
>  include/hw/s390x/css.h  |  2 +-
>  4 files changed, 19 insertions(+), 5 deletions(-)

With the error_report change:

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2017-07-13  8:47 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-12 12:57 [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Christian Borntraeger
2017-07-12 12:57 ` [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management Christian Borntraeger
2017-07-12 13:49   ` Cornelia Huck
2017-07-13  5:37     ` Janosch Frank
2017-07-12 12:57 ` [Qemu-devel] [PATCH 02/11] linux-headers: update to 4.13-rc0 Christian Borntraeger
2017-07-12 12:57 ` [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device Christian Borntraeger
2017-07-12 14:09   ` Thomas Huth
2017-07-13  7:11     ` Christian Borntraeger
2017-07-13  7:32       ` Cornelia Huck
2017-07-13  7:35       ` Thomas Huth
2017-07-13  7:45         ` Christian Borntraeger
2017-07-12 12:57 ` [Qemu-devel] [PATCH 04/11] s390x/migration: Monitor commands for storage attributes Christian Borntraeger
2017-07-12 12:57 ` [Qemu-devel] [PATCH 05/11] s390x/cpumodel: clean up spacing and comments Christian Borntraeger
2017-07-12 12:57 ` [Qemu-devel] [PATCH 06/11] s390x/cpumodel: provide compat handling for new cpu features Christian Borntraeger
2017-07-12 14:51   ` Cornelia Huck
2017-07-12 12:57 ` [Qemu-devel] [PATCH 07/11] s390x: add flags field for registering I/O adapter Christian Borntraeger
2017-07-12 15:00   ` Cornelia Huck
2017-07-12 12:57 ` [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback Christian Borntraeger
2017-07-12 15:07   ` Cornelia Huck
2017-07-13  7:12     ` Christian Borntraeger
2017-07-13  7:27       ` Cornelia Huck
2017-07-13  7:35         ` Christian Borntraeger
2017-07-13  7:47           ` Cornelia Huck
2017-07-12 12:57 ` [Qemu-devel] [PATCH 09/11] s390x/flic: introduce inject_airq callback Christian Borntraeger
2017-07-12 15:12   ` Cornelia Huck
2017-07-12 12:57 ` [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling Christian Borntraeger
2017-07-12 13:40   ` Thomas Huth
2017-07-12 15:40     ` Cornelia Huck
2017-07-12 12:57 ` [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt Christian Borntraeger
2017-07-12 14:26   ` Thomas Huth
2017-07-13  8:08     ` Christian Borntraeger
2017-07-13  8:18       ` Thomas Huth
2017-07-13  8:46   ` Cornelia Huck
2017-07-12 13:31 ` [Qemu-devel] [PATCH 00/11] pending s390 patches part 1 Cornelia Huck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.