Skip to contentSkip to conversation

pending s390 patches part 1

PATCH In review Christian Borntraeger 4 participants 34 messages Jul 12, 2017 – Jul 13, 2017

lore
Share & tools
lore
#0 lore raw

cover pending s390 patches part 1

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
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/11 s390x/kvm: Rework cmma management

From: Janosch Frank <[email protected]>

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.

---
 target/s390x/cpu.h |  1 +
 target/s390x/kvm.c | 26 +++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)
target/s390x/cpu.h +1 -0
index bdb9bdb..8ab75c0 100644
@@ -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);
target/s390x/kvm.c +17 -9
index a3d0019..7a2a7c0 100644
@@ -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();
     }
 }
Signature · 1 line
2.7.4
Reviewed-by on v1 1/11
#2 lore raw

Re: [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management

Quoted 14 lines · On Wed, 12 Jul 2017 14:57:35 +0200 Christian Borntraeger…

From: Janosch Frank <[email protected]>

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.

---
 target/s390x/cpu.h |  1 +
 target/s390x/kvm.c | 26 +++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

target/s390x/kvm.c int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit) · line 185

Quoted 7 lines
target/s390x/kvm.c +4 -0
@@ -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"...

target/s390x/kvm.c void kvm_s390_cmma_reset(void) · line 209

Quoted 12 lines
target/s390x/kvm.c +2 -1
+
 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

#3 lore raw

Re: [Qemu-devel] [PATCH 01/11] s390x/kvm: Rework cmma management

Quoted 35 lines · Cornelia Huck
Quoted 14 lines · On Wed, 12 Jul 2017 14:57:35 +0200 Christian Borntraeger…

From: Janosch Frank <[email protected]>

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.

---
 target/s390x/cpu.h |  1 +
 target/s390x/kvm.c | 26 +++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

target/s390x/kvm.c int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit) · line 185

Quoted 7 lines
target/s390x/kvm.c +4 -0
@@ -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"...

Quoted 8 lines
target/s390x/kvm.c +1 -0
+
 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,
     };
 
Quoted 6 lines

target/s390x/kvm.c void kvm_s390_cmma_reset(void) · line 209

Quoted 4 lines
target/s390x/kvm.c +1 -1
-    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.

Quoted 4 lines

Confused me a bit at first, but

Thanks!

#4 lore raw

PATCH 2/11 linux-headers: update to 4.13-rc0

In reply to 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

---
 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(-)
include/standard-headers/asm-x86/hyperv.h +12 -9
index d0c6e0a..fac7651 100644
@@ -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)
include/standard-headers/linux/input-event-codes.h +1 -0
index 29d463a..2fa0f4e 100644
@@ -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 */
include/standard-headers/linux/pci_regs.h +1 -0
index d56bb00..c22d3eb 100644
@@ -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 */
linux-headers/asm-arm/kvm.h +8 -0
index 7258a00..fa9fae8 100644
@@ -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
linux-headers/asm-arm64/kvm.h +3 -0
index 31bb1dd..d254700 100644
@@ -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
linux-headers/asm-powerpc/kvm.h +6 -0
index 07fbeb9..8cf8f0c 100644
@@ -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
linux-headers/asm-s390/kvm.h +12 -0
index 243f195..8387d71 100644
@@ -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 */
linux-headers/linux/kvm.h +35 -0
index d2892da..43e2d82 100644
@@ -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)
Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/11 s390x/migration: Storage attributes device

In reply to Christian Borntraeger

From: Claudio Imbrenda <[email protected]>

Storage attributes device, like we have for storage keys.

---
 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
hw/s390x/Makefile.objs +2 -0
index a8e5575..b2aade2 100644
@@ -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
hw/s390x/s390-stattrib-kvm.c new file +178 -0

178 lines not on this page · raw message

hw/s390x/s390-stattrib.c new file +348 -0

348 lines not on this page · raw message

hw/s390x/s390-virtio-ccw.c +9 -1
index 41ca666..0c8f758 100644
@@ -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 \
include/hw/s390x/storage-attributes.h new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.7.4
#6 lore raw

Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device

