From f6f171baae36b31b6f84381736e3e2a63738f0eb Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Wed, 18 Dec 2024 16:48:18 -0300 Subject: [PATCH 01/11] klp-build: Add SLE Micro support The changes are straighforward: * Started to handle patchinfoid, along with the IBS project * Changes in the parsing of the supported.csv due to MICRO * Use patchinfoid when querying and download the packages * Use the new config, symvers and vmlinux paths due to usrmerge being enabled on Micro It's still disabled until kernel-livepatch-devel is built accordly. Signed-off-by: Marcos Paulo de Souza --- klpbuild/codestream.py | 43 +++++++++++++++++++++++++++++------------- klpbuild/ibs.py | 33 ++++++++++++++++++++------------ klpbuild/ksrc.py | 2 ++ 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/klpbuild/codestream.py b/klpbuild/codestream.py index 2954965..415c067 100644 --- a/klpbuild/codestream.py +++ b/klpbuild/codestream.py @@ -10,8 +10,8 @@ class Codestream: __slots__ = ("data_path", "lp_path", "lp_name", "sle", "sp", "update", "rt", - "ktype", "needs_ibt", "project", "kernel", "archs", "files", - "modules", "repo") + "ktype", "needs_ibt", "is_micro", "project", "patchid", "kernel", + "archs", "files", "modules", "repo") def __init__(self, data_path, lp_path, sle, sp, update, rt, project, kernel, archs, files, modules): @@ -24,24 +24,34 @@ def __init__(self, data_path, lp_path, sle, sp, update, rt, project, self.rt = rt self.ktype = "-rt" if rt else "-default" self.needs_ibt = sle > 15 or (sle == 15 and sp >= 6) - self.project = project + self.is_micro = sle == 6 + if self.is_micro: + self.project, self.patchid = project.split("/") + else: + self.project = project + self.patchid = None self.kernel = kernel self.archs = archs self.files = files self.modules = modules self.repo = self.get_repo() - @classmethod def from_codestream(cls, data_path, lp_path, cs, proj, kernel): # Parse SLE15-SP2_Update_25 to 15.2u25 rt = "rt" if "-RT" in cs else "" + sp = "0" + u = "0" - sle, _, u = cs.replace("SLE", "").replace("-RT", "").split("_") - if "-SP" in sle: - sle, sp = sle.split("-SP") - else: - sp = "0" + # SLE12-SP5_Update_51 + if "SLE" in cs: + sle, _, u = cs.replace("SLE", "").replace("-RT", "").split("_") + if "-SP" in sle: + sle, sp = sle.split("-SP") + + # MICRO-6-0_Update_2 + elif "MICRO" in cs: + sle, sp, u = cs.replace("MICRO-", "").replace("-RT", "").replace("_Update_", "-").split("-") return cls(data_path, lp_path, int(sle), int(sp), int(u), rt, proj, kernel, [], {}, {}) @@ -89,11 +99,14 @@ def get_ipa_file(self, fname): def get_boot_file(self, file, arch=ARCH): assert file in ["vmlinux", "config", "symvers"] - return Path(self.get_data_dir(arch), "boot", f"{file}-{self.kname()}") + # Micro only created links on /boot for files on /usr/lib/modules + if self.is_micro: + return Path(self.get_mod_path(arch), file) + return Path(self.get_data_dir(arch), "boot", f"{file}-{self.kname()}") def get_repo(self): - if self.update == 0: + if self.update == 0 or self.is_micro: return "standard" repo = f"SUSE_SLE-{self.sle}" @@ -165,10 +178,14 @@ def name_full(self): def is_mod_mutex(self): return self.sle < 15 or (self.sle == 15 and self.sp < 4) - def get_mod_path(self, arch): - return Path(self.get_data_dir(arch), "lib", "modules", f"{self.kname()}") + # Micro already has support for usrmerge + if self.is_micro: + mod_path = Path("usr", "lib") + else: + mod_path = Path("lib") + return Path(self.get_data_dir(arch), mod_path, "modules", f"{self.kname()}") # A codestream can be patching multiple objects, so get the path related to # the module that we are interested diff --git a/klpbuild/ibs.py b/klpbuild/ibs.py index 267ed79..ba5efba 100644 --- a/klpbuild/ibs.py +++ b/klpbuild/ibs.py @@ -142,32 +142,41 @@ def download_cs_data(self, cs_list): rpms = [] i = 1 + # The packages that we search for are: + # kernel-source + # kernel-devel + # kernel-(default|rt) + # kernel-(default|rt)-devel + # kernel-(default|rt)-livepatch-devel (for SLE15+) + # kernel-default-kgraft (for SLE12) + # kernel-default-kgraft-devel (for SLE12) cs_data = { "kernel-default": r"(kernel-(default|rt)\-((livepatch|kgraft)?\-?devel)?\-?[\d\.\-]+.(s390x|x86_64|ppc64le).rpm)", "kernel-source": r"(kernel-(source|devel)(\-rt)?\-?[\d\.\-]+.noarch.rpm)", } + dest = Path(self.data, "kernel-rpms") + dest.mkdir(exist_ok=True, parents=True) + logging.info("Getting list of files...") for cs in cs_list: - prj = cs.project - repo = cs.repo - - path_dest = Path(self.data, "kernel-rpms") - path_dest.mkdir(exist_ok=True, parents=True) - for arch in cs.archs: for pkg, regex in cs_data.items(): + if cs.is_micro: + # For MICRO, we use the patchid to find the list of binaries + pkg = cs.patchid + + elif cs.rt: # RT kernels have different package names - if cs.rt: if pkg == "kernel-default": pkg = "kernel-rt" elif pkg == "kernel-source": pkg = "kernel-source-rt" - if repo != "standard": - pkg = f"{pkg}.{repo}" + if cs.repo != "standard": + pkg = f"{pkg}.{cs.repo}" - ret = self.osc.build.get_binary_list(prj, repo, arch, pkg) + ret = self.osc.build.get_binary_list(cs.project, cs.repo, arch, pkg) for file in re.findall(regex, str(etree.tostring(ret))): # FIXME: adjust the regex to only deal with strings if isinstance(file, str): @@ -187,7 +196,7 @@ def download_cs_data(self, cs_list): if arch != ARCH: continue - rpms.append((i, cs, prj, repo, arch, pkg, rpm, path_dest)) + rpms.append((i, cs, cs.project, cs.repo, arch, pkg, rpm, dest)) i += 1 logging.info(f"Downloading {len(rpms)} rpms...") @@ -199,7 +208,7 @@ def download_cs_data(self, cs_list): for cs in cs_list: for arch in cs.archs: # Extract modules and vmlinux files that are compressed - mod_path = Path(cs.get_data_dir(arch), "lib", "modules", cs.kname()) + mod_path = cs.get_mod_path(arch) for fext, ecmd in [("zst", "unzstd -f -d"), ("xz", "xz --quiet -d -k")]: cmd = rf'find {mod_path} -name "*ko.{fext}" -exec {ecmd} --quiet {{}} \;' subprocess.check_output(cmd, shell=True) diff --git a/klpbuild/ksrc.py b/klpbuild/ksrc.py index 96d48c0..42c0ff4 100644 --- a/klpbuild/ksrc.py +++ b/klpbuild/ksrc.py @@ -35,6 +35,8 @@ def __init__(self, lp_name, lp_filter, skips): "15.5": "SLE15-SP5-LTSS", "15.6": "SLE15-SP6", "15.6rt": "SLE15-SP6-RT", + "6.0": "SUSE-2024", + "6.0rt": "SUSE-2024-RT", "cve-5.3": "cve/linux-5.3-LTSS", "cve-5.14": "cve/linux-5.14-LTSS", } From 3342364d8f3bf7eeaaaca0e5060b3ad8dc5a39c5 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Mon, 6 Jan 2025 20:36:17 -0300 Subject: [PATCH 02/11] ksrc: Enable MICRO The ipa-clones were built manually, so it's now possible to enable it. Signed-off-by: Marcos Paulo de Souza --- klpbuild/codestream.py | 24 +++++++++++------------- klpbuild/extractor.py | 2 +- klpbuild/ibs.py | 4 ++-- klpbuild/ksrc.py | 12 +++++++----- klpbuild/utils.py | 9 +++++++++ 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/klpbuild/codestream.py b/klpbuild/codestream.py index 415c067..2926938 100644 --- a/klpbuild/codestream.py +++ b/klpbuild/codestream.py @@ -14,7 +14,7 @@ class Codestream: "archs", "files", "modules", "repo") def __init__(self, data_path, lp_path, sle, sp, update, rt, project, - kernel, archs, files, modules): + patchid, kernel, archs, files, modules): self.data_path = data_path self.lp_path = lp_path self.lp_name = PurePath(lp_path).name @@ -23,13 +23,10 @@ def __init__(self, data_path, lp_path, sle, sp, update, rt, project, self.update = update self.rt = rt self.ktype = "-rt" if rt else "-default" - self.needs_ibt = sle > 15 or (sle == 15 and sp >= 6) self.is_micro = sle == 6 - if self.is_micro: - self.project, self.patchid = project.split("/") - else: - self.project = project - self.patchid = None + self.needs_ibt = self.is_micro or sle > 15 or (sle == 15 and sp >= 6) + self.project = project + self.patchid = patchid self.kernel = kernel self.archs = archs self.files = files @@ -37,7 +34,7 @@ def __init__(self, data_path, lp_path, sle, sp, update, rt, project, self.repo = self.get_repo() @classmethod - def from_codestream(cls, data_path, lp_path, cs, proj, kernel): + def from_codestream(cls, data_path, lp_path, cs, proj, patchid, kernel): # Parse SLE15-SP2_Update_25 to 15.2u25 rt = "rt" if "-RT" in cs else "" sp = "0" @@ -53,21 +50,21 @@ def from_codestream(cls, data_path, lp_path, cs, proj, kernel): elif "MICRO" in cs: sle, sp, u = cs.replace("MICRO-", "").replace("-RT", "").replace("_Update_", "-").split("-") - return cls(data_path, lp_path, int(sle), int(sp), int(u), rt, proj, kernel, [], {}, {}) + return cls(data_path, lp_path, int(sle), int(sp), int(u), rt, proj, patchid, kernel, [], {}, {}) @classmethod def from_cs(cls, cs): match = re.search(r"(\d+)\.(\d+)(rt)?u(\d+)", cs) return cls("", "", int(match.group(1)), int(match.group(2)), - int(match.group(4)), match.group(3), "", "", [], {}, {}) + int(match.group(4)), match.group(3), "", "", "", [], {}, {}) @classmethod def from_data(cls, data): return cls(data["data_path"], data["lp_path"], data["sle"], data["sp"], - data["update"], data["rt"], data["project"], data["kernel"], - data["archs"], data["files"], data["modules"]) + data["update"], data["rt"], data["project"], data["patchid"], + data["kernel"], data["archs"], data["files"], data["modules"]) def __eq__(self, cs): @@ -176,7 +173,7 @@ def name_full(self): # 15.4 onwards we don't have module_mutex, so template generates # different code def is_mod_mutex(self): - return self.sle < 15 or (self.sle == 15 and self.sp < 4) + return not self.is_micro and (self.sle < 15 or (self.sle == 15 and self.sp < 4)) def get_mod_path(self, arch): # Micro already has support for usrmerge @@ -342,6 +339,7 @@ def data(self): "update" : self.update, "rt" : self.rt, "project" : self.project, + "patchid": self.patchid, "kernel" : self.kernel, "archs" : self.archs, "files" : self.files, diff --git a/klpbuild/extractor.py b/klpbuild/extractor.py index 6e0c101..1bb25f1 100644 --- a/klpbuild/extractor.py +++ b/klpbuild/extractor.py @@ -389,7 +389,7 @@ def cmd_args(self, cs, fname, out_dir, fdata, cmd): ]: cmd = cmd.replace(opt, "") - if cs.sle >= 15 and cs.sp >= 4: + if cs.is_micro or (cs.sle >= 15 and cs.sp >= 4): cmd += " -D__has_attribute(x)=0" ccp_args.extend(cmd.split(" ")) diff --git a/klpbuild/ibs.py b/klpbuild/ibs.py index ba5efba..e576b9c 100644 --- a/klpbuild/ibs.py +++ b/klpbuild/ibs.py @@ -459,7 +459,7 @@ def status(self, wait=False): # codestreams built without issues if not finished: states = set(archs.values()) - if len(states) == 1 and states.pop() == "succeeded": + if len(states) == 1 and states.pop() in ["succeeded", "excluded"]: finished = True if finished: @@ -535,7 +535,7 @@ def create_lp_package(self, i, cs): except Exception as e: logging.error(e, e.response.content) - raise RuntimeError("") + raise RuntimeError("") from e # Remove previously created directories prj_path = Path(cs.dir(), "checkout") diff --git a/klpbuild/ksrc.py b/klpbuild/ksrc.py index 42c0ff4..9fd2b4a 100644 --- a/klpbuild/ksrc.py +++ b/klpbuild/ksrc.py @@ -436,14 +436,16 @@ def download_supported_file(data_path, lp_path): # remove the build counter number full_cs, proj, kernel_full, _, _ = line.decode("utf-8").strip().split(",") - # for now, skip MICRO releases - if "MICRO" in full_cs: - continue - kernel = re.sub(r"\.\d+$", "", kernel_full) + # MICRO releases contain project/patchid format + if "/" in proj: + proj, patchid = proj.split("/") + else: + patchid = "" + codestreams.append(Codestream.from_codestream(data_path, lp_path, full_cs, - proj, kernel)) + proj, patchid, kernel)) return codestreams diff --git a/klpbuild/utils.py b/klpbuild/utils.py index ffd20e1..308d54f 100644 --- a/klpbuild/utils.py +++ b/klpbuild/utils.py @@ -256,6 +256,15 @@ def fix_mod_string(mod): def get_kgraft_branch(cs_name): + if "6.0" in cs_name: + branch = "MICRO-6-0" + + if "rt" in cs_name: + branch = branch + "-RT" + + _, update = cs_name.split("u") + return f"{branch}_Update_{update}" + if '12.' in cs_name: return "master-livepatch-sle12" From 3d6702c19c2eee61ad2dec0c4d3d986e295caa8b Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Tue, 7 Jan 2025 09:11:05 -0300 Subject: [PATCH 03/11] ibs: Change push/log projects from devbuild to standard This is needed since we now have _buildenv files that are created on kgraft-patches, and the filenames are using "standard" project, so change it accordly. The name "devbuild" is here since forever. Let's change it and see what happens. Signed-off-by: Marcos Paulo de Souza --- klpbuild/ibs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/klpbuild/ibs.py b/klpbuild/ibs.py index e576b9c..615f1f3 100644 --- a/klpbuild/ibs.py +++ b/klpbuild/ibs.py @@ -405,7 +405,7 @@ def download(self): archs = result.xpath("repository/arch") for arch in archs: - ret = self.osc.build.get_binary_list(prj, "devbuild", arch, "klp") + ret = self.osc.build.get_binary_list(prj, "standard", arch, "klp") rpm_name = f"{arch}.rpm" for rpm in ret.xpath("binary/@filename"): if not rpm.endswith(rpm_name): @@ -418,7 +418,7 @@ def download(self): dest = Path(cs.dir(), str(arch), "rpm") dest.mkdir(exist_ok=True, parents=True) - rpms.append((i, cs, prj, "devbuild", arch, "klp", rpm, dest)) + rpms.append((i, cs, prj, "standard", arch, "klp", rpm, dest)) i += 1 logging.info(f"Downloading {len(rpms)} packages...") @@ -497,7 +497,7 @@ def create_prj_meta(self, cs): "" "" "" - '' + '' f"" "" "" @@ -596,7 +596,7 @@ def create_lp_package(self, i, cs): logging.info(f"({i}/{self.total}) {cs.name()} done") def log(self, cs, arch): - logging.info(self.osc.build.get_log(self.cs_to_project(cs), "devbuild", arch, "klp")) + logging.info(self.osc.build.get_log(self.cs_to_project(cs), "standard", arch, "klp")) def push(self, wait=False): cs_list = filter_cs(self.lp_filter, "", self.codestreams) From 7b02ed01e4d513a7d9ce98fddefdc8b62c7d5fe9 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Wed, 8 Jan 2025 11:28:34 -0300 Subject: [PATCH 04/11] codestreams: Add MICRO version on name_full method Signed-off-by: Marcos Paulo de Souza --- klpbuild/codestream.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/klpbuild/codestream.py b/klpbuild/codestream.py index 2926938..36520f8 100644 --- a/klpbuild/codestream.py +++ b/klpbuild/codestream.py @@ -156,13 +156,15 @@ def name_cs(self): return f"{self.sle}.{self.sp}rt" return f"{self.sle}.{self.sp}" - - # Parse 15.2u25 to SLE15-SP2_Update_25 def name_full(self): - buf = f"SLE{self.sle}" - - if int(self.sp) > 0: - buf = f"{buf}-SP{self.sp}" + # Parse 15.2u25 to SLE15-SP2_Update_25 + # Parse 6.0u2 to MICRO + if self.is_micro: + buf = f"MICRO-{self.sle}-{self.sp}" + else: + buf = f"SLE{self.sle}" + if int(self.sp) > 0: + buf = f"{buf}-SP{self.sp}" if self.rt: buf = f"{buf}-RT" From fe676621e7a033bec28b9aa91def8fc6143b8a97 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Wed, 8 Jan 2025 11:29:05 -0300 Subject: [PATCH 05/11] ibs: Extract all zst and xz files under /usr/lib/modules This is necessay because MICRO has vmlinux.xz on /usr/lib/modules, and we need this to be extracted in order to check for symbols when prepare-tests is called. Signed-off-by: Marcos Paulo de Souza --- klpbuild/ibs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/klpbuild/ibs.py b/klpbuild/ibs.py index 615f1f3..a8172f2 100644 --- a/klpbuild/ibs.py +++ b/klpbuild/ibs.py @@ -210,7 +210,7 @@ def download_cs_data(self, cs_list): # Extract modules and vmlinux files that are compressed mod_path = cs.get_mod_path(arch) for fext, ecmd in [("zst", "unzstd -f -d"), ("xz", "xz --quiet -d -k")]: - cmd = rf'find {mod_path} -name "*ko.{fext}" -exec {ecmd} --quiet {{}} \;' + cmd = rf'find {mod_path} -name "*.{fext}" -exec {ecmd} --quiet {{}} \;' subprocess.check_output(cmd, shell=True) # Extract gzipped files per arch From 31ba44acf5de07df8841358baa7726a2ac6a88d8 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Wed, 8 Jan 2025 11:30:07 -0300 Subject: [PATCH 06/11] ibs: Refactor validate_livepatch_module to support MICRO This was overly complicated, and the version strings are different for MICRO, so refactor everything to be as generic as possible. Signed-off-by: Marcos Paulo de Souza --- klpbuild/ibs.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/klpbuild/ibs.py b/klpbuild/ibs.py index a8172f2..1318405 100644 --- a/klpbuild/ibs.py +++ b/klpbuild/ibs.py @@ -269,28 +269,18 @@ def find_missing_symbols(self, cs, arch, lp_mod_path): return missing_syms def validate_livepatch_module(self, cs, arch, rpm_dir, rpm): - match = re.search(r"(livepatch)-.*(default|rt)\-(\d+)\-(\d+)\.(\d+)\.(\d+)\.", rpm) - if match: - dir_path = match.group(1) - ktype = match.group(2) - lp_file = f"livepatch-{match.group(3)}-{match.group(4)}_{match.group(5)}_{match.group(6)}.ko" - else: - ktype = "default" - match = re.search(r"(kgraft)\-patch\-.*default\-(\d+)\-(\d+)\.(\d+)\.", rpm) - if match: - dir_path = match.group(1) - lp_file = f"kgraft-patch-{match.group(2)}-{match.group(3)}_{match.group(4)}.ko" - fdest = Path(rpm_dir, rpm) # Extract the livepatch module for later inspection - cmd = f"rpm2cpio {fdest} | cpio --quiet -uidm" - subprocess.check_output(cmd, shell=True, cwd=rpm_dir) + subprocess.check_output(f"rpm2cpio {fdest} | cpio --quiet -uidm", + shell=True, cwd=rpm_dir) + + # There should be only one .ko file extracted + lp_mod_path = sorted(rpm_dir.glob("**/*.ko"))[0] + elffile = get_elf_object(lp_mod_path) # Check depends field # At this point we found that our livepatch module depends on # exported functions from other modules. List the modules here. - lp_mod_path = Path(rpm_dir, "lib", "modules", f"{cs.kernel}-{ktype}", dir_path, lp_file) - elffile = get_elf_object(lp_mod_path) deps = get_elf_modinfo_entry(elffile, "depends") if len(deps): logging.warning(f"{cs.name()}:{arch} has dependencies: {deps}.") From 4d1a1aee6dc3049dbd1d1677eab4fc9fa051ac07 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Wed, 8 Jan 2025 14:32:51 -0300 Subject: [PATCH 07/11] templ: Add SLE MICRO6 Signed-off-by: Marcos Paulo de Souza --- klpbuild/templ.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/klpbuild/templ.py b/klpbuild/templ.py index 6066f02..389b4e6 100644 --- a/klpbuild/templ.py +++ b/klpbuild/templ.py @@ -82,6 +82,9 @@ def get_commits(cmts, cs): * SLE15-SP6 commit: ${get_commits(commits, '15.6')} * + * SLE MICRO-6-0 commit: +${get_commits(commits, '6.0')} + * % endif * Copyright (c) ${year} SUSE * Author: ${ user } <${ email }> From 95ae36c860d2d18315a572dfe8778425d1c70267 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Wed, 8 Jan 2025 14:36:57 -0300 Subject: [PATCH 08/11] tests: Add tests for MICRO-6-0 Signed-off-by: Marcos Paulo de Souza --- tests/test_setup.py | 20 ++++++++++++++++++++ tests/test_templ.py | 26 ++++++++++++++++++++++++++ tests/utils.py | 6 ++++++ 3 files changed, 52 insertions(+) diff --git a/tests/test_setup.py b/tests/test_setup.py index b5a9aaa..7b117d0 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -7,6 +7,7 @@ from klpbuild.setup import Setup from klpbuild import utils +from tests.utils import get_codestreams_file CS = "15.5u19" DEFAULT_DATA = {"cve": None, "lp_filter": CS, "lp_skips": None, "conf": "CONFIG_TUN", "no_check": False} @@ -77,6 +78,25 @@ def test_invalid_sym(caplog): assert "Symbols tun_chr_ioctll not found on tun" in caplog.text +def test_valid_micro_patchid(): + # Make sure that patchid is informed for SLE MICRO + lp = "bsc_" + inspect.currentframe().f_code.co_name + lp_setup = Setup(lp) + + ffuncs = {"drivers/net/tun.c": {"module": "tun", "conf": "CONFIG_TUN", + "symbols": ["tun_chr_ioctl", "tun_free_netdev"]}} + + micro_cs = "6.0u2" + micro_data = {"cve": None, "lp_filter": micro_cs, "lp_skips": None, "conf": "CONFIG_TUN", "no_check": False} + + codestreams = lp_setup.setup_codestreams(micro_data) + lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS) + + cs_conf = get_codestreams_file(lp)["codestreams"][micro_cs] + + assert cs_conf["patchid"] + + def test_valite_conf_mod_file_funcs(): # Check that passing mod-file-funcs can create entries differently from general # --module and --file-funcs diff --git a/tests/test_templ.py b/tests/test_templ.py index 67ce01e..c0b244e 100644 --- a/tests/test_templ.py +++ b/tests/test_templ.py @@ -91,6 +91,11 @@ def test_check_header_file_included(): # test the livepatch_ prefix file assert "Upstream commit:" in get_file_content(lp, cs) + # Check for all supported codestreams + for item in ["SLE12-SP5", "SLE15-SP2 and -SP3", "SLE15-SP4 and -SP5", + "SLE15-SP6", "SLE MICRO-6-0"]: + assert item in get_file_content(lp, cs) + # Check the other two files assert "Upstream commit:" not in get_file_content(lp, cs, f"{lp}_kernel_events_core.c") assert "Upstream commit:" not in get_file_content(lp, cs, f"{lp}_net_ipv6_rpl.c") @@ -136,3 +141,24 @@ def test_templ_exts_mod_name(): # The module name should be nvme_core instead of nvme-core assert '{ "nvme_should_fail", (void *)&klpe_nvme_should_fail, "nvme_core" },' in get_file_content(lp, cs) + + +def test_templ_micro_is_ibt(): + """ + SLE Micro is based on kernel 6.4, make sure it uses IBT. + """ + lp = "bsc_" + inspect.currentframe().f_code.co_name + cs = "6.0u2" + + lp_setup = Setup(lp) + ffuncs = Setup.setup_file_funcs("CONFIG_NVME_TCP", "nvme-tcp", [ + ["drivers/nvme/host/tcp.c", "nvme_tcp_io_work"]], [], []) + + codestreams = lp_setup.setup_codestreams( + {"cve": None, "lp_filter": cs, "lp_skips": None, "conf": "CONFIG_NVME_TCP", "no_check": True}) + + lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS) + + Extractor(lp_name=lp, lp_filter=cs, apply_patches=False, avoid_ext=[]).run() + + assert 'KLP_RELOC_SYMBOL' in get_file_content(lp, cs) diff --git a/tests/utils.py b/tests/utils.py index 1002286..47226c2 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -4,6 +4,7 @@ # Author: Marcos Paulo de Souza from pathlib import Path +import json from klpbuild.config import Config @@ -21,3 +22,8 @@ def get_file_content(lp_name, lp_filter, fname=None): with open(Path(path, fname)) as f: return f.read() + + +def get_codestreams_file(lp_name): + with open(Path(get_workdir(lp_name), "codestreams.json")) as f: + return json.loads(f.read()) From e007ab25d235234b3ae4e1b34aea413fa1a54ee3 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Thu, 9 Jan 2025 11:18:50 -0300 Subject: [PATCH 09/11] klp-build: Extract gz files on MICRO as well Without this fix the symvers files isn't extract on MICRO codestreams. Signed-off-by: Marcos Paulo de Souza --- klpbuild/codestream.py | 8 ++++---- klpbuild/ibs.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/klpbuild/codestream.py b/klpbuild/codestream.py index 36520f8..9552ade 100644 --- a/klpbuild/codestream.py +++ b/klpbuild/codestream.py @@ -93,14 +93,14 @@ def get_odir(self): def get_ipa_file(self, fname): return Path(self.get_odir(), f"{fname}.000i.ipa-clones") - def get_boot_file(self, file, arch=ARCH): - assert file in ["vmlinux", "config", "symvers"] - # Micro only created links on /boot for files on /usr/lib/modules + assert file.startswith("vmlinux") or file.startswith("config") or file.startswith("symvers") if self.is_micro: return Path(self.get_mod_path(arch), file) - return Path(self.get_data_dir(arch), "boot", f"{file}-{self.kname()}") + # Strip the suffix from the filename so we can add the kernel version in the middle + fname = f"{Path(file).stem}-{self.kname()}{Path(file).suffix}" + return Path(self.get_data_dir(arch), "boot", fname) def get_repo(self): if self.update == 0 or self.is_micro: diff --git a/klpbuild/ibs.py b/klpbuild/ibs.py index 1318405..21f2061 100644 --- a/klpbuild/ibs.py +++ b/klpbuild/ibs.py @@ -216,7 +216,7 @@ def download_cs_data(self, cs_list): # Extract gzipped files per arch files = ["vmlinux", "symvers"] for f in files: - f_path = Path(cs.get_data_dir(arch), "boot", f"{f}-{cs.kname()}.gz") + f_path = cs.get_boot_file(f"{f}.gz") # ppc64le doesn't gzips vmlinux if f_path.exists(): subprocess.check_output(rf'gzip -k -d -f {f_path}', shell=True) From 26b1d21e017d5b05d8dd2035bf0288a9ea5cfbe4 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Thu, 16 Jan 2025 17:51:58 -0300 Subject: [PATCH 10/11] ibs: push: fetch the remote codestreams before rebasing The rebase can fail is the target branch wasn't being tracked locally before the clone being done. When the clone succeeds, the origin remote is set to the local directory, so it's cannot find the remote branches on the original remote. The fix in this case is to readd the remote and fetch all codestreams before the rebase. Signed-off-by: Marcos Paulo de Souza --- klpbuild/ibs.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/klpbuild/ibs.py b/klpbuild/ibs.py index 21f2061..358d155 100644 --- a/klpbuild/ibs.py +++ b/klpbuild/ibs.py @@ -550,9 +550,19 @@ def create_lp_package(self, i, cs): stderr=subprocess.STDOUT, ) + # Add remote with all codestreams, because the clone above will set the remote origin + # to the local directory, so it can't find the remote codestreams + subprocess.check_output(["/usr/bin/git", "remote", "add", "kgr", + "gitlab@gitlab.suse.de:kernel/kgraft-patches.git"], + stderr=subprocess.STDOUT, cwd=code_path) + + # Fetch all remote codestreams so we can rebase in the next step + subprocess.check_output(["/usr/bin/git", "fetch", "kgr", str(base_branch)], + stderr=subprocess.STDOUT, cwd=code_path) + # Get the new bsc commit on top of the codestream branch (should be the last commit on the specific branch) subprocess.check_output( - ["/usr/bin/git", "rebase", f"origin/{base_branch}"], + ["/usr/bin/git", "rebase", f"kgr/{base_branch}"], stderr=subprocess.STDOUT, cwd=code_path ) From 7cb451820bb17a0de6c33877485d6e7c1986e4f2 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Fri, 17 Jan 2025 11:29:36 -0300 Subject: [PATCH 11/11] codestreams: Make set_archs to choose the correct archs per codestream Signed-off-by: Marcos Paulo de Souza --- klpbuild/codestream.py | 12 ++++++++++-- klpbuild/ksrc.py | 8 +------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/klpbuild/codestream.py b/klpbuild/codestream.py index 9552ade..5ca3d16 100644 --- a/klpbuild/codestream.py +++ b/klpbuild/codestream.py @@ -118,10 +118,18 @@ def get_repo(self): return f"{repo}_Products_SLERT_Update" + def set_archs(self): + # RT is supported only on x86_64 at the moment + if self.rt: + self.archs = ["x86_64"] - def set_archs(self, archs): - self.archs = archs + # MICRO 6.0 doest support ppc64le + elif "6.0" in self.name(): + self.archs = ["x86_64", "s390x"] + # We support all architecture for all other codestreams + else: + self.archs = ["x86_64", "s390x", "ppc64le"] def set_files(self, files): self.files = files diff --git a/klpbuild/ksrc.py b/klpbuild/ksrc.py index 9fd2b4a..17e3733 100644 --- a/klpbuild/ksrc.py +++ b/klpbuild/ksrc.py @@ -484,13 +484,7 @@ def scan(self, cve, conf, no_check): unaffected_cs.append(cs) continue - # Set supported archs for the codestream - # RT is supported only on x86_64 at the moment - archs = ["x86_64"] - if not cs.rt: - archs.extend(["ppc64le", "s390x"]) - - cs.set_archs(archs) + cs.set_archs() if conf and not cs.get_boot_file("config").exists(): data_missing.append(cs)