From: Kienan Stewart Date: Fri, 8 Mar 2024 16:26:02 +0000 (-0500) Subject: Fix: Handle recent SLE major version codes X-Git-Tag: v2.13.12~4 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9e6736d66a9cad84106bf57640a07e0e2776a30e;p=lttng-modules.git Fix: Handle recent SLE major version codes Starting in early 2022, the SLE linux version codes changed from the previous style `5.3.18-59.40.1` to a new convention in which the major version is a compound number consisting of the major release version, the service pack version, and the auxillary version (currently unused from my understanding) similar to the following `5.3.18-150300.59.43.1`[1]. The newer values used in the SLE major version causes the integer value to "overflow" the expected number of digits and the comparisons may fail. The `LTTNG_SLE_KERNEL_VERSION` macro also multiplies the `LTTNG_KERNEL_VERSION` by `100000000ULL` which doesn't work in all situations, as the resulting value is too large to be stored fully in an `unsigned long long`. Example of previous results: ``` // Example range comparison. True or false depending on the value of // `LTTNG_SLE_VERSION_CODE` and `LTTNG_LINUX_VERSION_CODE`. LTTNG_SLE_KERNEL_RANGE(5,15,21,150400,24,46, 5,15,0,0,0,0); // Note: values printed with `%ull` LTTNG_SLE_KERNEL_VERSION(5,15,21,24,26,1); // 6106486698364570153 LTTNG_SLE_KERNEL_VERSION(5,15,0,0,0,0); // 0 LTTNG_KERNEL_VERSION(5,15,0); // 84869120 // Corrected SLE version codes LTTNG_SLE_KERNEL_VERSION(5,14,21,150400,24,26); // 14918348902249793914 LTTNG_SLE_KERNEL_VERSION(5,14,21,150400,24,46); // 14918348902249793934 LTTNG_SLE_KERNEL_VERSION(5,15,0,150400,0,0)); // 6971507145825058816 ``` `LTTNG_KERNEL_VERSION` packs the kernel version into a 32-bit integer; however, using that type of packing on the SLE kernel version will not work well: * Major: `150400` needs 18 bits * Minor: may exceed 127, requires 8 bits (eg. `4.12.14-150100.197.148.1`) * Patch: may exceed 127, requires 8 bits (eg. `5.3.18-150300.59.124.1`) In this patch, the SLE version is packed into a 64-bit integer with 48 bits for the major version, 8 bits for each of the minor and patch versions. As a result of packing the SLE version into a 64-bit integer, it is not possible to coherently combine an `LTTNG_KERNEL_VERSION` and an `LTTNG_SLE_KERNEL_VERSION`. Doing so would require an integer larger than 64-bits. Therefore, the `LTTNG_SLE_KERNEL_RANGE` macro has been adjusted to perform the range comparisons using the two values separately. The usage of the `LTTNG_SLE_KERNEL_RANGE` remains unchanged, as `LTTNG_SLE_VERSION` is only used inside that macro. Using the adjusted macros: ``` // Example range comparison. True or false depending on the value of // `LTTNG_SLE_VERSION_CODE` and `LTTNG_LINUX_VERSION_CODE`. LTTNG_SLE_KERNEL_RANGE(5,15,21,150400,24,46, 5,15,0,0,0,0); // Note: values printed with `%ull` LTTNG_SLE_VERSION(24,26,1); // 1579521 LTTNG_SLE_VERSION(0,0,0); // 0 LTTNG_KERNEL_VERSION(5,15,0); // 84869120 // Corrected SLE version codes LTTNG_SLE_VERSION(150400,24,26); // 9856620570 LTTNG_SLE_VERSION(150400,24,46); // 9856620590 LTTNG_SLE_VERSION(150400,0,0)); // 9863168000 ``` Known drawbacks =============== It's possible that future releases of SLE kernels have minor or patch values that exceed 255 (SLE15SP1 has a release using `197`, for example), requiring an adjustment to using more bits for those fields when packing into a 64-bit integer. The schema of multiplying an `LTTNG_KERNEL_VERSION` by a large value is used for other distributions. RHEL in particular uses `100000000ULL`, which could lead to overflow issues with certain comparisons similar to the previous behaviour of `LTTNG_SLE_KERNEL_VERSION(5,15,0,0,0,0);`. [1]: https://www.suse.com/support/kb/doc/?id=000019587#SLE15SP4 Change-Id: Iaa90bfa422e47213a13829cdf008ab20d7484cab Signed-off-by: Kienan Stewart Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/kernel-version.h b/include/lttng/kernel-version.h index d292c087..cfd21381 100644 --- a/include/lttng/kernel-version.h +++ b/include/lttng/kernel-version.h @@ -127,22 +127,48 @@ /* SUSE Linux enterprise */ -#define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \ - (((LTTNG_KERNEL_VERSION(a, b, c)) * 100000000ULL) + ((d) * 100000) + ((e) * 100) + (f)) +/* + * SLE major version codes may be large, eg. 150400, and require more than + * 32 bits to store. Multiplying `a` by `1ULL` avoids compiler warnings, eg: + * + * `warning: result of ‘150400 << 16’ requires 35 bits to represent, but ‘int’ only has 32 bits` + * + */ +#define LTTNG_SLE_VERSION(a, b, c) \ + ((((a * 1ULL) << 16) + (b << 8) + c) * 1ULL) -#ifdef SLE_API_VERSION +#if defined(SLE_API_VERSION_MAJOR) && defined(SLE_API_VERSION_MINOR) && defined(SLE_API_VERSION_PATCH) #define LTTNG_SLE_VERSION_CODE \ - ((LTTNG_LINUX_VERSION_CODE * 100000000ULL) + SLE_API_VERSION) + (LTTNG_SLE_VERSION(SLE_API_VERSION_MAJOR, SLE_API_VERSION_MINOR, SLE_API_VERSION_PATCH)) #else -#define LTTNG_SLE_VERSION_CODE 0 +#define LTTNG_SLE_VERSION_CODE 0 #endif #define LTTNG_SLE_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ a_high, b_high, c_high, d_high, e_high, f_high) \ - (LTTNG_SLE_VERSION_CODE >= \ - LTTNG_SLE_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ - LTTNG_SLE_VERSION_CODE < \ - LTTNG_SLE_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) + ( \ + LTTNG_SLE_VERSION_CODE != 0 && \ + ( \ + /* Linux kernel version code exclusive inside range */ \ + (LTTNG_LINUX_VERSION_CODE > LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \ + LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(a_high, b_high, c_high)) || \ + \ + /* Linux kernel version code is at lower and upper limit */ \ + (LTTNG_LINUX_VERSION_CODE == LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \ + LTTNG_LINUX_VERSION_CODE == LTTNG_KERNEL_VERSION(a_high, b_high, c_high) && \ + LTTNG_SLE_VERSION_CODE >= LTTNG_SLE_VERSION(d_low, e_low, f_low) && \ + LTTNG_SLE_VERSION_CODE < LTTNG_SLE_VERSION(d_high, e_high, f_high)) || \ + \ + /* Linux kernel version code is at lower limit */ \ + (LTTNG_LINUX_VERSION_CODE == LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \ + LTTNG_KERNEL_VERSION(a_low, b_low, c_low) != LTTNG_KERNEL_VERSION(a_high, b_high, c_high) && \ + LTTNG_SLE_VERSION_CODE >= LTTNG_SLE_VERSION(d_low, e_low, f_low)) || \ + \ + /* Linux kernel version code is at upper limit */ \ + (LTTNG_LINUX_VERSION_CODE == LTTNG_KERNEL_VERSION(a_high, b_high, c_high) && \ + LTTNG_KERNEL_VERSION(a_low, b_low, c_low) != LTTNG_KERNEL_VERSION(a_high, b_high, c_high) && \ + LTTNG_SLE_VERSION_CODE < LTTNG_SLE_VERSION(d_high, e_high, f_high)) \ + )) /* Fedora */ diff --git a/scripts/abi-sle-version.sh b/scripts/abi-sle-version.sh index e079e065..9b7da92d 100755 --- a/scripts/abi-sle-version.sh +++ b/scripts/abi-sle-version.sh @@ -37,7 +37,4 @@ if [ "x$SLE_RELEASE_PATCH" = "x" ]; then SLE_RELEASE_PATCH=0 fi -# Combine all update numbers into one -SLE_API_VERSION="$((SLE_RELEASE_MAJOR * 100000 + SLE_RELEASE_MINOR * 100 + SLE_RELEASE_PATCH))" - -echo ${SLE_API_VERSION} +echo "${SLE_RELEASE_MAJOR} ${SLE_RELEASE_MINOR} ${SLE_RELEASE_PATCH}" diff --git a/src/Kbuild.common b/src/Kbuild.common index f64cb09d..78afa21e 100644 --- a/src/Kbuild.common +++ b/src/Kbuild.common @@ -25,7 +25,9 @@ endif SLE_API_VERSION:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/abi-sle-version.sh $(CURDIR)) ifneq ($(SLE_API_VERSION), 0) - ccflags-y += -DSLE_API_VERSION=$(SLE_API_VERSION) + ccflags-y += -DSLE_API_VERSION_MAJOR=$(word 1, $(SLE_API_VERSION)) + ccflags-y += -DSLE_API_VERSION_MINOR=$(word 2, $(SLE_API_VERSION)) + ccflags-y += -DSLE_API_VERSION_PATCH=$(word 3, $(SLE_API_VERSION)) endif FEDORA_REVISION_VERSION:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/abi-fedora-version.sh $(CURDIR))