Skip to contentSkip to conversation

s390: channel I/O support in qemu.

PATCH Applied Cornelia Huck 3 participants 21 messages Jan 17, 2013 – Jan 18, 2013

Subsystems (2)

v5 of 6 Applied Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover s390: channel I/O support in qemu.

Hi,

here's the latest incarnation of my channel I/O and virtio-ccw patchset for qemu, containing various changes over the last one.

(Note that "s390: Add a hypercall registration interface." has already been posted: http://marc.info/?l=qemu-devel&m=135834160607372&w=2)

Changes include:
- Add various defines for magic constants.
- Introduce helpers for various mapping stuff and use them.
- Adapt virtio-ccw to QOM conventions.
- Move the new s390-ccw-virtio machine into an extra file (and an extra patch).
- Improve cpu handling during machine init (don't pass around env).

Cornelia Huck (12):
s390: Add a hypercall registration interface.
s390: Lowcore mapping helper.
s390: Add mapping helper functions. Update linux headers.
s390: Channel I/O basic defintions.
s390: I/O interrupt and machine check injection.
s390: Add channel I/O instructions.
s390: Virtual channel subsystem support.
s390: Wire up channel I/O in kvm.
s390: Add new channel I/O based virtio transport.
s390-virtio: Factor out some initialization code.
s390: Add s390-ccw-virtio machine.

 hw/s390-virtio.c                     |  240 ++++----
 hw/s390-virtio.h                     |   28 +
 hw/s390x/Makefile.objs               |    4 +
 hw/s390x/css.c                       | 1131 ++++++++++++++++++++++++++++++++++
 hw/s390x/css.h                       |   92 +++
 hw/s390x/s390-virtio-ccw.c           |  141 +++++
 hw/s390x/s390-virtio-hcall.c         |   36 ++
 hw/s390x/virtio-ccw.c                |  906 +++++++++++++++++++++++++++
 hw/s390x/virtio-ccw.h                |   79 +++
 linux-headers/asm-generic/kvm_para.h |    4 +
 linux-headers/asm-powerpc/kvm_para.h |    2 +-
 linux-headers/linux/kvm.h            |   21 +
 target-s390x/Makefile.objs           |    2 +-
 target-s390x/cpu.h                   |  257 +++++++-
 target-s390x/helper.c                |  200 +++++-
 target-s390x/ioinst.c                |  709 +++++++++++++++++++++
 target-s390x/ioinst.h                |  223 +++++++
 target-s390x/kvm.c                   |  254 +++++++-
 target-s390x/misc_helper.c           |    2 +-
 trace-events                         |   18 +
 20 files changed, 4215 insertions(+), 134 deletions(-)
 create mode 100644 hw/s390-virtio.h
 create mode 100644 hw/s390x/css.c
 create mode 100644 hw/s390x/css.h
 create mode 100644 hw/s390x/s390-virtio-ccw.c
 create mode 100644 hw/s390x/s390-virtio-hcall.c
 create mode 100644 hw/s390x/virtio-ccw.c
 create mode 100644 hw/s390x/virtio-ccw.h
 create mode 100644 linux-headers/asm-generic/kvm_para.h
 create mode 100644 target-s390x/ioinst.c
 create mode 100644 target-s390x/ioinst.h
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH v5 1/12 s390: Add a hypercall registration interface.

Allow virtio machines to register for different diag500 function codes and convert s390-virtio to use it.

---
 hw/s390-virtio.c             | 90 +++++++++++++++++++++++---------------------
 hw/s390-virtio.h             | 22 +++++++++++
 hw/s390x/Makefile.objs       |  1 +
 hw/s390x/s390-virtio-hcall.c | 36 ++++++++++++++++++
 target-s390x/cpu.h           |  2 +-
 target-s390x/kvm.c           |  2 +-
 target-s390x/misc_helper.c   |  2 +-
 7 files changed, 110 insertions(+), 45 deletions(-)
 create mode 100644 hw/s390-virtio.h
 create mode 100644 hw/s390x/s390-virtio-hcall.c
hw/s390-virtio.c +48 -42
index 0e93cc3..bded30b 100644
@@ -33,6 +33,7 @@
 
 #include "hw/s390-virtio-bus.h"
 #include "hw/s390x/sclp.h"
+#include "hw/s390-virtio.h"
 
 //#define DEBUG_S390
 
@@ -44,10 +45,6 @@
     do { } while (0)
 #endif
 
-#define KVM_S390_VIRTIO_NOTIFY          0
-#define KVM_S390_VIRTIO_RESET           1
-#define KVM_S390_VIRTIO_SET_STATUS      2
-
 #define KERN_IMAGE_START                0x010000UL
 #define KERN_PARM_AREA                  0x010480UL
 #define INITRD_START                    0x800000UL
@@ -73,56 +70,63 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
     return ipi_states[cpu_addr];
 }
 
-int s390_virtio_hypercall(CPUS390XState *env, uint64_t mem, uint64_t hypercall)
+static int s390_virtio_hcall_notify(const uint64_t *args)
 {
+    uint64_t mem = args[0];
     int r = 0, i;
 
-    dprintf("KVM hypercall: %ld\n", hypercall);
-    switch (hypercall) {
-    case KVM_S390_VIRTIO_NOTIFY:
-        if (mem > ram_size) {
-            VirtIOS390Device *dev = s390_virtio_bus_find_vring(s390_bus,
-                                                               mem, &i);
-            if (dev) {
-                virtio_queue_notify(dev->vdev, i);
-            } else {
-                r = -EINVAL;
-            }
-        } else {
-            /* Early printk */
-        }
-        break;
-    case KVM_S390_VIRTIO_RESET:
-    {
-        VirtIOS390Device *dev;
-
-        dev = s390_virtio_bus_find_mem(s390_bus, mem);
-        virtio_reset(dev->vdev);
-        stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_STATUS, 0);
-        s390_virtio_device_sync(dev);
-        s390_virtio_reset_idx(dev);
-        break;
-    }
-    case KVM_S390_VIRTIO_SET_STATUS:
-    {
-        VirtIOS390Device *dev;
-
-        dev = s390_virtio_bus_find_mem(s390_bus, mem);
+    if (mem > ram_size) {
+        VirtIOS390Device *dev = s390_virtio_bus_find_vring(s390_bus, mem, &i);
         if (dev) {
-            s390_virtio_device_update_status(dev);
+            virtio_queue_notify(dev->vdev, i);
         } else {
             r = -EINVAL;
         }
-        break;
+    } else {
+        /* Early printk */
     }
-    default:
+    return r;
+}
+
+static int s390_virtio_hcall_reset(const uint64_t *args)
+{
+    uint64_t mem = args[0];
+    VirtIOS390Device *dev;
+
+    dev = s390_virtio_bus_find_mem(s390_bus, mem);
+    virtio_reset(dev->vdev);
+    stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_STATUS, 0);
+    s390_virtio_device_sync(dev);
+    s390_virtio_reset_idx(dev);
+
+    return 0;
+}
+
+static int s390_virtio_hcall_set_status(const uint64_t *args)
+{
+    uint64_t mem = args[0];
+    int r = 0;
+    VirtIOS390Device *dev;
+
+    dev = s390_virtio_bus_find_mem(s390_bus, mem);
+    if (dev) {
+        s390_virtio_device_update_status(dev);
+    } else {
         r = -EINVAL;
-        break;
     }
-
     return r;
 }
 
+static void s390_virtio_register_hcalls(void)
+{
+    s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
+                                   s390_virtio_hcall_notify);
+    s390_register_virtio_hypercall(KVM_S390_VIRTIO_RESET,
+                                   s390_virtio_hcall_reset);
+    s390_register_virtio_hypercall(KVM_S390_VIRTIO_SET_STATUS,
+                                   s390_virtio_hcall_set_status);
+}
+
 /*
  * The number of running CPUs. On s390 a shutdown is the state of all CPUs
  * being either stopped or disabled (for interrupts) waiting. We have to
@@ -186,6 +190,9 @@ static void s390_init(QEMUMachineInitArgs *args)
     s390_bus = s390_virtio_bus_init(&my_ram_size);
     s390_sclp_init();
 
+    /* register hypercalls */
+    s390_virtio_register_hcalls();
+
     /* allocate RAM */
     memory_region_init_ram(ram, "s390.ram", my_ram_size);
     vmstate_register_ram_global(ram);
@@ -339,4 +346,3 @@ static void s390_machine_init(void)
 }
 
 machine_init(s390_machine_init);