Quoted 7 lines · Christian Borntraeger

From: Claudio Imbrenda <[email protected]>

Storage attributes device, like we have for storage keys.

---

[...]

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +4 -0
new file mode 100644
index 0000000..2e7f144
@@ -0,0 +1,178 @@
+/*
+ * s390 storage attributes device -- KVM object
+ *
+ * Copyright 2016 IBM Corp.

hw/s390x/s390-stattrib-kvm.c line 14

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+ * Author(s): Claudio Imbrenda <[email protected]>
+ *
+ * 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?

Quoted 9 lines
hw/s390x/s390-stattrib-kvm.c new file +9 -0
+#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)
+{

hw/s390x/s390-stattrib-kvm.c line 33

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+    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 ----------^

hw/s390x/s390-stattrib-kvm.c line 46

Quoted 13 lines
hw/s390x/s390-stattrib-kvm.c new file +13 -0
+{
+    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".

Quoted 26 lines
hw/s390x/s390-stattrib-kvm.c new file +26 -0
+        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,

hw/s390x/s390-stattrib-kvm.c line 82

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+                                        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.

Quoted 21 lines
hw/s390x/s390-stattrib-kvm.c new file +21 -0
+        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,

hw/s390x/s390-stattrib-kvm.c line 113

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+    };
+
+    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?

hw/s390x/s390-stattrib-kvm.c line 120

Quoted 7 lines
hw/s390x/s390-stattrib-kvm.c new file +7 -0
+            }
+        }
+        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?

Quoted 96 lines
hw/s390x/s390-stattrib-kvm.c new file +58 -0
+        }
+        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)
hw/s390x/s390-stattrib.c new file +32 -0
new file mode 100644
index 0000000..eb41fe9
@@ -0,0 +1,348 @@
+/*
+ * s390 storage attributes device
+ *
+ * Copyright 2016 IBM Corp.
+ * Author(s): Claudio Imbrenda <[email protected]>
+ *
+ * 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;
+

hw/s390x/s390-stattrib.c line 42

Quoted 10 lines
hw/s390x/s390-stattrib.c new file +10 -0
+#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?

Quoted 6 lines
hw/s390x/s390-stattrib.c new file +6 -0
+    object_property_add_child(qdev_get_machine(), TYPE_S390_STATTRIB,
+                              obj, NULL);
+    object_unref(obj);
+
+    qdev_init_nofail(DEVICE(obj));
+}

[...]

Quoted 14 lines
hw/s390x/s390-stattrib.c new file +14 -0
+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;
+    }

hw/s390x/s390-stattrib.c line 165

Quoted 10 lines
hw/s390x/s390-stattrib.c new file +10 -0
+
+    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.

Quoted 16 lines
hw/s390x/s390-stattrib.c new file +16 -0
+            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);

hw/s390x/s390-stattrib.c line 191

Quoted 10 lines
hw/s390x/s390-stattrib.c new file +10 -0
+    }
+    qemu_put_be64(f, STATTR_FLAG_EOS);
+
+    r = qemu_file_get_error(f);
+    if (r < 0) {
+        return r;
+    }
+
+    return ret;
+}

[...]

Thomas

#7 lore raw

Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device

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(-)
hw/s390x/s390-stattrib-kvm.c +19 -7
index 2e7f144..2ab3060 100644
@@ -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;
hw/s390x/s390-stattrib.c +3 -9
index b9533b4..bac9aea 100644
@@ -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);
include/hw/s390x/storage-attributes.h +9 -0
index ccf4aa1..9be954d 100644
@@ -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);
 
Quoted 333 lines · Thomas Huth
Quoted 7 lines · Christian Borntraeger

From: Claudio Imbrenda <[email protected]>

Storage attributes device, like we have for storage keys.

---

[...]

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +4 -0
new file mode 100644
index 0000000..2e7f144
@@ -0,0 +1,178 @@
+/*
+ * s390 storage attributes device -- KVM object
+ *
+ * Copyright 2016 IBM Corp.

hw/s390x/s390-stattrib-kvm.c line 14

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+ * Author(s): Claudio Imbrenda <[email protected]>
+ *
+ * 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?

Quoted 9 lines
hw/s390x/s390-stattrib-kvm.c new file +9 -0
+#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)
+{

hw/s390x/s390-stattrib-kvm.c line 33

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+    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 ----------^

hw/s390x/s390-stattrib-kvm.c line 46

Quoted 13 lines
hw/s390x/s390-stattrib-kvm.c new file +13 -0
+{
+    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".

Quoted 26 lines
hw/s390x/s390-stattrib-kvm.c new file +26 -0
+        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,

hw/s390x/s390-stattrib-kvm.c line 82

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+                                        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.

Quoted 21 lines
hw/s390x/s390-stattrib-kvm.c new file +21 -0
+        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,

hw/s390x/s390-stattrib-kvm.c line 113

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c new file +10 -0
+    };
+
+    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?

hw/s390x/s390-stattrib-kvm.c line 120

Quoted 7 lines
hw/s390x/s390-stattrib-kvm.c new file +7 -0
+            }
+        }
+        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?

Quoted 96 lines
hw/s390x/s390-stattrib-kvm.c new file +58 -0
+        }
+        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)
hw/s390x/s390-stattrib.c new file +32 -0
new file mode 100644
index 0000000..eb41fe9
@@ -0,0 +1,348 @@
+/*
+ * s390 storage attributes device
+ *
+ * Copyright 2016 IBM Corp.
+ * Author(s): Claudio Imbrenda <[email protected]>
+ *
+ * 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;
+

hw/s390x/s390-stattrib.c line 42

Quoted 10 lines
hw/s390x/s390-stattrib.c new file +10 -0
+#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?

Quoted 6 lines
hw/s390x/s390-stattrib.c new file +6 -0
+    object_property_add_child(qdev_get_machine(), TYPE_S390_STATTRIB,
+                              obj, NULL);
+    object_unref(obj);
+
+    qdev_init_nofail(DEVICE(obj));
+}

[...]

Quoted 14 lines
hw/s390x/s390-stattrib.c new file +14 -0
+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;
+    }

hw/s390x/s390-stattrib.c

Quoted 10 lines
hw/s390x/s390-stattrib.c new file +10 -0
+
+    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.

Quoted 16 lines
hw/s390x/s390-stattrib.c new file +16 -0
+            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);

hw/s390x/s390-stattrib.c

Quoted 10 lines
hw/s390x/s390-stattrib.c new file +10 -0
+    }
+    qemu_put_be64(f, STATTR_FLAG_EOS);
+
+    r = qemu_file_get_error(f);
+    if (r < 0) {
+        return r;
+    }
+
+    return ret;
+}

[...]

Thomas

#8 lore raw

Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device

Quoted 3 lines · On Thu, 13 Jul 2017 09:11:34 +0200 Christian Borntraeger…

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.

#9 lore raw

Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device

In reply to Christian Borntraeger
Quoted 27 lines · Christian Borntraeger

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(-)
hw/s390x/s390-stattrib-kvm.c +0 -1
index 2e7f144..2ab3060 100644
@@ -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"

hw/s390x/s390-stattrib-kvm.c line 28

Quoted 10 lines
hw/s390x/s390-stattrib-kvm.c +8 -0
 #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 ...

Quoted 7 lines
hw/s390x/s390-stattrib.c +0 -0
index b9533b4..bac9aea 100644
@@ -40,16 +40,10 @@ void s390_stattrib_init(void)
 {
     Object *obj;

hw/s390x/s390-stattrib.c void s390_stattrib_init(void) · line 46

Quoted 10 lines
hw/s390x/s390-stattrib.c +2 -5
 
-#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

#10 lore raw

Re: [Qemu-devel] [PATCH 03/11] s390x/migration: Storage attributes device

Quoted 30 lines · Thomas Huth
Quoted 29 lines · Christian Borntraeger

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(-)
hw/s390x/s390-stattrib-kvm.c +0 -1
index 2e7f144..2ab3060 100644
@@ -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"
 
Quoted 11 lines

hw/s390x/s390-stattrib-kvm.c line 28

Quoted 8 lines
hw/s390x/s390-stattrib-kvm.c +8 -0
+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

Quoted 23 lines
Quoted 8 lines
hw/s390x/s390-stattrib.c +0 -0
index b9533b4..bac9aea 100644
@@ -40,16 +40,10 @@ void s390_stattrib_init(void)
 {
     Object *obj;

hw/s390x/s390-stattrib.c void s390_stattrib_init(void) · line 46

Quoted 10 lines
hw/s390x/s390-stattrib.c +2 -5
 
-#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

#11 lore raw

PATCH 4/11 s390x/migration: Monitor commands for storage attributes

In reply to Christian Borntraeger

From: Claudio Imbrenda <[email protected]>

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).

---
 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(+)
hmp-commands-info.hx +16 -0
index 07500ef..d9df238 100644
@@ -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  = "",
hmp-commands.hx +16 -0
index 275ccdf..eec9cc2 100644
@@ -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?",
hw/s390x/s390-stattrib.c +62 -0

80 lines not on this page · raw message

include/hw/s390x/storage-attributes.h +4 -0
index 161440b..ccf4aa1 100644
@@ -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 */
monitor.c +1 -0
index d8ac20f..8e084f5 100644
@@ -81,6 +81,7 @@
 
 #if defined(TARGET_S390X)
 #include "hw/s390x/storage-keys.h"
