From b7a1f752c0a76a546cf0483c4b573c93d860670e Mon Sep 17 00:00:00 2001 From: Jianyong Wu Date: Mon, 18 Jan 2021 16:11:09 +0800 Subject: [PATCH] arm64: enable acpi for qemu/virt. acpi is enabled for kata 1.x, port and rebase code for 2.x including: runtime: enable pflash; agent: add acpi support for pci bus path; packaging: enable CONFIG_RTC_DRV_EFI; Fixes: #1317 Signed-off-by: Jianyong Wu --- src/agent/src/linux_abi.rs | 8 +++++++ .../cli/config/configuration-qemu.toml.in | 4 ++++ src/runtime/pkg/katatestutils/utils.go | 1 + src/runtime/pkg/katautils/config.go | 24 +++++++++++++++++++ src/runtime/virtcontainers/hypervisor.go | 3 +++ src/runtime/virtcontainers/qemu.go | 7 ++++++ src/runtime/virtcontainers/qemu_arch_base.go | 15 ++++++++++++ src/runtime/virtcontainers/qemu_arm64.go | 13 ++++++++++ .../kernel/configs/fragments/arm64/acpi.conf | 1 + .../kernel/configs/fragments/arm64/base.conf | 4 ---- 10 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/agent/src/linux_abi.rs b/src/agent/src/linux_abi.rs index d801963288..c4a08376b6 100644 --- a/src/agent/src/linux_abi.rs +++ b/src/agent/src/linux_abi.rs @@ -25,10 +25,18 @@ pub fn create_pci_root_bus_path() -> String { pub fn create_pci_root_bus_path() -> String { let ret = String::from("/devices/platform/4010000000.pcie/pci0000:00"); + let acpi_root_bus_path = String::from("/devices/pci0000:00"); + let mut acpi_sysfs_dir = String::from(SYSFS_DIR); let mut sysfs_dir = String::from(SYSFS_DIR); let mut start_root_bus_path = String::from("/devices/platform/"); let end_root_bus_path = String::from("/pci0000:00"); + // check if there is pci bus path for acpi + acpi_sysfs_dir.push_str(&acpi_root_bus_path); + if let Ok(_) = fs::metadata(&acpi_sysfs_dir) { + return acpi_root_bus_path; + } + sysfs_dir.push_str(&start_root_bus_path); let entries = match fs::read_dir(sysfs_dir) { Ok(e) => e, diff --git a/src/runtime/cli/config/configuration-qemu.toml.in b/src/runtime/cli/config/configuration-qemu.toml.in index 7c2eda5f12..ecbe88cbb6 100644 --- a/src/runtime/cli/config/configuration-qemu.toml.in +++ b/src/runtime/cli/config/configuration-qemu.toml.in @@ -241,6 +241,10 @@ valid_file_mem_backends = @DEFVALIDFILEMEMBACKENDS@ # The behaviour is undefined if mem_prealloc is also set to true #enable_swap = true +# -pflash can add image file to VM. The arguments of it should be in format +# of ["/path/to/flash0.img", "/path/to/flash1.img"] +pflashes = [] + # This option changes the default hypervisor and kernel parameters # to enable debug output where available. # diff --git a/src/runtime/pkg/katatestutils/utils.go b/src/runtime/pkg/katatestutils/utils.go index e2f8b14f55..226355f98d 100644 --- a/src/runtime/pkg/katatestutils/utils.go +++ b/src/runtime/pkg/katatestutils/utils.go @@ -28,6 +28,7 @@ type RuntimeConfigOptions struct { AgentTraceType string SharedFS string VirtioFSDaemon string + PFlash []string PCIeRootPort uint32 DisableBlock bool EnableIOThreads bool diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index e542d14757..6a016495c5 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -91,6 +91,7 @@ type hypervisor struct { VirtioFSDaemonList []string `toml:"valid_virtio_fs_daemon_paths"` VirtioFSCache string `toml:"virtio_fs_cache"` VirtioFSExtraArgs []string `toml:"virtio_fs_extra_args"` + PFlashList []string `toml:"pflashes"` VirtioFSCacheSize uint32 `toml:"virtio_fs_cache_size"` BlockDeviceCacheSet bool `toml:"block_device_cache_set"` BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"` @@ -228,6 +229,23 @@ func (h hypervisor) firmware() (string, error) { return ResolvePath(p) } +func (h hypervisor) PFlash() ([]string, error) { + pflashes := h.PFlashList + + if len(pflashes) == 0 { + return []string{}, nil + } + + for _, pflash := range pflashes { + _, err := ResolvePath(pflash) + if err != nil { + return []string{}, fmt.Errorf("failed to resolve path: %s: %v", pflash, err) + } + } + + return pflashes, nil +} + func (h hypervisor) machineAccelerators() string { var machineAccelerators string for _, accelerator := range strings.Split(h.MachineAccelerators, ",") { @@ -581,6 +599,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { return vc.HypervisorConfig{}, err } + pflashes, err := h.PFlash() + if err != nil { + return vc.HypervisorConfig{}, err + } + if image != "" && initrd != "" { return vc.HypervisorConfig{}, errors.New("having both an image and an initrd defined in the configuration file is not supported") @@ -645,6 +668,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { InitrdPath: initrd, ImagePath: image, FirmwarePath: firmware, + PFlash: pflashes, MachineAccelerators: machineAccelerators, CPUFeatures: cpuFeatures, KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)), diff --git a/src/runtime/virtcontainers/hypervisor.go b/src/runtime/virtcontainers/hypervisor.go index 75834e8da7..1ed9e597dd 100644 --- a/src/runtime/virtcontainers/hypervisor.go +++ b/src/runtime/virtcontainers/hypervisor.go @@ -333,6 +333,9 @@ type HypervisorConfig struct { // FileBackedMemRootList is the list of valid root directories values for annotations FileBackedMemRootList []string + // PFlash image paths + PFlash []string + // customAssets is a map of assets. // Each value in that map takes precedence over the configured assets. // For example, if there is a value for the "kernel" key in this map, diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 66cad3bc11..1a6b0df2fc 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -262,6 +262,7 @@ func (q *qemu) setup(id string, hypervisorConfig *HypervisorConfig) error { } q.arch.setBridges(q.state.Bridges) + q.arch.setPFlash(q.config.PFlash) if create { q.Logger().Debug("Creating bridges") @@ -572,6 +573,11 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa return err } + pflash, err := q.arch.getPFlash() + if err != nil { + return err + } + qemuPath, err := q.qemuPath() if err != nil { return err @@ -595,6 +601,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa VGA: "none", GlobalParam: "kvm-pit.lost_tick_policy=discard", Bios: firmwarePath, + PFlash: pflash, PidFile: filepath.Join(q.store.RunVMStoragePath(), q.id, "pid"), } diff --git a/src/runtime/virtcontainers/qemu_arch_base.go b/src/runtime/virtcontainers/qemu_arch_base.go index b3580562f6..2c4b8efed9 100644 --- a/src/runtime/virtcontainers/qemu_arch_base.go +++ b/src/runtime/virtcontainers/qemu_arch_base.go @@ -119,6 +119,12 @@ type qemuArch interface { // addBridge adds a new Bridge to the list of Bridges addBridge(types.Bridge) + // getPFlash() get pflash from configuration + getPFlash() ([]string, error) + + // setPFlash() grants access to pflash + setPFlash([]string) + // handleImagePath handles the Hypervisor Config image path handleImagePath(config HypervisorConfig) @@ -151,6 +157,7 @@ type qemuArchBase struct { kernelParamsDebug []Param kernelParams []Param Bridges []types.Bridge + PFlash []string } const ( @@ -798,3 +805,11 @@ func (q *qemuArchBase) appendPVPanicDevice(devices []govmmQemu.Device) ([]govmmQ devices = append(devices, govmmQemu.PVPanicDevice{NoShutdown: true}) return devices, nil } + +func (q *qemuArchBase) getPFlash() ([]string, error) { + return q.PFlash, nil +} + +func (q *qemuArchBase) setPFlash(p []string) { + q.PFlash = p +} diff --git a/src/runtime/virtcontainers/qemu_arm64.go b/src/runtime/virtcontainers/qemu_arm64.go index 14fdc4627e..f837bdeee6 100644 --- a/src/runtime/virtcontainers/qemu_arm64.go +++ b/src/runtime/virtcontainers/qemu_arm64.go @@ -119,3 +119,16 @@ func (q *qemuArm64) append9PVolume(devices []govmmQemu.Device, volume types.Volu devices = append(devices, d) return devices, nil } + +func (q *qemuArm64) getPFlash() ([]string, error) { + length := len(q.PFlash) + if length == 0 { + return nil, nil + } else if length == 1 { + return nil, fmt.Errorf("two pflash images needed for arm64") + } else if length == 2 { + return q.PFlash, nil + } else { + return nil, fmt.Errorf("too many pflash images for arm64") + } +} diff --git a/tools/packaging/kernel/configs/fragments/arm64/acpi.conf b/tools/packaging/kernel/configs/fragments/arm64/acpi.conf index 2f89803897..4ad8634450 100644 --- a/tools/packaging/kernel/configs/fragments/arm64/acpi.conf +++ b/tools/packaging/kernel/configs/fragments/arm64/acpi.conf @@ -3,3 +3,4 @@ CONFIG_EFI=y CONFIG_EFI_STUB=y # ARM64 can run properly in ACPI hardware reduced mode. CONFIG_ACPI_REDUCED_HARDWARE_ONLY=y +CONFIG_RTC_DRV_EFI=y diff --git a/tools/packaging/kernel/configs/fragments/arm64/base.conf b/tools/packaging/kernel/configs/fragments/arm64/base.conf index dfe51e29a7..f7c572cf2a 100644 --- a/tools/packaging/kernel/configs/fragments/arm64/base.conf +++ b/tools/packaging/kernel/configs/fragments/arm64/base.conf @@ -24,10 +24,6 @@ CONFIG_PERF_EVENTS=y CONFIG_ARM64_PSEUDO_NMI=y CONFIG_ARM64_SVE=y -# Arm64 prefers to use REFCOUNT_FULL by default, disable it as the -# latest kernel has discarded it, add it to whitelist. -CONFIG_REFCOUNT_FULL=y - # # ARMv8.1 architectural features #