mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-30 23:37:45 +00:00
Merge pull request #938 from Jimmy-Xu/kernel-support-gpu
add kernel config for gpu
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Build Kata Containers Kernel
|
||||
|
||||
* [Requirements](#requirements)
|
||||
* [Usage](#usage)
|
||||
* [Setup kernel source code](#setup-kernel-source-code)
|
||||
* [Build the kernel](#build-the-kernel)
|
||||
* [Install the Kernel in the default path for Kata](#install-the-kernel-in-the-default-path-for-kata)
|
||||
@@ -17,6 +18,54 @@ automates the process to build a kernel for Kata Containers.
|
||||
The `build-kernel.sh` script requires an installed Golang version matching the
|
||||
[component build requirements](https://github.com/kata-containers/documentation/blob/master/Developer-Guide.md#requirements-to-build-individual-components).
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
$ ./build-kernel.sh -h
|
||||
Overview:
|
||||
|
||||
Build a kernel for Kata Containers
|
||||
|
||||
Description: This script is the *ONLY* to build a kernel for development.
|
||||
|
||||
|
||||
Usage:
|
||||
|
||||
build-kernel.sh [options] <command> <argument>
|
||||
|
||||
Commands:
|
||||
|
||||
- setup
|
||||
|
||||
- build
|
||||
|
||||
- install
|
||||
|
||||
Options:
|
||||
|
||||
-c <path> : Path to config file to build a the kernel.
|
||||
-d : Enable bash debug.
|
||||
-e : Enable experimental kernel.
|
||||
-f : Enable force generate config when setup.
|
||||
-g <vendor> : GPU vendor, intel or nvidia.
|
||||
-h : Display this help.
|
||||
-k <path> : Path to kernel to build.
|
||||
-p <path> : Path to a directory with patches to apply to kernel.
|
||||
-t : Hypervisor_target.
|
||||
-v : Kernel version to use if kernel path not provided.
|
||||
```
|
||||
|
||||
Example:
|
||||
```
|
||||
$ ./build-kernel.sh -v 4.19.86 -g nvidia -f -d setup
|
||||
```
|
||||
> **Note**
|
||||
> - `-v 4.19.86`: Specify the guest kernel version.
|
||||
> - `-g nvidia`: To build a guest kernel supporting Nvidia GPU.
|
||||
> - `-f`: The .config file is forced to be generated even if the kernel directory already exists.
|
||||
> - `-d`: Enable bash debug mode.
|
||||
|
||||
|
||||
## Setup kernel source code
|
||||
|
||||
```bash
|
||||
|
@@ -39,10 +39,18 @@ readonly default_kernel_config_dir="${GOPATH}/src/${kernel_config_repo}/kernel/c
|
||||
# Default path to search for kernel config fragments
|
||||
readonly default_config_frags_dir="${GOPATH}/src/${kernel_config_repo}/kernel/configs/fragments"
|
||||
readonly default_config_whitelist="${GOPATH}/src/${kernel_config_repo}/kernel/configs/fragments/whitelist.conf"
|
||||
# GPU vendor
|
||||
readonly GV_INTEL="intel"
|
||||
readonly GV_NVIDIA="nvidia"
|
||||
|
||||
#Path to kernel directory
|
||||
kernel_path=""
|
||||
#Experimental kernel support. Pull from virtio-fs GitLab instead of kernel.org
|
||||
experimental_kernel="false"
|
||||
#Force generate config when setup
|
||||
force_setup_generate_config="false"
|
||||
#GPU kernel support
|
||||
gpu_vendor=""
|
||||
#
|
||||
patches_path=""
|
||||
#
|
||||
@@ -80,13 +88,16 @@ Commands:
|
||||
|
||||
Options:
|
||||
|
||||
-c <path>: Path to config file to build a the kernel.
|
||||
-e : Enable experimental kernel.
|
||||
-h : Display this help.
|
||||
-k <path>: Path to kernel to build.
|
||||
-p <path>: Path to a directory with patches to apply to kernel.
|
||||
-t : Hypervisor_target.
|
||||
-v : Kernel version to use if kernel path not provided.
|
||||
-c <path> : Path to config file to build a the kernel.
|
||||
-d : Enable bash debug.
|
||||
-e : Enable experimental kernel.
|
||||
-f : Enable force generate config when setup.
|
||||
-g <vendor> : GPU vendor, intel or nvidia.
|
||||
-h : Display this help.
|
||||
-k <path> : Path to kernel to build.
|
||||
-p <path> : Path to a directory with patches to apply to kernel.
|
||||
-t : Hypervisor_target.
|
||||
-v : Kernel version to use if kernel path not provided.
|
||||
EOT
|
||||
exit "$exit_code"
|
||||
}
|
||||
@@ -167,6 +178,8 @@ get_major_kernel_version() {
|
||||
get_kernel_frag_path() {
|
||||
local arch_path="$1"
|
||||
local common_path="${arch_path}/../common"
|
||||
local gpu_path="${arch_path}/../gpu"
|
||||
|
||||
local kernel_path="$2"
|
||||
local cmdpath="${kernel_path}/scripts/kconfig/merge_config.sh"
|
||||
local config_path="${arch_path}/.config"
|
||||
@@ -190,6 +203,12 @@ get_kernel_frag_path() {
|
||||
all_configs="${all_configs} ${experimental_configs}"
|
||||
fi
|
||||
|
||||
if [[ "${gpu_vendor}" != "" ]];then
|
||||
info "Add kernel config for GPU due to '-g ${gpu_vendor}'"
|
||||
local gpu_configs="$(ls ${gpu_path}/${gpu_vendor}.conf)"
|
||||
all_configs="${all_configs} ${gpu_configs}"
|
||||
fi
|
||||
|
||||
info "Constructing config from fragments: ${config_path}"
|
||||
|
||||
|
||||
@@ -298,23 +317,27 @@ setup_kernel() {
|
||||
|
||||
if [ -d "$kernel_path" ]; then
|
||||
info "${kernel_path} already exist"
|
||||
return
|
||||
if [[ "${force_setup_generate_config}" != "true" ]];then
|
||||
return
|
||||
else
|
||||
info "Force generate config due to '-f'"
|
||||
fi
|
||||
else
|
||||
info "kernel path does not exist, will download kernel"
|
||||
download_kernel="true"
|
||||
[ -n "$kernel_version" ] || die "failed to get kernel version: Kernel version is emtpy"
|
||||
|
||||
if [[ ${download_kernel} == "true" ]]; then
|
||||
get_kernel "${kernel_version}" "${kernel_path}"
|
||||
fi
|
||||
|
||||
[ -n "$kernel_path" ] || die "failed to find kernel source path"
|
||||
|
||||
get_config_and_patches
|
||||
|
||||
[ -d "${patches_path}" ] || die " patches path '${patches_path}' does not exist"
|
||||
fi
|
||||
|
||||
info "kernel path does not exist, will download kernel"
|
||||
download_kernel="true"
|
||||
[ -n "$kernel_version" ] || die "failed to get kernel version: Kernel version is emtpy"
|
||||
|
||||
if [[ ${download_kernel} == "true" ]]; then
|
||||
get_kernel "${kernel_version}" "${kernel_path}"
|
||||
fi
|
||||
|
||||
[ -n "$kernel_path" ] || die "failed to find kernel source path"
|
||||
|
||||
get_config_and_patches
|
||||
|
||||
[ -d "${patches_path}" ] || die " patches path '${patches_path}' does not exist"
|
||||
|
||||
local major_kernel
|
||||
major_kernel=$(get_major_kernel_version "${kernel_version}")
|
||||
local patches_dir_for_version="${patches_path}/${major_kernel}.x"
|
||||
@@ -365,8 +388,17 @@ install_kata() {
|
||||
config_version=$(get_config_version)
|
||||
[ -n "${config_version}" ] || die "failed to get config version"
|
||||
install_path=$(readlink -m "${DESTDIR}/${PREFIX}/share/${project_name}")
|
||||
vmlinuz="vmlinuz-${kernel_version}-${config_version}"
|
||||
vmlinux="vmlinux-${kernel_version}-${config_version}"
|
||||
|
||||
suffix=""
|
||||
if [[ ${experimental_kernel} == "true" ]]; then
|
||||
suffix="-virtiofs"
|
||||
fi
|
||||
if [[ ${gpu_vendor} != "" ]];then
|
||||
suffix="-${gpu_vendor}-gpu${suffix}"
|
||||
fi
|
||||
|
||||
vmlinuz="vmlinuz-${kernel_version}-${config_version}${suffix}"
|
||||
vmlinux="vmlinux-${kernel_version}-${config_version}${suffix}"
|
||||
|
||||
if [ -e "arch/${arch_target}/boot/bzImage" ]; then
|
||||
bzImage="arch/${arch_target}/boot/bzImage"
|
||||
@@ -392,21 +424,15 @@ install_kata() {
|
||||
|
||||
install --mode 0644 -D ./.config "${install_path}/config-${kernel_version}"
|
||||
|
||||
if [[ ${experimental_kernel} == "true" ]]; then
|
||||
sufix="-virtiofs.container"
|
||||
else
|
||||
sufix=".container"
|
||||
fi
|
||||
|
||||
ln -sf "${vmlinuz}" "${install_path}/vmlinuz${sufix}"
|
||||
ln -sf "${vmlinux}" "${install_path}/vmlinux${sufix}"
|
||||
ls -la "${install_path}/vmlinux${sufix}"
|
||||
ls -la "${install_path}/vmlinuz${sufix}"
|
||||
ln -sf "${vmlinuz}" "${install_path}/vmlinuz${suffix}.container"
|
||||
ln -sf "${vmlinux}" "${install_path}/vmlinux${suffix}.container"
|
||||
ls -la "${install_path}/vmlinux${suffix}.container"
|
||||
ls -la "${install_path}/vmlinuz${suffix}.container"
|
||||
popd >>/dev/null
|
||||
}
|
||||
|
||||
main() {
|
||||
while getopts "a:c:hk:p:t:v:e" opt; do
|
||||
while getopts "a:c:defg:hk:p:t:v:" opt; do
|
||||
case "$opt" in
|
||||
a)
|
||||
arch_target="${OPTARG}"
|
||||
@@ -414,9 +440,20 @@ main() {
|
||||
c)
|
||||
kernel_config_path="${OPTARG}"
|
||||
;;
|
||||
d)
|
||||
PS4=' Line ${LINENO}: '
|
||||
set -x
|
||||
;;
|
||||
e)
|
||||
experimental_kernel="true"
|
||||
;;
|
||||
f)
|
||||
force_setup_generate_config="true"
|
||||
;;
|
||||
g)
|
||||
gpu_vendor="${OPTARG}"
|
||||
[[ "${gpu_vendor}" == "${GV_INTEL}" || "${gpu_vendor}" == "${GV_NVIDIA}" ]] || die "GPU vendor only support intel and nvidia"
|
||||
;;
|
||||
h)
|
||||
usage 0
|
||||
;;
|
||||
|
7
kernel/configs/fragments/gpu/intel.conf
Normal file
7
kernel/configs/fragments/gpu/intel.conf
Normal file
@@ -0,0 +1,7 @@
|
||||
# The following i915 kernel config options need to be enabled
|
||||
CONFIG_DRM=y
|
||||
CONFIG_DRM_I915=y
|
||||
CONFIG_DRM_I915_USERPTR=y
|
||||
|
||||
# Linux kernel version suffix
|
||||
CONFIG_LOCALVERSION="-intel-gpu"
|
14
kernel/configs/fragments/gpu/nvidia.conf
Normal file
14
kernel/configs/fragments/gpu/nvidia.conf
Normal file
@@ -0,0 +1,14 @@
|
||||
# Support mmconfig PCI config space access.
|
||||
# It's used to enable the MMIO access method for PCIe devices.
|
||||
CONFIG_PCI_MMCONFIG=y
|
||||
|
||||
# Support for loading modules.
|
||||
# It is used to support loading GPU drivers.
|
||||
CONFIG_MODULES=y
|
||||
CONFIG_MODULE_UNLOAD=y
|
||||
|
||||
# CRYPTO_FIPS requires this config when loading modules is enabled.
|
||||
CONFIG_MODULE_SIG=y
|
||||
|
||||
# Linux kernel version suffix
|
||||
CONFIG_LOCALVERSION="-nvidia-gpu"
|
@@ -1 +1 @@
|
||||
69
|
||||
70
|
||||
|
Reference in New Issue
Block a user