forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 4
/
qemu_s390x.go
382 lines (327 loc) · 11.5 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
//go:build linux
// Copyright (c) 2018 IBM
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"context"
"fmt"
"time"
"github.com/kata-containers/kata-containers/src/runtime/pkg/device/config"
govmmQemu "github.com/kata-containers/kata-containers/src/runtime/pkg/govmm/qemu"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
"github.com/sirupsen/logrus"
)
type qemuS390x struct {
// inherit from qemuArchBase, overwrite methods if needed
qemuArchBase
}
const (
defaultQemuPath = "/usr/bin/qemu-system-s390x"
defaultQemuMachineType = QemuCCWVirtio
defaultQemuMachineOptions = "accel=kvm"
virtioSerialCCW = "virtio-serial-ccw"
qmpMigrationWaitTimeout = 5 * time.Second
logSubsystem = "qemuS390x"
// Secure Execution, also known as Protected Virtualization
// https://qemu.readthedocs.io/en/latest/system/s390x/protvirt.html
secExecID = "pv0"
)
// Verify needed parameters
var kernelParams = []Param{}
var ccwbridge = types.NewBridge(types.CCW, "", make(map[uint32]string, types.CCWBridgeMaxCapacity), 0)
var supportedQemuMachine = govmmQemu.Machine{
Type: QemuCCWVirtio,
Options: defaultQemuMachineOptions,
}
func newQemuArch(config HypervisorConfig) (qemuArch, error) {
machineType := config.HypervisorMachineType
if machineType == "" {
machineType = defaultQemuMachineType
}
if machineType != defaultQemuMachineType {
return nil, fmt.Errorf("unrecognised machinetype: %v", machineType)
}
q := &qemuS390x{
qemuArchBase{
qemuMachine: supportedQemuMachine,
qemuExePath: defaultQemuPath,
memoryOffset: config.MemOffset,
kernelParamsNonDebug: kernelParamsNonDebug,
kernelParamsDebug: kernelParamsDebug,
kernelParams: kernelParams,
legacySerial: false,
},
}
// Set first bridge type to CCW
q.Bridges = append(q.Bridges, ccwbridge)
if config.ConfidentialGuest {
if err := q.enableProtection(); err != nil {
return nil, err
}
if !q.qemuArchBase.disableNvdimm {
hvLogger.WithField("subsystem", "qemuS390x").Warn("Nvdimm is not supported with confidential guest, disabling it.")
q.qemuArchBase.disableNvdimm = true
}
}
if config.ImagePath != "" {
kernelParams, err := GetKernelRootParams(config.RootfsType, true, false)
if err != nil {
return nil, err
}
q.kernelParams = append(q.kernelParams, kernelParams...)
q.kernelParamsNonDebug = append(q.kernelParamsNonDebug, kernelParamsSystemdNonDebug...)
q.kernelParamsDebug = append(q.kernelParamsDebug, kernelParamsSystemdDebug...)
}
return q, nil
}
func (q *qemuS390x) bridges(number uint32) {
q.Bridges = genericBridges(number, q.qemuMachine.Type)
}
// appendConsole appends a console to devices.
// The function has been overwriten to correctly set the driver to the CCW device
func (q *qemuS390x) appendConsole(ctx context.Context, devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
id := "serial0"
addr, b, err := q.addDeviceToBridge(ctx, 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)
}
q.kernelParams = append(q.kernelParams, Param{"console", "ttysclp0"})
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) appendImage(ctx context.Context, devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
drive, err := genericImage(path)
if err != nil {
return nil, err
}
return q.appendCCWBlockDevice(ctx, devices, drive)
}
func (q *qemuS390x) appendBlockDevice(ctx context.Context, devices []govmmQemu.Device, drive config.BlockDrive) ([]govmmQemu.Device, error) {
return q.appendCCWBlockDevice(ctx, devices, drive)
}
func (q *qemuS390x) appendCCWBlockDevice(ctx context.Context, 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(ctx, 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
}
func (q *qemuS390x) appendVhostUserDevice(ctx context.Context, devices []govmmQemu.Device, attr config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error) {
if attr.Type != config.VhostUserFS {
return devices, fmt.Errorf("vhost-user device of type %s not supported on s390x, only vhost-user-fs-ccw is supported", attr.Type)
}
addr, b, err := q.addDeviceToBridge(ctx, attr.DevID, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append vhost user device: %s", err)
}
var devno string
devno, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append vhost user device: %s", err)
}
qemuVhostUserDevice := govmmQemu.VhostUserDevice{
SocketPath: attr.SocketPath,
CharDevID: utils.MakeNameID("char", attr.DevID, maxDevIDSize),
TypeDevID: utils.MakeNameID("fs", attr.DevID, maxDevIDSize),
Tag: attr.Tag,
CacheSize: attr.CacheSize,
VhostUserType: govmmQemu.VhostUserFS,
DevNo: devno,
}
devices = append(devices, qemuVhostUserDevice)
return devices, nil
}
// 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(ctx context.Context, 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(ctx, 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(ctx context.Context, devices []govmmQemu.Device, rngDev config.RNGDev) ([]govmmQemu.Device, error) {
addr, b, err := q.addDeviceToBridge(ctx, 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(ctx context.Context, 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(ctx, 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
}
func (q *qemuS390x) appendSCSIController(ctx context.Context, devices []govmmQemu.Device, enableIOThreads bool) ([]govmmQemu.Device, *govmmQemu.IOThread, error) {
d, t := genericSCSIController(enableIOThreads, q.nestedRun)
addr, b, err := q.addDeviceToBridge(ctx, 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(ctx context.Context, devices []govmmQemu.Device, vsock types.VSock) ([]govmmQemu.Device, error) {
var devno string
id := fmt.Sprintf("vsock-%d", vsock.ContextID)
addr, b, err := q.addDeviceToBridge(ctx, 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
}
func (q *qemuS390x) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
return devices, fmt.Errorf("S390x does not support appending a vIOMMU")
}
func (q *qemuS390x) addDeviceToBridge(ctx context.Context, ID string, t types.Type) (string, types.Bridge, error) {
addr, b, err := genericAddDeviceToBridge(ctx, q.Bridges, ID, types.CCW)
if err != nil {
return "", b, err
}
return fmt.Sprintf("%04x", addr), b, nil
}
// enableProtection enables guest protection for QEMU's machine option.
func (q *qemuS390x) enableProtection() error {
protection, err := availableGuestProtection()
if err != nil {
return err
}
if protection != seProtection {
return fmt.Errorf("Got unexpected protection %v, only seProtection (Secure Execution) is supported", protection)
}
q.protection = protection
if q.qemuMachine.Options != "" {
q.qemuMachine.Options += ","
}
q.qemuMachine.Options += fmt.Sprintf("confidential-guest-support=%s", secExecID)
hvLogger.WithFields(logrus.Fields{
"subsystem": logSubsystem,
"machine": q.qemuMachine}).
Info("Enabling guest protection with Secure Execution")
return nil
}
// appendProtectionDevice appends a QEMU object for Secure Execution.
// Takes devices and returns updated version. Takes BIOS and returns it (no modification on s390x).
func (q *qemuS390x) appendProtectionDevice(devices []govmmQemu.Device, firmware, firmwareVolume string) ([]govmmQemu.Device, string, error) {
switch q.protection {
case seProtection:
return append(devices,
govmmQemu.Object{
Type: govmmQemu.SecExecGuest,
ID: secExecID,
}), firmware, nil
case noneProtection:
return devices, firmware, nil
default:
return devices, firmware, fmt.Errorf("Unsupported guest protection technology: %v", q.protection)
}
}
func (q *qemuS390x) appendVFIODevice(devices []govmmQemu.Device, vfioDev config.VFIODev) []govmmQemu.Device {
if vfioDev.SysfsDev == "" {
return devices
}
if len(vfioDev.APDevices) > 0 {
devices = append(devices,
govmmQemu.VFIODevice{
SysfsDev: vfioDev.SysfsDev,
Transport: govmmQemu.TransportAP,
},
)
return devices
}
devices = append(devices,
govmmQemu.VFIODevice{
SysfsDev: vfioDev.SysfsDev,
},
)
return devices
}
// Query QMP to find a device's PCI path given its QOM path or ID
func (q *qemuS390x) qomGetPciPath(qemuID string, qmpCh *qmpChannel) (types.PciPath, error) {
hvLogger.Warnf("qomGetPciPath not implemented for s390x")
return types.PciPath{}, nil
}