From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wSz+GXPhS2r6BioAWB0awg (envelope-from ) for ; Mon, 06 Jul 2026 13:10:11 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=VS/MQLhj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 62E501E098; Mon, 06 Jul 2026 13:10:11 -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 9424B1E024 for ; Mon, 06 Jul 2026 13:10:10 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C72E94BA2E2A for ; Mon, 6 Jul 2026 17:10:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C72E94BA2E2A Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=VS/MQLhj Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010055.outbound.protection.outlook.com [52.101.85.55]) by sourceware.org (Postfix) with ESMTPS id 80A0E4BA2E0F for ; Mon, 6 Jul 2026 17:08:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80A0E4BA2E0F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 80A0E4BA2E0F Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.85.55 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1783357725; cv=pass; b=SbSQVdbuVQm98bNpDsKsgP4UckKLxAperTBwA9YViKDMC2ow/MrWrmTFk4xuYDU4tRUhonB1WvZFOcApMoeklnNSzt1GVnly1FBSgc/Sj0ZzHtFXOH8RDXwuzkkj9pK9P8vA2Bs82rrF/1QRzlKg4WxyjNWuhvZQtNJr0Gdqg9s= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1783357725; c=relaxed/simple; bh=V6dMxbj1DpEInVKawoknOMFOo4a9XHVokI6rf6Iabao=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Fjq8GXsz+iIyv9Af59ikW/YP2T5782dA9PP4hT+tT06u65r7TniYAwTJ1t3vOTVG4IzgVV90cPVt8od6vtUdn7x+l2vnYPyZ+7loD5ewlaA8VMjDninjbMEXr4Nzy0B6dvLPmuyzYf58KGvr/93ET5x7LzSg8KoJNYZxMIsJaik= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=VS/MQLhj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80A0E4BA2E0F ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=drYlcmRoWA4vCJ67qDgeMNYKs5KnHs13YxfVZDeeM6CSzcEJ5RXPDajlpp4pV2FfcjW85LeWNWuEIPYGOJgUf+ls7C54xnyG78psPhKzJcDXE/bxEtc02GKzmmpk1N841i7FcOwC1hPZGFSFv+BTh+jFQeRccqrPHYp+F1Hi7pVHpyKY0/CdzvCYxEd9okL0k0hYRADyoaUboZUD0Qc0Fh8iKFHyZW3/KMPDx3Uyf5jWqbNKMX8r+VtUyNBg4ogVWzf33BhBPPZVhBXQkaQIN+GzQuSObUOyt2Tnwv1UuJU36p6JgxM8FTAQYv+am4kAVf4Xi22uRX4xzkXNYxGlzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kUAWkp3U8g1uJwz/kMcTJVS4WTBNsuEZcAPOLS1nR4A=; b=k10SXfJ2qMueo0/55DcHepbweeKNxliqKKSrfLjnTFdEr7TH/t6QagitH/WrkfkpgDS1JNhq5a8S+1GMbliX34wF6At64gMQLB1oaca/is5Luwz1/zWF5D80Tr1pD2+B9kHc75G/oxJH76tQloUT1vGXSo6R/z4nNK+YZIIpAscQmq67DIWwWuwDms/JaVLw8to3A5xiVvuVRc1Hl9iapkk4DVlBz6GU2N0eYcdtnSrmywAsZjQmQw12qTYMoOYLYgYsd1MHWqi3a/qg0Hq0eO+puHvVn1u1w/FpQNV/7qfNhP7JAg24P102GpnRCCj3utNUuRI2ENfXcQzWOmPL5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=efficios.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kUAWkp3U8g1uJwz/kMcTJVS4WTBNsuEZcAPOLS1nR4A=; b=VS/MQLhj4kqKnp5BnMCMjCX1P9+s0+RI3G93B0UyIlQ6+7IbwfyjK4LuIt1qADzaa0I6+zm/a8kfgBm4IL8KF24Ktsc7ndv5zpdD6SCBznUc/o1t5LM3PIM21zarD5jEy0ywAvx15HgCWyXOfT71M85IjGryTltPrr28EddRhpc= Received: from BL0PR05CA0018.namprd05.prod.outlook.com (2603:10b6:208:91::28) by SJ0PR12MB8091.namprd12.prod.outlook.com (2603:10b6:a03:4d5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.10; Mon, 6 Jul 2026 17:08:29 +0000 Received: from BN2PEPF000044A8.namprd04.prod.outlook.com (2603:10b6:208:91:cafe::17) by BL0PR05CA0018.outlook.office365.com (2603:10b6:208:91::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.202.9 via Frontend Transport; Mon, 6 Jul 2026 17:08:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by BN2PEPF000044A8.mail.protection.outlook.com (10.167.243.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Mon, 6 Jul 2026 17:08:28 +0000 Received: from khazad-dum (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 6 Jul 2026 12:08:25 -0500 Date: Mon, 6 Jul 2026 18:08:02 +0100 From: Lancelot SIX To: Simon Marchi , Subject: Re: [PATCH v2 1/10] gdb/solib-rocm: assert that host ops isn't rocm_solib_ops Message-ID: <6gbkcfk4obf6kj7klfyrxumeatic3fnv3ppdiliu5xonlqecmj@5iy76y22ekzc> References: <20260608200100.666134-2-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20260608200100.666134-2-simon.marchi@efficios.com> X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb08.amd.com (10.181.42.217) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A8:EE_|SJ0PR12MB8091:EE_ X-MS-Office365-Filtering-Correlation-Id: bb56f078-05f2-4e04-f8a9-08dedb81331b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700016|1800799024|23010399003|376014|22082099003|18002099003|3023799007|6133799003|5023799004|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: CNpaq9AE4mQTdfZBN5M0sIahQKcc3NHkCNjj7jSfdYXK0nprS4upqUY9bFCye8unkiUsVUl1/9ZlnplVYj9MJzs1UFgugtgPBcDgNVwYdhpDhh57zx+lyqvFbX8jSZbKvNtLy4eJ0w0y1GrWQdgPyUIAqTgv9aHgTPpZLh7T6e5HiDJTW9FvRU/NzDRNci4SrDIyZupPkOlucIZkIDETKVned1qPdsinPdXYZrjMAxjrnUSVC7H0kY+gdaToWNzKUVcjI8Yqvbwzd9AN5bveNIvedohW0F8sMNDfbgzX8obYlu0Wh9bhKbBP3ica2FfttQeDBOUpIZsW4yo+wXOmP9Zk9jphHcq0eJVpgk4ed9OPvlfLyjESwebi/pOAskWCAfOq+Pc8c4ex4ytBSLxaLA4l+bouDUXxcNyOd9WgTJP0nBXXAGvMhG8RYbaWtA6AmBKpHPtt52asoKCOlUA3MLhCGa8qpttMr6I+n5EoOS//7iJwpRRWl+QWyBP3Y6mw/oDg0c9DZ5fX16+PTjbrVrMGPxA3quc7BmIxS6osptLkXwMi3rQDMtz7mEzCrVL0y3NgJgFRRysSFbCN87lGwshf4g4rKZpadNz2FQiHsHG0DO74pfaE9dAVf9gwPBjWnpIce2q1IDC7h2GjuBzaxPxjy1CisRFPQmGrU2dcg11DZqAs8PMcU4gHiG+bTeKUvTjxjlDwKIUs/iGNu9Al8A== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb08.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(36860700016)(1800799024)(23010399003)(376014)(22082099003)(18002099003)(3023799007)(6133799003)(5023799004)(56012099006)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uXlAWF75kebG1XxEcmTGoCDIFcqu8PJd2E8GISyUYO+1W9kaY/JsRYsOC5eZTHKF5HY8twYWK82ujMZtnTu03VpXOyozw21xKbgvG0ORWHk00kl8VpOIxybyZ0XzB7IwURdsPPwauEvRIlNmt5XjgNKh8oEmAlTU083+jNtoeVVc+3noWad8NClyzlAoNgOg0cYTcncLn1KnhopMRtpsi4L4eZKCLUWUedz2/i8AcMV7QiPWqJ9kKQWcjrKykW80roC1dH0ljBP8MFIXc43xgk0JUrVqLjzdUbOCq+VJKa0M7dcIVJlPSMN+0Y9nJoXjaOy4Mc6Z0fvBKgucQ7xDZCGETuR8UC4hxq7wO3smHv2mxTbGB4zcG+1OQ4FwLVZgiY7Zq+YrwkUHB3+/uFEZRbDyxuEbX6peRy/FWqaWv8RLcyURZlOxMgVf2gnUI3de X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2026 17:08:28.7495 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb56f078-05f2-4e04-f8a9-08dedb81331b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A8.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8091 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 On Mon, Jun 08, 2026 at 04:00:25PM -0400, Simon Marchi wrote: > In some fork cases, the rocm_solib_target_inferior_created observer gets > called while the child inferior (passed as a parameter) already has a > rocm_solib_ops installed. Since we unconditionally wrap the existing > solib_ops with a new rocm_solib_ops, we can end up with a chain of > multiple rocm_solib_ops, like: > > rocm_solib_ops -> rocm_solib_ops -> svr4_solib_ops > > I don't think it is technically harmful as of now (unless the process > does a ton of forks and the rocm_solib_ops accumulate), but it is for > sure useless. Add an assert for this in the rocm_solib_ops constructor, > which reveals the cases where this happens. > > When a fork happens with follow-fork-mode == child and detach-on-fork > on, infrun's follow_fork_inferior function directly moves the program > space from the parent the child inferior, as an optimization. Coming > into rocm_solib_target_inferior_created, the inferior's pspace > unexpectedly already has a rocm_solib_ops pushed. > > Fix this locally by using an inferior_forked observer. In the scenario > described above, remove the rocm_solib_ops and restore the host > solib_ops as the program space's solib_ops, to make it look as if infrun > didn't do this trick. This requires adding two parameters to the > inferior_forked observer (detach_on_fork and follow_child). > > This should probably be done by infrun directly at some point. The > logic being that it's fine to do an optimization, but it should look as > if it didn't occur. If infrun created a brand new pspace for the child, > there wouldn't be a rocm_solib_ops there already. But I prefer a local > fix for now. > > Finally, there are also the vfork cases, where the child inferior shares > the program space with its parent, and therefore the child's program > space already has a rocm_solib_ops installed. Address this case by > returning early (the `inf->vfork_parent != nullptr` check), because > there is nothing we want to do for a vfork child anyway. Hi Simon, Sorry for the very delayed reply. Given our previous discussions on list (on the V1), this LGTM, thanks. Approved-by: Lancelot Six (amdgpu) This of course only covers the amdgpu bits. Best, Lancelot > > Change-Id: I2e76d111e96f1e01b6799b04da9cdd6f6e2984c9 > --- > gdb/amd-dbgapi-target.c | 3 ++- > gdb/infrun.c | 3 ++- > gdb/observable.h | 8 ++++++-- > gdb/solib-rocm.c | 31 +++++++++++++++++++++++++++++++ > 4 files changed, 41 insertions(+), 4 deletions(-) > > diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c > index d44f03d0b80a..6b2314f7de79 100644 > --- a/gdb/amd-dbgapi-target.c > +++ b/gdb/amd-dbgapi-target.c > @@ -2335,7 +2335,8 @@ amd_dbgapi_inferior_execd (inferior *exec_inf, inferior *follow_inf) > > static void > amd_dbgapi_inferior_forked (inferior *parent_inf, inferior *child_inf, > - target_waitkind fork_kind) > + target_waitkind fork_kind, bool detach_on_fork, > + bool follow_child) > { > if (child_inf != nullptr) > { > diff --git a/gdb/infrun.c b/gdb/infrun.c > index 22a056084861..2edd6e0445b3 100644 > --- a/gdb/infrun.c > +++ b/gdb/infrun.c > @@ -699,7 +699,8 @@ holding the child stopped. Try \"set %ps\" or \"%ps\".\n"), > target_follow_fork (child_inf, child_ptid, fork_kind, follow_child, > detach_fork); > > - gdb::observers::inferior_forked.notify (parent_inf, child_inf, fork_kind); > + gdb::observers::inferior_forked.notify (parent_inf, child_inf, fork_kind, > + detach_fork, follow_child); > > /* target_follow_fork must leave the parent as the current inferior. If we > want to follow the child, we make it the current one below. */ > diff --git a/gdb/observable.h b/gdb/observable.h > index 9f1c33ba7100..979e9d1c3ace 100644 > --- a/gdb/observable.h > +++ b/gdb/observable.h > @@ -92,9 +92,13 @@ extern observable > the child (because we follow only the child or we follow both), CHILD_INF > is the child inferior. Otherwise, CHILD_INF is nullptr. > > - FORK_KIND is TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED. */ > + FORK_KIND is TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED. > + > + DETACH_ON_FORK and FOLLOW_CHILD represent the "detach-on-fork" and > + "follow-fork-mode" settings. */ > extern observable - target_waitkind /* fork_kind */> inferior_forked; > + target_waitkind /* fork_kind */, bool /* detach_on_fork */, > + bool /* follow_child */> inferior_forked; > > /* The shared library specified by SOLIB has been loaded. Note that > when gdb calls this observer, the library's symbols probably > diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c > index 34cb2bb9e57c..dcaa0ee980a3 100644 > --- a/gdb/solib-rocm.c > +++ b/gdb/solib-rocm.c > @@ -165,8 +165,14 @@ struct rocm_solib_ops : public solib_ops > explicit rocm_solib_ops (program_space *pspace, solib_ops_up host_ops) > : solib_ops (pspace), m_host_ops (std::move (host_ops)) > { > + gdb_assert (m_host_ops != nullptr); > + gdb_assert (dynamic_cast (m_host_ops.get ()) == nullptr); > } > > + /* Release the host solib_ops. */ > + solib_ops_up release_host_ops () > + { return std::move (m_host_ops); } > + > /* The methods implemented by rocm_solib_ops. */ > owning_intrusive_list current_sos () const override; > void create_inferior_hook (int from_tty) const override; > @@ -820,6 +826,10 @@ rocm_update_solib_list () > static void > rocm_solib_target_inferior_created (inferior *inf) > { > + /* A vfork child shares its pspace with its parent, do not touch anything. */ > + if (inf->vfork_parent != nullptr) > + return; > + > get_solib_info (inf)->solib_list.clear (); > > auto prev_ops = inf->pspace->release_solib_ops (); > @@ -851,6 +861,24 @@ rocm_solib_target_inferior_execd (inferior *exec_inf, inferior *follow_inf) > get_solib_info (exec_inf)->solib_list.clear (); > } > > +static void > +rocm_solib_target_inferior_forked (inferior *parent_inf, inferior *child_inf, > + target_waitkind fork_kind, > + bool detach_on_fork, bool follow_child) > +{ > + if (detach_on_fork && follow_child && fork_kind == TARGET_WAITKIND_FORKED) > + { > + /* In this particular configuration, infrun's follow_fork_inferior > + function moves the parent pspace to the child directly. Remove the > + existing rocm_solib_ops from the child and restore the host solib_ops, > + to make it look like a brand new pspace. */ > + auto rocm_ops_holder = child_inf->pspace->release_solib_ops (); > + auto rocm_ops > + = gdb::checked_static_cast (rocm_ops_holder.get ()); > + child_inf->pspace->set_solib_ops (rocm_ops->release_host_ops ()); > + } > +} > + > INIT_GDB_FILE (rocm_solib) > { > /* The dependency on the amd-dbgapi exists because solib-rocm's > @@ -864,4 +892,7 @@ INIT_GDB_FILE (rocm_solib) > gdb::observers::inferior_execd.attach > (rocm_solib_target_inferior_execd, "solib-rocm", > { &get_amd_dbgapi_target_inferior_execd_observer_token () }); > + > + gdb::observers::inferior_forked.attach > + (rocm_solib_target_inferior_forked, "solib-rocm"); > } > -- > 2.54.0