-
hw/s390-virtio.h new file +22 -0
new file mode 100644
index 0000000..25bb610
@@ -0,0 +1,22 @@
+/*
+ * Virtio interfaces for s390
+ *
+ * Copyright 2012 IBM Corp.
+ * Author(s): Cornelia Huck <[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.
+ */
+
+#ifndef HW_S390_VIRTIO_H
+#define HW_S390_VIRTIO_H 1
+
+#define KVM_S390_VIRTIO_NOTIFY          0
+#define KVM_S390_VIRTIO_RESET           1
+#define KVM_S390_VIRTIO_SET_STATUS      2
+
+typedef int (*s390_virtio_fn)(const uint64_t *args);
+void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
+
+#endif
hw/s390x/Makefile.objs +1 -0
index 096dfcd..ae87a12 100644
@@ -1,6 +1,7 @@
 obj-y = s390-virtio-bus.o s390-virtio.o
 
 obj-y := $(addprefix ../,$(obj-y))
+obj-y += s390-virtio-hcall.o
 obj-y += sclp.o
 obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
hw/s390x/s390-virtio-hcall.c new file +36 -0
new file mode 100644
index 0000000..d7938c0
@@ -0,0 +1,36 @@
+/*
+ * Support for virtio hypercalls on s390
+ *
+ * Copyright 2012 IBM Corp.
+ * Author(s): Cornelia Huck <[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 "cpu.h"
+#include "hw/s390-virtio.h"
+
+#define MAX_DIAG_SUBCODES 255
+
+static s390_virtio_fn s390_diag500_table[MAX_DIAG_SUBCODES];
+
+void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn)
+{
+    assert(code < MAX_DIAG_SUBCODES);
+    assert(!s390_diag500_table[code]);
+
+    s390_diag500_table[code] = fn;
+}
+
+int s390_virtio_hypercall(CPUS390XState *env)
+{
+    s390_virtio_fn fn = s390_diag500_table[env->regs[1]];
+
+    if (!fn) {
+        return -EINVAL;
+    }
+
+    return fn(&env->regs[2]);
+}
target-s390x/cpu.h +1 -1
index bc3fab2..6700fe9 100644
@@ -302,7 +302,7 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw
 void s390x_tod_timer(void *opaque);
 void s390x_cpu_timer(void *opaque);
 
-int s390_virtio_hypercall(CPUS390XState *env, uint64_t mem, uint64_t hypercall);
+int s390_virtio_hypercall(CPUS390XState *env);
 
 #ifdef CONFIG_KVM
 void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code);
target-s390x/kvm.c +1 -1
index 6ec5e6d..ae6ae07 100644
@@ -386,7 +386,7 @@ static int handle_priv(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1)
 static int handle_hypercall(CPUS390XState *env, struct kvm_run *run)
 {
     cpu_synchronize_state(env);
-    env->regs[2] = s390_virtio_hypercall(env, env->regs[2], env->regs[1]);
+    env->regs[2] = s390_virtio_hypercall(env);
 
     return 0;
 }
target-s390x/misc_helper.c +1 -1
index 3015bfe..1937e0c 100644
@@ -107,7 +107,7 @@ uint64_t HELPER(diag)(CPUS390XState *env, uint32_t num, uint64_t mem,
     switch (num) {
     case 0x500:
         /* KVM hypercall */
-        r = s390_virtio_hypercall(env, mem, code);
+        r = s390_virtio_hypercall(env);
         break;
     case 0x44:
         /* yield */
Signature · 1 line
1.7.12.4
#3 lore raw

PATCH v5 2/12 s390: Lowcore mapping helper.

In reply to Cornelia Huck

Create a lowcore mapping helper that includes a check for sufficient length.

---
 target-s390x/helper.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
target-s390x/helper.c +25 -6
index 9a132e6..bf2b4d3 100644
@@ -471,13 +471,32 @@ static uint64_t get_psw_mask(CPUS390XState *env)
     return r;
 }
 
+static LowCore *cpu_map_lowcore(CPUS390XState *env, hwaddr *len)
+{
+    LowCore *lowcore;
+
+    if (*len < sizeof(LowCore)) {
+        cpu_abort(env, "Insufficient length %d for mapping lowcore\n",
+                  (int) *len);
+    }
+
+    lowcore = cpu_physical_memory_map(env->psa, len, 1);
+
+    return lowcore;
+}
+
+static void cpu_unmap_lowcore(LowCore *lowcore, hwaddr len)
+{
+    cpu_physical_memory_unmap(lowcore, len, 1, len);
+}
+
 static void do_svc_interrupt(CPUS390XState *env)
 {
     uint64_t mask, addr;
     LowCore *lowcore;
     hwaddr len = TARGET_PAGE_SIZE;
 
-    lowcore = cpu_physical_memory_map(env->psa, &len, 1);
+    lowcore = cpu_map_lowcore(env, &len);
 
     lowcore->svc_code = cpu_to_be16(env->int_svc_code);
     lowcore->svc_ilen = cpu_to_be16(env->int_svc_ilen);
@@ -486,7 +505,7 @@ static void do_svc_interrupt(CPUS390XState *env)
     mask = be64_to_cpu(lowcore->svc_new_psw.mask);
     addr = be64_to_cpu(lowcore->svc_new_psw.addr);
 
-    cpu_physical_memory_unmap(lowcore, len, 1, len);
+    cpu_unmap_lowcore(lowcore, len);
 
     load_psw(env, mask, addr);
 }
@@ -513,7 +532,7 @@ static void do_program_interrupt(CPUS390XState *env)
     qemu_log_mask(CPU_LOG_INT, "%s: code=0x%x ilen=%d\n",
                   __func__, env->int_pgm_code, ilen);
 
-    lowcore = cpu_physical_memory_map(env->psa, &len, 1);
+    lowcore = cpu_map_lowcore(env, &len);
 
     lowcore->pgm_ilen = cpu_to_be16(ilen);
     lowcore->pgm_code = cpu_to_be16(env->int_pgm_code);
@@ -522,7 +541,7 @@ static void do_program_interrupt(CPUS390XState *env)
     mask = be64_to_cpu(lowcore->program_new_psw.mask);
     addr = be64_to_cpu(lowcore->program_new_psw.addr);
 
-    cpu_physical_memory_unmap(lowcore, len, 1, len);
+    cpu_unmap_lowcore(lowcore, len);
 
     DPRINTF("%s: %x %x %" PRIx64 " %" PRIx64 "\n", __func__,
             env->int_pgm_code, ilen, env->psw.mask,
@@ -549,7 +568,7 @@ static void do_ext_interrupt(CPUS390XState *env)
     }
 
     q = &env->ext_queue[env->ext_index];
-    lowcore = cpu_physical_memory_map(env->psa, &len, 1);
+    lowcore = cpu_map_lowcore(env, &len);
 
     lowcore->ext_int_code = cpu_to_be16(q->code);
     lowcore->ext_params = cpu_to_be32(q->param);
@@ -560,7 +579,7 @@ static void do_ext_interrupt(CPUS390XState *env)
     mask = be64_to_cpu(lowcore->external_new_psw.mask);
     addr = be64_to_cpu(lowcore->external_new_psw.addr);
 
-    cpu_physical_memory_unmap(lowcore, len, 1, len);
+    cpu_unmap_lowcore(lowcore, len);
 
     env->ext_index--;
     if (env->ext_index == -1) {
Signature · 1 line
1.7.12.4
#5 lore raw

PATCH v5 3/12 s390: Add mapping helper functions.

In reply to Cornelia Huck

Add s390_cpu_physical_memory_{map,unmap} with special handling for the lowcore.

---
 target-s390x/cpu.h    |  4 ++++
 target-s390x/helper.c | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
target-s390x/cpu.h +4 -0
index 6700fe9..cd729d3 100644
@@ -299,6 +299,10 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw
 
 
 #ifndef CONFIG_USER_ONLY
+void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr len,
+                                   int is_write);
+void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
+                                    int is_write);
 void s390x_tod_timer(void *opaque);
 void s390x_cpu_timer(void *opaque);
 
target-s390x/helper.c +26 -0
index bf2b4d3..d350f28 100644
@@ -490,6 +490,32 @@ static void cpu_unmap_lowcore(LowCore *lowcore, hwaddr len)
     cpu_physical_memory_unmap(lowcore, len, 1, len);
 }
 
