From patchwork Thu Feb 1 19:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Jeanson X-Patchwork-Id: 1894173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=b4gVa4NI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TQq3N6kGvz23gx for ; Fri, 2 Feb 2024 06:39:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E7B54385E01D for ; Thu, 1 Feb 2024 19:39:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by sourceware.org (Postfix) with ESMTPS id 085B63857B95 for ; Thu, 1 Feb 2024 19:37:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 085B63857B95 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 085B63857B95 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706816247; cv=none; b=MLa3nmx1uipIMKiBk6QlMshDA3phj+3PYSnB46eDp2t/U4n0Shmnxs+37rVfN3P+O3+cm7tqcA1cLW5MaPk1ZRkjzsIePix59X9DYpRwKoxWj20EPl0tJuTUUOu00SG94+DdhgURlC7SBlkv9GrtJzDka7m8XzX13hiQf9hAcBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706816247; c=relaxed/simple; bh=vTw191Cg2Q8r4qRPrPRe30z0GrOj5Q+dIN9y6rrE3a4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=B8ut7QzYdxY05SYpsuwuHynjWYO4MacbGBv/gT3jazDsVqkgKw/TiWSj65CHyjEQ/QCdQsCAA1jzD1/Mu0AKumQ0nrg4UaM3gUVT8JwUrV2U37nkIVOlEFxSntUvah8y0P5UqY0ePq+UwS6VFq185sd78JZBIfO8/PAW7vw7qyc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1706816244; bh=vTw191Cg2Q8r4qRPrPRe30z0GrOj5Q+dIN9y6rrE3a4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b4gVa4NIYkyTMjKrf3agk5FV3bQBGGbx3LAxaqt1B83bRAc0hkZ7udn6UTE6/7YSx i94QDHogP+r5cDYWqcBpaDAOUizosWSI3KhW87Q+PmzjX27pGevqUmUkLl0l7Uzftm FNkqMASxfXU4uTCONbMfAsm6ZBTyysSft4VJq1+lKaczysDJEyPTWm98jSgtKAo3as nxEv/BThVdFmngccLtzPVUGoDvzFE9QCs0EcN+uGpwh37/ROeQIlzsx6mAxzTnGmWG ty9LmkYkqLyNF0NfRa6PtvmUzzNSrFwgoRFUFve+wkaOSsczwKym+imG0nZeoDuCmV 9CQA5+G+tJXog== Received: from laptop-mjeanson.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4TQq1J3cKMzX3y; Thu, 1 Feb 2024 14:37:24 -0500 (EST) From: Michael Jeanson To: libc-alpha@sourceware.org Cc: Michael Jeanson , Florian Weimer , Carlos O'Donell , Mathieu Desnoyers Subject: [PATCH v7 5/8] nptl: Add rseq internal utils Date: Thu, 1 Feb 2024 14:36:45 -0500 Message-Id: <20240201193648.584917-6-mjeanson@efficios.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201193648.584917-1-mjeanson@efficios.com> References: <20240201193648.584917-1-mjeanson@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Implement internal rseq utils in preparation for their use in rseq_load32_load32_relaxed(). This implementation is imported from the librseq project. Co-authored-by: Mathieu Desnoyers Signed-off-by: Mathieu Desnoyers Signed-off-by: Michael Jeanson --- sysdeps/unix/sysv/linux/rseq-internal.h | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h index a63e4afbdb..b6c29c14cc 100644 --- a/sysdeps/unix/sysv/linux/rseq-internal.h +++ b/sysdeps/unix/sysv/linux/rseq-internal.h @@ -41,12 +41,68 @@ struct rseq_area uint32_t mm_cid; }; +/* + * gcc prior to 4.8.2 miscompiles asm goto. + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 + * + * gcc prior to 8.1.0 miscompiles asm goto at O1. + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103908 + * + * clang prior to version 13.0.1 miscompiles asm goto at O2. + * https://github.com/llvm/llvm-project/issues/52735 + * + * Work around these issues by adding a volatile inline asm with + * memory clobber in the fallthrough after the asm goto and at each + * label target. Emit this for all compilers in case other similar + * issues are found in the future. + */ +#define rseq_after_asm_goto() __asm__ __volatile__ ("" : : : "memory") + +#define __rseq_str_1(x) #x +#define __rseq_str(x) __rseq_str_1(x) + +/* Offset of rseq_cs field in struct rseq. */ +#define RSEQ_CS_OFFSET 8 + +#define rseq_sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) +#define rseq_offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + rseq_sizeof_field(TYPE, MEMBER)) + +/* Returns a pointer to the current thread rseq area. */ static inline struct rseq_area * rseq_get_area(void) { return (struct rseq_area *) ((char *) __thread_pointer() + GLRO (dl_tls_rseq_offset)); } +/* Returns the int value of 'rseq_area->cpu_id'. */ +static inline int +rseq_get_cpu_id(void) +{ + return (int) RSEQ_GETMEM_VOLATILE (rseq_get_area(), cpu_id); +} + +/* Returns true if the rseq registration is active. */ +static inline bool +rseq_is_registered(void) +{ + return rseq_get_cpu_id() >= 0; +} + +/* Returns true if the current rseq registration has the 'node_id' field. */ +static inline bool +rseq_node_id_available(void) +{ + return __rseq_feature_size >= rseq_offsetofend(struct rseq_area, node_id); +} + +/* Returns true if the current rseq registration has the 'mm_cid' field. */ +static inline bool +rseq_mm_cid_available(void) +{ + return __rseq_feature_size >= rseq_offsetofend(struct rseq_area, mm_cid); +} + #ifdef RSEQ_SIG static inline bool rseq_register_current_thread (struct pthread *self, bool do_rseq)