Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions baselines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ Each baseline lives in its own subdirectory with a kernel patch, a
* These directories ship the kernel patches and build scripts. They do not
include per-system workload run wrappers; boot the patched kernel and drive
workloads with your own launcher (PACT's own runner is in [`../`](../)).

## Older-kernel build compatibility

TPP, Nomad and Memtis builds also apply
[`common/libsubcmd-realloc.patch`](common/libsubcmd-realloc.patch), upstream Linux
commit `52a9dab6d892763b2a8334a568bd4e2c1a6fde66`. It fixes the host-tool
`realloc(ptr, 0)` use-after-free diagnosed by GCC 12 and newer. The patch retains
its upstream authorship and the affected file's GPL-2.0 license. It does not
change kernel tiering policy. The helper skips the fix when already present
and stops if neither patch direction applies; it does not suppress compiler
warnings. NBT and the Linux 6.3 baselines already contain this fix.

Colloid-tpp and Soar/Alto also apply `common/colloid-build.patch`, which removes
an unused declaration in the tier-reset helper so `CONFIG_WERROR=y` builds
succeed. It leaves the helper's operations and tiering policy unchanged.
2 changes: 1 addition & 1 deletion baselines/colloid-tpp/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
KERNEL_DIR="$SCRIPT_DIR/linux"
LOGF="$SCRIPT_DIR/log"
PATCHES=("$SCRIPT_DIR/colloid-skx.patch" "$SCRIPT_DIR/colloid-skx-alto.patch")
PATCHES=("$SCRIPT_DIR/colloid-skx.patch" "$SCRIPT_DIR/colloid-skx-alto.patch" "$SCRIPT_DIR/../common/colloid-build.patch")

[[ -d "$KERNEL_DIR" ]] || { echo "ERROR: kernel tree not found at $KERNEL_DIR (clone Linux there first)"; exit 1; }
for p in "${PATCHES[@]}"; do
Expand Down
13 changes: 13 additions & 0 deletions baselines/common/apply-build-fixes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# Apply the upstream host-tool fix needed by pre-5.17 baseline kernels.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
[[ $# -eq 1 ]] || { echo "Usage: $0 KERNEL_DIR" >&2; exit 2; }
KERNEL_DIR="$1"
PATCH="$SCRIPT_DIR/libsubcmd-realloc.patch"
if git -C "$KERNEL_DIR" apply --reverse --check "$PATCH" >/dev/null 2>&1; then
echo "libsubcmd realloc fix already present"
else
git -C "$KERNEL_DIR" apply --check "$PATCH"
git -C "$KERNEL_DIR" apply "$PATCH"
fi
16 changes: 16 additions & 0 deletions baselines/common/colloid-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Subject: [PATCH] mm: remove unused Colloid tier-reset declaration

The reset helper does not use a memory_tier pointer. Drop the declaration
so CONFIG_WERROR builds succeed without weakening compiler checks.

--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -672,8 +672,6 @@
EXPORT_SYMBOL_GPL(colloid_init_memory_tier);

void colloid_clear_memory_tier(int node) {
- struct memory_tier *memtier;
-
mutex_lock(&memory_tier_lock);
clear_node_memory_tier(node);
pr_info("clear_node_memory_tier");
66 changes: 66 additions & 0 deletions baselines/common/libsubcmd-realloc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
From 52a9dab6d892763b2a8334a568bd4e2c1a6fde66 Mon Sep 17 00:00:00 2001
From: Kees Cook <keescook@chromium.org>
Date: Sun, 13 Feb 2022 10:24:43 -0800
Subject: [PATCH] libsubcmd: Fix use-after-free for realloc(..., 0)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

GCC 12 correctly reports a potential use-after-free condition in the
xrealloc helper. Fix the warning by avoiding an implicit "free(ptr)"
when size == 0:

In file included from help.c:12:
In function 'xrealloc',
inlined from 'add_cmdname' at help.c:24:2: subcmd-util.h:56:23: error: pointer may be used after 'realloc' [-Werror=use-after-free]
56 | ret = realloc(ptr, size);
| ^~~~~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to 'realloc' here
52 | void *ret = realloc(ptr, size);
| ^~~~~~~~~~~~~~~~~~
subcmd-util.h:58:31: error: pointer may be used after 'realloc' [-Werror=use-after-free]
58 | ret = realloc(ptr, 1);
| ^~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to 'realloc' here
52 | void *ret = realloc(ptr, size);
| ^~~~~~~~~~~~~~~~~~

Fixes: 2f4ce5ec1d447beb ("perf tools: Finalize subcmd independence")
Reported-by: Valdis Klētnieks <valdis.kletnieks@vt.edu>
Signed-off-by: Kees Kook <keescook@chromium.org>
Tested-by: Valdis Klētnieks <valdis.kletnieks@vt.edu>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: linux-hardening@vger.kernel.org
Cc: Valdis Klētnieks <valdis.kletnieks@vt.edu>
Link: http://lore.kernel.org/lkml/20220213182443.4037039-1-keescook@chromium.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/subcmd/subcmd-util.h | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/lib/subcmd/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h
index 794a375dad36..b2aec04fce8f 100644
--- a/tools/lib/subcmd/subcmd-util.h
+++ b/tools/lib/subcmd/subcmd-util.h
@@ -50,15 +50,8 @@ static NORETURN inline void die(const char *err, ...)
static inline void *xrealloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
- if (!ret && !size)
- ret = realloc(ptr, 1);
- if (!ret) {
- ret = realloc(ptr, size);
- if (!ret && !size)
- ret = realloc(ptr, 1);
- if (!ret)
- die("Out of memory, realloc failed");
- }
+ if (!ret)
+ die("Out of memory, realloc failed");
return ret;
}

--
2.43.0

9 changes: 9 additions & 0 deletions baselines/memtis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ Verify after reboot:
uname -r
# expected: 5.15.19-htmm
```

## Build corrections

The setup script applies `memtis-vmstat.patch` after the original Memtis patch.
It makes HTMM counter names independent of memory-balloon support, matching
the counter enums and allowing builds with `CONFIG_MEMORY_BALLOON=n`. The
shared host-tool fix described in [`../README.md`](../README.md) also enables
compilation with newer GCC versions. Neither correction changes placement
policy. Local compilation does not establish boot or workload performance.
25 changes: 25 additions & 0 deletions baselines/memtis/memtis-vmstat.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Subject: [PATCH] mm: expose Memtis vmstat names independently of balloon support

HTMM event enums are enabled by CONFIG_HTMM alone. The original Memtis patch
nested their text labels inside CONFIG_MEMORY_BALLOON, leaving the vmstat
array eight entries short when balloon support is disabled. Match the enum
conditionals so that those configurations compile and preserve counter names.

--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1361,6 +1361,7 @@
#ifdef CONFIG_BALLOON_COMPACTION
"balloon_migrate",
#endif
+#endif /* CONFIG_MEMORY_BALLOON */
#ifdef CONFIG_HTMM
"htmm_nr_promoted",
"htmm_nr_demoted",
@@ -1371,7 +1372,6 @@
"htmm_alloc_dram",
"htmm_alloc_nvm",
#endif
-#endif /* CONFIG_MEMORY_BALLOON */
#ifdef CONFIG_DEBUG_TLBFLUSH
"nr_tlb_remote_flush",
"nr_tlb_remote_flush_received",
2 changes: 2 additions & 0 deletions baselines/memtis/setup_memtis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ patch -p1 --dry-run < "$PATCH_FILE"
echo "==> Applying memtis.patch..."
patch -p1 < "$PATCH_FILE"
echo " Patch applied successfully."
git apply "$SCRIPT_DIR/memtis-vmstat.patch"
bash "$SCRIPT_DIR/../common/apply-build-fixes.sh" "$KERNEL_DIR"

# ---------------------------------------------------------------------------
# 3. Kernel configuration
Expand Down
2 changes: 2 additions & 0 deletions baselines/nomad/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ for p in "${PATCHES[@]}"; do
git apply "$p"
done

bash "$SCRIPT_DIR/../common/apply-build-fixes.sh" "$KERNEL_DIR"

# Base the config on the running kernel, then resolve new symbols
# non-interactively. (Do NOT pipe `yes` into `make oldconfig`: under
# `set -o pipefail`, `yes` dies with SIGPIPE and aborts the build.)
Expand Down
2 changes: 1 addition & 1 deletion baselines/soar-alto/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
KERNEL_DIR="$SCRIPT_DIR/linux"
LOGF="$SCRIPT_DIR/log"
PATCHES=("$SCRIPT_DIR/colloid-skx.patch" "$SCRIPT_DIR/colloid-skx-alto.patch")
PATCHES=("$SCRIPT_DIR/colloid-skx.patch" "$SCRIPT_DIR/colloid-skx-alto.patch" "$SCRIPT_DIR/../common/colloid-build.patch")

[[ -d "$KERNEL_DIR" ]] || { echo "ERROR: kernel tree not found at $KERNEL_DIR (clone Linux there first)"; exit 1; }
for p in "${PATCHES[@]}"; do
Expand Down
2 changes: 2 additions & 0 deletions baselines/tpp/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ else
git apply "$PATCH"
fi

bash "$SCRIPT_DIR/../common/apply-build-fixes.sh" "$KERNEL_DIR"

# Base the config on the running kernel, then resolve new symbols
# non-interactively. (Do NOT pipe `yes` into `make oldconfig`: under
# `set -o pipefail`, `yes` dies with SIGPIPE and aborts the build.)
Expand Down
Loading