From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 3354A3858D1E for ; Sun, 12 Feb 2023 16:51:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3354A3858D1E 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-pg1-x530.google.com with SMTP id s8so6704659pgg.11 for ; Sun, 12 Feb 2023 08:51:46 -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=m7bfgDrNu8SLLAjgUbFDX8WvfTYohkOKc+ELIuKjajk=; b=M2m0i0HjXgDkkYaKhRVMzVIqnAY2xcu6dGIoinsgjxeCYoATVgfOUNi625+W3KK2// CtyvVnF7pvBu/ZbZd10bGKiBCwjelt4fWumxmrMfV6fp8mMf405OLsm8MI3jKlcvEaIe wqtOll7Ygsn4NfxNZOY9POXet43uma4kELUbtq+gfSBirtWdyKhB8G1GfZHv9pIyP8f+ Lty/nEV69su1LklnqxLr9ri0ZJNGM0b4k+O1vx10zrbnc5X8zlo0+iv9DkxdlesCSIt6 KoHpDk/PX0arpXh/JbWF42NLQsrqGJOvOmBVoQ/rIwCUjlhNo/pfUpJFZZ055ItFsAAK Q4nw== 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=m7bfgDrNu8SLLAjgUbFDX8WvfTYohkOKc+ELIuKjajk=; b=ZIP40bE40ICr4x9QRmsewFXtrqs9a2BxLqQr0UbeDPf/yO28/gykz9R9qIcuiiYGw2 mL+AZIz0sMlRGw6vKPCFQWAMR73Vtr0dPVAgOW0lgsRqjbXmx1whZnSSjKMIjnY4CwTX y9fhfPmlNERMDF/m0FE6gN9ccBNldx2+5li/188UNwO2vsmZXJ/W9Ip+AF5CRXCnHyF/ n/kfs6WCcSV/VML4qMtkfgJefKdl6XtuKcx3gUXZcM0MLan62AiW4TiigNXyFIPzXLCG LOYNeVFX3ChyzqNc8EwfY85AdSPQK9muxh/3bycoybHLFkmzWARPJlH7ODpiWAQyit74 UEzg== X-Gm-Message-State: AO0yUKV7m9fRMcEaaWhXLC58Eqi2w+vnpkBbEOmb+wkpoREkYZE32g18 QnvaWCq0ciAieGYfBu8z6oa6arXlBFYFzbflKDg= X-Google-Smtp-Source: AK7set+akmNR9tTNRFI32gqb1V2fSx6XJromy2pHYwsCtURNueIsP06oo/878gb4F8NQWo+YxSTbVk1VR94OwjUDZW8= X-Received: by 2002:a63:ab48:0:b0:490:afa3:2334 with SMTP id k8-20020a63ab48000000b00490afa32334mr3790207pgp.35.1676220704903; Sun, 12 Feb 2023 08:51:44 -0800 (PST) MIME-Version: 1.0 References: <20230212111044.610942-1-bugaevc@gmail.com> <20230212111044.610942-12-bugaevc@gmail.com> <20230212161153.q4km4h2ql3k5pasp@begin> <20230212163607.47dynpr5rpbohrhe@begin> In-Reply-To: <20230212163607.47dynpr5rpbohrhe@begin> From: Sergey Bugaev Date: Sun, 12 Feb 2023 19:51:33 +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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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:36 PM Samuel Thibault w= rote: > > Sergey Bugaev, le dim. 12 f=C3=A9vr. 2023 19:25:11 +0300, a ecrit: > > On Sun, Feb 12, 2023 at 7:11 PM Samuel Thibault wrote: > > > 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. > > ? Well, sure, just like setting fs/gs through thread state was not done > for i386. > > I don't see where you're aiming. Getting fs/gs from __thread_get_state > won't actually give you the base, you'll just read something like 0. It is my understanding that the actual values of fs/gs (i.e. the index of a descriptor) are not useful on x86_64. But fs_base and gs_base are now things that you have to store in the thread state and save/restore on every context switch. fs_base and gs_base are like registers in their own right (well, MSRs are registers). Thus, it should be easy to read them from the state structure exposed by the kernel. But again, I really have very little understanding of this, so maybe I'm talking nonsense. Sergey