github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/qemu_ppc64le.go (about)

     1  // Copyright (c) 2018 IBM
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  
     6  package virtcontainers
     7  
     8  import (
     9  	"fmt"
    10  	"time"
    11  
    12  	govmmQemu "github.com/kata-containers/govmm/qemu"
    13  	"github.com/kata-containers/runtime/virtcontainers/types"
    14  	"github.com/sirupsen/logrus"
    15  )
    16  
    17  type qemuPPC64le struct {
    18  	// inherit from qemuArchBase, overwrite methods if needed
    19  	qemuArchBase
    20  }
    21  
    22  const defaultQemuPath = "/usr/bin/qemu-system-ppc64"
    23  
    24  const defaultQemuMachineType = QemuPseries
    25  
    26  const defaultQemuMachineOptions = "accel=kvm,usb=off"
    27  
    28  const defaultMemMaxPPC64le = 32256 // Restrict MemMax to 32Gb on PPC64le
    29  
    30  const qmpMigrationWaitTimeout = 5 * time.Second
    31  
    32  var qemuPaths = map[string]string{
    33  	QemuPseries: defaultQemuPath,
    34  }
    35  
    36  var kernelParams = []Param{
    37  	{"tsc", "reliable"},
    38  	{"no_timer_check", ""},
    39  	{"rcupdate.rcu_expedited", "1"},
    40  	{"noreplace-smp", ""},
    41  	{"reboot", "k"},
    42  	{"console", "hvc0"},
    43  	{"console", "hvc1"},
    44  	{"cryptomgr.notests", ""},
    45  	{"net.ifnames", "0"},
    46  }
    47  
    48  var supportedQemuMachines = []govmmQemu.Machine{
    49  	{
    50  		Type:    QemuPseries,
    51  		Options: defaultQemuMachineOptions,
    52  	},
    53  }
    54  
    55  // Logger returns a logrus logger appropriate for logging qemu messages
    56  func (q *qemuPPC64le) Logger() *logrus.Entry {
    57  	return virtLog.WithField("subsystem", "qemu")
    58  }
    59  
    60  // MaxQemuVCPUs returns the maximum number of vCPUs supported
    61  func MaxQemuVCPUs() uint32 {
    62  	return uint32(128)
    63  }
    64  
    65  func newQemuArch(config HypervisorConfig) qemuArch {
    66  	machineType := config.HypervisorMachineType
    67  	if machineType == "" {
    68  		machineType = defaultQemuMachineType
    69  	}
    70  
    71  	qemuMachines := make([]govmmQemu.Machine, len(supportedQemuMachines))
    72  	copy(qemuMachines, supportedQemuMachines)
    73  
    74  	q := &qemuPPC64le{
    75  		qemuArchBase{
    76  			machineType:           machineType,
    77  			memoryOffset:          config.MemOffset,
    78  			qemuPaths:             qemuPaths,
    79  			supportedQemuMachines: qemuMachines,
    80  			kernelParamsNonDebug:  kernelParamsNonDebug,
    81  			kernelParamsDebug:     kernelParamsDebug,
    82  			kernelParams:          kernelParams,
    83  		},
    84  	}
    85  
    86  	q.handleImagePath(config)
    87  
    88  	q.memoryOffset = config.MemOffset
    89  
    90  	return q
    91  }
    92  
    93  func (q *qemuPPC64le) capabilities() types.Capabilities {
    94  	var caps types.Capabilities
    95  
    96  	// pseries machine type supports hotplugging drives
    97  	if q.machineType == QemuPseries {
    98  		caps.SetBlockDeviceHotplugSupport()
    99  	}
   100  
   101  	caps.SetMultiQueueSupport()
   102  	caps.SetFsSharingSupport()
   103  
   104  	return caps
   105  }
   106  
   107  func (q *qemuPPC64le) bridges(number uint32) {
   108  	q.Bridges = genericBridges(number, q.machineType)
   109  }
   110  
   111  func (q *qemuPPC64le) cpuModel() string {
   112  	cpuModel := defaultCPUModel
   113  
   114  	return cpuModel
   115  }
   116  
   117  func (q *qemuPPC64le) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory {
   118  
   119  	if (qemuMajorVersion > 2) || (qemuMajorVersion == 2 && qemuMinorVersion >= 10) {
   120  		q.Logger().Debug("Aligning maxmem to multiples of 256MB. Assumption: Kernel Version >= 4.11")
   121  		hostMemoryMb -= (hostMemoryMb % 256)
   122  	} else {
   123  		q.Logger().Debug("Restricting maxmem to 32GB as Qemu Version < 2.10, Assumption: Kernel Version >= 4.11")
   124  		hostMemoryMb = defaultMemMaxPPC64le
   125  	}
   126  
   127  	return genericMemoryTopology(memoryMb, hostMemoryMb, slots, q.memoryOffset)
   128  }
   129  
   130  // appendBridges appends to devices the given bridges
   131  func (q *qemuPPC64le) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
   132  	return genericAppendBridges(devices, q.Bridges, q.machineType)
   133  }
   134  
   135  func (q *qemuPPC64le) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
   136  	return devices, fmt.Errorf("PPC64le does not support appending a vIOMMU")
   137  }