public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/4] kernel-{build,install}.eclass: make kernel install paths match release
@ 2024-07-15 13:43 Andrew Nowa Ammerlaan
  2024-07-15 13:44 ` [gentoo-dev] [PATCH 2/4] kernel-build.eclass: sanity check the prepared kernel's release string Andrew Nowa Ammerlaan
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-07-15 13:43 UTC (permalink / raw
  To: gentoo-dev

Part of https://github.com/gentoo/gentoo/pull/37327

 From d57b75ed204432c11ae643ea3526b46dab40c746 Mon Sep 17 00:00:00 2001
From: James Calligeros <jcalligeros99@gmail.com>
Date: Thu, 27 Jun 2024 05:56:44 +0000
Subject: [PATCH] kernel-{build,install}.eclass: make kernel install paths
  match release

dist-kernel releases are required to match the package's version, with
'_' substituted for '-' as per kernel release format rules. Curiously,
we made no such substitution on the kernel install directory names.

The consequence of this is that Catalyst has technically only been
working with dist-kernels by pure coincidence - it had never been tested
with kernels containing '_' in ${PV}. When attempting to build install
media for the Gentoo Asahi project, which necessitates using kernels
versioned with '_p*', Catalyst's call to Dracut's --kver argument
passes in the name of the source directory while Dracut expects
the kernel release (module directory).

Make sure that all directories installed by the kernel match the
kernel's own idea of its version exactly. This fixes Catalyst,
makes directories like /usr/src/linux-* consistent with /lib/modules

For compatibility with existing bin kernels, KV_FULL will be
set to ${PV}${KV_LOCALVERSION} in kernel-install.eclass if it
has not been explicitly set elsewhere.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
---
  eclass/kernel-build.eclass   | 46 +++++++++++++++-------------
  eclass/kernel-install.eclass | 59 +++++++++++++++++++++---------------
  2 files changed, 60 insertions(+), 45 deletions(-)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 86c7cd4a172d5..7d4b98ac027d9 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -20,6 +20,14 @@
  # the kernel and installing it along with its modules and subset
  # of sources needed to build external modules.

+# @ECLASS_VARIABLE: KV_FULL
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# A string containing the full kernel release version, e.g.
+# '6.9.6-gentoo-dist'. This is used to ensure consistency between the
+# kernel's release version and Gentoo's tooling. This is set by
+# kernel-build_src_configure() once we have a kernel.release file.
+
  case ${EAPI} in
  	8) ;;
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
@@ -225,6 +233,12 @@ kernel-build_src_configure() {
  	emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" olddefconfig
  	emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" modules_prepare
  	cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die
+
+	# Now that we have a release file, set KV_FULL
+	if [[ -z ${KV_FULL} ]]; then
+		local relfile=${WORKDIR}/build/include/config/kernel.release
+		KV_FULL=$(<"${relfile}") || die
+	fi
  }

  # @FUNCTION: kernel-build_src_compile
@@ -254,20 +268,15 @@ kernel-build_src_test() {
  		INSTALL_MOD_PATH="${T}" INSTALL_MOD_STRIP="${strip_args}" \
  		modules_install

-	local dir_ver=${PV}${KV_LOCALVERSION}
-	local relfile=${WORKDIR}/build/include/config/kernel.release
-	local module_ver
-	module_ver=$(<"${relfile}") || die
-
-	kernel-install_test "${module_ver}" \
+	kernel-install_test "${KV_FULL}" \
  		"${WORKDIR}/build/$(dist-kernel_get_image_path)" \
-		"${T}/lib/modules/${module_ver}"
+		"${T}/lib/modules/${KV_FULL}"
  }

  # @FUNCTION: kernel-build_src_install
  # @DESCRIPTION:
  # Install the built kernel along with subset of sources
-# into /usr/src/linux-${PV}.  Install the modules.  Save the config.
+# into /usr/src/linux-${KV_FULL}.  Install the modules.  Save the config.
  kernel-build_src_install() {
  	debug-print-function ${FUNCNAME} "${@}"

@@ -304,8 +313,7 @@ kernel-build_src_install() {
  	# note: we're using mv rather than doins to save space and time
  	# install main and arch-specific headers first, and scripts
  	local kern_arch=$(tc-arch-kernel)
-	local dir_ver=${PV}${KV_LOCALVERSION}
-	local kernel_dir=/usr/src/linux-${dir_ver}
+	local kernel_dir=/usr/src/linux-${KV_FULL}

  	if use sparc ; then
  		# We don't want tc-arch-kernel's sparc64, even though we do
@@ -378,10 +386,6 @@ kernel-build_src_install() {
  	# strip empty directories
  	find "${D}" -type d -empty -exec rmdir {} + || die

-	local relfile=${ED}${kernel_dir}/include/config/kernel.release
-	local module_ver
-	module_ver=$(<"${relfile}") || die
-
  	# warn when trying to "make" a dist-kernel
  	cat <<-EOF >> "${ED}${kernel_dir}/Makefile" || die

@@ -399,12 +403,12 @@ kernel-build_src_install() {
  	echo "${CATEGORY}/${PF}:${SLOT}" > "${ED}${kernel_dir}/dist-kernel" 
|| die

  	# fix source tree and build dir symlinks
-	dosym "../../../${kernel_dir}" "/lib/modules/${module_ver}/build"
-	dosym "../../../${kernel_dir}" "/lib/modules/${module_ver}/source"
+	dosym "../../../${kernel_dir}" "/lib/modules/${KV_FULL}/build"
+	dosym "../../../${kernel_dir}" "/lib/modules/${KV_FULL}/source"
  	if [[ "${image_path}" == *vmlinux* ]]; then
-		dosym "../../../${kernel_dir}/${image_path}" 
"/lib/modules/${module_ver}/vmlinux"
+		dosym "../../../${kernel_dir}/${image_path}" 
"/lib/modules/${KV_FULL}/vmlinux"
  	else
-		dosym "../../../${kernel_dir}/${image_path}" 
"/lib/modules/${module_ver}/vmlinuz"
+		dosym "../../../${kernel_dir}/${image_path}" 
"/lib/modules/${KV_FULL}/vmlinuz"
  	fi

  	if [[ ${KERNEL_IUSE_MODULES_SIGN} ]]; then
@@ -435,7 +439,7 @@ kernel-build_src_install() {
  				--conf "${T}/empty-file"
  				--confdir "${T}/empty-directory"
  				--kernel-image "${image}"
-				--kmoddir "${ED}/lib/modules/${dir_ver}"
+				--kmoddir "${ED}/lib/modules/${KV_FULL}"
  				--kver "${dir_ver}"
  				--verbose
  				--compress="xz -9e --check=crc32"
@@ -462,7 +466,7 @@ kernel-build_src_install() {
  				--linux="${image}"
  				--initrd="${image%/*}/initrd"
  				--cmdline="${KERNEL_GENERIC_UKI_CMDLINE}"
-				--uname="${dir_ver}"
+				--uname="${KV_FULL}"
  				--output="${image%/*}/uki.efi"
  			)

@@ -520,7 +524,7 @@ kernel-build_pkg_postinst() {
  			ewarn
  			ewarn "MODULES_SIGN_KEY was not set, this means the kernel build 
system"
  			ewarn "automatically generated the signing key. This key was installed"
-			ewarn "in ${EROOT}/usr/src/linux-${PV}${KV_LOCALVERSION}/certs"
+			ewarn "in ${EROOT}/usr/src/linux-${KV_FULL}/certs"
  			ewarn "and will also be included in any binary packages."
  			ewarn "Please take appropriate action to protect the key!"
  			ewarn
diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index f512d815fe098..e0716b63a2489 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -28,6 +28,15 @@
  # If set to a non-null value, adds IUSE=generic-uki and required
  # logic to install a generic unified kernel image.

+# @ECLASS_VARIABLE: KV_FULL
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# A string containing the full kernel release version, e.g.
+# '6.9.6-gentoo-dist'. Defaults to ${PV}${KV_LOCALVERSION},
+# but can be set by the ebuild when this default value does
+# not match the kernel release. kernel-build.eclass sets this
+# to whatever is in the built kernel's kernel.release file.
+
  # @ECLASS_VARIABLE: KV_LOCALVERSION
  # @DEFAULT_UNSET
  # @DESCRIPTION:
@@ -569,40 +578,40 @@ kernel-install_src_test() {
  kernel-install_pkg_preinst() {
  	debug-print-function ${FUNCNAME} "${@}"

-	local dir_ver=${PV}${KV_LOCALVERSION}
-	local kernel_dir=${ED}/usr/src/linux-${dir_ver}
-	local relfile=${kernel_dir}/include/config/kernel.release
+	# Set KV_FULL to ${PV}${KV_LOCALVERSION} if it hasn't
+	# been set elsewhere for backward compatibility with existing
+	# bin-kernel packages
+	if [[ -z ${KV_FULL} ]]; then
+		KV_FULL=${PV}${KV_LOCALVERSION}
+	fi
+
+	local kernel_dir=${ED}/usr/src/linux-${KV_FULL}
  	local image_path=$(dist-kernel_get_image_path)
  	[[ ! -d ${kernel_dir} ]] &&
  		die "Kernel directory ${kernel_dir} not installed!"
-	[[ ! -f ${relfile} ]] &&
-		die "Release file ${relfile} not installed!"
-	local release
-	release="$(<"${relfile}")" || die
-	DIST_KERNEL_RELEASE="${release}"

  	# perform the version check for release ebuilds only
  	if [[ ${PV} != *9999 ]]; then
  		local expected_ver=$(dist-kernel_PV_to_KV "${PV}")

-		if [[ ${release} != ${expected_ver}* ]]; then
+		if [[ ${KV_FULL} != ${expected_ver}* ]]; then
  			eerror "Kernel release mismatch!"
  			eerror "  expected (PV): ${expected_ver}*"
-			eerror "          found: ${release}"
+			eerror "          found: ${KV_FULL}"
  			eerror "Please verify that you are applying the correct patches."
-			die "Kernel release mismatch (${release} instead of ${expected_ver}*)"
+			die "Kernel release mismatch (${KV_FULL} instead of ${expected_ver}*)"
  		fi
  	fi

  	if [[ -L ${EROOT}/lib && ${EROOT}/lib -ef ${EROOT}/usr/lib ]]; then
  		# Adjust symlinks for merged-usr.
-		rm "${ED}/lib/modules/${release}"/{build,source} || die
-		dosym "../../../src/linux-${dir_ver}" "/usr/lib/modules/${release}/build"
-		dosym "../../../src/linux-${dir_ver}" 
"/usr/lib/modules/${release}/source"
+		rm "${ED}/lib/modules/${KV_FULL}"/{build,source} || die
+		dosym "../../../src/linux-${KV_FULL}" "/usr/lib/modules/${KV_FULL}/build"
+		dosym "../../../src/linux-${KV_FULL}" 
"/usr/lib/modules/${KV_FULL}/source"
  		for file in vmlinux vmlinuz; do
-			if [[ -L "${ED}/lib/modules/${release}/${file}" ]]; then
-				rm "${ED}/lib/modules/${release}/${file}" || die
-				dosym "../../../src/linux-${dir_ver}/${image_path}" 
"/usr/lib/modules/${release}/${file}"
+			if [[ -L "${ED}/lib/modules/${KV_FULL}/${file}" ]]; then
+				rm "${ED}/lib/modules/${KV_FULL}/${file}" || die
+				dosym "../../../src/linux-${KV_FULL}/${image_path}" 
"/usr/lib/modules/${KV_FULL}/${file}"
  			fi
  		done
  	fi
@@ -695,13 +704,12 @@ kernel-install_install_all() {
  kernel-install_pkg_postinst() {
  	debug-print-function ${FUNCNAME} "${@}"

-	local dir_ver=${PV}${KV_LOCALVERSION}
-	kernel-install_update_symlink "${EROOT}/usr/src/linux" "${dir_ver}"
+	kernel-install_update_symlink "${EROOT}/usr/src/linux" "${KV_FULL}"
  	dist-kernel_compressed_module_cleanup \
-		"${EROOT}/lib/modules/${DIST_KERNEL_RELEASE}"
+		"${EROOT}/lib/modules/${KV_FULL}"

  	if [[ -z ${ROOT} ]]; then
-		kernel-install_install_all "${dir_ver}"
+		kernel-install_install_all "${KV_FULL}"
  	fi

  	if [[ ${KERNEL_IUSE_GENERIC_UKI} ]] && use generic-uki; then
@@ -734,8 +742,7 @@ kernel-install_pkg_postrm() {
  	debug-print-function ${FUNCNAME} "${@}"

  	if [[ -z ${ROOT} && ! ${KERNEL_IUSE_GENERIC_UKI} ]]; then
-		local dir_ver=${PV}${KV_LOCALVERSION}
-		local kernel_dir=${EROOT}/usr/src/linux-${dir_ver}
+		local kernel_dir=${EROOT}/usr/src/linux-${KV_FULL}
  		local image_path=$(dist-kernel_get_image_path)
  		ebegin "Removing initramfs"
  		rm -f "${kernel_dir}/${image_path%/*}"/{initrd,uki.efi} &&
@@ -750,7 +757,11 @@ kernel-install_pkg_postrm() {
  kernel-install_pkg_config() {
  	[[ -z ${ROOT} ]] || die "ROOT!=/ not supported currently"

-	kernel-install_install_all "${PV}${KV_LOCALVERSION}"
+	if [[ -z ${KV_FULL} ]]; then
+		KV_FULL=${PV}${KV_LOCALVERSION}
+	fi
+
+	kernel-install_install_all "${KV_FULL}"
  }

  # @FUNCTION: kernel-install_compress_modules


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH 2/4] kernel-build.eclass: sanity check the prepared kernel's release string
  2024-07-15 13:43 [gentoo-dev] [PATCH 1/4] kernel-{build,install}.eclass: make kernel install paths match release Andrew Nowa Ammerlaan
@ 2024-07-15 13:44 ` Andrew Nowa Ammerlaan
  2024-07-15 13:45   ` [gentoo-dev] [PATCH 3/4] " Andrew Nowa Ammerlaan
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-07-15 13:44 UTC (permalink / raw
  To: gentoo-dev

Part of https://github.com/gentoo/gentoo/pull/37327

 From 021915604b90ee45332dc373f401e52afa832370 Mon Sep 17 00:00:00 2001
From: James Calligeros <jcalligeros99@gmail.com>
Date: Sat, 29 Jun 2024 01:55:12 +0000
Subject: [PATCH] kernel-build.eclass: sanity check the prepared kernel's
  release string

Previously, this was only checked by kernel-install_pkg_preinst(). This
means that the entire kernel would have to be built and stripped before
we knew if we had built the correct kernel or not.

Duplicate this check in kernel-build_src_configure() so that we don't waste
time and energy building an incorrectly-versioned kernel.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
---
  eclass/kernel-build.eclass | 13 +++++++++++++
  1 file changed, 13 insertions(+)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 7d4b98ac027d9..408837c4c57a7 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -239,6 +239,19 @@ kernel-build_src_configure() {
  		local relfile=${WORKDIR}/build/include/config/kernel.release
  		KV_FULL=$(<"${relfile}") || die
  	fi
+
+	# Make sure we are about to build the correct kernel
+	if [[ ${PV} != *9999 ]]; then
+		local expected_ver=$(dist-kernel_PV_to_KV "${PV}")
+
+		if [[ ${KV_FULL} != ${expected_ver}* ]]; then
+			eerror "Kernel version does not match PV!"
+			eerror "Source version: ${KV_FULL}"
+			eerror "Expected (PV*): ${expected_ver}*"
+			eerror "Please ensure you are applying the correct patchset."
+			die "Kernel version mismatch: got ${KV_FULL}, expected ${expected_ver}*"
+		fi
+	fi
  }

  # @FUNCTION: kernel-build_src_compile



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH 3/4] kernel-build.eclass: sanity check the prepared kernel's release string
  2024-07-15 13:44 ` [gentoo-dev] [PATCH 2/4] kernel-build.eclass: sanity check the prepared kernel's release string Andrew Nowa Ammerlaan
