Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RHEL support to snp.sh #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LakshmiSaiHarika
Copy link
Contributor

@LakshmiSaiHarika LakshmiSaiHarika commented Oct 6, 2023

  1. Changed AMDSEV URL and AMDSEV branch for AMDSEV build with RHEL fixes

  2. rhel_install_dependencies for rhel library package manager dependencies for AMDSEV branch.
    requires subscription manager credential for installing RedHat libraries

  3. set_grub_default_snp() using grubby tool for RHEL.
    Changing the default kernel in Red Hat Enterprise Linux 8 & 9
    https://access.redhat.com/solutions/4326431

  4. Modified save_binary_paths() due to the
    >differences in the location of guest kernel file path for ubuntu and rhel
    >differences in the boot menu for initial ram disk images(initd.img- for ubuntu and initramfs- for rhel)

@LakshmiSaiHarika LakshmiSaiHarika changed the title setup-host option for RHEL WIP: setup-host option for RHEL Oct 9, 2023
@LakshmiSaiHarika LakshmiSaiHarika changed the title WIP: setup-host option for RHEL setup-host option for RHEL Oct 10, 2023
@ryansavino
Copy link
Collaborator

The PR should group like changes together for a required feature. Separate further more distinct parts into separate commit messages.

PR Title: Add RHEL support to snp.sh
Commit 1: RHEL support for setup-host option
Commit 2: ...etc...

Squash the existing two commits. The previous debug changes you made do not need to be part of the tree.

tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
tools/snp.sh Outdated Show resolved Hide resolved
@LakshmiSaiHarika LakshmiSaiHarika changed the title setup-host option for RHEL Add RHEL support to snp.sh Oct 16, 2023
1. Changed AMDSEV URL and AMDSEV branch for AMDSEV build with RHEL fixes

2. rhel_install_dependencies for rhel library package manager dependencies for AMDSEV branch.
      requires subscription manager credential for installing RedHat
libraries

3. set_grub_default_snp() using grubby tool for RHEL

4. Modified save_binary_paths() due to the differences in the location of guest kernel file path for ubuntu and rhel and differences in the boot menu for initial ram disk images(initd.img-<kernel-version> for ubuntu and initramfs-<kernel-version> for rhel)

Signed-off-by: Harika <lnittala@amd.com>
Copy link
Collaborator

@larrydewey larrydewey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes to apply. I would also recommend going to check the code at https://www.shellcheck.net/ to make sure we are addressing linting and possible exploit coverage.

;;
rhel)
# Can't Initialize CLOUD_INIT_IMAGE_URL for redhat due to redhat subscription requirement
echo "Download Red Hat Enterprise Linux 9.2 KVM Guest Image from RedHat Login"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this from static 9.2 to the version in question being installed.

