Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1251510imw; Tue, 5 Jul 2022 06:27:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s7c8kxaXu5HRSbeKFVWmOi8lVdgDV/a33RHk0STz7/Dw0A1S1PZFy81VNwO4HUzCtOIHMb X-Received: by 2002:a17:903:2443:b0:16a:2b65:7edd with SMTP id l3-20020a170903244300b0016a2b657eddmr39992745pls.20.1657027640389; Tue, 05 Jul 2022 06:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657027640; cv=none; d=google.com; s=arc-20160816; b=kiTQzt42xgMQg+FPTjb0TT/HfnywnrV5iHCV52xq4qBnsXnbwNwmvwrFXx9aElmNPB +oLpKbc7i03LyAiHQfHTsOmKSAt2MiR4zgKG1OPVR2i6CCJrRY/hzoJIBGPtt/UGZ/d1 xOXZk+AkM5jqGeFOcQhCCdghokg5W+/kASV1BRrLnA9M2QqOilfUWGjyzxPnlzFDNhP6 7sxXCKgvuKoQ2i5dyY/ApPebv6RsGw6lagoQhyATUpemAMK7pR3QhCCo/3XdrPUGla/x 9Xgf7xeyDQkFD9EsvKoz9IxS++uuK2fb3finC5REgFQo99oof5b/qyHaU+LA5ZvgXyZT eVyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=i2D/1qIMm/LQ5ESK0O1LPoR39MhQeXQzXMze7fW0SR0=; b=XwmqRcX/lxQ15SUbkjo5OBucPdYc+qmdYCyod8FLL3Aa50AeFwv06pQWvWboQx3+J9 L0Lx7e1bg83fOPLA9B0cik7wupsY1tT6YX4phIEBBtGWn6lsYSy58qe3W4Q9xLnwBDEI EvfGZA0U0HActmJgIKCZMjlWurzwq4lK5bFaT7WckhEWKdXF8qZjfSbhIl3a4UqE1zFL fkca9TaJBq/Jg4qVc5moK7pjEU7KY3RgFd8HVNpygh0PzG3hJJ8HmjrB3NGA/nzCS5lk PpfBPsOfAnScz60SEqZFHHROWkJQbi+tkChM9+TnEB4FbyjJV9nsTZ3HOw5bscvHbD60 MG6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hm879B9X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s32-20020a635260000000b00408c9608148si18106963pgl.488.2022.07.05.06.27.08; Tue, 05 Jul 2022 06:27:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hm879B9X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234910AbiGEMKe (ORCPT + 99 others); Tue, 5 Jul 2022 08:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234011AbiGEMFo (ORCPT ); Tue, 5 Jul 2022 08:05:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 474E518E23; Tue, 5 Jul 2022 05:05:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E02AEB817CC; Tue, 5 Jul 2022 12:05:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44F1CC341C7; Tue, 5 Jul 2022 12:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657022706; bh=G9rKul6QLomKJrTc71bzE9xvfktuMjJvjc1FJYL1LoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hm879B9X3IMIcTa6TfDoc+vFB9S/7nZWTQrzsx8p8OzAXW9cStDDecSJ72Wrhgskz wPc5iZKWYyyMpQ36OOlJvqDIhk8om98C6YkciyIkiuW/EBQ7VpV7PZxbtQsaO6Da4e /IPT/i0RvlU4H4AsKoiVtpw8hxw9ol6eaoSyddN0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Desnoyers , "Peter Zijlstra (Intel)" Subject: [PATCH 5.4 40/58] selftests/rseq: Introduce thread pointer getters Date: Tue, 5 Jul 2022 13:58:16 +0200 Message-Id: <20220705115611.424171379@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220705115610.236040773@linuxfoundation.org> References: <20220705115610.236040773@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Desnoyers commit 886ddfba933f5ce9d76c278165d834d114ba4ffc upstream. This is done in preparation for the selftest uplift to become compatible with glibc-2.35. glibc-2.35 exposes the rseq per-thread data in the TCB, accessible at an offset from the thread pointer. The toolchains do not implement accessing the thread pointer on all architectures. Provide thread pointer getters for ppc and x86 which lack (or lacked until recently) toolchain support. Signed-off-by: Mathieu Desnoyers Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20220124171253.22072-7-mathieu.desnoyers@efficios.com Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/rseq/rseq-generic-thread-pointer.h | 25 ++++++++ tools/testing/selftests/rseq/rseq-ppc-thread-pointer.h | 30 +++++++++ tools/testing/selftests/rseq/rseq-thread-pointer.h | 19 ++++++ tools/testing/selftests/rseq/rseq-x86-thread-pointer.h | 40 +++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 tools/testing/selftests/rseq/rseq-generic-thread-pointer.h create mode 100644 tools/testing/selftests/rseq/rseq-ppc-thread-pointer.h create mode 100644 tools/testing/selftests/rseq/rseq-thread-pointer.h create mode 100644 tools/testing/selftests/rseq/rseq-x86-thread-pointer.h --- /dev/null +++ b/tools/testing/selftests/rseq/rseq-generic-thread-pointer.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */ +/* + * rseq-generic-thread-pointer.h + * + * (C) Copyright 2021 - Mathieu Desnoyers + */ + +#ifndef _RSEQ_GENERIC_THREAD_POINTER +#define _RSEQ_GENERIC_THREAD_POINTER + +#ifdef __cplusplus +extern "C" { +#endif + +/* Use gcc builtin thread pointer. */ +static inline void *rseq_thread_pointer(void) +{ + return __builtin_thread_pointer(); +} + +#ifdef __cplusplus +} +#endif + +#endif --- /dev/null +++ b/tools/testing/selftests/rseq/rseq-ppc-thread-pointer.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */ +/* + * rseq-ppc-thread-pointer.h + * + * (C) Copyright 2021 - Mathieu Desnoyers + */ + +#ifndef _RSEQ_PPC_THREAD_POINTER +#define _RSEQ_PPC_THREAD_POINTER + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void *rseq_thread_pointer(void) +{ +#ifdef __powerpc64__ + register void *__result asm ("r13"); +#else + register void *__result asm ("r2"); +#endif + asm ("" : "=r" (__result)); + return __result; +} + +#ifdef __cplusplus +} +#endif + +#endif --- /dev/null +++ b/tools/testing/selftests/rseq/rseq-thread-pointer.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */ +/* + * rseq-thread-pointer.h + * + * (C) Copyright 2021 - Mathieu Desnoyers + */ + +#ifndef _RSEQ_THREAD_POINTER +#define _RSEQ_THREAD_POINTER + +#if defined(__x86_64__) || defined(__i386__) +#include "rseq-x86-thread-pointer.h" +#elif defined(__PPC__) +#include "rseq-ppc-thread-pointer.h" +#else +#include "rseq-generic-thread-pointer.h" +#endif + +#endif --- /dev/null +++ b/tools/testing/selftests/rseq/rseq-x86-thread-pointer.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */ +/* + * rseq-x86-thread-pointer.h + * + * (C) Copyright 2021 - Mathieu Desnoyers + */ + +#ifndef _RSEQ_X86_THREAD_POINTER +#define _RSEQ_X86_THREAD_POINTER + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#if __GNUC_PREREQ (11, 1) +static inline void *rseq_thread_pointer(void) +{ + return __builtin_thread_pointer(); +} +#else +static inline void *rseq_thread_pointer(void) +{ + void *__result; + +# ifdef __x86_64__ + __asm__ ("mov %%fs:0, %0" : "=r" (__result)); +# else + __asm__ ("mov %%gs:0, %0" : "=r" (__result)); +# endif + return __result; +} +#endif /* !GCC 11 */ + +#ifdef __cplusplus +} +#endif + +#endif