From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2087.outbound.protection.outlook.com [40.107.103.87]) by sourceware.org (Postfix) with ESMTPS id 6AC0D385616B for ; Fri, 21 Oct 2022 09:21:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6AC0D385616B ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=CdEo9CMmcPxAT0vhu7Sn6yNszcVqqnQfALt4aeDfem4NtYDZWcM7YtfWJeuMcvhr2vxehyKfug9HNLVNJUUsldoF8+7hcwfAgQhacFd6cZytEHAFbHmUymMixd8HRqCbUFFo1L6ZYirxFKBnzplWn7t9Qrut5sel/U9PMPWAdWJJ+9nt3JLDcyeiBzSjHWt6bqXfmBTgjW9B2kbIrL4zDssRto21xixUzKQETjfsy8DY1LGAJdGm7XMvri+nAXgxGUG9YX9dcGIyodUs4fVXbaUFd1qjefVtJR1+ux/StVy0cX0JLb+p5OBmNeqP8lNDMLjcftTr3NvIvPGlDUxnMg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=2AZPKCXtVgEEJ9fPuUHyAAfP1SWXjtwGr4qEEjGL/UE=; b=FafPMv1qZbb72q4moSiiKglxUMa0D9PpJVXqTE/58wuwwFmmL2XPHZpCByf7bcW7IBVDoIk/mNEqCWX2Bwe4cAy9D58lSMAadpaRkTZRSK4bctJbmJTZoiGYEvh0T+QOhraV0c2+lxpKUq2Fiuhycbk7ulMMivfQDEA4/aGe0U5yUUuUNKSQ89SxLNu/HGtoxNz5Fne2S5GqifQxFY82PUK3w7CeAhOj7w/5zrDvlMXMJPJqrn84ny9+FpZHtPKXtyYbk6109Rcp2nOPJ3uCrpa2W/JJmoAZikR5UJ+q5wfs+z9NozOuASPnTlPVFKjWuJNilyLm62PPed7FRithKw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB8PR06CA0057.eurprd06.prod.outlook.com (2603:10a6:10:120::31) by AS8PR08MB9362.eurprd08.prod.outlook.com (2603:10a6:20b:5a9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Fri, 21 Oct 2022 09:20:57 +0000 Received: from DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:120:cafe::1d) by DB8PR06CA0057.outlook.office365.com (2603:10a6:10:120::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15 via Frontend Transport; Fri, 21 Oct 2022 09:20:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT025.mail.protection.outlook.com (100.127.142.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.10 via Frontend Transport; Fri, 21 Oct 2022 09:20:57 +0000 Received: ("Tessian outbound f394866f3f2b:v130"); Fri, 21 Oct 2022 09:20:57 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ade5f87555fd0842 X-CR-MTA-TID: 64aa7808 Received: from 948abb6886f8.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2B62E47B-E1A5-42F8-801C-6C9D5A33F400.1; Fri, 21 Oct 2022 09:20:50 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 948abb6886f8.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 21 Oct 2022 09:20:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KRaQlYunhNfBqg0SQEF1mku+P+Dutyefu/lKbpDOdEJ0WKOS5viphTM6zfnkBwMdHIjwfpPjvo2nXY0r4NfMGd86cqVBcdlAOaNv7hxzsI7H3TlaetZ31nRBXZjg6xN14Mies5SJOgypWI9rZkr1EioZCk0C7sSrcgg56R5kZEgIJiLt+SfYBPvy8YdwjIjkyQpyoCLVOv2VEDqPx+xCedtQIzh9JdtDOUYlA4elHhuIm+ogTXCK4AS4tiaDWPyd3XKi4MAfzr9q2rbdiul9SPJhWK85O6ff8hvW6U9cNbqDVps0Ax53WDRSATWcRJCeSJPgxmKGkNYukQhmkuuMgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=2AZPKCXtVgEEJ9fPuUHyAAfP1SWXjtwGr4qEEjGL/UE=; b=dCVKFR8aopDXE75cBWtcPVgO7oR5NhHST4oMsUNsdGo4oX9V96u3JdBCp8SxabXKuh8o3NI0WmOAqPYHZ2hGtC6mO+9KN4SrF5/MSlhQ5sMQEk1kS6+/c8XnIoyZ8AfDvmUg6ar8vIVSc1KErbfXDIzAElnVUBhDS6309UdB4SXFKrhYfyOEAl3TS3od8zybtXkDw5hFplMIl1OZhR5BeLTmNuKjaHldUyBLIikysiAW8CSaOFVrHquUuLgVXjtu+UXGxylCkvRY9R3OeQj9UcS6oeGxe238chRX1BKVZVTIT6RGbGdu54tGvjRE4KAaaY08E8ZCMyzA0qwQgerHjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by DB8PR08MB5402.eurprd08.prod.outlook.com (2603:10a6:10:11b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32; Fri, 21 Oct 2022 09:20:46 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7f57:1601:9b18:7529]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7f57:1601:9b18:7529%7]) with mapi id 15.20.5723.034; Fri, 21 Oct 2022 09:20:45 +0000 Message-ID: Date: Fri, 21 Oct 2022 10:20:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3] gdb/arm: Terminate frame unwinding in M-profile lockup state Content-Language: en-US To: Tomas Vanek , gdb-patches@sourceware.org, Torbjorn SVENSSON References: <1666035056-19619-1-git-send-email-vanekt@fbl.cz> From: Luis Machado In-Reply-To: <1666035056-19619-1-git-send-email-vanekt@fbl.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SA0PR11CA0205.namprd11.prod.outlook.com (2603:10b6:806:1bc::30) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|DB8PR08MB5402:EE_|DBAEUR03FT025:EE_|AS8PR08MB9362:EE_ X-MS-Office365-Filtering-Correlation-Id: 21cd738b-881b-4230-04bc-08dab3458fd2 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: wajoN02R7ZR2U5BYAsdEy5L8J9qDgcF1NkZke96XCNdyoyLvj9fZ8rfHZRFAmPnAvFNrRJPL/V/tdR6+9C36Vydl30mAIoSonpRgeC7/BalCvYhc/TYQDmlV4KQRvkQ8XsqSe1ADC5K2oCAONets6zoQOpAYoQgruHvOqaYJhclabvA5IDkCSsd2ezzg91jxfyOp1vAB0LD1Po+4YzmPpNGBtpb9ezxiD8/fHzIIXASoufhym8vyWIXFhPekbbommoA+eDoewvhnjlC1Gvy7eg/HjL9LawkQ3Fm0gECg7wwN3qkKK5hybyJirInbVG+0U95M1UUHLsrlUtrPuIqk2O/IVHGTbpPsFDEcFRW7LUmXVbV/CSf9qw229YXoGapg4oGwPjNfkybIvXmzAVRC47SOAtzICO1+MklMmhRafJ+Lg7qq+bp86eiywwiSf4kb+0MNeFCwnHA6RmXFmIdm+R/bNLmSmlvN+ngwI+NuXcMwnTvijdGtp2dZ3d0Vp0H0O/T75KYDivzsmqpaufjnTERaazwmh1oH9j6VtiSBAdJSMNY4sg9L4uKjk9yKNV99cADCf0QtKJjp3LZxPQbn+K+4mtAtxVF9Zn66CF2iMV52rWkuYnlrs0kwxWkeYuGaQPR4OQ2g+QO+2dKXVoMUlfZ6yoAJHkGyGnep5kzdJfxsYSlg29jNfQHEePLR0EbmsvcijwGfvS5q+FzQBrV8Ffl/wE8llpJHHTRj6zy5D7fzFiTk9nuuCmFNEOMIMrJZ9ttmzx80qngJiKMn+h0CTEtX4eY8uMFxioK5AVlp/4c= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB3919.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(376002)(346002)(39860400002)(396003)(451199015)(41300700001)(316002)(66556008)(44832011)(110136005)(36756003)(2906002)(8936002)(478600001)(66476007)(5660300002)(66946007)(38100700002)(2616005)(8676002)(31696002)(186003)(53546011)(66574015)(6512007)(6666004)(26005)(6486002)(83380400001)(86362001)(6506007)(31686004)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5402 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 0c843304-7829-4ec8-96b3-08dab3458839 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z3ochOT+HTcsG/ZhywHp8NEFjSFVfisYNVK/uMRgTSLQU3puLFaRHRmBZEy0MikmiBdnIFwepB0jVQXQrPg0A/MoU5RPFy3AgZZOaipJko4V36jVFfRNZITUXvhgMPtx7xEOJVNJ12Evheby5G8cmISxkgPz2xceF/wMhwSDpXkULj2f3cz6/Lc9h0QuM78HRfJexFUCHN7Xuri32jTtcbBJ0HBEnltpCVfsFsaQA8+5kL9v3iFyNoa31On19G6yWaLS5QpjWZjEwssBTzn3Dz0rruQRAvW3Caou2As8cc7RxbuUcK/SnhtLS92HW9Mv7RV8romorVHbqgdHzd5lEMO/Y88TfM4+9iBfqQlTiqko2Ukr9x17rkh3C+Z2L4IR4Eg6GRnPGaZ+ZDKOJLkHQtnXhmheuI78pW36cnkkLH2aKVErZGglF3k7mCOyZ3h644X9ijd1pM15kqVk8B4eoEoEH7fISkJQa4TKsZFqPghOcBtegAxukie+MlXlN7kpWAuKeDVdgNXoYNftjey57RIVKwiAGzMbx6o9oM3ROH+1BGdwDYMDxCTw1kC1Zxlbo1Z/J24lgKXH+nlbbtQbxbAOaQ6bHUg8sy6X/K/pVN7Np+oSJQJkDejwGWf/2tttD6ORbwoSDEdoxJQfw9tXEN3HcJPITv0vRyUL3I50cqyGPc1ZoY+flOC98MKCFfBGb1c0YvYx9Ks4CbSwO9Vws3bXcc7wpCAut3HePjm7khmK1ag/5Ils1WZCvciKhGU0lL4kXT59AOGnPtBVqRskb8VNXAhHlQOPJhY994jgdhWW1DqolFv+XK4qPCCJGjsw X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(396003)(346002)(39860400002)(376002)(136003)(451199015)(46966006)(36840700001)(40470700004)(66574015)(47076005)(83380400001)(82740400003)(82310400005)(356005)(36756003)(40460700003)(86362001)(40480700001)(36860700001)(31696002)(6666004)(81166007)(316002)(110136005)(5660300002)(44832011)(31686004)(53546011)(2616005)(186003)(8936002)(2906002)(70206006)(6506007)(70586007)(478600001)(6512007)(41300700001)(26005)(8676002)(6486002)(336012)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2022 09:20:57.3211 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21cd738b-881b-4230-04bc-08dab3458fd2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9362 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2022 09:21:04 -0000 On 10/17/22 20:30, Tomas Vanek wrote: > In the lockup state the PC value of the the outer frame is irreversibly > lost. The other registers are intact so LR likely contains > PC of some frame next to the outer one, but we cannot analyze > the nearest outer frame without knowing its PC > therefore we do not know SP fixup for this frame. > > The frame unwinder possibly gets mad due to the wrong SP value. > To prevent problems terminate unwinding if PC contains the magic > value of the lockup state. > > Example session wihtout this change, > Cortex-M33 CPU in lockup, gdb 13.0.50.20221016-git: > ---------------- > (gdb) c > Continuing. > > Program received signal SIGINT, Interrupt. > 0xeffffffe in ?? () > (gdb) bt > #0 0xeffffffe in ?? () > #1 0x0c000a9c in HardFault_Handler () > at C:/dvl/stm32l5trustzone/GPIO_IOToggle_TrustZone/Secure/Src/stm32l5xx_it.c:99 > #2 0x2002ffd8 in ?? () > Backtrace stopped: previous frame identical to this frame (corrupt stack?) > (gdb) > ---------------- > The frame #1 is at correct PC taken from LR, #2 is a total nonsense. > > With the change: > ---------------- > (gdb) c > Continuing. > > Program received signal SIGINT, Interrupt. > warning: ARM M in lockup state, stack unwinding terminated. > > (gdb) bt > #0 > (gdb) > ---------------- > > There is a visible drawback of emitting a warning in a cache buildnig routine > as introduced in Torbjörn SVENSSON's > [PATCH v4] gdb/arm: Stop unwinding on error, but do not assert > The warning is printed just once and not repeated on each backtrace command. > > v2 update: warning supressed for other frames than the innermost one. > v3 update: boolean values and comment fixes > > Signed-off-by: Tomas Vanek > --- > gdb/arm-tdep.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 52 insertions(+), 3 deletions(-) > > diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c > index b5facae..aefd241 100644 > --- a/gdb/arm-tdep.c > +++ b/gdb/arm-tdep.c > @@ -724,9 +724,30 @@ class target_arm_instruction_reader : public arm_instruction_reader > return 0; > } > > +static inline bool > +arm_m_addr_is_lockup (CORE_ADDR addr) > +{ > + switch (addr) > + { > + /* Values for lockup state. > + For more details see "B1.5.15 Unrecoverable exception cases" in > + both ARMv6-M and ARMv7-M Architecture Reference Manuals, or > + see "B4.32 Lockup" in ARMv8-M Architecture Reference Manual. */ > + case 0xeffffffe: > + case 0xfffffffe: > + case 0xffffffff: > + return true; > + > + default: > + /* Address is not lockup. */ > + return false; > + } > +} > + > /* Determine if the address specified equals any of these magic return > values, called EXC_RETURN, defined by the ARM v6-M, v7-M and v8-M > - architectures. > + architectures. Also include lockup magic PC value. Formatting: Two spaces after '.' > + Check also for FNC_RETURN if we have v8-M security extension. we have -> we have the > > From ARMv6-M Reference Manual B1.5.8 > Table B1-5 Exception return behavior > @@ -769,6 +790,9 @@ class target_arm_instruction_reader : public arm_instruction_reader > static int > arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr) > { > + if (arm_m_addr_is_lockup (addr)) > + return 1; > + > arm_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); > if (tdep->have_sec_ext) > { > @@ -3355,6 +3379,30 @@ struct frame_unwind arm_stub_unwind = { > describes which bits in LR that define which stack was used prior > to the exception and if FPU is used (causing extended stack frame). */ > > + /* In the lockup state PC contains a lockup magic value. > + The PC value of the the next outer frame is irreversibly > + lost. The other registers are intact so LR likely contains Formatting: Two spaces after '.'. > + PC of some frame next to the outer one, but we cannot analyze > + the next outer frame without knowing its PC > + therefore we do not know SP fixup for this frame. > + Some heuristics to resynchronize SP might be possible. > + For simplicity just terminate unwinding to prevent the unwinder > + going mad. */ How about... For simplicity, just terminate the unwinding to prevent it going astray and attempting to read data/addresses it shouldn't, which may cause further issues due to side-effects. Does that make sense? > + CORE_ADDR pc = get_frame_pc (this_frame); > + if (arm_m_addr_is_lockup (pc)) > + { > + /* The lockup can be real just in the innermost frame > + as the CPU is stopped and cannot create more frames. > + If we hit lockup magic PC in the other frame, it is > + just a sentinel at the top of stack: do not warn then. */ > + if (frame_relative_level (this_frame) == 0) > + warning (_("ARM M in lockup state, stack unwinding terminated.")); > + > + /* Terminate any further stack unwinding. */ > + arm_cache_set_active_sp_value (cache, tdep, 0); > + return cache; > + } > + > CORE_ADDR lr = get_frame_register_unsigned (this_frame, ARM_LR_REGNUM); > > /* ARMv7-M Architecture Reference "A2.3.1 Arm core registers" > @@ -3824,11 +3872,12 @@ struct frame_unwind arm_stub_unwind = { > return arm_m_addr_is_magic (gdbarch, this_pc); > } > > -/* Frame unwinder for M-profile exceptions. */ > +/* Frame unwinder for M-profile exceptions (EXC_RETURN on stack), > + lockup and secure/nonsecure interstate function calls (FNC_RETURN). */ > > struct frame_unwind arm_m_exception_unwind = > { > - "arm m exception", > + "arm m exception lockup sec_fnc", > SIGTRAMP_FRAME, > arm_m_exception_frame_unwind_stop_reason, > arm_m_exception_this_id, Torbjörn, have you managed to exercise this on your end? Does it behave as expected (stops unwinding gracefully)? From looking at the code, this looks OK to me, but I don't have the proper setup to exercise it.