From c076a0bc698c537f72c33bad2925f4e3da59d23c Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 29 Jan 2021 17:07:28 +0000 Subject: malloc: Only support zeroing and not arbitrary memset with mtag The memset api is suboptimal and does not provide much benefit. Memory tagging only needs a zeroing memset (and only for memory that's sized and aligned to multiples of the tag granule), so change the internal api and the target hooks accordingly. This is to simplify the implementation of the target hook. Reviewed-by: DJ Delorie --- sysdeps/aarch64/Makefile | 2 +- sysdeps/aarch64/__mtag_memset_tag.S | 53 -------------------------------- sysdeps/aarch64/__mtag_tag_zero_region.S | 49 +++++++++++++++++++++++++++++ sysdeps/aarch64/libc-mtag.h | 4 +-- sysdeps/generic/libc-mtag.h | 6 ++-- 5 files changed, 55 insertions(+), 59 deletions(-) delete mode 100644 sysdeps/aarch64/__mtag_memset_tag.S create mode 100644 sysdeps/aarch64/__mtag_tag_zero_region.S (limited to 'sysdeps') diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile index d3ab37a..259070c 100644 --- a/sysdeps/aarch64/Makefile +++ b/sysdeps/aarch64/Makefile @@ -41,7 +41,7 @@ endif ifeq ($(subdir),misc) sysdep_headers += sys/ifunc.h sysdep_routines += __mtag_address_get_tag \ - __mtag_memset_tag \ + __mtag_tag_zero_region \ __mtag_new_tag \ __mtag_tag_region diff --git a/sysdeps/aarch64/__mtag_memset_tag.S b/sysdeps/aarch64/__mtag_memset_tag.S deleted file mode 100644 index 3c20288..0000000 --- a/sysdeps/aarch64/__mtag_memset_tag.S +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (C) 2020-2021 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#include - -#ifdef USE_MTAG - -/* Use the same register names and assignments as memset. */ -#include "memset-reg.h" - - .arch armv8.5-a - .arch_extension memtag - -/* NB, only supported on variants with 64-bit pointers. */ - -/* FIXME: This is a minimal implementation. We could do much better than - this for large values of COUNT. */ - -ENTRY(__libc_mtag_memset_with_tag) - - and valw, valw, 255 - orr valw, valw, valw, lsl 8 - orr valw, valw, valw, lsl 16 - orr val, val, val, lsl 32 - mov dst, dstin - -L(loop): - stgp val, val, [dst], #16 - subs count, count, 16 - bne L(loop) -#if 0 - /* This is not currently needed, since for now we are only called - to tag memory that is taggable. */ - ldg dstin, [dstin] // Recover the tag created (might be untagged). -#endif - ret -END (__libc_mtag_memset_with_tag) -#endif /* USE_MTAG */ diff --git a/sysdeps/aarch64/__mtag_tag_zero_region.S b/sysdeps/aarch64/__mtag_tag_zero_region.S new file mode 100644 index 0000000..74d398b --- /dev/null +++ b/sysdeps/aarch64/__mtag_tag_zero_region.S @@ -0,0 +1,49 @@ +/* Copyright (C) 2020-2021 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include + +#ifdef USE_MTAG + + .arch armv8.5-a + .arch_extension memtag + +/* NB, only supported on variants with 64-bit pointers. */ + +/* FIXME: This is a minimal implementation. We could do much better than + this for large values of COUNT. */ + +#define dstin x0 +#define count x1 +#define dst x2 + +ENTRY(__libc_mtag_tag_zero_region) + + mov dst, dstin +L(loop): + stzg dst, [dst], #16 + subs count, count, 16 + bne L(loop) +#if 0 + /* This is not currently needed, since for now we are only called + to tag memory that is taggable. */ + ldg dstin, [dstin] // Recover the tag created (might be untagged). +#endif + ret +END (__libc_mtag_tag_zero_region) +#endif /* USE_MTAG */ diff --git a/sysdeps/aarch64/libc-mtag.h b/sysdeps/aarch64/libc-mtag.h index 979cbb7..f58402c 100644 --- a/sysdeps/aarch64/libc-mtag.h +++ b/sysdeps/aarch64/libc-mtag.h @@ -39,8 +39,8 @@ void *__libc_mtag_tag_region (const void *, size_t) */ void *__libc_mtag_tag_region (void *, size_t); -/* Optimized equivalent to __libc_mtag_tag_region followed by memset. */ -void *__libc_mtag_memset_with_tag (void *, int, size_t); +/* Optimized equivalent to __libc_mtag_tag_region followed by memset to 0. */ +void *__libc_mtag_tag_zero_region (void *, size_t); /* Convert address P to a pointer that is tagged correctly for that location. diff --git a/sysdeps/generic/libc-mtag.h b/sysdeps/generic/libc-mtag.h index e8fc236..4743e87 100644 --- a/sysdeps/generic/libc-mtag.h +++ b/sysdeps/generic/libc-mtag.h @@ -44,12 +44,12 @@ __libc_mtag_tag_region (void *p, size_t n) return p; } -/* Optimized equivalent to __libc_mtag_tag_region followed by memset. */ +/* Optimized equivalent to __libc_mtag_tag_region followed by memset to 0. */ static inline void * -__libc_mtag_memset_with_tag (void *p, int c, size_t n) +__libc_mtag_tag_zero_region (void *p, size_t n) { __libc_mtag_link_error (); - return memset (p, c, n); + return memset (p, 0, n); } /* Convert address P to a pointer that is tagged correctly for that -- cgit v1.1