From nobody Sun Apr 12 04:23:20 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=1770943439; cv=none; d=zohomail.com; s=zohoarc; b=m4/ihtziyq+MX13rpAJ23X88QXH2sht/1rIyWqoMoluH6lfPsVc3ULD3YJpNe5s7JZajNGFBRJD+fyJnHEnE67+fZpGlSV5WdTgAF0OIQlIYaXNCPeJ1MdePy6G15WpPd9idbUIyS1E0rqokkzWKw2iXVTaf8eQ4l+YJs6IYkes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770943439; h=Content-Type: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=Qc+ukIsOiKgzsRkLbscq45ZmsrUzNjBvF9i+XTW1u7g=; b=lbvK2o5nGU6Ryyytf41+gDKyQGsgBkJU35RZpD2O55/9IdlObuqqDcUV4iPzV2O9/Jr1ChbB7vLmP0Lo7U2xejxBHPUHHagNEPpg4lu8M7qWXCS0D9S8EkalthKV8pXsKphlc4xR/Rb3r7qEHbDCvNazOw12OEeGE1q2bYrKEq0= 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 1770943438929885.7678992175918; Thu, 12 Feb 2026 16:43:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqhH0-0003nD-6h; Thu, 12 Feb 2026 19:43:06 -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 1vqhGy-0003mC-4e for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:04 -0500 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqhGw-0000qO-CR for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:03 -0500 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-82491fbf02cso233182b3a.1 for ; Thu, 12 Feb 2026 16:43:01 -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 d2e1a72fcca58-824c6a431f2sm504326b3a.22.2026.02.12.16.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 16:43:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770943381; x=1771548181; 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=Qc+ukIsOiKgzsRkLbscq45ZmsrUzNjBvF9i+XTW1u7g=; b=Ny6j6GIN20839aWicWJy9zRpQdIocQzNKXdPTfjUoNvrP+H5NxcgwyXJn5J2GWBOEG mc5N31Qxsj+jEmXEYz7Be+GYEkZiNoo2gsr/Rkvc/vfGG6FqO9SeiWb0h+bm/FBntdyT N7wG2/5/WED8o1HqKSgO6Zh32F17+cjRdEtFlEaUtMXNXagru1UqPA/5BX9af6cGnjKE jwQxbH/WzxXeH9PEb8bTtfHmpvGx5vgr4lv8Ndkj8UBAc3U47Exzqoyox/UaOpEyq6ZT nafOXILFCGxwdnAyB9FQth+le2FPYQve4R7zjZaN+XeEH4FRnDVbKAmeXgNFXhJpnDyB 6Z7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770943381; x=1771548181; 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=Qc+ukIsOiKgzsRkLbscq45ZmsrUzNjBvF9i+XTW1u7g=; b=op7jkYR58oEcYFMO/Z0q5NM08R5ECI8fUYvXItGQg8tIHiQMev037ub0alcggTJHeO 4D/UU6GWOirxcRobSP13995hqA/q2Zh1Ml3etnyXVTEP2ZJp2ScoL5DNyFPkYos1CcRQ 0g5RZQeXLFQgECAyZxuRvPQMwUAw0DDqYMTQH98Kb1CXhNha+NXjCvbJqzFP8vqoFi0/ Ti7DM3J6k5h2iOALu1XIMSM3Py97fxJUPgQa8SYDd2m7VpdKUgczx4eICp4I8EA5EwDl bFbO6c9atUhVIpHoCsIq6yH+uW4oYyBKzAaYtgfLysicsotXzugLlKaWncHZZ/Jdx3K6 T/EA== X-Gm-Message-State: AOJu0YyfVJyQx0GUEztAgdQIPTRKQmMlBrK3CxuSDOAb6qONg0omasfY 1sLDSwt+5m3z5m6U2XpcnzDMcC8+BRekk94SM5xwQhLeyz8zm7vgDN7uK7F6yNXW/GRD7FcueoW PgioN X-Gm-Gg: AZuq6aLziFwonuX190HKU/rHLmvCy85TtywK6dUOiylqg2j+irrnXvHn4rw8UkydYwi nwWHkp6P/ubZN/+HVSepbrTCJ9FMwl0xdC0ocY+pZBGvSspwPcBc2F4qdxJc/nqTzjYcS7Q+C9z FeEirB+5Dg3xCrbKOlHjQyx5Af9EoLFzqGokjSIoGeCGGW3cIs+JjmwtOUX8TcsMOVcK3B4F+V4 Gxe4ASGIxswMdFCSoaUrV/EwlGgjepAMYO/1cmFJGt+7u9kdEmlbsSFormXt9Ho/niZW4NsdqlC 4VBAU9pYDKNYkp355DlB6uqUpPiAdBbyQyzMQAzUpAxGnOjgW/con1ICx5VxW6BFKTIiUSJ7yqp 5Vwmm/zj+hVXIutGZRBl2xaBk4y4g0jUB+5VT3chn4VOklQPJa7ccNv7/5sd9OnKmuqNk0nVP7G AAP51PYqffaDINhkqE+Ikbf4PYY94w/TPyrnU7AXFmdNmSMqJLBZVrBlgfOa+s+go1vVvkqlt2E KEe X-Received: by 2002:a05:6a00:1706:b0:824:3eb9:11e2 with SMTP id d2e1a72fcca58-824c95d5ae5mr230697b3a.46.1770943380796; Thu, 12 Feb 2026 16:43:00 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org, peter.maydell@linaro.org, richard.henderson@linaro.org, pbonzini@redhat.com, stefanha@redhat.com Cc: pierrick.bouvier@linaro.org Subject: [PULL 1/4] contrib/plugins/uftrace: fix infinite stack unwind detection Date: Thu, 12 Feb 2026 16:42:51 -0800 Message-ID: <20260213004254.493059-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260213004254.493059-1-pierrick.bouvier@linaro.org> References: <20260213004254.493059-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::431; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x431.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: 1770943440414158500 So far, we were detecting infinite stacks but not stopping unwinding since break only exited inner loop. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260210201344.1403613-2-pierrick.= bouvier@linaro.org Signed-off-by: Pierrick Bouvier --- 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 Sun Apr 12 04:23:20 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=1770943413; cv=none; d=zohomail.com; s=zohoarc; b=cz1DIO2ewb/gjXcw1QvJTy1ZjoTBza3PaC8k3J+KIaJOPbUOVqw/O39O+oXYxwsSzuSdfyissUEnNemi11mqGY09S4iNT/1W4yDKDRyTCsZcGVHTlUqIdl5a1/DgVbNiHsg8+eOUzXiAWfyhd82qbQASR1xy4SboCl8kEPHuQgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770943413; h=Content-Type: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=MhP9UxZvtyw4qXts11XqOhuLW6bLHIrLsrfSheQGMKU=; b=CPerEuOy/uOPsIUV1bhKLkaYmY3OkbIOIY2WMidCqcDoCKCxkVqU/bZczo0ZjnM+W+Doqo80IaxbjoRyvv0Z5dpTy0GoMzGbR6X1k27w3p05kNmFiB9B8YD8+3gOBZcSPAlG6s/9eXDBg9KSJYHh1s3PEyKM5y0BLyuqaecbvPs= 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 1770943413662857.2044526427512; Thu, 12 Feb 2026 16:43:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqhGz-0003nA-Uk; Thu, 12 Feb 2026 19:43:06 -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 1vqhGy-0003me-OF for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:04 -0500 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqhGw-0000qR-TW for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:04 -0500 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-82318b640beso222246b3a.0 for ; Thu, 12 Feb 2026 16:43:02 -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 d2e1a72fcca58-824c6a431f2sm504326b3a.22.2026.02.12.16.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 16:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770943381; x=1771548181; 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=MhP9UxZvtyw4qXts11XqOhuLW6bLHIrLsrfSheQGMKU=; b=yd0wJ6m0ompvTeVoSrf+WzlEeLF1ViV76VeY+dK2+9CSjDiwCz6iKb2mrHkPKop9Ju rLbMcdA86jLyStttx9hWEiwF2+QmnHgeh9oDhbEaR/j8CDufB23BPVgFyZLLT2jREAv/ MOwQpnpsPj6ixJaG35xu3400INEix3MzKrGAxES3I2p3Gw0RbEv6Q2YDmXPKU4UpISIH z/H9mG1t7/5Fg+vP0bW2wBoGykzrZHYFrzVsi4ob7DUSU5FCCnuMIKb4mNeEQGAqGhsS EmUfunSlD4Lc+Y5v+E6cmIcK6F6+61CKSID3eFpdUOT1iaXfsZhudKm/h7N8568nT9yf K58A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770943381; x=1771548181; 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=MhP9UxZvtyw4qXts11XqOhuLW6bLHIrLsrfSheQGMKU=; b=s3D0fw75kIOqcEY6K/nBqalCeWM36Crt5GqJCNpb0xpoc7xMudQsO2KJ/nrEixNzDC qtRRNF7e9cTDRtX9JutOqSRKmuu04rV8Exx5FEkfmxWNwvqaCfTHpnzXVwUMjPOUBeKd zicVoGRCodIwqG9VMe3XcuO6E15EpWpgAFvGBr0rf6zdqsYYlUT2IbuAeILDFXfBBQmK JYEE5agqrIEq1ZTSoqAM5g5i+TUDKYYIA/xbed43njDEif5zeONo/+6h75etYM4bjjB4 UlL4RiRD+0/ri6Wnd/JWyKqfUIaV/dSpfm2oMTyfhzFNYcGtRszDnCqAE5THkInI7jCq gkxw== X-Gm-Message-State: AOJu0YzaJRwtC5gH+lXBfDBg5lwXYtQXLmrs6nTs1mJW/fBrUYFi9BQl pYo8OWqfNIRq64piWbAeW8qqcUQcqU3xzZvPz6nge2MEbrafLGRangDqHlY3BXOIyXB7/rY4zfL gj3LP X-Gm-Gg: AZuq6aLOB0/84bQQQr/p7UeOEpjYmT5hg5SvTDvXzObNSOEtxXmwZMgdkscCfvjUeUz rAFOfVOPUUMvv28L3FVZKfOo/2m+LWH4/X4MfpD7y+d+UVsEIN5OlqlVjf/kNHjp0nJ2VEfnl8t p9wDZm+Y2PM9c8PevLdifZLPegBK+N0+kJjWi7Q4LF816I4WvdHGPZzhrxycx0DXDY7emA8YAkP vIbzMs4C0h5LMDIfpSk6MJqctHKcUFTAmdlwwJNzp/JeI7/3/ChEXkXb3N/XhZSxhxKeFsf1LsO ox6gXZgvf7oEUb37Tq+XaLsgVfNw9W5VRec1GqJ64gbfeYw7ZtLc9vJ4yYOyMxTV5VIdpR4QpJ6 y8+3c51T2CzNMRZGH61y5UriOSAMSNWkxdH1NbTd2nCqLeJ0H6Jl2elx3q0z9PxASr7ytKVW18s 9MCFaGrQ2ulArC0T9szmCarCLsXfU9VK0eSevjx/oVb2NH3Nm3hWLOfTOxbsMjC/A4smMhHaXRV 54/ X-Received: by 2002:a05:6a00:4515:b0:821:8ebc:2899 with SMTP id d2e1a72fcca58-824c9446cf7mr284157b3a.7.1770943381452; Thu, 12 Feb 2026 16:43:01 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org, peter.maydell@linaro.org, richard.henderson@linaro.org, pbonzini@redhat.com, stefanha@redhat.com Cc: pierrick.bouvier@linaro.org Subject: [PULL 2/4] contrib/plugins/uftrace: add ops for walking frame pointers chain Date: Thu, 12 Feb 2026 16:42:52 -0800 Message-ID: <20260213004254.493059-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260213004254.493059-1-pierrick.bouvier@linaro.org> References: <20260213004254.493059-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::434; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x434.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: 1770943414615158500 x86_64 and aarch64 use same stack layout. However, other architectures might use different offset for return address and next frame pointer. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260210201344.1403613-3-pierrick.= bouvier@linaro.org Signed-off-by: Pierrick Bouvier --- 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 Sun Apr 12 04:23:20 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=1770943449; cv=none; d=zohomail.com; s=zohoarc; b=LXD3CZ2JljBO2WO06IBEGm6kIquhCy5RJ6PVzyvR6TjZos0lFZM6X+3LBXzecYUfGCHXxiWsNgl7QntFPdntBXpWqI2227xromZwpTk6WGtyE+LrZMBuvvsUeZfyQbWxe3osUN96gR2x+XABN9XK55YxLJYP967CHc0sswJLRR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770943449; h=Content-Type: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=sbsBM3kE23XRKko7Z/Dni4MLoWdVDjlTC1rdXg1+3EM=; b=YfWoRjMKrfCACpqUtntEVOTSh7xXvCd4/YtjIckzcZQ58GN/mc9u042/BdXxlPqnLx9lHENeHiheYK5v6ynKOjqiIxEWEn+cyscKe8N4ykpXUI9TAtthOg81nUXnkV1X87FKrDr3zgCQh/L//tDJV8I4KXVoc8HfA3Zj9asp/+U= 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 1770943449972322.4759050567294; Thu, 12 Feb 2026 16:44:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqhH1-0003ne-TA; Thu, 12 Feb 2026 19:43:09 -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 1vqhGz-0003ms-K5 for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:05 -0500 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqhGx-0000qa-Nm for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:05 -0500 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-824484dba4dso415017b3a.0 for ; Thu, 12 Feb 2026 16:43:03 -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 d2e1a72fcca58-824c6a431f2sm504326b3a.22.2026.02.12.16.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 16:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770943382; x=1771548182; 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=sbsBM3kE23XRKko7Z/Dni4MLoWdVDjlTC1rdXg1+3EM=; b=X1ZdWvan0EL+kVNiyxCxyrGKq7lk/wNkHZnOdXzykxP9HC7oKaDzJLQvYIXMexfysb AfIefdnUURbUVN/sJtmfLaPxjK2lj8aEV+TuJCqmX7CpRzkwUEZIjS3aRgyqbGR5ruG7 coEDv+AyoJTKf4GBYWjq/klb0qWkindYflLTenX+q23XRamXRXTogN3s48iEgrjG8unZ jUe9ULBdjQa8zbZ256PeRDxUFSWa01gqJ6Ipbngn9zCuI+TJoi6kCMLasIkLhY4JwpvW 5EmlUZQ3lR3cX4WrbuACoXlVkEcajXojTgQ7s+b4gu8sLzti4cCy37ABGBSHcoYFDoJo D34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770943382; x=1771548182; 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=sbsBM3kE23XRKko7Z/Dni4MLoWdVDjlTC1rdXg1+3EM=; b=C4/ln9/04mNuaxC5+pTn2Pqb3n/2aCCQGmg1BCQ9aJjmzWY5sMpg+T9NnCbaIauWgU yLFZaKw+16K3C3vIcTBqf+aX8uoH44OeJwRi7QF3xLDu4G6m2jc06UxAiY6intxpozlY hd4iHmxD21jpJhQ9cNS4mcaoKpjmtFmMATyHmdDSLtWNEmUT7xisgfmpAHeJuxh+SI5b QEyEnvODuGumdEY0OK/6jw6ewopR64MAW9BWWFJpsPXZCikufTqUAhwRLepLVgX/UDZ8 sH/XVFnbdmJEndrh5CdjZ8OJfWP9X7HY3BiqNZUguyI187xqXxq069/MIhWS31F9/hKE m86w== X-Gm-Message-State: AOJu0Yz8w22Ngyj4CiA6YHlt3+13twYhLpk5wF0tRfXLX9/NJlpf1DQg 062F2clJCd4Rc1hR25wqEkC4jR1QIDAUJoRao2PNpU3zw8w+P9r7f9oEgFBmlh0giaZUJTOktSA HtfQY X-Gm-Gg: AZuq6aLxu+JoBaP0ZZcv8n/OrY5qdFvspOh+8jP4AD2WX20SDBr2nE0JNqG59TlIxmz BuoYM60Ox82iL+KYwWsnKtX80rHvw44xPDndxSyLVfUJ+p/S/At8uAEMGoRoBgpk071fA8M9GnI DE3/KqwiRBHrwn6ZvfI2ofQX/d8Ltgmy0ihdgMN03i/CEJ15U4N5bOjMrytvEiqeoXPN3Os0YRr wxfVUKTNs5KQyjoTGbgapcVqlDGeqf308opXGVVagOzxdvum5CM+Yb5zllToCFO28zUgWkr8CuD Ti8pnpURcoocwG04w2fqf9huQATFYD6MmZPK0UjWBnezE8tmHtEucfAxGgDGStIxU3UHEbkEuKV xZFJizDEJ18yS+YoMki8KAY6A2ol1Hh8tYXbZD4zc+GrXue5i19JucOh238fJv+ycIUFpcRh015 WJ/iDh1fAfI+eJzQ7LKYAJenH9vVB4O0h/x/6pnKRn0aZoGI2psKk65I7J2UsSCz2FSvK/fMtDo 9Xt X-Received: by 2002:a05:6a00:4f87:b0:823:9c6:1985 with SMTP id d2e1a72fcca58-824c948163bmr265064b3a.16.1770943382230; Thu, 12 Feb 2026 16:43:02 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org, peter.maydell@linaro.org, richard.henderson@linaro.org, pbonzini@redhat.com, stefanha@redhat.com Cc: pierrick.bouvier@linaro.org Subject: [PULL 3/4] docs/about/emulation/uftrace: add info about automatic tracing Date: Thu, 12 Feb 2026 16:42:53 -0800 Message-ID: <20260213004254.493059-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260213004254.493059-1-pierrick.bouvier@linaro.org> References: <20260213004254.493059-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::430; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x430.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: 1770943452386158500 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260210201344.1403613-4-pierrick.= bouvier@linaro.org Signed-off-by: Pierrick Bouvier --- 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 Sun Apr 12 04:23:20 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=1770943438; cv=none; d=zohomail.com; s=zohoarc; b=ddPLDxG3At0j4tB5kLTHnXBrEDy8MSJBHzkWPPIdQNlaQqEToiYxczArGFjL5SsZMSZkOL4+9U3SNNEa2EBadM0uQhTzlzaCnU6H6CnCRU/bnY+zclUIdm05AJFfU9at5wYlWONdA8NHGAEBrz5fKm0MeBrdtProWfrNu/P92kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770943438; h=Content-Type: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=rk8/s27IDHW4parj5IMaohWkfowsvr1X/ujkaJmQXGs=; b=KK9WPvFejVk65I1KNHeh8HcH1k8BIIdnzizsP4M6GaWM16PEn7lRYpAL/TG7yV3ZAeJoIUxSzz8nWKQs5wFGjx0JQ34hRQbic7GUclB2azs05tPdONa0/ijtEn+H8N54XVp6HsHnUE2Z8EWJw/iFCHAdPcy2ELOSwU+KISHtyQY= 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 17709434386951014.9860093818642; Thu, 12 Feb 2026 16:43:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqhH1-0003nc-FQ; Thu, 12 Feb 2026 19:43:07 -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 1vqhH0-0003nE-EV for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:06 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqhGy-0000ql-LJ for qemu-devel@nongnu.org; Thu, 12 Feb 2026 19:43:06 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-8249aca0affso245633b3a.3 for ; Thu, 12 Feb 2026 16:43:04 -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 d2e1a72fcca58-824c6a431f2sm504326b3a.22.2026.02.12.16.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 16:43:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770943383; x=1771548183; 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=rk8/s27IDHW4parj5IMaohWkfowsvr1X/ujkaJmQXGs=; b=QTQQUpyCx7XFkMYYlrmheYp8Iyak49B2o0kI9PsfqCIEJ1jTexZePGFLjSSKLGt4bC SnWn4MscJHOn7k3EXi3PkeXpoEuLAdOzSgZD2pW9iLqVkwveEqYjJbE41BWgB3g679Pm Xt2hoLzlSiItE0AYnejgT0hoTpgaUzYoWb8qoMeHVytmBdD7xStjcuYvaejR9ttCpnD5 kH4kTQ2oLMyYn1WTFwSXBpOZhuHQP1+aR2di48dLG6mW41KdlPo8OZpQXaAMs4V0Pm3Q rpMQPykSkjix7M08hCSRkS6yFzJMvZv+MI2qreZiQZ4wfLLoK+7RyJ18MIOLYbJ1J2RG 67aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770943383; x=1771548183; 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=rk8/s27IDHW4parj5IMaohWkfowsvr1X/ujkaJmQXGs=; b=n1tK4PCGSBDUAnd4iC06n9SSBYd2Imq/w/hvLEd8EtYDJpfqFfXU5fSGbFFV4wm8lj Zbihaj1eSYnzLraNhm3ZVrE/3BYiMkZDlLpZFg0/h7754USJeMy2m4S81etCoSXMTp8o RJNBQ6Z1ZY/526vTwfNxzmfvOQq5I0E11Um4yZ9IyNb/EJ42BvlB7Zkw45ndul73ZuLT MIEGCgU/gz3uneVvTu3JAYrvYCOEZ5P+0/7BXZnSmy2px+48jHAMONTdWuQjl9T5i3WO XJI3aVBacrToTsTvtaWy8t5+EMatnROPukNqTrDmyJMKl4gFiu9znZ435lhlSQrid6xA hzNA== X-Gm-Message-State: AOJu0Yy0WcDaSRRUUsEDFuPizYTsO7x3IaROJgSMz1xgrcw2pHOmclU6 iNJMLWkby4mgRqUDIVzusWpEQa5oKQItVeY0lRaRcnaVh5wp8tgudrldOrvmFn7DR5akJmKtdiL UKWCj X-Gm-Gg: AZuq6aIam5QCnY/M48PZ9ypq21KKT9I4G5KgHHZI+V9yKpdcGhS22cDOuVYzXF+Bpdq gtYeRvSk5WyC1gJX5n1A24eBOPGz9YtIaS3BQtnT+/IkVedfmD5lLOm6L/h8SMraRmXM0Qr0NA1 lQrewESeqzZ7kcI9C++i+0BtHISVoZz5mtHlWNIIFri6btvnx3OWNRCoTq/xXlWCwANuztgQYKX Xw0gKSXgKYJHZEbfMpjkhoxvNdU3CkK2eU1cgIZLjf3ev1oNixqSjlSabnqtYQd+axKlVjyFxvp XXYVKhfyZEVAmkRH81bjWe1WAKsq+Kxgod86Y73NfPdYAL/gR/Q4KqRSzkvPlzvT+8v3y/tSt7b A1DhuG8kpF7SDoQ4WBg7SVJspr87vM1URABdfNGHTWiJo2re/B8tQSN4c2JDvEuoGUVf5zuaX+g bZTTenjmUXiR02/32d+bptA7SSNxzlRnxTGTnFLmivJt+d+Y5oJp57O8lyIpbvfTZu9B99WX/fh TUg X-Received: by 2002:a05:6a00:4515:b0:81f:4dfe:ddd5 with SMTP id d2e1a72fcca58-824c94458eamr301360b3a.4.1770943383053; Thu, 12 Feb 2026 16:43:03 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org, peter.maydell@linaro.org, richard.henderson@linaro.org, pbonzini@redhat.com, stefanha@redhat.com Cc: pierrick.bouvier@linaro.org Subject: [PULL 4/4] contrib/plugins/uftrace: add riscv64 support Date: Thu, 12 Feb 2026 16:42:54 -0800 Message-ID: <20260213004254.493059-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260213004254.493059-1-pierrick.bouvier@linaro.org> References: <20260213004254.493059-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::42c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x42c.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: 1770943439651154100 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260210201344.1403613-5-pierrick.= bouvier@linaro.org 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