Skip to content

Commit

Permalink
klpbuild: Remove the --skip argument and use negative regex
Browse files Browse the repository at this point in the history
There is an example in the manpage about how to avoid a codestream using
a negative regex.

Signed-off-by: Marcos Paulo de Souza <[email protected]>
  • Loading branch information
marcosps committed Jan 30, 2025
1 parent bb5943c commit df8600e
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 63 deletions.
9 changes: 4 additions & 5 deletions klp-build.1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ livepatches.
.TP
.BI --filter " FILTER"
List of accepted codestreams. Must be specified in regex format.
Example: "15\.3u[0-9]+|15\.6u0"
Example: '15\.3u[0-9]+|15\.6u0'

You can also use a negative regex in order to filter out a specific codestream.
Example: '^(?!12.5u12).*'
.SH COMMANDS
.TP
.B scan
Expand Down Expand Up @@ -94,10 +97,6 @@ will be livepatched instead.
.TP
.BI --archs " {ppc64le,s390x,x86_64} [{ppc64le,s390x,x86_64} ...]"
Supported architectures for this livepatch.
.TP
.BI --skips " SKIPS"
List of excluded codestreams. Must be specified in regex format.
Example: "15\.3u[0-9]+|15\.6u0"
.RE
.B check-inline
.RS 7
Expand Down
1 change: 0 additions & 1 deletion klpbuild/klplib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def create_parser() -> argparse.ArgumentParser:
nargs="+",
help="SLE specific. Supported architectures for this livepatch",
)
setup.add_argument("--skips", help="List of codestreams to filter out")

check_inline = sub.add_parser("check-inline", parents=[parentparser])
check_inline.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions klpbuild/klplib/ibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def prepare_tests(self):

logging.info(f"Checking {arch} symbols...")
build_cs = []
for cs in filter_codestreams(self.lp_filter, "", get_codestreams_dict()):
for cs in filter_codestreams(self.lp_filter, get_codestreams_dict()):
if arch not in cs.archs:
continue

Expand Down Expand Up @@ -594,7 +594,7 @@ def log(self, arch):
logging.info(self.osc.build.get_log(self.cs_to_project(cs), "standard", arch, "klp"))

def push(self, wait=False):
cs_list = filter_codestreams(self.lp_filter, "", get_codestreams_dict())
cs_list = filter_codestreams(self.lp_filter, get_codestreams_dict())

if not cs_list:
logging.error(f"push: No codestreams found for {self.lp_name}")
Expand Down
6 changes: 2 additions & 4 deletions klpbuild/klplib/ksrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class GitHelper():
def __init__(self, lp_name, lp_filter, skips):
def __init__(self, lp_name, lp_filter):

self.kern_src = get_user_path('kernel_src_dir', isopt=True)

Expand All @@ -42,7 +42,6 @@ def __init__(self, lp_name, lp_filter, skips):

self.lp_name = lp_name
self.lp_filter = lp_filter
self.lp_skip = skips

def format_patches(self, version):
ver = f"v{version}"
Expand Down Expand Up @@ -542,8 +541,7 @@ def scan(self, cve, conf, no_check):

# working_cs will contain the final dict of codestreams that wast set
# by the user, avoid downloading missing codestreams that are not affected
working_cs = utils.filter_codestreams(self.lp_filter, self.lp_skip,
working_cs, verbose=True)
working_cs = utils.filter_codestreams(self.lp_filter, working_cs, verbose=True)

if not working_cs:
logging.info("All supported codestreams are already patched. Exiting klp-build")
Expand Down
8 changes: 2 additions & 6 deletions klpbuild/klplib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ def check_module_unsupported(mod_path):
return "no" == get_elf_modinfo_entry(elffile, "supported")


def filter_codestreams(lp_filter, lp_skip, cs_list, verbose=False):
def filter_codestreams(lp_filter, cs_list, verbose=False):
if isinstance(cs_list, dict):
full_cs = copy.deepcopy(list(cs_list.values()))
else:
full_cs = copy.deepcopy(cs_list)

if verbose:
logging.info("Checking filter and skips...")
logging.info("Checking filter...")

result = []
filtered = []
Expand All @@ -227,10 +227,6 @@ def filter_codestreams(lp_filter, lp_skip, cs_list, verbose=False):
filtered.append(name)
continue

if lp_skip and re.match(lp_skip, name):
filtered.append(name)
continue

result.append(cs)

if verbose:
Expand Down
8 changes: 4 additions & 4 deletions klpbuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():
args.mod_file_funcs, args.conf_mod_file_funcs)
codestreams = setup.setup_codestreams(
{"cve": args.cve, "conf": args.conf, "lp_filter": args.filter,
"lp_skips": args.skips, "no_check": args.no_check})
"no_check": args.no_check})
setup.setup_project_files(codestreams, ffuncs, args.archs)

elif args.cmd == "extract":
Expand All @@ -46,13 +46,13 @@ def main():
Inliner(args.name, args.codestream).check_inline(args.file, args.symbol)

