From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OAgKFbhcUWhd8hEAWB0awg (envelope-from ) for ; Tue, 17 Jun 2025 08:16:56 -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=AZjanE6V; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4F1381E11C; Tue, 17 Jun 2025 08:16:56 -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 A103D1E089 for ; Tue, 17 Jun 2025 08:16:55 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FE933844BB9 for ; Tue, 17 Jun 2025 12:16:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FE933844BB9 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=AZjanE6V Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by sourceware.org (Postfix) with ESMTPS id 1FCE438E9BE0 for ; Tue, 17 Jun 2025 12:12:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FCE438E9BE0 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 1FCE438E9BE0 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=1750162346; cv=none; b=BYUQzp+NI4yQ/P5D/sSB3qggsvVXBo0NUnOddbg4CWFo299bKGC8w5nuzR+u17J6YpqK710jvQyk/bqDhUFp4GKZ6NNirnd0Cxc91IhZU6CQFlTmP1T3ifazObb0DCiNbvwenBxTn5VPgJLesWahHdJO/kl7oEFPoJxgo0ROQjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750162346; c=relaxed/simple; bh=Oe6AK4FB+ag0VgwnWzkMyPlEg0ZOOS9nU5yILu97ZHI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=sayfqz8ck8roiHfWkLdG377jqP44YdRdjTuSs9VHQMlVvMUFLnzLzxxa5/hXGgBFrpDgS7ybObCdPMp2DpbnJre+OyW/FRgT1wPb8QijuoW0S7cQ1dT5hg0GPP7vjojN2Cm11IAAhBu1UqQODO6+7Z/P3JOIwRh7gtwED4eO3xU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1FCE438E9BE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750162346; x=1781698346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Oe6AK4FB+ag0VgwnWzkMyPlEg0ZOOS9nU5yILu97ZHI=; b=AZjanE6V4hYBeee6YQdA+XEibWyLbFSvjsQNN77Ar6MR+0VL5GeDt5qj kWM19zNO6/CwGGc2H4Yk52BOlFh7PfrAI+MVJqZvwS9/DEN/oRWLV6Ifl pwqI/+II/0GMjLf8ypBc97yY0cA2LiQ7XjOBljv72JpEq0hNiJb1rJlSh Z+aBS1k7sDyeISrik1mUTqarknaVW50z8Br3ddObuxcRRE5sjfiuUj4Dp N8udEvQxnpyr0K0XZwkQl5O53qwI9O0wx5p3kJNJDkP4c3VMTnkUV/PO4 GdAu8IGdMMqV5hcRwVZYxWqiJ8I5WSN6oRxXWjAVKnflj1GeGqMsiCUkH g==; X-CSE-ConnectionGUID: /bzW+LQmS86Y1vx6+v3zkw== X-CSE-MsgGUID: XbpvG7RUSOOEiHIPIakTBg== X-IronPort-AV: E=McAfee;i="6800,10657,11467"; a="52429434" X-IronPort-AV: E=Sophos;i="6.16,243,1744095600"; d="scan'208";a="52429434" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2025 05:12:26 -0700 X-CSE-ConnectionGUID: 1VygQx6YQLmST31RbsumIQ== X-CSE-MsgGUID: fhjQQkSVTOGp+w+JzgAOlQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,243,1744095600"; d="scan'208";a="148748612" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2025 05:12:24 -0700 From: Christina Schimpe To: gdb-patches@sourceware.org Cc: thiago.bauermann@linaro.org, eliz@gnu.org Subject: [PATCH v4 01/11] gdbserver: Add optional runtime register set type. Date: Tue, 17 Jun 2025 12:11:37 +0000 Message-Id: <20250617121147.1956686-2-christina.schimpe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250617121147.1956686-1-christina.schimpe@intel.com> References: <20250617121147.1956686-1-christina.schimpe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --- 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 1d223c11db9..93fa14ddae9 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 7d3e35fa9b0..8a2b4302c76 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.34.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928