Compare commits

..

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
ee47ebf809
!156 [sync] PR-153: riscv64: fix typo in spec file
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2025-01-23 07:50:17 +00:00
laokz
80ebaa6c97 riscv64: fix typo in spec file
(cherry picked from commit f4c3e0fdd3eed753978fb2697986c2f52fee42dc)
2025-01-13 16:38:36 +08:00
openeuler-ci-bot
9c3a8fcce1
!155 [sync] PR-150: Fix missing kernel configuration for RISC-V
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2025-01-06 11:33:32 +00:00
Ruoqing He
4836e03404 Fix missing kernel configuration for RISC-V
Previous configuration path is missing in building environment, replace
`/boot/config*` with `arch/riscv/config/openeuler_defconfig` since the
kernel source code will be present while building.

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
(cherry picked from commit 31dc280a84164c3f23b1d05502879e5f17b56a3f)
2024-12-31 09:40:03 +08:00
openeuler-ci-bot
0a5c6708a2
!141 [sync] PR-140: Add support for Go runtime on riscv64 platform
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2024-11-19 03:51:07 +00:00
Ruoqing He
ba7c85d417 Add support for riscv64 platform
Add patch to support Go runtime on riscv64 platform.

Signed-off-by: Ruoqing He <ruoqing@isrc.iscas.ac.cn>
(cherry picked from commit a37b75757527098881fb5db9ac3e9d0df127f0a6)
2024-06-21 13:26:43 +08:00
openeuler-ci-bot
d625ea46c6
!139 [sync] PR-134: Allow swappiness to be -1 as default
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2024-05-08 06:13:39 +00:00
xuxuepeng
4b7725203b Allow swappiness to be -1 as default
Signed-off-by: xuxuepeng <xuxuepeng1@huawei.com>
(cherry picked from commit ccfbf74810da05bfe42352343bc5125845bb8901)
2024-05-08 11:13:36 +08:00
openeuler-ci-bot
a6449fe8c6
!138 [sync] PR-136: spec: Fix the spec for configuration-stratovirt toml file install
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2024-05-08 03:12:23 +00:00
Liu Wenyuan
129de0c0be spec: Fix the spec for configuration-stratovirt toml file
The lack of configuration-stratovirt.toml in %file would
cause the failure of toml install.

Signed-off-by: Liu Wenyuan <liuwenyuan9@huawei.com>
(cherry picked from commit d5d3427d8dcaa4fc4de58418deddbb5e647ec95c)
2024-05-08 09:42:33 +08:00
4 changed files with 405 additions and 3 deletions

View File

