Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8899EC433E0 for ; Wed, 27 May 2020 14:40:23 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5F8F1207D8 for ; Wed, 27 May 2020 14:40:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F8F1207D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jdxE5-0003fa-6f; Wed, 27 May 2020 14:40:13 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jdxE3-0003fQ-9W for xen-devel@lists.xenproject.org; Wed, 27 May 2020 14:40:11 +0000 X-Inumbo-ID: f6e21558-a027-11ea-a759-12813bfff9fa Received: from ppsw-31.csi.cam.ac.uk (unknown [131.111.8.131]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f6e21558-a027-11ea-a759-12813bfff9fa; Wed, 27 May 2020 14:40:09 +0000 (UTC) X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://help.uis.cam.ac.uk/email-scanner-virus Received: from 88-109-182-220.dynamic.dsl.as9105.com ([88.109.182.220]:36104 helo=[192.168.1.219]) by ppsw-31.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.157]:465) with esmtpsa (PLAIN:amc96) (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1jdxE0-000m4V-KT (Exim 4.92.3) (return-path ); Wed, 27 May 2020 15:40:08 +0100 Subject: Re: -mno-tls-direct-seg-refs support in glibc for i386 PV Xen To: Jan Beulich References: <87mu5til8a.fsf@oldenburg2.str.redhat.com> <551ceac2-9cf6-00fd-95a6-a5b9fea6a383@citrix.com> <69bdaedf-c403-a77d-8ab1-12feffa15494@suse.com> From: Andrew Cooper Message-ID: <779861db-f9eb-634e-3d28-e113fcc37846@citrix.com> Date: Wed, 27 May 2020 15:40:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <69bdaedf-c403-a77d-8ab1-12feffa15494@suse.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-GB X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Florian Weimer , xen-devel@lists.xenproject.org, libc-alpha@sourceware.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 27/05/2020 15:00, Jan Beulich wrote: > On 27.05.2020 15:39, Andrew Cooper wrote: >> On 27/05/2020 14:03, Florian Weimer wrote: >>> I'm about to remove nosegneg support from upstream glibc, special builds >>> that use -mno-tls-direct-seg-refs, and the ability load different >>> libraries built in this mode automatically, when the Linux kernel tells >>> us to do that. I think the intended effect is that these special builds >>> do not use operands of the form %gs:(%eax) when %eax has the MSB set >>> because that had a performance hit with paravirtualization on 32-bit >>> x86. Instead, the thread pointer is first loaded from %gs:0, and the >>> actual access does not use a segment prefix. >>> >>> Before doing that, I'd like to ask if anybody is still using this >>> feature? >>> >>> I know that we've been carrying nosegneg libraries for many years, in >>> some cases even after we stopped shipping 32-bit kernels. 8-/ The >>> feature has always been rather poorly documented, and the way the >>> dynamic loader selects those nosegneg library variants is still very >>> bizarre. >> I wasn't even aware of this feature, or that there was a problem wanting >> fixing. >> >> That said, I have found: >> >> # 32-bit x86 does not perform well with -ve segment accesses on Xen. >> CFLAGS-$(CONFIG_X86_32) += $(call cc-option,$(CC),-mno-tls-direct-seg-refs) >> >> in one of our makefiles. >> >> Why does the MSB make any difference?  %gs still needs to remain intact >> so the thread pointer can be pulled out, so there is nothing that Xen or >> Linux can do in the way of lazy loading. >> >> Beyond that, its straight up segment base semantics in x86.  There will >> be a 1-cycle AGU delay from a non-zero base, but that nothing to do with >> Xen and applies to all segment based TLS accesses on x86, and you'll win >> that back easily through reduced register pressure. >> >> Are there any further details on the perf problem claim?  I find it >> suspicious. > To guard the hypervisor area, 32-bit Xen reduced the limits of guest > usable segment descriptors. Right.  Segment limits are what keept the guest kernel (ring 1, supervisor) out of Xen (ring 1, also supervisor). > While this works fine for flat ones (you > just chop off some space at the top), there's no way to represent a > full segment with a non-zero base. (From the other thread,) The problem isn't related to the base, per say. It is that a segment with a non-4G limit now faults rather than truncating usefully for the 32bit TLS model. > You can have the descriptor map > only the [base,XenBase] part or the [0,base) one. Hence Xen, from its > #GP handler, flipped the descriptor between the two options depending > on whether the current access was to the positive of negative part of > the TLS seg. (An in-practice use of expand down segments, as you'll > surely notice.) I've found gpf_emulate_4gb() in source history.  It was specific to 32bit builds of Xen (now long gone). What I can't figure out is why this is unnecessary in 64bit builds of Xen.  We still enforce reduced segment limits on the guests descriptors. I have a worrying suspicion that Xen's ABI for PV32 (on top of a 64bit Xen) now depends on -mno-tls-direct-seg-refs ~Andrew