From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 1EA913858D1E for ; Sun, 12 Feb 2023 16:25:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EA913858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102d.google.com with SMTP id pj3so9823707pjb.1 for ; Sun, 12 Feb 2023 08:25:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YoESSltfEI/AOaI64AijwW0EJ3ikv2bnl1k8BqOsRN8=; b=DxRvYOXHtSH0eQty8/d6U4JmaW+aMmfaUwBFsLlzP+F4VShMcCpw7mv9+HcKCb2jzn Kr0h2zekXNYzco8yQkyurQ+R17KZ2t2yJ6NYFuh2BwBYPqlcpAOcIDrC82Ys08IWcYMX 6DHK6MFQ69ZOkuYWufYHkHiKNUFXTTj/idQPhjJJEfyts6RRc39f8IF8Sw1CZeDE8t/y ydd8SXHquG+k25q82PKj4Z2fbZIh4wTP7Twk++2B3pXMDogY13nkf51Q1lZjs9f+7HkX Jy4/NjF4dPRZcCyxzQMcPgM5eW1asFC3F59vwHWFXTuJQriGLk41Vyvmz4bPjYg/8/bn ZQqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YoESSltfEI/AOaI64AijwW0EJ3ikv2bnl1k8BqOsRN8=; b=DM6/TQ3pYeGODPmO6jIzH2vwOU7zYkPGd224VuBRyJA7a0Xcgko1tSZArC1nT/j2xM XsgK8U7YGstHRWTgzfG/MqFgsq7ObNr0VS2cc54VKqpAB0xuw16k1QQbISDlErMa/Hc3 K5sojvCT2DIALJdDbSk74YkQezJDJrImgyoH412jUCsZYsf4YwmuRWmv0/25rqyYNwhD lbuuxU0diybE0l1Me9aOGhvxIgDjUuThCwTgKw5ZRNS9J0BghwYc539mbtuIqqpMg/zt Xms3xpbygI6NC9YPw1S4sBf96Jc19vKJuzQ9e0YA9wl0WkNQfEtY7sTVMhraXTi+noj7 p4kg== X-Gm-Message-State: AO0yUKWVjJCv5Vr02mn4tSm7Awld6R7LrdjK/Ic8qL1Swm9oZK8MCufv bZwmqpWMjEV6mDytf8PsrYdgFLVP6zj9i/BWK8k= X-Google-Smtp-Source: AK7set9eo/hv1x/QuyciL/slr1QubjBKeXBQvXQEULhcqJEHg4cDdw0GEtHF1fvyuzB1SCzbSJJ9Mkiu5XFHZel6Fns= X-Received: by 2002:a17:90a:7c4a:b0:232:ccdc:268e with SMTP id e10-20020a17090a7c4a00b00232ccdc268emr2814443pjl.34.1676219122105; Sun, 12 Feb 2023 08:25:22 -0800 (PST) MIME-Version: 1.0 References: <20230212111044.610942-1-bugaevc@gmail.com> <20230212111044.610942-12-bugaevc@gmail.com> <20230212161153.q4km4h2ql3k5pasp@begin> In-Reply-To: <20230212161153.q4km4h2ql3k5pasp@begin> From: Sergey Bugaev Date: Sun, 12 Feb 2023 19:25:11 +0300 Message-ID: Subject: Re: [RFC PATCH glibc 11/12] hurd, htl: Add some x86_64-specific code To: Samuel Thibault Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org, =?UTF-8?B?RmzDoXZpbyBDcnV6?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: On Sun, Feb 12, 2023 at 7:11 PM Samuel Thibault w= rote: > > Sergey Bugaev, le dim. 12 f=C3=A9vr. 2023 14:10:42 +0300, a ecrit: > > We should not need a getter routine, because one can simply inspect the= target > > thread's state (unless, again, I misunderstand things horribly). > > For 16bit fs/gs values we could read them from userland yes. But for > fs/gs base, the FSGSBASE instruction is not available on all 64bit > processors. And ATM in THREAD_TCB we want to be able to get the base of > another thread. What I've meant is: __thread_get_state (whatever_thread, &state); uintptr_t its_fs_base =3D state->fs_base; You can't really do the same to *write* [fg]s_base, because doing thread_set_state on your own thread is bound to end badly. > > diff --git a/sysdeps/mach/hurd/x86_64/static-start.S b/sysdeps/mach/hur= d/x86_64/static-start.S > > new file mode 100644 > > index 00000000..982d3d52 > > --- /dev/null > > +++ b/sysdeps/mach/hurd/x86_64/static-start.S > > @@ -0,0 +1,27 @@ > > +/* Type of the TCB. */ > > +typedef struct > > +{ > > + void *tcb; /* Points to this structure. */ > > + dtv_t *dtv; /* Vector of pointers to TLS data= . */ > > + thread_t self; /* This thread's control port. */ > > + int __glibc_padding1; > > + int multiple_threads; > > + int gscope_flag; > > + uintptr_t sysinfo; > > + uintptr_t stack_guard; > > + uintptr_t pointer_guard; > > + long __glibc_padding2[2]; > > + int private_futex; > > ? Isn't that rather feature_1 ? sysdeps/mach/hurd/i386/tls.h has 'int private_futex;', which is where I stole this from. A quick grep confirms that it's never used, so we might rename both to feature_1, or maybe another instance of __glibc_padding. > > +/* GCC generates %fs:0x28 to access the stack guard. */ > > +_Static_assert (offsetof (tcbhead_t, stack_guard) =3D=3D 0x28, > > + "stack guard offset"); > > +/* libgcc uses %fs:0x70 to access the split stack pointer. */ > > +_Static_assert (offsetof (tcbhead_t, __private_ss) =3D=3D 0x70, > > + "split stack pointer offset"); > > Indeed. Could you perhaps also add them to the i386 tls.h? > > +/* Install new dtv for current thread. */ > > +# define INSTALL_NEW_DTV(dtvp) THREAD_SETMEM (THREAD_SELF, dtv, dtvp) > > +/* Return the address of the dtv for the current thread. */ > > +# define THREAD_DTV() THREAD_GETMEM (THREAD_SELF, dtv) > > While at it, try to make the i386 version use that too? Yeah, I have not ported the improvements back to the 32-bit version; maybe I should. Another cool one is doing fs/gs-relative access using GCC's __seg_fs/__seg_gs when supported. Sergey