glibc:nsz/mtag-2

Last commit made on 2021-03-19
Get this branch:
git clone -b nsz/mtag-2 https://git.launchpad.net/glibc

Branch merges

Branch information

Name:
nsz/mtag-2
Repository:
lp:glibc

Recent commits

57b9625... by Szabolcs Nagy <email address hidden> on 2021-03-15

malloc: Ensure mtag code path in checked_request2size is cold

This is a workaround (hack) for a gcc optimization issue (PR 99551).
Without this the generated code may evaluate the expression in the
cold path which causes performance regression for small allocations
in the memory tagging disabled (common) case.

7203bf2... by Szabolcs Nagy <email address hidden> on 2021-03-12

malloc: Remove unnecessary tagging around _mid_memalign

The internal _mid_memalign already returns newly tagged memory.
(__libc_memalign and posix_memalign already relied on this, this
patch fixes the other call sites.)

39adedf... by Szabolcs Nagy <email address hidden> on 2021-03-11

malloc: Rename chunk2rawmem

The previous patch ensured that all chunk to mem computations use
chunk2rawmem, so now we can rename it to chunk2mem, and in the few
cases where the tag of mem is relevant chunk2mem_tag can be used.

Replaced tag_at (chunk2rawmem (x)) with chunk2mem_tag (x).
Renamed chunk2rawmem to chunk2mem.

e24c5ca... by Szabolcs Nagy <email address hidden> on 2021-03-09

malloc: Use chunk2rawmem throughout

The difference between chunk2mem and chunk2rawmem is that the latter
does not get the memory tag for the returned pointer. It turns out
chunk2rawmem almost always works:

The input of chunk2mem is a chunk pointer that is untagged so it can
access the chunk header. All memory that is not user allocated heap
memory is untagged, which in the current implementation means that it
has the 0 tag, but this patch does not rely on the tag value. The
patch relies on that chunk operations are either done on untagged
chunks or without doing memory access to the user owned part.

Internal interface contracts:

sysmalloc: Returns untagged memory.
_int_malloc: Returns untagged memory.
_int_free: Takes untagged memory.
_int_memalign: Returns untagged memory.
_int_realloc: Takes and returns tagged memory.

So only _int_realloc and functions outside this list need care.
Alignment checks do not need the right tag and tcache works with
untagged memory.

tag_at was kept in realloc after an mremap, which is not strictly
necessary, since the pointer is only used to retag the memory, but this
way the tag is guaranteed to be different from the old tag.

4aadeff... by Szabolcs Nagy <email address hidden> on 2021-03-12

malloc: Use different tag after mremap

The comment explained why different tag is used after mremap, but
for that correctly tagged pointer should be passed to tag_new_usable.
Use chunk2mem to get the tag.

4af59f6... by Szabolcs Nagy <email address hidden> on 2021-03-08

malloc: Use memsize instead of CHUNK_AVAILABLE_SIZE

This is a pure refactoring change that does not affect behaviour.

The CHUNK_AVAILABLE_SIZE name was unclear, the memsize name tries to
follow the existing convention of mem denoting the allocation that is
handed out to the user, while chunk is its internally used container.

The user owned memory for a given chunk starts at chunk2mem(p) and
the size is memsize(p). It is not valid to use on dumped heap chunks.

Moved the definition next to other chunk and mem related macros.

601c47c... by Szabolcs Nagy <email address hidden> on 2021-02-09

aarch64: Optimize __libc_mtag_tag_zero_region

This is a target hook for memory tagging, the original was a naive
implementation. Uses the same algorithm as __libc_mtag_tag_region,
but with instructions that also zero the memory. This was not
benchmarked on real cpu, but expected to be faster than the naive
implementation.

138ff9a... by Szabolcs Nagy <email address hidden> on 2021-02-09

aarch64: Optimize __libc_mtag_tag_region

This is a target hook for memory tagging, the original was a naive
implementation. The optimized version relies on "dc gva" to tag 64
bytes at a time for large allocations and optimizes small cases without
adding too many branches. This was not benchmarked on real cpu, but
expected to be faster than the naive implementation.

5def14a... by Szabolcs Nagy <email address hidden> on 2021-02-04

aarch64: inline __libc_mtag_new_tag

This is a common operation when heap tagging is enabled, so inline the
instructions instead of using an extern call.

8ab2764... by Szabolcs Nagy <email address hidden> on 2021-02-04

aarch64: inline __libc_mtag_address_get_tag

This is a common operation when heap tagging is enabled, so inline the
instruction instead of using an extern call.

The .inst directive is used instead of the name of the instruction (or
acle intrinsics) because malloc.c is not compiled for armv8.5-a+memtag
architecture, runtime cpu support detection is used.

Prototypes are removed from the comments as they were not always
correct.