@ -2,7 +2,7 @@
%global debug_package %{nil}
%define VERSION 3.2.0
%define RELEASE 2
%define RELEASE 6
Name: kata-containers
Version: %{VERSION}
@ -17,6 +17,9 @@ Source2: kernel.tar.gz
BuildRoot: %_topdir/BUILDROOT
BuildRequires: automake golang gcc bc glibc-devel glibc-static busybox glib2-devel glib2 ipvsadm conntrack-tools nfs-utils
BuildRequires: patch elfutils-libelf-devel openssl-devel bison flex rust cargo rust-packaging libgcc dtc-devel
%ifarch riscv64
BuildRequires: protobuf-compiler dwarves
%endif
%description
This is core component of Kata Container, to make it work, you need a isulad/docker engine.
@ -37,6 +40,8 @@ mv kernel linux
cd %{_builddir}/kernel/linux/
%ifarch %{ix86} x86_64
cp %{_builddir}/kata_integration/hack/config-kata-x86_64 ./.config
%elifarch riscv64
cp arch/riscv/configs/openeuler_defconfig ./.config
%else
cp %{_builddir}/kata_integration/hack/config-kata-arm64 ./.config
%endif
@ -76,6 +81,8 @@ make initrd
mkdir -p -m 755 %{buildroot}/var/lib/kata
%ifarch %{ix86} x86_64
install -p -m 755 -D %{_builddir}/kernel/linux/arch/x86_64/boot/bzImage %{buildroot}/var/lib/kata/kernel
%elifarch riscv64
install -p -m 755 -D %{_builddir}/kernel/linux/arch/riscv/boot/Image %{buildroot}/var/lib/kata/kernel
%else
install -p -m 755 -D %{_builddir}/kernel/linux/arch/arm64/boot/Image %{buildroot}/var/lib/kata/kernel
%endif
@ -86,7 +93,9 @@ install -p -m 750 %{_builddir}/kata-containers/src/runtime/kata-runtime %{buildr
install -p -m 750 %{_builddir}/kata-containers/src/runtime/kata-monitor %{buildroot}/usr/bin/
install -p -m 750 %{_builddir}/kata-containers/src/runtime/containerd-shim-kata-v2 %{buildroot}/usr/bin/
install -p -m 640 -D %{_builddir}/kata-containers/src/runtime/config/configuration-qemu.toml %{buildroot}/usr/share/defaults/kata-containers/configuration.toml
%ifnarch riscv64
install -p -m 640 -D %{_builddir}/kata-containers/src/runtime/config/configuration-stratovirt.toml %{buildroot}/usr/share/defaults/kata-containers/configuration-stratovirt.toml
%endif
install -p -m 640 ./build/kata-containers-initrd.img %{buildroot}/var/lib/kata/
mkdir -p -m 750 %{buildroot}/usr/share/defaults/kata-containers/
strip %{buildroot}/usr/bin/kata*
@ -101,23 +110,50 @@ strip %{buildroot}/usr/bin/containerd-shim-kata-v2
/var/lib/kata/kernel
/var/lib/kata/kata-containers-initrd.img
%config(noreplace) /usr/share/defaults/kata-containers/configuration.toml
%ifnarch riscv64
%config(noreplace) /usr/share/defaults/kata-containers/configuration-stratovirt.toml
%endif
%doc
%changelog
* Fri Dec 27 2024 laokz <zhangkai@iscas.ac.cn> - 3.2.0-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:riscv64: fix typo
* Wed Nov 27 2024 heruoqing <heruoqing@iscas.ac.cn> - 3.2.0-5
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix missing kernel config for RISC-V when building
* Wed May 8 2024 heruoqing <ruoqing@isrc.iscas.ac.cn> - 3.2.0-4
- Type:feature
- ID:NA
- SUG:NA
- DESC:add riscv64 platform support for kata 3.2.0
* Tue May 7 2024 xuxuepeng <xuxuepeng1@huawei.com> - 3.2.0-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:allow swappiness to be -1 as default
* Tue May 7 2024 wenyuanlau <liuwenyuan9@huawei.com> - 3.2.0-2
- Type:feature
- ID:NA
- SUG:NA
- DESC:add stratovirt microvm support for kata 3.2.0
* Tue Feb 2024 Vanient <xidanni1@huawei.com> - 3.2.0-1
* Tue Feb 19 2024 Vanient <xidanni1@huawei.com> - 3.2.0-1
- Type:feature
- ID:NA
- SUG:NA
- DESC:update to 3.2.0
* Tue Sep 2023 xiadanni <xiadanni1@huawei.com> - 2.1.0-33
* Tue Sep 5 2023 xiadanni <xiadanni1@huawei.com> - 2.1.0-33
- Type:bugfix
- ID:NA
- SUG:NA

View File

@ -0,0 +1,26 @@
From 5a85bf2eb90ce9403f3f11e04ae3d5ba35db322a Mon Sep 17 00:00:00 2001
From: xuxuepeng <xuxuepeng1@huawei.com>
Date: Mon, 29 Apr 2024 05:44:44 +0800
Subject: [PATCH] Allow swappiness to be -1 as default
Signed-off-by: xuxuepeng <xuxuepeng1@huawei.com>
---
src/agent/rustjail/src/cgroups/fs/mod.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/agent/rustjail/src/cgroups/fs/mod.rs b/src/agent/rustjail/src/cgroups/fs/mod.rs
index 6145f5f..c49d041 100644
--- a/src/agent/rustjail/src/cgroups/fs/mod.rs
+++ b/src/agent/rustjail/src/cgroups/fs/mod.rs
@@ -475,7 +475,7 @@ fn set_memory_resources(cg: &cgroups::Cgroup, memory: &LinuxMemory, update: bool
if let Some(swappiness) = memory.swappiness {
if (0..=100).contains(&swappiness) {
mem_controller.set_swappiness(swappiness)?;
- } else {
+ } else if swappiness != (-1i64 as u64){
return Err(anyhow!(
"invalid value:{}. valid memory swappiness range is 0-100",
swappiness
--
2.33.0

View File

@ -0,0 +1,338 @@
From 52f4da0246fa1dd170bb45f0216c2cff15968f24 Mon Sep 17 00:00:00 2001
From: Ruoqing He <ruoqing@isrc.iscas.ac.cn>
Date: Mon, 29 Apr 2024 16:20:35 +0800
Subject: [PATCH] Add support for riscv64 platform
Signed-off-by: Ruoqing He <ruoqing@isrc.iscas.ac.cn>
---
src/agent/src/linux_abi.rs | 3 +-
src/runtime/Makefile | 3 +
src/runtime/arch/riscv64-options.mk | 13 ++
.../cmd/kata-runtime/kata-check_riscv64.go | 130 ++++++++++++++++++
src/runtime/pkg/govmm/vmm_riscv64.go | 12 ++
.../factory/template/template_riscv64.go | 14 ++
.../virtcontainers/hypervisor_riscv64.go | 11 ++
src/runtime/virtcontainers/qemu_riscv64.go | 68 +++++++++
8 files changed, 253 insertions(+), 1 deletion(-)
create mode 100644 src/runtime/arch/riscv64-options.mk
create mode 100644 src/runtime/cmd/kata-runtime/kata-check_riscv64.go
create mode 100644 src/runtime/pkg/govmm/vmm_riscv64.go
create mode 100644 src/runtime/virtcontainers/factory/template/template_riscv64.go
create mode 100644 src/runtime/virtcontainers/hypervisor_riscv64.go
create mode 100644 src/runtime/virtcontainers/qemu_riscv64.go
diff --git a/src/agent/src/linux_abi.rs b/src/agent/src/linux_abi.rs
index b87da3c..fdb70be 100644
--- a/src/agent/src/linux_abi.rs
+++ b/src/agent/src/linux_abi.rs
@@ -15,7 +15,8 @@ pub const SYSFS_DIR: &str = "/sys";
target_arch = "powerpc64",
target_arch = "s390x",
target_arch = "x86_64",
- target_arch = "x86"
+ target_arch = "x86",
+ target_arch = "riscv64"
))]
pub fn create_pci_root_bus_path() -> String {
String::from("/devices/pci0000:00")
diff --git a/src/runtime/Makefile b/src/runtime/Makefile
index 33fa8f2..977dbfc 100644
--- a/src/runtime/Makefile
+++ b/src/runtime/Makefile
@@ -22,6 +22,9 @@ endif
ifeq ($(ARCH),aarch64)
override ARCH = arm64
endif
+ifeq ($(ARCH),riscv64)
+ override ARCH = riscv64
+endif
ARCH_DIR = arch
ARCH_FILE_SUFFIX = -options.mk
diff --git a/src/runtime/arch/riscv64-options.mk b/src/runtime/arch/riscv64-options.mk
new file mode 100644
index 0000000..91eef18
--- /dev/null
+++ b/src/runtime/arch/riscv64-options.mk
@@ -0,0 +1,13 @@
+# Copyright (c) 2023 Xin Liu
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+# riscv64 settings
+
+MACHINETYPE := virt
+KERNELPARAMS :=
+MACHINEACCELERATORS :=
+CPUFEATURES :=
+
+QEMUCMD := qemu-system-riscv64
diff --git a/src/runtime/cmd/kata-runtime/kata-check_riscv64.go b/src/runtime/cmd/kata-runtime/kata-check_riscv64.go
new file mode 100644
index 0000000..a16f869
--- /dev/null
+++ b/src/runtime/cmd/kata-runtime/kata-check_riscv64.go
@@ -0,0 +1,130 @@
+// Copyright (c) 2018 Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+
+package main
+
+import (
+ "fmt"
+ "strings"
+
+ vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
+ "github.com/sirupsen/logrus"
+)
+
+const (
+ cpuFlagsTag = genericCPUFlagsTag
+ archCPUVendorField = "uarch"
+ archCPUModelField = "isa"
+)
+
+// archRequiredCPUFlags maps a CPU flag value to search for and a
+// human-readable description of that value.
+var archRequiredCPUFlags = map[string]string{}
+
+// archRequiredCPUAttribs maps a CPU (non-CPU flag) attribute value to search for
+// and a human-readable description of that value.
+var archRequiredCPUAttribs = map[string]string{}
+
+// archRequiredKernelModules maps a required module name to a human-readable
+// description of the modules functionality and an optional list of
+// required module parameters.
+var archRequiredKernelModules = map[string]kernelModule{
+ "kvm": {
+ desc: "Kernel-based Virtual Machine",
+ required: true,
+ },
+ "vhost_vsock": {
+ desc: "Host Support for Linux VM Sockets",
+ required: false,
+ },
+}
+
+func setCPUtype(hypervisorType vc.HypervisorType) error {
+ return nil
+}
+
+// kvmIsUsable determines if it will be possible to create a full virtual machine
+// by creating a minimal VM and then deleting it.
+func kvmIsUsable() error {
+ return genericKvmIsUsable()
+}
+
+func archHostCanCreateVMContainer(hypervisorType vc.HypervisorType) error {
+ return kvmIsUsable()
+}
+
+// hostIsVMContainerCapable checks to see if the host is theoretically capable
+// of creating a VM container.
+func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
+
+ _, err := getCPUInfo(details.cpuInfoFile)
+ if err != nil {
+ return err
+ }
+
+ count, err := checkKernelModules(details.requiredKernelModules, archKernelParamHandler)
+ if err != nil {
+ return err
+ }
+
+ if count == 0 {
+ return nil
+ }
+
+ return fmt.Errorf("ERROR: %s", failMessage)
+
+}
+
+func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
+ return genericArchKernelParamHandler(onVMM, fields, msg)
+}
+
+func getRiscv64CPUDetails() (vendor, model string, err error) {
+ prefixModel := "processor"
+ cpuinfo, err := getCPUInfo(procCPUInfo)
+ if err != nil {
+ return "", "", err
+ }
+
+ lines := strings.Split(cpuinfo, "\n")
+
+ for _, line := range lines {
+ if archCPUVendorField != "" {
+ if strings.HasPrefix(line, archCPUVendorField) {
+ fields := strings.Split(line, ":")
+ if len(fields) > 1 {
+ vendor = strings.TrimSpace(fields[1])
+ }
+ }
+ } else {
+ vendor = "Unknown"
+ }
+ if archCPUModelField != "" {
+ if strings.HasPrefix(line, prefixModel) {
+ fields := strings.Split(line, ":")
+ if len(fields) > 1 {
+ model = strings.TrimSpace(fields[1])
+ }
+ }
+ }
+ }
+
+ if vendor == "" {
+ return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
+ }
+
+ if model == "" {
+ return "", "", fmt.Errorf("Error in parsing cpu model from %v", procCPUInfo)
+ }
+
+ return vendor, model, nil
+}
+
+func getCPUDetails() (string, string, error) {
+ if vendor, model, err := genericGetCPUDetails(); err == nil {
+ return vendor, model, nil
+ }
+ return getRiscv64CPUDetails()
+}
diff --git a/src/runtime/pkg/govmm/vmm_riscv64.go b/src/runtime/pkg/govmm/vmm_riscv64.go
new file mode 100644
index 0000000..5ea2e94
--- /dev/null
+++ b/src/runtime/pkg/govmm/vmm_riscv64.go
@@ -0,0 +1,12 @@
+//
+// Copyright (c) 2018 Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+
+package govmm
+
+// MaxVCPUs returns the maximum number of vCPUs supported
+func MaxVCPUs() uint32 {
+ return uint32(512)
+}
diff --git a/src/runtime/virtcontainers/factory/template/template_riscv64.go b/src/runtime/virtcontainers/factory/template/template_riscv64.go
new file mode 100644
index 0000000..abb639b
--- /dev/null
+++ b/src/runtime/virtcontainers/factory/template/template_riscv64.go
@@ -0,0 +1,14 @@
+// Copyright (c) 2023 Xin Liu
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+// template implements base vm factory with vm templating.
+
+package template
+
+// templateDeviceStateSize denotes device state size when
+// mount tmpfs.
+// when bypass-shared-memory is not support like arm64,
+// creating template will occupy more space. That's why we
+// put it here.
+const templateDeviceStateSize = 8
diff --git a/src/runtime/virtcontainers/hypervisor_riscv64.go b/src/runtime/virtcontainers/hypervisor_riscv64.go
new file mode 100644
index 0000000..78d128f
--- /dev/null
+++ b/src/runtime/virtcontainers/hypervisor_riscv64.go
@@ -0,0 +1,11 @@
+// Copyright (c) 2021 Arm Ltd.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package virtcontainers
+
+// Guest protection is not supported on RISCV64.
+func availableGuestProtection() (guestProtection, error) {
+ return noneProtection, nil
+}
+
diff --git a/src/runtime/virtcontainers/qemu_riscv64.go b/src/runtime/virtcontainers/qemu_riscv64.go
new file mode 100644
index 0000000..846a5f2
--- /dev/null
+++ b/src/runtime/virtcontainers/qemu_riscv64.go
@@ -0,0 +1,68 @@
+// Copyright (c) 2023 Xin Liu
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+
+package virtcontainers
+
+import (
+ "fmt"
+ "time"
+
+ govmmQemu "github.com/kata-containers/kata-containers/src/runtime/pkg/govmm/qemu"
+)
+
+type qemuRiscv64 struct {
+ // inherit from qemuArchBase, overwrite methods if needed
+ qemuArchBase
+}
+
+const defaultQemuPath = "/usr/bin/qemu-system-riscv64"
+
+const defaultQemuMachineType = QemuVirt
+
+const qmpMigrationWaitTimeout = 10 * time.Second
+
+const defaultQemuMachineOptions = ""
+
+var defaultGICVersion = uint32(3)
+
+var kernelParams = []Param{
+ {"numa", "off"},
+}
+
+var supportedQemuMachine = govmmQemu.Machine{
+ Type: QemuVirt,
+ Options: defaultQemuMachineOptions,
+}
+
+// MaxQemuVCPUs returns the maximum number of vCPUs supported
+func MaxQemuVCPUs() uint32 {
+ return uint32(512)
+}
+
+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 := &qemuRiscv64{
+ qemuArchBase{
+ qemuMachine: supportedQemuMachine,
+ qemuExePath: defaultQemuPath,
+ memoryOffset: config.MemOffset,
+ kernelParamsNonDebug: kernelParamsNonDebug,
+ kernelParamsDebug: kernelParamsDebug,
+ kernelParams: kernelParams,
+ },
+ }
+
+ q.handleImagePath(config)
+
+ return q, nil
+}
--
2.43.0

View File

@ -3,3 +3,5 @@
0003-configuration-add-configuration-for-StratoVirt-hyper.patch
0004-kata-deploy-Add-StratoVirt-support-to-deploy-process.patch
0005-mount-Reduce-the-mount-points-with-namespace-isolati.patch
0006-Allow-swappiness-to-be-1-as-default.patch
0007-Add-support-for-riscv64-platform.patch