From nobody Wed Feb 11 07:26:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1770754475; cv=none; d=zohomail.com; s=zohoarc; b=SDdK3SoApSDwxKlcf3GGKWTzGLorKZPHzlYHqm4q0k/ba13BPd5XASfMxsgmLaIn5k0ibET7wc15e+Vd4fKBNZxON90FWdFV7vT2A3whoxavniZSzfHPvwy3X634O9MWmJfxV54tm6f2FVS5xl07sQDCLLGo2s24B0VaDkd9UDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770754475; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TUXohQh66NEYdqhO2tX9stkTnV8Hh6W32mBAqP3BQwU=; b=AKM6i3myK6N2INiNgeQX9UMkB4FduaM+YNCKk8iGQYawGBWm8/SWlxlUc7zLYQWoP2bnuRCCCljctWNJzeNqGKWVnBv6c6hb3W4D83hISF8kRuUmFsH+CEQMhAVTmkzNRYOcmyhEH05bnVya9r+F9XhZEIw2sHB3daDlB0m0O9M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770754475824536.1336887884801; Tue, 10 Feb 2026 12:14:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpu7V-0005nh-Ha; Tue, 10 Feb 2026 15:14:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpu7U-0005nM-3Y for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:00 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vpu7S-0007nR-Le for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:13:59 -0500 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-8230f8f27cfso2898444b3a.0 for ; Tue, 10 Feb 2026 12:13:58 -0800 (PST) Received: from pc.taild8403c.ts.net (216-71-219-44.dyn.novuscom.net. [216.71.219.44]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6dcb5e3e8csm13930031a12.21.2026.02.10.12.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 12:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770754437; x=1771359237; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TUXohQh66NEYdqhO2tX9stkTnV8Hh6W32mBAqP3BQwU=; b=tkNjyPCHZDGW+ayP+lnwgOUBAymzOTfluBwMtQvZ4hF/DNFrkt4K0ZYzFQmlLGrRG/ KmKIRWilu24AeSHjEI+7JQBvkUI+RuyqH9kcO5Dbqc3FjkChOEMYl4lUBa5MnWAorRwZ +ikqUb7XHxJM1+H1p1CBVhdfhq1ZjVeCwn70k5u+nTH51n12LSWFh9tx2OvmF8PXj9+L Rlua9UvalF6iT4znge+PLeTIeVU+gueSJtOaXIokwQuvGtdVaRVCbnDBwd3uooluwQvh NLelRXkQE/Q4Ke2UyXQOLE3jQPH0N2zZj0RBeFFrQfpLBJ0xY3+cx69qQxblo6rEKWsW OhkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770754437; x=1771359237; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TUXohQh66NEYdqhO2tX9stkTnV8Hh6W32mBAqP3BQwU=; b=FlnmhCETwUV6BI41siGQwQp0nEQY6dBr9a6v7zNtZbDmq1IliLMhjdQOQ8qnS09q3A Kp5wrO6OzB6BrXO3+rT+vku4gEws9Yw1cxeCrsEfiD4ofPQJMaQqCmYQ26T6djMzi/tm zFRMLp4l8A1Drd6H7AjQLnMj7xO5p4D1tNLPfKFqebX+04klbaqdIEAYl3zeetLfJElH Tg3VIkUpC/Yye5Oy+K1suwRrOLh/hfTODCKMnJL7dk9X0w4PZO/SaGl8Nszse4OB6lRA v2PDxCiGhM62Mowz6Xz56c0ydjmYF2X07iDzfOuj3a1JJLV5DwSuAtqcfXXFbK9LP5k+ HDLg== X-Gm-Message-State: AOJu0YxS9vlJ6nhHbCDz2H6/AgHE+ZTuzLyf/uO0uUseUDXFgx7onZJ/ 46BHHMmIx6EO7RgEwarRpC/zX5fOntj7vXJSBAlUxfhdE/pNgFW4bj0klnYTYDJOU+aQVukrR+b QtQsB X-Gm-Gg: AZuq6aLeteOEgs7RWgNhGEBJY8nOHqJFz5w0jKaQo7f9ggWa8beW3CMomY/WtsRqZbY LgiVEuT9LZ/OdTE1IxkYQLgFqwNwwYw2/pJJR+8Rd4kwy356lENpqp6riSIuyOceeYto2vR3sPV hWy7xPn28EAkGoofqh0LX0u1HYTA1KLSYUhAoxqhw+yA1t2MdpFYkSaEmg43D0tzrc0s85B3+I/ 2Y8Ty6jwAuhoDY1LQNMrT6fXXpWkdJDhOhIJmzPW4b1A86IJWL2HB9c2gtXhlLGHsIYD2/oHKum rhK/9a+6Pk5pllaI6r/qvnWFrfNobvs0wgcKXX2cXSqGMum1Ris56FwIMk+jriOjA5IktAmrCuJ okbQrHt+CYL4/g5GWdc2MOCfXvY76DOrn579FyXZ19mfavd/kufUjdIK45g8MILv1q19Q23nLHT AZCNrky8DcVEt7jZ7T0sNMX/Dkwos3ZxIANNefgET2GqBFhDAbPPuP+pldwAZ0H94YKhkmMqmcA u9M X-Received: by 2002:a05:6a21:8202:b0:304:313a:4bcd with SMTP id adf61e73a8af0-39417c1fae3mr3025900637.30.1770754436624; Tue, 10 Feb 2026 12:13:56 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Pierrick Bouvier , alistair.francis@wdc.com, Mahmoud Mandour , manos.pitsidianakis@linaro.org, philmd@linaro.org, anjo@rev.ng, brian.cain@oss.qualcomm.com Subject: [PATCH 1/4] contrib/plugins/uftrace: fix infinite stack unwind detection Date: Tue, 10 Feb 2026 12:13:41 -0800 Message-ID: <20260210201344.1403613-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> References: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1770754477346158500 Content-Type: text/plain; charset="utf-8" So far, we were detecting infinite stacks but not stopping unwinding since break only exited inner loop. Signed-off-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- contrib/plugins/uftrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index a7e21b5b87a..1ed982999ed 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -443,7 +443,7 @@ static void cpu_unwind_stack(Cpu *cpu, uint64_t frame_p= ointer, uint64_t pc) /* check we don't have an infinite stack */ for (size_t i =3D 0; i < depth; ++i) { if (frame_pointer =3D=3D unwind[i].frame_pointer) { - break; + goto after_unwind; } } CallstackEntry e =3D {.frame_pointer =3D frame_pointer, .pc =3D pc= }; @@ -456,6 +456,7 @@ static void cpu_unwind_stack(Cpu *cpu, uint64_t frame_p= ointer, uint64_t pc) } while (frame_pointer && pc && depth < UNWIND_STACK_MAX_DEPTH); #undef UNWIND_STACK_MAX_DEPTH =20 +after_unwind: /* push it from bottom to top */ while (depth) { callstack_push(cpu->cs, unwind[depth - 1]); --=20 2.47.3 From nobody Wed Feb 11 07:26:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1770754475; cv=none; d=zohomail.com; s=zohoarc; b=ZMSc9BsvlG4QWJBF5zxDJS4R3UQmlgLHlGYXGxqGyJtfsOW7FJxdonX2ofkiEU/zydm5X8uI8j0QrUSuf+dsWuJ5ZkAzZXTdj8UGTVwwr0w9XEEx5QNn/Qud/QuBQlCFInBJtzl7PUcqAyc2mg/mbX8SfqYIUH2ur5JkmERsnoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770754475; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f6lfjFGTpP9sqItRbR9rxD4pmFfc0wMz2+PxtkzkfnQ=; b=VqX8RpshKjJC8PfOjSobwvgnf7DXtXAjlChTgD2NY9q++3Z+W9A1MuGi1NtB5UBEXAUex/aRJ3xh7Qgi4Bj+c4kJ36w0iRKT29F5m1Qywb029JFdm4F2teHpTqO3rqprxdbC+IbHNKOv2qMsHk8HhXLfmhBuiVblpQnHd1MbJV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177075447522210.288557398979265; Tue, 10 Feb 2026 12:14:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpu7X-0005ox-2d; Tue, 10 Feb 2026 15:14:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpu7V-0005nX-5i for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:01 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vpu7T-0007nU-0b for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:00 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2aae4816912so18824215ad.2 for ; Tue, 10 Feb 2026 12:13:58 -0800 (PST) Received: from pc.taild8403c.ts.net (216-71-219-44.dyn.novuscom.net. [216.71.219.44]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6dcb5e3e8csm13930031a12.21.2026.02.10.12.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 12:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770754437; x=1771359237; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f6lfjFGTpP9sqItRbR9rxD4pmFfc0wMz2+PxtkzkfnQ=; b=byyrD16t911RaHKcTnnf4F34A/v6HvcCCX7bwBq4thWDJ/xm8PW9IiIM5KcDjQ+zX7 Cdy/zUQvurvDJgpl+NNuVCFkFHAe68TxzHyLaJhtKOqND/+lEReTa+V4y7vsQKdgPLAe d6/79+dYo0K+BzmFCkKqxjlhSxOqZQ4Rj9DEZdw06f946trJUKFiCgWcHnfLcwvk5Sq3 hKFOLr3o93WNr9I+13PBNWl15lW8e4sey3Z5eAj70+fp+9vrQ8TuqRAo42zY/eXMb/Mh JZhUsoLS2BPsJ3oDgST81MpRTMSK0/lHp1xTQvRHjeUrZugN3or3MLCEQlM6QdbFUzd5 C7tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770754437; x=1771359237; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=f6lfjFGTpP9sqItRbR9rxD4pmFfc0wMz2+PxtkzkfnQ=; b=G6RlZU5XQcU/9/Aspq3WXh2QLTh30h1EF+43L9LR/Zh04t6blygiyb0Lluev2cqznX SYtaIMwkdYQi7UPZRwC9HM/4OkCTX43urXCnAUNYsFfZDvRW745sswwAUsrXRN7dEHOF jeYGntwIpDGZe48PDWEe5ag5usKOoUJwkc/ZuTU6XHMBYFjdzkGVnR63tNNmwUHHz3dJ 7yuL6NQXHHi7aK2ngSKvm82yQuwvFaO5u6sZtWV5yoRfE6gUWN3E2icCgvuD0ewJpad7 qmtpOt9Wb5iomCnt0U1HH8eq9xiAG1PqFCAV2S1Rb3hiFub2rzeb6ZUeiJpRVMayoDv9 qC4w== X-Gm-Message-State: AOJu0Yyvgs3Px4debkCnMe3JJU3ZPUhVfvEiEfhvo2jTOLNgNndEz7Mk rmAol37vCLbR88rr1tKoGqyeT+Sw0BNNdhg7izPsgwDEWwgIAFnwnhMiNKwNZvfrHgfmzjT+a9a iIw6j X-Gm-Gg: AZuq6aKpUr1iVNm3P8xk8Wb7j/qrnz8j10sU3KuQwPXMD2kt9aaUeYVEiqNmlTctZe4 6p3DYgtht5AtLfKPDtRJYasD/fhwzdOym2aQqPaXL6VrafVvUWdZ5SXhuQ5pUxWV0GWQ3lgqNul y/n9TuViCjoGnWe+VdR3s4hsBZPTyNiGtIjxUAzNQDIYe+ic5R4q02dyXcj9nCZ1ZT5EKwWVi9e ophswsZuyWEixpo8yohQfq5Vls27yRFfmveCoLN2M3uTy/xXTEHNacWEg12c2waZPJaP4BYe0nn 65mSb5qes4gT0Vcc4ESRX9GS2CkUKGmoeGRtqjGIZ6eZBm9Jcxmkmn57Z8yVfAwg+cupveVezhH CVJ61N1VfmcAWVF8ygKySqxe6MBgUu6r5+1mOR1+vkyk7Dif4/ZUQxmFX3oMyxk8q7MaIL9Sn9j AZEWt9ziNqnvrNZvR9Il5QIXFLVuW43pstfiozCjJtJQdk7b8X7w6DxVTbg+NhnKA3bL7S5+y29 T3im7+6LKwPEEc= X-Received: by 2002:a17:903:b46:b0:2aa:f43d:7c42 with SMTP id d9443c01a7336-2ab27d13dd8mr2959015ad.24.1770754437398; Tue, 10 Feb 2026 12:13:57 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Pierrick Bouvier , alistair.francis@wdc.com, Mahmoud Mandour , manos.pitsidianakis@linaro.org, philmd@linaro.org, anjo@rev.ng, brian.cain@oss.qualcomm.com Subject: [PATCH 2/4] contrib/plugins/uftrace: add ops for walking frame pointers chain Date: Tue, 10 Feb 2026 12:13:42 -0800 Message-ID: <20260210201344.1403613-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> References: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1770754478291158501 Content-Type: text/plain; charset="utf-8" x86_64 and aarch64 use same stack layout. However, other architectures might use different offset for return address and next frame pointer. Signed-off-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- contrib/plugins/uftrace.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index 1ed982999ed..21ac1402047 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -46,6 +46,8 @@ typedef struct { void (*init)(Cpu *cpu); void (*end)(Cpu *cpu); uint64_t (*get_frame_pointer)(Cpu *cpu); + uint64_t (*get_next_frame_pointer)(Cpu *cpu, uint64_t fp); + uint64_t (*get_next_return_address)(Cpu *cpu, uint64_t fp); uint8_t (*get_privilege_level)(Cpu *cpu); uint8_t (*num_privilege_levels)(void); const char *(*get_privilege_level_name)(uint8_t pl); @@ -421,7 +423,9 @@ static uint32_t cpu_read_register32(Cpu *cpu, struct qe= mu_plugin_register *reg) =20 static uint64_t cpu_read_memory64(Cpu *cpu, uint64_t addr) { - g_assert(addr); + if (!addr) { + return 0; + } GByteArray *buf =3D cpu->buf; g_byte_array_set_size(buf, 0); bool read =3D qemu_plugin_read_memory_vaddr(addr, buf, 8); @@ -449,10 +453,8 @@ static void cpu_unwind_stack(Cpu *cpu, uint64_t frame_= pointer, uint64_t pc) CallstackEntry e =3D {.frame_pointer =3D frame_pointer, .pc =3D pc= }; unwind[depth] =3D e; depth++; - if (frame_pointer) { - frame_pointer =3D cpu_read_memory64(cpu, frame_pointer); - } - pc =3D cpu_read_memory64(cpu, frame_pointer + 8); /* read previous= lr */ + frame_pointer =3D cpu->ops.get_next_frame_pointer(cpu, frame_point= er); + pc =3D cpu->ops.get_next_return_address(cpu, frame_pointer); } while (frame_pointer && pc && depth < UNWIND_STACK_MAX_DEPTH); #undef UNWIND_STACK_MAX_DEPTH =20 @@ -545,6 +547,16 @@ static uint64_t aarch64_get_frame_pointer(Cpu *cpu_) return cpu_read_register64(cpu_, cpu->reg_fp); } =20 +static uint64_t aarch64_get_next_frame_pointer(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp); +} + +static uint64_t aarch64_get_next_return_address(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp + 8); +} + static void aarch64_init(Cpu *cpu_) { Aarch64Cpu *cpu =3D g_new0(Aarch64Cpu, 1); @@ -580,6 +592,8 @@ static CpuOps aarch64_ops =3D { .init =3D aarch64_init, .end =3D aarch64_end, .get_frame_pointer =3D aarch64_get_frame_pointer, + .get_next_frame_pointer =3D aarch64_get_next_frame_pointer, + .get_next_return_address =3D aarch64_get_next_return_address, .get_privilege_level =3D aarch64_get_privilege_level, .num_privilege_levels =3D aarch64_num_privilege_levels, .get_privilege_level_name =3D aarch64_get_privilege_level_name, @@ -623,6 +637,16 @@ static uint64_t x64_get_frame_pointer(Cpu *cpu_) return cpu_read_register64(cpu_, cpu->reg_rbp); } =20 +static uint64_t x64_get_next_frame_pointer(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp); +} + +static uint64_t x64_get_next_return_address(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp + 8); +} + static void x64_init(Cpu *cpu_) { X64Cpu *cpu =3D g_new0(X64Cpu, 1); @@ -649,6 +673,8 @@ static CpuOps x64_ops =3D { .init =3D x64_init, .end =3D x64_end, .get_frame_pointer =3D x64_get_frame_pointer, + .get_next_frame_pointer =3D x64_get_next_frame_pointer, + .get_next_return_address =3D x64_get_next_return_address, .get_privilege_level =3D x64_get_privilege_level, .num_privilege_levels =3D x64_num_privilege_levels, .get_privilege_level_name =3D x64_get_privilege_level_name, @@ -710,7 +736,7 @@ static void track_callstack(unsigned int cpu_index, voi= d *udata) return; } =20 - uint64_t caller_fp =3D fp ? cpu_read_memory64(cpu, fp) : 0; + uint64_t caller_fp =3D cpu->ops.get_next_frame_pointer(cpu, fp); if (caller_fp =3D=3D top.frame_pointer) { /* call */ callstack_push(cs, (CallstackEntry){.frame_pointer =3D fp, .pc =3D= pc}); --=20 2.47.3 From nobody Wed Feb 11 07:26:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1770754475; cv=none; d=zohomail.com; s=zohoarc; b=HeA5NE+Mn0KA8eu4CgG7gk7JYFelrNdfOgfhgiHvBseANTP2IDj9MCiglHSbThvOSwRHyDMk/CvNqIDGYgGTQ/ZMlWPBRydSim8a9nspHF5ido7iOUqLiW78vHJMLTEgq0hkM6AiRejhNvq5Bdw5orRdNgFWM4bvdDbEnVzMVOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770754475; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Uns7vUCLwr62MBErOAPukryvxRwaPsZ2c+g8wZ8a1iY=; b=TD4p+pGyjzaDpc7WU1meMH5RPFoy5qgpb2m3Zv4i7QKO5lit3xt6VP1f1Z624s/1IpsabvddzVvLrpQexbPYTnkDlgF4Wl9TwQyhRq0vc9MNvr5ZO36SIGLJjzX5l5ohiNHeJR5rKOBdvUI1CoSvCdhH0z0IfGD2sPTUeBMJ/7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770754475730815.6208634263024; Tue, 10 Feb 2026 12:14:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpu7W-0005od-TX; Tue, 10 Feb 2026 15:14:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpu7V-0005nj-G7 for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:01 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vpu7T-0007na-Nw for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:01 -0500 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-b4755f37c3eso2902060a12.3 for ; Tue, 10 Feb 2026 12:13:59 -0800 (PST) Received: from pc.taild8403c.ts.net (216-71-219-44.dyn.novuscom.net. [216.71.219.44]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6dcb5e3e8csm13930031a12.21.2026.02.10.12.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 12:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770754438; x=1771359238; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Uns7vUCLwr62MBErOAPukryvxRwaPsZ2c+g8wZ8a1iY=; b=a8t6EHFtFl1uR4u4V9BmDy7GIim89R0cCBagB2DsOqdto0rO08r/nveJeHTydVy6BP +DrckN/mmwfYLAuyRwUoL2X7iElSz1UKy/i48qACSWyd8692htfdmbei2vnb01+Y0efh n2NfFrXPje2cIweu65GCLrzDDLMfOJOId0JuX7fwOpSc7M9frsxx67qR9F3esOlHl2yE SX+Vs5+pIzLHXX7WpPh0uIlgDt08qKv+nRTV28pmHaQciyhDChYqap46tChxAv1SOm0Q oJ4Bpfz8Vwr3Ow1H+EeqOtzvYa+vA4CBgk+4skgZPkGpmXAISIdFO2KGviqCQbNbmvmC 7CnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770754438; x=1771359238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Uns7vUCLwr62MBErOAPukryvxRwaPsZ2c+g8wZ8a1iY=; b=M5gJujRl5NuqXdC5xMla5nojDlORV5l2ap5TvoZ4i3H7EvOrmaGHWvBa0okD9FhuW/ HLezqf8bhwMH88/tS3ytfcremkqtj5E7NjIDcgbIo0PYHCYwtENxrsSTRqqc8wjaGPEs /LWKpdsytZZN7oIoBdctvBXk9w2B4hNEg8j8pEJSGvjssTiJNp1fbBqjcXiYhqoS3VeB SYxE9bsaFwscsUiD7Us/sE0CQN93zd0uTnZbFw7geiqyPWZuBPba4Q4Vso8azuotFNuW UcCsTh8+lYOzqs37eD9qxlJwr19BvYXZxjxKmuiSC28AfzAHMun9rn3vZiPTDDIrh0uJ E5WA== X-Gm-Message-State: AOJu0YzdOzzLJoiVQrNKpbX2PUqTop2CU71ovdB/nHv9ziGMtP+IIQR1 sQL/Ma+QiToX2gh8Rn/hxRSzHTvD+yq8bByTisuom/fpLYtjjNQcmrqNCBmNscquFRTuKJVZu+q /I648 X-Gm-Gg: AZuq6aK8s4ennWLKmsGrzsbMGvJ0Q3ipSJXMTChYOeuDN1n/9dYjMheslrdgk2FW8di aJJpz76CYsIEqY/mPBH3sfEFjT3nx4rZhu2yDxmvjaxDK+uwI/7EnyGO4ZJgU4Xm0eDsMBiw2UR x3TYX0cSomcCMkNzikUxtyl4g+9K+ITG2SUsuR6tTBIo72LMFqfXCYxWUcHI4sH/qsquUZryf+n fP2ZyIzrjxij0MiO7sdqZBTKsqwiOQpey70EFcBSnCBinAKIbr66qRUea+aAiCdHj6aFoonq4Qc eaNiyxje0CGlWPuaXFKThLLnDQ+zrOgOEaQh01urxiMKDOBtpPL2kyQFg5qb7tvAeK/I8t2QxSg rO9IT6ae135lc9OX3mK41vRjsg88LWnFz3/2ANPJuSPJZ6zKVLYq1W6ZnW+VsbjXAOeeulVUnfy v9atR+ogaj5WpZM0jEQBDmV+a3ydMCYSagfSh4jgE91THIF1YMYkyhJ+HM41mQiTLCkFUuWpFOY 7dU X-Received: by 2002:a05:6300:614a:b0:393:8fc:5291 with SMTP id adf61e73a8af0-3942e6ba5c2mr265571637.74.1770754438273; Tue, 10 Feb 2026 12:13:58 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Pierrick Bouvier , alistair.francis@wdc.com, Mahmoud Mandour , manos.pitsidianakis@linaro.org, philmd@linaro.org, anjo@rev.ng, brian.cain@oss.qualcomm.com Subject: [PATCH 3/4] docs/about/emulation/uftrace: add info about automatic tracing Date: Tue, 10 Feb 2026 12:13:43 -0800 Message-ID: <20260210201344.1403613-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> References: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1770754477356158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- docs/about/emulation.rst | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index e8793b0f9ce..f547e118eef 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -849,7 +849,7 @@ Symbols must be present in ELF binaries. It tracks the call stack (based on frame pointer analysis). Thus, your pro= gram and its dependencies must be compiled using ``-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer``. In 2024, `Ubuntu and Fedora enabled it by -default again on x64 +default again on 64-bit platforms `_. On aarch64, this is less of a problem, as they are usually part of the ABI, except for leaf functions. That's true for user space applications, but not @@ -976,7 +976,7 @@ You can follow the exact same instructions for a x64 sy= stem, combining edk2, Linux, and Ubuntu, simply by switching to `x86_64 `_ bra= nch. =20 -To build the system:: +To build and run the system:: =20 # Install dependencies $ sudo apt install -y podman qemu-user-static @@ -988,7 +988,14 @@ To build the system:: # system can be started using: $ ./run.sh /path/to/qemu-system-aarch64 =20 -To generate a uftrace for a system boot from that:: + # generate a uftrace for execution (collect symbols automatically) + $ ./trace.sh /path/to/qemu-system-aarch64 + # show output log to read timestamps + $ cat uftrace.data/exec.log + # generate final trace (compressed) for perfetto + $ ./perfetto.sh ~/trace.gz + +To generate manually the same trace:: =20 # run true and poweroff the system $ env INIT=3Dtrue ./run.sh path/to/qemu-system-aarch64 \ --=20 2.47.3 From nobody Wed Feb 11 07:26:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1770754475; cv=none; d=zohomail.com; s=zohoarc; b=mbf8SU++vJJF9gVSk9Keq2jBh9QGTgDV7oXdBdZrrg3ALBC8pntDPIQMpNfc7xXY1vnkzgY2rWBmmXGPR76tB9wLjE5MuNCgrgGXeqFPxD1P3lMBsY7zGLpjWPms/rspP4YcFtojvLbvbIqAGmCLf8akwdMS8VU2DafQoCzc3t8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770754475; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=srp3JrZ1BiVLkmTdSaWF+Z7j3MJg4Rv2VkDUwj+jfYE=; b=a/CMeJ/UJQGEekMh6jWNMW35nttgwgoGBIfzepmBUkpCVwdIlGjlEbtowqTOfTk7oM86sBhz302W1PqX5W10vteovmzJk3PCnqSTQyoxFzzga+1ToVeIoznTwluiIh6HAXCckzoSYGhsv227kf9CRDz112XSlj8EfhQJmKnQokE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770754475411139.70192562972215; Tue, 10 Feb 2026 12:14:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpu7Y-0005pA-1j; Tue, 10 Feb 2026 15:14:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpu7W-0005oN-Kd for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:02 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vpu7U-0007nn-MY for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:02 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2aaecf9c325so1268015ad.1 for ; Tue, 10 Feb 2026 12:14:00 -0800 (PST) Received: from pc.taild8403c.ts.net (216-71-219-44.dyn.novuscom.net. [216.71.219.44]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6dcb5e3e8csm13930031a12.21.2026.02.10.12.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 12:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770754439; x=1771359239; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=srp3JrZ1BiVLkmTdSaWF+Z7j3MJg4Rv2VkDUwj+jfYE=; b=bMely8esPODz/3NyocJ44bVdYRxn6zcNDGS2EyC8IGmbK5bYdwBjTy0WSRx5MwLTB/ 9B2W3tP1L+Ltu5/G/CnpcGlnbhIwx103bLHkBEJyf6y/01d73x2RJ3tEZGDH4IIZ3Lei pSygoyR8EmH/pJPOcjOZSQW39wjPo6zVZKqjp0c0Z2w6DJA2ljxgyFf4ecpW3EpnFkKY +GdIhgqeg/4tHjiwYtoqIofotBeh+AI+utT7DEetJTT+DlLahGIw5TWfTSxYdaQ7w/EC yaq+FJL85nVrA5SWwCf7KDYYahRKaDBeu6Z5iSHfoMeKVtnDkhr54omT0hllTmDQwyCo pZog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770754439; x=1771359239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=srp3JrZ1BiVLkmTdSaWF+Z7j3MJg4Rv2VkDUwj+jfYE=; b=IyPWoJswgB2FsNDAs645fLXS3izmBeN4KaN80Yx2CDkrjiYSPtyNbEMZE2H84ww8cT xeHSNkpoixjccf2/A9SC7gxC5qd0GzVO2Fr+rKCEAm32/64lBWqoFaGB2oWtHhswPhzB IbBu837roO5xpeu+3zB/ZqgDj7VfwGa1M7U+ANPu14VQI6NAcz2vnCQEdYrPm4o2tram qw+E2Opf71uHrGK3yGKoWeonub9xx54rFD8UAKfJkoRE8cNc3b4sn5ng05DMJbZZo4m5 r2NNTR2LeXZSPKFPOnjVAxniVNfUPSa0XdjJrm9cn57HOVgMF1lMGQaO+vPMebggqgtS tpUw== X-Gm-Message-State: AOJu0YyAhBVnqVWQywOii6cme1aUr69rDXx3hlR9CRlm0cfIKeTWjMEF JvWzZGLO5o0Vt+knwrlwEyNUQCv1b1tHMYLDyuzn9m3cHZZ17pHSJdWYMvonvbyscD0vTse/YXQ rdqg9 X-Gm-Gg: AZuq6aJPSl/olV48WzM4EyNFTmMhVaNgKOIMicPpThDQVxvxwSJU8Pq3e+1Knuuenrv Ej1KVS0njcQ4LCAW+3Xj/mTLl9Vd+DDUrZbcH1OPyOqlfGV5CUwOBRZ4xDQ+CqCJGQ+icKFFSEj ZF77b3Yq2o7/p1vv4YeUtCuGT9Uw6qOn8Px5S4hQ55pHVAk5Kh8mT1m2EmFq/0gSNNcGRZMkp5v ayNJdT/MnbpGq2uE3FJwPsasKCJQy6hRxlAVaC2lVo1mu6ewBcnZG7tT48pJJNWGsmi4zBmeGB0 hIfxe9g97AnmZA+vAnCfEFBjmWW9sAr+9nRatVXVoc8A6S2cC1AjcBGcdA9iJTa9OPj7QTCNtDN U0q+cZDRi7uwaMBPvz9GEfVjs6rWWhruQA4cZwAuUbrbdwqlGzxz0mS8L9VbBZogJdGOhWcAcvo Wmzi+07xgoCgL04DFebaGdWdwadMO2e9iM7Zl76OVnMCNnY5BtG4y7Sft5Uz7iRxBGLCVu8YrFA fSb X-Received: by 2002:a17:902:e74b:b0:2aa:e4f2:f076 with SMTP id d9443c01a7336-2ab1007a93emr39343155ad.8.1770754439108; Tue, 10 Feb 2026 12:13:59 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Pierrick Bouvier , alistair.francis@wdc.com, Mahmoud Mandour , manos.pitsidianakis@linaro.org, philmd@linaro.org, anjo@rev.ng, brian.cain@oss.qualcomm.com Subject: [PATCH 4/4] contrib/plugins/uftrace: add riscv64 support Date: Tue, 10 Feb 2026 12:13:44 -0800 Message-ID: <20260210201344.1403613-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> References: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1770754478697154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier --- docs/about/emulation.rst | 10 +++-- contrib/plugins/uftrace.c | 87 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index f547e118eef..76c6ea92ca9 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -836,8 +836,8 @@ Uftrace This plugin generates a binary trace compatible with `uftrace `_. =20 -Plugin supports aarch64 and x64, and works in user and system mode, allowi= ng to -trace a system boot, which is not something possible usually. +Plugin supports aarch64, x64 and riscv64, and works in user and system mod= e, +allowing to trace a system boot, which is not something possible usually. =20 In user mode, the memory mapping is directly copied from ``/proc/self/maps= `` at the end of execution. Uftrace should be able to retrieve symbols by itself, @@ -872,7 +872,7 @@ Performance wise, overhead compared to normal tcg execu= tion is around x5-x15. - Description * - trace-privilege-level=3D[on|off] - Generate separate traces for each privilege level (Exception Level + - Security State on aarch64, Rings on x64). + Security State on aarch64, Privilege levels on riscv64 and Rings on = x64). =20 .. list-table:: uftrace_symbols.py arguments :widths: 20 80 @@ -976,6 +976,10 @@ You can follow the exact same instructions for a x64 s= ystem, combining edk2, Linux, and Ubuntu, simply by switching to `x86_64 `_ bra= nch. =20 +You can follow the exact same instructions for a riscv64 system, combining +opensbi, Linux, and Ubuntu, simply by switching to +`riscv64 `_ b= ranch. + To build and run the system:: =20 # Install dependencies diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index 21ac1402047..e3c65a1c930 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -99,6 +99,19 @@ typedef struct { struct qemu_plugin_register *reg_cr0; } X64Cpu; =20 +typedef struct { + struct qemu_plugin_register *reg_fp; + struct qemu_plugin_register *reg_priv; +} Riscv64Cpu; + +typedef enum { + RISCV64_USER, + RISCV64_SUPERVISOR, + RISCV64_RESERVED, + RISCV64_MACHINE, + RISCV64_PRIVILEGE_LEVEL_MAX, +} Riscv64PrivilegeLevel; + typedef struct { uint64_t timestamp; uint64_t data; @@ -681,6 +694,78 @@ static CpuOps x64_ops =3D { .does_insn_modify_frame_pointer =3D x64_does_insn_modify_frame_pointer, }; =20 +static uint8_t riscv64_num_privilege_levels(void) +{ + return RISCV64_PRIVILEGE_LEVEL_MAX; +} + +static const char *riscv64_get_privilege_level_name(uint8_t pl) +{ + switch (pl) { + case RISCV64_USER: return "User"; + case RISCV64_SUPERVISOR: return "Supervisor"; + case RISCV64_RESERVED: return "Unknown"; + case RISCV64_MACHINE: return "Machine"; + default: + g_assert_not_reached(); + } +} + +static uint8_t riscv64_get_privilege_level(Cpu *cpu_) +{ + Riscv64Cpu *cpu =3D cpu_->arch; + return cpu_read_register64(cpu_, cpu->reg_priv); +} + +static uint64_t riscv64_get_frame_pointer(Cpu *cpu_) +{ + Riscv64Cpu *cpu =3D cpu_->arch; + return cpu_read_register64(cpu_, cpu->reg_fp); +} + +static uint64_t riscv64_get_next_frame_pointer(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp - 16); +} + +static uint64_t riscv64_get_next_return_address(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp - 8); +} + +static void riscv64_init(Cpu *cpu_) +{ + Riscv64Cpu *cpu =3D g_new0(Riscv64Cpu, 1); + cpu_->arch =3D cpu; + cpu->reg_fp =3D plugin_find_register("fp"); + g_assert(cpu->reg_fp); + cpu->reg_priv =3D plugin_find_register("priv"); + g_assert(cpu->reg_priv); +} + +static void riscv64_end(Cpu *cpu) +{ + g_free(cpu->arch); +} + +static bool riscv64_does_insn_modify_frame_pointer(const char *disas) +{ + /* fp is s0 in disassembly */ + return strstr(disas, "s0"); +} + +static CpuOps riscv64_ops =3D { + .init =3D riscv64_init, + .end =3D riscv64_end, + .get_frame_pointer =3D riscv64_get_frame_pointer, + .get_next_frame_pointer =3D riscv64_get_next_frame_pointer, + .get_next_return_address =3D riscv64_get_next_return_address, + .get_privilege_level =3D riscv64_get_privilege_level, + .num_privilege_levels =3D riscv64_num_privilege_levels, + .get_privilege_level_name =3D riscv64_get_privilege_level_name, + .does_insn_modify_frame_pointer =3D riscv64_does_insn_modify_frame_poi= nter, +}; + static void track_privilege_change(unsigned int cpu_index, void *udata) { Cpu *cpu =3D qemu_plugin_scoreboard_find(score, cpu_index); @@ -890,6 +975,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, arch_ops =3D aarch64_ops; } else if (!strcmp(info->target_name, "x86_64")) { arch_ops =3D x64_ops; + } else if (!strcmp(info->target_name, "riscv64")) { + arch_ops =3D riscv64_ops; } else { fprintf(stderr, "plugin uftrace: %s target is not supported\n", info->target_name); --=20 2.47.3