From patchwork Tue Feb 6 16:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Jeanson X-Patchwork-Id: 85361 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95F903857C4E for ; Tue, 6 Feb 2024 16:31:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtpout.efficios.com (smtpout.efficios.com [IPv6:2607:5300:203:b2ee::31e5]) by sourceware.org (Postfix) with ESMTPS id CA05C3858C66 for ; Tue, 6 Feb 2024 16:28:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA05C3858C66 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 CA05C3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:5300:203:b2ee::31e5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707236896; cv=none; b=Xj54xhAcIhAEwG2CVnfXaOCwB+vMaZ5kFigPcUm5xuDRQrvcGFv6uknIi6VGIPLD7KTfXv8GsL08E53D3Uy/fphy+5+/2C9O/shPBlNhlXs8z7SymyM9a2DKkAc7g2qIpV2nk7ikTsrB0Z5QuDk+TTayBn6r5T+tJp5dy+ER4ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707236896; c=relaxed/simple; bh=vTw191Cg2Q8r4qRPrPRe30z0GrOj5Q+dIN9y6rrE3a4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vAxwAGeRGOOZV62uyO/hFmh7r1+fcFARImBIOvEjohfE+0ajTpTUou0w2WZy9vi2ra787mCQ6lVjHXv6fL7rKJffqLkR9jaB4Wf292QlT9DdlgRsgdOIQ+xUzwn7mO9e0LGWSuSUtLdhry/WbXsXd2zVyPG7tmqvZYLk8YIKd1U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1707236893; bh=vTw191Cg2Q8r4qRPrPRe30z0GrOj5Q+dIN9y6rrE3a4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=geseu1FClqmvu0zPLiWS3HaGBfrZ5ctWNjlJ0kALM/R+FQPIucPI5rvGVdjpYjdD6 SwbWy8YxtFZ1XzOhEkqtt+t6NPVM4DKOG/4WuSM9fnj46ESihinMWebA5W3RrAXCSh nHQ2KpD3uW2c1njQLW7oTimGSHSLWqSVeKRSE/AIKdqjajgBRsl+LkuHB1wCegpQJc 5FfjF0zkKBTuYksNstI7fgbFJ6IDJN12KiJL3TRGWGEHIHCugHwNoIb1Bw1BhTTJIv MXGUmyphekZ+0o2pIUbsFi79SU6DiUCxT0hxpeqVoSi08CaOfMmTwTm+R56l3dzRoE Qfa0xUh3DrFHw== 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 4TTpZj35xlzXSL; Tue, 6 Feb 2024 11:28:13 -0500 (EST) From: Michael Jeanson To: libc-alpha@sourceware.org Cc: Michael Jeanson , Mathieu Desnoyers Subject: [PATCH v8 5/8] nptl: Add rseq internal utils Date: Tue, 6 Feb 2024 11:27:58 -0500 Message-Id: <20240206162801.882585-6-mjeanson@efficios.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240206162801.882585-1-mjeanson@efficios.com> References: <20240206162801.882585-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+patchwork=sourceware.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)