From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B269C77B7E for ; Tue, 2 May 2023 06:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233453AbjEBGRE (ORCPT ); Tue, 2 May 2023 02:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233537AbjEBGQ4 (ORCPT ); Tue, 2 May 2023 02:16:56 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3BB42723 for ; Mon, 1 May 2023 23:16:53 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 341LOrPr009135; Tue, 2 May 2023 06:16:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2023-03-30; bh=nULBJ8az7WdnOgNrP9ktSW+gAYwZGktn1jNIuxEDG58=; b=y+TMPNGx2bpaGDT2APAUtF7H9NyQdOz2qd6sOzVxBurVhA4/fDaO9QpWWK5eHJclyQVg +c6d2ADNOebSwZSdcyuyvTpttYAp7lxP3gJtozGkx89p3dGUSq3LAR579Si/cdxKebo/ TUt76tslYH7GEuI65RIWdhQmj5j5uCiB5IpJImTDXjaT7K1hHgPN+Inp5RbYwGEH3Whv YMGDj5VN/ySS8aNM6EV2c7NH33eM+Ct4XwfDnBroBgIfSc/V/Ose3lDHlDXqt1uEcuRU D0GmP2ibBBuz6WCon89vIbzDwfL1WHq6xICEt+qKfLlwa1MAkQYKAZzucoDxKKDBqbIV Uw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8t5fkw03-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 02 May 2023 06:16:46 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3425Kl1G003572; Tue, 2 May 2023 06:16:45 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp5h8u2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 02 May 2023 06:16:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jArvhEXkQERbm4XpQz0Qcx7itp1xZLSaHvsVnKkXTmBwcDJDVMU6X+SsdfSNCfEmMhDs48EyuojS/i+9kC71eXaxNELOdvDzxDLrvDPW5mDhjxpEOhGBJfVts9PFsS78wWKq5n4m+gP6YKM0uB9fEAlMspNX4uiGQha5E/sn7jg56MHZmTn7LSIbj3aVWxfa+Hsh+EVv/hL/iB2bDXWrmNo3KzMeKzUYkq4+WP/OPSM7lmKDIf9Z7z1+2jmiVT7WYH8yDky2jwJauf6I0UPL+lREoDYuCFr0cPUx4iWf1OXFazE24dkqpr/t2KxJElEf7p85wAC5jkeTxJAdhovzRA== 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=nULBJ8az7WdnOgNrP9ktSW+gAYwZGktn1jNIuxEDG58=; b=eKwCDXxqFDwyTJ5UmF/5Y5m+qj33QbTz5th58rz/HMGPBy3ZzXcFTA2iihEew8VZ3U8xz8l7CJwticozOSqB/jFxU5PkZacW45nAXcozan8yxa5jgtTEd5NW6NH6exTTVAWMyCQ+0Xk5d8NEpzKZJ0ACS/WJql9OB2LAnYLPhNHShDFGObn8LiWOMIgUJqJ+8uBhX49byJvE+QcG3UvFihVzPk+5xPG4wVOxpZlnUZRdBRR+UKnsM7DhI5Mj4qQSnT3GI4Rb4ImqnY9/yJivWwm2kWvXlsI5yQh7xpEmIKJOopEdNpEma7RSNF5hSCbDj5pTsfjPHA5oSjPFXI1IkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nULBJ8az7WdnOgNrP9ktSW+gAYwZGktn1jNIuxEDG58=; b=OhW0C43sX9z9ruvKg/zgBD9hgT+K+JylrZAtKIKLwZ4csZKtu0LOSdFoBtanlAQ5cig3P3UV0I/tAxVUyMyfzQ0tvziLP7nUS2FI0LB/WgyeYCYE3Kb/HUxDp29QROy5BN4XLByUHky/1sLvdwUUDWeuYLVocNKHDgLtLclALBs= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by DS0PR10MB6894.namprd10.prod.outlook.com (2603:10b6:8:134::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 06:16:42 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ff1c:f1fb:8db9:22e2]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ff1c:f1fb:8db9:22e2%6]) with mapi id 15.20.6340.030; Tue, 2 May 2023 06:16:42 +0000 Message-ID: <84bf4aee-e5a5-8e49-3826-ecb79eefc85b@oracle.com> Date: Mon, 1 May 2023 23:16:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [POC 4/5] sframe: add an SFrame format stack tracer Content-Language: en-US To: Steven Rostedt Cc: linux-toolchains@vger.kernel.org, daandemeyer@meta.com, andrii@kernel.org, kris.van.hees@oracle.com, elena.zannoni@oracle.com, nick.alcock@oracle.com References: <20230501200410.3973453-1-indu.bhagat@oracle.com> <20230501200410.3973453-5-indu.bhagat@oracle.com> <20230501190018.24ae7704@gandalf.local.home> From: Indu Bhagat In-Reply-To: <20230501190018.24ae7704@gandalf.local.home> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MW4PR03CA0023.namprd03.prod.outlook.com (2603:10b6:303:8f::28) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|DS0PR10MB6894:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f81ffb5-eebd-4ded-2531-08db4ad4cc4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NyPtZqmY2+YlW9M1RQ97pmycMjR/ot9EP2dWoqEc2eju15LMmadrN+0gWAfMgEXZmazgtYk0zwU7EofPW7e/4UnrKHK/iIINX1Jt9EEZXFHkBnq9xwExYoAL5t3ECDeTkozSP3Kh8dKtK5Z9/35bsdKe6fFU/ccXprlMBjsUgLYQ7/e9RGy4MiiQOdFCSwNj/GV3+0kbVyf2coeo5bnhgykrhDIU+3RhNtTX+rSQkgAPiF8Q3SW/+TmKDpNlnz/1/PMvfLrnvOTswZf0TzzqHQsJnTOF3+wot3X9trsD5oPSuyCsCWN+f8pN+I18Ia7R02MNvPf2Zz3tRnj0jItSKpKkh3WZH90qPpHPEz9xA8vduhTM143HdPds8WrMusO0krqafZw9XFY0ZI47CUUjNWPqHVOEQ8Lvco3+z6n12k/0RjC+Z2AdM9dZiaa/c7Bt+srVRSxfNfp5frukuWs2hsbiakzdPz4Yzzwq0SyXONYS3SMj0tM3O0LK6U12mtnh8wnC6ziSXMiVhebKTrJf12LzYYGaaYYwzRRuLnZPaVHgSaGxld9FjvXhfHUzyqO9f5kRRddAUVfmU76Rqjndrqtm0xabDiIytxs+LHJtbxncz1TKMXpaUmUJ6bKpACLAvGpHCEk7sgVMXsZN8nshhw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2158.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(376002)(396003)(346002)(136003)(366004)(451199021)(36756003)(83380400001)(107886003)(44832011)(41300700001)(2616005)(6486002)(6666004)(6506007)(6512007)(186003)(53546011)(2906002)(30864003)(5660300002)(38100700002)(4326008)(66946007)(66556008)(66476007)(6916009)(8676002)(8936002)(31696002)(86362001)(316002)(478600001)(31686004)(66899021)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?QTBvSk1Sbk9PbHZGa1Rub000NDl5WDJtL0lua011Z0tTcHVISWtCdEg5NFd4?= =?utf-8?B?aXgrV1dIUEVZbFdZT3l2VWR3OWtyTnVYVTFBZ3BtUFFtMUNN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XExEbzs5a9DDfgjGyHJ/Qv+oAzYQXfOrCNKTf6JrVJidRN2J02SzKl/mjlX/wIOU3WOawRHLROEEHSxwtRydNbw7CBsnLb5ROmHtEesH4Z4rvYYb1w250WMR7KUp9VjGhPixBu63DMcv2eFR4cWv48/M00Bp35VL45Myu1nb1dkEnwMZot4kfrHdpRjLp/P7E7pULP8oNVyWuXSHfD2CNndrGGSM/JIcvUoo86aA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f81ffb5-eebd-4ded-2531-08db4ad4cc4a X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 06:16:42.5693 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QSTEzar95KzS589lvu3QrZwvZ3BLP3ZgbwO8zGOoDbF81y6Hq16SN/1Qnq3/NLfrOB5s7sdmE57KWj1ZckDIlw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6894 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-02_02,2023-04-27_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305020054 X-Proofpoint-GUID: T4QIFUL4tTDCSPIYuWgctMSXFUX9jeWa X-Proofpoint-ORIG-GUID: T4QIFUL4tTDCSPIYuWgctMSXFUX9jeWa Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On 5/1/23 16:00, Steven Rostedt wrote: > On Mon, 1 May 2023 13:04:09 -0700 > Indu Bhagat wrote: > >> This patch adds an SFrame format based stack tracer. >> >> The files iterate_phdr.c, iterate_phdr.h implement a dl_iterate_phdr() >> like functionality. >> >> The SFrame format based stack tracer is implemented in the >> sframe_unwind.c with architecture specific bits in the >> arch/arm64/include/asm/sframe_regs.h and >> arch/x86/include/asm/sframe_regs.h. Please note that the SFrame format >> is supported for x86_64 (AMD64 ABI) and aarch64 (AAPCS64 ABI) only at >> this time. >> >> The files sframe_state.[ch] implement the SFrame state management APIs. >> >> Some aspects of the implementation are "POC like". These will need to >> addressed for the implementation to become more palatable: >> - dealing with only Elf64_Phdr (no Elf32_Phdr) at this time, and other >> TODOs in the iterate_phdr.c, >> - detecting whether a program did a dlopen/dlclose, >> - code stubs around user space memory access (.sframe section, ELF hdr >> etc.) by the kernel need careful review. >> >> There are more aspects than above; The intention of this patch set is to >> help drive the discussion on how to best incorporate an SFrame-based user >> space unwinder in the kernel. >> >> Signed-off-by: Indu Bhagat >> --- >> arch/arm64/include/asm/sframe_regs.h | 37 +++ >> arch/x86/include/asm/sframe_regs.h | 34 +++ >> include/sframe/sframe_regs.h | 11 + >> include/sframe/sframe_unwind.h | 62 ++++ >> lib/sframe/Makefile | 8 +- >> lib/sframe/iterate_phdr.c | 113 +++++++ >> lib/sframe/iterate_phdr.h | 34 +++ >> lib/sframe/sframe_state.c | 424 +++++++++++++++++++++++++++ >> lib/sframe/sframe_state.h | 80 +++++ >> lib/sframe/sframe_unwind.c | 208 +++++++++++++ >> 10 files changed, 1010 insertions(+), 1 deletion(-) >> create mode 100644 arch/arm64/include/asm/sframe_regs.h >> create mode 100644 arch/x86/include/asm/sframe_regs.h >> create mode 100644 include/sframe/sframe_regs.h >> create mode 100644 include/sframe/sframe_unwind.h >> create mode 100644 lib/sframe/iterate_phdr.c >> create mode 100644 lib/sframe/iterate_phdr.h >> create mode 100644 lib/sframe/sframe_state.c >> create mode 100644 lib/sframe/sframe_state.h >> create mode 100644 lib/sframe/sframe_unwind.c >> >> diff --git a/arch/arm64/include/asm/sframe_regs.h b/arch/arm64/include/asm/sframe_regs.h >> new file mode 100644 >> index 000000000000..ae9ab9d5d3c1 >> --- /dev/null >> +++ b/arch/arm64/include/asm/sframe_regs.h >> @@ -0,0 +1,37 @@ >> +/* SPDX-License-Identifier: GPL-2.0-or-later */ >> +/* >> + * Copyright (C) 2023, Oracle and/or its affiliates. >> + */ >> + >> +#ifdef ASM_ARM64_SFRAME_REGS_H >> +#define ASM_ARM64_SFRAME_REGS_H >> + >> +#define STACK_ACCESS_LEN 8 >> + >> +static inline uint64_t >> +get_ptregs_ip(struct pt_regs *regs) >> +{ >> + return regs->pc; >> +} >> + >> +static inline uint64_t >> +get_ptregs_sp(struct pt_regs *regs) >> +{ >> + return regs->sp; >> +} >> + >> +static inline uint64_t >> +get_ptregs_fp(struct pt_regs *regs) >> +{ >> +#define UNWIND_AARCH64_X29 29 /* 64-bit frame pointer. */ >> + return (uint64_t)regs->regs[UNWIND_AARCH64_X29]; >> +} >> + >> +static inline uint64_t >> +get_ptregs_ra(struct pt_regs *regs) >> +{ >> +#define UNWIND_AARCH64_X30 30 /* 64-bit link pointer. */ >> + return (uint64_t)regs->regs[UNWIND_AARCH64_X30]; >> +} >> + >> +#endif /* ASM_ARM64_SFRAME_REGS_H */ >> diff --git a/arch/x86/include/asm/sframe_regs.h b/arch/x86/include/asm/sframe_regs.h >> new file mode 100644 >> index 000000000000..99f84955854a >> --- /dev/null >> +++ b/arch/x86/include/asm/sframe_regs.h >> @@ -0,0 +1,34 @@ >> +/* SPDX-License-Identifier: GPL-2.0-or-later */ >> +/* >> + * Copyright (C) 2023, Oracle and/or its affiliates. >> + */ >> + >> +#ifndef ASM_X86_SFRAME_REGS_H >> +#define ASM_X86_SFRAME_REGS_H >> + >> +#define STACK_ACCESS_LEN 8 >> + >> +static inline uint64_t >> +get_ptregs_ip(struct pt_regs *regs) >> +{ >> + return (uint64_t)regs->ip; >> +} >> + >> +static inline uint64_t >> +get_ptregs_sp(struct pt_regs *regs) >> +{ >> + return (uint64_t)regs->sp; >> +} >> + >> +static inline uint64_t >> +get_ptregs_fp(struct pt_regs *regs) >> +{ >> + return (uint64_t)regs->bp; >> +} >> + >> +static inline uint64_t >> +get_ptregs_ra(struct pt_regs *regs) >> +{ >> + return 0; /* SFRAME_CFA_FIXED_RA_INVALID */ >> +} >> +#endif /* ASM_X86_SFRAME_REGS_H */ >> diff --git a/include/sframe/sframe_regs.h b/include/sframe/sframe_regs.h >> new file mode 100644 >> index 000000000000..32b67f7a7c78 >> --- /dev/null >> +++ b/include/sframe/sframe_regs.h >> @@ -0,0 +1,11 @@ >> +/* SPDX-License-Identifier: GPL-2.0-or-later */ >> +/* >> + * Copyright (C) 2023, Oracle and/or its affiliates. >> + */ >> + >> +#ifndef _SFRAME_REGS_H >> +#define _SFRAME_REGS_H >> + >> +#include >> + >> +#endif /* _SFRAME_REGS_H */ >> diff --git a/include/sframe/sframe_unwind.h b/include/sframe/sframe_unwind.h >> new file mode 100644 >> index 000000000000..3e2c12816b60 >> --- /dev/null >> +++ b/include/sframe/sframe_unwind.h > > Also, these should probably go into include/linux, Unless there's going to > be a lot more header files. > I'd expect at most the current headers: include/sframe/sframe_unwind.h include/sframe/sframe_regs.h And perhaps one more, for a callchain format and callbacks suggested below ? >> @@ -0,0 +1,62 @@ >> +/* SPDX-License-Identifier: GPL-2.0-or-later */ >> +/* >> + * Copyright (C) 2023, Oracle and/or its affiliates. >> + */ >> + >> +#ifndef _SFRAME_UNWIND_H >> +#define _SFRAME_UNWIND_H >> + >> +#include >> +#include >> + >> +#define PT_GNU_SFRAME 0x6474e554 >> + >> +/* >> + * State used for SFrame-based stack tracing for a user space task. >> + */ >> +struct user_unwind_state { >> + uint64_t pc, sp, fp, ra; > > I know this is POC, but please make each structure field a separate item. > Also, should be tab delimited. > OK. >> + enum stack_type stype; >> + struct task_struct *task; >> + bool error; >> +}; > > Also swap the task and the stype, as the pointer to the task will create a > hole in the structure. > > struct user_unwind_state { > uint64_t pc; > uint64_t sp; > uint64_t fp; > uint64_t ra; > struct task_stuct *task; > enum stack_type stype; > bool error; > }; > OK. >> + >> +/* >> + * APIs for an SFrame based stack tracer. >> + */ >> + >> +void sframe_unwind_start(struct user_unwind_state *state, >> + struct task_struct *task, struct pt_regs *regs); >> +bool sframe_unwind_next_frame(struct user_unwind_state *state); >> +uint64_t sframe_unwind_get_return_address(struct user_unwind_state *state); >> + >> +static inline bool sframe_unwind_done(struct user_unwind_state *state) >> +{ >> + return state->stype == STACK_TYPE_UNKNOWN; >> +} >> + >> +static inline bool sframe_unwind_error(struct user_unwind_state *state) >> +{ >> + return state->error; >> +} >> + >> +/* >> + * APIs to manage the SFrame state per task for stack tracing. >> + */ >> + >> +extern struct sframe_state *unwind_sframe_state_alloc(struct task_struct *task); >> +extern int unwind_sframe_state_update(struct task_struct *task); >> +extern void unwind_sframe_state_cleanup(struct task_struct *task); >> + >> +extern bool unwind_sframe_state_valid_p(struct sframe_state *sfstate); >> +extern bool unwind_sframe_state_ready_p(struct sframe_state *sftate); >> + >> +/* >> + * Get the callchain using SFrame unwind info for the given task. >> + */ >> +extern int >> +sframe_callchain_user(struct task_struct *task, >> + struct perf_callchain_entry_ctx *entry, >> + struct pt_regs *regs); > > > I plan on using this without any perf involvement, I'd like to keep perf > separate from the sframe logic. As I mentioned in a previous email, I > expect sframe to have callbacks. So the callchain format should be defined > by sframe, and not reuse perf. > I will think about this. Do you have some model of the expected callbacks for me to explore ? >> + >> +#endif /* _SFRAME_UNWIND_H */ >> diff --git a/lib/sframe/Makefile b/lib/sframe/Makefile >> index 4e4291d9294f..5ee9e3e7ec93 100644 >> --- a/lib/sframe/Makefile >> +++ b/lib/sframe/Makefile >> @@ -1,5 +1,11 @@ >> # SPDX-License-Identifier: GPL-2.0 >> ################################## >> -obj-$(CONFIG_USER_UNWINDER_SFRAME) += sframe_read.o \ >> +obj-$(CONFIG_USER_UNWINDER_SFRAME) += iterate_phdr.o \ >> + sframe_read.o \ >> + sframe_state.o \ >> + sframe_unwind.o > > Ah, the backslash is fixed here. > Yes, it was a rebase thing. It got missed when moving code between patches. >> >> +CFLAGS_iterate_phdr.o += -I $(srctree)/lib/sframe/ -Wno-error=declaration-after-statement >> CFLAGS_sframe_read.o += -I $(srctree)/lib/sframe/ >> +CFLAGS_sframe_state.o += -I $(srctree)/lib/sframe/ >> +CFLAGS_sframe_unwind.o += -I $(srctree)/lib/sframe/ >> diff --git a/lib/sframe/iterate_phdr.c b/lib/sframe/iterate_phdr.c >> new file mode 100644 >> index 000000000000..c10d590ecc67 >> --- /dev/null >> +++ b/lib/sframe/iterate_phdr.c >> @@ -0,0 +1,113 @@ >> +// SPDX-License-Identifier: GPL-2.0-or-later >> +/* >> + * Copyright (C) 2023, Oracle and/or its affiliates. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> + >> +#include "iterate_phdr.h" >> + >> +/* >> + * Iterate over the task's memory mappings and find the ELF headers. >> + * >> + * This is expected to be called from perf_callchain_user(), so user process >> + * context is expected. > > My thought is that this will be called in the ptrace path (not the perf > path), so yes, it will be in user process context. > >> + */ >> + >> +int iterate_phdr(int (*callback)(struct phdr_info *info, >> + struct task_struct *task, >> + void *data), >> + struct task_struct *task, void *data) >> +{ >> + struct mm_struct *mm; >> + struct vm_area_struct *vma_mt; >> + struct page *page; >> + >> + Elf64_Ehdr *ehdr; >> + struct phdr_info phinfo; >> + >> + int ret = 0, res = 0; >> + int err = 0; >> + bool first = true; >> + >> + memset(&phinfo, 0, sizeof(struct phdr_info)); >> + >> + mm = task->mm; >> + >> + MA_STATE(mas, &mm->mm_mt, 0, 0); >> + > > So this is the code I want to discuss at LSFMM :-) As there will be more > experts about this than what I know. > > Let me go and start making the infrastructure to encompass this. > > -- Steve > > >> + mas_for_each(&mas, vma_mt, ULONG_MAX) { >> + /* ELF header has a fixed place in the file, starting at offset >> + * zero. >> + */ >> + if (vma_mt->vm_pgoff) >> + continue; >> + >> + /* For the callback to infer if its the prog or DSO we are >> + * dealing with. >> + */ >> + phinfo.pi_prog = first; >> + first = false; >> + /* FIXME TODO >> + * - This code assumes 64-bit ELF by using Elf64_Ehdr. >> + * - Detect the case when ELF program headers to be of >> + * size > 1 page. >> + */ >> + >> + /* FIXME TODO KERNEL >> + * - get_user_pages_WHAT, which API. >> + * What flags ? Is this correct ? >> + */ >> + ret = get_user_pages_remote(mm, vma_mt->vm_start, 1, FOLL_GET, >> + &page, &vma_mt, NULL); >> + if (ret <= 0) >> + continue; >> + >> + /* The first page must have the ELF header. */ >> + ehdr = vmap(&page, 1, VM_MAP, PAGE_KERNEL); >> + if (!ehdr) >> + goto put_page; >> + >> + /* Check for magic bytes to make sure this is ehdr. */ >> + err = 0; >> + err |= ((ehdr->e_ident[EI_MAG0] != ELFMAG0) >> + || (ehdr->e_ident[EI_MAG1] != ELFMAG1) >> + || (ehdr->e_ident[EI_MAG2] != ELFMAG2) >> + || (ehdr->e_ident[EI_MAG3] != ELFMAG3)); >> + if (err) >> + goto unmap; >> + >> + /* >> + * FIXME TODO handle the case when number of program headers is >> + * greater than or equal to PN_XNUM later. >> + */ >> + if (ehdr->e_phnum == PN_XNUM) >> + goto unmap; >> + /* >> + * FIXME TODO handle the case when Elf phdrs span more than one >> + * page later ? >> + */ >> + if ((sizeof(Elf64_Ehdr) + ehdr->e_phentsize * ehdr->e_phnum) >> + > PAGE_SIZE) >> + goto unmap; >> + >> + /* Save the location of program headers and the phnum. */ >> + phinfo.pi_addr = vma_mt->vm_start; >> + phinfo.pi_phdr = (void *)ehdr + ehdr->e_phoff; >> + phinfo.pi_phnum = ehdr->e_phnum; >> + >> + res = callback(&phinfo, task, data); >> +unmap: >> + vunmap(ehdr); >> +put_page: >> + put_page(page); >> + >> + if (res < 0) >> + break; >> + } >> + >> + return res; >> +} >>