+#include "hw/s390x/storage-attributes.h"
 #endif
 
 /*
Signature · 1 line
2.7.4
#12 lore raw

PATCH 5/11 s390x/cpumodel: clean up spacing and comments

In reply to Christian Borntraeger

From: "Jason J. Herne" <[email protected]>

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.

---
 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(-)
target/s390x/cpu_features.c +3 -0
index 42fd9d7..0436dc2 100644
@@ -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"),
target/s390x/cpu_features_def.h +35 -0
index aa5ab8d..f5bb7ed 100644
@@ -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;
target/s390x/gen-features.c +55 -3

225 lines not on this page · raw message

Signature · 1 line
2.7.4
#13 lore raw

PATCH 6/11 s390x/cpumodel: provide compat handling for new cpu features

In reply to Christian Borntraeger

From: "Jason J. Herne" <[email protected]>

Provide a mechanism to disable features in compatibility machines.

---
 target/s390x/cpu_models.c | 26 ++++++++++++++++++++++++++
 target/s390x/cpu_models.h |  2 ++
 2 files changed, 28 insertions(+)
target/s390x/cpu_models.c +26 -0
index 7cb55dc..fd3f459 100644
@@ -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;
target/s390x/cpu_models.h +2 -0
index d41f8d6..c0bee15 100644
@@ -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);
Signature · 1 line
2.7.4
Acked-by on v1 6/11
#14 lore raw

Re: [Qemu-devel] [PATCH 06/11] s390x/cpumodel: provide compat handling for new cpu features

Quoted 3 lines · On Wed, 12 Jul 2017 14:57:40 +0200 Christian Borntraeger…

From: "Jason J. Herne" <[email protected]>

Provide a mechanism to disable features in compatibility machines.

User to come in the next batch of patches?

Quoted 8 lines
---
 target/s390x/cpu_models.c | 26 ++++++++++++++++++++++++++
 target/s390x/cpu_models.h |  2 ++
 2 files changed, 28 insertions(+)
#15 lore raw

PATCH 7/11 s390x: add flags field for registering I/O adapter

In reply to Christian Borntraeger

From: Fei Li <[email protected]>

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.

---
 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(-)
hw/intc/s390_flic.c +1 -1
index 837158b..d3938b3 100644
@@ -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;
hw/intc/s390_flic_kvm.c +2 -1
index 0bcd49f..15ff534 100644
@@ -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;
hw/s390x/css-bridge.c +1 -1
index 823747f..c4a9735 100644
@@ -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;
  }
hw/s390x/css.c +6 -2
index d67fffa..1fcbc84 100644
@@ -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 "
hw/s390x/s390-pci-bus.c +2 -1
index 5651483..b9603e7 100644
@@ -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;
 }
include/hw/s390x/css.h +7 -1
index eb0e26f..e028960 100644
@@ -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,
include/hw/s390x/s390_flic.h +1 -1
index caa6fc6..d4145ad 100644
@@ -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);
Signature · 1 line
2.7.4
Reviewed-by on v1 7/11
#16 lore raw

Re: [Qemu-devel] [PATCH 07/11] s390x: add flags field for registering I/O adapter

Quoted 11 lines · On Wed, 12 Jul 2017 14:57:41 +0200 Christian Borntraeger…

From: Fei Li <[email protected]>

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.

Quoted 9 lines
---
 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(-)
#17 lore raw

PATCH 8/11 s390x/flic: introduce modify_ais_mode callback

In reply to Christian Borntraeger

From: Fei Li <[email protected]>

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.

---
 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(-)
hw/intc/s390_flic.c +36 -1
index d3938b3..ce7f355 100644
@@ -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)
hw/intc/s390_flic_kvm.c +36 -0
index 15ff534..55aa35f 100644
@@ -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 = {
include/hw/s390x/s390_flic.h +8 -1
index d4145ad..f500184 100644
@@ -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);
Signature · 1 line
2.7.4
#18 lore raw

Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback

Quoted 29 lines · On Wed, 12 Jul 2017 14:57:42 +0200 Christian Borntraeger…

From: Fei Li <[email protected]>

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.

---
 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(-)
hw/intc/s390_flic.c +3 -0
index d3938b3..ce7f355 100644
@@ -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)
+{

hw/intc/s390_flic.c static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id, · line 94

Quoted 10 lines
hw/intc/s390_flic.c +10 -0
+    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.

Quoted 9 lines
hw/intc/s390_flic.c +8 -0
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
 

(...)

hw/intc/s390_flic.c static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) · line 463

Quoted 13 lines
hw/intc/s390_flic.c +2 -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?

Quoted 3 lines
hw/intc/s390_flic.c +0 -0
     return;
 fail:
     error_propagate(errp, errp_local);
#19 lore raw

Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback

Quoted 10 lines · Cornelia Huck

hw/intc/s390_flic.c static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id, · line 94

Quoted 9 lines
hw/intc/s390_flic.c +9 -0
+
+    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);
Quoted 3 lines

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?

Quoted 25 lines
Quoted 10 lines
hw/intc/s390_flic.c +8 -0
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    return 0;
+}
+

(...)

Quoted 12 lines
hw/intc/s390_flic_kvm.c +1 -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);
 
Quoted 4 lines

hw/intc/s390_flic_kvm.c static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) · line 463

Quoted 1 line
hw/intc/s390_flic_kvm.c +1 -0
+    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.

#20 lore raw

Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback

Quoted 11 lines · On Thu, 13 Jul 2017 09:12:50 +0200 Christian Borntraeger…
Quoted 10 lines · Cornelia Huck
Quoted 9 lines
hw/intc/s390_flic.c +9 -0
+
+    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);  
Quoted 6 lines
Quoted 3 lines

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.

#21 lore raw

Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback

Quoted 18 lines · Cornelia Huck
Quoted 15 lines · On Thu, 13 Jul 2017 09:12:50 +0200 Christian Borntraeger…
Quoted 13 lines · Cornelia Huck

hw/intc/s390_flic.c static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id, · line 94

Quoted 9 lines
hw/intc/s390_flic.c +9 -0
+
+    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.

Quoted 6 lines
Quoted 2 lines

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
#22 lore raw

Re: [Qemu-devel] [PATCH 08/11] s390x/flic: introduce modify_ais_mode callback

Quoted 26 lines · On Thu, 13 Jul 2017 09:35:16 +0200 Christian Borntraeger…
Quoted 18 lines · Cornelia Huck
Quoted 15 lines · On Thu, 13 Jul 2017 09:12:50 +0200 Christian Borntraeger…
Quoted 13 lines · Cornelia Huck

hw/intc/s390_flic.c static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id, · line 94

Quoted 9 lines
hw/intc/s390_flic.c +9 -0
+
+    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.

Quoted 6 lines
Quoted 2 lines

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.

Quoted 5 lines

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/

Quoted 6 lines

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:

Quoted 8 lines
    interruption mode | simm bit | nimm bit
    ------------------|----------|----------
             ALL      |    0     |     0
           SINGLE     |    1     |     0
             NO       |    1     |     1

Sounds good.

#23 lore raw

PATCH 9/11 s390x/flic: introduce inject_airq callback

In reply to Christian Borntraeger

From: Yi Min Zhao <[email protected]>

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.

---
 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(+)
hw/intc/s390_flic.c +27 -0
index ce7f355..efcb1dd 100644
@@ -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[] = {
hw/intc/s390_flic_kvm.c +18 -0
index 55aa35f..a587ace 100644
@@ -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 = {
hw/intc/trace-events +4 -0
index 729c128..c586714 100644
@@ -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"
include/hw/s390x/s390_flic.h +2 -0
index f500184..2f173d9 100644
@@ -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"
Signature · 1 line
2.7.4
Reviewed-by on v1 9/11
#24 lore raw

Re: [Qemu-devel] [PATCH 09/11] s390x/flic: introduce inject_airq callback

Quoted 11 lines · On Wed, 12 Jul 2017 14:57:43 +0200 Christian Borntraeger…

From: Yi Min Zhao <[email protected]>

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/

Quoted 10 lines
---
 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(+)
#25 lore raw

PATCH 10/11 s390x/sic: realize SIC handling

In reply to Christian Borntraeger

From: Fei Li <[email protected]>

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

---
 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(-)
hw/s390x/css.c +26 -0
index 1fcbc84..7b82176 100644
@@ -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;
hw/s390x/trace-events +1 -0
index 84ea964..f07e974 100644
@@ -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"
include/hw/s390x/css.h +2 -0
index e028960..5ee6d52 100644
@@ -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);
target/s390x/kvm.c +15 -1
index 7a2a7c0..78ebe83 100644
@@ -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;
 }
 
Signature · 1 line
2.7.4
#26 lore raw

Re: [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling

Quoted 23 lines · Christian Borntraeger

From: Fei Li <[email protected]>

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

---
 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(-)
hw/s390x/css.c +0 -0
index 1fcbc84..7b82176 100644
@@ -521,6 +521,32 @@ void css_conditional_io_interrupt(SubchDev *sch)
     }
 }

hw/s390x/css.c void css_conditional_io_interrupt(SubchDev *sch) · line 532

Quoted 10 lines
hw/s390x/css.c +9 -0
 
+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.

Quoted 37 lines
hw/s390x/css.c +17 -0
+    }
+
+    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;
hw/s390x/trace-events +1 -0
index 84ea964..f07e974 100644
@@ -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"
include/hw/s390x/css.h +0 -0
index e028960..5ee6d52 100644

include/hw/s390x/css.h line 15

Quoted 4 lines
include/hw/s390x/css.h +1 -0
@@ -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?

Quoted 27 lines
include/hw/s390x/css.h +1 -0
 #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);
target/s390x/kvm.c +7 -1
index 7a2a7c0..78ebe83 100644
@@ -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;
+

target/s390x/kvm.c static int kvm_stpcifc_service_call(S390CPU *cpu, struct kvm_run *run) · line 1225

Quoted 10 lines
target/s390x/kvm.c +8 -0
+    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

#27 lore raw

Re: [Qemu-devel] [PATCH 10/11] s390x/sic: realize SIC handling

Quoted 37 lines · On Wed, 12 Jul 2017 15:40:02 +0200 Thomas Huth <[email protected]> wrote:
Quoted 23 lines · Christian Borntraeger

From: Fei Li <[email protected]>

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

---
 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(-)
hw/s390x/css.c +0 -0
index 1fcbc84..7b82176 100644
@@ -521,6 +521,32 @@ void css_conditional_io_interrupt(SubchDev *sch)
     }
 }

hw/s390x/css.c void css_conditional_io_interrupt(SubchDev *sch) · line 532

Quoted 10 lines
hw/s390x/css.c +9 -0
 
+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:

Quoted 6 lines
           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.

Quoted 21 lines
Quoted 21 lines
hw/s390x/css.c +17 -0
+    }
+
+    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;

(...)

Quoted 8 lines
Quoted 8 lines
include/hw/s390x/css.h +0 -0
index e028960..5ee6d52 100644
@@ -12,6 +12,7 @@
 #ifndef CSS_H
 #define CSS_H
 
Quoted 5 lines

include/hw/s390x/css.h line 15

Quoted 1 line
include/hw/s390x/css.h +1 -0
+#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.)

Quoted 2 lines

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.

#28 lore raw

PATCH 11/11 s390x/css: update css_adapter_interrupt

In reply to Christian Borntraeger

From: Yi Min Zhao <[email protected]>

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.

---
 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(-)
hw/s390x/css.c +16 -2
index 7b82176..ee4ebbf 100644
@@ -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)
hw/s390x/s390-pci-bus.c +1 -1
index b9603e7..2de4435 100644
@@ -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);
     }
 }
 
hw/s390x/virtio-ccw.c +1 -1
index e18fd26..5afd9bb 100644
@@ -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,
include/hw/s390x/css.h +1 -1
index 5ee6d52..dd36d39 100644
@@ -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,
Signature · 1 line
2.7.4
#29 lore raw

Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt

Quoted 32 lines · Christian Borntraeger

From: Yi Min Zhao <[email protected]>

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.

---
 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(-)
hw/s390x/css.c +4 -1
index 7b82176..ee4ebbf 100644
@@ -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];

hw/s390x/css.c out: · line 564

Quoted 10 lines
hw/s390x/css.c +7 -1
+
+    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?

hw/s390x/css.c out: · line 570

Quoted 6 lines
hw/s390x/css.c +5 -0
+            exit(1);
+        }
+    } else {
+        s390_io_interrupt(0, 0, 0, io_int_word);
+    }
 }

Thomas

#30 lore raw

Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt

Quoted 38 lines · Thomas Huth
Quoted 37 lines · Christian Borntraeger

From: Yi Min Zhao <[email protected]>

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.

---
 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(-)
hw/s390x/css.c +8 -1
index 7b82176..ee4ebbf 100644
@@ -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;
+    }
 
Quoted 7 lines

hw/s390x/css.c out: · line 564

Quoted 5 lines
hw/s390x/css.c +3 -1
     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?

hw/s390x/css.c +1 -1
index 3d28caa..997815c 100644
@@ -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 {
#31 lore raw

Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt

Quoted 54 lines · Christian Borntraeger
Quoted 38 lines · Thomas Huth
Quoted 37 lines · Christian Borntraeger

From: Yi Min Zhao <[email protected]>

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.

---
 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(-)
hw/s390x/css.c +8 -1
index 7b82176..ee4ebbf 100644
@@ -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;
+    }
 
Quoted 7 lines

hw/s390x/css.c out: · line 564

Quoted 5 lines
hw/s390x/css.c +3 -1
     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?

hw/s390x/css.c +0 -0
index 3d28caa..997815c 100644

hw/s390x/css.c void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc) · line 680

Quoted 8 lines
hw/s390x/css.c +1 -1
@@ -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

Reviewed-by on v1 11/11
#32 lore raw

Re: [Qemu-devel] [PATCH 11/11] s390x/css: update css_adapter_interrupt

In reply to Christian Borntraeger
Quoted 10 lines · On Wed, 12 Jul 2017 14:57:45 +0200 Christian Borntraeger…

From: Yi Min Zhao <[email protected]>

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.

Quoted 6 lines
---
 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:

#33 lore raw
In reply to Christian Borntraeger
Quoted 10 lines · On Wed, 12 Jul 2017 14:57:34 +0200 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.

2.10 will really be a huge update for s390x :)

Quoted 63 lines

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