+void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr len,
+                                   int is_write)
+{
+    hwaddr start = addr;
+
+    /* Mind the prefix area. */
+    if (addr < 8192) {
+        start += env->psa;
+    } else if ((env->psa <= addr) && (addr < env->psa + 8192)) {
+        start -= env->psa;
+    }
+
+    if ((addr + len <= env->psa) || (addr >= env->psa + 8192)) {
+        return cpu_physical_memory_map(start, &len, is_write);
+    }
+
+    DPRINTF("mapping across lowcore boundaries not yet supported\n");
+    return NULL;
+}
+
+void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
+                                    int is_write)
+{
+    cpu_physical_memory_unmap(addr, len, is_write, len);
+}
+
 static void do_svc_interrupt(CPUS390XState *env)
 {
     uint64_t mask, addr;
Signature · 1 line
1.7.12.4
#7 lore raw

PATCH v5 4/12 Update linux headers.

In reply to Cornelia Huck

Base is kvm-next as of 2013/01/16.

---
 linux-headers/asm-generic/kvm_para.h |  4 ++++
 linux-headers/asm-powerpc/kvm_para.h |  2 +-
 linux-headers/linux/kvm.h            | 21 +++++++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 linux-headers/asm-generic/kvm_para.h
linux-headers/asm-generic/kvm_para.h new file +4 -0
new file mode 100644
index 0000000..486f0af
@@ -0,0 +1,4 @@
+/*
+ * There isn't anything here, but the file must not be empty or patch
+ * will delete it.
+ */
linux-headers/asm-powerpc/kvm_para.h +1 -1
index 7e64f57..484bcaa 100644
@@ -78,7 +78,7 @@ struct kvm_vcpu_arch_shared {
 
 #define KVM_HCALL_TOKEN(num)     _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
 
-#include <asm/epapr_hcalls.h>
+#include <uapi/asm/epapr_hcalls.h>
 
 #define KVM_FEATURE_MAGIC_PAGE	1
 
linux-headers/linux/kvm.h +21 -0
index bfdbf4d..2602437 100644
@@ -168,6 +168,7 @@ struct kvm_pit_config {
 #define KVM_EXIT_PAPR_HCALL	  19
 #define KVM_EXIT_S390_UCONTROL	  20
 #define KVM_EXIT_WATCHDOG         21
+#define KVM_EXIT_S390_TSCH        22
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -285,6 +286,15 @@ struct kvm_run {
 			__u64 ret;
 			__u64 args[9];
 		} papr_hcall;
+		/* KVM_EXIT_S390_TSCH */
+		struct {
+			__u16 subchannel_id;
+			__u16 subchannel_nr;
+			__u32 io_int_parm;
+			__u32 io_int_word;
+			__u32 ipb;
+			__u8 dequeued;
+		} s390_tsch;
 		/* Fix the size of the union. */
 		char padding[256];
 	};
@@ -397,10 +407,20 @@ struct kvm_s390_psw {
 #define KVM_S390_PROGRAM_INT		0xfffe0001u
 #define KVM_S390_SIGP_SET_PREFIX	0xfffe0002u
 #define KVM_S390_RESTART		0xfffe0003u
+#define KVM_S390_MCHK			0xfffe1000u
 #define KVM_S390_INT_VIRTIO		0xffff2603u
 #define KVM_S390_INT_SERVICE		0xffff2401u
 #define KVM_S390_INT_EMERGENCY		0xffff1201u
 #define KVM_S390_INT_EXTERNAL_CALL	0xffff1202u
+/* Anything below 0xfffe0000u is taken by INT_IO */
+#define KVM_S390_INT_IO(ai,cssid,ssid,schid)   \
+	(((schid)) |			       \
+	 ((ssid) << 16) |		       \
+	 ((cssid) << 18) |		       \
+	 ((ai) << 26))
+#define KVM_S390_INT_IO_MIN		0x00000000u
+#define KVM_S390_INT_IO_MAX		0xfffdffffu
+
 
 struct kvm_s390_interrupt {
 	__u32 type;
@@ -635,6 +655,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_IRQFD_RESAMPLE 82
 #define KVM_CAP_PPC_BOOKE_WATCHDOG 83
 #define KVM_CAP_PPC_HTAB_FD 84
+#define KVM_CAP_S390_CSS_SUPPORT 85
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
Signature · 1 line
1.7.12.4
#11 lore raw

PATCH v5 5/12 s390: Channel I/O basic defintions.

In reply to Cornelia Huck

Basic channel I/O structures and helper function.

---
 target-s390x/Makefile.objs |   2 +-
 target-s390x/cpu.h         |   5 ++
 target-s390x/ioinst.c      |  36 ++++++++
 target-s390x/ioinst.h      | 207 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 249 insertions(+), 1 deletion(-)
 create mode 100644 target-s390x/ioinst.c
 create mode 100644 target-s390x/ioinst.h
target-s390x/Makefile.objs +1 -1
index e728abf..3afb0b7 100644
@@ -1,4 +1,4 @@
 obj-y += translate.o helper.o cpu.o interrupt.o
 obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o
-obj-$(CONFIG_SOFTMMU) += machine.o
+obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o
 obj-$(CONFIG_KVM) += kvm.o
target-s390x/cpu.h +5 -0
index cd729d3..931ed4d 100644
@@ -352,6 +352,11 @@ static inline unsigned s390_del_running_cpu(CPUS390XState *env)
 void cpu_lock(void);
 void cpu_unlock(void);
 
+typedef struct SCHIB SCHIB;
+typedef struct ORB ORB;
+typedef struct IRB IRB;
+typedef struct CRW CRW;
+
 static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
 {
     env->aregs[0] = newtls >> 32;
target-s390x/ioinst.c new file +36 -0
new file mode 100644
index 0000000..06a16ee
@@ -0,0 +1,36 @@
+/*
+ * I/O instructions for S/390
+ *
+ * Copyright 2012 IBM Corp.
+ * Author(s): Cornelia Huck <[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 <sys/types.h>
+
+#include "cpu.h"
+#include "ioinst.h"
+
+int ioinst_disassemble_sch_ident(uint32_t value, int *m, int *cssid, int *ssid,
+                                 int *schid)
+{
+    if (!IOINST_SCHID_ONE(value)) {
+        return -EINVAL;
+    }
+    if (!IOINST_SCHID_M(value)) {
+        if (IOINST_SCHID_CSSID(value)) {
+            return -EINVAL;
+        }
+        *cssid = 0;
+        *m = 0;
+    } else {
+        *cssid = IOINST_SCHID_CSSID(value);
+        *m = 1;
+    }
+    *ssid = IOINST_SCHID_SSID(value);
+    *schid = IOINST_SCHID_NR(value);
+    return 0;
+}
target-s390x/ioinst.h new file +207 -0

207 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#12 lore raw

PATCH v5 6/12 s390: I/O interrupt and machine check injection.

In reply to Cornelia Huck

I/O interrupts are queued per isc. Only crw pending machine checks are supported.

---
 target-s390x/cpu.h    |  69 +++++++++++++++++++++++-
 target-s390x/helper.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 211 insertions(+), 1 deletion(-)
target-s390x/cpu.h +68 -1
index 931ed4d..97f70f3 100644
@@ -47,6 +47,11 @@
 #define MMU_USER_IDX 1
 
 #define MAX_EXT_QUEUE 16
+#define MAX_IO_QUEUE 16
+#define MAX_MCHK_QUEUE 16
+
+#define PSW_MCHK_MASK 0x0004000000000000
+#define PSW_IO_MASK 0x0200000000000000
 
 typedef struct PSW {
     uint64_t mask;
@@ -59,6 +64,17 @@ typedef struct ExtQueue {
     uint32_t param64;
 } ExtQueue;
 
+typedef struct IOIntQueue {
+    uint16_t id;
+    uint16_t nr;
+    uint32_t parm;
+    uint32_t word;
+} IOIntQueue;
+
+typedef struct MchkQueue {
+    uint16_t type;
+} MchkQueue;
+
 typedef struct CPUS390XState {
     uint64_t regs[16];     /* GP registers */
     CPU_DoubleU fregs[16]; /* FP registers */
@@ -90,9 +106,17 @@ typedef struct CPUS390XState {
     uint64_t cregs[16]; /* control registers */
 
     ExtQueue ext_queue[MAX_EXT_QUEUE];
-    int pending_int;
+    IOIntQueue io_queue[MAX_IO_QUEUE][8];
+    MchkQueue mchk_queue[MAX_MCHK_QUEUE];
 
+    int pending_int;
     int ext_index;
+    int io_index[8];
+    int mchk_index;
+
+    uint64_t ckc;
+    uint64_t cputm;
+    uint32_t todpr;
 
     CPU_COMMON
 
@@ -373,10 +397,14 @@ static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
 #define EXCP_EXT 1 /* external interrupt */
 #define EXCP_SVC 2 /* supervisor call (syscall) */
 #define EXCP_PGM 3 /* program interruption */
+#define EXCP_IO  7 /* I/O interrupt */
+#define EXCP_MCHK 8 /* machine check */
 
 #define INTERRUPT_EXT        (1 << 0)
 #define INTERRUPT_TOD        (1 << 1)
 #define INTERRUPT_CPUTIMER   (1 << 2)
+#define INTERRUPT_IO         (1 << 3)
+#define INTERRUPT_MCHK       (1 << 4)
 
 /* Program Status Word.  */
 #define S390_PSWM_REGNUM 0
@@ -920,6 +948,45 @@ static inline void cpu_inject_ext(CPUS390XState *env, uint32_t code, uint32_t pa
     cpu_interrupt(env, CPU_INTERRUPT_HARD);
 }
 
+static inline void cpu_inject_io(CPUS390XState *env, uint16_t subchannel_id,
+                                 uint16_t subchannel_number,
+                                 uint32_t io_int_parm, uint32_t io_int_word)
+{
+    int isc = ffs(io_int_word << 2) - 1;
+
+    if (env->io_index[isc] == MAX_IO_QUEUE - 1) {
+        /* ugh - can't queue anymore. Let's drop. */
+        return;
+    }
+
+    env->io_index[isc]++;
+    assert(env->io_index[isc] < MAX_IO_QUEUE);
+
+    env->io_queue[env->io_index[isc]][isc].id = subchannel_id;
+    env->io_queue[env->io_index[isc]][isc].nr = subchannel_number;
+    env->io_queue[env->io_index[isc]][isc].parm = io_int_parm;
+    env->io_queue[env->io_index[isc]][isc].word = io_int_word;
+
+    env->pending_int |= INTERRUPT_IO;
+    cpu_interrupt(env, CPU_INTERRUPT_HARD);
+}
+
+static inline void cpu_inject_crw_mchk(CPUS390XState *env)
+{
+    if (env->mchk_index == MAX_MCHK_QUEUE - 1) {
+        /* ugh - can't queue anymore. Let's drop. */
+        return;
+    }
+
+    env->mchk_index++;
+    assert(env->mchk_index < MAX_MCHK_QUEUE);
+
+    env->mchk_queue[env->mchk_index].type = 1;
+
+    env->pending_int |= INTERRUPT_MCHK;
+    cpu_interrupt(env, CPU_INTERRUPT_HARD);
+}
+
 static inline bool cpu_has_work(CPUState *cpu)
 {
     CPUS390XState *env = &S390_CPU(cpu)->env;
target-s390x/helper.c +143 -0

167 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#13 lore raw

PATCH v5 7/12 s390: Add channel I/O instructions.

In reply to Cornelia Huck

Provide handlers for (most) channel I/O instructions.

---
 target-s390x/cpu.h    | 101 ++++++++
 target-s390x/ioinst.c | 673 ++++++++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/ioinst.h |  16 ++
 trace-events          |   6 +
 4 files changed, 796 insertions(+)
target-s390x/cpu.h +101 -0
index 97f70f3..cf5334e 100644
@@ -130,6 +130,8 @@ typedef struct CPUS390XState {
     QEMUTimer *tod_timer;
 
     QEMUTimer *cpu_timer;
+
+    uint8_t chsc_page[TARGET_PAGE_SIZE];
 } CPUS390XState;
 
 #include "cpu-qom.h"
@@ -144,6 +146,9 @@ static inline void cpu_clone_regs(CPUS390XState *env, target_ulong newsp)
 }
 #endif
 
+/* distinguish between 24 bit and 31 bit addressing */
+#define HIGH_ORDER_BIT 0x80000000
+
 /* Interrupt Codes */
 /* Program Interrupts */
 #define PGM_OPERATION                   0x0001
@@ -327,6 +332,20 @@ void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr len,
                                    int is_write);
 void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
                                     int is_write);
+static inline hwaddr decode_basedisp_s(CPUS390XState *env, uint32_t ipb)
+{
+    hwaddr addr = 0;
+    uint8_t reg;
+
+    reg = ipb >> 28;
+    if (reg > 0) {
+        addr = env->regs[reg];
+    }
+    addr += (ipb >> 16) & 0xfff;
+
+    return addr;
+}
+
 void s390x_tod_timer(void *opaque);
 void s390x_cpu_timer(void *opaque);
 
@@ -376,11 +395,93 @@ static inline unsigned s390_del_running_cpu(CPUS390XState *env)
 void cpu_lock(void);
 void cpu_unlock(void);
 
+typedef struct SubchDev SubchDev;
 typedef struct SCHIB SCHIB;
 typedef struct ORB ORB;
 typedef struct IRB IRB;
 typedef struct CRW CRW;
 
+static inline SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid,
+                                       uint16_t schid)
+{
+    return NULL;
+}
+static inline bool css_subch_visible(SubchDev *sch)
+{
+    return false;
+}
+static inline void css_conditional_io_interrupt(SubchDev *sch)
+{
+}
+static inline int css_do_stsch(SubchDev *sch, SCHIB *schib)
+{
+    return -ENODEV;
+}
+static inline bool css_schid_final(uint8_t cssid, uint8_t ssid, uint16_t schid)
+{
+    return true;
+}
+static inline int css_do_msch(SubchDev *sch, SCHIB *schib)
+{
+    return -ENODEV;
+}
+static inline int css_do_xsch(SubchDev *sch)
+{
+    return -ENODEV;
+}
+static inline int css_do_csch(SubchDev *sch)
+{
+    return -ENODEV;
+}
+static inline int css_do_hsch(SubchDev *sch)
+{
+    return -ENODEV;
+}
+static inline int css_do_ssch(SubchDev *sch, ORB *orb)
+{
+    return -ENODEV;
+}
+static inline int css_do_tsch(SubchDev *sch, IRB *irb)
+{
+    return -ENODEV;
+}
+static inline int css_do_stcrw(CRW *crw)
+{
+    return 1;
+}
+static inline int css_do_tpi(uint64_t addr, int lowcore)
+{
+    return 0;
+}
+static inline int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid,
+                                       int rfmt, uint8_t l_chpid, void *buf)
+{
+    return 0;
+}
+static inline void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo)
+{
+}
+static inline int css_enable_mss(void)
+{
+    return -EINVAL;
+}
+static inline int css_enable_mcsse(void)
+{
+    return -EINVAL;
+}
+static inline int css_do_rsch(SubchDev *sch)
+{
+    return -ENODEV;
+}
+static inline int css_do_rchp(uint8_t cssid, uint8_t chpid)
+{
+    return -ENODEV;
+}
+static inline bool css_present(uint8_t cssid)
+{
+    return false;
+}
+
 static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
 {
     env->aregs[0] = newtls >> 32;
target-s390x/ioinst.c +673 -0

682 lines not on this page · raw message

target-s390x/ioinst.h +16 -0
index 5580d91..fdc50e3 100644
@@ -204,4 +204,20 @@ struct CRW {
 
 int ioinst_disassemble_sch_ident(uint32_t value, int *m, int *cssid, int *ssid,
                                  int *schid);
+int ioinst_handle_xsch(CPUS390XState *env, uint64_t reg1);
+int ioinst_handle_csch(CPUS390XState *env, uint64_t reg1);
+int ioinst_handle_hsch(CPUS390XState *env, uint64_t reg1);
+int ioinst_handle_msch(CPUS390XState *env, uint64_t reg1, uint32_t ipb);
+int ioinst_handle_ssch(CPUS390XState *env, uint64_t reg1, uint32_t ipb);
+int ioinst_handle_stcrw(CPUS390XState *env, uint32_t ipb);
+int ioinst_handle_stsch(CPUS390XState *env, uint64_t reg1, uint32_t ipb);
+int ioinst_handle_tsch(CPUS390XState *env, uint64_t reg1, uint32_t ipb);
+int ioinst_handle_chsc(CPUS390XState *env, uint32_t ipb);
+int ioinst_handle_tpi(CPUS390XState *env, uint32_t ipb);
+int ioinst_handle_schm(CPUS390XState *env, uint64_t reg1, uint64_t reg2,
+                       uint32_t ipb);
+int ioinst_handle_rsch(CPUS390XState *env, uint64_t reg1);
+int ioinst_handle_rchp(CPUS390XState *env, uint64_t reg1);
+int ioinst_handle_sal(CPUS390XState *env, uint64_t reg1);
+
 #endif
trace-events +6 -0
index 6eabbac..266cfd6 100644
@@ -1051,3 +1051,9 @@ xics_set_irq_lsi(int srcno, int nr) "set_irq_lsi: srcno %d [irq %#x]"
 xics_ics_write_xive(int nr, int srcno, int server, uint8_t priority) "ics_write_xive: irq %#x [src %d] server %#x prio %#x"
 xics_ics_reject(int nr, int srcno) "reject irq %#x [src %d]"
 xics_ics_eoi(int nr) "ics_eoi: irq %#x"
+
+# target-s390x/ioinst.c
+ioinst(const char *insn) "IOINST: %s"
+ioinst_sch_id(const char *insn, int cssid, int ssid, int schid) "IOINST: %s (%x.%x.%04x)"
+ioinst_chp_id(const char *insn, int cssid, int chpid) "IOINST: %s (%x.%02x)"
+ioinst_chsc_cmd(uint16_t cmd, uint16_t len) "IOINST: chsc command %04x, len %04x"
Signature · 1 line
1.7.12.4
#14 lore raw

PATCH v5 8/12 s390: Virtual channel subsystem support.

In reply to Cornelia Huck

Provide a mechanism for qemu to provide fully virtual subchannels to the guest.

---
 hw/s390x/Makefile.objs |    1 +
 hw/s390x/css.c         | 1131 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/css.h         |   92 ++++
 target-s390x/cpu.h     |   65 +++
 trace-events           |    8 +
 5 files changed, 1297 insertions(+)
 create mode 100644 hw/s390x/css.c
 create mode 100644 hw/s390x/css.h
hw/s390x/Makefile.objs +1 -0
index ae87a12..029a0b2 100644
@@ -5,3 +5,4 @@ obj-y += s390-virtio-hcall.o
 obj-y += sclp.o
 obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
+obj-y += css.o
hw/s390x/css.c new file +1131 -0

1,131 lines not on this page · raw message

hw/s390x/css.h new file +92 -0

92 lines not on this page · raw message

target-s390x/cpu.h +65 -0

81 lines not on this page · raw message

trace-events +8 -0
index 266cfd6..1f93fd6 100644
@@ -1057,3 +1057,11 @@ ioinst(const char *insn) "IOINST: %s"
 ioinst_sch_id(const char *insn, int cssid, int ssid, int schid) "IOINST: %s (%x.%x.%04x)"
 ioinst_chp_id(const char *insn, int cssid, int chpid) "IOINST: %s (%x.%02x)"
 ioinst_chsc_cmd(uint16_t cmd, uint16_t len) "IOINST: chsc command %04x, len %04x"
+
+# hw/s390x/css.c
+css_enable_facility(const char *facility) "CSS: enable %s"
+css_crw(uint8_t rsc, uint8_t erc, uint16_t rsid, const char *chained) "CSS: queueing crw: rsc=%x, erc=%x, rsid=%x %s"
+css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02x (type %02x)"
+css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x %s"
+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"
Signature · 1 line
1.7.12.4
#15 lore raw

PATCH v5 9/12 s390: Wire up channel I/O in kvm.

In reply to Cornelia Huck

Trigger the code for our virtual css in case of instruction intercepts for I/O instructions.

Handle the tsch exit for the subchannel-related part of tsch.

---
 target-s390x/cpu.h |  11 +++
 target-s390x/kvm.c | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 250 insertions(+), 13 deletions(-)
target-s390x/cpu.h +11 -0
index b619edb..4438dc8 100644
@@ -1136,6 +1136,13 @@ void program_interrupt(CPUS390XState *env, uint32_t code, int ilen);
 void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp,
                                      uintptr_t retaddr);
 
+#ifdef CONFIG_KVM
+int kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,
+                          uint16_t subchannel_nr, uint32_t io_int_parm,
+                          uint32_t io_int_word);
+int kvm_s390_crw_mchk(S390CPU *cpu);
+void kvm_s390_enable_css_support(S390CPU *cpu);
+#else
 static inline int kvm_s390_io_interrupt(S390CPU *cpu,
                                         uint16_t subchannel_id,
                                         uint16_t subchannel_nr,
@@ -1148,6 +1155,10 @@ static inline int kvm_s390_crw_mchk(S390CPU *cpu)
 {
     return -EOPNOTSUPP;
 }
+static inline void kvm_s390_enable_css_support(S390CPU *cpu)
+{
+}
+#endif
 
 static inline void s390_io_interrupt(S390CPU *cpu,
                                      uint16_t subchannel_id,
target-s390x/kvm.c +239 -13

302 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#16 lore raw

PATCH v5 10/12 s390: Add new channel I/O based virtio transport.

In reply to Cornelia Huck

Add a new virtio transport that uses channel commands to perform virtio operations.

---
 hw/s390x/Makefile.objs |   1 +
 hw/s390x/virtio-ccw.c  | 906 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/virtio-ccw.h  |  79 +++++
 trace-events           |   4 +
 4 files changed, 990 insertions(+)
 create mode 100644 hw/s390x/virtio-ccw.c
 create mode 100644 hw/s390x/virtio-ccw.h
hw/s390x/Makefile.objs +1 -0
index 029a0b2..71ad255 100644
@@ -6,3 +6,4 @@ obj-y += sclp.o
 obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
 obj-y += css.o
+obj-y += virtio-ccw.o
hw/s390x/virtio-ccw.c new file +906 -0

906 lines not on this page · raw message

hw/s390x/virtio-ccw.h new file +79 -0

79 lines not on this page · raw message

trace-events +4 -0
index 1f93fd6..1bbcd79 100644
@@ -1065,3 +1065,7 @@ css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02
 css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x %s"
 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"
+
+# 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"
+virtio_ccw_new_device(int cssid, int ssid, int schid, int devno, const char *devno_mode) "VIRTIO-CCW: add subchannel %x.%x.%04x, devno %04x (%s)"
Signature · 1 line
1.7.12.4
#17 lore raw

PATCH v5 11/12 s390-virtio: Factor out some initialization code.

In reply to Cornelia Huck

Some of the machine initialization for s390-virtio will be reused by virtio-ccw.

---
 hw/s390-virtio.c | 155 ++++++++++++++++++++++++++++++-------------------------
 hw/s390-virtio.h |   5 ++
 2 files changed, 91 insertions(+), 69 deletions(-)
hw/s390-virtio.c +86 -69
index bded30b..603f6b0 100644
@@ -155,62 +155,10 @@ unsigned s390_del_running_cpu(CPUS390XState *env)
     return s390_running_cpus;
 }
 
-/* PC hardware initialisation */
-static void s390_init(QEMUMachineInitArgs *args)
+void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys)
 {
-    ram_addr_t my_ram_size = args->ram_size;
-    const char *cpu_model = args->cpu_model;
-    const char *kernel_filename = args->kernel_filename;
-    const char *kernel_cmdline = args->kernel_cmdline;
-    const char *initrd_filename = args->initrd_filename;
-    CPUS390XState *env = NULL;
-    MemoryRegion *sysmem = get_system_memory();
-    MemoryRegion *ram = g_new(MemoryRegion, 1);
-    ram_addr_t kernel_size = 0;
-    ram_addr_t initrd_offset;
-    ram_addr_t initrd_size = 0;
-    int shift = 0;
-    uint8_t *storage_keys;
-    void *virtio_region;
-    hwaddr virtio_region_len;
-    hwaddr virtio_region_start;
     int i;
 
-    /* s390x ram size detection needs a 16bit multiplier + an increment. So
-       guests > 64GB can be specified in 2MB steps etc. */
-    while ((my_ram_size >> (20 + shift)) > 65535) {
-        shift++;
-    }
-    my_ram_size = my_ram_size >> (20 + shift) << (20 + shift);
-
-    /* lets propagate the changed ram size into the global variable. */
-    ram_size = my_ram_size;
-
-    /* get a BUS */
-    s390_bus = s390_virtio_bus_init(&my_ram_size);
-    s390_sclp_init();
-
-    /* register hypercalls */
-    s390_virtio_register_hcalls();
-
-    /* allocate RAM */
-    memory_region_init_ram(ram, "s390.ram", my_ram_size);
-    vmstate_register_ram_global(ram);
-    memory_region_add_subregion(sysmem, 0, ram);
-
-    /* clear virtio region */
-    virtio_region_len = my_ram_size - ram_size;
-    virtio_region_start = ram_size;
-    virtio_region = cpu_physical_memory_map(virtio_region_start,
-                                            &virtio_region_len, true);
-    memset(virtio_region, 0, virtio_region_len);
-    cpu_physical_memory_unmap(virtio_region, virtio_region_len, 1,
-                              virtio_region_len);
-
-    /* allocate storage keys */
-    storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE);
-
-    /* init CPUs */
     if (cpu_model == NULL) {
         cpu_model = "host";
     }
@@ -219,21 +167,27 @@ static void s390_init(QEMUMachineInitArgs *args)
 
     for (i = 0; i < smp_cpus; i++) {
         S390CPU *cpu;
-        CPUS390XState *tmp_env;
 
         cpu = cpu_s390x_init(cpu_model);
-        tmp_env = &cpu->env;
-        if (!env) {
-            env = tmp_env;
-        }
+
         ipi_states[i] = cpu;
-        tmp_env->halted = 1;
-        tmp_env->exception_index = EXCP_HLT;
-        tmp_env->storage_keys = storage_keys;
+        cpu->env.halted = 1;
+        cpu->env.exception_index = EXCP_HLT;
+        cpu->env.storage_keys = storage_keys;
     }
+}
+
+void s390_set_up_kernel(const char *kernel_filename,
+                        const char *kernel_cmdline,
+                        const char *initrd_filename)
+{
+    ram_addr_t kernel_size = 0;
+    ram_addr_t initrd_offset;
+    ram_addr_t initrd_size = 0;
+    S390CPU *cpu = s390_cpu_addr2state(0);
 
     /* One CPU has to run */
-    s390_add_running_cpu(env);
+    s390_add_running_cpu(&cpu->env);
 
     if (kernel_filename) {
 
@@ -252,8 +206,8 @@ static void s390_init(QEMUMachineInitArgs *args)
          * value was 0x800 (the SALIPL loader) and it wont work. For
          * all (Linux) cases 0x10000 (KERN_IMAGE_START) should be fine.
          */
-        env->psw.addr = KERN_IMAGE_START;
-        env->psw.mask = 0x0000000180000000ULL;
+        cpu->env.psw.addr = KERN_IMAGE_START;
+        cpu->env.psw.mask = 0x0000000180000000ULL;
     } else {
         ram_addr_t bios_size = 0;
         char *bios_filename;
@@ -275,8 +229,8 @@ static void s390_init(QEMUMachineInitArgs *args)
             hw_error("stage1 bootloader is > 4k\n");
         }
 
-        env->psw.addr = ZIPL_START;
-        env->psw.mask = 0x0000000180000000ULL;
+        cpu->env.psw.addr = ZIPL_START;
+        cpu->env.psw.mask = 0x0000000180000000ULL;
     }
 
     if (initrd_filename) {
@@ -302,9 +256,13 @@ static void s390_init(QEMUMachineInitArgs *args)
         memcpy(rom_ptr(KERN_PARM_AREA), kernel_cmdline,
                strlen(kernel_cmdline) + 1);
     }
