From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id g+OuGGHXnmopfjQAWB0awg (envelope-from ) for ; Mon, 07 Sep 2026 11:25:21 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H/N+tN9K; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4B9401E09E; Mon, 07 Sep 2026 11:25:21 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (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 4ADE01E033 for ; Mon, 07 Sep 2026 11:25:20 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1EF648F90E9 for ; Mon, 7 Sep 2026 15:25:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1EF648F90E9 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H/N+tN9K Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 2F6894BB3BD5 for ; Mon, 7 Sep 2026 15:24:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F6894BB3BD5 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2F6894BB3BD5 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788794694; cv=none; b=RgxePA4t5/w0sXAAlV038bXpTvB8XKL6PPWtGSTLk8/cCRXMXryo1dIkn9Lgoqp5mm56MTiVPI21sIcBb8tPiO0ehWDEiFiqpP/QtoeoW41NCWq+Bh0E+loc139fPIlg81W3cPuGNoggkBv1Pd8oXOrElMZEDxv8lM7j5M7O1G4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788794694; c=relaxed/simple; bh=ccv2yWHVnqv9PcjaRbg54LFhk/2qTH0l/WOUMJAOQS8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=n9zz7PtwJTor2DwPzlnUiLk7BOzGA/0voPnhuuIb1kfVQPJrjR0PQv/oAAOu6Jtz2ZcxDhHSVq+79SCI1ekBP49XfL6uG4zWXULTho6fHt+xQTowH9gtIoBICcjh+lDmdsLrK3kmcoMsnWB+PeNabohm0+LsUObyU3jWvSZ/gS8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H/N+tN9K DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F6894BB3BD5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788794693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7Bbglzabe2FpAaj+DBnFN3Ai2MzuTBm9wzHth5bBix8=; b=H/N+tN9KjwnRoEKRE/WXKFk8ASsfQToyrDL8TBJXt5qEptGyvXvVudBvQTlFIkK038l3Nb 8FBfKoS0IIBkemvp7NbZB8g+stElifK7sdkKlvVayYI4L/MExHDFi/f9eVKMoEjjHApQfK rmzzr2NalDFLbKG7nTb9nHFudezpqEU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-aI_yzBjKNXSX2zDB2_d8Og-1; Mon, 07 Sep 2026 11:24:51 -0400 X-MC-Unique: aI_yzBjKNXSX2zDB2_d8Og-1 X-Mimecast-MFC-AGG-ID: aI_yzBjKNXSX2zDB2_d8Og_1788794690 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-49b0e6638e3so27550795e9.2 for ; Mon, 07 Sep 2026 08:24:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788794690; x=1789399490; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=7Bbglzabe2FpAaj+DBnFN3Ai2MzuTBm9wzHth5bBix8=; b=n28IDGqfcLo7HIJc0WduSkbc6kMu9iZuPNIoMhzjdcMsIFsQ0nGQJp6+eDNZxjPRlv /4fF/LYxuQx9DtIrJ3qCBoucgEiRvnS02/KmUukNMewg7aQnrPcJVoSJyLOkH8l/DM/K 7Mcr6XtKA8X0tyYdO0lcQLB4jgpvymzsWWnzizMc2oZ4ooZIXFAsdCXd3phDgM93dfKp oibdLttybmQ7utPICRy6vGqYbEVwIt/NEF+8PAb2hwT+d5U+TNXqB/a3benDv6zX3h+l FjMKUcn64jMYZEXdxx9kNduphXyAcBGmfL+9839SBCBLcjiP6eDmMTQ9BhGJy2Iyev0C kMdw== X-Forwarded-Encrypted: i=1; AKwUvBwGLriH+oeSNb97D4O1gN07Ozxj4yrmDgyBVPcvuuf4t9GQV/MoJUpIDoILx+e1cryV6fRZ4ap8ioXryg==@sourceware.org X-Gm-Message-State: AFuF++l1hvElXVtqmoVMkvMRUq3asO2fpQ+ZgXeFV6mP4vQ12DOq1s8f VhO8e0scqPOiEHWLETb1fNQzIAqwVjOlHIh1iJ/FECHGxO4Jgeo+QSENYTz1UFBDZy5Ti5A/dv9 CKqjkLr8a5yIvajuKuKJhmdhr+CgNTvFJN80mP1u5nqfL52+slZVdazDjS/j4xWQ= X-Gm-Gg: AYBFou11ka2sOXGROtzw617eEjPXpHH1yePJUUTOxJKLBR7QDAaHWNeyAFD/ttejj7P X+7PItMNdtTUdz4vvhXKs7Ft6VmwHix3P3aF4Hbgy1tnus2CqPrquV+sNDnU/WwI/XeK2pat32/ pHtJXSoAMPqMhCDC6YrJaLwbiMSNp1vOBzQRMGd4uhAoqbXPOcuXGCy5BepaqoyUVWXjvXf/w6s kbqM3YvcNFaCOIguhLe3rnuxtM8Qml3Y2sbgqwJwKU1VPji5g+XxZK/w2lOseIPnTqrwmV1ZxgS AU1O3Bg5P2fW7BI903cNujEknAigr0hj8vPuY3I5pDHrIkSof5pajvfh8G6CGleKCqTHII6z+e7 rLRlfBR32e6Tivuf+QUBtZDETmqM= X-Received: by 2002:a05:600c:1c24:b0:498:952:e276 with SMTP id 5b1f17b1804b1-49cf824894cmr275654585e9.8.1788794690099; Mon, 07 Sep 2026 08:24:50 -0700 (PDT) X-Received: by 2002:a05:600c:1c24:b0:498:952:e276 with SMTP id 5b1f17b1804b1-49cf824894cmr275654145e9.8.1788794689627; Mon, 07 Sep 2026 08:24:49 -0700 (PDT) Received: from localhost (128.223.159.143.dyn.plus.net. [143.159.223.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4859162f354sm21616195f8f.20.2026.09.07.08.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2026 08:24:48 -0700 (PDT) From: Andrew Burgess To: Matthieu Longo , gdb-patches@sourceware.org Cc: Luis Machado , Luis Machado , Thiago Jung Bauermann , Srinath Parvathaneni Subject: Re: [PATCH v1] gdb/linux-tdep: display ProtectionKey in info proc mappings In-Reply-To: References: <20260728152921.256276-1-matthieu.longo@arm.com> Date: Mon, 07 Sep 2026 16:24:48 +0100 Message-ID: <87fqzlqe2n.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: htY85tDnEx6ypOmBZkoensMyxxuDKLdjSmnpJPI-5UM_1788794690 X-Mimecast-Originator: redhat.com 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 Matthieu Longo writes: > On 28/07/2026 16:29, Matthieu Longo wrote: >> Memory Protection Keys provide a mechanism for enforcing page-based >> protections without requiring modification of the page tables >> when an application changes protection domains. [1] >> >> The "ProtectionKey" field may be present in /proc/PID/smaps on x86_64, >> PowerPC, and AArch64 systems since Linux 4.9, when the kernel is built >> with Memory Protection Keys support. >> >> Store the parsed PKey in smaps_data as an optional value on systems >> where the kernel reports memory protection keys. >> >> Parse /proc/PID/smaps alongside /proc/PID/maps when printing 'info >> proc mappings', and add a PKey column when at least one smaps entry >> contains a "ProtectionKey" field. >> This lets 'info proc mappings' show the protection key associated with >> each mapped address range. >> >> [1]: https://docs.kernel.org/core-api/protection-keys.html, >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/ >> linux.git/commit/?id=c1192f842841 >> --- >> gdb/linux-tdep.c | 93 ++++++++++++++++++++++++++++++++++++++++-------- >> 1 file changed, 78 insertions(+), 15 deletions(-) >> >> diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c >> index 2e9cb14d5bf..2cdf93f3193 100644 >> --- a/gdb/linux-tdep.c >> +++ b/gdb/linux-tdep.c >> @@ -124,6 +124,7 @@ struct smaps_data >> >> ULONGEST rss; >> ULONGEST swap; >> + std::optional pkey; >> }; >> >> /* Whether to take the /proc/PID/coredump_filter into account when >> @@ -907,6 +908,11 @@ extract_string_view_from_buffer (gdb::array_view &buffer, >> return {gdb::array_view (start, it), next_start}; >> } >> >> +/* Forward declaration of parse_smaps_data used in linux_info_proc below. */ >> + >> +static std::vector >> +parse_smaps_data (const file_reader_t &freader); >> + >> /* Implement the "info proc" command. */ >> >> static void >> @@ -1010,33 +1016,69 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, >> } >> if (mappings_f) >> { >> + /* Parse the content of /proc/PID/smaps. */ >> + bool pkey_column = false; >> + std::vector smaps_data; >> + file_reader_t smaps_freader >> + (string_printf ("/proc/%ld/smaps", ptid.lwp ())); >> + if (smaps_freader.error ()) >> + warning (_("unable to open /proc file '%s'"), >> + smaps_freader.c_filepath ()); >> + else if (smaps_freader) >> + { >> + smaps_data = parse_smaps_data (smaps_freader); >> + >> + /* Check whether "ProtectionKey" field is present. */ >> + pkey_column >> + = std::any_of (smaps_data.cbegin (), smaps_data.cend (), >> + [] (const struct smaps_data &d) -> bool >> + { return d.pkey.has_value (); }); >> + } >> + >> + /* Parse the content of /proc/PID/maps. */ >> + std::vector maps_data; >> file_reader_t map_freader >> (string_printf ("/proc/%ld/maps", ptid.lwp ())); >> - if (map_freader) >> + if (map_freader.error ()) >> + warning (_("unable to open /proc file '%s'"), >> + map_freader.c_filepath ()); >> + else if (map_freader) >> + { >> + auto content = map_freader.view (); >> + for (auto it = content.begin (); it != content.end ();) >> + { >> + auto [line, next_line_begin] >> + = extract_string_view_from_buffer (content, it, '\n'); >> + it = next_line_begin; >> + >> + /* read_mapping() expects a null-terminated string. */ >> + *std::prev (it) = '\0'; >> + maps_data.emplace_back (read_mapping (line.data ())); >> + } >> + } >> + >> + gdb_assert (maps_data.size () == smaps_data.size ()); >> + >> + if (maps_data.size () > 0) >> { >> gdb_printf (_("Mapped address spaces:\n\n")); >> - ui_out_emit_table emitter (current_uiout, 6, -1, "ProcMappings"); >> + int n_cols = (pkey_column ? 7 : 6); >> + ui_out_emit_table emitter (current_uiout, n_cols, -1, "ProcMappings"); >> >> int width = gdbarch_addr_bit (gdbarch) == 32 ? 10 : 18; >> current_uiout->table_header (width, ui_left, "start", "Start Addr"); >> current_uiout->table_header (width, ui_left, "end", "End Addr"); >> current_uiout->table_header (width, ui_left, "size", "Size"); >> current_uiout->table_header (width, ui_left, "offset", "Offset"); >> + if (pkey_column) >> + current_uiout->table_header (4, ui_left, "pkey", "PKey"); >> current_uiout->table_header (5, ui_left, "perms", "Perms"); >> current_uiout->table_header (0, ui_left, "objfile", "File"); >> current_uiout->table_body (); >> >> - auto content = map_freader.view (); >> - for (auto it = content.begin (); it != content.end ();) >> + auto it_smaps = smaps_data.cbegin (); >> + for (const auto &m: maps_data) >> { >> - auto [line, next_line_begin] >> - = extract_string_view_from_buffer (content, it, '\n'); >> - it = next_line_begin; >> - >> - /* read_mapping() expects a null-terminated string. */ >> - *std::prev (it) = '\0'; >> - struct mapping m = read_mapping (line.data ()); >> - >> ui_out_emit_tuple tuple_emitter (current_uiout, nullptr); >> current_uiout->field_core_addr ("start", gdbarch, m.addr); >> current_uiout->field_core_addr ("end", gdbarch, m.endaddr); >> @@ -1047,15 +1089,21 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, >> m.endaddr - m.addr)); >> current_uiout->field_string ("offset", >> paddress (gdbarch, m.offset)); >> + if (pkey_column) >> + { >> + if (it_smaps->pkey.has_value ()) >> + current_uiout->field_signed ("pkey", >> + it_smaps->pkey.value ()); >> + else >> + current_uiout->field_skip ("pkey"); >> + } >> current_uiout->field_string ("perms", m.permissions); >> current_uiout->field_string ("objfile", m.filename, >> file_name_style.style ()); >> current_uiout->text ("\n"); >> + ++it_smaps; >> } >> } >> - else >> - warning (_("unable to open /proc file '%s'"), >> - map_freader.c_filepath ()); >> } >> if (status_f) >> { >> @@ -1605,6 +1653,7 @@ parse_smaps_data (const file_reader_t &freader) >> int mapping_file_p; >> ULONGEST rss = -1; >> ULONGEST swap = -1; >> + int pkey = -1; >> >> memset (&v, 0, sizeof (v)); >> struct mapping m = read_mapping (line); >> @@ -1705,6 +1754,18 @@ parse_smaps_data (const file_reader_t &freader) >> mapping_anon_p = 1; >> } >> } >> + >> + if (streq (keyword, "ProtectionKey:")) >> + { >> + if (sscanf (line, "%*s%d", &pkey) != 1) >> + { >> + /* Remove the trailing column when printing the warning. */ >> + keyword[sizeof ("ProtectionKey:") - 2] = '\0'; >> + warning (_("Error parsing %s's value in {s,}maps file '%s'"), >> + keyword, freader.c_filepath ()); >> + break; >> + } >> + } >> } >> /* Save the smaps entry to the vector. */ >> struct smaps_data map; >> @@ -1724,6 +1785,8 @@ parse_smaps_data (const file_reader_t &freader) >> map.inode = m.inode; >> map.rss = rss; >> map.swap = swap; >> + if (pkey != -1) >> + map.pkey.emplace (pkey); >> >> smaps.emplace_back (map); >> } > > Ping. Isn't this patch blocked on some other patches being merged? I'm not sure it needs to be pinged if it doesn't apply yet. Apologies if I'm wrong here. Thanks, Andrew