elif args.cmd == "get-patches":
GitHelper(args.name, args.filter, "").get_commits(args.cve)
GitHelper(args.name, args.filter).get_commits(args.cve)

elif args.cmd == "scan":
GitHelper("bsc_check", "", "").scan(args.cve, args.conf, False)
GitHelper("bsc_check", "").scan(args.cve, args.conf, False)

elif args.cmd == "format-patches":
GitHelper(args.name, args.filter, "").format_patches(args.version)
GitHelper(args.name, args.filter).format_patches(args.version)

elif args.cmd == "status":
IBS(args.name, args.filter).status(args.wait)
Expand Down
6 changes: 2 additions & 4 deletions klpbuild/plugins/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,7 @@ def process(self, args):
def run(self):
logging.info(f"Work directory: %s", utils.get_workdir(self.lp_name))

working_cs = utils.filter_codestreams(self.lp_filter, "",
get_codestreams_dict(),
verbose=True)
working_cs = utils.filter_codestreams(self.lp_filter, get_codestreams_dict(), verbose=True)

if len(working_cs) == 0:
logging.error("No codestreams found")
Expand Down Expand Up @@ -619,7 +617,7 @@ def cs_diff(self):
"""
To compare two codestreams the filter should result in exactly two codestreams
"""
cs_args = utils.filter_codestreams(self.lp_filter, "", get_codestreams_dict(), verbose=True)
cs_args = utils.filter_codestreams(self.lp_filter, get_codestreams_dict(), verbose=True)
if len(cs_args) != 2:
logging.error("The filter specified found %d while it should point to only 2.", len(cs_args))
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion klpbuild/plugins/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, lp_name, lp_filter):
def check_inline(self, fname, func):
ce_args = [ str(self.ce_inline_path), "-where-is-inlined" ]

filtered = filter_codestreams(self.lp_filter, "", get_codestreams_dict())
filtered = filter_codestreams(self.lp_filter, get_codestreams_dict())
if not filtered:
raise RuntimeError(f"Codestream {self.lp_filter} not found. Aborting.")

Expand Down
2 changes: 1 addition & 1 deletion klpbuild/plugins/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def setup_codestreams(self, data):
if not self.lp_name.startswith("bsc"):
raise ValueError("Please use prefix 'bsc' when creating a livepatch for codestreams")

ksrc = GitHelper(self.lp_name, data["lp_filter"], data["lp_skips"])
ksrc = GitHelper(self.lp_name, data["lp_filter"])

# Called at this point because codestreams is populated
# FIXME: we should check all configs, like when using --conf-mod-file-funcs
Expand Down
40 changes: 16 additions & 24 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,28 @@ def list_to_cs(cs_list):
return ret

# Same output because filter and skip were not informed
assert filter_codestreams("", "", list_to_dict(["12.5u10", "15.6u10"])) \
== list_to_cs(["12.5u10", "15.6u10"])

assert filter_codestreams("", list_to_dict(["12.5u10", "15.6u10"])) \
== list_to_cs(["12.5u10", "15.6u10"])

# Same as before, but using a list instead of a dict
assert filter_codestreams("", "", list_to_cs(["12.5u10", "15.6u10"])) \
== list_to_cs(["12.5u10", "15.6u10"])
assert filter_codestreams("", list_to_cs(["12.5u10", "15.6u10"])) \
== list_to_cs(["12.5u10", "15.6u10"])

# Filter only one codestream
assert filter_codestreams("12.5u10", "", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) == \
list_to_cs(["12.5u10"])
assert filter_codestreams("12.5u10", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) == \
list_to_cs(["12.5u10"])

# Filter codestreams using regex
assert filter_codestreams("12.5u1[01]", "", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) \
== list_to_cs(["12.5u10", "12.5u11"])

assert filter_codestreams("12.5u1[01]|15.6u10", "", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) \
== list_to_cs(["12.5u10", "12.5u11", "15.6u10"])

# Use skip with filter
assert filter_codestreams("12.5u1[01]", "15.6u10", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) \
== list_to_cs(["12.5u10", "12.5u11"])
assert filter_codestreams("12.5u1[01]", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) \
== list_to_cs(["12.5u10", "12.5u11"])

# Use skip with filter
assert filter_codestreams("12.5u1[01]", "15.6", list_to_dict(["12.5u10", "12.5u11", "15.6u12", "15.6u13"])) \
== list_to_cs(["12.5u10", "12.5u11"])
assert filter_codestreams("12.5u1[01]|15.6u10", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) \
== list_to_cs(["12.5u10", "12.5u11", "15.6u10"])

# filter is off, but skip will also only filter the 12.5 ones
assert filter_codestreams("", "15.6", list_to_dict(["12.5u10", "12.5u11", "15.6u12", "15.6u13"])) \
== list_to_cs(["12.5u10", "12.5u11"])
# Use negative filter to skip 15.6u10 codestreams while keeping the 12.5 ones
assert filter_codestreams("^(?!15.6u10).*", list_to_dict(["12.5u10", "12.5u11", "15.6u10"])) \
== list_to_cs(["12.5u10", "12.5u11"])

