kernel: support build guest kernel for gpu

Add option '-g' in build-kernel.sh to build a guest kernel that supports Intel/Nvidia GPU

Fixes: #979

Signed-off-by: Jimmy Xu <junming.xjm@antfin.com>
This commit is contained in:
Jimmy Xu 2020-03-20 01:48:43 +08:00
parent 3b88f2cd0f
commit d248e4144c
3 changed files with 63 additions and 20 deletions

View File

@ -39,10 +39,16 @@ readonly default_kernel_config_dir="${GOPATH}/src/${kernel_config_repo}/kernel/c
# Default path to search for kernel config fragments # Default path to search for kernel config fragments
readonly default_config_frags_dir="${GOPATH}/src/${kernel_config_repo}/kernel/configs/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" 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 #Path to kernel directory
kernel_path="" kernel_path=""
#Experimental kernel support. Pull from virtio-fs GitLab instead of kernel.org #Experimental kernel support. Pull from virtio-fs GitLab instead of kernel.org
experimental_kernel="false" experimental_kernel="false"
#GPU kernel support
gpu_vendor=""
# #
patches_path="" patches_path=""
# #
@ -80,13 +86,14 @@ Commands:
Options: Options:
-c <path>: Path to config file to build a the kernel. -c <path> : Path to config file to build a the kernel.
-e : Enable experimental kernel. -e : Enable experimental kernel.
-h : Display this help. -g <vendor> : GPU vendor, intel or nvidia.
-k <path>: Path to kernel to build. -h : Display this help.
-p <path>: Path to a directory with patches to apply to kernel. -k <path> : Path to kernel to build.
-t : Hypervisor_target. -p <path> : Path to a directory with patches to apply to kernel.
-v : Kernel version to use if kernel path not provided. -t : Hypervisor_target.
-v : Kernel version to use if kernel path not provided.
EOT EOT
exit "$exit_code" exit "$exit_code"
} }
@ -167,6 +174,8 @@ get_major_kernel_version() {
get_kernel_frag_path() { get_kernel_frag_path() {
local arch_path="$1" local arch_path="$1"
local common_path="${arch_path}/../common" local common_path="${arch_path}/../common"
local gpu_path="${arch_path}/../gpu"
local kernel_path="$2" local kernel_path="$2"
local cmdpath="${kernel_path}/scripts/kconfig/merge_config.sh" local cmdpath="${kernel_path}/scripts/kconfig/merge_config.sh"
local config_path="${arch_path}/.config" local config_path="${arch_path}/.config"
@ -190,6 +199,12 @@ get_kernel_frag_path() {
all_configs="${all_configs} ${experimental_configs}" all_configs="${all_configs} ${experimental_configs}"
fi 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}" info "Constructing config from fragments: ${config_path}"
@ -365,8 +380,17 @@ install_kata() {
config_version=$(get_config_version) config_version=$(get_config_version)
[ -n "${config_version}" ] || die "failed to get config version" [ -n "${config_version}" ] || die "failed to get config version"
install_path=$(readlink -m "${DESTDIR}/${PREFIX}/share/${project_name}") 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 if [ -e "arch/${arch_target}/boot/bzImage" ]; then
bzImage="arch/${arch_target}/boot/bzImage" bzImage="arch/${arch_target}/boot/bzImage"
@ -392,21 +416,15 @@ install_kata() {
install --mode 0644 -D ./.config "${install_path}/config-${kernel_version}" install --mode 0644 -D ./.config "${install_path}/config-${kernel_version}"
if [[ ${experimental_kernel} == "true" ]]; then ln -sf "${vmlinuz}" "${install_path}/vmlinuz${suffix}.container"
sufix="-virtiofs.container" ln -sf "${vmlinux}" "${install_path}/vmlinux${suffix}.container"
else ls -la "${install_path}/vmlinux${suffix}.container"
sufix=".container" ls -la "${install_path}/vmlinuz${suffix}.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}"
popd >>/dev/null popd >>/dev/null
} }
main() { main() {
while getopts "a:c:hk:p:t:v:e" opt; do while getopts "a:c:eg:hk:p:t:v:" opt; do
case "$opt" in case "$opt" in
a) a)
arch_target="${OPTARG}" arch_target="${OPTARG}"
@ -417,6 +435,10 @@ main() {
e) e)
experimental_kernel="true" experimental_kernel="true"
;; ;;
g)
gpu_vendor="${OPTARG}"
[[ "${gpu_vendor}" == "${GV_INTEL}" || "${gpu_vendor}" == "${GV_NVIDIA}" ]] || die "GPU vendor only support intel and nvidia"
;;
h) h)
usage 0 usage 0
;; ;;

View 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"

View 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"