From patchwork Fri Jan 14 12:41:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50030 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 6A4B93858D35 for ; Fri, 14 Jan 2022 12:44:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A4B93858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164297; bh=tqM4mIuIGowqkloLu8ZiH8EdDoZBVAaEiYt0lDMCq14=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=KuUjB5dxNRq8QonsIj8ccx2aei/IkDbrWmL51zriQz9h5mA4FPLzWkEufhlaxZCTr wlt/zfwY7o4mjiJxFOoYkSpbOo9DXUZtiC1Nh+QCZDX4nEYknp21BhjZzo01vd0wPY wmFA+5z7ms3fJSAAo1H9uYClOivnxaO4DEH0qJEQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DC12A383602A for ; Fri, 14 Jan 2022 12:41:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC12A383602A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-261-sk9wCAhCOrClfYxftLvLZA-1; Fri, 14 Jan 2022 07:41:05 -0500 X-MC-Unique: sk9wCAhCOrClfYxftLvLZA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1820984BA40; Fri, 14 Jan 2022 12:41:04 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DF3B26576; Fri, 14 Jan 2022 12:41:02 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 6/7] x86: Add x86-64-vN check to early startup In-Reply-To: References: X-From-Line: efa4a91cd090981e827e7ff90dad97475aadfd26 Mon Sep 17 00:00:00 2001 Message-Id: Date: Fri, 14 Jan 2022 13:41:01 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This ISA level covers the glibc build itself. cannot be used because this check (by design) happens before DL_PLATFORM_INIT and the x86 CPU flags initialization. --- sysdeps/x86/Makefile | 1 + sysdeps/x86/dl-get-cpu-features.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 402986ff68..0c5ab42667 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -7,6 +7,7 @@ sysdep_routines += get-cpuid-feature-leaf sysdep-dl-routines += dl-get-cpu-features sysdep_headers += sys/platform/x86.h bits/platform/x86.h +CFLAGS-dl-get-cpu-features.os += $(early-cflags) CFLAGS-get-cpuid-feature-leaf.o += $(no-stack-protector) tests += tst-get-cpu-features tst-get-cpu-features-static \ diff --git a/sysdeps/x86/dl-get-cpu-features.c b/sysdeps/x86/dl-get-cpu-features.c index 6339c9df4e..4ec0e5d2af 100644 --- a/sysdeps/x86/dl-get-cpu-features.c +++ b/sysdeps/x86/dl-get-cpu-features.c @@ -20,6 +20,7 @@ #ifdef SHARED # include +# include /* NB: Normally, DL_PLATFORM_INIT calls init_cpu_features to initialize CPU features in dynamic executable. But when loading ld.so inside of @@ -36,7 +37,35 @@ _dl_x86_init_cpu_features (void) { struct cpu_features *cpu_features = __get_cpu_features (); if (cpu_features->basic.kind == arch_kind_unknown) - init_cpu_features (cpu_features); + { + init_cpu_features (cpu_features); + +# if IS_IN (rtld) + /* See isa-level.c. */ +# if defined GCCMACRO__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 \ + && defined HAVE_X86_LAHF_SAHF && defined GCCMACRO__POPCNT__ \ + && defined GCCMACRO__SSE3__ && defined GCCMACRO__SSSE3__ \ + && defined GCCMACRO__SSE4_1__ && defined GCCMACRO__SSE4_2__ + if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V2)) + _dl_fatal_printf ("\ +Fatal glibc error: CPU does not support x86-64-v%d\n", 2); +# if defined GCCMACRO__AVX__ && defined GCCMACRO__AVX2__ \ + && defined GCCMACRO__F16C__ && defined GCCMACRO__FMA__ \ + && defined GCCMACRO__LZCNT__ && defined HAVE_X86_MOVBE + if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V3)) + _dl_fatal_printf ("\ +Fatal glibc error: CPU does not support x86-64-v%d\n", 3); +# if defined GCCMACRO__AVX512F__ && defined GCCMACRO__AVX512BW__ \ + && defined GCCMACRO__AVX512CD__ && defined GCCMACRO__AVX512DQ__ \ + && defined GCCMACRO__AVX512VL__ + if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V4)) + _dl_fatal_printf ("\ +Fatal glibc error: CPU does not support x86-64-v%d\n", 4); +# endif /* ISA level 4 */ +# endif /* ISA level 3 */ +# endif /* ISA level 2 */ +# endif /* IS_IN (rtld) */ + } } __ifunc (__x86_cpu_features, __x86_cpu_features, NULL, void,