assert filter_codestreams("", "15.6u13", list_to_dict(["12.5u10", "12.5u11", "15.6u12", "15.6u13"])) \
== list_to_cs(["12.5u10", "12.5u11", "15.6u12"])
# Use negative filter to skip all 15.6 codestreams while keeping the 12.5 ones
assert filter_codestreams("^(?!15.6).*", list_to_dict(["12.5u10", "12.5u11", "15.6u12", "15.6u13"])) \
== list_to_cs(["12.5u10", "12.5u11"])
2 changes: 1 addition & 1 deletion tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_detect_file_without_ftrace_support(caplog):
ffuncs = Setup.setup_file_funcs("CONFIG_SMP", "vmlinux", [["lib/seq_buf.c", "seq_buf_putmem_hex"]],
[], [])
codestreams = setup.setup_codestreams({"cve": None, "conf": "CONFIG_SMP",
"no_check": False, "lp_filter": cs, "lp_skips": None})
"no_check": False, "lp_filter": cs})
setup.setup_project_files(codestreams, ffuncs, [utils.ARCH])

with caplog.at_level(logging.WARNING):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ksrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def test_multiline_upstream_commit_subject():
# This CVE is already covered on all codestreams
def test_scan_all_cs_patched(caplog):
with pytest.raises(SystemExit):
GitHelper("bsc_check", "", "").scan("2022-48801", "", False)
GitHelper("bsc_check", "").scan("2022-48801", "", False)
assert "All supported codestreams are already patched" not in caplog.text
4 changes: 2 additions & 2 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from klpbuild.klplib import utils

CS = "15.5u19"
DEFAULT_DATA = {"cve": None, "lp_filter": CS, "lp_skips": None, "conf": "CONFIG_TUN", "no_check": False}
DEFAULT_DATA = {"cve": None, "lp_filter": CS, "conf": "CONFIG_TUN", "no_check": False}


def test_missing_file_funcs():
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_valid_micro_patchid():
"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}
micro_data = {"cve": None, "lp_filter": micro_cs, "conf": "CONFIG_TUN", "no_check": False}

codestreams = lp_setup.setup_codestreams(micro_data)
lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_templ.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_templ_with_externalized_vars():
["fs/proc/cmdline.c", "cmdline_proc_show"]], [], [])

codestreams = lp_setup.setup_codestreams(
{"cve": None, "lp_filter": cs, "lp_skips": None, "conf": "CONFIG_PROC_FS", "no_check": False})
{"cve": None, "lp_filter": cs, "conf": "CONFIG_PROC_FS", "no_check": False})

lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS)

Expand Down Expand Up @@ -48,7 +48,7 @@ def test_templ_without_externalized_vars():
["net/ipv6/rpl.c", "ipv6_rpl_srh_size"]], [], [])

codestreams = lp_setup.setup_codestreams(
{"cve": None, "lp_filter": cs, "lp_skips": None, "conf": "CONFIG_IPV6", "no_check": False})
{"cve": None, "lp_filter": cs, "conf": "CONFIG_IPV6", "no_check": False})

lp_setup.setup_project_files(codestreams, ffuncs, [utils.ARCH])

Expand Down Expand Up @@ -82,7 +82,7 @@ def test_check_header_file_included():
[], [])

codestreams = lp_setup.setup_codestreams(
{"cve": None, "lp_filter": cs, "lp_skips": None, "conf": "CONFIG_IPV6", "no_check": False})
{"cve": None, "lp_filter": cs, "conf": "CONFIG_IPV6", "no_check": False})

lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS)

Expand Down Expand Up @@ -110,7 +110,7 @@ def test_templ_cve_specified():
["fs/proc/cmdline.c", "cmdline_proc_show"]], [], [])

codestreams = lp_setup.setup_codestreams(
{"cve": "1234-5678", "lp_filter": cs, "lp_skips": None, "conf": "CONFIG_PROC_FS", "no_check": True})
{"cve": "1234-5678", "lp_filter": cs, "conf": "CONFIG_PROC_FS", "no_check": True})

lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS)

Expand All @@ -133,7 +133,7 @@ def test_templ_exts_mod_name():
["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})
{"cve": None, "lp_filter": cs, "conf": "CONFIG_NVME_TCP", "no_check": True})

lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS)

Expand All @@ -155,7 +155,7 @@ def test_templ_micro_is_ibt():
["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})
{"cve": None, "lp_filter": cs, "conf": "CONFIG_NVME_TCP", "no_check": True})

lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS)

Expand All @@ -176,7 +176,7 @@ def test_templ_kbuild_has_contents():
["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})
{"cve": None, "lp_filter": cs, "conf": "CONFIG_NVME_TCP", "no_check": True})

lp_setup.setup_project_files(codestreams, ffuncs, utils.ARCHS)

Expand Down

0 comments on commit df8600e

Please sign in to comment.