From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5F9AE3857838 for ; Wed, 8 Mar 2023 10:44:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F9AE3857838 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678272290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c5avs4GtWSmLoiAnDUPI+pPB4SIq8bESRu8lHYqFhHk=; b=V5Z9lg5lwuI9e3MFjHd5MbGDL1EktkmpM+GJN9NRJ+rl7jCGJcs+swVhBUQh2lsmS7xdVm NY2SKhFjpAMZJUiYrf3q1A3c27yWFiwMX+ZqcfEb42UpGmkqo4qH4A4d1EBIoJiJ/pEyUC /UeYipvdgSnzGtuo5Mn24XfwMY64K0c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-345-e_QVJ8s4MuGmswlAVysF5g-1; Wed, 08 Mar 2023 05:44:48 -0500 X-MC-Unique: e_QVJ8s4MuGmswlAVysF5g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F3BC800050; Wed, 8 Mar 2023 10:44:48 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4332A2026D4B; Wed, 8 Mar 2023 10:44:47 +0000 (UTC) From: Florian Weimer To: Jan Kratochvil Cc: libc-alpha@sourceware.org, Anton Kozlov , Adhemerval Zanella Netto Subject: Re: [PATCH] RFC: Provide a function to reset IFUNC PLTs References: <87v8jdq7ht.fsf@oldenburg.str.redhat.com> Date: Wed, 08 Mar 2023 11:44:45 +0100 In-Reply-To: (Jan Kratochvil's message of "Wed, 8 Mar 2023 18:23:55 +0800") Message-ID: <87fsafsesi.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * Jan Kratochvil: > On Tue, 07 Mar 2023 16:40:46 +0800, Florian Weimer wrote: >> Use of is somewhat rare. Not even GCC uses it >> AFAIK. It has its own cached CPU data used for target clones and >> similar features. Re-running those IFUNC resolvers will just give the >> same results. > > I do not use anywhere, why do you mention it? > I am doing there > memset((volatile uint8_t *)cpu_features, 0, sizeof(*cpu_features)); > ... > _dl_x86_init_cpu_features(); > to prevent the cache of CPU data. And it does work. This code resets the data queried by . But GCC and others do not use these interfaces, they use CPUID/XGETBV directly and cache the result, so this reset does not alter the outcome of their IFUNC resolvers. >> Distributions have started to deploy alternate builds in >> glibc-hwcaps/x86-64-v3 directories: >> >> openSUSE Tumbleweed gains optional x86-64-v3 optimization >> >> >> This might be a common situation fairly soon. This is not IFUNC-based >> at all, so any IFUNC-based approach is not going to help with that. > > What about some "dlreopen" to replace the variant of glibc? The trivial implementation is not going to work because most of the function and data addresses will change as a result of the reload. Most checkpoints probably occur in a blocking system call, and that would need some form of on-stack replacement to work properly. >> Practically speaking, I think cluster heterogeneity needs to be hidden >> at the cluster level. > > The question is how to implement it. I have found > https://github.com/ddcc/libcpuidoverride > but it is not compatible with latest glibc (maybe its loader code needs to > implement ELF relocations, it would be definitely fixable). It needs kernel support for sure. I do not know to what extent CPUID can be context-switched at the silicon level, maybe the masking is system-wide (or per-guest in a virtualized configuration). > Another option is GLIBC_TUNABLES=glibc.cpu.hwcaps=... although then one has to > translate cpuid feature bits into the glibc names like SSE4_2 etc. > Also re-exec() after setenv("GLIBC_TUNABLES") is not too nice. Again, that's not going to work in practice because libraries and applications do not use . Thanks, Florian