From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id JSNLMhsopGdR0iUAWB0awg (envelope-from ) for ; Wed, 05 Feb 2025 22:10:19 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=HOpqdFJB; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BE20C1E105; Wed, 5 Feb 2025 22:10:19 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 230201E05C for ; Wed, 5 Feb 2025 22:10:19 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2E253858432 for ; Thu, 6 Feb 2025 03:10:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2E253858432 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=HOpqdFJB Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id 251553858C51 for ; Thu, 6 Feb 2025 03:09:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 251553858C51 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 251553858C51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1033 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738811387; cv=none; b=Svdx2Qnc8+jpji0tHjf5EGtSJnpe43g3K6TMPCoj6GKA7LA/F9+8AFO4M0BBULJ4GRpMvqdHXsd/JgWrfoo4Yj72nFqCSNoB9oIwmbDDPq4yT/HQiKyPGZrrQ4I1lz/Cey4Pk0Ea/qZfu3TB7FxNLCKLVxqymmNcdyWestFa/z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738811387; c=relaxed/simple; bh=gaHRjwrHKan5Ky8lbLnb4ht0ELBgOnKYbojU+xjngbg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Kk6exLNbrjd7+ZmkDQBD+k3uotZKl7mfVM5pPCHnq4UrA0m16UCZvDEwzJyCRhH22h45jPaR1K2iJBr7qVljmkqbJKHgt6Vm+GieEt9wwpkPxCLgftt+yIOi9Pb88e4hDKvr218iEH/dm1D3wGDgJdrNYd5ca/zJUAYCKfwkj7o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 251553858C51 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2f9c69aefdbso739622a91.2 for ; Wed, 05 Feb 2025 19:09:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738811386; x=1739416186; darn=sourceware.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=peMSg+TbBjyybVYbGT88yh9IfXX1GNiaF+3kl64ybZk=; b=HOpqdFJBMlzYII0bux0KHddh/Z054+iE6CqKe+kiRdDAikmzlNsWMrFLcXGvTHTfDG +qGU+axlxYNkDqT+0YIvsAsypHGPGLTmCbl18HEPFh1tTbu6iDmeMPZ/fNYVJ0oO4O4r +cuZMA+9hawudlwq3akSiRkfOvx8j/WzlR3HJ4BHHprfYn4lcZVoTlZbnLGAywYBNQLn mvckDeb7SRserz9H2FHE9Sot2whZt7ezAB4g/rsjeIrVSi6ez4A7EslD+M8pVad5LUKj ntV8JsxfqpXSktAevDXYvl3OE2Fy5n8SYD+RxkywxUTe8XiI2NYPF58bUJRNDFciADKT tQng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738811386; x=1739416186; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=peMSg+TbBjyybVYbGT88yh9IfXX1GNiaF+3kl64ybZk=; b=jG9PkpW2QfwJj/V7y+L/b3hmYHlSCaQ0Bvg1KSpgwceX1PXqfqMo9n2wTqRCQYyBDD QexwT0GrdNsgAJDgEVhfx1zXcxSjolQy69CcAJD3F/fvKay2h2dQI3/tTu3DB0lXKGxB Ud0Rljw6WlcfwIDIaZ1I/c2m4mLG4qnLCHfXmFDPZ61GtKEeVaaEb7178Kf6JbPAFn7E 49WxVSfNLWbhy+aGfABfFv1+sqnWtUkuylXmdh8EUFRKko36KDAnZKgM9LY5wn0HtCB1 GqxBQx7r29BKBi09yGk6hVjqfvw1kbyzBA2+ixpxlYl2wF7/Mwm3AvxPV183/nee8GaX EsWw== X-Gm-Message-State: AOJu0Yxp49THl/NjZpHy2V7Her3HxD5PqiTQ18buN8CmNdLZPWMx0uN/ vM2i4sI4szcdFNfVPRaN1e1ojOXPdyu6ZNDYpV/rBPPxTItGUrAF/bZItEWdPjkgXzZV/2vXj3a Y X-Gm-Gg: ASbGncvm4/qFiJmHP8znTGrvAm7D8kMFBhuC1R0fosAjFpZD5i6/QMqu+UBN685F5+W fneDLo4ms06RtncViDa2LkU/m8Y7nDdKiqOWiCXNeRHb9tR9f3qMa2Kd2YpYPKXbxO4mFxJZ+nf WwjaU32zLzwIRJa6B4Ow64Og3lWQy/G6PRBRLOhzVZBoFBOQ7c/cjROkvUgxRa8KfXH9/lStNKD dtZ3raLYAIDryz0Yn0bT5hxrR6FbDHUdEJsK372ItIl9S0i/Q1r2TB4Kri+Ds2iVVlE90Fbf4ps bZm27tk4QBJ1PymRJygqxg8= X-Google-Smtp-Source: AGHT+IEPajbcToOXM1mmz47GLWjTBcW36z2IkPOok08y45xp9y2ZXbMCb4dXNqEW17giuKt2SnDgkg== X-Received: by 2002:a05:6a00:8d8d:b0:725:f1ca:fd75 with SMTP id d2e1a72fcca58-7303510815amr8287338b3a.2.1738811385991; Wed, 05 Feb 2025 19:09:45 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:7e5:16be:a0c6:ff7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73048c16292sm209758b3a.149.2025.02.05.19.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 19:09:45 -0800 (PST) From: Thiago Jung Bauermann To: "Schimpe, Christina" Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 05/12] gdb, gdbserver: Use xstate_bv for target description creation on x86. In-Reply-To: <20241220200501.324191-6-christina.schimpe@intel.com> (Christina Schimpe's message of "Fri, 20 Dec 2024 20:04:54 +0000") References: <20241220200501.324191-1-christina.schimpe@intel.com> <20241220200501.324191-6-christina.schimpe@intel.com> User-Agent: mu4e 1.12.8; emacs 29.4 Date: Thu, 06 Feb 2025 00:09:42 -0300 Message-ID: <87bjvfixah.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org "Schimpe, Christina" writes: > The XSAVE features set is organized in state components, which are a set > of or parts of registers. So-called XSAVE-supported features are > organized using state-component bitmaps, each bit corresonding to a Typo: "corresponding" > single state component. > > The SDM uses the term xstate_bv for a state-component bitmap, which is > defined as XCR0 | IA32_XSS. The control register XCR0 only contains a > state-component bitmap that specifies user state components, while IA32_XSS > contains a state-component bitmap that specifies supervisor state components. > > Until now, XCR0 is used as input for target description creation in GDB. > However, a following patch will add userspace support for the CET shadow > stack feature by Intel. The CET state is configured in IA32_XSS and consists > of 2 state components: > - State component 11 used for the 2 MSRs controlling user-mode > functionality for CET (CET_U state) > - State component 12 used for the 3 MSRs containing shadow-stack pointers > for privilege levels 0-2 (CET_S state). > > Reading the CET shadow stack pointer register on linux requires a separate > ptrace call using NT_X86_SHSTK. To pass the CET shadow stack enablement > state we would like to pass the xstate_bv value instead of xcr0 for target > description creation. To prepare for that, we rename the xcr0 mask > values for target description creation to xstate_bv. However, this > patch doesn't add any functional changes in GDB. > > Future states specified in IA32_XSS such as CET will create a combined > xstate_bv_mask including xcr0 register value and its corresponding bit in > the state component bitmap. This combined mask will then be used to create > the target descriptions. > --- > gdb/amd64-tdep.c | 14 ++++---- > gdb/amd64-tdep.h | 8 +++-- > gdb/arch/amd64-linux-tdesc.c | 33 ++++++++--------- > gdb/arch/amd64-linux-tdesc.h | 7 ++-- > gdb/arch/amd64.c | 15 ++++---- > gdb/arch/amd64.h | 10 ++++-- > gdb/arch/i386-linux-tdesc.c | 29 ++++++++------- > gdb/arch/i386-linux-tdesc.h | 5 +-- > gdb/arch/i386.c | 15 ++++---- > gdb/arch/i386.h | 8 ++++- > gdb/arch/x86-linux-tdesc-features.c | 55 +++++++++++++++-------------- > gdb/arch/x86-linux-tdesc-features.h | 25 +++++++------ > gdb/i386-tdep.c | 14 ++++---- > gdb/i386-tdep.h | 7 ++-- > gdb/nat/x86-linux-tdesc.c | 18 +++++----- > gdb/nat/x86-linux-tdesc.h | 7 ++-- > gdb/x86-linux-nat.c | 11 ++++-- > gdbserver/i387-fp.cc | 40 ++++++++++----------- > gdbserver/linux-amd64-ipa.cc | 10 +++--- > gdbserver/linux-i386-ipa.cc | 6 ++-- > gdbserver/linux-x86-low.cc | 9 +++-- > gdbsupport/x86-xstate.h | 4 ++- > 22 files changed, 196 insertions(+), 154 deletions(-) Just some minor suggestions in comments. Reviewed-by: Thiago Jung Bauermann > diff --git a/gdb/arch/x86-linux-tdesc-features.c b/gdb/arch/x86-linux-tdesc-features.c > index f6eb112f312..3f041ece6eb 100644 > --- a/gdb/arch/x86-linux-tdesc-features.c > +++ b/gdb/arch/x86-linux-tdesc-features.c > @@ -28,18 +28,21 @@ > > We want to cache target descriptions, and this is currently done in > three separate caches, one each for i386, amd64, and x32. Additionally, > - the caching we're discussing here is Linux only, and for Linux, the only > - thing that has an impact on target description creation is the xcr0 > - value. > + the caching we're discussing here is Linux only. Currently for linux, Nit: "Linux" > + the only thing that has an impact on target description creation are > + the supported features in xsave which are modelled by a xstate_bv_mask > + value, which has the same format than the state component bitmap. > > In order to ensure the cache functions correctly we need to filter out I think this should read "filter" rather than "filter out". I understand the latter to mean that xstate_bv_mask feature bits that are relevant should be ignored, which isn't what the code does. > @@ -51,11 +54,13 @@ extern int x86_linux_amd64_tdesc_count (); > extern int x86_linux_x32_tdesc_count (); > extern int x86_linux_i386_tdesc_count (); > > -/* Convert an index number (as returned from x86_linux_xcr0_to_tdesc_idx) > - into an xcr0 value which can then be used to create a target > - description. */ > +/* Convert an index number (as returned from > + x86_linux_xstate_bv_mask_to_tdesc_idx) into an xstate_bv_mask > + value which can then be used to create a target description. > + The return mask same format than the state component bitmap and does Missing words: "The return mask has the same format ..." > + include user and supervisor state components.*/ > > -extern uint64_t x86_linux_tdesc_idx_to_xcr0 (int idx); > +extern uint64_t x86_linux_tdesc_idx_to_xstate_bv_mask (int idx); > > #endif /* IN_PROCESS_AGENT */ -- Thiago