@ 2024-07-15 13:45   ` Andrew Nowa Ammerlaan
  2024-07-15 13:46     ` [gentoo-dev] [PATCH 4/4] kernel-install.eclass: improve kernel version check Andrew Nowa Ammerlaan
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-07-15 13:45 UTC (permalink / raw
  To: gentoo-dev

Part of https://github.com/gentoo/gentoo/pull/37327

 From ec4e55ae9fd7cc6a4833981040f051ad2a3df15b Mon Sep 17 00:00:00 2001
From: James Calligeros <jcalligeros99@gmail.com>
Date: Sat, 29 Jun 2024 03:44:38 +0000
Subject: [PATCH] kernel-build.eclass: check that KV_FULL matches the kernel
  release

We want to ensure all our installed directories are consistent and
match the kernel's own idea of its release version. Do an extra
sanity check to ensure that KV_FULL is indeed what it is supposed
to be, and bail out if it isn't.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
---
  eclass/kernel-build.eclass | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 408837c4c57a7..6658435b92587 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -235,14 +235,22 @@ kernel-build_src_configure() {
  	cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die

  	# Now that we have a release file, set KV_FULL
+	local relfile=${WORKDIR}/build/include/config/kernel.release
  	if [[ -z ${KV_FULL} ]]; then
-		local relfile=${WORKDIR}/build/include/config/kernel.release
  		KV_FULL=$(<"${relfile}") || die
  	fi

  	# Make sure we are about to build the correct kernel
  	if [[ ${PV} != *9999 ]]; then
  		local expected_ver=$(dist-kernel_PV_to_KV "${PV}")
+		local expected_rel=$(<"${relfile}")
+
+		if [[ ${KV_FULL} != ${expected_rel} ]]; then
+			eerror "KV_FULL mismatch!"
+			eerror "KV_FULL:  ${KV_FULL}"
+			eerror "Expected: ${expected_rel}"
+			die "KV_FULL mismatch: got ${KV_FULL}, expected ${expected_rel}"
+		fi

  		if [[ ${KV_FULL} != ${expected_ver}* ]]; then
  			eerror "Kernel version does not match PV!"


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH 4/4] kernel-install.eclass: improve kernel version check
  2024-07-15 13:45   ` [gentoo-dev] [PATCH 3/4] " Andrew Nowa Ammerlaan
@ 2024-07-15 13:46     ` Andrew Nowa Ammerlaan
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-07-15 13:46 UTC (permalink / raw
  To: gentoo-dev

Part of https://github.com/gentoo/gentoo/pull/37327

 From bcbc9191becab3cda6af8f9f2c0e1da6ebe395e1 Mon Sep 17 00:00:00 2001
From: James Calligeros <jcalligeros99@gmail.com>
Date: Sat, 13 Jul 2024 22:47:33 +1000
Subject: [PATCH] kernel-install.eclass: improve kernel version check

Now that we have an improved version check in kernel-build.eclass,
copy it here so that the two eclasses match.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
---
  eclass/kernel-install.eclass | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index e0716b63a2489..59bab9c0af08d 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -595,11 +595,11 @@ kernel-install_pkg_preinst() {
  		local expected_ver=$(dist-kernel_PV_to_KV "${PV}")

  		if [[ ${KV_FULL} != ${expected_ver}* ]]; then
-			eerror "Kernel release mismatch!"
-			eerror "  expected (PV): ${expected_ver}*"
-			eerror "          found: ${KV_FULL}"
-			eerror "Please verify that you are applying the correct patches."
-			die "Kernel release mismatch (${KV_FULL} instead of ${expected_ver}*)"
+			eerror "Kernel version does not match PV!"
+			eerror "Source version: ${KV_FULL}"
+			eerror "Expected (PV*): ${expected_ver}*"
+			eerror "Please ensure you are applying the correct patchset."
+			die "Kernel version mismatch: got ${KV_FULL}, expected ${expected_ver}*"
  		fi
  	fi



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-15 13:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-15 13:43 [gentoo-dev] [PATCH 1/4] kernel-{build,install}.eclass: make kernel install paths match release Andrew Nowa Ammerlaan
2024-07-15 13:44 ` [gentoo-dev] [PATCH 2/4] kernel-build.eclass: sanity check the prepared kernel's release string Andrew Nowa Ammerlaan
2024-07-15 13:45   ` [gentoo-dev] [PATCH 3/4] " Andrew Nowa Ammerlaan
2024-07-15 13:46     ` [gentoo-dev] [PATCH 4/4] kernel-install.eclass: improve kernel version check Andrew Nowa Ammerlaan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox