Skip to content

Commit

Permalink
Merge branch 'refs/heads/upstream-HEAD' into repo-HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Delphix Engineering committed Oct 11, 2024
2 parents 625b60a + 764baba commit 15eb240
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 43 deletions.
7 changes: 4 additions & 3 deletions src/addrxlat/x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,10 @@ linux_ktext_extents(struct os_init_data *ctl,

linearoff = ctl->sys->meth[ADDRXLAT_SYS_METH_KTEXT].param.linear.off;
*high = *low;
status = highest_linear(&step, high, LINUX_KTEXT_END_NOKASLR,
linearoff);
if (status == ADDRXLAT_OK && *high == LINUX_KTEXT_END_NOKASLR) {
if (*high <= LINUX_KTEXT_END_NOKASLR)
status = highest_linear(&step, high, LINUX_KTEXT_END_NOKASLR,
linearoff);
if (status == ADDRXLAT_OK && *high >= LINUX_KTEXT_END_NOKASLR) {
++*high;
status = highest_linear(&step, high, LINUX_KTEXT_END,
linearoff);
Expand Down
2 changes: 1 addition & 1 deletion src/kdumpfile/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ read_blob_attr(kdump_ctx_t *ctx, unsigned fidx, off_t off, size_t size,
struct fcache_chunk fch;
kdump_status ret;

ret = fcache_get_chunk(ctx->shared->fcache, &fch, size, fidx, off);
ret = flatmap_get_chunk(ctx->shared->flatmap, &fch, size, fidx, off);
if (ret != KDUMP_OK)
return set_error(ctx, ret,
"Cannot read %s (%zu bytes at %llu in %s)",
Expand Down
7 changes: 7 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ test_scripts = \
diskdump-empty-s390x \
diskdump-empty-x86_64 \
diskdump-basic-raw \
diskdump-basic-vmcoreinfo \
diskdump-flat-raw \
diskdump-flat-vmcoreinfo \
diskdump-multiread \
diskdump-excluded \
diskdump-split \
Expand Down Expand Up @@ -295,6 +297,7 @@ test_scripts = \
xlat-linux-x86_64-ktext-40M \
xlat-linux-x86_64-ktext-512M \
xlat-linux-x86_64-ktext-520M \
xlat-linux-x86_64-ktext-54M-kaslr \
xlat-linux-x86_64-old \
xlat-linux-x86_64-old-nover \
xlat-linux-x86_64-2.6.11 \
Expand Down Expand Up @@ -392,6 +395,7 @@ dist_check_DATA = \
diskdump-split.expect.3 \
sys-xlat-x86_64-linux.expect \
sys-xlat-x86_64-linux-xen.expect \
vmcoreinfo.data \
xlatmap.expect \
xlat-os-aarch64-none.expect \
xlat-os-ia32-none.expect \
Expand Down Expand Up @@ -476,6 +480,9 @@ dist_check_DATA = \
xlat-linux-x86_64-ktext-520M.data \
xlat-linux-x86_64-ktext-520M.expect \
xlat-linux-x86_64-ktext-520M.sym \
xlat-linux-x86_64-ktext-54M-kaslr.data \
xlat-linux-x86_64-ktext-54M-kaslr.expect \
xlat-linux-x86_64-ktext-54M-kaslr.sym \
xlat-linux-x86_64-old.expect \
xlat-linux-x86_64-old-nover.data \
xlat-linux-x86_64-old-nover.expect \
Expand Down
3 changes: 2 additions & 1 deletion tests/diskdump-basic
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ echo "@0 $pageflags" > "$datafile"
cat "$expectfile" >> "$datafile"

./mkdiskdump "$dumpfile" <<EOF
$extraparam
version = 6
arch_name = x86_64
block_size = 4096
Expand All @@ -32,6 +31,7 @@ uts.domainname = (none)
nr_cpus = 1

DATA = $datafile
$extraparam
EOF
rc=$?
if [ $rc -ne 0 ]; then
Expand All @@ -43,6 +43,7 @@ echo "Created DISKDUMP dump: $dumpfile"
./checkattr "$dumpfile" <<EOF
file.pagemap = bitmap: 1
memory.pagemap = bitmap: 1
$extracheckattr
EOF
rc=$?
if [ $rc -ne 0 ]; then
Expand Down
20 changes: 20 additions & 0 deletions tests/diskdump-basic-vmcoreinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/sh

#
# Create a diskdump file with VMCOREINFO data. The corresponding header field
# was added in v3 and superseded by ELF notes in v4, so the version is forced
# to v3 here.
#

pageflags=raw
extraparam="
version = 3
VMCOREINFO = vmcoreinfo.data
"
extracheckattr="
linux.vmcoreinfo.lines.OSRELEASE = string:6.4.3-1-default
linux.vmcoreinfo.lines.PAGESIZE = string:4096
linux.vmcoreinfo.lines.CRASHTIME = string:1689103980
"
. "$srcdir"/diskdump-basic
exit 0
20 changes: 20 additions & 0 deletions tests/diskdump-flat-vmcoreinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/sh

#
# Create a flattened diskdump file with VMCOREINFO data.
# See also diskdump-basic-vmcoreinfo.
#

pageflags=raw
extraparam="
flattened = yes
version = 3
VMCOREINFO = vmcoreinfo.data
"
extracheckattr="
linux.vmcoreinfo.lines.OSRELEASE = string:6.4.3-1-default
linux.vmcoreinfo.lines.PAGESIZE = string:4096
linux.vmcoreinfo.lines.CRASHTIME = string:1689103980
"
. "$srcdir"/diskdump-basic
exit 0
117 changes: 79 additions & 38 deletions tests/mkdiskdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ enum compress_method {
COMPRESS_ZSTD,
};

struct data_block {
off_t filepos;
struct blob *blob;
};

static bool flattened;
static unsigned long long flattened_type = MDF_TYPE_FLAT_HEADER;
static unsigned long long flattened_version = MDF_VERSION_FLAT_HEADER;
Expand Down Expand Up @@ -123,9 +118,9 @@ static unsigned long long split;
static unsigned long long start_pfn;
static unsigned long long end_pfn;

static struct data_block vmcoreinfo;
static struct data_block notes;
static struct data_block eraseinfo;
static struct blob *vmcoreinfo;
static struct blob *notes;
static struct blob *eraseinfo;

static char *vmcoreinfo_file;
static char *note_file;
Expand Down Expand Up @@ -251,6 +246,7 @@ writeheader_32(FILE *f)
struct timeval tv;
struct disk_dump_header_32 hdr;
struct kdump_sub_header_32 subhdr;
off_t pos;

if (gettimeofday(&tv, NULL) != 0) {
perror("gettimeofday");
Expand Down Expand Up @@ -290,23 +286,45 @@ writeheader_32(FILE *f)
if (write_chunk(f, 0, &hdr, sizeof hdr, "header"))
return TEST_ERR;

pos = DISKDUMP_HEADER_BLOCKS * block_size + sizeof(subhdr);
subhdr.phys_base = htodump32(be, phys_base);
subhdr.dump_level = htodump32(be, dump_level);
subhdr.split = htodump32(be, split);
subhdr.start_pfn = htodump32(be, start_pfn);
subhdr.end_pfn = htodump32(be, end_pfn);
subhdr.offset_vmcoreinfo = htodump64(be, vmcoreinfo.filepos);
subhdr.size_vmcoreinfo = htodump32(be, (vmcoreinfo.blob
? vmcoreinfo.blob->length
: 0));
subhdr.offset_note = htodump64(be, notes.filepos);
subhdr.size_note = htodump32(be, (notes.blob
? notes.blob->length
: 0));
subhdr.offset_eraseinfo = htodump64(be, eraseinfo.filepos);
subhdr.size_eraseinfo = htodump32(be, (eraseinfo.blob
? eraseinfo.blob->length
: 0));
if (vmcoreinfo) {
subhdr.offset_vmcoreinfo = htodump64(be, pos);
subhdr.size_vmcoreinfo = htodump32(be, vmcoreinfo->length);
if (write_chunk(f, pos, vmcoreinfo->data, vmcoreinfo->length,
"VMCOREINFO"))
return TEST_ERR;
pos += vmcoreinfo->length;
} else {
subhdr.offset_vmcoreinfo = htodump64(be, 0);
subhdr.size_vmcoreinfo = htodump32(be, 0);
}
if (notes) {
subhdr.offset_note = htodump64(be, pos);
subhdr.size_note = htodump32(be, notes->length);
if (write_chunk(f, pos, notes->data, notes->length,
"ELF notes"))
return TEST_ERR;
pos += notes->length;
} else {
subhdr.offset_note = htodump64(be, 0);
subhdr.size_note = htodump32(be, 0);
}
if (eraseinfo) {
subhdr.offset_eraseinfo = htodump64(be, pos);
subhdr.size_eraseinfo = htodump32(be, eraseinfo->length);
if (write_chunk(f, pos, notes->data, notes->length,
"eraseinfo"))
return TEST_ERR;
pos += eraseinfo->length;
} else {
subhdr.offset_eraseinfo = htodump64(be, 0);
subhdr.size_eraseinfo = htodump32(be, 0);
}
subhdr.start_pfn_64 = htodump64(be, start_pfn);
subhdr.end_pfn_64 = htodump64(be, end_pfn);
subhdr.max_mapnr_64 = htodump64(be, max_mapnr);
Expand All @@ -324,6 +342,7 @@ writeheader_64(FILE *f)
struct timeval tv;
struct disk_dump_header_64 hdr;
struct kdump_sub_header_64 subhdr;
off_t pos;

if (gettimeofday(&tv, NULL) != 0) {
perror("gettimeofday");
Expand Down Expand Up @@ -363,23 +382,45 @@ writeheader_64(FILE *f)
if (write_chunk(f, 0, &hdr, sizeof hdr, "header"))
return TEST_ERR;

pos = DISKDUMP_HEADER_BLOCKS * block_size + sizeof(subhdr);
subhdr.phys_base = htodump64(be, phys_base);
subhdr.dump_level = htodump32(be, dump_level);
subhdr.split = htodump32(be, split);
subhdr.start_pfn = htodump64(be, start_pfn);
subhdr.end_pfn = htodump64(be, end_pfn);
subhdr.offset_vmcoreinfo = htodump64(be, vmcoreinfo.filepos);
subhdr.size_vmcoreinfo = htodump64(be, (vmcoreinfo.blob
? vmcoreinfo.blob->length
: 0));
subhdr.offset_note = htodump64(be, notes.filepos);
subhdr.size_note = htodump64(be, (notes.blob
? notes.blob->length
: 0));
subhdr.offset_eraseinfo = htodump64(be, eraseinfo.filepos);
subhdr.size_eraseinfo = htodump64(be, (eraseinfo.blob
? eraseinfo.blob->length
: 0));
if (vmcoreinfo) {
subhdr.offset_vmcoreinfo = htodump64(be, pos);
subhdr.size_vmcoreinfo = htodump64(be, vmcoreinfo->length);
if (write_chunk(f, pos, vmcoreinfo->data, vmcoreinfo->length,
"VMCOREINFO"))
return TEST_ERR;
pos += vmcoreinfo->length;
} else {
subhdr.offset_vmcoreinfo = htodump64(be, 0);
subhdr.size_vmcoreinfo = htodump64(be, 0);
}
if (notes) {
subhdr.offset_note = htodump64(be, pos);
subhdr.size_note = htodump64(be, notes->length);
if (write_chunk(f, pos, notes->data, notes->length,
"ELF notes"))
return TEST_ERR;
pos += notes->length;
} else {
subhdr.offset_note = htodump64(be, 0);
subhdr.size_note = htodump64(be, 0);
}
if (eraseinfo) {
subhdr.offset_eraseinfo = htodump64(be, pos);
subhdr.size_eraseinfo = htodump64(be, eraseinfo->length);
if (write_chunk(f, pos, notes->data, notes->length,
"eraseinfo"))
return TEST_ERR;
pos += eraseinfo->length;
} else {
subhdr.offset_eraseinfo = htodump64(be, 0);
subhdr.size_eraseinfo = htodump64(be, 0);
}
subhdr.start_pfn_64 = htodump64(be, start_pfn);
subhdr.end_pfn_64 = htodump64(be, end_pfn);
subhdr.max_mapnr_64 = htodump64(be, max_mapnr);
Expand Down Expand Up @@ -904,20 +945,20 @@ main(int argc, char **argv)
return rc;

if (vmcoreinfo_file) {
vmcoreinfo.blob = slurp(vmcoreinfo_file);
if (vmcoreinfo.blob == NULL)
vmcoreinfo = slurp(vmcoreinfo_file);
if (vmcoreinfo == NULL)
return TEST_ERR;
}

if (note_file) {
notes.blob = slurp(note_file);
if (notes.blob == NULL)
notes = slurp(note_file);
if (notes == NULL)
return TEST_ERR;
}

if (eraseinfo_file) {
eraseinfo.blob = slurp(eraseinfo_file);
if (eraseinfo.blob == NULL)
eraseinfo = slurp(eraseinfo_file);
if (eraseinfo == NULL)
return TEST_ERR;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/vmcoreinfo.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OSRELEASE=6.4.3-1-default
PAGESIZE=4096
CRASHTIME=1689103980
14 changes: 14 additions & 0 deletions tests/xlat-linux-x86_64-ktext-54M-kaslr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash

#
# Check Linux X86_64 translation with a 54M kASLR ktext mapping starting
# above the fixed (non-kASLR) virtual address region.
#

opts=(
arch=x86_64
ostype=linux
phys_base=0x23c00000
)

. "$srcdir"/xlat-os-common
9 changes: 9 additions & 0 deletions tests/xlat-linux-x86_64-ktext-54M-kaslr.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# kernel text
@0x4c610ff8
000000004c615067
@0x4c615ff0
000000004c616063
@0x4c616000
0000000000000000*313
000000004ae001e1*27+200000
0000000000000000*172
40 changes: 40 additions & 0 deletions tests/xlat-linux-x86_64-ktext-54M-kaslr.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@rootpgt: PGT
target_as=MACHPHYSADDR
root=KVADDR:0xffffffffa8a10000
pte_mask=0x0
pte_format=x86_64
fields=12,9,9,9,9

@ktext: LINEAR
target_as=KPHYSADDR
off=0xa3c00000

@machphys_kphys: LINEAR
target_as=KPHYSADDR
off=0x0

@kphys_machphys: LINEAR
target_as=MACHPHYSADDR
off=0x0

KV -> HW:
0-7fffffffffff: @rootpgt
800000000000-ffff7fffffffffff: NONE
ffff800000000000-ffffffffffffffff: @rootpgt

KV -> PHYS:
0-7fffffffffff: @rootpgt
800000000000-ffff7fffffffffff: NONE
ffff800000000000-ffffffffa71fffff: @rootpgt
ffffffffa7200000-ffffffffaa7fffff: @ktext
ffffffffaa800000-ffffffffffffffff: @rootpgt

KPHYS -> DIRECT:

MACHPHYS -> KPHYS:
0-fffffffffffff: @machphys_kphys
10000000000000-ffffffffffffffff: NONE

KPHYS -> MACHPHYS:
0-fffffffffffff: @kphys_machphys
10000000000000-ffffffffffffffff: NONE
4 changes: 4 additions & 0 deletions tests/xlat-linux-x86_64-ktext-54M-kaslr.sym
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@VALUE(init_top_pgt)
ffffffffa8a10000
@VALUE(_stext)
ffffffffa7200000

0 comments on commit 15eb240

Please sign in to comment.