[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v4 5/7] arch: provide thread-local storage helper functions
Because the layout of the TLS area is architecture-specific, we provide helper functions to get the required size and alignment of the TLS area, as well as a help function that does the actual copying of the TLS "master copy" according the layout required by the ABI. Only the x86-64 implementation is complete and tested. Arm32 is pure boilerplate. Arm64 has some rough guesses about how the layout should look like, but is untested. Signed-off-by: Florian Schmidt <florian.schmidt@xxxxxxxxx> Reviewed-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- arch/arm/arm/include/uk/asm/tls.h | 62 ++++++++++++++++++++++++ arch/arm/arm64/include/uk/asm/tls.h | 72 ++++++++++++++++++++++++++++ arch/x86/x86_64/include/uk/asm/tls.h | 68 ++++++++++++++++++++++++++ include/uk/arch/tls.h | 40 ++++++++++++++++ plat/kvm/arm/link64.lds.S | 2 + plat/xen/arm/link32.lds.S | 2 + 6 files changed, 246 insertions(+) create mode 100644 arch/arm/arm/include/uk/asm/tls.h create mode 100644 arch/arm/arm64/include/uk/asm/tls.h create mode 100644 arch/x86/x86_64/include/uk/asm/tls.h create mode 100644 include/uk/arch/tls.h diff --git a/arch/arm/arm/include/uk/asm/tls.h b/arch/arm/arm/include/uk/asm/tls.h new file mode 100644 index 00000000..67d6f264 --- /dev/null +++ b/arch/arm/arm/include/uk/asm/tls.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Florian Schmidt <florian.schmidt@xxxxxxxxx> + * + * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#ifndef __UKARCH_TLS_H__ +#error Do not include this header directly +#endif + +#error Thread-local storage not implemented for arm32! + +#include <uk/arch/types.h> + +extern char _tls_start[], _etdata[], _tls_end[]; + +static inline __sz ukarch_tls_area_size(void) +{ + return 0; +} + +static inline __sz ukarch_tls_area_align(void) +{ + return 1; +} + +static inline void ukarch_tls_copy(void *tls_area) +{ +} + +static inline void *ukarch_tls_pointer(void *tls_area) +{ + return NULL; +} diff --git a/arch/arm/arm64/include/uk/asm/tls.h b/arch/arm/arm64/include/uk/asm/tls.h new file mode 100644 index 00000000..829334e7 --- /dev/null +++ b/arch/arm/arm64/include/uk/asm/tls.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Florian Schmidt <florian.schmidt@xxxxxxxxx> + * + * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#ifndef __UKARCH_TLS_H__ +#error Do not include this header directly +#endif + +#warning Thread-local storage has not been tested on aarch64! + +#include <uk/arch/types.h> +#include <string.h> + +extern char _tls_start[], _etdata[], _tls_end[]; + +static inline __sz ukarch_tls_area_size(void) +{ + /* aarch64 ABI adds 16 bytes of TCB at the beginning of the TLS area, + * followed by the actual TLS data. + */ + return _tls_end - _tls_start + 16; +} + +static inline __sz ukarch_tls_area_align(void) +{ + return 8; +} + +static inline void ukarch_tls_area_copy(void *tls_area) +{ + __sz tls_data_len = _etdata - _tls_start; + __sz tls_bss_len = _tls_end - _etdata; + + memset(tls_area, 0, 16); + memcpy(tls_area + 16, _tls_start, tls_data_len); + memset(tls_area + tls_data_len + 16, 0, tls_bss_len); +} + +static inline void *ukarch_tls_pointer(void *tls_area) +{ + return tls_area; +} diff --git a/arch/x86/x86_64/include/uk/asm/tls.h b/arch/x86/x86_64/include/uk/asm/tls.h new file mode 100644 index 00000000..70bbc1d1 --- /dev/null +++ b/arch/x86/x86_64/include/uk/asm/tls.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Florian Schmidt <florian.schmidt@xxxxxxxxx> + * + * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#ifndef __UKARCH_TLS_H__ +#error Do not include this header directly +#endif + +#include <uk/arch/types.h> +#include <string.h> + +extern char _tls_start[], _etdata[], _tls_end[]; + +static inline __sz ukarch_tls_area_size(void) +{ + /* x86_64 ABI requires that fs:%0 contains the address of itself, to + * allow certain optimizations. Hence, the overall size of the size of + * the TLS area, plus 8 bytes. + */ + return _tls_end - _tls_start + 8; +} + +static inline __sz ukarch_tls_area_align(void) +{ + return 8; +} + +static inline void ukarch_tls_area_copy(void *tls_area) +{ + __sz tls_len = _tls_end - _tls_start; + __sz tls_data_len = _etdata - _tls_start; + __sz tls_bss_len = _tls_end - _etdata; + + memcpy(tls_area, _tls_start, tls_data_len); + memset(tls_area + tls_data_len, 0, tls_bss_len); + /* x86_64 ABI requires that fs:%0 contains the address of itself. */ + *((__uptr *)(tls_area + tls_len)) = (__uptr)(tls_area + tls_len); +} diff --git a/include/uk/arch/tls.h b/include/uk/arch/tls.h new file mode 100644 index 00000000..bfbcd5fc --- /dev/null +++ b/include/uk/arch/tls.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Florian Schmidt <florian.schmidt@xxxxxxxxx> + * + * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#ifndef __UKARCH_TLS_H__ +#define __UKARCH_TLS_H__ + +#include <uk/asm/tls.h> + +#endif /* __UKARCH_TLS_H__ */ diff --git a/plat/kvm/arm/link64.lds.S b/plat/kvm/arm/link64.lds.S index 753d1696..d08abe48 100644 --- a/plat/kvm/arm/link64.lds.S +++ b/plat/kvm/arm/link64.lds.S @@ -103,6 +103,8 @@ SECTIONS { _ectors = .; . = ALIGN(__PAGE_SIZE); + TLS_SECTIONS + /* Read-write data that is initialized explicitly in code */ _data = .; .data : diff --git a/plat/xen/arm/link32.lds.S b/plat/xen/arm/link32.lds.S index 642b5eb3..cade70a1 100644 --- a/plat/xen/arm/link32.lds.S +++ b/plat/xen/arm/link32.lds.S @@ -81,6 +81,8 @@ SECTIONS . = ALIGN(__PAGE_SIZE); _ectors = .; + TLS_SECTIONS + /* Data */ _data = .; .data : { -- 2.21.0 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |