From owner-freebsd-current@FreeBSD.ORG Tue Jun 26 03:22:07 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 90CEA16A421 for ; Tue, 26 Jun 2007 03:22:07 +0000 (UTC) (envelope-from kbottle@gmail.com) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.244]) by mx1.freebsd.org (Postfix) with ESMTP id 49A6A13C45D for ; Tue, 26 Jun 2007 03:22:07 +0000 (UTC) (envelope-from kbottle@gmail.com) Received: by an-out-0708.google.com with SMTP id c14so413870anc for ; Mon, 25 Jun 2007 20:22:06 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=FAsG2Sw5YxsjYkAMA0eJshA3TXszhmq09RKvivCVbGJPQa4CnsUaaUx/mTwNdnS0XK0UEAdsvJq+iNGXdPPcWhkXfTUkICY14ozB6d/PeIduNs436a/K/paMmhThPeF1X01nxwCwrRIPHdO5KTBNBB26OJv9c7jAnr2vfPjqNPo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=m/tP90R+XH8Jz+aw/EYy4erCZn7mq75vCelZ8EniwCwVvUIbW61l0T6sVEGyrHxRC8vQp9UKRWgJGPdS4Ptw+0+BAQXty6+XO2ccLAH7YWFk8fERwqyfJuMSrbS6prvKl08jBLqXPQa6UUdqenRr8rH1wGe6XjWHMMN0r7OsWqA= Received: by 10.100.11.7 with SMTP id 7mr3493112ank.1182826454787; Mon, 25 Jun 2007 19:54:14 -0700 (PDT) Received: by 10.100.107.9 with HTTP; Mon, 25 Jun 2007 19:54:14 -0700 (PDT) Message-ID: <293b12a20706251954g479c0d72o9144832682f2cc54@mail.gmail.com> Date: Tue, 26 Jun 2007 10:54:14 +0800 From: "jj shen" To: "Jung-uk Kim" In-Reply-To: <200706251851.15377.jkim@FreeBSD.org> MIME-Version: 1.0 References: <293b12a20706251037t39a0227p45434a8d71feeba1@mail.gmail.com> <200706251851.15377.jkim@FreeBSD.org> X-Mailman-Approved-At: Tue, 26 Jun 2007 03:42:47 +0000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-current@freebsd.org Subject: Re: The relation between %fs and fs base X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2007 03:22:07 -0000 Hi, I know that NPTL use %fs to access thread local data. It seems that when the base address can be fitted in 32 bits, a GDT entry is used for better performance and the selector is loaded to %fs; otherwise, if the base address is larger than 0xffffffff, it is loaded to FS_BASE MSR and %fs is set to zero. I need to maintain these two kinds of TLS simultaneously (for system simulation), but was confused with the %fs and fs base. Maybe, someone can help me, at least my last two questions. Thanks! On 6/26/07, Jung-uk Kim wrote: > On Monday 25 June 2007 01:37 pm, jj shen wrote: > > Hi, > > > > I want to access different TLS through both fs base and GDT > > simultaneously. Let us call the two ways TLS_FSBASE and TLS_GDT > > respectively. > > > > (1) Can I switch from TLS_FSBASE to TLS_GDT just by: "movl GDT_SEL, > > %fs" (where GDT_SEL is the selector of GDT entry)? > > Will this instruction destroy the content of the IA32_FS_BASE MSR? > > > > (2) When switching from TLS_GDT to TLS_FSBASE, can I just set %fs > > to zero to indicate the fs base should be used, or must I invoke > > the > > *wrmsrl*instruction to reset IA32_FS_BASE once again? > > > > (3) What is the length of %fs? What I get by "movl %fs, %eax" in > > %eax? In the programmer manual from AMD, it is said somewhere that > > segment registers are still 16 bits as in x86, and it is also said > > otherwhere that "segment loads into FS and GS load a standard > > 32-bit base value in the hidden portion of the segment descriptor > > register". > > > > (4) What is the content of %fs, a descriptor selector or a base > > address smaller than 0xffffffff? > > What is effect of "movl val, %fs", loading a GDT selector or a > > 32-bit base address to %fs? > > Seen from the citation above, I think *val *should be a 32-bit > > base address; however seen from the implementation of Linux > > *arch_prctl* system call, it is a GDT selector loaded into %fs. > > I don't know what you are trying to achieve but don't mess up with %fs > and %gs on amd64 unless you are absolutely sure. It is deprecated > and it won't work as you expected. The only way to get/set %fs and > %gs properly on amd64 is via proper API, i.e., sysarch(2) with > AMD64_{GET,SET}_{FS,GS}BASE. If you use the API, the MSR will be > properly saved and restored while switching contexts. However, it is > very much discouraged as the manual page says, e. g., it will cause > serious problem if the application is threaded, etc. In fact, the > API should be only used by threading libraries. > > Jung-uk Kim >