+}
 
-    /* Create VirtIO network adapters */
-    for(i = 0; i < nb_nics; i++) {
+void s390_create_virtio_net(BusState *bus, const char *name)
+{
+    int i;
+
+    for (i = 0; i < nb_nics; i++) {
         NICInfo *nd = &nd_table[i];
         DeviceState *dev;
 
@@ -317,12 +275,71 @@ static void s390_init(QEMUMachineInitArgs *args)
             exit(1);
         }
 
-        dev = qdev_create((BusState *)s390_bus, "virtio-net-s390");
+        dev = qdev_create(bus, name);
         qdev_set_nic_properties(dev, nd);
         qdev_init_nofail(dev);
     }
 }
 
+/* PC hardware initialisation */
+static void s390_init(QEMUMachineInitArgs *args)
+{
+    ram_addr_t my_ram_size = args->ram_size;
+    const char *cpu_model = args->cpu_model;
+    const char *kernel_filename = args->kernel_filename;
+    const char *kernel_cmdline = args->kernel_cmdline;
+    const char *initrd_filename = args->initrd_filename;
+    MemoryRegion *sysmem = get_system_memory();
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
+    int shift = 0;
+    uint8_t *storage_keys;
+    void *virtio_region;
+    hwaddr virtio_region_len;
+    hwaddr virtio_region_start;
+
+    /* s390x ram size detection needs a 16bit multiplier + an increment. So
+       guests > 64GB can be specified in 2MB steps etc. */
+    while ((my_ram_size >> (20 + shift)) > 65535) {
+        shift++;
+    }
+    my_ram_size = my_ram_size >> (20 + shift) << (20 + shift);
+
+    /* lets propagate the changed ram size into the global variable. */
+    ram_size = my_ram_size;
+
+    /* get a BUS */
+    s390_bus = s390_virtio_bus_init(&my_ram_size);
+    s390_sclp_init();
+
+    /* register hypercalls */
+    s390_virtio_register_hcalls();
+
+    /* allocate RAM */
+    memory_region_init_ram(ram, "s390.ram", my_ram_size);
+    vmstate_register_ram_global(ram);
+    memory_region_add_subregion(sysmem, 0, ram);
+
+    /* clear virtio region */
+    virtio_region_len = my_ram_size - ram_size;
+    virtio_region_start = ram_size;
+    virtio_region = cpu_physical_memory_map(virtio_region_start,
+                                            &virtio_region_len, true);
+    memset(virtio_region, 0, virtio_region_len);
+    cpu_physical_memory_unmap(virtio_region, virtio_region_len, 1,
+                              virtio_region_len);
+
+    /* allocate storage keys */
+    storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE);
+
+    /* init CPUs */
+    s390_init_cpus(cpu_model, storage_keys);
+
+    s390_set_up_kernel(kernel_filename, kernel_cmdline, initrd_filename);
+
+    /* Create VirtIO network adapters */
+    s390_create_virtio_net((BusState *)s390_bus, "virtio-net-s390");
+}
+
 static QEMUMachine s390_machine = {
     .name = "s390-virtio",
     .alias = "s390",
hw/s390-virtio.h +5 -0
index 25bb610..aefc99d 100644
@@ -19,4 +19,9 @@
 typedef int (*s390_virtio_fn)(const uint64_t *args);
 void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
 
+void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys);
+void s390_set_up_kernel(const char *kernel_filename,
+                        const char *kernel_cmdline,
+                        const char *initrd_filename);
+void s390_create_virtio_net(BusState *bus, const char *name);
 #endif
