forked from kata-containers/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
virtcontainers: Get qemu suppport for ppc64le
Fixes kata-containers#302 Signed-off-by: Nitesh Konkar [email protected]
- Loading branch information
Showing
4 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright (c) 2018 IBM | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package virtcontainers | ||
|
||
import ( | ||
"encoding/hex" | ||
"os" | ||
|
||
govmmQemu "github.com/intel/govmm/qemu" | ||
"github.com/kata-containers/runtime/virtcontainers/device/drivers" | ||
"github.com/kata-containers/runtime/virtcontainers/utils" | ||
) | ||
|
||
type qemuPPC64le struct { | ||
// inherit from qemuArchBase, overwrite methods if needed | ||
qemuArchBase | ||
} | ||
|
||
const defaultQemuPath = "/usr/bin/qemu-system-ppc64le" | ||
|
||
const defaultQemuMachineType = QemuPseries | ||
|
||
const defaultQemuMachineOptions = "accel=kvm,usb=off" | ||
|
||
const defaultPCBridgeBus = "pci.0" | ||
|
||
var qemuPaths = map[string]string{ | ||
QemuPseries: defaultQemuPath, | ||
} | ||
|
||
var kernelRootParams = []Param{} | ||
|
||
var kernelParams = []Param{ | ||
{"tsc", "reliable"}, | ||
{"no_timer_check", ""}, | ||
{"rcupdate.rcu_expedited", "1"}, | ||
{"noreplace-smp", ""}, | ||
{"reboot", "k"}, | ||
{"console", "hvc0"}, | ||
{"console", "hvc1"}, | ||
{"iommu", "off"}, | ||
{"cryptomgr.notests", ""}, | ||
{"net.ifnames", "0"}, | ||
{"pci", "lastbus=0"}, | ||
} | ||
|
||
var supportedQemuMachines = []govmmQemu.Machine{ | ||
{ | ||
Type: QemuPseries, | ||
Options: defaultQemuMachineOptions, | ||
}, | ||
} | ||
|
||
// returns the maximum number of vCPUs supported | ||
func MaxQemuVCPUs() uint32 { | ||
return uint32(128) | ||
} | ||
|
||
func newQemuArch(config HypervisorConfig) qemuArch { | ||
machineType := config.HypervisorMachineType | ||
if machineType == "" { | ||
machineType = defaultQemuMachineType | ||
} | ||
|
||
q := &qemuPPC64le{ | ||
qemuArchBase{ | ||
machineType: machineType, | ||
qemuPaths: qemuPaths, | ||
supportedQemuMachines: supportedQemuMachines, | ||
kernelParamsNonDebug: kernelParamsNonDebug, | ||
kernelParamsDebug: kernelParamsDebug, | ||
kernelParams: kernelParams, | ||
}, | ||
} | ||
|
||
q.handleImagePath(config) | ||
return q | ||
} | ||
|
||
func (q *qemuPPC64le) capabilities() capabilities { | ||
var caps capabilities | ||
|
||
// pseries machine type supports hotplugging drives | ||
if q.machineType == QemuPseries { | ||
caps.setBlockDeviceHotplugSupport() | ||
} | ||
|
||
return caps | ||
} | ||
|
||
func (q *qemuPPC64le) bridges(number uint32) []Bridge { | ||
return genericBridges(number, q.machineType) | ||
} | ||
|
||
func (q *qemuPPC64le) cpuModel() string { | ||
cpuModel := defaultCPUModel | ||
if q.nestedRun { | ||
cpuModel += ",pmu=off" | ||
} | ||
return cpuModel | ||
} | ||
|
||
func (q *qemuPPC64le) memoryTopology(memoryMb, hostMemoryMb uint64) govmmQemu.Memory { | ||
|
||
// align hostMemoryMb to 256 MB multiples | ||
hostMemoryMb -= (hostMemoryMb % 256) | ||
return genericMemoryTopology(memoryMb, hostMemoryMb) | ||
} | ||
|
||
func (q *qemuPPC64le) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) { | ||
if _, err := os.Stat(path); os.IsNotExist(err) { | ||
return nil, err | ||
} | ||
|
||
randBytes, err := utils.GenerateRandomBytes(8) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
id := utils.MakeNameID("image", hex.EncodeToString(randBytes), maxDevIDSize) | ||
|
||
drive := drivers.Drive{ | ||
File: path, | ||
Format: "raw", | ||
ID: id, | ||
} | ||
|
||
return q.appendBlockDevice(devices, drive), nil | ||
} | ||
|
||
// appendBridges appends to devices the given bridges | ||
func (q *qemuPPC64le) appendBridges(devices []govmmQemu.Device, bridges []Bridge) []govmmQemu.Device { | ||
return genericAppendBridges(devices, bridges, q.machineType) | ||
} |