aboutsummaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2019-10-03 15:23:34 +0930
committerOliver O'Halloran <oohall@gmail.com>2019-10-14 16:27:10 +1100
commite08fee36a5196ca094c5fb7dd1421279b146531f (patch)
tree946784f12439f247431a842599fea0cfcf516413 /external
parentcc34635df59e4f5aa8ad80bc788e74f8cf197880 (diff)
downloadskiboot-e08fee36a5196ca094c5fb7dd1421279b146531f.zip
skiboot-e08fee36a5196ca094c5fb7dd1421279b146531f.tar.gz
skiboot-e08fee36a5196ca094c5fb7dd1421279b146531f.tar.bz2
gard: Fix data corruption when clearing single records
Attempting to clear a specific gard record leads to corruption of the target record rather than the expected removal: $ ./opal-gard -f romulus.pnor list No GARD entries to display $ ./opal-gard -f romulus.pnor create /sys0/node0/proc1 $ ./opal-gard -f romulus.pnor list ID | Error | Type | Path --------------------------------------------------------- 00000001 | 00000000 | Manual | /Sys0/Node0/Proc1 ========================================================= $ ./opal-gard -f romulus.pnor clear 00000001 Clearing gard record 0x00000001...done $ ./opal-gard -f romulus.pnor list ID | Error | Type | Path --------------------------------------------------------- 00000001 | 00000000 | Unknown | /Sys0/Node0/Proc1 ========================================================= The GUARD partition needs to be compacted when clearing records as the end of the list is a sentinel represented by the erased-flash state. The compaction strategy is to read the trailing records and write them to the offset of the record to be removed, followed by writing the sentinel record at the offset of what was previously the last valid record. The corruption occurs due to incorrect calculation of the offset at which the trailing records will be written. Cc: Skiboot Stable <skiboot-stable@lists.ozlabs.org> Fixes: 5616c42d900a ("libflash/blocklevel: Make read/write be ECC agnostic for callers") Signed-off-by: Andrew Jeffery <andrew@aj.id.au> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Diffstat (limited to 'external')
-rw-r--r--external/gard/gard.c2
-rw-r--r--external/gard/test/results/10-clear-single.err0
-rw-r--r--external/gard/test/results/10-clear-single.out7
-rw-r--r--external/gard/test/tests/10-clear-single23
4 files changed, 31 insertions, 1 deletions
diff --git a/external/gard/gard.c b/external/gard/gard.c
index f8c1032..6f75932 100644
--- a/external/gard/gard.c
+++ b/external/gard/gard.c
@@ -570,7 +570,7 @@ static int do_clear_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, v
return rc;
}
- rc = blocklevel_smart_write(ctx->bl, buf_pos - sizeof(gard), buf, buf_len);
+ rc = blocklevel_smart_write(ctx->bl, buf_pos - sizeof(*gard), buf, buf_len);
free(buf);
if (rc) {
fprintf(stderr, "Couldn't write to flash at 0x%08x for len 0x%08x\n",
diff --git a/external/gard/test/results/10-clear-single.err b/external/gard/test/results/10-clear-single.err
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/external/gard/test/results/10-clear-single.err
diff --git a/external/gard/test/results/10-clear-single.out b/external/gard/test/results/10-clear-single.out
new file mode 100644
index 0000000..904e61a
--- /dev/null
+++ b/external/gard/test/results/10-clear-single.out
@@ -0,0 +1,7 @@
+Clearing the entire gard partition...done
+ ID | Error | Type | Path
+---------------------------------------------------------
+ 00000001 | 00000000 | Manual | /Sys0/Node0/Proc1
+=========================================================
+Clearing gard record 0x00000001...done
+No GARD entries to display
diff --git a/external/gard/test/tests/10-clear-single b/external/gard/test/tests/10-clear-single
new file mode 100644
index 0000000..3a5f962
--- /dev/null
+++ b/external/gard/test/tests/10-clear-single
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e
+
+DATA=$(mktemp)
+
+cleanup() {
+ rm -f $DATA
+}
+
+trap cleanup EXIT
+
+dd if=/dev/zero of=$DATA bs=$((0x1000)) count=5 2>/dev/null
+
+run_binary "./opal-gard" "-p -e -f $DATA clear all"
+run_binary "./opal-gard" "-p -e -f $DATA create /sys0/node0/proc1"
+run_binary "./opal-gard" "-p -e -f $DATA list"
+run_binary "./opal-gard" "-p -e -f $DATA clear 00000001"
+run_binary "./opal-gard" "-p -e -f $DATA list"
+
+diff_with_result
+
+pass_test