forked from kata-containers/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qemu_s390x.go
258 lines (217 loc) · 7.39 KB
/
qemu_s390x.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Copyright (c) 2018 IBM
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"fmt"
"time"
govmmQemu "github.com/intel/govmm/qemu"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/types"
)
type qemuS390x struct {
// inherit from qemuArchBase, overwrite methods if needed
qemuArchBase
}
const defaultQemuPath = "/usr/bin/qemu-system-s390x"
const defaultQemuMachineType = QemuCCWVirtio
const defaultQemuMachineOptions = "accel=kvm"
const virtioSerialCCW = "virtio-serial-ccw"
const qmpMigrationWaitTimeout = 5 * time.Second
var qemuPaths = map[string]string{
QemuCCWVirtio: defaultQemuPath,
}
// Verify needed parameters
var kernelParams = []Param{
{"console", "ttysclp0"},
}
var ccwbridge = types.NewBridge(types.CCW, "", make(map[uint32]string, types.CCWBridgeMaxCapacity), 0)
var supportedQemuMachines = []govmmQemu.Machine{
{
Type: QemuCCWVirtio,
Options: defaultQemuMachineOptions,
},
}
// MaxQemuVCPUs returns the maximum number of vCPUs supported
func MaxQemuVCPUs() uint32 {
// Max number of virtual Cpu defined in qemu. See
// https://github.com/qemu/qemu/blob/80422b00196a7af4c6efb628fae0ad8b644e98af/target/s390x/cpu.h#L55
// #define S390_MAX_CPUS 248
return uint32(248)
}
func newQemuArch(config HypervisorConfig) qemuArch {
machineType := config.HypervisorMachineType
if machineType == "" {
machineType = defaultQemuMachineType
}
q := &qemuS390x{
qemuArchBase{
machineType: machineType,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
supportedQemuMachines: supportedQemuMachines,
kernelParamsNonDebug: kernelParamsNonDebug,
kernelParamsDebug: kernelParamsDebug,
kernelParams: kernelParams,
},
}
// Set first bridge type to CCW
q.Bridges = append(q.Bridges, ccwbridge)
if config.ImagePath != "" {
q.kernelParams = append(q.kernelParams, commonVirtioblkKernelRootParams...)
q.kernelParamsNonDebug = append(q.kernelParamsNonDebug, kernelParamsSystemdNonDebug...)
q.kernelParamsDebug = append(q.kernelParamsDebug, kernelParamsSystemdDebug...)
}
return q
}
func (q *qemuS390x) bridges(number uint32) {
q.Bridges = genericBridges(number, q.machineType)
}
// appendConsole appends a console to devices.
// The function has been overwriten to correctly set the driver to the CCW device
func (q *qemuS390x) appendConsole(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
id := "serial0"
addr, b, err := q.addDeviceToBridge(id, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append console %v", err)
}
var devno string
devno, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append console %v", err)
}
serial := govmmQemu.SerialDevice{
Driver: virtioSerialCCW,
ID: id,
DisableModern: q.nestedRun,
DevNo: devno,
}
devices = append(devices, serial)
console := govmmQemu.CharDevice{
Driver: govmmQemu.Console,
Backend: govmmQemu.Socket,
DeviceID: "console0",
ID: "charconsole0",
Path: path,
}
devices = append(devices, console)
return devices, nil
}
func (q *qemuS390x) appendBlockDevice(devices []govmmQemu.Device, drive config.BlockDrive) ([]govmmQemu.Device, error) {
d, err := genericBlockDevice(drive, false)
if err != nil {
return devices, fmt.Errorf("Failed to append blk-dev %v", err)
}
addr, b, err := q.addDeviceToBridge(drive.ID, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append blk-dev %v", err)
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append blk-dev %v", err)
}
devices = append(devices, d)
return devices, nil
}
// appendVhostUserDevice throws an error if vhost devices are tried to be used.
// See issue https://github.com/kata-containers/runtime/issues/659
func (q *qemuS390x) appendVhostUserDevice(devices []govmmQemu.Device, attr config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error) {
return nil, fmt.Errorf("No vhost-user devices supported on s390x")
}
// supportGuestMemoryHotplug return false for s390x architecture. The pc-dimm backend device for s390x
// is not support. PC-DIMM is not listed in the devices supported by qemu-system-s390x -device help
func (q *qemuS390x) supportGuestMemoryHotplug() bool {
return false
}
func (q *qemuS390x) appendNetwork(devices []govmmQemu.Device, endpoint Endpoint) ([]govmmQemu.Device, error) {
d, err := genericNetwork(endpoint, false, false, q.networkIndex)
if err != nil {
return devices, fmt.Errorf("Failed to append network %v", err)
}
q.networkIndex++
addr, b, err := q.addDeviceToBridge(d.ID, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append network %v", err)
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append network %v", err)
}
devices = append(devices, d)
return devices, nil
}
func (q *qemuS390x) appendRNGDevice(devices []govmmQemu.Device, rngDev config.RNGDev) ([]govmmQemu.Device, error) {
addr, b, err := q.addDeviceToBridge(rngDev.ID, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append RNG-Device %v", err)
}
var devno string
devno, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append RNG-Device %v", err)
}
devices = append(devices,
govmmQemu.RngDevice{
ID: rngDev.ID,
Filename: rngDev.Filename,
DevNo: devno,
},
)
return devices, nil
}
func (q *qemuS390x) append9PVolume(devices []govmmQemu.Device, volume types.Volume) ([]govmmQemu.Device, error) {
if volume.MountTag == "" || volume.HostPath == "" {
return devices, nil
}
d := generic9PVolume(volume, false)
addr, b, err := q.addDeviceToBridge(d.ID, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append 9p-Volume %v", err)
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append 9p-Volume %v", err)
}
devices = append(devices, d)
return devices, nil
}
// appendBridges appends to devices the given bridges
func (q *qemuS390x) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
return genericAppendBridges(devices, q.Bridges, q.machineType)
}
func (q *qemuS390x) appendSCSIController(devices []govmmQemu.Device, enableIOThreads bool) ([]govmmQemu.Device, *govmmQemu.IOThread, error) {
d, t := genericSCSIController(enableIOThreads, q.nestedRun)
addr, b, err := q.addDeviceToBridge(d.ID, types.CCW)
if err != nil {
return devices, nil, fmt.Errorf("Failed to append scsi-controller %v", err)
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, nil, fmt.Errorf("Failed to append scsi-controller %v", err)
}
devices = append(devices, d)
return devices, t, nil
}
func (q *qemuS390x) appendVSock(devices []govmmQemu.Device, vsock types.VSock) ([]govmmQemu.Device, error) {
var devno string
id := fmt.Sprintf("vsock-%d", vsock.ContextID)
addr, b, err := q.addDeviceToBridge(id, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append VSock: %v", err)
}
devno, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append VSock: %v", err)
}
devices = append(devices,
govmmQemu.VSOCKDevice{
ID: id,
ContextID: vsock.ContextID,
VHostFD: vsock.VhostFd,
DisableModern: false,
DevNo: devno,
},
)
return devices, nil
}