install_common_dependencies(){
# pip issue on 20.04 - some openssl bug
#sudo rm -f "/usr/lib/python3/dist-packages/OpenSSL/crypto.py"
pip install sev-snp-measure
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to worry about Ubuntu using pip3 vs pip?

pip install sev-snp-measure

# Rust is required to build snpguest
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -sSf | sh -s -- -y
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not assume that the program is installed. Let's make sure we check before we call it.

Comment on lines +971 to +972
sudo dnf install -y git
sudo dnf install -y make automake gcc gcc-c++ kernel-devel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo dnf install -y git
sudo dnf install -y make automake gcc gcc-c++ kernel-devel
sudo dnf install -y git make automake gcc gcc-c++ kernel-devel

Comment on lines +979 to +987
sudo dnf install -y ninja-build
sudo dnf install -y pkg-config
sudo dnf install -y glib2-devel
sudo dnf install -y pixman-devel
sudo dnf install -y libslirp-devel

# ovmf dependencies
sudo dnf install -y uuid-devel
sudo dnf install -y iasl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo dnf install -y ninja-build
sudo dnf install -y pkg-config
sudo dnf install -y glib2-devel
sudo dnf install -y pixman-devel
sudo dnf install -y libslirp-devel
# ovmf dependencies
sudo dnf install -y uuid-devel
sudo dnf install -y iasl
sudo dnf install -y ninja-build pkg-config glib2-devel pixman-devel libslirp-devel
# ovmf dependencies
sudo dnf install -y uuid-devel iasl

Comment on lines +1023 to +1026
sudo apt install -y ninja-build pkg-config
sudo apt install -y libglib2.0-dev
sudo apt install -y libpixman-1-dev
sudo apt install -y libslirp-dev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo apt install -y ninja-build pkg-config
sudo apt install -y libglib2.0-dev
sudo apt install -y libpixman-1-dev
sudo apt install -y libslirp-dev
sudo apt install -y ninja-build pkg-config libglib2.0-dev libpixman-1-dev libslirp-dev

if ! $UPM; then
SETUP_WORKING_DIR="${SETUP_WORKING_DIR}/non-upm"
SETUP_WORKING_DIR="${SETUP_WORKING_DIR}/sev-snp-devel"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small Question

Is this AMDSEV/sev-snp-devel branch actively used now?
Asking this as I need to make changes in the sev-snp-devel branch for RedHat and Fedora environment.
Till now I focused on snp-latest branch

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We need to determine how to handle sev-snp-devel. Do not change the non-upm identifier text. We can discuss this with Mike.

echo "Enter RedHat subscription Manager credentials"
read -p "Username: " RHEL_SUBS_MGR_USER
read -sp "Password: " RHEL_SUBS_MGR_PASS
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a check to see if the subscription manager status is already active and only prompt if not active? Can you check out this example and test it out?
https://access.redhat.com/discussions/2217891

Also, only prompt for values if not already exported in the variables.


# Save binary paths in source file
cat > "${SETUP_WORKING_DIR}/source-bins" <<EOF
QEMU_BIN="${SETUP_WORKING_DIR}/AMDSEV/qemu/build/qemu-system-x86_64"
OVMF_BIN="${SETUP_WORKING_DIR}/AMDSEV/ovmf/Build/AmdSev/DEBUG_GCC5/FV/OVMF.fd"
OVMF_BIN="${SETUP_WORKING_DIR}/AMDSEV/ovmf/Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed? If you use the standard OVMF package, it does not have support for direct boot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it as I could not get AmdSev package in ovmf folder.
I was using the package I got after AMDSEV build step from the snp-latest branch.

tools/snp.sh Outdated Show resolved Hide resolved
# dracut built initrd. This dependency is removed for now due to this reason. For now,
# initrd is installed with the kernel debian package on the guest, and then scp-ed back to
# the host for direct-boot use.
sudo apt install -y pkg-config libkmod-dev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this uncommented now?

Copy link
Contributor Author

@LakshmiSaiHarika LakshmiSaiHarika Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry.. didn't notice this change earlier
I will modify

sudo dnf install -y make automake gcc gcc-c++ kernel-devel

# Enable RedHat Repository for qemu dependencies
sudo subscription-manager register --username ${RHEL_SUBS_MGR_USER} --password ${RHEL_SUBS_MGR_PASS} --force
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why register twice? Same comment as before.

source "${HOME}/.cargo/env" 2>/dev/null

echo "true" > "${dependencies_installed_file}"
install_dependencies(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the other install_dependencies methods up here. The goal being to keep the ubuntu method closely tied to the code on the original. That way we can see the changes as opposed to seeing a giant delete block on the original and new code on the PR. Keep like code grouped together.

# For UBUNTU, it is /boot/initrd.img-<kernel-version>
# For RHEL, fedora it is /initramfs-<kernel-version>.img
# For standardizing, I want to try creating inital ramdisk image manually (apart from intrd which comes from kernel package installaion) using commands like dracut,
# but I wanted to confirm before I try
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to discuss this. The above should be left alone as default value.

SNPGUEST_URL="https://github.com/virtee/snpguest.git"
SNPGUEST_BRANCH="tags/v0.2.2"
NASM_SOURCE_TAR_URL="https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/nasm-2.16.01.tar.gz"
CLOUD_INIT_IMAGE_URL="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
# CLOUD_INIT_IMAGE_URL initialized under set_cloud_init_url_based_on_linux_distribution()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables should live here. Create different variables for different distros.

if ! $UPM; then
SETUP_WORKING_DIR="${SETUP_WORKING_DIR}/non-upm"
SETUP_WORKING_DIR="${SETUP_WORKING_DIR}/sev-snp-devel"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We need to determine how to handle sev-snp-devel. Do not change the non-upm identifier text. We can discuss this with Mike.

sudo dnf install -y rsync
sudo dnf install -y ncurses-devel

# libssl-dev is openssl-devel in RHEL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you calling this out here? I don't see it being installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added rsync and ncurses-devel here as I faced dependencies issue in the amd_sev_snp_build_step.

sudo dnf install -y ncurses-devel

# libssl-dev is openssl-devel in RHEL
# rpm-build -- Scripts and executable programs used to build packages
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment:

# RPM package building dependencies

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a kernel dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a kernel dependency

# Get Host CPU Architecture info( like: x86_64. x86.. so on)
# My Assumption: Guest CPU has same cpu architecture as host architecture
# Reason: Guest using CPU type "host" may increase the VM performance
local host_arch=$(arch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to do this. A regex to determine the only compiled file should work here.


# Copy and rename guest snp kernel from bzImage to vmlinuz
local bzImage_file=$(realpath ${SETUP_WORKING_DIR}/AMDSEV/linux/guest/arch/$host_arch/boot/bzImage)
cp -v $bzImage_file ${SETUP_WORKING_DIR}/AMDSEV/linux/guest/vmlinuz-$guest_kernel_version
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're doing the cp, might as well do it for all OSes and then you can share more code here.

@LakshmiSaiHarika LakshmiSaiHarika marked this pull request as draft December 7, 2023 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants