From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OD+9B/GoX2hkXSMAWB0awg (envelope-from ) for ; Sat, 28 Jun 2025 04:33:53 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=I1kvsTm6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1C5291E11E; Sat, 28 Jun 2025 04:33:53 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.1 required=5.0 tests=ARC_SIGNED,ARC_VALID, BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 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 898161E089 for ; Sat, 28 Jun 2025 04:33:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30FEC385B538 for ; Sat, 28 Jun 2025 08:33:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30FEC385B538 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=I1kvsTm6 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by sourceware.org (Postfix) with ESMTPS id 11E2C385C6FE for ; Sat, 28 Jun 2025 08:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11E2C385C6FE Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 11E2C385C6FE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751099325; cv=none; b=h77wPatDHKyrIIFcM9ETRrmG90UiiFLNvJVeyNuF2BWYoZMx213xhJbFlNARgakqd5FaanpOapoCiLNr7kTWvxlLGq5q6WtH4Lj4/ky/DlVNmgRd1MG0UB3Mt8lQcO2sJ9xTz927Zpl5t9/sCiDGqeTdMORjM/v9rthkm5/AoVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751099325; c=relaxed/simple; bh=XYydDfI5UOtFUSVRxkqv5weprrqx/mz6DkWCj2X9kO4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=d29v2oixou3+LT/QgeGxW34Lfdi0Sc7wPR3R8az29AzA8awrD21S5m48VfvoR3/cxVb0KOA4I8Q0/SKE69garJh3zqt8x9J/ExoeaeNoTCyIPiTZ9LTiWMEvuXxr0Gue3CzmhbEzHvaAYhEYIIiE8bUTW0Cmq1mdItqfz8ZwnOY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11E2C385C6FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1751099325; x=1782635325; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XYydDfI5UOtFUSVRxkqv5weprrqx/mz6DkWCj2X9kO4=; b=I1kvsTm69LMvcjp99lqbJkVoiFmFfc6RGfQ5tkcO+k+loUbFeDl4aLSU Ns4dVkOE5Vz2hw0AbaLsmZWBkhPv1ReaAFyhHQ2tRkwBBet8g4w7iYnpS 6sT3erD5Ta5IwMG3V+aJ9dF18J9w0f/TjBtAdcOHs8SVGMrVwWsVRG1O+ MQiSdlX/1UMZTtmmzfEVIt55BQtMsfO3O1BRUh+2E6wBh8iL04uPu+F+2 t+joOwNZ/ffrQqXhrEJObJf5R9q7T8a/94t9cElR1/ycfG1EGUvmgkzYY yV+Nb9pqZd25HG4f/J7d/UHyjIveVo1T5sBahfF5P5CDUyg7DQNOOjB5v Q==; X-CSE-ConnectionGUID: /cjQ0J1+TTCGr1eQ3tqprQ== X-CSE-MsgGUID: vhw30rf3RXK/NUDnZHaSGA== X-IronPort-AV: E=McAfee;i="6800,10657,11477"; a="53491468" X-IronPort-AV: E=Sophos;i="6.16,272,1744095600"; d="scan'208";a="53491468" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2025 01:28:44 -0700 X-CSE-ConnectionGUID: kSszI/+kTo+CCRxLs8MpYQ== X-CSE-MsgGUID: +l+Uu0I2ScGTB0NQcIwlYw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,272,1744095600"; d="scan'208";a="152734118" Received: from 0007e934a912.jf.intel.com (HELO localhost) ([10.165.58.208]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2025 01:28:44 -0700 From: Christina Schimpe To: gdb-patches@sourceware.org Cc: thiago.bauermann@linaro.org, luis.machado@arm.com Subject: [PATCH v5 02/12] gdbserver: Add optional runtime register set type. Date: Sat, 28 Jun 2025 01:28:00 -0700 Message-ID: <20250628082810.332526-3-christina.schimpe@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250628082810.332526-1-christina.schimpe@intel.com> References: <20250628082810.332526-1-christina.schimpe@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Some register sets can be activated and deactivated by the OS during the runtime of a process. One example register is the Intel CET shadow stack pointer. This patch adds a new type of register set to handle such cases. We shouldn't deactivate these regsets and should not show a warning if the register set is not active but supported by the kernel. However, it is safe to deactivate them, if they are unsupported by the kernel. To differentiate those scenarios we can use the errno returned by the ptrace call. Reviewed-by: Thiago Jung Bauermann Reviewed-By: Luis Machado --- gdbserver/linux-low.cc | 50 ++++++++++++++++++++++++++++++------------ gdbserver/linux-low.h | 7 +++++- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 39642705b0d..e8c4eb8a78d 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -5006,23 +5006,31 @@ regsets_fetch_inferior_registers (struct regsets_info *regsets_info, if (res < 0) { if (errno == EIO - || (errno == EINVAL && regset->type == OPTIONAL_REGS)) + || (errno == EINVAL + && (regset->type == OPTIONAL_REGS + || regset->type == OPTIONAL_RUNTIME_REGS))) { /* If we get EIO on a regset, or an EINVAL and the regset is - optional, do not try it again for this process mode. */ + optional, do not try it again for this process mode. + Even if the regset can be enabled at runtime it is safe + to deactivate the regset in case of EINVAL, as we know + the regset itself was the invalid argument of the ptrace + call which means that it's unsupported by the kernel. */ disable_regset (regsets_info, regset); } - else if (errno == ENODATA) + else if (errno == ENODATA + || (errno == ENODEV + && regset->type == OPTIONAL_RUNTIME_REGS) + || errno == ESRCH) { - /* ENODATA may be returned if the regset is currently - not "active". This can happen in normal operation, - so suppress the warning in this case. */ - } - else if (errno == ESRCH) - { - /* At this point, ESRCH should mean the process is - already gone, in which case we simply ignore attempts - to read its registers. */ + /* ENODATA or ENODEV may be returned if the regset is + currently not "active". For ENODEV we additionally check + if the register set is of type OPTIONAL_RUNTIME_REGS. + This can happen in normal operation, so suppress the + warning in this case. + ESRCH should mean the process is already gone at this + point, in which case we simply ignore attempts to read + its registers. */ } else { @@ -5104,12 +5112,26 @@ regsets_store_inferior_registers (struct regsets_info *regsets_info, if (res < 0) { if (errno == EIO - || (errno == EINVAL && regset->type == OPTIONAL_REGS)) + || (errno == EINVAL + && (regset->type == OPTIONAL_REGS + || regset->type == OPTIONAL_RUNTIME_REGS))) { /* If we get EIO on a regset, or an EINVAL and the regset is - optional, do not try it again for this process mode. */ + optional, do not try it again for this process mode. + Even if the regset can be enabled at runtime it is safe + to deactivate the regset in case of EINVAL, as we know + the regset itself was the invalid argument of the ptrace + call which means that it's unsupported by the kernel. */ disable_regset (regsets_info, regset); } + else if (errno == ENODEV + && regset->type == OPTIONAL_RUNTIME_REGS) + { + /* If we get ENODEV on a regset and the regset can be + enabled at runtime try it again for this process mode. + This can happen in normal operation, so suppress the + warning in this case. */ + } else if (errno == ESRCH) { /* At this point, ESRCH should mean the process is diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index e1c88ee0bb2..5710e49d950 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -42,7 +42,12 @@ enum regset_type { GENERAL_REGS, FP_REGS, EXTENDED_REGS, - OPTIONAL_REGS, /* Do not error if the regset cannot be accessed. */ + OPTIONAL_REGS, /* Do not error if the regset cannot be accessed. + Disable the regset instead. */ + OPTIONAL_RUNTIME_REGS, /* Some optional regsets can only be accessed + dependent on the execution flow. For such + access errors don't show a warning and don't + disable the regset. */ }; /* The arch's regsets array initializer must be terminated with a NULL -- 2.43.0