From fdd5bd4a09ce8abb00b848704191da683b881cb2 Mon Sep 17 00:00:00 2001 From: Harika Nittala Date: Mon, 12 Aug 2024 19:39:43 +0000 Subject: [PATCH 1/6] Update snp docs for RHEL Added RHEL 9.4 OS as one of the tested OS distribution for sev-utils Signed-off-by: Harika Nittala --- docs/snp.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/snp.md b/docs/snp.md index aca8a12..002dc53 100644 --- a/docs/snp.md +++ b/docs/snp.md @@ -13,6 +13,7 @@ CLI tool. Tested on the following OS distributions: - Ubuntu 20.04 - Ubuntu 22.04 +- RHEL 9.4 Image formats supported: - qcow2 From 91aa8beeea2b81dddf129176a5f32953b5aaa94f Mon Sep 17 00:00:00 2001 From: Harika Nittala Date: Wed, 18 Sep 2024 21:42:21 +0000 Subject: [PATCH 2/6] snp.sh: Update ubuntu dependency installation structure Renamed old install_dependencies feature to ubuntu_install_dependencies Updated install_dependencies to perform installation of dependencies based on identified linux distribution and their package manager command Signed-off-by: Harika Nittala --- tools/snp.sh | 53 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/tools/snp.sh b/tools/snp.sh index 95fa637..2991b8f 100755 --- a/tools/snp.sh +++ b/tools/snp.sh @@ -214,15 +214,7 @@ install_sev_snp_measure() { pip install sev-snp-measure==${SEV_SNP_MEASURE_VERSION} } -install_dependencies() { - local dependencies_installed_file="${WORKING_DIR}/dependencies_already_installed" - source "${HOME}/.cargo/env" 2>/dev/null || true - - if [ -f "${dependencies_installed_file}" ]; then - echo -e "Dependencies previously installed" - return 0 - fi - +install_ubuntu_dependencies() { # Build dependencies sudo apt install -y build-essential git @@ -274,7 +266,48 @@ install_dependencies() { # Needed to build 6.11.0-rc3 SNP kernel on the host pip install tomli - +} + +get_linux_distro() { + local linux_distro + + [ -e /etc/os-release ] && . /etc/os-release + + case ${ID,,} in + ubuntu | debian) + linux_distro='ubuntu' + ;; + *) + linux_distro="Unsupported Linux Distribution: ${ID}" + ;; + esac + + echo "${linux_distro}" +} + +install_dependencies() { + local linux_distro=$(get_linux_distro) + + local dependencies_installed_file="${WORKING_DIR}/dependencies_already_installed" + source "${HOME}/.cargo/env" 2>/dev/null || true + + if [ -f "${dependencies_installed_file}" ]; then + echo -e "Dependencies previously installed" + return 0 + fi + + # Perform the installation of dependencies specific to the linux distribution + case ${linux_distro} in + ubuntu) + install_ubuntu_dependencies + break + ;; + *) + >&2 echo -e "ERROR: ${linux_distro}" + return 1 + ;; + esac + echo "true" > "${dependencies_installed_file}" } From 7a5fe802250f5c859204d5770bf198707a62c38a Mon Sep 17 00:00:00 2001 From: Harika Nittala Date: Mon, 16 Sep 2024 18:26:10 +0000 Subject: [PATCH 3/6] snp.sh: Remove nasm package uninstallation step Removed ubuntu nasm package uninstallation step from the nasm source installation process Signed-off-by: Harika Nittala --- tools/snp.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/snp.sh b/tools/snp.sh index 2991b8f..e888adf 100755 --- a/tools/snp.sh +++ b/tools/snp.sh @@ -173,9 +173,6 @@ install_nasm_from_source() { return 0 fi - # Remove package manager nasm - sudo apt purge nasm - pushd "${WORKING_DIR}" >/dev/null # Install from source From a98ab53071b8827971762aeff2464addc2ef3d45 Mon Sep 17 00:00:00 2001 From: Harika Nittala Date: Mon, 16 Sep 2024 18:10:43 +0000 Subject: [PATCH 4/6] snp.sh: Add Redhat dependencies installation prior to the SNP kernel build Added RHEL dependencies to build the SNP kernel rpm package for the host and guest Signed-off-by: Harika Nittala --- tools/snp.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/snp.sh b/tools/snp.sh index e888adf..44f6275 100755 --- a/tools/snp.sh +++ b/tools/snp.sh @@ -265,6 +265,47 @@ install_ubuntu_dependencies() { pip install tomli } +install_rhel_dependencies() { + # Build dependencies + sudo dnf install -y wget curl + sudo dnf install -y git + + # Check if codeready-builder RH repository is enabled for ninja-build qemu dependency + if [[ -z $(sudo dnf repolist | grep codeready-builder-for-rhel-9-x86_64-rpms) ]]; then + echo "Install and enable codeready-builder RH repository" + return 1 + fi + + # qemu dependencies + sudo dnf install -y gcc + sudo dnf install -y ninja-build + sudo dnf install -y bzip2 + sudo dnf install -y glib2-devel + + # ovmf dependencies + sudo dnf install -y gcc-c++ + sudo dnf install -y libuuid-devel + sudo dnf install -y iasl + install_nasm_from_source + + # kernel dependencies + sudo dnf install -y bison + sudo dnf install -y flex + sudo dnf install -y kernel-devel + sudo dnf install -y bc + sudo dnf install -y rpm-build + sudo dnf install -y dwarves perl + + # cloud-utils dependency + sudo dnf install -y cloud-init + + # sev-snp-measure + sudo dnf install -y python3-pip + + # Needed to build 6.11.0-rc3 SNP kernel on the host + pip install tomli +} + get_linux_distro() { local linux_distro @@ -274,6 +315,9 @@ get_linux_distro() { ubuntu | debian) linux_distro='ubuntu' ;; + rhel) + linux_distro="rhel" + ;; *) linux_distro="Unsupported Linux Distribution: ${ID}" ;; @@ -299,6 +343,10 @@ install_dependencies() { install_ubuntu_dependencies break ;; + rhel) + install_rhel_dependencies + break + ;; *) >&2 echo -e "ERROR: ${linux_distro}" return 1 From 5a1aa646f044803636d5fc8064316c590f49a667 Mon Sep 17 00:00:00 2001 From: Harika Nittala Date: Mon, 16 Sep 2024 18:37:02 +0000 Subject: [PATCH 5/6] snp.sh: Set GRUB default menu to built SNP kernel Generalized set_default_grub_menu across various OS distribution Renamed ubuntu_set_default_grub_menu to set specific default ubuntu grub menu to the built SNP kernel Added a function to set the RHEL default grub menu to the built SNP kernel Signed-off-by: Harika Nittala --- tools/snp.sh | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tools/snp.sh b/tools/snp.sh index 44f6275..81ba472 100755 --- a/tools/snp.sh +++ b/tools/snp.sh @@ -365,7 +365,7 @@ get_host_kernel_version() { echo "${host_kernel}" } -set_grub_default_snp() { +set_ubuntu_grub_default_snp() { # Get the path to host kernel and the version for setting grub default local host_kernel_version=$(get_host_kernel_version) @@ -398,6 +398,45 @@ set_grub_default_snp() { sudo update-grub } +set_rhel_grub_default_snp() { + # Get the SNP host latest version from snp host kernel config + local snp_host_kernel_version=$(get_host_kernel_version) + + # Retrieve snp menuitem name from grub.cfg + local snp_menuitem_name=$(sudo cat /boot/grub2/grub.cfg \ + | grep "menuentry.*${snp_host_kernel_version}" \ + | grep -v "(recovery mode)" \ + | grep -o -P "(?<=').*" \ + | grep -o -P "^[^']*") + + # Create default grub backup + sudo cp /etc/default/grub /etc/default/grub_bkup + + # Replace grub default with snp menuitem name + sudo sed -i -e "s|^\(GRUB_DEFAULT=\).*$|\1\"${snp_menuitem_name}\"|g" "/etc/default/grub" + + # Regenerate GRUB configuration for UEFI based machine or BIOS based machine + [ -d /sys/firmware/efi ] && sudo grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg || sudo grub2-mkconfig -o /boot/grub2/grub.cfg +} + +set_grub_default_snp() { + local linux_distro=$(get_linux_distro) + + # Set the host default GRUB Menu to boot into built SNP kernel based on specific linux distro + case ${linux_distro} in + ubuntu) + set_ubuntu_grub_default_snp + ;; + rhel) + set_rhel_grub_default_snp + ;; + *) + >&2 echo -e "ERROR: ${linux_distro}" + return 1 + ;; + esac +} + generate_guest_ssh_keypair() { if [[ -f "${GUEST_SSH_KEY_PATH}" \ && -f "${GUEST_SSH_KEY_PATH}.pub" ]]; then From 72880bc5f9a702de642a5bfef4dd55621f42b864 Mon Sep 17 00:00:00 2001 From: Harika Nittala Date: Mon, 16 Sep 2024 21:44:58 +0000 Subject: [PATCH 6/6] snp.sh: Update AMDSEV_URL and AMDSEV_DEFAULT_BRANCH for the RHEL fixes Modified AMDSEV URL to add RHEL fixes for the latest SNP kernel patches, qemu build on the RHEL OS Requested code merge into ryan's latest fix issues branch for the updated AMD_SEV_URL in sev-utils Signed-off-by: Harika Nittala --- tools/snp.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/snp.sh b/tools/snp.sh index 81ba472..fb8be5b 100755 --- a/tools/snp.sh +++ b/tools/snp.sh @@ -91,8 +91,8 @@ IMAGE="${IMAGE:-${LAUNCH_WORKING_DIR}/${GUEST_NAME}.img}" GENERATED_INITRD_BIN="${SETUP_WORKING_DIR}/initrd.img" # URLs and repos -AMDSEV_URL="https://github.com/ryansavino/AMDSEV.git" -AMDSEV_DEFAULT_BRANCH="snp-latest-fixes" +AMDSEV_URL="https://github.com/LakshmiSaiHarika/AMDSEV.git" +AMDSEV_DEFAULT_BRANCH="rhel-setup-host" AMDSEV_NON_UPM_BRANCH="snp-non-upm" SNPGUEST_URL="https://github.com/virtee/snpguest.git" SNPGUEST_BRANCH="tags/v0.7.1"