Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 664f1b2

Browse files
committed
ACPI: enable acpi for arm64 on qemu
ACPI is dumb on arm64 when using qemu as VMM since no EFI firmware avaliable. "-pflash" is enabled here. For arm64, EFI firmware can be stored in these flash image and let ACPI be avaliable. Fixes: #3078 Signed-off-by: Jianyong Wu <[email protected]>
1 parent cafd967 commit 664f1b2

File tree

7 files changed

+67
-0
lines changed

7 files changed

+67
-0
lines changed

cli/config/configuration-qemu.toml.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ valid_file_mem_backends = @DEFVALIDFILEMEMBACKENDS@
365365
# Default /var/run/kata-containers/cache.sock
366366
#vm_cache_endpoint = "/var/run/kata-containers/cache.sock"
367367

368+
# -pflash can add image file to VM. The arguments of it should be in format
369+
# of ["/path/to/flash0.img", "/path/to/flash1.img"]
370+
#pflashes = []
371+
368372
[proxy.@PROJECT_TYPE@]
369373
path = "@PROXYPATH@"
370374

pkg/katatestutils/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type RuntimeConfigOptions struct {
2929
AgentTraceType string
3030
SharedFS string
3131
VirtioFSDaemon string
32+
PFlash []string
3233
PCIeRootPort uint32
3334
DisableBlock bool
3435
EnableIOThreads bool

pkg/katautils/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type hypervisor struct {
106106
VirtioFSDaemonList []string `toml:"valid_virtio_fs_daemon_paths"`
107107
VirtioFSCache string `toml:"virtio_fs_cache"`
108108
VirtioFSExtraArgs []string `toml:"virtio_fs_extra_args"`
109+
PFlashList []string `toml:"pflashes"`
109110
VirtioFSCacheSize uint32 `toml:"virtio_fs_cache_size"`
110111
BlockDeviceCacheSet bool `toml:"block_device_cache_set"`
111112
BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"`
@@ -250,6 +251,23 @@ func (h hypervisor) firmware() (string, error) {
250251
return ResolvePath(p)
251252
}
252253

254+
func (h hypervisor) PFlash() ([]string, error) {
255+
pflashes := h.PFlashList
256+
257+
if len(pflashes) == 0 {
258+
return []string(nil), nil
259+
}
260+
261+
for _, pflash := range pflashes {
262+
_, err := ResolvePath(pflash)
263+
if err != nil {
264+
return []string{}, fmt.Errorf("pflash path doesn't exist: %s", pflash)
265+
}
266+
}
267+
268+
return pflashes, nil
269+
}
270+
253271
func (h hypervisor) machineAccelerators() string {
254272
var machineAccelerators string
255273
for _, accelerator := range strings.Split(h.MachineAccelerators, ",") {
@@ -626,6 +644,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
626644
return vc.HypervisorConfig{}, err
627645
}
628646

647+
pflashes, err := h.PFlash()
648+
if err != nil {
649+
return vc.HypervisorConfig{}, err
650+
}
651+
629652
machineAccelerators := h.machineAccelerators()
630653
cpuFeatures := h.cpuFeatures()
631654
kernelParams := h.kernelParams()
@@ -690,6 +713,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
690713
VirtioFSCacheSize: h.VirtioFSCacheSize,
691714
VirtioFSCache: h.defaultVirtioFSCache(),
692715
VirtioFSExtraArgs: h.VirtioFSExtraArgs,
716+
PFlash: pflashes,
693717
MemPrealloc: h.MemPrealloc,
694718
HugePages: h.HugePages,
695719
IOMMU: h.IOMMU,

virtcontainers/hypervisor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ type HypervisorConfig struct {
333333
// File based memory backend root directory
334334
FileBackedMemRootDir string
335335

336+
// PFlash image paths
337+
PFlash []string
338+
336339
// FileBackedMemRootList is the list of valid root directories values for annotations
337340
FileBackedMemRootList []string
338341

virtcontainers/qemu.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func (q *qemu) setup(id string, hypervisorConfig *HypervisorConfig) error {
261261
}
262262

263263
q.arch.setBridges(q.state.Bridges)
264+
q.arch.setPFlash(q.config.PFlash)
264265

265266
if create {
266267
q.Logger().Debug("Creating bridges")
@@ -570,6 +571,11 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa
570571
return err
571572
}
572573

574+
pflash, err := q.arch.getPFlash()
575+
if err != nil {
576+
return err
577+
}
578+
573579
qemuPath, err := q.qemuPath()
574580
if err != nil {
575581
return err
@@ -593,6 +599,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa
593599
VGA: "none",
594600
GlobalParam: "kvm-pit.lost_tick_policy=discard",
595601
Bios: firmwarePath,
602+
PFlash: pflash,
596603
PidFile: filepath.Join(q.store.RunVMStoragePath(), q.id, "pid"),
597604
}
598605

virtcontainers/qemu_arch_base.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ type qemuArch interface {
119119
// addBridge adds a new Bridge to the list of Bridges
120120
addBridge(types.Bridge)
121121

122+
// getPFlash() get pflash from configuration
123+
getPFlash() ([]string, error)
124+
125+
// setPFlash() grants access to pflash
126+
setPFlash([]string)
127+
122128
// handleImagePath handles the Hypervisor Config image path
123129
handleImagePath(config HypervisorConfig)
124130

@@ -149,6 +155,7 @@ type qemuArchBase struct {
149155
kernelParamsDebug []Param
150156
kernelParams []Param
151157
Bridges []types.Bridge
158+
PFlash []string
152159
}
153160

154161
const (
@@ -800,3 +807,11 @@ func (q *qemuArchBase) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Devi
800807
return devices, fmt.Errorf("Machine Type %s does not support vIOMMU", q.machineType)
801808
}
802809
}
810+
811+
func (q *qemuArchBase) getPFlash() ([]string, error) {
812+
return q.PFlash, nil
813+
}
814+
815+
func (q *qemuArchBase) setPFlash(p []string) {
816+
q.PFlash = p
817+
}

virtcontainers/qemu_arm64.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,16 @@ func (q *qemuArm64) append9PVolume(devices []govmmQemu.Device, volume types.Volu
122122
devices = append(devices, d)
123123
return devices, nil
124124
}
125+
126+
func (q *qemuArm64) getPFlash() ([]string, error) {
127+
length := len(q.PFlash)
128+
if length == 0 {
129+
return nil, nil
130+
} else if length == 1 {
131+
return nil, fmt.Errorf("two pflash images needed for arm64")
132+
} else if length == 2 {
133+
return q.PFlash, nil
134+
} else {
135+
return nil, fmt.Errorf("too many pflash images for arm64")
136+
}
137+
}

0 commit comments

Comments
 (0)