Signature · 1 line
1.7.12.4
#18 lore raw

PATCH v5 12/12 s390: Add s390-ccw-virtio machine.

In reply to Cornelia Huck

Add a new machine type, s390-ccw-virtio, making use of the virtio-ccw transport to present virtio devices as channel devices and make it the default on s390.

---
 hw/s390-virtio.c           |   1 -
 hw/s390-virtio.h           |   1 +
 hw/s390x/Makefile.objs     |   1 +
 hw/s390x/s390-virtio-ccw.c | 141 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 hw/s390x/s390-virtio-ccw.c
hw/s390-virtio.c +0 -1
index 603f6b0..3e58bc2 100644
@@ -353,7 +353,6 @@ static QEMUMachine s390_machine = {
     .no_sdcard = 1,
     .use_virtcon = 1,
     .max_cpus = 255,
-    .is_default = 1,
     DEFAULT_MACHINE_OPTIONS,
 };
 
hw/s390-virtio.h +1 -0
index aefc99d..a2cad40 100644
@@ -15,6 +15,7 @@
 #define KVM_S390_VIRTIO_NOTIFY          0
 #define KVM_S390_VIRTIO_RESET           1
 #define KVM_S390_VIRTIO_SET_STATUS      2
+#define KVM_S390_VIRTIO_CCW_NOTIFY      3
 
 typedef int (*s390_virtio_fn)(const uint64_t *args);
 void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
hw/s390x/Makefile.objs +1 -0
index 71ad255..54688b4 100644
@@ -6,4 +6,5 @@ obj-y += sclp.o
 obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
 obj-y += css.o
+obj-y += s390-virtio-ccw.o
 obj-y += virtio-ccw.o
hw/s390x/s390-virtio-ccw.c new file +141 -0

141 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#8 lore raw

Re: [Qemu-devel] [PATCH 04/12] Update linux headers.

In reply to Cornelia Huck

linux-headers/asm-powerpc/kvm_para.h struct kvm_vcpu_arch_shared { · line 81

Quoted 10 lines · Cornelia Huck

Base is kvm-next as of 2013/01/16.

linux-headers/asm-powerpc/kvm_para.h +1 -1
@@ -78,7 +78,7 @@ struct kvm_vcpu_arch_shared {
 
 #define KVM_HCALL_TOKEN(num)     _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
 
-#include <asm/epapr_hcalls.h>
+#include <uapi/asm/epapr_hcalls.h>

This is reintroducing a bug, isn't it? cf
http://lists.gnu.org/archive/html/qemu-devel/2012-12/msg02807.html

(maybe this just means the sync needs to be against some different set of kernel headers?)

-- PMM

#9 lore raw

Re: [Qemu-devel] [PATCH 04/12] Update linux headers.

Quoted 15 lines · On Thu, 17 Jan 2013 15:05:46 +0000 Peter Maydell <[email protected]>…

linux-headers/asm-powerpc/kvm_para.h struct kvm_vcpu_arch_shared { · line 81

Quoted 10 lines · Cornelia Huck

Base is kvm-next as of 2013/01/16.

linux-headers/asm-powerpc/kvm_para.h +1 -1
@@ -78,7 +78,7 @@ struct kvm_vcpu_arch_shared {
 
 #define KVM_HCALL_TOKEN(num)     _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
 
-#include <asm/epapr_hcalls.h>
+#include <uapi/asm/epapr_hcalls.h>

This is reintroducing a bug, isn't it? cf
http://lists.gnu.org/archive/html/qemu-devel/2012-12/msg02807.html

Quoted 5 lines

(maybe this just means the sync needs to be against some different set of kernel headers?)

-- PMM

Hm, I seem to have some stale copy here - will check.

#10 lore raw

Re: [Qemu-devel] [PATCH 04/12] Update linux headers.

Quoted 18 lines · Cornelia Huck
Quoted 15 lines · On Thu, 17 Jan 2013 15:05:46 +0000 Peter Maydell <[email protected]>…

linux-headers/asm-powerpc/kvm_para.h struct kvm_vcpu_arch_shared { · line 81

Quoted 10 lines · Cornelia Huck

Base is kvm-next as of 2013/01/16.

linux-headers/asm-powerpc/kvm_para.h +1 -1
@@ -78,7 +78,7 @@ struct kvm_vcpu_arch_shared {
 
 #define KVM_HCALL_TOKEN(num)     _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
 
-#include <asm/epapr_hcalls.h>
+#include <uapi/asm/epapr_hcalls.h>

This is reintroducing a bug, isn't it? cf
http://lists.gnu.org/archive/html/qemu-devel/2012-12/msg02807.html

Quoted 7 lines
Quoted 5 lines

(maybe this just means the sync needs to be against some different set of kernel headers?)

-- PMM

Hm, I seem to have some stale copy here - will check.

No, the problem is that the fix went into master, but you were probably basing off of next. This is the way Linus envisions Linux development. Next is always a broken tree.

Alex

#20 lore raw
In reply to Cornelia Huck
Quoted 4 lines · Cornelia Huck

Hi,

here's the latest incarnation of my channel I/O and virtio-ccw patchset for qemu, containing various changes over the last one.

Which tree are you working against? This set doesn't apply on s390-next.

Alex

Quoted 61 lines

(Note that "s390: Add a hypercall registration interface." has already been posted: http://marc.info/?l=qemu-devel&m=135834160607372&w=2)

Changes include:
- Add various defines for magic constants.
- Introduce helpers for various mapping stuff and use them.
- Adapt virtio-ccw to QOM conventions.
- Move the new s390-ccw-virtio machine into an extra file (and an extra patch).
- Improve cpu handling during machine init (don't pass around env).

Cornelia Huck (12):
s390: Add a hypercall registration interface.
s390: Lowcore mapping helper.
s390: Add mapping helper functions. Update linux headers.
s390: Channel I/O basic defintions.
s390: I/O interrupt and machine check injection.
s390: Add channel I/O instructions.
s390: Virtual channel subsystem support.
s390: Wire up channel I/O in kvm.
s390: Add new channel I/O based virtio transport.
s390-virtio: Factor out some initialization code.
s390: Add s390-ccw-virtio machine.

hw/s390-virtio.c                     |  240 ++++----
hw/s390-virtio.h                     |   28 +
hw/s390x/Makefile.objs               |    4 +
hw/s390x/css.c                       | 1131 ++++++++++++++++++++++++++++++++++
hw/s390x/css.h                       |   92 +++
hw/s390x/s390-virtio-ccw.c           |  141 +++++
hw/s390x/s390-virtio-hcall.c         |   36 ++
hw/s390x/virtio-ccw.c                |  906 +++++++++++++++++++++++++++
hw/s390x/virtio-ccw.h                |   79 +++
linux-headers/asm-generic/kvm_para.h |    4 +
linux-headers/asm-powerpc/kvm_para.h |    2 +-
linux-headers/linux/kvm.h            |   21 +
target-s390x/Makefile.objs           |    2 +-
target-s390x/cpu.h                   |  257 +++++++-
target-s390x/helper.c                |  200 +++++-
target-s390x/ioinst.c                |  709 +++++++++++++++++++++
target-s390x/ioinst.h                |  223 +++++++
target-s390x/kvm.c                   |  254 +++++++-
target-s390x/misc_helper.c           |    2 +-
trace-events                         |   18 +
20 files changed, 4215 insertions(+), 134 deletions(-)

create mode 100644 hw/s390-virtio.h
create mode 100644 hw/s390x/css.c
create mode 100644 hw/s390x/css.h
create mode 100644 hw/s390x/s390-virtio-ccw.c create mode 100644 hw/s390x/s390-virtio-hcall.c create mode 100644 hw/s390x/virtio-ccw.c create mode 100644 hw/s390x/virtio-ccw.h create mode 100644 linux-headers/asm-generic/kvm_para.h create mode 100644 target-s390x/ioinst.c create mode 100644 target-s390x/ioinst.h

Signature · 1 line
1.7.12.4
#4 lore raw

Re: [PATCH 02/12] s390: Lowcore mapping helper.

In reply to Cornelia Huck
Quoted 13 lines · Cornelia Huck

Create a lowcore mapping helper that includes a check for sufficient length.

---
target-s390x/helper.c | 31 +++++++++++++++++++++++++------

1 file changed, 25 insertions(+), 6 deletions(-)
target-s390x/helper.c +0 -0
index 9a132e6..bf2b4d3 100644

target-s390x/helper.c static uint64_t get_psw_mask(CPUS390XState *env) · line 474

Quoted 4 lines
target-s390x/helper.c +1 -0
@@ -471,13 +471,32 @@ static uint64_t get_psw_mask(CPUS390XState *env)
    return r;
 }
 
+static LowCore *cpu_map_lowcore(CPUS390XState *env, hwaddr *len)

Just declare len to PAGE_SIZE * 2, like you do in kvm. Or to sizeof(LowCore). Then don't pass it in as parameter, but basically guarantee that the function always returns a full LowCore struct.

target-s390x/helper.c static uint64_t get_psw_mask(CPUS390XState *env) · line 483

Quoted 9 lines
target-s390x/helper.c +9 -0
+{
+    LowCore *lowcore;
+
+    if (*len < sizeof(LowCore)) {
+        cpu_abort(env, "Insufficient length %d for mapping lowcore\n",
+                  (int) *len);
+    }
+
+    lowcore = cpu_physical_memory_map(env->psa, len, 1);

Here is the place where the size check should be really :).

Alex

#6 lore raw

Re: [PATCH 03/12] s390: Add mapping helper functions.

In reply to Cornelia Huck
Quoted 29 lines · Cornelia Huck

Add s390_cpu_physical_memory_{map,unmap} with special handling for the lowcore.

---
target-s390x/cpu.h | 4 ++++
target-s390x/helper.c | 26 ++++++++++++++++++++++++++

2 files changed, 30 insertions(+)
target-s390x/cpu.h +4 -0
index 6700fe9..cd729d3 100644
@@ -299,6 +299,10 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw
 
 
 #ifndef CONFIG_USER_ONLY
+void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr len,
+                                   int is_write);
+void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
+                                    int is_write);
 void s390x_tod_timer(void *opaque);
 void s390x_cpu_timer(void *opaque);
 
target-s390x/helper.c +0 -0
index bf2b4d3..d350f28 100644

target-s390x/helper.c static void cpu_unmap_lowcore(LowCore *lowcore, hwaddr len) · line 493

Quoted 4 lines
target-s390x/helper.c +1 -0
@@ -490,6 +490,32 @@ static void cpu_unmap_lowcore(LowCore *lowcore, hwaddr len)
    cpu_physical_memory_unmap(lowcore, len, 1, len);
 }
 
+void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr len,

Please stick to the same semantics as cpu_physical_memory_map and pass hwaddr *len here. Otherwise the caller can't do sanity checks.

Quoted 6 lines
target-s390x/helper.c +6 -0
+                                   int is_write)
+{
+    hwaddr start = addr;
+
+    /* Mind the prefix area. */
+    if (addr < 8192) {

target-s390x/helper.c static void cpu_unmap_lowcore(LowCore *lowcore, hwaddr len) · line 509

Quoted 10 lines
target-s390x/helper.c +10 -0
+        start += env->psa;
+    } else if ((env->psa <= addr) && (addr < env->psa + 8192)) {
+        start -= env->psa;
+    }
+
+    if ((addr + len <= env->psa) || (addr >= env->psa + 8192)) {
+        return cpu_physical_memory_map(start, &len, is_write);
+    }
+
+    DPRINTF("mapping across lowcore boundaries not yet supported\n");

I only understand half of what this function does :). You basically want

  if (addr < 8192) {
    start += env->psa;
    len = min(8192 - addr, len);
}

We can easily support mapping of the lowcode higher up in memory, right? So we only have to take the case into account where [addr..addr+len] is within the first 8192 bytes.

And if you pass len as pointer, we can also indicate to the caller that the mapping isn't for all of the memory he requested, but only part of it.

Alex

Quoted 15 lines
target-s390x/helper.c +9 -0
+    return NULL;
+}
+
+void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
+                                    int is_write)
+{
+    cpu_physical_memory_unmap(addr, len, is_write, len);
+}
+
 static void do_svc_interrupt(CPUS390XState *env)
 {
    uint64_t mask, addr;
Signature · 1 line
1.7.12.4
#19 lore raw

Re: [PATCH 12/12] s390: Add s390-ccw-virtio machine.

In reply to Cornelia Huck
Quoted 173 lines · Cornelia Huck

Add a new machine type, s390-ccw-virtio, making use of the virtio-ccw transport to present virtio devices as channel devices and make it the default on s390.

---

hw/s390-virtio.c           |   1 -
hw/s390-virtio.h           |   1 +
hw/s390x/Makefile.objs     |   1 +
hw/s390x/s390-virtio-ccw.c | 141 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 143 insertions(+), 1 deletion(-)

create mode 100644 hw/s390x/s390-virtio-ccw.c

hw/s390-virtio.c +0 -1
index 603f6b0..3e58bc2 100644
@@ -353,7 +353,6 @@ static QEMUMachine s390_machine = {
    .no_sdcard = 1,
    .use_virtcon = 1,
    .max_cpus = 255,
-    .is_default = 1,
    DEFAULT_MACHINE_OPTIONS,
 };
 
hw/s390-virtio.h +1 -0
index aefc99d..a2cad40 100644
@@ -15,6 +15,7 @@
 #define KVM_S390_VIRTIO_NOTIFY          0
 #define KVM_S390_VIRTIO_RESET           1
 #define KVM_S390_VIRTIO_SET_STATUS      2
+#define KVM_S390_VIRTIO_CCW_NOTIFY      3
 
 typedef int (*s390_virtio_fn)(const uint64_t *args);
 void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
hw/s390x/Makefile.objs +0 -0
index 71ad255..54688b4 100644
@@ -6,4 +6,5 @@ obj-y += sclp.o

obj-y += event-facility.o
obj-y += sclpquiesce.o sclpconsole.o
obj-y += css.o
+obj-y += s390-virtio-ccw.o
obj-y += virtio-ccw.o

hw/s390x/s390-virtio-ccw.c new file +120 -0
new file mode 100644
index 0000000..98552d3
@@ -0,0 +1,141 @@
+/*
+ * virtio ccw machine
+ *
+ * Copyright 2012 IBM Corp.
+ * Author(s): Cornelia Huck <[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 "hw/boards.h"
+#include "exec/address-spaces.h"
+#include "hw/s390-virtio.h"
+#include "hw/s390x/sclp.h"
+#include "ioinst.h"
+#include "css.h"
+#include "virtio-ccw.h"
+
+static VirtioCcwBus *ccw_bus;
+
+static int virtio_ccw_hcall_notify(const uint64_t *args)
+{
+    uint64_t subch_id = args[0];
+    uint64_t queue = args[1];
+    SubchDev *sch;
+    int cssid, ssid, schid, m;
+
+    if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
+        return -EINVAL;
+    }
+    sch = css_find_subch(m, cssid, ssid, schid);
+    if (!sch || !css_subch_visible(sch)) {
+        return -EINVAL;
+    }
+    virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
+    return 0;
+
+}
+
+static int virtio_ccw_hcall_early_printk(const uint64_t *args)
+{
+    uint64_t mem = args[0];
+
+    if (mem < ram_size) {
+        /* Early printk */
+        return 0;
+    }
+    return -EINVAL;
+}
+
+static void virtio_ccw_register_hcalls(void)
+{
+    s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
+                                   virtio_ccw_hcall_notify);
+    /* Tolerate early printk. */
+    s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
+                                   virtio_ccw_hcall_early_printk);
+}
+
+static void ccw_init(QEMUMachineInitArgs *args)
+{
+    ram_addr_t my_ram_size = args->ram_size;
+    const char *cpu_model = args->cpu_model;
+    const char *kernel_filename = args->kernel_filename;
+    const char *kernel_cmdline = args->kernel_cmdline;
+    const char *initrd_filename = args->initrd_filename;
+    MemoryRegion *sysmem = get_system_memory();
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
+    int shift = 0;
+    uint8_t *storage_keys;
+    int ret;
+
+    /* s390x ram size detection needs a 16bit multiplier + an increment. So
+       guests > 64GB can be specified in 2MB steps etc. */
+    while ((my_ram_size >> (20 + shift)) > 65535) {
+        shift++;
+    }
+    my_ram_size = my_ram_size >> (20 + shift) << (20 + shift);
+
+    /* lets propagate the changed ram size into the global variable. */
+    ram_size = my_ram_size;
+
+    /* get a BUS */
+    ccw_bus = virtio_ccw_bus_init();
+    s390_sclp_init();
+
+    /* register hypercalls */
+    virtio_ccw_register_hcalls();
+
+    /* allocate RAM */
+    memory_region_init_ram(ram, "s390.ram", my_ram_size);
+    vmstate_register_ram_global(ram);
+    memory_region_add_subregion(sysmem, 0, ram);
+
+    /* allocate storage keys */
+    storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE);
+
+    /* init CPUs */
+    s390_init_cpus(cpu_model, storage_keys);
+
+    kvm_s390_enable_css_support(s390_cpu_addr2state(0));
+
+    /*
+     * Create virtual css and set it as default so that non mcss-e
+     * enabled guests only see virtio devices.
+     */
+    ret = css_create_css_image(VIRTUAL_CSSID, true);
+    assert(ret == 0);
+
+
+    s390_set_up_kernel(kernel_filename, kernel_cmdline, initrd_filename);
+
+    /* Create VirtIO network adapters */
+    s390_create_virtio_net(BUS(ccw_bus), "virtio-net-ccw");
+
+}
+
+static QEMUMachine ccw_machine = {
+    .name = "s390-ccw-virtio",

hw/s390x/s390-virtio-ccw.c line 130

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c new file +10 -0
+    .alias = "s390-ccw",
+    .desc = "VirtIO-ccw based S390 machine",
+    .init = ccw_init,
+    .block_default_type = IF_VIRTIO,
+    .no_cdrom = 1,
+    .no_floppy = 1,
+    .no_serial = 1,
+    .no_parallel = 1,
+    .no_sdcard = 1,
+    .use_virtcon = 1,

Still using virtcon? :)

Alex

Quoted 14 lines
hw/s390x/s390-virtio-ccw.c new file +11 -0
+    .max_cpus = 255,
+    .is_default = 1,
+    DEFAULT_MACHINE_OPTIONS,
+};
+
+static void ccw_machine_init(void)
+{
+    qemu_register_machine(&ccw_machine);
+}
+
+machine_init(ccw_machine_init);
Signature · 1 line
1.7.12.4