From nobody Sun Sep 28 14:48:18 2025 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=1758892771; cv=none; d=zohomail.com; s=zohoarc; b=noF01SENJd5bwTxYjInJwvNNePwx8Ucxz09QRH9gAmlWhRff5edyVUBcuEvJK9hpJrnyrDlzpMJXb+/VNH8OiGKwI7181ydnohnfIgQ0R6h1jDajhj18klLqyHSrcDvqF5kbLCV6tEalnLTmL8GcQzBLTkhli9Mj9mgxXst0L/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892771; 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=M/bRTlt+mHsgTlsr9RW/nD8staDPYyKjxTlCJTfUZE8=; b=aAPNl8uAlQrOrwcxooH6aPVOb9QRQEI6E5XkPeGNIjGHUBUg4feRUsrRSBGpeTCI2m7c770osc4ysBMq8Rl0JaBmXjmzjphxZk39Gg2vaXW5tWHOEOnOViMzzUR3+7+jHRnfrxseXmnM4gZ+RL98AqdC6amk0ZIhtdxhAi6fRjg= 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 1758892771746730.026433272554; Fri, 26 Sep 2025 06:19:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LC-00081g-LH; Fri, 26 Sep 2025 09:18:26 -0400 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 1v28L9-00080x-LB for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:23 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Ks-000429-Sy for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:23 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-46e3af7889fso6958855e9.2 for ; Fri, 26 Sep 2025 06:17:52 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e33bf701dsm73403215e9.24.2025.09.26.06.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:45 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C19CD5F7D9; Fri, 26 Sep 2025 14:17:44 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892669; x=1759497469; 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=M/bRTlt+mHsgTlsr9RW/nD8staDPYyKjxTlCJTfUZE8=; b=HJutUhhXkahZKxenyFoPfcb5b8UKtf3wNjIPMOCLf0+Ufcbbmu5zpbNjo1S36fnOkV pzpXGxEgefsGD932cCGVXjxaQbLeVIfW//ISMZQLt01xd1RHep+g08J7IH4ZVCiPhGtz wGTFGUFsrXwkdxUIQVoXtduZYwm9ZjccKxLTk+K8Tmul1czulwC6K2k8SnlneKlA5SYF /CouVrd1ZNYCGpeMt+wY+fStS9jPY3ECW2qqHzpkozmyoeC7pJ4u3VzsFTRqTxqRI34K uiKRO/cpb1yto79l4/tp/tG0eE5OSJ80VOofwcUl6QsKrExBMBSempXl4nrfGBpGN9w7 K4wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892669; x=1759497469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M/bRTlt+mHsgTlsr9RW/nD8staDPYyKjxTlCJTfUZE8=; b=kdpipfn7LwhuBAsa6MHOQDbVF3qx0NZ99aR7hkhAhWyIxFPAJ+LwmVC+42DYkED+ox gwT6exrehfTJ0fp/8Ph6w0RPGd6sq9hddrnWGyQgJsSsN+3FX/DbKtsfHcONfIjci1h7 oTGtjz2E5Jst/JQPMQMR3fXI1ZHxpjFFGYsl8vGQe9VCYeenaNxSP74nFkGdgDwJvbeH 8kUvByji+EsEzd21JZ9nhWGqWKXrZ8hwHzcmszQxybxhSC57f+u7Bn3RaeDJnM18ZtxM TUWHtShPzfTPzC8UpVVCPvgPey0d/SUYRG3hSn3m1GNBTRqgf3scBO3R0NeC4ZMfUBCn IRsg== X-Gm-Message-State: AOJu0Yz136YE/kuZwWwtT0j3/5/KdKZt0yRKvDdJNgPs6fA+7HCmU8Vy sWSZPXrgT8B7Dqvo+7Bm3EqvFaOw4h8w25oVoPW5GRgSA4xNdtw/Y6YVc5ht8MMxg+E= X-Gm-Gg: ASbGncskxRS4JmbKZamwOvpxfECUhqbGnbGXowofXOpJ4LhblCYdhhXG7K5J/RJ5u9T a9iCT6Ouv7MbA8jnakHubKE0sU/lWCsVUjgPmPaRUW5ioIVwzXIV7wTdOyZ0ZA43XFeC9QOJ7xJ onKlimtTwm/7ByIxrq0quL+e0V5iXPAsuyUa+aSjshcWR8PqfoLdV8wSU4pqRvy8ErgZJfFskQc NMgLi4Ji3PKvoaBKkTRXouFMG7XFEMLYEQOPkB4Icv3e7k/+54dcG5fgikh2t7X8YxC+LYMgE9y 5gU5QKwNAbk0y6edOEJ3d+502/O6wzctrozWsqRFwuq+05gMJwkQifBobA50/UsFxdF7a5XSKIm dlv8XJQYHlgM+JkofLIkt8mUCjGAbbxRU5A== X-Google-Smtp-Source: AGHT+IEoJsuvq3T1s/LuLL9mpKiE3/d0FvBOstG3kJOabwc2WvsVIPouUlA1QrCjkcjbKB0ZjXT9xw== X-Received: by 2002:a05:600c:3551:b0:45d:f81d:eae7 with SMTP id 5b1f17b1804b1-46e32a13207mr69480315e9.28.1758892668509; Fri, 26 Sep 2025 06:17:48 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth Subject: [PULL 01/24] scripts/ci: add gitlab-failure-analysis script Date: Fri, 26 Sep 2025 14:17:20 +0100 Message-ID: <20250926131744.432185-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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: 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: 1758892774136116600 This is a script designed to collect data from multiple pipelines and analyse the failure modes they have. By default it will probe the last 3 failed jobs on the staging branch. However this can all be controlled by the CLI: ./scripts/ci/gitlab-failure-analysis --count 2 --branch=3Dtesting/next --= id 39915562 --status=3D running pipeline 2028486060, total jobs 125, skipped 5, failed 0, 39742 = tests, 0 failed tests success pipeline 2015018135, total jobs 125, skipped 5, failed 0, 49219 = tests, 0 failed tests You can also skip failing jobs and just dump the tests: ./scripts/ci/gitlab-failure-analysis --branch=3D --id 39915562 --status= =3D --skip-jobs --pipeline 1946202491 1919542960 failed pipeline 1946202491, total jobs 127, skipped 5, failed 26, 38742 = tests, 278 skipped tests, 2 failed tests Failed test qemu.qemu:qtest+qtest-s390x / qtest-s390x/boot-serial-test,= check-system-opensuse, 1 /s390x/boot-serial/s390-ccw-virtio - FATAL-ERROR:= Failed to find expected string. Please check '/tmp/qtest-boot-serial-sW77E= A3' Failed test qemu.qemu:qtest+qtest-aarch64 / qtest-aarch64/arm-cpu-featu= res, check-system-opensuse, 1 /aarch64/arm/query-cpu-model-expansion - ERRO= R:../tests/qtest/arm-cpu-features.c:459:test_query_cpu_model_expansion: ass= ertion failed (_error =3D=3D "The CPU type 'host' requires KVM"): ("The CPU= type 'host' requires hardware accelerator" =3D=3D "The CPU type 'host' req= uires KVM") failed pipeline 1919542960, total jobs 127, skipped 5, failed 2, 48753 t= ests, 441 skipped tests, 1 failed tests Failed test qemu.qemu:unit / test-aio, msys2-64bit, 12 /aio/timer/sched= ule - ERROR:../tests/unit/test-aio.c:413:test_timer_schedule: assertion fai= led: (aio_poll(ctx, true)) Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-3-alex.bennee@linaro.org> diff --git a/scripts/ci/gitlab-failure-analysis b/scripts/ci/gitlab-failure= -analysis new file mode 100755 index 00000000000..906725be973 --- /dev/null +++ b/scripts/ci/gitlab-failure-analysis @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# +# A script to analyse failures in the gitlab pipelines. It requires an +# API key from gitlab with the following permissions: +# - api +# - read_repository +# - read_user +# + +import argparse +import gitlab +import os + +# +# Arguments +# +class NoneForEmptyStringAction(argparse.Action): + def __call__(self, parser, namespace, value, option_string=3DNone): + if value =3D=3D '': + setattr(namespace, self.dest, None) + else: + setattr(namespace, self.dest, value) + + +parser =3D argparse.ArgumentParser(description=3D"Analyse failed GitLab CI= runs.") + +parser.add_argument("--gitlab", + default=3D"https://gitlab.com", + help=3D"GitLab instance URL (default: https://gitlab.c= om).") +parser.add_argument("--id", default=3D11167699, + type=3Dint, + help=3D"GitLab project id (default: 11167699 for qemu-= project/qemu)") +parser.add_argument("--token", + default=3Dos.getenv("GITLAB_TOKEN"), + help=3D"Your personal access token with 'api' scope.") +parser.add_argument("--branch", + type=3Dstr, + default=3D"staging", + action=3DNoneForEmptyStringAction, + help=3D"The name of the branch (default: 'staging')") +parser.add_argument("--status", + type=3Dstr, + action=3DNoneForEmptyStringAction, + default=3D"failed", + help=3D"Filter by branch status (default: 'failed')") +parser.add_argument("--count", type=3Dint, + default=3D3, + help=3D"The number of failed runs to fetch.") +parser.add_argument("--skip-jobs", + default=3DFalse, + action=3D'store_true', + help=3D"Skip dumping the job info") +parser.add_argument("--pipeline", type=3Dint, + nargs=3D"+", + default=3DNone, + help=3D"Explicit pipeline ID(s) to fetch.") + + +if __name__ =3D=3D "__main__": + args =3D parser.parse_args() + + gl =3D gitlab.Gitlab(url=3Dargs.gitlab, private_token=3Dargs.token) + project =3D gl.projects.get(args.id) + + + pipelines_to_process =3D [] + + # Use explicit pipeline IDs if provided, otherwise fetch a list + if args.pipeline: + args.count =3D len(args.pipeline) + for p_id in args.pipeline: + pipelines_to_process.append(project.pipelines.get(p_id)) + else: + # Use an iterator to fetch the pipelines + pipe_iter =3D project.pipelines.list(iterator=3DTrue, + status=3Dargs.status, + ref=3Dargs.branch) + # Check each failed pipeline + pipelines_to_process =3D [next(pipe_iter) for _ in range(args.coun= t)] + + # Check each pipeline + for p in pipelines_to_process: + + jobs =3D p.jobs.list(get_all=3DTrue) + failed_jobs =3D [j for j in jobs if j.status =3D=3D "failed"] + skipped_jobs =3D [j for j in jobs if j.status =3D=3D "skipped"] + manual_jobs =3D [j for j in jobs if j.status =3D=3D "manual"] + + trs =3D p.test_report_summary.get() + total =3D trs.total["count"] + skipped =3D trs.total["skipped"] + failed =3D trs.total["failed"] + + print(f"{p.status} pipeline {p.id}, total jobs {len(jobs)}, " + f"skipped {len(skipped_jobs)}, " + f"failed {len(failed_jobs)}, ", + f"{total} tests, " + f"{skipped} skipped tests, " + f"{failed} failed tests") + + if not args.skip_jobs: + for j in failed_jobs: + print(f" Failed job {j.id}, {j.name}, {j.web_url}") + + # It seems we can only extract failing tests from the full + # test report, maybe there is some way to filter it. + + if failed > 0: + ftr =3D p.test_report.get() + failed_suites =3D [s for s in ftr.test_suites if + s["failed_count"] > 0] + for fs in failed_suites: + name =3D fs["name"] + tests =3D fs["test_cases"] + failed_tests =3D [t for t in tests if t["status"] =3D=3D '= failed'] + for t in failed_tests: + print(f" Failed test {t["classname"]}, {name}, {t["na= me"]}") --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892775; cv=none; d=zohomail.com; s=zohoarc; b=NXir+t+YbFs46x37RM1KKRrD0NpdM4WJQ4pWm0suS/DzEERCPpOLIzXeovYkIsPsnX533+35RW9lRuuKXOO2EY3y7RXJ+07XeoSjtanbMz20rQLXt6JQpEsOgJv6hXKI5lJrjzfNlEKiE3Q9itu+1oE1nob4GEhAeSflRRahumo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892775; 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=QuPD+L61acvA0x8PKEn4VJj4NNmgzobTUEaPWcs990U=; b=Xt2eG1spktpE5F/PAMuE3cscMP8wXbSzSDcoUVNGCq2C8OOVYQVdIlclZ+WgW+nVVM5RH8Iwyx8SAo2cOFWCUw1pn00HaK8iQBw+NK24uy2zl7sii+Js0OH1LG4bt/uxssNYotIr4FVokROfuRlI2H1DAFD3XZK8xDj7gBySMy4= 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 1758892775867326.19687167616337; Fri, 26 Sep 2025 06:19:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28L1-0007wE-Tp; Fri, 26 Sep 2025 09:18:15 -0400 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 1v28Kz-0007vf-4U for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:13 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kq-00041z-SM for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:12 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-46e2e6a708fso12825355e9.0 for ; Fri, 26 Sep 2025 06:17:51 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e33bf6ecbsm80460305e9.22.2025.09.26.06.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:45 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DA4365F8AD; Fri, 26 Sep 2025 14:17:44 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892667; x=1759497467; 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=QuPD+L61acvA0x8PKEn4VJj4NNmgzobTUEaPWcs990U=; b=CymS9TvZOWq85rmrmqwwMaYT/C4V1TEH/UYLqiRay7L9wU9m6+8WbaI2R2wg9o1NzW aB9Te/7cbA0DujBajnfd62V3cVwQQgqn1e2UB9AAFScLGJtNDUVxy9TSp/OMwNKSYLN6 zyDozXb6CnBWXi0nsue9OxmOK9s4XH7odeLK0Ys4Wc0sB2a4D/+5w7guhsXDWsUV0Ggd SeS2I7GOT42HULU/PCytkJGbBmzukYrFJv0R2ogXWB5+DqI49b9Bg5qTmMwHXOKnpdk3 hCvSKeSTmum/ArCOywrciSagpbNx4V4jjdFrc5A/U4KuzstAXhrMTsx4w5d/aAbAdTA2 pnqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892667; x=1759497467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QuPD+L61acvA0x8PKEn4VJj4NNmgzobTUEaPWcs990U=; b=Td9jlkdsnxB3c0gPhZuUUGUP3O6w9W85sCyRdwH12quhCHPMLshtqc7yW6FdQk2/1L x9U6jEQQMqtPY8yc74tPJTjDJZlMINYoTR5ehnTa1AvsDhNR3hOvcoGyo3uRlgeFjWBC RsTwQMN98mODiAOPRcrwtLdC4377pDkWv+K14fKZXXIkF1JW05qilDyGSq71Kx3htZIf 4X2y+YnhPQ4PZO93hfyg/d60A/R9nwPWhdY9sEAkCxuSikSTZ2Xtwh/xYK8fYiHaRDwJ /RlYeSHF/8XNDKc4Y9m2W57o5/b28v4xW3bfOxBcVJ+JTWLn//wSef4shJHoLQ4hOjyX i23A== X-Gm-Message-State: AOJu0YwgIkNTIqks8Zp3lcuL5EMXVMIeVJTO/TceIqhcyUO4envQ2KfO pTNbo8vByE0vQS6/dNV4t6242JQciajFWNbeqPL/6iL6GborfsMu6s/63iG4FXZuGSc= X-Gm-Gg: ASbGncuXj4aadhW89cBh87CzuGEOUdSmwpL5VdEGIx6FoH108u26KuB0lM77nWE34cH 04ON+ngT54+riaN4tPOgTA+mLFZNC4sOPm5gXJ2RQPsmHnNJ0QJI1YBc/bgcmuMqLPDMvOx3yoI 9zZLgXKhAWCj1adROp89FeXTjGEV3rO4ns077yobaoR7jual0tD2GKT7gQzSEsRw+uX3GSFn2FV 7+7Km2KTL+1KMbGele+3kbHuJPe5u8TYUMJClC+xH4vpzFDOPeNyl2ZaS98aklwxwqTnlz8gPw1 eGOXJi2B9QA8zVkRjFCQDT62lTK8su8JGqd83tvzPLqHqH/6Q0Y4+G3o/UmBsyxCvXzK4mnMSGz lVfBen9iJozpDh5xLYGFA6Bo= X-Google-Smtp-Source: AGHT+IEvwMYJ0STpamQ6LtPXC30S+bE3uFkVgVceMGkjSvZY6sa0z5vbPATgnvqCi83D1cMAp+5OxA== X-Received: by 2002:a05:600c:a09:b0:45f:29e4:92fc with SMTP id 5b1f17b1804b1-46e329eb12emr65161935e9.20.1758892667375; Fri, 26 Sep 2025 06:17:47 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Nabih Estefan , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 02/24] checkpatch: Ignore removed lines in license check Date: Fri, 26 Sep 2025 14:17:21 +0100 Message-ID: <20250926131744.432185-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::333; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x333.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: 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: 1758892778010116600 From: Nabih Estefan When running the license check, if we are updating a license it is possible for the checkpatch script to test against old license lines instead of newer ones, since the removal lines appear before the addition lines in a .patch file. Fix this by skipping over lines that start with "-" in the checkpatch script. Signed-off-by: Nabih Estefan Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Alex Benn=C3=A9e Message-ID: <20250916165928.10048-1-nabihestefan@google.com> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-4-alex.bennee@linaro.org> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 91616c974f2..40b6955c698 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1816,7 +1816,8 @@ sub process { } =20 # Check SPDX-License-Identifier references a permitted license - if ($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) { + if (($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) && + $rawline !~ /^-/) { $fileinfo->{facts}->{sawspdx} =3D 1; &checkspdx($realfile, $1); } --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892778; cv=none; d=zohomail.com; s=zohoarc; b=WtdpijQUw4owujM4xJG9rvwViFoQTn9ydhxywmP6XgJqMf2MjeTbutkoqgGjdPK4aAuTWK0Fc5aZN1xs+kageKY4h3VduPQyWDcvzfnDSf1iqIL3cWmmLox+JHwXfGXL3lP6uC6UjQ35KzXc5jMNx+J63RMR1c1ZH2VV3Jbysgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892778; 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=wog2u7ZRqBCvVQUI8DPnDXMtSGN90PRtiQocp7urOxA=; b=ZMV4zK+PlXDPeAyqCV97O8Qrp3BOcxEwsNtP2g0z46cR9s3HzSaKV7mL9zXHUCsKVeqkCY8N8mfVRQFsmjScUNHQ0zI9fH1ZXQmnqJ71o6T2blSTYgeqb9dAMm8k/CL5vtiH51Qca55Pa91+kTsAssi/qtNsfvobCKA00ky/oz8= 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 175889277820059.18050350446913; Fri, 26 Sep 2025 06:19:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LB-00081w-VR; Fri, 26 Sep 2025 09:18:26 -0400 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 1v28L9-00080f-0Z for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:24 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kq-00042K-SN for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:22 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3ee1381b835so1816564f8f.1 for ; Fri, 26 Sep 2025 06:17:51 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fc5603365sm7353419f8f.37.2025.09.26.06.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:45 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 019505F8B1; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892669; x=1759497469; 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=wog2u7ZRqBCvVQUI8DPnDXMtSGN90PRtiQocp7urOxA=; b=l8mk9V4r8RGsVbrqIJDHGQfcI7uWc6W6EP/qwjzlqCmfM97T5lBBn+nd+jYmp43EOz +ScvPJy+npCx1bhNRPkmg9XGkBjsOzRU0JJF5U5yZZIoicV8v5mHJCH/VlQ9FUBhd8uO 3rQOHT7662MKtS0yyX3P+lZgANYjTPC+1W+pMNYRHeOvx+qxNn6ZYxek2A7ve3cHxi4y 2Af/MTgM1T9SqbwA24Vbc1tO5RBgNM3yujUMTxOSyT0Z50GgWyJa0g4d99hiSt7Of1Ze XbNtjxsY/YLP/OCtVx5fsHycPpCaZpH2ItTenJPn1bzBJyHQk+ukIC3KRuSgEddv4/yY t4pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892670; x=1759497470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wog2u7ZRqBCvVQUI8DPnDXMtSGN90PRtiQocp7urOxA=; b=p2OwIUhOZ+o1HZPXijzZyxSoBE6dBQQLVCR3DFWLAMI9zztS0S+gDIKUuS6v2TQE5N 9394KWif2MDB5W/LvMn4Uu/oYR4zpZa1Xp3sYEqYCiDqshM8Iu4OgXXG67DR3p6x4q2l 7dLBCobD+U49DvzIMve/WUtcr2nsKeP4dC/wIvTqgrER/Upgds+pIkK55N6N3hX6P92J QgwRV4xZHYY4gAH5uJHBQva7c0PkfjI9rjttsk+oG/d2G3q+cmlTwHV5cU5V9IxZ5RjJ PvANbLprT6odXhWOOOuITSX/Zt2e99YyFdwdd/f9hA0+5fKB8dM4d+py2Atj7Fb6JN/i HA9g== X-Gm-Message-State: AOJu0Yy6qkRrLHiscgPJBJFu/znfEDk+Q1KgqJ8TszB/jvZIHHDsRIi6 laUaV/X9ujWxmNrGOo5VMtapOVjF95v9sx6jkzgjDAad+PQ58gPR4VhhGksA4WWYt9I= X-Gm-Gg: ASbGncsn+tP83shfJl4Nzz/GngSm8a8f3GbfI00Qxi16Dtl3yGxIMfnKV93CffgMgwz jtm/VF691Ryc1Gxo/CMOyNoOdZXSxK1VVjzuHKBN8vWyLQIYdspfkTmKQ5ppJw4eXM8z5DB2Cnq Q0f6ktpChrqsrZqFJN/DzPeVl1JTYY44xQJeV8EtzkEMro9Xdy7pc5ilRYUJ+0oXLJWc9qnOnqX PDbi3ke4GPnWl0VdIdsZrRn+tp2yMKdmJotFR66LmSbc6KshHac0KC4oA4upALE9QMpZoi3PKeJ Cndtu/UxgFWgPtOxIzJYWcrO2aw9/wcY31cttvnuU4tSiGGHkJdlFlJQURR2WBHT6HgaashfuUE jZ3G6TKQwIaQEV0/avFut1xZmOUd1P0EhLQ== X-Google-Smtp-Source: AGHT+IEPwCnkNMZ7ZM1XdFg6nGJN7t8pwLovdGHDGkfo+OxeCTdPoVqtWDhmyCK5F3erCw5Yz6oZKw== X-Received: by 2002:a05:6000:1447:b0:3e8:e52:31c5 with SMTP id ffacd0b85a97d-40e468e626emr6823674f8f.2.1758892669524; Fri, 26 Sep 2025 06:17:49 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 03/24] semihosting/syscalls: compile once in system and per target for user mode Date: Fri, 26 Sep 2025 14:17:22 +0100 Message-ID: <20250926131744.432185-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::433; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x433.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_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: 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: 1758892780007116600 From: Pierrick Bouvier We replace target_ulong mechanically by uint64_t. We can't compile (easily) this code once for user, as it relies on various target/function types, so leave it in specific_ss for user mode. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-2-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-5-alex.bennee@linaro.org> diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 6627c45fb28..03aa45b7bb9 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -9,7 +9,7 @@ #ifndef SEMIHOSTING_SYSCALLS_H #define SEMIHOSTING_SYSCALLS_H =20 -#include "exec/cpu-defs.h" +#include "exec/vaddr.h" #include "gdbstub/syscalls.h" =20 /* @@ -24,23 +24,23 @@ typedef struct GuestFD GuestFD; =20 void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, + vaddr fname, uint64_t fname_len, int gdb_flags, int mode); =20 void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd); =20 void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, - int fd, target_ulong buf, target_ulong len); + int fd, vaddr buf, uint64_t len); =20 void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len); + GuestFD *gf, vaddr buf, uint64_t len); =20 void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, - int fd, target_ulong buf, target_ulong len); + int fd, vaddr buf, uint64_t len); =20 void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len= ); + GuestFD *gf, vaddr buf, uint64_t len); =20 void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, int fd, int64_t off, int gdb_whence); @@ -50,27 +50,27 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_comp= lete_cb complete, =20 void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, - int fd, target_ulong fstat_addr); + int fd, vaddr fstat_addr); =20 void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - int fd, target_ulong addr); + int fd, vaddr addr); =20 void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, - target_ulong addr); + vaddr fname, uint64_t fname_len, + vaddr addr); =20 void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len); + vaddr fname, uint64_t fname_len); =20 void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong oname, target_ulong oname_len, - target_ulong nname, target_ulong nname_len); + vaddr oname, uint64_t oname_len, + vaddr nname, uint64_t nname_len); =20 void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong cmd, target_ulong cmd_len); + vaddr cmd, uint64_t cmd_len); =20 void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb compl= ete, - target_ulong tv_addr, target_ulong tz_addr); + vaddr tv_addr, vaddr tz_addr); =20 void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, int fd, GIOCondition cond, int timeout); diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index bcd13cd6dfd..64ddc749bf8 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -34,6 +34,7 @@ #include "qemu/osdep.h" #include "qemu/timer.h" #include "exec/gdbstub.h" +#include "cpu.h" #include "gdbstub/syscalls.h" #include "semihosting/semihost.h" #include "semihosting/console.h" diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index f6451d9bb0e..f072d919193 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -8,7 +8,6 @@ =20 #include "qemu/osdep.h" #include "qemu/log.h" -#include "cpu.h" #include "gdbstub/syscalls.h" #include "semihosting/guestfd.h" #include "semihosting/syscalls.h" @@ -23,7 +22,7 @@ /* * Validate or compute the length of the string (including terminator). */ -static int validate_strlen(CPUState *cs, target_ulong str, target_ulong tl= en) +static int validate_strlen(CPUState *cs, uint64_t str, uint64_t tlen) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char c; @@ -52,7 +51,7 @@ static int validate_strlen(CPUState *cs, target_ulong str= , target_ulong tlen) } =20 static int validate_lock_user_string(char **pstr, CPUState *cs, - target_ulong tstr, target_ulong tlen) + uint64_t tstr, uint64_t tlen) { int ret =3D validate_strlen(cs, tstr, tlen); CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); @@ -72,7 +71,7 @@ static int validate_lock_user_string(char **pstr, CPUStat= e *cs, * big-endian. Until we do something with gdb, also produce the * same big-endian result from the host. */ -static int copy_stat_to_user(CPUState *cs, target_ulong addr, +static int copy_stat_to_user(CPUState *cs, uint64_t addr, const struct stat *s) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); @@ -129,7 +128,7 @@ static void gdb_open_cb(CPUState *cs, uint64_t ret, int= err) } =20 static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, + uint64_t fname, uint64_t fname_len, int gdb_flags, int mode) { int len =3D validate_strlen(cs, fname, fname_len); @@ -151,14 +150,14 @@ static void gdb_close(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, uint64_t buf, uint64_t len) { gdb_do_syscall(complete, "read,%x,%lx,%lx", (uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len); } =20 static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, uint64_t buf, uint64_t len) { gdb_do_syscall(complete, "write,%x,%lx,%lx", (uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len); @@ -178,15 +177,15 @@ static void gdb_isatty(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong addr) + GuestFD *gf, uint64_t addr) { gdb_do_syscall(complete, "fstat,%x,%lx", (uint32_t)gf->hostfd, (uint64_t)addr); } =20 static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, - target_ulong addr) + uint64_t fname, uint64_t fname_len, + uint64_t addr) { int len =3D validate_strlen(cs, fname, fname_len); if (len < 0) { @@ -199,7 +198,7 @@ static void gdb_stat(CPUState *cs, gdb_syscall_complete= _cb complete, } =20 static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len) + uint64_t fname, uint64_t fname_len) { int len =3D validate_strlen(cs, fname, fname_len); if (len < 0) { @@ -211,8 +210,8 @@ static void gdb_remove(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong oname, target_ulong oname_len, - target_ulong nname, target_ulong nname_len) + uint64_t oname, uint64_t oname_len, + uint64_t nname, uint64_t nname_len) { int olen, nlen; =20 @@ -233,7 +232,7 @@ static void gdb_rename(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong cmd, target_ulong cmd_len) + uint64_t cmd, uint64_t cmd_len) { int len =3D validate_strlen(cs, cmd, cmd_len); if (len < 0) { @@ -245,7 +244,7 @@ static void gdb_system(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complet= e, - target_ulong tv_addr, target_ulong tz_addr) + uint64_t tv_addr, uint64_t tz_addr) { gdb_do_syscall(complete, "gettimeofday,%lx,%lx", (uint64_t)tv_addr, (uint64_t)tz_addr); @@ -256,7 +255,7 @@ static void gdb_gettimeofday(CPUState *cs, gdb_syscall_= complete_cb complete, */ =20 static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, + uint64_t fname, uint64_t fname_len, int gdb_flags, int mode) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); @@ -316,7 +315,7 @@ static void host_close(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, uint64_t buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); void *ptr =3D lock_user(VERIFY_WRITE, buf, len, 0); @@ -337,7 +336,7 @@ static void host_read(CPUState *cs, gdb_syscall_complet= e_cb complete, } =20 static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, uint64_t buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); void *ptr =3D lock_user(VERIFY_READ, buf, len, 1); @@ -395,7 +394,7 @@ static void host_flen(CPUState *cs, gdb_syscall_complet= e_cb complete, } =20 static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong addr) + GuestFD *gf, uint64_t addr) { struct stat buf; int ret; @@ -410,8 +409,8 @@ static void host_fstat(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, - target_ulong addr) + uint64_t fname, uint64_t fname_len, + uint64_t addr) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); struct stat buf; @@ -440,7 +439,7 @@ static void host_stat(CPUState *cs, gdb_syscall_complet= e_cb complete, } =20 static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len) + uint64_t fname, uint64_t fname_len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *p; @@ -458,8 +457,8 @@ static void host_remove(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong oname, target_ulong oname_len, - target_ulong nname, target_ulong nname_len) + uint64_t oname, uint64_t oname_len, + uint64_t nname, uint64_t nname_len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *ostr, *nstr; @@ -484,7 +483,7 @@ static void host_rename(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong cmd, target_ulong cmd_len) + uint64_t cmd, uint64_t cmd_len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *p; @@ -502,7 +501,7 @@ static void host_system(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb comple= te, - target_ulong tv_addr, target_ulong tz_addr) + uint64_t tv_addr, uint64_t tz_addr) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); struct gdb_timeval *p; @@ -547,10 +546,10 @@ static void host_poll_one(CPUState *cs, gdb_syscall_c= omplete_cb complete, */ =20 static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong le= n) + GuestFD *gf, uint64_t buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); - target_ulong rest =3D gf->staticfile.len - gf->staticfile.off; + uint64_t rest =3D gf->staticfile.len - gf->staticfile.off; void *ptr; =20 if (len > rest) { @@ -605,7 +604,7 @@ static void staticfile_flen(CPUState *cs, gdb_syscall_c= omplete_cb complete, */ =20 static void console_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, uint64_t buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *ptr; @@ -622,7 +621,7 @@ static void console_read(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 static void console_write(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, uint64_t buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *ptr =3D lock_user(VERIFY_READ, buf, len, 1); @@ -638,7 +637,7 @@ static void console_write(CPUState *cs, gdb_syscall_com= plete_cb complete, } =20 static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong addr) + GuestFD *gf, uint64_t addr) { static const struct stat tty_buf =3D { .st_mode =3D 020666, /* S_IFCHR, ugo+rw */ @@ -683,7 +682,7 @@ static void console_poll_one(CPUState *cs, gdb_syscall_= complete_cb complete, */ =20 void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, + vaddr fname, uint64_t fname_len, int gdb_flags, int mode) { if (use_gdb_syscalls()) { @@ -719,7 +718,7 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_compl= ete_cb complete, int fd) } =20 void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, vaddr buf, uint64_t len) { /* * Bound length for 64-bit guests on 32-bit hosts, not overflowing ssi= ze_t. @@ -748,7 +747,7 @@ void semihost_sys_read_gf(CPUState *cs, gdb_syscall_com= plete_cb complete, } =20 void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, - int fd, target_ulong buf, target_ulong len) + int fd, vaddr buf, uint64_t len) { GuestFD *gf =3D get_guestfd(fd); =20 @@ -760,7 +759,7 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, target_ulong buf, target_ulong len) + GuestFD *gf, vaddr buf, uint64_t len) { /* * Bound length for 64-bit guests on 32-bit hosts, not overflowing ssi= ze_t. @@ -790,7 +789,7 @@ void semihost_sys_write_gf(CPUState *cs, gdb_syscall_co= mplete_cb complete, } =20 void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, - int fd, target_ulong buf, target_ulong len) + int fd, vaddr buf, uint64_t len) { GuestFD *gf =3D get_guestfd(fd); =20 @@ -856,7 +855,7 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_comp= lete_cb complete, int fd) =20 void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, - target_ulong fstat_addr) + vaddr fstat_addr) { GuestFD *gf =3D get_guestfd(fd); =20 @@ -881,7 +880,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_comple= te_cb fstat_cb, } =20 void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - int fd, target_ulong addr) + int fd, vaddr addr) { GuestFD *gf =3D get_guestfd(fd); =20 @@ -906,8 +905,8 @@ void semihost_sys_fstat(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len, - target_ulong addr) + vaddr fname, uint64_t fname_len, + vaddr addr) { if (use_gdb_syscalls()) { gdb_stat(cs, complete, fname, fname_len, addr); @@ -917,7 +916,7 @@ void semihost_sys_stat(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong fname, target_ulong fname_len) + vaddr fname, uint64_t fname_len) { if (use_gdb_syscalls()) { gdb_remove(cs, complete, fname, fname_len); @@ -927,8 +926,8 @@ void semihost_sys_remove(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong oname, target_ulong oname_len, - target_ulong nname, target_ulong nname_len) + vaddr oname, uint64_t oname_len, + vaddr nname, uint64_t nname_len) { if (use_gdb_syscalls()) { gdb_rename(cs, complete, oname, oname_len, nname, nname_len); @@ -938,7 +937,7 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, - target_ulong cmd, target_ulong cmd_len) + vaddr cmd, uint64_t cmd_len) { if (use_gdb_syscalls()) { gdb_system(cs, complete, cmd, cmd_len); @@ -948,7 +947,7 @@ void semihost_sys_system(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb compl= ete, - target_ulong tv_addr, target_ulong tz_addr) + vaddr tv_addr, vaddr tz_addr) { if (use_gdb_syscalls()) { gdb_gettimeofday(cs, complete, tv_addr, tz_addr); diff --git a/semihosting/meson.build b/semihosting/meson.build index b1ab2506c6e..77200a7f27b 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,6 +1,5 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'guestfd.c', - 'syscalls.c', )) =20 common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c')) @@ -9,9 +8,12 @@ system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'config.c', 'console.c', 'uaccess.c', + 'syscalls.c', ), if_false: files( 'stubs-system.c', )) =20 +specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'], + if_true: files('syscalls.c')) specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], if_true: files('arm-compat-semi.c')) --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893021; cv=none; d=zohomail.com; s=zohoarc; b=F0HRkhyr8kX2nOHH/PA7vxE51h6rv8eZ2Gh4kSkhULm5JlT1ircjZFtTh8xNE6lj3I3fS+WvdsgHJLaFeMnR4jClOVrFpXvVZaTDeQGTNeFB/pOlfU5DRRQ+Tu7koaB1i+z/ZxqmSTHuwGoEnbvfQ0jEAstnZdiAen1ADDoG/M8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893021; 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=ACx74X0aVOokugEYr9mMB95UikdQzR30m6cDT5fxuCE=; b=UwFxx4FJVetp1+Vtx9P36B2kwYAtB24OnvEVbNom1hiU6NU3LB8IGvH7G06TDNLxMcsyL9d/5KIUYNllB/+qohihzdS/trNjcc4oBSySmDK+t8A0hZdmJm2yO551znQsWFE6pHHSlCjDSWP6hmEme2CEYvRmEHw7X8p+b0xnuiQ= 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 1758893021688373.78872766152654; Fri, 26 Sep 2025 06:23:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LN-00086l-V4; Fri, 26 Sep 2025 09:18:39 -0400 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 1v28LL-00085k-8s for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:36 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Ks-00042Q-1v for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:34 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-46e42fa08e4so1844415e9.3 for ; Fri, 26 Sep 2025 06:17:52 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fc5602efdsm7367139f8f.34.2025.09.26.06.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:47 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 170E85F8B2; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892670; x=1759497470; 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=ACx74X0aVOokugEYr9mMB95UikdQzR30m6cDT5fxuCE=; b=usO2+dXcLE9ofrsmFxQTrzFTlB7agWjci+cN5ciAuIiYBEeG2kXE+MHN4xMje6SLmm SycsXDGCmvdTgHQ1eRfA8buKgPGYi+3OScKirQzktFxEgZXhyiuGBrZ94yQxvf5QvkDh kCZ+8a1/NulhqyZDCAmOn4HZqexDj/weRKz7/tXi+Z7gVVNEK+vDNG2Xo24dsfdqoncM K1cL68t86+lgdJOMmknftCwWEesBoaOf+IEZWm0gMaXxoh+NtHE+WaGlm4pBPkOlELgt ZRBtAoOknlEsY+3lsy235A4eecllY1Hep1EO9G4NwZPG5Z3+nClq0moGQqmwwxQHSvMy 4LlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892670; x=1759497470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ACx74X0aVOokugEYr9mMB95UikdQzR30m6cDT5fxuCE=; b=E5zl+b1Y7mi+TGbxiFYSaoNc2PCbrz+gbYEz0QLlIq7mZ67dfKe7x+Yanh0qL3smRs DNfeQYo4k1MiMTapGi/2+0dFg7XBpAk4G0Qu37nBorz3teGtI3DIhiCtjLqH4AGQ/nqO GSC2vZwUwNpA1DYHNx7RbKuRT49qW+k+mHEfmyy9CDnLBZ+xfCIIZCjZnMsRyX5UzJaU McvuRAM7DQRFxTEAqRVRbiJpim9rRzlcst8I0vlur+2TiOGtptidn6PZxY+w437oICah qVQ9J6vjBawGQ2WGdC6+VzNmcKYNcyjLVQMitzXqJRCsH2o6JSJWOLiMSNsYNTU1z6kF yENw== X-Gm-Message-State: AOJu0YyJ62X0FRboj4BRlf6HNn1bAEThLpXYpeNmBu/nuPbkOmlNpb7U nTbEqLY9eYVnmaCiYaUI9MYchRpDNEW+yOwVc9eoJ6rrtS1VU/3PruaSU1WVbVx4p+Y= X-Gm-Gg: ASbGncvvm/vk8BRS1EUhM8dkyhUbbq2RqQzjHZ/Rmgu998MaSq6tBONJ7Sb4aZLGDc7 NLpJ+Mt9qLka2Zmu3FZO1nKxsLAVKil6YP4hr2dNoRqw8ut8JgUCJm1D6/Tj9qg3SGjJXjQhr3O xGXc478nGLytbO0l4fr8WW2GDUYfCeawOlBfa2+n6Z1/6P1OGkJmIqpZDj6CbhFvLpIBqC5BxV9 kUJ+TnGb7duLChPsaNZmAbLburJmcO5zlUkwTPKlg2COPcH7rn1xyWzfRQ5VmjRGXSMdw2VrL2q evbp7QbLw7r8UnFmnDpe4UnPAZICyFwIXZwhSUM9/N63FtCE0ZCEI1PtQasWEHsQRaJpRgGUpUX 9rHUDNOn5MrGorCqEHZ13XCQ= X-Google-Smtp-Source: AGHT+IF7O55KcR3SZ8WpdDkbZhCTaDZdkGB7iO+ZwTZPPWR8he4ep0OztFb1NY9kSPW7Dml7OqvyLQ== X-Received: by 2002:a05:6000:2484:b0:3f0:9bf0:a369 with SMTP id ffacd0b85a97d-40e43b08823mr7092818f8f.14.1758892670344; Fri, 26 Sep 2025 06:17:50 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 04/24] semihosting/syscalls: replace uint64_t with vaddr where appropriate Date: Fri, 26 Sep 2025 14:17:23 +0100 Message-ID: <20250926131744.432185-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.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, T_SPF_TEMPERROR=0.01 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: 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: 1758893023230116600 From: Pierrick Bouvier Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-6-alex.bennee@linaro.org> diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index f072d919193..20f155f869a 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -22,7 +22,7 @@ /* * Validate or compute the length of the string (including terminator). */ -static int validate_strlen(CPUState *cs, uint64_t str, uint64_t tlen) +static int validate_strlen(CPUState *cs, vaddr str, uint64_t tlen) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char c; @@ -51,7 +51,7 @@ static int validate_strlen(CPUState *cs, uint64_t str, ui= nt64_t tlen) } =20 static int validate_lock_user_string(char **pstr, CPUState *cs, - uint64_t tstr, uint64_t tlen) + vaddr tstr, uint64_t tlen) { int ret =3D validate_strlen(cs, tstr, tlen); CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); @@ -71,7 +71,7 @@ static int validate_lock_user_string(char **pstr, CPUStat= e *cs, * big-endian. Until we do something with gdb, also produce the * same big-endian result from the host. */ -static int copy_stat_to_user(CPUState *cs, uint64_t addr, +static int copy_stat_to_user(CPUState *cs, vaddr addr, const struct stat *s) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); @@ -128,7 +128,7 @@ static void gdb_open_cb(CPUState *cs, uint64_t ret, int= err) } =20 static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t fname, uint64_t fname_len, + vaddr fname, uint64_t fname_len, int gdb_flags, int mode) { int len =3D validate_strlen(cs, fname, fname_len); @@ -139,7 +139,7 @@ static void gdb_open(CPUState *cs, gdb_syscall_complete= _cb complete, =20 gdb_open_complete =3D complete; gdb_do_syscall(gdb_open_cb, "open,%s,%x,%x", - (uint64_t)fname, (uint32_t)len, + (vaddr)fname, (uint32_t)len, (uint32_t)gdb_flags, (uint32_t)mode); } =20 @@ -150,17 +150,17 @@ static void gdb_close(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t buf, uint64_t len) + GuestFD *gf, vaddr buf, uint64_t len) { gdb_do_syscall(complete, "read,%x,%lx,%lx", - (uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len); + (uint32_t)gf->hostfd, (vaddr)buf, (uint64_t)len); } =20 static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t buf, uint64_t len) + GuestFD *gf, vaddr buf, uint64_t len) { gdb_do_syscall(complete, "write,%x,%lx,%lx", - (uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len); + (uint32_t)gf->hostfd, (vaddr)buf, (uint64_t)len); } =20 static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete, @@ -177,15 +177,15 @@ static void gdb_isatty(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t addr) + GuestFD *gf, vaddr addr) { gdb_do_syscall(complete, "fstat,%x,%lx", - (uint32_t)gf->hostfd, (uint64_t)addr); + (uint32_t)gf->hostfd, (vaddr)addr); } =20 static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t fname, uint64_t fname_len, - uint64_t addr) + vaddr fname, uint64_t fname_len, + vaddr addr) { int len =3D validate_strlen(cs, fname, fname_len); if (len < 0) { @@ -194,11 +194,11 @@ static void gdb_stat(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 gdb_do_syscall(complete, "stat,%s,%lx", - (uint64_t)fname, (uint32_t)len, (uint64_t)addr); + (vaddr)fname, (uint32_t)len, (vaddr)addr); } =20 static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t fname, uint64_t fname_len) + vaddr fname, uint64_t fname_len) { int len =3D validate_strlen(cs, fname, fname_len); if (len < 0) { @@ -206,12 +206,12 @@ static void gdb_remove(CPUState *cs, gdb_syscall_comp= lete_cb complete, return; } =20 - gdb_do_syscall(complete, "unlink,%s", (uint64_t)fname, (uint32_t)len); + gdb_do_syscall(complete, "unlink,%s", (vaddr)fname, (uint32_t)len); } =20 static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t oname, uint64_t oname_len, - uint64_t nname, uint64_t nname_len) + vaddr oname, uint64_t oname_len, + vaddr nname, uint64_t nname_len) { int olen, nlen; =20 @@ -227,12 +227,12 @@ static void gdb_rename(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 gdb_do_syscall(complete, "rename,%s,%s", - (uint64_t)oname, (uint32_t)olen, - (uint64_t)nname, (uint32_t)nlen); + (vaddr)oname, (uint32_t)olen, + (vaddr)nname, (uint32_t)nlen); } =20 static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t cmd, uint64_t cmd_len) + vaddr cmd, uint64_t cmd_len) { int len =3D validate_strlen(cs, cmd, cmd_len); if (len < 0) { @@ -240,14 +240,14 @@ static void gdb_system(CPUState *cs, gdb_syscall_comp= lete_cb complete, return; } =20 - gdb_do_syscall(complete, "system,%s", (uint64_t)cmd, (uint32_t)len); + gdb_do_syscall(complete, "system,%s", (vaddr)cmd, (uint32_t)len); } =20 static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complet= e, - uint64_t tv_addr, uint64_t tz_addr) + vaddr tv_addr, vaddr tz_addr) { gdb_do_syscall(complete, "gettimeofday,%lx,%lx", - (uint64_t)tv_addr, (uint64_t)tz_addr); + (vaddr)tv_addr, (vaddr)tz_addr); } =20 /* @@ -255,7 +255,7 @@ static void gdb_gettimeofday(CPUState *cs, gdb_syscall_= complete_cb complete, */ =20 static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t fname, uint64_t fname_len, + vaddr fname, uint64_t fname_len, int gdb_flags, int mode) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); @@ -315,7 +315,7 @@ static void host_close(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t buf, uint64_t len) + GuestFD *gf, vaddr buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); void *ptr =3D lock_user(VERIFY_WRITE, buf, len, 0); @@ -336,7 +336,7 @@ static void host_read(CPUState *cs, gdb_syscall_complet= e_cb complete, } =20 static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t buf, uint64_t len) + GuestFD *gf, vaddr buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); void *ptr =3D lock_user(VERIFY_READ, buf, len, 1); @@ -394,7 +394,7 @@ static void host_flen(CPUState *cs, gdb_syscall_complet= e_cb complete, } =20 static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t addr) + GuestFD *gf, vaddr addr) { struct stat buf; int ret; @@ -409,8 +409,8 @@ static void host_fstat(CPUState *cs, gdb_syscall_comple= te_cb complete, } =20 static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t fname, uint64_t fname_len, - uint64_t addr) + vaddr fname, uint64_t fname_len, + vaddr addr) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); struct stat buf; @@ -439,7 +439,7 @@ static void host_stat(CPUState *cs, gdb_syscall_complet= e_cb complete, } =20 static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t fname, uint64_t fname_len) + vaddr fname, uint64_t fname_len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *p; @@ -457,8 +457,8 @@ static void host_remove(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t oname, uint64_t oname_len, - uint64_t nname, uint64_t nname_len) + vaddr oname, uint64_t oname_len, + vaddr nname, uint64_t nname_len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *ostr, *nstr; @@ -483,7 +483,7 @@ static void host_rename(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, - uint64_t cmd, uint64_t cmd_len) + vaddr cmd, uint64_t cmd_len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *p; @@ -501,7 +501,7 @@ static void host_system(CPUState *cs, gdb_syscall_compl= ete_cb complete, } =20 static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb comple= te, - uint64_t tv_addr, uint64_t tz_addr) + vaddr tv_addr, vaddr tz_addr) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); struct gdb_timeval *p; @@ -546,7 +546,7 @@ static void host_poll_one(CPUState *cs, gdb_syscall_com= plete_cb complete, */ =20 static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t buf, uint64_t len) + GuestFD *gf, vaddr buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); uint64_t rest =3D gf->staticfile.len - gf->staticfile.off; @@ -604,7 +604,7 @@ static void staticfile_flen(CPUState *cs, gdb_syscall_c= omplete_cb complete, */ =20 static void console_read(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t buf, uint64_t len) + GuestFD *gf, vaddr buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *ptr; @@ -621,7 +621,7 @@ static void console_read(CPUState *cs, gdb_syscall_comp= lete_cb complete, } =20 static void console_write(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t buf, uint64_t len) + GuestFD *gf, vaddr buf, uint64_t len) { CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); char *ptr =3D lock_user(VERIFY_READ, buf, len, 1); @@ -637,7 +637,7 @@ static void console_write(CPUState *cs, gdb_syscall_com= plete_cb complete, } =20 static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete, - GuestFD *gf, uint64_t addr) + GuestFD *gf, vaddr addr) { static const struct stat tty_buf =3D { .st_mode =3D 020666, /* S_IFCHR, ugo+rw */ --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892951; cv=none; d=zohomail.com; s=zohoarc; b=KDsxwdjTSD+upfCBna3srtQNLX6iZPBh2UIgPYp9BjdsnONv3WPDrYabD5BiAvKrWQmP37uuRDYcf0ax8+znikV3xmzcG1aWP3YLpifK8n2pUmz4SzdXB6hz1Jrr6Zw4MQp4qCd2cpNbwRtBWFM4wwSzkRH6ImWEORJCZaENBt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892951; 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=PT5ys6VW+Xb6TbLCy138ABnHFrZi9OZshK4P6osFvUA=; b=DCfWPiIjFu7I8OiJ5aAw8r/V5y2ELj3tRWep1NLzKmaLmrwck//rwVUSd+y8NOKTenaicI84VmD075evkaNTxKmkR5L0YVn9y++/0SQ6cFtJbmbJJ9IhUycM7K4DP7ZzidmAsH9lGKiTbjqXHp8d+CF+ASGse5rRSMu3ZuYt5Iw= 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 1758892951737644.6529284158369; Fri, 26 Sep 2025 06:22:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LI-00084c-Ea; Fri, 26 Sep 2025 09:18:32 -0400 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 1v28LG-00082R-LJ for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:30 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450: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 1v28Ks-00042j-T2 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:26 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3ee15505cdeso1808685f8f.0 for ; Fri, 26 Sep 2025 06:17:55 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fb89fb19fsm7203035f8f.21.2025.09.26.06.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:49 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 321A75F8BD; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892672; x=1759497472; 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=PT5ys6VW+Xb6TbLCy138ABnHFrZi9OZshK4P6osFvUA=; b=UuL8QjIN6HJEZrzeHcFvf2Hd4qNLsWGZBNfpWavjNg/5/bHTZ3qUT/xjxjW1riFrO1 MnH0rvg6YwIMVwkysyV51FNzcjaPeQEbDUy4vpxpnIrBywuHPXNTcuOYtWH8p7//+cd7 v0ZO4UEH6YYzCe8vFB1ymUb/B9KljkGXSZL4TR53h2xBa7Kxr3uLBdbWgxXqPLCxi65/ 4P/qgVTM1iX7d3/fn35WjOX36twhcaJM71vRarhVy2DXcsNV70yIUIn+doLOrB9Glqri AebJ8Ztu3TSzjD4IKbEuHX2yAmkqzYT3vx78HoIrk7Xnu+Gf2vX1w3z/li9Za7cYdtUp GcCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892672; x=1759497472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PT5ys6VW+Xb6TbLCy138ABnHFrZi9OZshK4P6osFvUA=; b=O8/kt+bNSF/quC6XbcnJCWqJVdYJ1cvZT/XaT2KjuIvaNFTFQ6oqa7QWxHt8brspMr CyhAMJZ5FsikGtooGOKcLjkFolZen9Vcb4S1F206PJ7D4gud8ehA9k9taHQkJho7Altm bDRrSx/6AZXIb81YKlemfCCtONrM6dQpHLsSnjEn7khaIiwSFN7qriL0eouyHoTSLGkA loZxMFRXqj+DGrUtjbk9eQqHv0pc1qtEcIU41gfCWZjEIQYi4eHlYfT9QhIVKLJCDyTX igIoQmdTzGUa4ER+rFuvC/wGMgvrAuZeEjK+K8mZC8iKsTVOEtUke7UD7F+cfW6lplBY 932w== X-Gm-Message-State: AOJu0Yxw3P7eVU4kei3hWRl7Q+jqaUCaO23/U6duRZdT86O/pqqp0ul/ 03QKKFbFPd03fHArqmtHNrOrwcaeqz6VGsnm2MN6rZ9CR3YA7U2+OpdO0n3omSCiSIGE18fDdzg 5qXLu2WQ= X-Gm-Gg: ASbGnctP5pKF7g8fr8hkVC5UdQgVTesLGSL4MJHBM3df6qqlGVw/8q1JcWKpBmq2PhS G33ySa2iqvIEt2VpXnW961xPyCtrYmiNDRaX8043tLE6dao+yriKW0itFTRLCQdxLs0pgjhEUPB ZOOd8LfC0y8h+Drj2MKz3xoVDO6jAq6XEEBaLudf3Owd9IdcgMqWF7tqUHHXcYwqLMkbjMzMvKM zUlzu1QHrzgyo0NW1Oc53TMQ6SJUHX1cn30V/WsDgEhPHu5/2dob/mIHlr5R+GNpqohsfpgFlW/ xiLntkYlHXJf/cmgd+nnt+MrTpD9kmi+PN/dHkCFEaWoCtspurbu7OYUjfJw6ux7OK4iVhumLlX R/Hks8mPnSNcZ7PIR7t3gYSs= X-Google-Smtp-Source: AGHT+IFf62eKmnb99Ql2AppSqUCSmIlUINfeJUej6wDmXORVXuCqVzerfj65VhA4qG+UvJbsOXX8ZQ== X-Received: by 2002:a5d:588b:0:b0:401:2cbf:ccad with SMTP id ffacd0b85a97d-40f65ac6671mr5939799f8f.17.1758892671942; Fri, 26 Sep 2025 06:17:51 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 05/24] semihosting/guestfd: compile once for system/user Date: Fri, 26 Sep 2025 14:17:24 +0100 Message-ID: <20250926131744.432185-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-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: 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: 1758892952422116600 From: Pierrick Bouvier We move relevant code to semihosting/arm-compat-semi.c, and add functions to query CONFIG_ARM_COMPATIBLE_SEMIHOSTING at runtime. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-4-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-7-alex.bennee@linaro.org> diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 3d426fedab3..a7ea1041ea0 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -35,13 +35,6 @@ typedef struct GuestFD { }; } GuestFD; =20 -/* - * For ARM semihosting, we have a separate structure for routing - * data for the console which is outside the guest fd address space. - */ -extern GuestFD console_in_gf; -extern GuestFD console_out_gf; - /** * alloc_guestfd: * diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index b03e6375787..231dc890395 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -33,6 +33,8 @@ typedef enum SemihostingTarget { * Return true if guest code is allowed to make semihosting calls. */ bool semihosting_enabled(bool is_user); +bool semihosting_arm_compatible(void); +void semihosting_arm_compatible_init(void); =20 SemihostingTarget semihosting_get_target(void); const char *semihosting_get_arg(int i); diff --git a/semihosting/arm-compat-semi-stub.c b/semihosting/arm-compat-se= mi-stub.c new file mode 100644 index 00000000000..bfa3681e267 --- /dev/null +++ b/semihosting/arm-compat-semi-stub.c @@ -0,0 +1,19 @@ +/* + * Stubs for platforms different from ARM + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "semihosting/semihost.h" +#include + +bool semihosting_arm_compatible(void) +{ + return false; +} + +void semihosting_arm_compatible_init(void) +{ + g_assert_not_reached(); +} diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 64ddc749bf8..a239cfc5a9d 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -101,6 +101,13 @@ static int gdb_open_modeflags[12] =3D { GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND, }; =20 +/* + * For ARM semihosting, we have a separate structure for routing + * data for the console which is outside the guest fd address space. + */ +static GuestFD console_in_gf; +static GuestFD console_out_gf; + #ifndef CONFIG_USER_ONLY =20 /** @@ -353,6 +360,25 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 +bool semihosting_arm_compatible(void) +{ + return true; +} + +void semihosting_arm_compatible_init(void) +{ + /* For ARM-compat, the console is in a separate namespace. */ + if (use_gdb_syscalls()) { + console_in_gf.type =3D GuestFDGDB; + console_in_gf.hostfd =3D 0; + console_out_gf.type =3D GuestFDGDB; + console_out_gf.hostfd =3D 2; + } else { + console_in_gf.type =3D GuestFDConsole; + console_out_gf.type =3D GuestFDConsole; + } +} + /* * Do a semihosting call. * diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index d3241434c51..e8f236c690c 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -12,35 +12,20 @@ #include "gdbstub/syscalls.h" #include "semihosting/semihost.h" #include "semihosting/guestfd.h" -#ifndef CONFIG_USER_ONLY -#include CONFIG_DEVICES -#endif =20 static GArray *guestfd_array; =20 -#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING -GuestFD console_in_gf; -GuestFD console_out_gf; -#endif - void qemu_semihosting_guestfd_init(void) { /* New entries zero-initialized, i.e. type GuestFDUnused */ guestfd_array =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); =20 -#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING - /* For ARM-compat, the console is in a separate namespace. */ - if (use_gdb_syscalls()) { - console_in_gf.type =3D GuestFDGDB; - console_in_gf.hostfd =3D 0; - console_out_gf.type =3D GuestFDGDB; - console_out_gf.hostfd =3D 2; - } else { - console_in_gf.type =3D GuestFDConsole; - console_out_gf.type =3D GuestFDConsole; + if (semihosting_arm_compatible()) { + semihosting_arm_compatible_init(); + return; } -#else - /* Otherwise, the stdio file descriptors apply. */ + + /* Out of ARM, the stdio file descriptors apply. */ guestfd_array =3D g_array_set_size(guestfd_array, 3); #ifndef CONFIG_USER_ONLY if (!use_gdb_syscalls()) { @@ -54,7 +39,6 @@ void qemu_semihosting_guestfd_init(void) associate_guestfd(0, 0); associate_guestfd(1, 1); associate_guestfd(2, 2); -#endif } =20 /* diff --git a/semihosting/meson.build b/semihosting/meson.build index 77200a7f27b..bb0db323937 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,17 +1,18 @@ -specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( - 'guestfd.c', -)) - common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c')) -user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files('user.c')) +user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( + 'user.c', + 'guestfd.c')) system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'config.c', 'console.c', + 'guestfd.c', 'uaccess.c', 'syscalls.c', ), if_false: files( 'stubs-system.c', )) +system_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_false: files('arm-compat-semi-stub.c')) =20 specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'], if_true: files('syscalls.c')) --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892858; cv=none; d=zohomail.com; s=zohoarc; b=P7j8oU323GacTtJCd+FF7a0VKP80tRcnb4Dwq6PQv3+uyj32YMqqW7LZM7mrDymAzqSao3wsdgojW3jbp/3U1GGfFOu6px/I5wZNU5pSKNQxI2eMsbYOlTYVm3e0UVIi6+OGRQ1xEfS/gFqV1qw2JqHPCGoZIUqI+U5b55HTjv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892858; 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=4syHx7WycSoo7WnKZYyvkr/pUQB2YZb4jxe+1NDk0fE=; b=FlSmL19/8d0jUFRyU2SUg+YHPwrX5th9ocy28bGn5+X6QENVgFYQr63ryDIzIMsiQGJLnVpfRjEzexJCNtcCiYyqEb7YfBDGwZhaG9jdLEFROEP/ViKYWE14nBh96Cs+0GIc7psh7wBy132JopicG27tTyoO8Gip7GFHfrgJv8k= 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 1758892858249653.315617572291; Fri, 26 Sep 2025 06:20:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LJ-000852-9S; Fri, 26 Sep 2025 09:18:34 -0400 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 1v28LH-00084D-7B for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:31 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kq-00042a-T4 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:30 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3b9edf4cf6cso2205256f8f.3 for ; Fri, 26 Sep 2025 06:17:53 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fb72facf9sm7271074f8f.13.2025.09.26.06.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:49 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 4B8A05F8CC; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892671; x=1759497471; 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=4syHx7WycSoo7WnKZYyvkr/pUQB2YZb4jxe+1NDk0fE=; b=vvl73zRYwYEDz7/mRsszBkHAzwiJTcfSd0bZU7w9R1y28oDepCz30IMlCWIaMIjSiZ QXGcVSQwzvcam0mtpdy4DjPyUbD0v+c4KmalR1Hf2sH3XvZAxVS5w9CjiyGRQ7hKoS8o hIn/q63IbQprq1NLY2F4BTjLbZUjW325+rEXwUqShRF1cZOexFrrOqdjHeN0mN1U7gLK Ll38fNFbZnRIeL3EQB/AboCzzIeYdW6CsFUBZFubsProJK+6/4n1PnpxhClj3xrInSxD FQXRmJAXEHZPt6mjnLEprwIDYknlossmj9Ln9mr4VGTPYw+8qJIJCmG/ASwLTrSgnLH1 ZlUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892671; x=1759497471; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4syHx7WycSoo7WnKZYyvkr/pUQB2YZb4jxe+1NDk0fE=; b=eG3sQUVux8zeSDgitbDBiYIV4qoB20W/1viUuIZ/oV5yBqYk3H57KkNbNHZ9LYzZsh Jw5wOP4SlfFd5BCXbw7i8R1mjRxnFgy1mgh4R6DEgDDZmqBOs/zB1HFEjMRw+gOn/cur oIU1zsW2qnEqAIgR3liUMimDUjtlQL+YB5uwVbuyli+Uo4g4aSgSwvAKJ68FUwauCW/j ctcqLq3w7wWWnq647ajb4pJl/hfzHV+eo7HMEfuqahObBBtaez9o/w4vpmVAnU3CymBO k0Z9zHAgEEIOzLDG7MmyJMBzbk0iGGiF1okjxDCBF6P1wJfLrghPUFVsZIkxZYu8QkEc 6vsQ== X-Gm-Message-State: AOJu0YyrmBjiyCii+O7xLBo6Wh+zxn7JP5++8bcDvVN3VmnCMh99y2XV Xhs+npnoMHzXnHI1VdEf8xKEO6uinNA4u52Hy8msVpartWZt9pgs30bJ5PbHbkftkZE= X-Gm-Gg: ASbGncsCUWMreiOTo1XJIJiSpoqLjl4CkykMz7zc5qOxmPB+Yoalkt4tpovWvEuKUtL NnNmeG5+lGS0OHEn114via1pnDonrxLQpe/NlW1rWsdtkecRV1JG+5GTmxYxi2Z6wam0G0Yo9pG FYQEYs9AqFrpKtebcZuxqnuVSeGy3cOWR4IAKX44TvpV2yXDLgsniDxlruMb2Tvbo3F3tluEc3h 7aG/Olr3tFHrxcWltRbt9UubbCbGoeiHE16Fh0IqKvI10qWxT6ITQ153wX+D2hNcVmbYCetMXsO +2YRFTIqxEAn26lsk1IM3p/08drEYhQI4u6UDkzbiU4vi5oJ0+AsqqukWLZGDYmZ4GHChbNsJLt lEgrelq163qsM2dlEemGUi4qm2n6nfs6s8g== X-Google-Smtp-Source: AGHT+IHIWvDWMEeOnpVGSAMiXZZvEjPIdCvG9uZGsrWeHnNvcf5VGzNOUzxY0gbZMID750/Fusuiqw== X-Received: by 2002:a05:6000:1887:b0:3dd:8b62:5fe7 with SMTP id ffacd0b85a97d-40e4ca79f1bmr5693777f8f.49.1758892671218; Fri, 26 Sep 2025 06:17:51 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , qemu-arm@nongnu.org (open list:ARM TCG CPUs), qemu-riscv@nongnu.org (open list:RISC-V TCG CPUs) Subject: [PULL 06/24] semihosting/arm-compat-semi: change common_semi_sys_exit_extended Date: Fri, 26 Sep 2025 14:17:25 +0100 Message-ID: <20250926131744.432185-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1758892859457116600 From: Pierrick Bouvier We now check only is sys_exit is extended. This allows to break dependency to TARGET_SYS_EXIT_EXTENDED which will not be available anymore from this code. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-5-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-8-alex.bennee@linaro.org> diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-targe= t.h index da51f2d7f54..7bb442f24ca 100644 --- a/target/arm/common-semi-target.h +++ b/target/arm/common-semi-target.h @@ -34,9 +34,9 @@ static inline void common_semi_set_ret(CPUState *cs, targ= et_ulong ret) } } =20 -static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +static inline bool common_semi_sys_exit_is_extended(CPUState *cs) { - return nr =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(cpu_env(cs)); + return is_a64(cpu_env(cs)); } =20 static inline bool is_64bit_semihosting(CPUArchState *env) diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-t= arget.h index 7c8a59e0cc3..ba40e794dcc 100644 --- a/target/riscv/common-semi-target.h +++ b/target/riscv/common-semi-target.h @@ -25,9 +25,9 @@ static inline void common_semi_set_ret(CPUState *cs, targ= et_ulong ret) env->gpr[xA0] =3D ret; } =20 -static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +static inline bool common_semi_sys_exit_is_extended(CPUState *cs) { - return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); + return sizeof(target_ulong) =3D=3D 8; } =20 static inline bool is_64bit_semihosting(CPUArchState *env) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index a239cfc5a9d..26263a06b7a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -755,7 +755,8 @@ void do_common_semihosting(CPUState *cs) { uint32_t ret; =20 - if (common_semi_sys_exit_extended(cs, nr)) { + if (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || + common_semi_sys_exit_is_extended(cs)) { /* * The A64 version of SYS_EXIT takes a parameter block, * so the application-exit type can return a subcode which --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892769; cv=none; d=zohomail.com; s=zohoarc; b=iy551dSbvkt3YI+3ZEwrJKVf4ZEpwfvoNTfSnmsOd1COYILqL5HAWqe7ZfXxVBXPiR03cmHAz0NQBOe4eIpari8AQPJPFcQnh0jV6KDrG1UtNl2FeR3zS7XTQW5zcuq+7oCiypGqu73IpncfHQnE9amNdACcXtpcR3hPH/D9US0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892769; 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=yhNLGhktRTwuqsOnekbBybX9Mdf7SCvwNPr0M3/Sc8c=; b=IoIcZDhxaiLC3t0oEgaajzXWMz99+9ZqZ1cuiZGtc/6O9ZfVe7KP3AwHdvDvDbaFpMo+s2mk9bFLslNbRmvGmJlSWZOsbZ7yEnEN54OUsqy+P+EGxJ6F65eyPfxc7NTL/YoqPm/kDxxYKR9rAt2lVaOf4dRw3NT8BTGJHotY9gA= 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 1758892769952725.8425828873877; Fri, 26 Sep 2025 06:19:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28L9-00080u-Bo; Fri, 26 Sep 2025 09:18:24 -0400 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 1v28L7-0007zG-9f for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:22 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kq-00043J-SP for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:18 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-46b7bf21fceso16253865e9.3 for ; Fri, 26 Sep 2025 06:17:56 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e2ab7d4e3sm116908845e9.23.2025.09.26.06.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:50 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 612FE5F8DB; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892675; x=1759497475; 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=yhNLGhktRTwuqsOnekbBybX9Mdf7SCvwNPr0M3/Sc8c=; b=T4BGZEoW5Z17l/kyyV2UU0dUAjbRp8njVLTJW10Twa5thbvHQwfv6TKlzOgn7MMjUO 9IfAOnkcJj3j/KmQlYEYrDj9Mmt4tAs0trWtpkKj7qq3tL7zwwpOS9A+nZpNM59GR70+ iMk334vNQY4CFobiJnxBDkSiJHiZtwgjPH0ysmRYYsts4ZtrQ9+auwAykh5UXYISEujp oUZPOzmRlW8jiD5GFpov/Xz9QBT9dXVragPkShk7mVHtr1KexJaeuoHa4Q84t3NAydwr FKO3b7T0LMXSIjvVaCdB8op+MwK4iyVsacxelAUU6t0VtwlQ/Xzum2RKafQrmXRCOuPH lv8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892675; x=1759497475; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yhNLGhktRTwuqsOnekbBybX9Mdf7SCvwNPr0M3/Sc8c=; b=UEDVHihUU8xHOZJ291lEVc9yelfEROlIul3KzZBvE72KH1iVxJTbIisrT2Z4/SD2Io CByqmQV2CsKSxwz1IqPD8giD7teio6aEpfFRXjZN8id5LKVKar62FQmtAvf8jVywD0Y+ g7WRTyTo+WU17U0tloxb9HSOfvvXyhgMaFigjpil4wdDyG8HapINE86bPjC30ZjCrRMZ aA7PrfgkRCLCuEXRwlOvzeWqPvZAMgasuzS0AfEIMPWuP2qhV3COkvBksmD0Ep5UjUCC hnY+X5ys5SiGcD69x1dkrEPLfiVYwDzPVgwXBhS4sxw5zXIsF5bsEGhnKkuCW6muVIOC BaYg== X-Gm-Message-State: AOJu0YyCNyYTVo1E39DluS/hUyjg/zX0Rfb7eB8qq48zo2p/lk1IUClY M4YoRrWrf07+E/tRIXxAsOKUNZam9Fee2GNFpGfFdR4Nevs7dQu1uVEAHjFkKrw9IzA= X-Gm-Gg: ASbGncv2YVyeS+QyFBD9EXXVM0966Hw+VO1UgDC5eAgad5EcjIvKYpKjo6tVO+ZPIDG JBlrL2hI8VrWoI7Ibf0gGKCmjb4x6lv9omIxkteTW3LipPoMHn48lkYDV7wYR9AS9BuV+W5ty/2 CddZRutjUeJOoQK22OsEitODpwIVuJ3ipdQB3ldLDDeOy0qhsQL4HP5h677kVvMtGEUr3UoePkX q1VsT1vMxwNEHzT+eiFYwfczOOnfkyLvktmCFgYkup4ZAtC30N3KIdW+Ynw5t8hl+zDZ/nEOmra 1RezbXtuXHHutgfqFQ388r0AY1YAt27Kn6fBSeRoQFNbagB5bzHojAAnoEe/EIPTX5Ncga/5M+A w/NZr4+Wo24ym98dwWtBcHgw= X-Google-Smtp-Source: AGHT+IFOZ23h9C8Z9aOz2rcj7V/Zo5VGnV0+DO934XKhH8P+DB7c1tiq9zdkb0vmfxc3rVroUPII9w== X-Received: by 2002:a05:600c:8b16:b0:468:7f92:5a80 with SMTP id 5b1f17b1804b1-46e329fbd2bmr55052325e9.27.1758892674712; Fri, 26 Sep 2025 06:17:54 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , qemu-riscv@nongnu.org (open list:RISC-V TCG CPUs) Subject: [PULL 07/24] target/riscv/common-semi-target: remove sizeof(target_ulong) Date: Fri, 26 Sep 2025 14:17:26 +0100 Message-ID: <20250926131744.432185-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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: 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: 1758892772679116600 From: Pierrick Bouvier Only riscv64 extends SYS_EXIT, similar to aarch64. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-6-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-9-alex.bennee@linaro.org> diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-t= arget.h index ba40e794dcc..7e6ea8da02c 100644 --- a/target/riscv/common-semi-target.h +++ b/target/riscv/common-semi-target.h @@ -25,14 +25,14 @@ static inline void common_semi_set_ret(CPUState *cs, ta= rget_ulong ret) env->gpr[xA0] =3D ret; } =20 -static inline bool common_semi_sys_exit_is_extended(CPUState *cs) +static inline bool is_64bit_semihosting(CPUArchState *env) { - return sizeof(target_ulong) =3D=3D 8; + return riscv_cpu_mxl(env) !=3D MXL_RV32; } =20 -static inline bool is_64bit_semihosting(CPUArchState *env) +static inline bool common_semi_sys_exit_is_extended(CPUState *cs) { - return riscv_cpu_mxl(env) !=3D MXL_RV32; + return is_64bit_semihosting(cpu_env(cs)); } =20 static inline target_ulong common_semi_stack_bottom(CPUState *cs) --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892831; cv=none; d=zohomail.com; s=zohoarc; b=gZ6s7ETlwDjSIqOp0KY0+3jM3n96LAURu76rSJG0HUNveUDZznkQkfCeJNiENhOgtFHMetpgRSksgZQOa7jedkh9uBVvjQcWaomm+Z+RrmdVPai5S10R7uLMx6uFTGEXiltfYch8ZcPkwS8+4rMNn+pbHW/EkZfsBNKcewqz34s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892831; 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=y9d5BP7lns2PVAN5IYXcTxZLAWv4Unp9pZLQ6Ob5dbg=; b=Iu+Sb1Rn/9N53bJ6/sREoRVyZagxnC9voeo1WtdXNw30eiRQy6zoazU7Vo3t3k/9ZasyjR6f9FhuhO7e81lrctMJpJZEmBi1rNWJMRp2L2wgjFaJgn5/HStT60ffUsnRzaUy/RsOCukPLARt5uWAX4d5UqL7YLASt26B2Q11zww= 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 1758892831831745.1644890337939; Fri, 26 Sep 2025 06:20:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LJ-000853-9K; Fri, 26 Sep 2025 09:18:33 -0400 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 1v28LI-000848-4S for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:32 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kt-00043k-Jf for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:30 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-46d25f99d5aso23702625e9.0 for ; Fri, 26 Sep 2025 06:17:59 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e42eee0b6sm6427805e9.10.2025.09.26.06.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:50 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 7AE815F8E0; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892675; x=1759497475; 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=y9d5BP7lns2PVAN5IYXcTxZLAWv4Unp9pZLQ6Ob5dbg=; b=GvPqvqB/XYroVM2t8MrPtskvvOuBWoxgdagWqynvJda85yH2R0nSo30CN0WMTeAjuo MKf8sOYJW1C5PF3+gfuDtWUgHs4TZhlN4ly/ctVxKlYLGKVj7SwNkiQ4WFZ/rIS6bW7K 1o84C0d1eqd+yf79Ko6lcVtR+m0MyRR9RcDnvhnKUljqn4/oek9x4Xy5jhkKcxns4YcO ImB4dkhMuNL6Gxer6G8adLT+I8Fha7k+1C3Z73wp8bzlkQ1lJnd32+5WCSZDhTK/CICd 0CGAe31140PkUF7zX+cxtYFG4VjJgczuiAItkM/p8A4VXeYX08+k2X1dnMu0GnP7rfNJ Btdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892676; x=1759497476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y9d5BP7lns2PVAN5IYXcTxZLAWv4Unp9pZLQ6Ob5dbg=; b=I8wHwffYlgF7hSQF8KLWSD0/xMPBBptodEugrPVwwnGXKdigWgCvwFhuG/t8S1UYO6 gLbO7o7RNxf8gKa3biAjsi/vnRddf76TUxmuWB9hydoYMZao92plOwYcLUJu9yOjK7x8 yoZrg5TaJDFRO6DAiOoBFdnQu7M8WrLadr3f+dYgBMLd35aeYlrVN/Cyxae6VFVVYYER /FV2Dm5Yb0K3jPmIgoPY3kxM2UyOkw0V4fsg45yPWyTPjAxjbtCeJK9YK7W6gvAXHWn6 4F2vUO7MAShouaNngmHusecw4aqylo4QYbdpptRs2Zej0TSE1BDWzOvnqxVWa2KOzDpg eG9Q== X-Gm-Message-State: AOJu0Yx1Ky3NcMXqjWStV/xBlRRDOCy8XU34XRqK0AsgvOcm7B9iC/yn S9a5gxvsifyBFOzKzLP5XEEVDYcW/FVaqE0ZYpIi49NGW7BSHcETQawuTElarH1rgiI= X-Gm-Gg: ASbGnctKDuhNkHDnFsaT8xZAXBd5gU7xvfk5MpvsPGHaHL1RdqKN4td6jYXsEL7IJpd d+plz3Ynl1haUjCWnnTIexe3/kRgCcdFRBlDtcnbspaXbXHiVfNEI2Ve/GNgqK50cfEUlMWA4Rx oQQNLY6vykX32xGZgvleHe5cxxG8ayJGfUM9lSAHsAQ9V0X06ROmGKr6shCMYa1rv0ch8wlmOYG rkcaGcTj9pGY41PUzy/hPl5kUO4EnfdGPyK+qHVf3pXsZAO+uqAHYXnn/mECfDkXE7bhhoZlUnB hXd2JNXdKSAFrzDR+jj5eDU+PN9DH2UAErcLvzEyJKuMgBc+IwwJZr0gWW994Xax9CqEWTwGYK7 uCCpNX2c6Q1CqTWsI4P/MbXM= X-Google-Smtp-Source: AGHT+IFwNCoKqYkvjcluvDzTRuZ7pHZpM0OcM0pWV5vpgzZePXa2ycPhSZfvL+o2DIY995dN+bIoBQ== X-Received: by 2002:a05:600c:8b23:b0:458:b8b0:6338 with SMTP id 5b1f17b1804b1-46e33c4bd45mr75387065e9.6.1758892675569; Fri, 26 Sep 2025 06:17:55 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , qemu-arm@nongnu.org (open list:ARM TCG CPUs), qemu-riscv@nongnu.org (open list:RISC-V TCG CPUs) Subject: [PULL 08/24] target/{arm, riscv}/common-semi-target: eradicate target_ulong Date: Fri, 26 Sep 2025 14:17:27 +0100 Message-ID: <20250926131744.432185-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1758892832715116600 From: Pierrick Bouvier We replace mechanically with uint64_t. There is no semantic change, and allows us to extract a proper API from this set of functions. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-7-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-10-alex.bennee@linaro.org> diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-targe= t.h index 7bb442f24ca..6775a270aaa 100644 --- a/target/arm/common-semi-target.h +++ b/target/arm/common-semi-target.h @@ -12,7 +12,7 @@ =20 #include "target/arm/cpu-qom.h" =20 -static inline target_ulong common_semi_arg(CPUState *cs, int argno) +static inline uint64_t common_semi_arg(CPUState *cs, int argno) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; @@ -23,7 +23,7 @@ static inline target_ulong common_semi_arg(CPUState *cs, = int argno) } } =20 -static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +static inline void common_semi_set_ret(CPUState *cs, uint64_t ret) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; @@ -44,7 +44,7 @@ static inline bool is_64bit_semihosting(CPUArchState *env) return is_a64(env); } =20 -static inline target_ulong common_semi_stack_bottom(CPUState *cs) +static inline uint64_t common_semi_stack_bottom(CPUState *cs) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-t= arget.h index 7e6ea8da02c..663dedfdad2 100644 --- a/target/riscv/common-semi-target.h +++ b/target/riscv/common-semi-target.h @@ -11,14 +11,14 @@ #ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H #define TARGET_RISCV_COMMON_SEMI_TARGET_H =20 -static inline target_ulong common_semi_arg(CPUState *cs, int argno) +static inline uint64_t common_semi_arg(CPUState *cs, int argno) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; return env->gpr[xA0 + argno]; } =20 -static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +static inline void common_semi_set_ret(CPUState *cs, uint64_t ret) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; @@ -35,7 +35,7 @@ static inline bool common_semi_sys_exit_is_extended(CPUSt= ate *cs) return is_64bit_semihosting(cpu_env(cs)); } =20 -static inline target_ulong common_semi_stack_bottom(CPUState *cs) +static inline uint64_t common_semi_stack_bottom(CPUState *cs) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892771; cv=none; d=zohomail.com; s=zohoarc; b=Ft7VZR2OLPip1tSxwJCil8hcgPRJroxIuJCjlaK3cZ92eMhCpholFpU6/xVUlHSzXdXcaY22LzmrTRQKLAIKDL+GBuNbNHNHUjP8YHSgy6BOQsWpUBQkO8nxhrwKkRyhXdQBORz5JH/RiUAhzwqYrWjIRz73TvAEMETBIGyDQ9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892771; 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=BCG2zxRVNMR8qqgQNrkRM3H2KV89pqEU/0Kxiz6SNGs=; b=c2X6wn5TCebw8iQ8S6funOywj4c4NE5JD7VVFDq1ccpVnkn3qA7jZKnN7TMZ9s0JUDksmpxGrfYvu89IqHM0mf1FixKFfieGlnxbSdS2TLvqH07Qf59UEfdMdKxdjDclX6DxEhrYfb6XrC6Md2m8kfexldbA0OPFINmoUEhaN70= 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 1758892771226353.2116455654565; Fri, 26 Sep 2025 06:19:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28L8-0007za-0T; Fri, 26 Sep 2025 09:18:22 -0400 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 1v28L5-0007yW-FH for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:19 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kq-000434-T4 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:19 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-46b303f755aso19540635e9.1 for ; Fri, 26 Sep 2025 06:17:56 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e2ab6a514sm116613485e9.22.2025.09.26.06.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:50 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 978365F8EB; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892673; x=1759497473; 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=BCG2zxRVNMR8qqgQNrkRM3H2KV89pqEU/0Kxiz6SNGs=; b=inb/EeDT92NDyOMLU3aCyMLXqU4mrNmN5/I67o7dI2JgVfpXA/ilfFqObJpfz9keyF jJhMqOOjJt3IfOAneWT/CkzsyMTgeqaSzeRoBLQ8APixnYHHKktGqXgAsiy+xGkC/bI5 m57UdZ6AGIItfivCYLu1CQXGDvTOKrPt5Ew1stDywniAnCSbkgLCtKVAdFnfA8826PyA wfklX0FmS8vFNYJN+bZ/Q5+bEjS/nz6DK9MIFeD34BHkjgjnG6YeQx0H3L5Er9UX5k2C db91ZuwjKV6uMyxEpLKVu/pwOdeaJYTGAky6ZIowVErKIJ+JxdeyikF72wTlavYbmh9G 4y/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892673; x=1759497473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BCG2zxRVNMR8qqgQNrkRM3H2KV89pqEU/0Kxiz6SNGs=; b=khjVuCa6xnO2tPNjjp0XcSqG8RJyAoNSr1yOBc2verOXeuLfmKELndfYyZopjcMufb wWKptNtaiI6kVyYQUcKliXxKvdZLJjg7wZ2959HShPUqwQ34AlcQy7Xz7n4DKYxDkyDS FZogjmUB93djQkAQaXV5OYmu0Iok8pxxFrSOG61H8SvBIbBLqJ2kstpdnVEBvT7HeZZC vL9wThnXUw0f2ccYLqXL+UgWzu9oK5fCfdXJvupFA54Q4D2t2yd061HtPUrT5iRF6cVq 6DIqgfzz7lJBRrI4cGma+7IGmOE2cZ7zE65Liyniu3tp5ez6P8GfynO15EdYGtJgmNHs Dq4w== X-Gm-Message-State: AOJu0Yw+HNpe2mezh7EfhUOj6x/ZFs2i6FauIv9CvaKOHNV5N9pdsSf4 QV+PQUCgFuCmI/xXoBMmhO2ODtB8sypjT0E5OFeYVQk35mxP8y9G9KlwWuwzNy46uO0= X-Gm-Gg: ASbGncvIDh4+8irzh9gnDBy9VSWraVKTnlhI8BMSrhkBM1Y50oJHjuysAxN69QF6StV eVqOyNbwvKLIqTZzqYNeYZuxBvtt7754n5JmhXubOLBo7ZVjcShpv6jYaQDdqzd8gEtY3lEe03D aujcYj1w/7wJHIbz4auh5ysdv1Mi985+CQTruE19Fv5BVvYEROBcD+0Qdf86h3GOyvTksqxLoto YmoMVTFKG/j/ZU6q5j3PR0Q+LLWrPxXCsv+SP749xnKiSxeRhCdy3OKTFOKAJwuX0lxZjKb6pnu AAunbbx+S4mFbIr5OinTrTWoCBtWWaIPB1WYcBnL6kQehdCfFoAD9qKn0t7LDakZQk94rYGAH0D W1hDXk6VvaHKjMxqDGz2pAe23K4emkvEWPw== X-Google-Smtp-Source: AGHT+IG/Z1CHmcnC8V6yiUjrh3LW698deD/3AqWNec9++O4aXrTGEA3ZBTGgV9oR3Qr4oAlOKRfbiA== X-Received: by 2002:a05:600c:8b16:b0:45f:2bc1:22d0 with SMTP id 5b1f17b1804b1-46e32aff787mr71284645e9.33.1758892673208; Fri, 26 Sep 2025 06:17:53 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , qemu-arm@nongnu.org (open list:ARM TCG CPUs), qemu-riscv@nongnu.org (open list:RISC-V TCG CPUs) Subject: [PULL 09/24] include/semihosting/common-semi: extract common_semi API Date: Fri, 26 Sep 2025 14:17:28 +0100 Message-ID: <20250926131744.432185-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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: 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: 1758892772821116600 From: Pierrick Bouvier We transform target/{arm,riscv}/common-semi-target.h headers to proper compilation units, and use them in arm-compat-semi.c. This way, we can include only the declaration header (which is target agnostic), and selectively link the appropriate implementation based on current target. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-8-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-11-alex.bennee@linaro.org> diff --git a/include/semihosting/common-semi.h b/include/semihosting/common= -semi.h index 0a91db7c414..aa511a46f42 100644 --- a/include/semihosting/common-semi.h +++ b/include/semihosting/common-semi.h @@ -35,5 +35,11 @@ #define COMMON_SEMI_H =20 void do_common_semihosting(CPUState *cs); +uint64_t common_semi_arg(CPUState *cs, int argno); +void common_semi_set_ret(CPUState *cs, uint64_t ret); +bool is_64bit_semihosting(CPUArchState *env); +bool common_semi_sys_exit_is_extended(CPUState *cs); +uint64_t common_semi_stack_bottom(CPUState *cs); +bool common_semi_has_synccache(CPUArchState *env); =20 #endif /* COMMON_SEMI_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 26263a06b7a..604a69e3646 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -174,8 +174,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) =20 #endif =20 -#include "cpu.h" -#include "common-semi-target.h" +#include "semihosting/common-semi.h" =20 /* * Read the input value from the argument block; fail the semihosting diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-targe= t.c similarity index 64% rename from target/arm/common-semi-target.h rename to target/arm/common-semi-target.c index 6775a270aaa..2b77ce9c17b 100644 --- a/target/arm/common-semi-target.h +++ b/target/arm/common-semi-target.c @@ -7,12 +7,12 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 -#ifndef TARGET_ARM_COMMON_SEMI_TARGET_H -#define TARGET_ARM_COMMON_SEMI_TARGET_H - +#include "qemu/osdep.h" +#include "cpu.h" +#include "semihosting/common-semi.h" #include "target/arm/cpu-qom.h" =20 -static inline uint64_t common_semi_arg(CPUState *cs, int argno) +uint64_t common_semi_arg(CPUState *cs, int argno) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; @@ -23,7 +23,7 @@ static inline uint64_t common_semi_arg(CPUState *cs, int = argno) } } =20 -static inline void common_semi_set_ret(CPUState *cs, uint64_t ret) +void common_semi_set_ret(CPUState *cs, uint64_t ret) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; @@ -34,27 +34,25 @@ static inline void common_semi_set_ret(CPUState *cs, ui= nt64_t ret) } } =20 -static inline bool common_semi_sys_exit_is_extended(CPUState *cs) +bool common_semi_sys_exit_is_extended(CPUState *cs) { return is_a64(cpu_env(cs)); } =20 -static inline bool is_64bit_semihosting(CPUArchState *env) +bool is_64bit_semihosting(CPUArchState *env) { return is_a64(env); } =20 -static inline uint64_t common_semi_stack_bottom(CPUState *cs) +uint64_t common_semi_stack_bottom(CPUState *cs) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; return is_a64(env) ? env->xregs[31] : env->regs[13]; } =20 -static inline bool common_semi_has_synccache(CPUArchState *env) +bool common_semi_has_synccache(CPUArchState *env) { /* Ok for A64, invalid for A32/T32 */ return is_a64(env); } - -#endif diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-t= arget.c similarity index 59% rename from target/riscv/common-semi-target.h rename to target/riscv/common-semi-target.c index 663dedfdad2..aeaeb88d536 100644 --- a/target/riscv/common-semi-target.h +++ b/target/riscv/common-semi-target.c @@ -8,43 +8,42 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 -#ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H -#define TARGET_RISCV_COMMON_SEMI_TARGET_H +#include "qemu/osdep.h" +#include "cpu.h" +#include "semihosting/common-semi.h" =20 -static inline uint64_t common_semi_arg(CPUState *cs, int argno) +uint64_t common_semi_arg(CPUState *cs, int argno) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; return env->gpr[xA0 + argno]; } =20 -static inline void common_semi_set_ret(CPUState *cs, uint64_t ret) +void common_semi_set_ret(CPUState *cs, uint64_t ret) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; env->gpr[xA0] =3D ret; } =20 -static inline bool is_64bit_semihosting(CPUArchState *env) +bool is_64bit_semihosting(CPUArchState *env) { return riscv_cpu_mxl(env) !=3D MXL_RV32; } =20 -static inline bool common_semi_sys_exit_is_extended(CPUState *cs) +bool common_semi_sys_exit_is_extended(CPUState *cs) { return is_64bit_semihosting(cpu_env(cs)); } =20 -static inline uint64_t common_semi_stack_bottom(CPUState *cs) +uint64_t common_semi_stack_bottom(CPUState *cs) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; return env->gpr[xSP]; } =20 -static inline bool common_semi_has_synccache(CPUArchState *env) +bool common_semi_has_synccache(CPUArchState *env) { return true; } - -#endif diff --git a/target/arm/meson.build b/target/arm/meson.build index 914f1498fc5..638ee62525f 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -28,12 +28,16 @@ arm_user_ss.add(files( 'vfp_fpscr.c', 'el2-stubs.c', )) +arm_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_true: files('common-semi-target.c')) =20 arm_common_system_ss.add(files('cpu.c')) arm_common_system_ss.add(when: 'TARGET_AARCH64', if_false: files( 'cpu32-stubs.c')) arm_common_system_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) arm_common_system_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c')) +arm_common_system_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_true: files('common-semi-target.c')) arm_common_system_ss.add(files( 'arch_dump.c', 'arm-powerctl.c', diff --git a/target/riscv/meson.build b/target/riscv/meson.build index a4bd61e52a9..fdefe88ccdd 100644 --- a/target/riscv/meson.build +++ b/target/riscv/meson.build @@ -8,6 +8,10 @@ gen =3D [ =20 riscv_ss =3D ss.source_set() riscv_ss.add(gen) + +riscv_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_true: files('common-semi-target.c')) + riscv_ss.add(files( 'cpu.c', 'cpu_helper.c', --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893204; cv=none; d=zohomail.com; s=zohoarc; b=nIU0OfT3LEqjsAXP+jGqAk9fe6PlZxHbulHc9XoSCHrZBrYaZqsCGEwftM9yLE2h7/6Qv4ffe85oEQ5M6s/Ya2/AUaMf6J8/sU0w4xrEkSULKBH0AzNCFh6LgTijQVj7wWAlW3J4wwYDRS+TTFITdjE6g/KH3oWezHVeKYqwwUw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893204; 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=CoI6XSX4wJl5SW+3P8A8AhUt3YnoxIhpzdTpS8zDmoo=; b=LP4K68zZMrxxBWDj2cvsFoGLmh4JaOYEPLYHk96LvbBkkWem5mvzaqkjo27OyN8hUnpc05RI9LimKv8OlCKV9CC47Y+E3alGX/4IfTq0yYknteRs8i0l0Txz4etkm/sa/lnxEo8TLb9l55ZydIyeEio31wf25TQUHJEI2yNd3PU= 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 1758893204149726.8600183203295; Fri, 26 Sep 2025 06:26:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LW-0008BL-9u; Fri, 26 Sep 2025 09:18:46 -0400 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 1v28LQ-00087h-27 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:40 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kw-000437-18 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:38 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-46cf7bbfda8so11868725e9.2 for ; Fri, 26 Sep 2025 06:18:00 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e33baa53dsm73737465e9.6.2025.09.26.06.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:50 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id AE71B5F8EF; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892674; x=1759497474; 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=CoI6XSX4wJl5SW+3P8A8AhUt3YnoxIhpzdTpS8zDmoo=; b=UqC1xK0xVkKhyTcCmj9AEiOSrGZKx8P35MFnAx2YoMaAzaAcinbmIUSCcqd9b7Z1sg ir94kuOkdESRsOmTmobMjLI9qK7m32Ue4f5a2E65FBPl4Tm8rYKDBGwSc1z1IAI6h8dX 6NS8ILzxWhtFrv0KZv6Jjh9phNCdd69frTA9Vm1iD+dRxcEvEjDhVhR34Wr2Hx909Fuu s/1HACXlosQjWjV+n8eWVEhzosRiEVt82HdxQVu0+mN/rbkgOG6v4XceIkosH7qj68Zy mj2ajxx7Z/P6+Eb6grwrywLIQAs/BVvgNW+ufi+hPEoji4GEr2m5uHMSlVkU3PsdEcbk 7Mhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892674; x=1759497474; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CoI6XSX4wJl5SW+3P8A8AhUt3YnoxIhpzdTpS8zDmoo=; b=tMH4OVQCdoWLmUTLPn7WSooiiliSn+ZtPOGe9IDeqph+wmaGmssv2UihhBckqLfIWi uQsDtfvE090Uz8uAt3aYqQy1uXx5OfHoVp4FgYFiYkNEN8IUJwyaLAIrC7n424lnYGpG CWyibqA6dvhHN/Gc9kafQ9sVqhRPIE2mRGHC3FrSZGJS+qqrBDpSteIEH0aWSjhRRHmK eX728JWApeVny1S2K8988m8X5HQ0t7/Pr1cDPOYdCXvkwrFemzkwE+FjL+xe6hnfbUQm dVAZbeUvvh0vpQAgT9bZ6zQk9xkcq/wKkd8f6veGq23ghB5z1IRx1DlP+gdHWen1EMSf 4XZg== X-Gm-Message-State: AOJu0YyHz75X0cg3FgGWod/P9f9tDX54s0tQZIidARhxO2MWg+ATfmz6 8NQz7E93NR7dIXlv0ZJ7vwSXy+jpb0V6nZ7OnlInEdeaizNXC1tUdAmXu0hlK/g6HbQ= X-Gm-Gg: ASbGncuiqAIrev7vUXOdTuL4gVI6e2ef+nBsxZTxY3pYKTgnq3W8SpX9EKZnvrWWwnd CDsfgDkbQBYD4J78AEJrJwdxbue6qnXFVJx80XEo6Wv+Fge8tN4lmp+8QJt1+95b2oirPeXkryp hDORHCpeIqgei92Wkg41MfU6vvuqWhzRKT/DaDMWGWk2egEO8DhhZTCvAz7Z6eHw8m+XYNx8Zl7 cV02Z+6bS+r+LUkCALEq8HT8DZS0uTEwNtOTX+E+SvphVx82OLoVmvrhUfQFDM3BjDNIucP/54x MWvkIH8bwfL15UW2Vq4XYsAhmKo3JLm1voteLelEMBnD5M5N6umJplUc/IXTtN9dGLPRWiXtaBu qi3AvW9baftW3WmfJYeHfWIs+TzsxEJrbuw== X-Google-Smtp-Source: AGHT+IF2tsE8C2j/Wkx4xevHOulu52oXeCpOX1K+U9LFkJikKwt/mlcTISonkAJJCXlnDj0Nav/uRw== X-Received: by 2002:a05:600c:3f12:b0:46e:41e6:28c7 with SMTP id 5b1f17b1804b1-46e41e6293fmr18245475e9.8.1758892673943; Fri, 26 Sep 2025 06:17:53 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 10/24] semihosting/arm-compat-semi: eradicate sizeof(target_ulong) Date: Fri, 26 Sep 2025 14:17:29 +0100 Message-ID: <20250926131744.432185-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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: 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: 1758893205837116600 From: Pierrick Bouvier No semantic change. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-9-pierrick.bouvier@linaro.org> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-12-alex.bennee@linaro.org> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 604a69e3646..6725dcf4ba7 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -786,7 +786,7 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_ELAPSED: elapsed =3D get_clock() - clock_start; - if (sizeof(target_ulong) =3D=3D 8) { + if (is_64bit_semihosting(env)) { if (SET_ARG(0, elapsed)) { goto do_fault; } --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893026; cv=none; d=zohomail.com; s=zohoarc; b=hZ2AP8nIwsNdhAwG3UWMCt5W5EJfxkPMUvAXhXG6Yk4YMTIH24S/9JzeNs4VoKInY5POoDyZ1zKXfFB3mgrGujqLUpgPU/2EW0Yr+lty8XE9tg4pPjaQ++NqDcOYs2H/gbfyyjviljf/oZ6lxN8JcMu4TQQ3gtHPw72JdOjGURg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893026; 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=g/wqUDizy/NPKiHOFvPLPI/kIFdDzcoQO4p7ilmmc2A=; b=le+96i8k2+ZrQxP5AxFEXu2yhkV1+neg3OAz36Z5MeQUou5UO2ZST5ORCIu95oOZM7FLBjG9OQpApk5Ga7yNNZBiQRI0MygU5Yl9bfxtTn9HlTqKX9mKUU+9Z8mWgI6LrzsEVXGSIKYrpa+aeqCzTHJ8zevOTIQey57/6hhm4JA= 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 1758893026510449.7568339633309; Fri, 26 Sep 2025 06:23:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Lf-0008Ep-Eg; Fri, 26 Sep 2025 09:18:56 -0400 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 1v28Ld-0008EN-7z for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:53 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kw-00043r-17 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:52 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-46e37d10f3eso13265515e9.0 for ; Fri, 26 Sep 2025 06:17:59 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fb9e1bd14sm7371958f8f.28.2025.09.26.06.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C8CCB5F910; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892677; x=1759497477; 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=g/wqUDizy/NPKiHOFvPLPI/kIFdDzcoQO4p7ilmmc2A=; b=se1QDSdqYGcDisCrCL9JL9hexJNcB32m70iRujILgiQKjs46g8Ro6+LLq1E9g+EoMj Ox42oZyOpOnoxJSNKT8ZIzCEwP2jpsjPYvhYyUhepQJ4FkToe6wO3V3jQ/V5ALXSTQgo G/TxqUyMRXs2MWgKgyjWMIHy3nBRvYruKmC55ylKBi/R/0yjrumh/u8YcCLVMwaXZ4rl BPBE7nDl5sP+Ih30nJ37/uyB32JbJOWUnCMG6flQwZjes4fIoWcsW0klVBNhCN/8QdWi 5dFlfw6MQUEFtTuIvxTlUARYEw/n7EEd6NQb8noD2AoX1aU7LuN8Mdua9vKvjqy0ouPC kQKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892677; x=1759497477; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g/wqUDizy/NPKiHOFvPLPI/kIFdDzcoQO4p7ilmmc2A=; b=KNp3OEqhPjNsprkRUB+sw7N5E7j67hAXohScKQd3ql27hVP4ZQ8Hzty8KFvVlwnW4J FstVkpVn/2wcK0Cd7RGBY9OUh/tGj6CGLZJK6vo0o1OyXLsIwuOA9eZecODQmUz6eKtM 5ibGnMvN+HqBloBe6W2iTNaRM/wl4zYj0F8MtMgp5McAJAK87Os/DOk9ZgSpGpujAKk2 ifQu5LWWNZkpKnhmyqnSnViPI1MklwUP9boZ0OKehbeHsPa+eCMWfS/qY8QWeNTUKW7w jVMFiRWmQa06ApVVDlNAqHuGlTHQRHqqFYiJ16paU9OzAqc50VI8+3cKNGlfZHGNWUCJ VNVg== X-Gm-Message-State: AOJu0YxsbzFyxe2ose8sSLpDiEhD010vYzwAzOS9tLESlwc98GytXjdM Kn90Rpq9XXuBlp5r8BubOU1uUdNWzQqbm+M/SF7bZyI4muLo5plTfirzmGOxtokWSD0= X-Gm-Gg: ASbGncumFJbNrLjL68DRwIBm9dD9tn9NYTqME7bFavm82RObdNw5ZKqES8GALi96oCP Bvy3Vy7q1JgK71l1SnvIw0Udc/gVHVj66QRrAFe0Tpz4e8GxNC4ZA1AkJR/Jx9Q6gbkGL2Djs3J l1zuGqEQNBadigK7Vj/7TRDtIIkxoI/cIQ9GlfYE/obfjntnSfvRulV8eTabBrDKiaNQSvTS3k9 06DjELE2fKLWeVpoAzkuFKPj6FRERVUIwkEvV6kw/1Sa+6fuRlKlM1q6DN5/lLUE6/I1/LEQouD YZqVLTic6mXfppyXD3Cemqnx5giBiwU7C2BQEdaEMMTQOtBzqOdNjgXNs/vLeMDtRWD1ZK9GhzK Mlu/1epafEM3HJQ2F6L3xnOU= X-Google-Smtp-Source: AGHT+IEoyHkdMfK1FRJOTXJvPf43Jy2hYNLPEhhHi572lzLKYHFg7hPb/WfAZ/SwMOSpOVplD8VUGg== X-Received: by 2002:a05:600c:4ec6:b0:46c:7097:6363 with SMTP id 5b1f17b1804b1-46e329b441cmr64975835e9.13.1758892676415; Fri, 26 Sep 2025 06:17:56 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 11/24] semihosting/arm-compat-semi: replace target_ulong Date: Fri, 26 Sep 2025 14:17:30 +0100 Message-ID: <20250926131744.432185-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32e; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32e.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, T_SPF_TEMPERROR=0.01 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: 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: 1758893027344116600 From: Pierrick Bouvier Replace with vaddr or uint64_t where appropriate. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-10-pierrick.bouvier@linaro.org> [AJB: tweak commit message] Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-13-alex.bennee@linaro.org> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 6725dcf4ba7..29cdab66f73 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -123,7 +123,7 @@ static GuestFD console_out_gf; */ =20 typedef struct LayoutInfo { - target_ulong rambase; + vaddr rambase; size_t ramsize; hwaddr heapbase; hwaddr heaplimit; @@ -214,7 +214,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) * global, and we assume that the guest takes care of avoiding any races. */ #ifndef CONFIG_USER_ONLY -static target_ulong syscall_err; +static uint64_t syscall_err; =20 #include "semihosting/uaccess.h" #endif @@ -260,8 +260,8 @@ static void common_semi_rw_cb(CPUState *cs, uint64_t re= t, int err) { /* Recover the original length from the third argument. */ CPUArchState *env G_GNUC_UNUSED =3D cpu_env(cs); - target_ulong args =3D common_semi_arg(cs, 1); - target_ulong arg2; + uint64_t args =3D common_semi_arg(cs, 1); + uint64_t arg2; GET_ARG(2); =20 if (err) { @@ -300,9 +300,9 @@ static void common_semi_seek_cb(CPUState *cs, uint64_t = ret, int err) * is defined by GDB's remote protocol and is not target-specific.) * We put this on the guest's stack just below SP. */ -static target_ulong common_semi_flen_buf(CPUState *cs) +static uint64_t common_semi_flen_buf(CPUState *cs) { - target_ulong sp =3D common_semi_stack_bottom(cs); + vaddr sp =3D common_semi_stack_bottom(cs); return sp - 64; } =20 @@ -389,9 +389,9 @@ void semihosting_arm_compatible_init(void) void do_common_semihosting(CPUState *cs) { CPUArchState *env =3D cpu_env(cs); - target_ulong args; - target_ulong arg0, arg1, arg2, arg3; - target_ulong ul_ret; + uint64_t args; + uint64_t arg0, arg1, arg2, arg3; + uint64_t ul_ret; char * s; int nr; int64_t elapsed; @@ -462,7 +462,7 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_WRITEC: /* - * FIXME: the byte to be written is in a target_ulong slot, + * FIXME: the byte to be written is in a uint64_t slot, * which means this is wrong for a big-endian guest. */ semihost_sys_write_gf(cs, common_semi_dead_cb, @@ -688,7 +688,7 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_HEAPINFO: { - target_ulong retvals[4]; + uint64_t retvals[4]; int i; #ifdef CONFIG_USER_ONLY TaskState *ts =3D get_task_state(cs); --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892858; cv=none; d=zohomail.com; s=zohoarc; b=SBU1pqtABCC9NXEqgmVLVAasUVVXrvI6jfzF5U7xuBUVUyWUhBPMAgumw/A1DwWOxQycdAdjwY2mYH+BgvCZHpyzFRA6AaI9ZamTfmMq3ct5VWCiKDUs99YN+GcCySINNiw5Pq592VsJYlyiV5EXaZOomzJS05zWlzhydVpsIaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892858; 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=2uZvm9cPBkSG9bbZTTshS2q8p+jP2mb7XOCO/jSy1Uc=; b=jpKnChEOw7x5AMdvuLH9lXifGrXVHo38BgI40N4Pa/2Fa7m78iT+OkZcMIkufQ6L/hsdE/TTY/zayXreX9TJzqX63QTSDT8wBPDUI0OiqbJwTPOp2pcdLQtx7GmuJJ/vJxD1lozKTtC8jzJ36sqPjwqWABZrv/tcu3XBpcbC6/4= 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 1758892858454461.9423602657332; Fri, 26 Sep 2025 06:20:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LS-00089Y-L1; Fri, 26 Sep 2025 09:18:42 -0400 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 1v28LQ-00087g-0u for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:40 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kw-00043t-0b for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:39 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-46e430494ccso1323715e9.1 for ; Fri, 26 Sep 2025 06:17:58 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fb89fb264sm7315137f8f.20.2025.09.26.06.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DE3CD5F913; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892677; x=1759497477; 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=2uZvm9cPBkSG9bbZTTshS2q8p+jP2mb7XOCO/jSy1Uc=; b=OEJUKjWROEJVFjEGw/gE6J8FbHNTWQ32TfHOypCQqj0eAPpMJc3xj148lwa/R0ghRO LEZR+YMfdKk7FJRydwR6aJTMsZ8J7+7QVoH15vtvDq4cn+/WcMIBKZnXEvRylVrVjwNu RWKQSEm/Y9vYDIbInZsipkXVJlsdj5KRqBjy5+YAkhp0vqEb5WFyMJehd/Ivh+8mtRPw PA9mLvm/rzh6FFnYj3o2clhpy11Cm0z/DWo2EShXZBDaotAna9Vk4TYXri1P569eCOlZ IhDOquSxLzAO2dShLyekJ8dYQ1FFWjkIHfIACuw0WNJJb6hwQDfv6BSpeVaTHAvXF0Sr wnRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892677; x=1759497477; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2uZvm9cPBkSG9bbZTTshS2q8p+jP2mb7XOCO/jSy1Uc=; b=t0hkwEdP6rcVZuIGxT/hVr28THP+E9yRSgefdG1tRKym7lgDLeePTzlSUwndQ9xuga JU6IkwuS/POxJmyGBjgFPLItOMTFOoXbi6lRA1mdXBDMoalJjBce6VLhmmtB8hY3EF5T +sVxUXAo9OEpdQYsV6C/IK9M4YsHebKs21YtoWq6RDnVrX84eTt8N+BI5WbutPlGPPgI 9pXxJyqzI8kpx5idq5MLWrZQ58E2ugrbviVnC7Qep+JVuIwY7kxn2Fm45ufl2c5gYQz6 xoJ8N65fsSnk5jkZSQQDNxztstPqwfUc5+Yr1xnBPBrDYFIUsjJxKwc34G/qgtJ8Rsi9 pyng== X-Gm-Message-State: AOJu0YzfTJnX5kkne9t6xL1d+UXEi8pUmnE9649e0ru67brRp8cHaGVJ eRyqEQVGCQ5NhKambTs/Iptf7tGZI3h2KCw2vYSifwDatI7aqTB1LIUnIKPOx+amfJzXRUALjMx Cr9fh9Qk= X-Gm-Gg: ASbGncv/9t2azNlj1jL33WJbAFgT6kVciPGRQsg8Kjs0ekBQOmj2LrPdS7pm+Eefdwn dVcH94RnnVZGG86O3voQVf62rzMgrWxCBzYOv4qh+SkFEqs8jdzcL5izuSwF9ek2IQ8NmgH99RM 9CjOZR0k7Nud/v38DmN9zET2dikoaXTskTHaYLQX3OqG5rogEHs/+eAFnCmfq/qkt25AXvRglyc 2ytlt3u/jokvakwRehDqaxc4DtUN8qjKZF/iXB3MW4bXHulfncw6aB7ZmoP5hwJynxvdA/hZaJi 0pNSY1++9WnrLllkHk12Ag0V7HqvDaBgvKWibBfIjtgfkJCewhnoWEthBiY5tEipozw2WCraZ9t rTTuCWBwLFopV7SioRRutkJ0= X-Google-Smtp-Source: AGHT+IH7SbjjlyWml6WwYtidtfOkUi5BbTCCKHdAaRNnD4C4oZBo4oXSjY95863Y6T1UyOH2BuP5Cw== X-Received: by 2002:a05:6000:2504:b0:3fa:944b:9bc3 with SMTP id ffacd0b85a97d-40e4dabf402mr7201204f8f.62.1758892677207; Fri, 26 Sep 2025 06:17:57 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 12/24] semihosting/arm-compat-semi: eradicate target_long Date: Fri, 26 Sep 2025 14:17:31 +0100 Message-ID: <20250926131744.432185-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.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: 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: 1758892859256116600 From: Pierrick Bouvier We use int64_t or int32_t depending on ret size. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-11-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-14-alex.bennee@linaro.org> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 29cdab66f73..3c9192d8684 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -501,10 +501,13 @@ void do_common_semihosting(CPUState *cs) break; =20 case TARGET_SYS_ISERROR: + { GET_ARG(0); - common_semi_set_ret(cs, (target_long)arg0 < 0); + bool ret =3D is_64bit_semihosting(env) ? + (int64_t)arg0 < 0 : (int32_t)arg0 < 0; + common_semi_set_ret(cs, ret); break; - + } case TARGET_SYS_ISTTY: GET_ARG(0); semihost_sys_isatty(cs, common_semi_istty_cb, arg0); --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892935; cv=none; d=zohomail.com; s=zohoarc; b=jmKl9+GIxYotQy2RGJlitVZ0TvS1FfFdgIdIufLUhCa9Ao4aiCUKLL443X4u5mQMUcWDPgwb9UEWWuw7E96s18DDxuK5IQiivT1We2Mn4u9VQpWcOCvRLy0sP+Tuf6jxE38ajBLD36wmcYPXTAM7ZLj6ZAA7+DVA5kIHOyPub/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892935; 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=wLCg9N9mRsCQoeuOOPX2s1zSAKuTeL3IamSuzw4Escg=; b=j0OH2y/NT8qS+aFMPvxphoyssLSbGxgqtgzGgFJ4tNOunS+pgIA1BkcLm5qaXbt+AKxOI6sWuIDySpQRi1U47Lyzt1vSeYfoti4y5NNgqGIMbxu0q0HdyOZUUxAkg4Bgpaup7sAzJcGcTFQTfhoGB37EAVi3CsCN7NdfkPZu6hI= 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 1758892935089713.9454243254999; Fri, 26 Sep 2025 06:22:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Lb-0008Cb-8S; Fri, 26 Sep 2025 09:18:51 -0400 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 1v28LX-0008C7-Hz for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:47 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kz-00044T-CF for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:47 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-46e42fa08e4so1845795e9.3 for ; Fri, 26 Sep 2025 06:18:05 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fc5603365sm7353573f8f.37.2025.09.26.06.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:55 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id F25115F915; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892682; x=1759497482; 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=wLCg9N9mRsCQoeuOOPX2s1zSAKuTeL3IamSuzw4Escg=; b=ijcGYD9sXZWLMea9y/z8lTg2FpqaybRx/vcthRmDOfhSzxknccoQN1joYKlfBPrQ1d dstsQD4s+dcr3F8bfknC/v6MvVJ4svPUxvUXgmFmMruPfjrp1kljpTO+MXozVxdnMSNE iwgwEafWxroo9Bh5qZmV23dh4/hFY8rKD40/ecc4HbZ/wQATLx35sPUo4LlPQ4iAGpTu 7GXb1TWDMfN3dSwJGODwjH3b3V+e/1VghjMSvemGWzAAdBnLtIaLMHmfO4Q7uozVw0BU VRa84zU9rIKAvTwQ1s5PY7vpnS4pDaGEJ37IOp0BIX9XyKxHwd6PiFD+o+mQaGFGwXrG 4ETg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892682; x=1759497482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wLCg9N9mRsCQoeuOOPX2s1zSAKuTeL3IamSuzw4Escg=; b=uCNg7sUXeHZaRKxqWIqgpuxePpkriVDVGib49OM+H1ebAtFZ1qObJxmr1l9cHN7CtM 978UHqolhC7eXN3DTl1X2lORs93tosmfltaJ66Zp2vCP3HmjDwyESJ/1bfugNfiGTkPG KsH4D6bF1UIMTSU6QkrGaEV2KMgxJzRK95CQvVbIoHLYErPr1pY7TfnHZFqN64dSdpQX ZvvK4VxqXBW0UANTMZWTaJXOlqfiwnfZqMgUX63kqvBZSGH1xZlUaKcHfVQ14uRcPHkD kRvDkCKwwqYhfwlpWa5cqRhhHYyleI2ulDcBI51Py3khJmsUzMA+xEj+jbEZnGnWg19i vHcg== X-Gm-Message-State: AOJu0Ywd9HMFlOOPqavnsldSOqARPsFJb9mos61vSkWpeQICZu1CFJCE stGltRgj9j8PeKETwoJonsZ41Lo8WVrgqTfHfCbf4g7onsY+epX1Aiou4Sy3nr8HzF6wmhKlmQR rBFLpImk= X-Gm-Gg: ASbGncu5PC6s0s2USlq5McxnxRZ1r8Vvb9brorlVBwGy8jKiEy40vpqfosCZF5xaGPA aaakduYCT1nbsQqF+RLs0fvzWhlCrdC4sEvjUoeB6+TOP7DDVSoNuJHVuZOprPTl+Ru3p1Dc/+/ B9ixS1MTW68rnWnKl0MQxNZsKEjrAngJ+34umVNYCRwtrW8xppQbz/0HuDMDN732aKdFB7L1WyP y4eGg+KwPvInH0ze4YrlEfdXMK6DWyQTv0gjJA9cQJ34QzzJ1+nzgPrVlAoElLodvIZjhlHjmrN u1FmXwA9DwetHT9aG/vmQqVM//wJcPWw+9bzk/IC4wDEh7MJ/L5BiyCmrrYpfn4ItSFTFnb317F crGw9POSGX7wdL9MDBbv497Ga3BtX7ACw0w== X-Google-Smtp-Source: AGHT+IHZ9/Opv1Nw1rFjOBxc2VK5uIseSk2BPIdtgwLZCXPlHGoxK1LsYsdV5ko0pSZsBGUVMej0jQ== X-Received: by 2002:a05:6000:40dc:b0:3ee:13b1:d70e with SMTP id ffacd0b85a97d-40e47ee1da9mr7251603f8f.40.1758892681649; Fri, 26 Sep 2025 06:18:01 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 13/24] semihosting/arm-compat-semi: remove dependency on cpu.h Date: Fri, 26 Sep 2025 14:17:32 +0100 Message-ID: <20250926131744.432185-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.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, TVD_SPACE_RATIO=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: 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: 1758892935978116600 From: Pierrick Bouvier Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-12-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-15-alex.bennee@linaro.org> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 3c9192d8684..61001267965 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -34,7 +34,6 @@ #include "qemu/osdep.h" #include "qemu/timer.h" #include "exec/gdbstub.h" -#include "cpu.h" #include "gdbstub/syscalls.h" #include "semihosting/semihost.h" #include "semihosting/console.h" --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892843; cv=none; d=zohomail.com; s=zohoarc; b=SE+gIyM4L8bQWgpuaeoW0XBsNcqJ9P+RM8/1hTLiWTzXO0A3MIgz3k+Qb20JRPypS6A8f6tLrfTMjaqIYgHCRNwE+5D9LTO8iHXT2JKRL8E3eF9veJIPSgSVBanbPfPH4yid4xvD+5+uelBlkaIqLFTm0QNz2KUWl4OkzpjAxgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892843; 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=n9ccHrqUiuKP+PUJpZRKMvcFrFBUUGVHqrCB+4rnREA=; b=Iy0S1X23ndPTaQswJcsw16JmFj1VKoHsp1j/9hjnxMQu4KzivppzKIUy14DOkhJGL9SCw3RvNBtLBCh27NIv87WyRXDu84LSHy8R5o9BzcrrexNrbiUQo2JKB5Q6P+RlnTJH1e+W78ma/VHxxQYiYKVPMNthO0hlZbUOlO1J0Fc= 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 17588928429921017.3263302935623; Fri, 26 Sep 2025 06:20:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LX-0008Bl-4B; Fri, 26 Sep 2025 09:18:47 -0400 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 1v28LU-0008B4-RN for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:45 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kv-00044F-V0 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:44 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-46e30ef74b0so15673255e9.0 for ; Fri, 26 Sep 2025 06:18:01 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e33bf70dcsm73289055e9.23.2025.09.26.06.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:55 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 11FF45F91D; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892680; x=1759497480; 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=n9ccHrqUiuKP+PUJpZRKMvcFrFBUUGVHqrCB+4rnREA=; b=qrkey+miYQG4dMifwVhcpLXhq+x5uYHKYndo7OCJSWM8+avTJ1AqTo+m8Gsfb9Hr/v JRAUfi7MnjTxBXWxte/MTNfklqpWYaTXHzYrRpn0Z52gvFXCd4SK+Ch/ZjfDkFBjB/Kz 4F/5U2dBswzZObagTpWzUVQ5T264JACjT4RL/J+kgFuAxB9MQuQn4xWXyuEoomYj8XJL CHim4wMLXBqI3cmbmgNnyGxTw1i12t71PVSHepl9Ogc1qZYVj+PGbxuYA6Cj9nrQIDqq 7gAwwt414/SGfbSt0ZUHmzmUO+UBrDALjg4W8eFb+Xrkee+tljZ+rVgNi5gW7t8Ylc2g zFRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892680; x=1759497480; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n9ccHrqUiuKP+PUJpZRKMvcFrFBUUGVHqrCB+4rnREA=; b=Le5ooX4U37fX8H69p9TAJfpIK5dlu6r6Xk3hkGxGhtiGVMLaE+JrkDyE/PMDukgNSL 79IweOQi/i6f/Dbseshynts8+nkfUEfbniPdZOTAoKEpKJH9ImCSaWUmJ5NWzLDnInh7 f8TyssZVBGcwrCAg/oCyjBHdN6PeqENgOQFmEjld61Cs05uyMuMUKMtF/JtDOG7eYiqB BwtiTmWP7aIsG74juqJGoXp8tE/9ryGFwEQOV6z/EvVtle9gVEsKH/BB/317KTiKnIlL h59fNU2Nhkd9bPry9oStae/fHcFug/YQsbV91qb9BVbHJ1yFl4nUtWSvwNO410dn9jIw RLwA== X-Gm-Message-State: AOJu0Yx4QPeEPefckJNuUOFakVTqfgb3J/bU/FtpDaiPRNp3/JI6jalJ eY2X6okEm1jHo318jK/xz4aSU6ZZyNSixykIhiR0NoHcnfYtfxVWKLGwTkumvIdTlzI= X-Gm-Gg: ASbGnctsQupw4QkXTK0WOEsswnZMcvHjvUJKFQCh7y01bfkib8DGPJP++wUNNk0QrcB MVIDsPy3MjCYzy7yams4DtoSyIhd9q1oy2Ue/n8vn27FXZbKVGEArgNP2tNphwoFhDe7LN2zQ8L Y/Cc55sAHkf0CtxPYCdMUCCc/aWt/IlvnHvdkjLnn/tEcqjhX09UpzFocOG2eNYff99V4A8FZCB e1HELCvsBEd0tn0FH9ukVPAEXpLUiZXKL+/4i+9WZuBftew0aShk/G5iLAs6+4A25fp0AOBnc7r RlOQWfvEDXJEsUHuQte3gfODXLSa3H7u8jncW766uVNXEq0nKeNBM9DHedGvTaDpStcUbV0aCSl 2DvI+/WpCNdpGO0omGteFKsM= X-Google-Smtp-Source: AGHT+IEICVh1+1hKdSM3g9J4xsG3N8FLPIJbaT+jWJPd5Hk9aUYXMtZhD1TeiIdvjD1nYvCc5p73mQ== X-Received: by 2002:a05:600c:1695:b0:45b:79fd:cb3d with SMTP id 5b1f17b1804b1-46e32a1b1fcmr46636345e9.36.1758892679662; Fri, 26 Sep 2025 06:17:59 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 14/24] semihosting/arm-compat-semi: compile once in system and per target for user mode Date: Fri, 26 Sep 2025 14:17:33 +0100 Message-ID: <20250926131744.432185-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.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: 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: 1758892844837116600 From: Pierrick Bouvier We don't have any target dependency left in system mode, so we can compile once. User mode depends on qemu.h, which is duplicated between linux and bsd, so we can't easily compile it once. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-13-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-16-alex.bennee@linaro.org> diff --git a/semihosting/meson.build b/semihosting/meson.build index bb0db323937..99f10e2e2bb 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -12,9 +12,10 @@ system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'stubs-system.c', )) system_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_true: files('arm-compat-semi.c'), if_false: files('arm-compat-semi-stub.c')) =20 specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'], if_true: files('syscalls.c')) -specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], +specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING', 'CONFIG_USER_O= NLY'], if_true: files('arm-compat-semi.c')) --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893130; cv=none; d=zohomail.com; s=zohoarc; b=dYpq8+6kKUg02hxH9HNocK8yE/v42/MDWBiiceRb67xX6cFmAXgMRRye8GDwPlEtxpBbN2T5G7Da8/UBaawyTgDhh+NUqQP45pBE6dXZtXTKCQUxaYeqsKUpYG+D9Nzsb603cR1LbaY/XX/AP3xoSXm6DUylkWfe0pRgYtN4Kq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893130; 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=CGV/ovuNyIkegXod3SFApgfQtr3bgHJbOlxaNSaOG6U=; b=Ykm88BPNhMBPB2B4ARcNRZh/ZHa++0p0FBrl4FpupI+YJwuVhSLsBjIU5mowFlWvB559+hpRJQCgwBu2u1jBgcUcAJc6JUOZHKeWfqrSGJJjsZAfWkFTjj29K4do7VoOj8iFTJJOC6Ve26lC43SIgkp6cN0mUkd25NbnYrXqBNY= 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 1758893130416289.3259428941984; Fri, 26 Sep 2025 06:25:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LT-00089n-GX; Fri, 26 Sep 2025 09:18:43 -0400 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 1v28LQ-00087n-Bh for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:40 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kw-000451-04 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:39 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-4060b4b1200so2035246f8f.3 for ; Fri, 26 Sep 2025 06:18:06 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e2a9ac5basm138161865e9.7.2025.09.26.06.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:55 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 26D685F924; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892683; x=1759497483; 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=CGV/ovuNyIkegXod3SFApgfQtr3bgHJbOlxaNSaOG6U=; b=Xz1R4+0kMysSgfZ0nLThkWZkVCigbvYzAV3LRdf8TFcw+wHGYgAfzpdO1OR6Bu2wJy 02UG+WXl9CCuXwUMA3ZucPdWnWJWGurcwhHyQMWDKqtD3NKYrDVin3ejx69VjSVGNB+L CXllu0o+YUnb1OJTlaF795Ray3LE3erRYG1t9TP47gNjptMExKFNHs3zJh9/4jIObCnj nNZZv4rHylSaHTT4ytZIqa6w9jN4no2YL7a3PMrRSNlgZnaJxAeYSjsYhsQK2zrv7SdK /tXUH0P08UTmjiMLCcP4ICd1moDnlo8Qf5GSeYGUC95Zd+gp25K2tas9UINMpf4Eyz76 gY8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892683; x=1759497483; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CGV/ovuNyIkegXod3SFApgfQtr3bgHJbOlxaNSaOG6U=; b=gOUloS1GX41qDIcL5P5zKUz8HCGWP68BTRzLKW2XmWtCFwVu/YXGKdkPBQocFYjYNM 2vp0z/GLgn5c4vbXQXVvKIUk2SnQXyN1/0GpK6BFzzTavH2mf6647wJjkYamNJRnWep2 Mx8Ih1YrVZko8+bUtY9rJ6ct4aj25bWBAoPOjIz4+RX/z3PnMTk2rcmy8s8yayytMQej 345jlWWLPEVM09cYIWl0HsUPNnGzJZLRvT2xau/ktv7rB4N1Q6gVIl5uE69T7Q8EIbTU TrOCXveQhUlwmYYSdNXhOhja3qaB3flSffsgD0I6nzFl8d/L+fL5NKETA2QqiQbIX2Lg wI0w== X-Gm-Message-State: AOJu0Yw+BkfEJyBdazLsYbum1mNxGGPIm1PxF3eGBtX3mGjbpG6by91G lZSjj8nP9lAW1ngKweqCiTF5f9blLLdP6FzQKPuvK2LmVqtOTrxqsGOfLisP/z7ZsGM= X-Gm-Gg: ASbGncvIq80zQhF0YeqRlLZKvxx/5xYnkEp/b6VU6x5YX1uNdP/bd15id1UR4SeM7mb RoOF7UIUfuDnfjKNyCxbuGX7vwgHg+4Joubdhh8vlG8fgx5TProaf2TTCTD/GJxqdBzsgI/g44K q2f1W1YAtwkeQiHkP5oNcDSo5YZFOXge8NjmintkGzcNkPhylFgyTjK+MrcpcR8L6JIRCfkLM9q eGFTM4BTpcuOlp/CCT3QCGbrnLWd8QzobNiLu+KAMvy69+dzhgrOeTPzpSQ/gInqicpLUWWC8Zj JkquR7uUqVraZaJENfpBJtcdVFgUH0PwvUPpxHyWCmM1k+u0kt0S+qOoEQbch64EzD9M1XhWeSh RS5pHPZ9EPoWRdLcNM/hzaac= X-Google-Smtp-Source: AGHT+IGPqn24RRByExxDxg0OKc0IwFdWACknOyFRPsB09p+6WhtGHvZ1oLLR5jkeI+6XoQ9E1OXqSA== X-Received: by 2002:a05:6000:2285:b0:3de:78c8:120e with SMTP id ffacd0b85a97d-40e468e7392mr5964230f8f.6.1758892683366; Fri, 26 Sep 2025 06:18:03 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 15/24] contrib/plugins/execlog: Explicitly check for qemu_plugin_read_register() failure Date: Fri, 26 Sep 2025 14:17:34 +0100 Message-ID: <20250926131744.432185-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::42f; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42f.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: 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: 1758893132784116600 From: Peter Maydell In insn_check_regs() we don't explicitly check whether qemu_plugin_read_register() failed, which confuses Coverity into thinking that sz can be -1 in the memcmp(). In fact the assertion that sz =3D=3D reg->last->len means this can't happen, but it's clearer to both humans and Coverity if we explicitly assert that sz > 0, as we already do in init_vcpu_register(). Coverity: CID 1611901, 1611902 Fixes: af6e4e0a22c1 ("contrib/plugins: extend execlog to track register cha= nges") Signed-off-by: Peter Maydell Reviewed-by: Pierrick Bouvier Message-ID: <20250710144543.1187715-1-peter.maydell@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-17-alex.bennee@linaro.org> diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c index 06ec76d6e9a..811f3203199 100644 --- a/contrib/plugins/execlog.c +++ b/contrib/plugins/execlog.c @@ -95,6 +95,7 @@ static void insn_check_regs(CPU *cpu) =20 g_byte_array_set_size(reg->new, 0); sz =3D qemu_plugin_read_register(reg->handle, reg->new); + g_assert(sz > 0); g_assert(sz =3D=3D reg->last->len); =20 if (memcmp(reg->last->data, reg->new->data, sz)) { --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758892949; cv=none; d=zohomail.com; s=zohoarc; b=kAW0RfypeunyaDT9F4TBF8U2hqFNbNKuX2KtYLBa0J2pH1l2qI5tTn99y/t/4LfuIldlbB9mccCwIZTYcEJfV9qUfzLZxbVwnivRISidSvMffALoZCF3CuxlFV/MwXO0E1AGLZAsno0IEf5FTwY7pd81Hse7giUYgYzus4B4gy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892949; 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=GzN/TgoAIkonCXT/uVBGl8EaJyMt7CwI7sLpMGZB2gI=; b=dNTOA0tXjtErjkviM6a3clsUGh6KNjvcCJee2D9IQfCXYu37u+kc4vz2LLvIfn8WLatNB85SgoQXfQ/Hnc5vhmCUucMx7tsiZ3EZQDrbdeBqouiY72DkqNw8QGu1PlgsgnqSeHFnL9+5eYUY6ksbi1b8RAVT5aKUqLLHrWCC9Ek= 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 1758892949409959.8437482517157; Fri, 26 Sep 2025 06:22:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Lb-0008Do-8k; Fri, 26 Sep 2025 09:18:51 -0400 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 1v28LX-0008CK-NN for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:47 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Kw-000457-Kw for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:47 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-46e326e4e99so11929345e9.1 for ; Fri, 26 Sep 2025 06:18:09 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e330fbcc5sm37966075e9.4.2025.09.26.06.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:55 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 3D6945F926; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892685; x=1759497485; 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=GzN/TgoAIkonCXT/uVBGl8EaJyMt7CwI7sLpMGZB2gI=; b=nxpMkFHVnamkn44Fz7LIDSVqyo28u/2SRrFgnwI3HtaFxUjehLfKVOr0DbMUZT44VS 4D6zb679aDtu3ntlU5TgNeQJ58GTHoOYMQvJi65aGJqedvjp67X4y2HXA719QGNn2PJe V54TzxUZ98HPlCBDZ+vDs2nRuCUJ02pwEqIl/sOi0MnzRrcvrys7qHp2fGREanO9r4DY 2l682EwUEwLRsa3EQyyGDwmCQqI+JkbpSMGqIZbgLXsXhpFIZD9L/3hIUEBk7BnCgX2C UXwn2m8kuXM+gM76SPvltmwwOAsnVjYKDsyRkdry+CLWDZgQiit99wvs7pfUC6jJPHVX +I3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892685; x=1759497485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GzN/TgoAIkonCXT/uVBGl8EaJyMt7CwI7sLpMGZB2gI=; b=XnC1NZp01s0FnVPHXN/Y0pVDHOlSVmMlTX7S4/1s8x3GWSOecIwe1Mhxqh5pF4EMMy Y8StDQAtifap03xpWQyDPCicuIY6Vlv1BnqULpcDIJ2hQawtWN0RwW7BilrRY43QYOhu zeZE6XdLUqPHqRM9C1rY7T158c7WW7yQYw/cjKq4+V3So07QUo7fytBwkDDAPfSveMKO dY9pDw1daeMBz40IsET9J2sTuiDZK+7VkI52FEwoIW0ytlQ4sez+B5n3qkOBNnpSYOVx +lRCEKqzySM7Pq5kTlgTxmg72M3Yd5AHaY4R7TfxbVkCuR8sR5WgsL7lEiF7maZ8AZu3 xnNw== X-Gm-Message-State: AOJu0YzHdZzn3MFl28eJOt54rhtfpqdjBJpGuOgMFef1DQykyWmGs3JP ewLFz0Gw64ncGMuOQgXWb6uKbIUZTYs/WI9LaT7v3QwbjYOHTvyvZ1Y4CDNEE/Ux78w= X-Gm-Gg: ASbGncvo3rlTunhR3wYp7LGhNXsn4qmEUR+9grUNNsipOkWFTHQ5FjpcFeV9syPFpdp HsUdQtCPGaRl1jXIpBL0y4iyPRGOinIzkhkKyTCgDZtctLTC0Orh0nMrnpDyWYpDS4LN4FGopxD LzyBfLwy7IwSjd4Tcu/xGFYF0SQAEBv9m8B1TKhP016PPi34nLHiYE6hkuEsGm4/5ghh6NHx4dO 5om8jpvGkiRT5Mg8eWJCPeNJHqwlInEo+knuu1m0BEwZawzPGrLtmaNhYQQ0eqnUshyUkiVZ2qX pf1YSNLxkUcgYclalUujoN5NmF7/QCFGJARGXGxgQRf21RoQiKSPbJQ63jDL7iK7+qYLGYzhSee +O8CdhWKJSI9ALnUEok14iVg= X-Google-Smtp-Source: AGHT+IE6ih/y01eCo5mD5dGThigSu6jb7OvGSIkPL/6XOGqCD5efUMCmsZw9pFChFQ7b1TTlj4Wclg== X-Received: by 2002:a05:600c:8907:b0:46e:3732:88ec with SMTP id 5b1f17b1804b1-46e37328daemr44843325e9.9.1758892684737; Fri, 26 Sep 2025 06:18:04 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 16/24] contrib/plugins/uftrace: skeleton file Date: Fri, 26 Sep 2025 14:17:35 +0100 Message-ID: <20250926131744.432185-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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: 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: 1758892950452116600 From: Pierrick Bouvier We define a scoreboard that will hold our data per cpu. As well, we define a buffer per cpu that will be used to read registers and memories in a thread-safe way. For now, we just instrument all instructions with an empty callback. Reviewed-by: Manos Pitsidianakis Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-2-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-18-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c new file mode 100644 index 00000000000..4af0130b159 --- /dev/null +++ b/contrib/plugins/uftrace.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2025, Pierrick Bouvier + * + * Generates a trace compatible with uftrace (similar to uftrace record). + * https://github.com/namhyung/uftrace + * + * See docs/about/emulation.rst|Uftrace for details and examples. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +typedef struct Cpu { + GByteArray *buf; +} Cpu; + +static struct qemu_plugin_scoreboard *score; + +static void track_callstack(unsigned int cpu_index, void *udata) +{ +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n_insns =3D qemu_plugin_tb_n_insns(tb); + + for (size_t i =3D 0; i < n_insns; i++) { + struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); + + uintptr_t pc =3D qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_insn_exec_cb(insn, track_callstack, + QEMU_PLUGIN_CB_R_REGS, + (void *) pc); + } +} + +static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + Cpu *cpu =3D qemu_plugin_scoreboard_find(score, vcpu_index); + cpu->buf =3D g_byte_array_new(); +} + +static void vcpu_end(unsigned int vcpu_index) +{ + Cpu *cpu =3D qemu_plugin_scoreboard_find(score, vcpu_index); + g_byte_array_free(cpu->buf, true); + memset(cpu, 0, sizeof(Cpu)); +} + +static void at_exit(qemu_plugin_id_t id, void *data) +{ + for (size_t i =3D 0; i < qemu_plugin_num_vcpus(); ++i) { + vcpu_end(i); + } + + qemu_plugin_scoreboard_free(score); +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, + int argc, char **argv) +{ + score =3D qemu_plugin_scoreboard_new(sizeof(Cpu)); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_register_atexit_cb(id, at_exit, NULL); + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + + return 0; +} diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build index 1876bc78438..7eb3629c95d 100644 --- a/contrib/plugins/meson.build +++ b/contrib/plugins/meson.build @@ -1,5 +1,6 @@ contrib_plugins =3D ['bbv', 'cache', 'cflow', 'drcov', 'execlog', 'hotbloc= ks', - 'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger'] + 'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger', + 'uftrace'] if host_os !=3D 'windows' # lockstep uses socket.h contrib_plugins +=3D 'lockstep' --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893156; cv=none; d=zohomail.com; s=zohoarc; b=dnUtq0zPvYc1fUNBoL97NNxOQMvjuR2Gg1DTGwGaSAp1dVuxwHoda42tCHRn4eTZcZsW7sO0Szg1Af8DfJCTou6mNfdkNSlLeszAeu3Tb0LKV5wmCSbC90vfUr1CgtSJe9ztMU/moqpPA7eoPB7nCloE/HAuiB6tKebQWgc6PXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893156; 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=MRX+Cpo73yx+rWEIEKqZAU5Sre7tyLuOpCcwtQxBwO0=; b=fiJkx84q2kNzVUG8nVtIUO+kSOLbyslKKG8YdNAbwX4fOKXdCYtezMRXvNo04csh1pr/mGoGDQdoKkckpygLPzE/ME0j4nCHjpMHdunLNUjIYemDKq2fEeo3gikBzxevslwoL7kYHl6A+Rw7x5WelKdxx49cyXX/GBqIkam/AdY= 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 175889315609982.4898716972117; Fri, 26 Sep 2025 06:25:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Pu-0006HZ-60; Fri, 26 Sep 2025 09:23:18 -0400 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 1v28Ps-0006Gp-5n for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:16 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Pm-0004vY-Ii for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:15 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3fa528f127fso1627009f8f.1 for ; Fri, 26 Sep 2025 06:23:06 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fe4237f32sm7012074f8f.63.2025.09.26.06.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:23:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 55C425F92A; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892982; x=1759497782; 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=MRX+Cpo73yx+rWEIEKqZAU5Sre7tyLuOpCcwtQxBwO0=; b=dea6kKyZFq64pCSp18cHs48S86gl9iyCFuHBpown508ZPgGl2hS5C6ugrw+WebBQVW lnEfSntNKjLuqcO9R2TE2UuvwrfYtwYsKPHOyM62u08Xns5N0ArgWoZujCTdzpg0P18C MebycimbSZLTOaDjTgylQh7tbuAmmWDmdLPLX+XzhIa/prlPS69PeJCipm0M55UWJpZr HwH2twXhMr/nCs40LMnXPfW8cZFH0hIAP0/6I5jcwF2/8U7S2ULIJNgXTACktzSw1+2o +Qm4PGXcaPAmkKe6IJoLC8WwfRjYvtVC/0tpyv9hfy2waCg4wM+m360V/qrQ26zeAPRS ffVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892982; x=1759497782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MRX+Cpo73yx+rWEIEKqZAU5Sre7tyLuOpCcwtQxBwO0=; b=X7lvRFZp/Chj7F2KOAYxEivM6Xz6n2qasEZnp2LvAMpHlPiE0F16s4LdNfrCgCpbqX LVv7PP+gCFF0fXpcb3R8GPAmy8tzl+/qo9lJ83oWiYAPTZllhQPKViKsmiY6h0H/x1+f d6trUkpR143ww7d75TBBSikF6+UOx7ofaDZbGVI6WegEcDJLS/s4+59jqzZnVyB/5WqK 8xd2/pkeEhdzYNEIo/kpa/whDrsaK97QbfXe/ft83eDn20TM67TiZKSJDgKxsHnN/MpI 64Xm+w3l6dcCXYG9IhywHul/RRqKj1L2BmTYApnSNSEEwQX8UdBugK088HUVM6taD+zA bYlw== X-Gm-Message-State: AOJu0YxNph/0y2qlTyYHddD+vGTKQ3eXDKaDDX5ZS++pLC9B1+czpWBQ Bg/i5BczcaN0h75oQbhWPu8qSm71X5SBvOwexcgdSCzskyj4NpgWc1cpuMbRtES4QFE= X-Gm-Gg: ASbGncubKnA1N3es7b8JXhnSr1EqksNiJ2S7BTSnOVr/Jo/0DvNjx6NAIbCztWT4TIt BfUTtU+bgHEap9CaxK+iWGQlehboC+/N8PIZrtKDbXQHeebnz49LpoEcF8dhMluIOxFgjplp/iP 4geTsaKh/jidASIWezaxlvaXZCxrdeYvfRAUq/ECyWPvB5juPrZyKLnrII8nY4ecLgMDH4Z/o3R 1pGq7FxrfTkTr0/ISfwGXE0CZQkUQGW5VRGyACAue6CNNYtEhA5b2bQNsjxoqzLxnHzN8f8wp/W /EWh932fvg7bogZPCa0h8OdKk2qzI+fiHQmurNshEC4Mi/qerCD84gkfY07hrKjCWuI5s+dvV8+ bj2SdNcyzkAH7tLi731l4ExShyGyzISUFjw== X-Google-Smtp-Source: AGHT+IGm6h0yCBTll1ySHWuaEGoA1VDbE+OY1q9J4q55+McRnK8HlqjDKNZO8Jlc67L1YLyQqsEnUQ== X-Received: by 2002:a05:6000:2909:b0:3ee:1494:27f5 with SMTP id ffacd0b85a97d-40f6203ae47mr6652530f8f.13.1758892981610; Fri, 26 Sep 2025 06:23:01 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 17/24] contrib/plugins/uftrace: define cpu operations and implement aarch64 Date: Fri, 26 Sep 2025 14:17:36 +0100 Message-ID: <20250926131744.432185-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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: 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: 1758893157237116600 From: Pierrick Bouvier We define a new CpuOps structure that will be used to implement tracking independently of guest architecture. As well, we now instrument only instructions following ones that might have touched the frame pointer. Reviewed-by: Manos Pitsidianakis Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-19-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index 4af0130b159..d060513446c 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -11,14 +11,94 @@ =20 #include #include +#include =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 +typedef struct Cpu Cpu; + +typedef struct { + void (*init)(Cpu *cpu); + void (*end)(Cpu *cpu); + uint64_t (*get_frame_pointer)(Cpu *cpu); + bool (*does_insn_modify_frame_pointer)(const char *disas); +} CpuOps; + typedef struct Cpu { GByteArray *buf; + CpuOps ops; + void *arch; } Cpu; =20 +typedef struct { + struct qemu_plugin_register *reg_fp; +} Aarch64Cpu; + static struct qemu_plugin_scoreboard *score; +static CpuOps arch_ops; + +static uint64_t cpu_read_register64(Cpu *cpu, struct qemu_plugin_register = *reg) +{ + GByteArray *buf =3D cpu->buf; + g_byte_array_set_size(buf, 0); + size_t sz =3D qemu_plugin_read_register(reg, buf); + g_assert(sz =3D=3D 8); + g_assert(buf->len =3D=3D 8); + return *((uint64_t *) buf->data); +} + +static struct qemu_plugin_register *plugin_find_register(const char *name) +{ + g_autoptr(GArray) regs =3D qemu_plugin_get_registers(); + for (int i =3D 0; i < regs->len; ++i) { + qemu_plugin_reg_descriptor *reg; + reg =3D &g_array_index(regs, qemu_plugin_reg_descriptor, i); + if (!strcmp(reg->name, name)) { + return reg->handle; + } + } + return NULL; +} + +static uint64_t aarch64_get_frame_pointer(Cpu *cpu_) +{ + Aarch64Cpu *cpu =3D cpu_->arch; + return cpu_read_register64(cpu_, cpu->reg_fp); +} + +static void aarch64_init(Cpu *cpu_) +{ + Aarch64Cpu *cpu =3D g_new0(Aarch64Cpu, 1); + cpu_->arch =3D cpu; + cpu->reg_fp =3D plugin_find_register("x29"); + if (!cpu->reg_fp) { + fprintf(stderr, "uftrace plugin: frame pointer register (x29) is n= ot " + "available. Please use an AArch64 cpu (or -cpu max= ).\n"); + g_abort(); + } +} + +static void aarch64_end(Cpu *cpu) +{ + g_free(cpu->arch); +} + +static bool aarch64_does_insn_modify_frame_pointer(const char *disas) +{ + /* + * Check if current instruction concerns fp register "x29". + * We add a prefix space to make sure we don't match addresses dump + * in disassembly. + */ + return strstr(disas, " x29"); +} + +static CpuOps aarch64_ops =3D { + .init =3D aarch64_init, + .end =3D aarch64_end, + .get_frame_pointer =3D aarch64_get_frame_pointer, + .does_insn_modify_frame_pointer =3D aarch64_does_insn_modify_frame_poi= nter, +}; =20 static void track_callstack(unsigned int cpu_index, void *udata) { @@ -28,19 +108,37 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct = qemu_plugin_tb *tb) { size_t n_insns =3D qemu_plugin_tb_n_insns(tb); =20 + /* + * Callbacks and inline instrumentation are inserted before an instruc= tion. + * Thus, to see instruction effect, we need to wait for next one. + * Potentially, the last instruction of a block could modify the frame + * pointer. Thus, we need to always instrument first instruction in a = tb. + */ + bool instrument_insn =3D true; for (size_t i =3D 0; i < n_insns; i++) { struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); =20 - uintptr_t pc =3D qemu_plugin_insn_vaddr(insn); - qemu_plugin_register_vcpu_insn_exec_cb(insn, track_callstack, - QEMU_PLUGIN_CB_R_REGS, - (void *) pc); + if (instrument_insn) { + uintptr_t pc =3D qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_insn_exec_cb(insn, track_callstack, + QEMU_PLUGIN_CB_R_REGS, + (void *) pc); + instrument_insn =3D false; + } + + char *disas =3D qemu_plugin_insn_disas(insn); + if (arch_ops.does_insn_modify_frame_pointer(disas)) { + instrument_insn =3D true; + } } } =20 static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) { Cpu *cpu =3D qemu_plugin_scoreboard_find(score, vcpu_index); + cpu->ops =3D arch_ops; + + cpu->ops.init(cpu); cpu->buf =3D g_byte_array_new(); } =20 @@ -64,6 +162,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, const qemu_info_t *info, int argc, char **argv) { + if (!strcmp(info->target_name, "aarch64")) { + arch_ops =3D aarch64_ops; + } else { + fprintf(stderr, "plugin uftrace: %s target is not supported\n", + info->target_name); + return 1; + } + score =3D qemu_plugin_scoreboard_new(sizeof(Cpu)); qemu_plugin_register_vcpu_init_cb(id, vcpu_init); qemu_plugin_register_atexit_cb(id, at_exit, NULL); --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893298; cv=none; d=zohomail.com; s=zohoarc; b=ZP50qrNmfvBen58TzcTq/y0Lea15+3xcY4yEsmShWA10MulP9EVuEHOKAbDglR72+bnHKeAVd//WBMUFFKA9mse2YlsMWF4K0+ysKXis0NOBg54gD6ifUhI+8x89LiA1j5eW6Eum88hKpfKMBiOvV41KSLXrYNi5IE0RR3TJTh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893298; 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=YdDnD0rZnfTWEUKmWeobk/eVDfx9m8s0Jx+oQ2Wy7U8=; b=itV6tY+1IbFEfrIY61ZiYyabghw0xxhrDbuzhX/7hCQqzKHfJgmwe9uq57U1peP4hqDH4rxDw/v0SCxzp2Ip4NXbIJktsOZVwZpvjdRHZVahZ8fnqji0vn71ZGu2hci/L9JrAPLsAp1g3m49t/RGAVP8zJ3Vikn4vdxOgqwyGxE= 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 1758893298437707.7413467996203; Fri, 26 Sep 2025 06:28:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Q3-0006N3-GT; Fri, 26 Sep 2025 09:23:27 -0400 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 1v28Py-0006Hx-60 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:23 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Po-0004vx-CY for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:20 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-414f48bd785so539828f8f.1 for ; Fri, 26 Sep 2025 06:23:08 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fb9e1b665sm7014797f8f.27.2025.09.26.06.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:23:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 6EA455F92E; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892985; x=1759497785; 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=YdDnD0rZnfTWEUKmWeobk/eVDfx9m8s0Jx+oQ2Wy7U8=; b=WnpeMAvQPWlT5GonnN7W9AJdo0mJ2WKyfpUTM5UZZr2nilNBAQb07JxL8QJAT3npGa l4XJKB57Tm0E6qYjqLzUdDJDd5CYhAzUQu0DzTpW7Up4lP/A6clMrR5sC8/qoUcLmwuK tRCS6KKit7HhVIMudb1CMdVWn/EDOrRnWmBx4gKMnn2T6Lr4AT3XsFhO5CLq3l0/w8or 4/jeNqozPsF+e77mGgb7kWw20qPwYm4u8LFZ2k080GDfloM9VDxqXM3myqkOuRrQxhvM lR5qkZ34rb7RyV6igxw1wcIe8ppWVybAvbK2pZ6mfwO7kKOOUBETftVt+KrnbkdrRNj6 5LSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892985; x=1759497785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YdDnD0rZnfTWEUKmWeobk/eVDfx9m8s0Jx+oQ2Wy7U8=; b=A56uTz1QpkyNLNu0xamfWWIuY/u9ywFQYTyddM4eCtcu0ptTyi69o81ev7a1SLxUor hp/QmfC+T4miBjVVPEDO0rmiPwhpYJQCnmCyHfqwh1pbpUs13I+/1udunRKW+xsh8twY OlsKUJG65pNBwsSklT/R4s7qqKCPUjPom2BLgd9HnW0J9PrwsXscCc/ocdNNN8EJskzv lxaBEnRaGaThMiuYfAcq6I616O+QHXhUxLE6LjRmB4YoI9pQuCn3fmy6Iw7TRgOWtxUd PQ3vLH2LKkL4jvpYYBraSNDzhEU0wcLmOz5V1pcqmwtdYErekf9NeuGHg1+2iThPDYWP EVJQ== X-Gm-Message-State: AOJu0YwmMmIOiFi5nbSCNS2fdNue5/clRHXz1JtsCgxbG6I2k1BVxUn1 1WjviBu44FBhPc+0p2NGBcFl3Yp7bafhWsRR/sI+05kx0M5/x27zLB4bKX3fyahO/Ow= X-Gm-Gg: ASbGncsmt0bD5SI/8PgEl9PD8YHw0+wpVGgK+vh4Mr71Tjj1BUrunVC89Ptk+nbyK0J 4UFxN3PB4D3Ranxr+98GvnRI4IEUmQ/UTJby5hTcTDQsu+Kf6OYE/HJ6s3VHXpqUTQep3F7KmBd me/KsHAcoBavYaQ0WbI7oYWJYvn7q7V4TpY2LzehFvIJNKZBgzTmUvS23OXl6zTFmwQU16ePVNM OnaFzBRXLuh/eMh5ZoWYnpnn/erABLo9Q1fwMaqtT6VHtmM8yZ//On2e73jv+mqV3LciuJDldSz 3YVaN0Xn7KvHFQH0LU4j4yXikO+4IWiOpvKXM73rpFohSKThe9n62JS9lEDwbnN0uEV9QxCvECR nRdYVmiDylSwU6BLEuq4LuwJhNmAjZQ4dsA== X-Google-Smtp-Source: AGHT+IF75MhQqvzipsW2teu78Lt6+q6UjPOJz5TG39A7Hs9Kq6nZuPe4ctcibO8RQqUnd2exbILLxA== X-Received: by 2002:a5d:584c:0:b0:3fe:d6df:c679 with SMTP id ffacd0b85a97d-40e49e72688mr7183946f8f.55.1758892984820; Fri, 26 Sep 2025 06:23:04 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 18/24] contrib/plugins/uftrace: track callstack Date: Fri, 26 Sep 2025 14:17:37 +0100 Message-ID: <20250926131744.432185-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::42a; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42a.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: 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: 1758893299142116600 From: Pierrick Bouvier We now track callstack, based on frame pointer analysis. We can detect function calls, returns, and discontinuities. We implement a frame pointer based unwinding that is used for discontinuities. Reviewed-by: Manos Pitsidianakis Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-4-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-20-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index d060513446c..bb775916270 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -15,6 +15,15 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 +typedef struct { + GArray *s; +} Callstack; + +typedef struct { + uint64_t pc; + uint64_t frame_pointer; +} CallstackEntry; + typedef struct Cpu Cpu; =20 typedef struct { @@ -25,6 +34,7 @@ typedef struct { } CpuOps; =20 typedef struct Cpu { + Callstack *cs; GByteArray *buf; CpuOps ops; void *arch; @@ -37,6 +47,71 @@ typedef struct { static struct qemu_plugin_scoreboard *score; static CpuOps arch_ops; =20 +static Callstack *callstack_new(void) +{ + Callstack *cs =3D g_new0(Callstack, 1); + cs->s =3D g_array_new(false, false, sizeof(CallstackEntry)); + return cs; +} + +static void callstack_free(Callstack *cs) +{ + g_array_free(cs->s, true); + cs->s =3D NULL; + g_free(cs); +} + +static size_t callstack_depth(const Callstack *cs) +{ + return cs->s->len; +} + +static size_t callstack_empty(const Callstack *cs) +{ + return callstack_depth(cs) =3D=3D 0; +} + +static void callstack_clear(Callstack *cs) +{ + g_array_set_size(cs->s, 0); +} + +static const CallstackEntry *callstack_at(const Callstack *cs, size_t dept= h) +{ + g_assert(depth > 0); + g_assert(depth <=3D callstack_depth(cs)); + return &g_array_index(cs->s, CallstackEntry, depth - 1); +} + +static CallstackEntry callstack_top(const Callstack *cs) +{ + if (callstack_depth(cs) >=3D 1) { + return *callstack_at(cs, callstack_depth(cs)); + } + return (CallstackEntry){}; +} + +static CallstackEntry callstack_caller(const Callstack *cs) +{ + if (callstack_depth(cs) >=3D 2) { + return *callstack_at(cs, callstack_depth(cs) - 1); + } + return (CallstackEntry){}; +} + +static void callstack_push(Callstack *cs, CallstackEntry e) +{ + g_array_append_val(cs->s, e); +} + +static CallstackEntry callstack_pop(Callstack *cs) +{ + g_assert(!callstack_empty(cs)); + CallstackEntry e =3D callstack_top(cs); + g_array_set_size(cs->s, callstack_depth(cs) - 1); + return e; +} + static uint64_t cpu_read_register64(Cpu *cpu, struct qemu_plugin_register = *reg) { GByteArray *buf =3D cpu->buf; @@ -47,6 +122,50 @@ static uint64_t cpu_read_register64(Cpu *cpu, struct qe= mu_plugin_register *reg) return *((uint64_t *) buf->data); } =20 +static uint64_t cpu_read_memory64(Cpu *cpu, uint64_t addr) +{ + g_assert(addr); + GByteArray *buf =3D cpu->buf; + g_byte_array_set_size(buf, 0); + bool read =3D qemu_plugin_read_memory_vaddr(addr, buf, 8); + if (!read) { + return 0; + } + g_assert(buf->len =3D=3D 8); + return *((uint64_t *) buf->data); +} + +static void cpu_unwind_stack(Cpu *cpu, uint64_t frame_pointer, uint64_t pc) +{ + g_assert(callstack_empty(cpu->cs)); + + #define UNWIND_STACK_MAX_DEPTH 1024 + CallstackEntry unwind[UNWIND_STACK_MAX_DEPTH]; + size_t depth =3D 0; + do { + /* 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; + } + } + 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 */ + } while (frame_pointer && pc && depth < UNWIND_STACK_MAX_DEPTH); + #undef UNWIND_STACK_MAX_DEPTH + + /* push it from bottom to top */ + while (depth) { + callstack_push(cpu->cs, unwind[depth - 1]); + --depth; + } +} + static struct qemu_plugin_register *plugin_find_register(const char *name) { g_autoptr(GArray) regs =3D qemu_plugin_get_registers(); @@ -102,6 +221,43 @@ static CpuOps aarch64_ops =3D { =20 static void track_callstack(unsigned int cpu_index, void *udata) { + uint64_t pc =3D (uintptr_t) udata; + Cpu *cpu =3D qemu_plugin_scoreboard_find(score, cpu_index); + Callstack *cs =3D cpu->cs; + + uint64_t fp =3D cpu->ops.get_frame_pointer(cpu); + if (!fp && callstack_empty(cs)) { + /* + * We simply push current pc. Note that we won't detect symbol cha= nge as + * long as a proper call does not happen. + */ + callstack_push(cs, (CallstackEntry){.frame_pointer =3D fp, .pc =3D= pc}); + return; + } + + CallstackEntry top =3D callstack_top(cs); + if (fp =3D=3D top.frame_pointer) { + /* same function */ + return; + } + + CallstackEntry caller =3D callstack_caller(cs); + if (fp =3D=3D caller.frame_pointer) { + /* return */ + callstack_pop(cs); + return; + } + + uint64_t caller_fp =3D fp ? cpu_read_memory64(cpu, fp) : 0; + if (caller_fp =3D=3D top.frame_pointer) { + /* call */ + callstack_push(cs, (CallstackEntry){.frame_pointer =3D fp, .pc =3D= pc}); + return; + } + + /* discontinuity, exit current stack and unwind new one */ + callstack_clear(cs); + cpu_unwind_stack(cpu, fp, pc); } =20 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -140,12 +296,16 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned i= nt vcpu_index) =20 cpu->ops.init(cpu); cpu->buf =3D g_byte_array_new(); + + cpu->cs =3D callstack_new(); } =20 static void vcpu_end(unsigned int vcpu_index) { Cpu *cpu =3D qemu_plugin_scoreboard_find(score, vcpu_index); g_byte_array_free(cpu->buf, true); + + callstack_free(cpu->cs); memset(cpu, 0, sizeof(Cpu)); } =20 --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893314; cv=none; d=zohomail.com; s=zohoarc; b=f6Jb82pukwRncKzoMfqr2iC1sH32famQUQjFwQVrH/808TfVaSEzRYFnm2JndRCfkIVg0rIBANv5rwXHQ4PX5CaTw+pSMG8pNw4/fTbk3ropmT1ZCTQsFlnEMsZxyi7cORPtSUpPH/r3vW8twYBFzIkgH6/d9c4DSAeEvS09ZzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893314; 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=jAz0JTk4vVsduSfTi2oHWjqlddYgsu0yU35539b5ArY=; b=jvW1m+hKO49v4lawzk7X71nwCCOerZ80qRepBQti64sISo5eJxGZWBU1azC0q0lXJg/uM5jcg8jbFhgltoSFhhcJh3VVYh4VBOuAhgPDECv3z1HQm33rtbiglDUCtyGlihqFRgQsDLJT3y6tvDQiunh2x2EnK7S2KFEVg0Eq1Yg= 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 1758893314808554.4239987515184; Fri, 26 Sep 2025 06:28:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Q3-0006Nj-3X; Fri, 26 Sep 2025 09:23:27 -0400 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 1v28Q1-0006MY-MW for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:25 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Pq-0004w9-Fu for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:25 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-46e3af7889fso7001255e9.2 for ; Fri, 26 Sep 2025 06:23:09 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e32c10823sm37200545e9.3.2025.09.26.06.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:23:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 864AE5F92F; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892985; x=1759497785; 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=jAz0JTk4vVsduSfTi2oHWjqlddYgsu0yU35539b5ArY=; b=nD1eflIVxqJxgPv4Su8NFreSR91U+7HOLY9Cgm8Or7wTynXLCbndwadokbOoTEOi0I Atf6+ya3fZSRpWzkjmy3+ZfHnFGKwdzrWQn39qJmEwD0VadK5WMSVZCuBzNjxrHtdQkJ V0SJoY8qEGTEIkucZbXu1DSnrbTLg9ofgcDDt1bjC6lULJu7kLUOJfvTsCBmDlqBc5pv FMSHhzijOgMKA7H+UQgxC/6AdJBboAciBQcNtb8/VGayXOCOHBgrdKywmOgRtdWY3R3O KX1UC7ltFdSas9Zb/VvfwyIZHSdcfBJ8iUmjIXTev8xKern9ZqLVl+kwdf/2Me0R1tWK gh3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892985; x=1759497785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jAz0JTk4vVsduSfTi2oHWjqlddYgsu0yU35539b5ArY=; b=oErNP6bPvsiUkUX9REU/C3tXBx53iHpEGPvj8+jFIWM14FcG5LkUXslXW5iAXbyWxT sYzWXYFUq1l4E1Mf0CgElOtmqrVwnfEnt91hgnevL0oy1oLed5SwapyWqIp0cTtHHS4E f216VZWEw8qZG4vBA8vA/Xuc08BXn5CUIS/Kav4PBxJllWYngUUdiqaII/NtoIYYeIB+ EbqDlX2UPSjgWkfY+Pih57Hgbc/EtMHaR3isxErDTDQvO8ivfTm2rEYWzNAOeHxHn9Jl IIqqolDsUS1KQ1zTbhJpgIvOKdizL4nPkpLy6g1xFsMA7EZUDxiEBVot484FVVuUGZRE xklA== X-Gm-Message-State: AOJu0YyRHLen9pxcAvn4IdsjkoUZqgVsATia2ZWi7hhOxWbPSqn/+qiq kGYdLmgA1n/vzy9FoO7E/vtMf/sCI+aTkuo46cbw95hQLrLpoa/72wZSl1FtARAgSmxLwH9obJt uM9IOFDk= X-Gm-Gg: ASbGncuFOcrtRWCygc42ugXaJmmWaIJwCmQDwmTVuiSF+TTXPBVgk2xVPu9ZC6VtHfg nrzWUBoxXmrsnKtIrdDF7QVXfhIfwG1MMUYS/Ad+cD0xoEGwoZXqT5urz27+vWpF6C5pRBmPq07 D9bP2TAJThgCkrmk5S8jDbz9XLZA5kDAVOYtqDjnQgETXyyy1AAW7qyBH+qgZk/10HOKd6Hr3Ry UDvWnLnGM8V2a2dGjxGN0pyG480iTK0O524jIyhTll4J90u6eeLwAuaTDpYk9AtuV/6c9KgnxVi WRMQuelwwbq23q+BLGGWEsfqdHgBOc2nczShCiFhpeeE6EW/61ox7ui14aU1Wa45yPmt64T8GR3 goOlHgdq4IlELYvtfE7J8r1Q= X-Google-Smtp-Source: AGHT+IHMg0pP8IcWQv+sJp0KMHZ/zOVH6kiu3X6NqcrUHR2mvPPSG2oJErDS7jgG1U4D18bBlhA8jA== X-Received: by 2002:a05:600c:4ec6:b0:46c:adf8:c845 with SMTP id 5b1f17b1804b1-46e329c1768mr86328835e9.16.1758892985547; Fri, 26 Sep 2025 06:23:05 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 19/24] contrib/plugins/uftrace: implement tracing Date: Fri, 26 Sep 2025 14:17:38 +0100 Message-ID: <20250926131744.432185-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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: 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: 1758893315696116600 From: Pierrick Bouvier We implement tracing, following uftrace format. Trace is flushed every 32 MB, so file operations don't impact performance at runtime. A different trace is generated per cpu, and we ensure they have a unique name, based on vcpu_index, while keeping room for privilege level coming in next commit. Uftrace format is not officially documented, but it can be found here: https://github.com/namhyung/uftrace/blob/v0.18/libmcount/record.c#L909 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-5-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-21-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index bb775916270..b9dcd531987 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -12,6 +12,15 @@ #include #include #include +#include +#include +#include +#include + +#define MiB (INT64_C(1) << 20) +#define NANOSECONDS_PER_SECOND 1000000000LL +#define TRACE_FLUSH_SIZE (32 * MiB) +#define TRACE_ID_SCALE 100 =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 @@ -24,6 +33,13 @@ typedef struct { uint64_t frame_pointer; } CallstackEntry; =20 +typedef struct { + GArray *t; + GString *path; + GString *name; + uint32_t id; +} Trace; + typedef struct Cpu Cpu; =20 typedef struct { @@ -34,6 +50,7 @@ typedef struct { } CpuOps; =20 typedef struct Cpu { + Trace *trace; Callstack *cs; GByteArray *buf; CpuOps ops; @@ -44,9 +61,41 @@ typedef struct { struct qemu_plugin_register *reg_fp; } Aarch64Cpu; =20 +typedef struct { + uint64_t timestamp; + uint64_t data; +} UftraceEntry; + +typedef enum { + UFTRACE_ENTRY, + UFTRACE_EXIT, + UFTRACE_LOST, + UFTRACE_EVENT, +} UftraceRecordType; + static struct qemu_plugin_scoreboard *score; static CpuOps arch_ops; =20 +static uint64_t gettime_ns(void) +{ +#ifdef _WIN32 + /* + * On Windows, timespec_get is available only with UCRT, but not with + * MinGW64 environment. Simplify by using only gettimeofday on this + * platform. This may result in a precision loss. + */ + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t now_ns =3D tv.tv_sec * NANOSECONDS_PER_SECOND + tv.tv_usec * = 1000; +#else + /* We need nanosecond precision for short lived functions. */ + struct timespec ts; + timespec_get(&ts, TIME_UTC); + uint64_t now_ns =3D ts.tv_sec * NANOSECONDS_PER_SECOND + ts.tv_nsec; +#endif + return now_ns; +} + static Callstack *callstack_new(void) { Callstack *cs =3D g_new0(Callstack, 1); @@ -112,6 +161,86 @@ static CallstackEntry callstack_pop(Callstack *cs) return e; } =20 +static Trace *trace_new(uint32_t id, GString *name) +{ + Trace *t =3D g_new0(Trace, 1); + t->t =3D g_array_new(false, false, sizeof(UftraceEntry)); + t->path =3D g_string_new(NULL); + g_string_append_printf(t->path, "./uftrace.data/%"PRIu32".dat", id); + t->name =3D g_string_new(name->str); + t->id =3D id; + return t; +} + +static void trace_free(Trace *t) +{ + g_assert(t->t->len =3D=3D 0); + g_array_free(t->t, true); + t->t =3D NULL; + g_string_free(t->path, true); + t->path =3D NULL; + g_string_free(t->name, true); + t->name =3D NULL; + g_free(t); +} + +static void trace_flush(Trace *t, bool append) +{ + int create_dir =3D g_mkdir_with_parents("./uftrace.data", + S_IRWXU | S_IRWXG | S_IRWXO); + g_assert(create_dir =3D=3D 0); + FILE *dat =3D fopen(t->path->str, append ? "a" : "w"); + g_assert(dat); + GArray *data =3D t->t; + if (data->len) { + size_t wrote =3D fwrite(data->data, sizeof(UftraceEntry), data->le= n, dat); + g_assert(wrote =3D=3D data->len); + } + fclose(dat); + g_array_set_size(data, 0); +} + +static void trace_add_entry(Trace *t, uint64_t timestamp, uint64_t pc, + size_t depth, UftraceRecordType type) +{ + /* https://github.com/namhyung/uftrace/blob/v0.18/libmcount/record.c#L= 909 */ + const uint64_t record_magic =3D 0x5; + uint64_t data =3D type | (record_magic << 3); + data +=3D depth << 6; + data +=3D pc << 16; + UftraceEntry e =3D {.timestamp =3D timestamp, .data =3D data}; + g_array_append_val(t->t, e); + if (t->t->len * sizeof(UftraceEntry) > TRACE_FLUSH_SIZE) { + trace_flush(t, true); + } +} + +static void trace_enter_function(Trace *t, uint64_t timestamp, + uint64_t pc, size_t depth) +{ + trace_add_entry(t, timestamp, pc, depth, UFTRACE_ENTRY); +} + +static void trace_exit_function(Trace *t, uint64_t timestamp, + uint64_t pc, size_t depth) +{ + trace_add_entry(t, timestamp, pc, depth, UFTRACE_EXIT); +} + +static void trace_enter_stack(Trace *t, Callstack *cs, uint64_t timestamp) +{ + for (size_t depth =3D 1; depth <=3D callstack_depth(cs); ++depth) { + trace_enter_function(t, timestamp, callstack_at(cs, depth)->pc, de= pth); + } +} + +static void trace_exit_stack(Trace *t, Callstack *cs, uint64_t timestamp) +{ + for (size_t depth =3D callstack_depth(cs); depth > 0; --depth) { + trace_exit_function(t, timestamp, callstack_at(cs, depth)->pc, dep= th); + } +} + static uint64_t cpu_read_register64(Cpu *cpu, struct qemu_plugin_register = *reg) { GByteArray *buf =3D cpu->buf; @@ -223,7 +352,9 @@ static void track_callstack(unsigned int cpu_index, voi= d *udata) { uint64_t pc =3D (uintptr_t) udata; Cpu *cpu =3D qemu_plugin_scoreboard_find(score, cpu_index); + uint64_t timestamp =3D gettime_ns(); Callstack *cs =3D cpu->cs; + Trace *t =3D cpu->trace; =20 uint64_t fp =3D cpu->ops.get_frame_pointer(cpu); if (!fp && callstack_empty(cs)) { @@ -232,6 +363,7 @@ static void track_callstack(unsigned int cpu_index, voi= d *udata) * long as a proper call does not happen. */ callstack_push(cs, (CallstackEntry){.frame_pointer =3D fp, .pc =3D= pc}); + trace_enter_function(t, timestamp, pc, callstack_depth(cs)); return; } =20 @@ -244,7 +376,8 @@ static void track_callstack(unsigned int cpu_index, voi= d *udata) CallstackEntry caller =3D callstack_caller(cs); if (fp =3D=3D caller.frame_pointer) { /* return */ - callstack_pop(cs); + CallstackEntry e =3D callstack_pop(cs); + trace_exit_function(t, timestamp, e.pc, callstack_depth(cs)); return; } =20 @@ -252,12 +385,16 @@ static void track_callstack(unsigned int cpu_index, v= oid *udata) if (caller_fp =3D=3D top.frame_pointer) { /* call */ callstack_push(cs, (CallstackEntry){.frame_pointer =3D fp, .pc =3D= pc}); + trace_enter_function(t, timestamp, pc, callstack_depth(cs)); return; } =20 /* discontinuity, exit current stack and unwind new one */ + trace_exit_stack(t, cs, timestamp); callstack_clear(cs); + cpu_unwind_stack(cpu, fp, pc); + trace_enter_stack(t, cs, timestamp); } =20 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -297,6 +434,16 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned in= t vcpu_index) cpu->ops.init(cpu); cpu->buf =3D g_byte_array_new(); =20 + g_assert(vcpu_index < UINT32_MAX / TRACE_ID_SCALE); + /* trace_id is: cpu_number * TRACE_ID_SCALE */ + uint32_t trace_id =3D (vcpu_index + 1) * TRACE_ID_SCALE; + + g_autoptr(GString) trace_name =3D g_string_new(NULL); + g_string_append_printf(trace_name, "cpu%u", vcpu_index); + cpu->trace =3D trace_new(trace_id, trace_name); + /* create/truncate trace file */ + trace_flush(cpu->trace, false); + cpu->cs =3D callstack_new(); } =20 @@ -305,6 +452,7 @@ static void vcpu_end(unsigned int vcpu_index) Cpu *cpu =3D qemu_plugin_scoreboard_find(score, vcpu_index); g_byte_array_free(cpu->buf, true); =20 + trace_free(cpu->trace); callstack_free(cpu->cs); memset(cpu, 0, sizeof(Cpu)); } @@ -312,6 +460,8 @@ static void vcpu_end(unsigned int vcpu_index) static void at_exit(qemu_plugin_id_t id, void *data) { for (size_t i =3D 0; i < qemu_plugin_num_vcpus(); ++i) { + Cpu *cpu =3D qemu_plugin_scoreboard_find(score, i); + trace_flush(cpu->trace, true); vcpu_end(i); } =20 --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893008; cv=none; d=zohomail.com; s=zohoarc; b=me6aMdQgYgcawWqdQyZsOuM0xRUaFtFVOe7+cV9iV+QhtsBX4J10OXV6IeURvlefuUHHzW0Cgj/QIMojP/PQHszz8x6VXXv9VNKvqu3xIyDm4btGhxnBtINmUJwc5zSGXQZ2xRDUTEek7nudKkkzxqhtbMfxqyL+dJs5+XHMmVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893008; 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=KdzNx30rUo3Pw9DUxxGobILss0kFa1i4zUf9JaHJaqw=; b=APD6JCuIBoma2qM485wZT6ODiG2grva0xEL0k/tSnAvRqz8tXN1SDA1/oog4VArVQc+0ZV1Pk/mZjXS602E4DHV97MvDzx+w0r9FCie+oztoycFd4RGIUlCRZcbgg2i6ssOjq0/j4QLkg/5T3qDLlak/ZYFzpL28U2EvDS5Ir5U= 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 1758893008614599.1886424012434; Fri, 26 Sep 2025 06:23:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Lj-0008Fi-La; Fri, 26 Sep 2025 09:18:59 -0400 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 1v28Le-0008EX-3m for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:54 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450: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 1v28L1-00045L-8l for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:52 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3ece1102998so1582251f8f.2 for ; Fri, 26 Sep 2025 06:18:09 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fc5602dfdsm6967723f8f.33.2025.09.26.06.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:57 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 9D8105F7C3; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892686; x=1759497486; 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=KdzNx30rUo3Pw9DUxxGobILss0kFa1i4zUf9JaHJaqw=; b=DrzcbKBDEX/NNzPbzlxM/5JjymvgHxBESDNYnnKYTalTJuITUwmeC1+S+R8nemCmp3 x9Ep6maMbMfsBMeEeXv8rOY5lNWfN4UJ44eMy35rwK4F5So2jJEVNT7d9UWEBd+t3BYt PTNH7NO4Qc4smf1EWjF86f2HffHmHWZeI0ZB2eD9ex+rv0DnYLWJZZGMmRjVvOqMUlBB T3vf/yS29Zur5DakErWk62FmQMQXn+liLbWaWryC1PpsSdKnlplg1llYQslFdiO+mmXw rCK7yrKDhi7PRCWuGUbT2q13WJPORaqxdDVPKwaPw53KVYjGSdJvcA8JU2ImxYavps9s LVFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892686; x=1759497486; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KdzNx30rUo3Pw9DUxxGobILss0kFa1i4zUf9JaHJaqw=; b=P1s3xNV1mLLHsexNvLlcUAlFqXNiN/Xh3A3PfUF6E97D+xlIaxUJQm6GIWf3nUhYE2 x+GgC0rXwveNk/1VD9oreObutH5dEAoGCrOjDlzJHXjM5spO5EoJsun4hVoJcwX6Qz1j cnDNob/dzuHvX+LO6d4WlgArM8gd6blUU1P3dmKWjl7/ytP+6yH66rwtfUJLdF7M2wig 36y+jfU9/NNhv7R1z6s9MwJWbVaFVKTmDiP4Awuj5u0NU7rkUXvEKCcWVUSaWGL+lQPX rAEMKfTKTgn1w6GekbpibFjekeosoE0zBp8zb6ckj0dpz/c6zk/oDBCe6RFIUSb53LQg J/Kw== X-Gm-Message-State: AOJu0YyADNH+AEQEzYZQ4jaTYJTJ8aK+NBzbQuDrjj32wN3g7Xq5Rh+A V7NpF5/OBkxSt6A/K2rfqh0KiTT8owE2b+yZ/277LrNyuZ1tgE3l0xC+ObrBJXf2LF1TUCW2zp6 A4idBOrA= X-Gm-Gg: ASbGncuP0Nceoy1vZJsPhzWuM1wolBjxSgT2ymci8VlqyCmrrVKS68IvAO7uJEf2wzR n5oyqKUvAIq8nt9U/JCSxvKRRf3xIweubvRPE7Q7OP9GKHodOhI+qaVFSqp0+vDcDAB8ZjSStHD WUDHlpw+NPcNn3+ZAiJrmV0dcYrt09gdd+et9VTxUNNDOcYvJaTfy3zSnB5Z4F1DyV89uxI43vg Ckg7wqR3WKLLl5q1mdwMB/WDl9387HtGUZJxSNSL0U8Rdmsmn5iTU4wlyWA6pbXXz18Zy1ngKkI ewh7y3pjewxfTcCGMk8odyF8m/YXdpDmX6mheCSSwRbdlYW1dHIUDov3amdnUgkIOlln4t82YXF o0fOm130VU0IZ2NMjP93c/+ELzGZm4UPdXQ== X-Google-Smtp-Source: AGHT+IH7oqdsryD8xwGboUcdNnv5j+wI5Mk5w0CXJErw1t6lnah7Q6qXmWYuRRTFb9uwJiIISoaYbw== X-Received: by 2002:a05:6000:2507:b0:3ec:d740:a71b with SMTP id ffacd0b85a97d-40e47ee096cmr6529209f8f.31.1758892685744; Fri, 26 Sep 2025 06:18:05 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 20/24] contrib/plugins/uftrace: implement privilege level tracing Date: Fri, 26 Sep 2025 14:17:39 +0100 Message-ID: <20250926131744.432185-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-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: 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: 1758893011097116600 From: Pierrick Bouvier We add new option trace-privilege-level=3Dbool, which will create a separate trace for each privilege level. This allows to follow changes of privilege during execution. We implement aarch64 operations to track current privilege level accordingly. Reviewed-by: Manos Pitsidianakis Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-6-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-22-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index b9dcd531987..10abad0673c 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -46,19 +46,40 @@ typedef struct { void (*init)(Cpu *cpu); void (*end)(Cpu *cpu); uint64_t (*get_frame_pointer)(Cpu *cpu); + uint8_t (*get_privilege_level)(Cpu *cpu); + uint8_t (*num_privilege_levels)(void); + const char *(*get_privilege_level_name)(uint8_t pl); bool (*does_insn_modify_frame_pointer)(const char *disas); } CpuOps; =20 typedef struct Cpu { Trace *trace; Callstack *cs; + uint8_t privilege_level; + GArray *traces; /* Trace *traces [] */ GByteArray *buf; CpuOps ops; void *arch; } Cpu; =20 +typedef enum { + AARCH64_EL0_SECURE, + AARCH64_EL0_NONSECURE, + AARCH64_EL0_REALM, + AARCH64_EL1_SECURE, + AARCH64_EL1_NONSECURE, + AARCH64_EL1_REALM, + AARCH64_EL2_SECURE, + AARCH64_EL2_NONSECURE, + AARCH64_EL2_REALM, + AARCH64_EL3, + AARCH64_PRIVILEGE_LEVEL_MAX, +} Aarch64PrivilegeLevel; + typedef struct { struct qemu_plugin_register *reg_fp; + struct qemu_plugin_register *reg_cpsr; + struct qemu_plugin_register *reg_scr_el3; } Aarch64Cpu; =20 typedef struct { @@ -74,6 +95,7 @@ typedef enum { } UftraceRecordType; =20 static struct qemu_plugin_scoreboard *score; +static bool trace_privilege_level; static CpuOps arch_ops; =20 static uint64_t gettime_ns(void) @@ -251,6 +273,16 @@ static uint64_t cpu_read_register64(Cpu *cpu, struct q= emu_plugin_register *reg) return *((uint64_t *) buf->data); } =20 +static uint32_t cpu_read_register32(Cpu *cpu, struct qemu_plugin_register = *reg) +{ + GByteArray *buf =3D cpu->buf; + g_byte_array_set_size(buf, 0); + size_t sz =3D qemu_plugin_read_register(reg, buf); + g_assert(sz =3D=3D 4); + g_assert(buf->len =3D=3D 4); + return *((uint32_t *) buf->data); +} + static uint64_t cpu_read_memory64(Cpu *cpu, uint64_t addr) { g_assert(addr); @@ -308,6 +340,68 @@ static struct qemu_plugin_register *plugin_find_regist= er(const char *name) return NULL; } =20 +static uint8_t aarch64_num_privilege_levels(void) +{ + return AARCH64_PRIVILEGE_LEVEL_MAX; +} + +static const char *aarch64_get_privilege_level_name(uint8_t pl) +{ + switch (pl) { + case AARCH64_EL0_SECURE: return "S-EL0"; + case AARCH64_EL0_NONSECURE: return "NS-EL0"; + case AARCH64_EL0_REALM: return "R-EL0"; + case AARCH64_EL1_SECURE: return "S-EL1"; + case AARCH64_EL1_NONSECURE: return "NS-EL1"; + case AARCH64_EL1_REALM: return "R-EL1"; + case AARCH64_EL2_SECURE: return "S-EL2"; + case AARCH64_EL2_NONSECURE: return "NS-EL2"; + case AARCH64_EL2_REALM: return "R-EL2"; + case AARCH64_EL3: return "EL3"; + default: + g_assert_not_reached(); + } +} + +static uint8_t aarch64_get_privilege_level(Cpu *cpu_) +{ + Aarch64Cpu *cpu =3D cpu_->arch; + /* + * QEMU gdbstub does not provide access to CurrentEL, + * so we use CPSR instead. + */ + uint8_t el =3D cpu_read_register32(cpu_, cpu->reg_cpsr) >> 2 & 0b11; + + if (el =3D=3D 3) { + return AARCH64_EL3; + } + + uint8_t ss =3D AARCH64_EL0_SECURE; + if (!cpu->reg_scr_el3) { + ss =3D AARCH64_EL0_NONSECURE; + } + uint64_t scr_el3 =3D cpu_read_register64(cpu_, cpu->reg_scr_el3); + uint64_t ns =3D (scr_el3 >> 0) & 0b1; + uint64_t nse =3D (scr_el3 >> 62) & 0b1; + switch (nse << 1 | ns) { + case 0b00: + ss =3D AARCH64_EL0_SECURE; + break; + case 0b01: + ss =3D AARCH64_EL0_NONSECURE; + break; + case 0b11: + ss =3D AARCH64_EL0_REALM; + break; + default: + g_assert_not_reached(); + } + + const uint8_t num_ss =3D 3; + Aarch64PrivilegeLevel pl =3D el * num_ss + ss; + return pl; +} + static uint64_t aarch64_get_frame_pointer(Cpu *cpu_) { Aarch64Cpu *cpu =3D cpu_->arch; @@ -324,6 +418,10 @@ static void aarch64_init(Cpu *cpu_) "available. Please use an AArch64 cpu (or -cpu max= ).\n"); g_abort(); } + cpu->reg_cpsr =3D plugin_find_register("cpsr"); + g_assert(cpu->reg_cpsr); + cpu->reg_scr_el3 =3D plugin_find_register("SCR_EL3"); + /* scr_el3 is optional */ } =20 static void aarch64_end(Cpu *cpu) @@ -345,9 +443,34 @@ static CpuOps aarch64_ops =3D { .init =3D aarch64_init, .end =3D aarch64_end, .get_frame_pointer =3D aarch64_get_frame_pointer, + .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, .does_insn_modify_frame_pointer =3D aarch64_does_insn_modify_frame_poi= nter, }; =20 +static void track_privilege_change(unsigned int cpu_index, void *udata) +{ + Cpu *cpu =3D qemu_plugin_scoreboard_find(score, cpu_index); + uint8_t new_pl =3D cpu->ops.get_privilege_level(cpu); + + if (new_pl =3D=3D cpu->privilege_level) { + return; + } + + uint64_t pc =3D (uintptr_t) udata; + uint64_t timestamp =3D gettime_ns(); + + trace_exit_stack(cpu->trace, cpu->cs, timestamp); + callstack_clear(cpu->cs); + + cpu->privilege_level =3D new_pl; + cpu->trace =3D g_array_index(cpu->traces, Trace*, new_pl); + + cpu_unwind_stack(cpu, cpu->ops.get_frame_pointer(cpu), pc); + trace_enter_stack(cpu->trace, cpu->cs, timestamp); +} + static void track_callstack(unsigned int cpu_index, void *udata) { uint64_t pc =3D (uintptr_t) udata; @@ -400,6 +523,13 @@ static void track_callstack(unsigned int cpu_index, vo= id *udata) static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { size_t n_insns =3D qemu_plugin_tb_n_insns(tb); + uintptr_t tb_pc =3D qemu_plugin_tb_vaddr(tb); + + if (trace_privilege_level) { + qemu_plugin_register_vcpu_tb_exec_cb(tb, track_privilege_change, + QEMU_PLUGIN_CB_R_REGS, + (void *) tb_pc); + } =20 /* * Callbacks and inline instrumentation are inserted before an instruc= tion. @@ -433,18 +563,36 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned i= nt vcpu_index) =20 cpu->ops.init(cpu); cpu->buf =3D g_byte_array_new(); + cpu->traces =3D g_array_new(0, 0, sizeof(Trace *)); =20 g_assert(vcpu_index < UINT32_MAX / TRACE_ID_SCALE); - /* trace_id is: cpu_number * TRACE_ID_SCALE */ + g_assert(cpu->ops.num_privilege_levels() < TRACE_ID_SCALE); + /* trace_id is: cpu_number * TRACE_ID_SCALE + privilege_level */ uint32_t trace_id =3D (vcpu_index + 1) * TRACE_ID_SCALE; =20 - g_autoptr(GString) trace_name =3D g_string_new(NULL); - g_string_append_printf(trace_name, "cpu%u", vcpu_index); - cpu->trace =3D trace_new(trace_id, trace_name); - /* create/truncate trace file */ - trace_flush(cpu->trace, false); + if (trace_privilege_level) { + for (uint8_t pl =3D 0; pl < cpu->ops.num_privilege_levels(); ++pl)= { + g_autoptr(GString) trace_name =3D g_string_new(NULL); + g_string_append_printf(trace_name, "cpu%u %s", vcpu_index, + cpu->ops.get_privilege_level_name(pl)); + Trace *t =3D trace_new(trace_id + pl, trace_name); + g_array_append_val(cpu->traces, t); + } + } else { + g_autoptr(GString) trace_name =3D g_string_new(NULL); + g_string_append_printf(trace_name, "cpu%u", vcpu_index); + Trace *t =3D trace_new(trace_id, trace_name); + g_array_append_val(cpu->traces, t); + } + + for (size_t i =3D 0; i < cpu->traces->len; ++i) { + /* create/truncate trace files */ + Trace *t =3D g_array_index(cpu->traces, Trace*, i); + trace_flush(t, false); + } =20 cpu->cs =3D callstack_new(); + cpu->trace =3D g_array_index(cpu->traces, Trace*, cpu->privilege_level= ); } =20 static void vcpu_end(unsigned int vcpu_index) @@ -452,7 +600,12 @@ static void vcpu_end(unsigned int vcpu_index) Cpu *cpu =3D qemu_plugin_scoreboard_find(score, vcpu_index); g_byte_array_free(cpu->buf, true); =20 - trace_free(cpu->trace); + for (size_t i =3D 0; i < cpu->traces->len; ++i) { + Trace *t =3D g_array_index(cpu->traces, Trace*, i); + trace_free(t); + } + + g_array_free(cpu->traces, true); callstack_free(cpu->cs); memset(cpu, 0, sizeof(Cpu)); } @@ -461,7 +614,13 @@ static void at_exit(qemu_plugin_id_t id, void *data) { for (size_t i =3D 0; i < qemu_plugin_num_vcpus(); ++i) { Cpu *cpu =3D qemu_plugin_scoreboard_find(score, i); - trace_flush(cpu->trace, true); + for (size_t j =3D 0; j < cpu->traces->len; ++j) { + Trace *t =3D g_array_index(cpu->traces, Trace*, j); + trace_flush(t, true); + } + } + + for (size_t i =3D 0; i < qemu_plugin_num_vcpus(); ++i) { vcpu_end(i); } =20 @@ -472,6 +631,21 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, const qemu_info_t *info, int argc, char **argv) { + for (int i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); + if (g_strcmp0(tokens[0], "trace-privilege-level") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &trace_privilege_level)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + return -1; + } + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + if (!strcmp(info->target_name, "aarch64")) { arch_ops =3D aarch64_ops; } else { --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893178; cv=none; d=zohomail.com; s=zohoarc; b=ORvzQhzwvDhVTACuaueS5YBIWXoewS1GI20VYTaKApuvY+HkmAwwZ3qabyr1ArCO6+dwQ5xXjKKEOkF2EEsf3vrDRaCSuWcF9ntXnRB3wN/s0ELDaJfyZjES1a6BC+GIcjmNYHnUIyS/OgKYre1RV6PpmJre+IadmLp37BPQYP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893178; 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=hb0ZYj52Z4H3YIBHbdmNBNYsAlkaUZjOCYd1cVoXjVU=; b=g4jM0avygzb7pVfygM+SIg4PtBANWkB0FOJswZybUj4BUpmaNqUKyaPEAXZbOWwFl2RtLCn6BLaqkgH6NJ1CGhZeDMJNQYBRp3VahYHOM2ayUvIDk+A4TDhnC9V1rvC78HCj6V6JeB4QKU8G96ztGLX6RfwoTODJpNnNW7Cz3gs= 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 1758893178856857.5718069903062; Fri, 26 Sep 2025 06:26:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Q1-0006Je-96; Fri, 26 Sep 2025 09:23:26 -0400 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 1v28Py-0006Hy-Bl for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:22 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Pm-0004vb-Ib for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:22 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3f0308469a4so1397362f8f.0 for ; Fri, 26 Sep 2025 06:23:07 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fb985e080sm7036686f8f.24.2025.09.26.06.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:23:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B6E4D5F936; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892982; x=1759497782; 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=hb0ZYj52Z4H3YIBHbdmNBNYsAlkaUZjOCYd1cVoXjVU=; b=schn0+LsKqD1Hr80nWZjxIyUKXuZtmq8TW81+3tLubmJFPTtqZcbd0SHmp8a+Y+IXG bjScQ7UdEs6jpWzqiPMhCKrTbRD+cIrO23UffC/330fkgFkZOvtcuK3g7uTktiAnkI0c 2FA3IXAMCOCFH8MxPJMaUFixeoJS9O+iWVc0uSXy9CzdB9mUo6SEtyT4Zq2eVHXJI/4k RuhguE895z2KT9wlc93biuT2IJFDuwM2Cc9xzx6v39UTZYYlxqBdhucGpTnXMIFi9Uuw m/qoSaKmsuTua3/x9gfo3fIMADIWfa+lOSTcCSgE+Nab3hDLmsRx/l/7Gob2VOYPPBLH pR4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892982; x=1759497782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hb0ZYj52Z4H3YIBHbdmNBNYsAlkaUZjOCYd1cVoXjVU=; b=l2EUiI6MhRPp6d30pA4ZrnV5NgeA0cuNAwM7l03V7wgiIYZfYa46HB8Jc7wRgbqAZP Xm3hga8ffrphUVo2aNPWJSAxCwWru6+qDMZEgSaDyWs3lII1g9aEfB5uDkPf398YHtdI kYmrM5ELiM2iT2AB9IcXvZNk+h+jjr7QpxtjQSWcuN3sSMQgvnK5o8R3MlCtgvHEnLZT 8KxDlZ3hFBxtaNaNf31mGM+VOCdhpTsZmZAAtkKJFpUJEyQTU1slHepn5p/woUEm+dP1 uWBREQxaklYfkgK6udeievN5z8nJUiMOgTP18vVUzBofr1RmoIZ4oxHTvPAKinm/GlWj TOJA== X-Gm-Message-State: AOJu0YyA/cb3iBSqMM8dlXusJiChgvXTgjJaeHD3cFncSanGEXqdDP1B UTTU4P/KmjQVs9tULW2LgOcskRB2vkR3P93SbDxekVtxoiNuTE+MyJLYk4A/hn3yfzI= X-Gm-Gg: ASbGnct2gdmH10j938/o3p3phiCpOsGVYepBTsqrdiaovu0RAnivPkcC7IC+Y6cHsOh a+awi5KNy6+muPI6mHg84WVNMEHXtlpPTUdf6OttAzv/O3v+g14sjy4Be67vJXm2byRg6zLlRLo Bd/RjMP23yZ5d3mRgbsvCisoYGXyz3YiayIXmWYDSHI+B9lOAlA4czelZpF+bpVoTvUBnRPwlaM gACWaQMQe4jlOQ7XeRRKenPwlc4z6OW5YVWrdyBWO5dDI3n1+P8UBxNGFOZljlcSrJRVR6r9BKs 8+qcv9B1mwQT6s1Vv7PIkkGqOskOQSEjhdf4gmohJ6WigVSDkZWVL6Az5KhWivsN71N9EqvvUCw Whiq9Cm19XEtaYnNx32VTbz4= X-Google-Smtp-Source: AGHT+IFIXqCoT/I1ny8MwE7F+MJvu3hx5zeuoSK7KuB/SQ7eOghmAFOmdCuJ85JZGSUQ1ebDY7SArg== X-Received: by 2002:a05:6000:2dc8:b0:3ec:42ad:591 with SMTP id ffacd0b85a97d-40e4a05c535mr7023621f8f.36.1758892982392; Fri, 26 Sep 2025 06:23:02 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 21/24] contrib/plugins/uftrace: generate additional files for uftrace Date: Fri, 26 Sep 2025 14:17:40 +0100 Message-ID: <20250926131744.432185-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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, T_SPF_TEMPERROR=0.01 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: 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: 1758893181682116600 From: Pierrick Bouvier Beyond traces per cpu, uftrace expect to find some specific files. - info: contains information about machine/program run those values are not impacting uftrace behaviour (only reported by uftrace info), and we simply added empty strings. - memory mapping: how every binary is mapped in memory. For system mode, we generate an empty mapping (uftrace_symbols.py, coming in future commit, will take care of that). For user mode, we copy current /proc/self/maps. We don't need to do any special filtering, as reported addresses will necessarily concern guest program, and not QEMU and its libraries. - task: list of tasks. We present every vcpu/privilege level as a separate process, as it's the best view we can have when generating a (visual) chrome trace. Using threads is less convenient in terms of UI. Reviewed-by: Manos Pitsidianakis Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-7-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-23-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index 10abad0673c..2386cc723bc 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -118,6 +118,127 @@ static uint64_t gettime_ns(void) return now_ns; } =20 +static void uftrace_write_map(bool system_emulation) +{ + const char *path =3D "./uftrace.data/sid-0.map"; + + if (system_emulation && access(path, F_OK) =3D=3D 0) { + /* do not erase existing map in system emulation, as a custom one = might + * already have been generated by uftrace_symbols.py */ + return; + } + + FILE *sid_map =3D fopen(path, "w"); + g_assert(sid_map); + + if (system_emulation) { + fprintf(sid_map, + "# map stack on highest address possible, to prevent uftra= ce\n" + "# from considering any kernel address\n"); + fprintf(sid_map, + "ffffffffffff-ffffffffffff rw-p 00000000 00:00 0 [stack]\n"); + } else { + /* in user mode, copy /proc/self/maps instead */ + FILE *self_map =3D fopen("/proc/self/maps", "r"); + g_assert(self_map); + for (;;) { + int c =3D fgetc(self_map); + if (c =3D=3D EOF) { + break; + } + fputc(c, sid_map); + } + fclose(self_map); + } + fclose(sid_map); +} + +static void uftrace_write_task(const GArray *traces) +{ + FILE *task =3D fopen("./uftrace.data/task.txt", "w"); + g_assert(task); + for (int i =3D 0; i < traces->len; ++i) { + Trace *t =3D g_array_index(traces, Trace*, i); + fprintf(task, "SESS timestamp=3D0.0 pid=3D%"PRIu32" sid=3D0 exenam= e=3D\"%s\"\n", + t->id, t->name->str); + fprintf(task, "TASK timestamp=3D0.0 tid=3D%"PRIu32" pid=3D%"PRIu32= "\n", + t->id, t->id); + } + fclose(task); +} + +static void uftrace_write_info(const GArray *traces) +{ + g_autoptr(GString) taskinfo_tids =3D g_string_new("taskinfo:tids=3D"); + for (int i =3D 0; i < traces->len; ++i) { + Trace *t =3D g_array_index(traces, Trace*, i); + const char *delim =3D i > 0 ? "," : ""; + g_string_append_printf(taskinfo_tids, "%s%"PRIu32, delim, t->id); + } + + g_autoptr(GString) taskinfo_nr_tid =3D g_string_new("taskinfo:nr_tid= =3D"); + g_string_append_printf(taskinfo_nr_tid, "%d", traces->len); + + FILE *info =3D fopen("./uftrace.data/info", "w"); + g_assert(info); + /* + * $ uftrace dump --debug + * uftrace file header: magic =3D 4674726163652100 + * uftrace file header: version =3D 4 + * uftrace file header: header size =3D 40 + * uftrace file header: endian =3D 1 (little) + * uftrace file header: class =3D 2 (64 bit) + * uftrace file header: features =3D 0x1263 (PLTHOOK | ... + * uftrace file header: info =3D 0x7bff (EXE_NAME | ... + * <0000000000000000>: 46 74 72 61 63 65 21 00 04 00 00 00 28 00 01 = 02 + * <0000000000000010>: 63 12 00 00 00 00 00 00 ff 7b 00 00 00 00 00 = 00 + * <0000000000000020>: 00 04 00 00 00 00 00 00 + */ + const uint8_t header[] =3D {0x46, 0x74, 0x72, 0x61, 0x63, 0x65, 0x21, = 0x00, + 0x04, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x= 02, + 0x63, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x= 00, + 0xff, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x= 00, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x= 00}; + size_t wrote =3D fwrite(header, sizeof(header), 1, info); + g_assert(wrote =3D=3D 1); + const char *info_data[] =3D { + "exename:", + "build_id:0000000000000000000000000000000000000000", + "exit_status:", + "cmdline:", + "cpuinfo:lines=3D2", + "cpuinfo:nr_cpus=3D", + "cpuinfo:desc=3D", + "meminfo:", + "osinfo:lines=3D3", + "osinfo:kernel=3D", + "osinfo:hostname=3D", + "osinfo:distro=3D", + "taskinfo:lines=3D2", + taskinfo_nr_tid->str, + taskinfo_tids->str, + "usageinfo:lines=3D6", + "usageinfo:systime=3D", + "usageinfo:usrtime=3D", + "usageinfo:ctxsw=3D", + "usageinfo:maxrss=3D", + "usageinfo:pagefault=3D", + "usageinfo:iops=3D", + "loadinfo:", + "record_date:", + "elapsed_time:", + "pattern_type:regex", + "uftrace_version:", + "utc_offset:", + 0}; + const char **info_data_it =3D info_data; + while (*(info_data_it)) { + fprintf(info, "%s\n", *info_data_it); + ++info_data_it; + } + fclose(info); +} + static Callstack *callstack_new(void) { Callstack *cs =3D g_new0(Callstack, 1); @@ -612,14 +733,22 @@ static void vcpu_end(unsigned int vcpu_index) =20 static void at_exit(qemu_plugin_id_t id, void *data) { + bool system_emulation =3D (bool) data; + g_autoptr(GArray) traces =3D g_array_new(0, 0, sizeof(Trace *)); + for (size_t i =3D 0; i < qemu_plugin_num_vcpus(); ++i) { Cpu *cpu =3D qemu_plugin_scoreboard_find(score, i); for (size_t j =3D 0; j < cpu->traces->len; ++j) { Trace *t =3D g_array_index(cpu->traces, Trace*, j); trace_flush(t, true); + g_array_append_val(traces, t); } } =20 + uftrace_write_map(system_emulation); + uftrace_write_info(traces); + uftrace_write_task(traces); + for (size_t i =3D 0; i < qemu_plugin_num_vcpus(); ++i) { vcpu_end(i); } @@ -656,7 +785,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 score =3D qemu_plugin_scoreboard_new(sizeof(Cpu)); qemu_plugin_register_vcpu_init_cb(id, vcpu_init); - qemu_plugin_register_atexit_cb(id, at_exit, NULL); + qemu_plugin_register_atexit_cb(id, at_exit, (void *) info->system_emul= ation); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); =20 return 0; --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893155; cv=none; d=zohomail.com; s=zohoarc; b=lI4kFOtEYz8UdFUHpt3CIoQqBXCl1Kpv4oD78EBcY50dDY8dyr7K63mweqc58pXCmLqvcm1S8zCo6Lt3ASHYnBFpQrAwB7n2amLmoXRgQu1Nv5fAEE4AxnEzMUC0UasNcZr0wwrKn8kg7AMplAA4EWuU1p+dOdBM1p67ae54H3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893155; 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=1CsXT4XW0gMpq2CgRKHDuuLo03s2cz6MrOCSkvlsK6s=; b=Uvz5blVSPurq6MrwrOmkHHG/4tUBx4SGKpWOVPor/IIPlzuKPi4A2+6EqTnNRcOrb63CWNNU3jff/dFB+dyloaiAFl4BU44WjTiyk3NgPo2Y19NNQXw0H/giMKzDTpeV9gimA173YvRQenEb9pIrprH3tvP6nlLuB4kuylFrt7o= 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 1758893155177278.5705622279562; Fri, 26 Sep 2025 06:25:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Q1-0006KH-Ip; Fri, 26 Sep 2025 09:23:25 -0400 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 1v28Pz-0006I7-C2 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:23 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Pq-0004wM-Ss for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:22 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-46e34052bb7so20607755e9.2 for ; Fri, 26 Sep 2025 06:23:09 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e33be21casm38066685e9.2.2025.09.26.06.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:23:05 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id CEE825F937; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892987; x=1759497787; 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=1CsXT4XW0gMpq2CgRKHDuuLo03s2cz6MrOCSkvlsK6s=; b=ItKDzA0Wcg0VCPuvBgKPzxQDFy+xm1qta1f/0A/0S74iB5uqCzi2fG9OUZDrZyjSX1 96g29oOIv5Cl062DQZuotULZ8PbT8HK+uNZsd53+hjCoO3K+5FDr2I5AHlYF9R6ad5mE sZJ1Ph4hgpiyXfUeB7Kp8wqPZoJjNNaYtuCsxOA5rX88KGlm4BD0xoLD/xuwEe1PjjJx UJiyREgenfKtQI7rET70vbkognjfqkv/iKYHy5PPI8CKNzZddp34V+TjJDX36jwDaYEL x3n5mscfdPzs5MYKmD/HCsLnhp8ucPlRvprYcJETPMVTyxpk3Dd7djp9edOlRiPzYe8+ H5HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892987; x=1759497787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1CsXT4XW0gMpq2CgRKHDuuLo03s2cz6MrOCSkvlsK6s=; b=AIGib42mGd4+SHqb46ngS10hJqvURcEFi0Z8rWtbmHG0GPU/+ujf+kCR3IVyy0m1Ea 0Kabm9VMjs8VVnOeyd4SfvH1v6HiQQ3i28DxPY7lRAje0BpJ2vIa1ZsoLar9UEj4Vj1d ltrklQ2xXMc3nzJkVP2Q9l+2ovOUGAwtwkd0+GjMgK9OgBRX47iweJiwF3tmEZM1mYQD Xi1TaLRQ1t13u1hqWrFAuPSVpi3EukX3Hk68hod48qs8cTnYbdZNRAG4+2VUL17NzW3f h+MupC1MWUh88A8pxPrf+b4dru6DkbpfLq+NnaLyF6eiEVhgWglcl7F3/2mpm20dlDgH idJw== X-Gm-Message-State: AOJu0Yymx3JJgkb+nOoWNahK0eqy3DV8j7PdMe5GlemN+4DBOkrHX/ea FsxmcB5oqxecle+b4KVSO6NZ3rEO3BM+Suex3B8Rh81KSXN30/r0QdGvRTprp80E3nU= X-Gm-Gg: ASbGncuA6jah8UtvmmEkd+o+cAk737WTTQo8U2Am1mK1Ormtf2CdAktO91J2op3eGaE 4OR/iCt8QC/JBD3AMmr1EHpHNOG0WV13dcjlA5RkhbvH06gDvszVlkbgchIQItZa/+cSgp1zOWG vyF2l0nbgUgPYjBuoZWENMaJQVnTNZqPYj5n/UzFlW6fWybtySw88HfE0V11xJ00wYn5L0Qs88Y C7xvpfAGV7/zXOP3aeOWEAP6WHTDYURK5DW/R33q69aTkqdXHdY774CDBN4OFp2BijJzraO8lli UHjY5UO+Cfi1IvzWGSR0i9ZuwPrjP14JengMyTJrVSg/fh5bCjf2Xgteyrz4ZlsGQG3Ng6tQrCJ /VUE+x7hB1JvsHvknuE/OtL4= X-Google-Smtp-Source: AGHT+IEUwpE+AP/TaYfDp6K1Tih84aIrjrAO6KZLiKKPRfkEjPbVI4ebuHjqrja48tfLrLsJMKxjQA== X-Received: by 2002:a05:600c:8b16:b0:45f:2bc1:22d0 with SMTP id 5b1f17b1804b1-46e32aff787mr71465645e9.33.1758892987200; Fri, 26 Sep 2025 06:23:07 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 22/24] contrib/plugins/uftrace: implement x64 support Date: Fri, 26 Sep 2025 14:17:41 +0100 Message-ID: <20250926131744.432185-23-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.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: 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: 1758893157336116600 From: Pierrick Bouvier It's trivial to implement x64 support, as it's the same stack layout as aarch64. Reviewed-by: Manos Pitsidianakis Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-8-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-24-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index 2386cc723bc..b7d6124d2f5 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -82,6 +82,21 @@ typedef struct { struct qemu_plugin_register *reg_scr_el3; } Aarch64Cpu; =20 +typedef enum { + X64_RING0, + X64_RING1, + X64_RING2, + X64_RING3, + X64_REAL_MODE, + X64_PRIVILEGE_LEVEL_MAX, +} X64PrivilegeLevel; + +typedef struct { + struct qemu_plugin_register *reg_rbp; + struct qemu_plugin_register *reg_cs; + struct qemu_plugin_register *reg_cr0; +} X64Cpu; + typedef struct { uint64_t timestamp; uint64_t data; @@ -570,6 +585,75 @@ static CpuOps aarch64_ops =3D { .does_insn_modify_frame_pointer =3D aarch64_does_insn_modify_frame_poi= nter, }; =20 +static uint8_t x64_num_privilege_levels(void) +{ + return X64_PRIVILEGE_LEVEL_MAX; +} + +static const char *x64_get_privilege_level_name(uint8_t pl) +{ + switch (pl) { + case X64_RING0: return "Ring0"; + case X64_RING1: return "Ring1"; + case X64_RING2: return "Ring2"; + case X64_RING3: return "Ring3"; + case X64_REAL_MODE: return "RealMode"; + default: + g_assert_not_reached(); + } +} + +static uint8_t x64_get_privilege_level(Cpu *cpu_) +{ + X64Cpu *cpu =3D cpu_->arch; + uint64_t cr0 =3D cpu_read_register64(cpu_, cpu->reg_cr0); + uint64_t protected_mode =3D (cr0 >> 0) & 0b1; + if (!protected_mode) { + return X64_REAL_MODE; + } + uint32_t cs =3D cpu_read_register32(cpu_, cpu->reg_cs); + uint32_t ring_level =3D (cs >> 0) & 0b11; + return ring_level; +} + +static uint64_t x64_get_frame_pointer(Cpu *cpu_) +{ + X64Cpu *cpu =3D cpu_->arch; + return cpu_read_register64(cpu_, cpu->reg_rbp); +} + +static void x64_init(Cpu *cpu_) +{ + X64Cpu *cpu =3D g_new0(X64Cpu, 1); + cpu_->arch =3D cpu; + cpu->reg_rbp =3D plugin_find_register("rbp"); + g_assert(cpu->reg_rbp); + cpu->reg_cs =3D plugin_find_register("cs"); + g_assert(cpu->reg_cs); + cpu->reg_cr0 =3D plugin_find_register("cr0"); + g_assert(cpu->reg_cr0); +} + +static void x64_end(Cpu *cpu) +{ + g_free(cpu->arch); +} + +static bool x64_does_insn_modify_frame_pointer(const char *disas) +{ + return strstr(disas, "rbp"); +} + +static CpuOps x64_ops =3D { + .init =3D x64_init, + .end =3D x64_end, + .get_frame_pointer =3D x64_get_frame_pointer, + .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, + .does_insn_modify_frame_pointer =3D x64_does_insn_modify_frame_pointer, +}; + static void track_privilege_change(unsigned int cpu_index, void *udata) { Cpu *cpu =3D qemu_plugin_scoreboard_find(score, cpu_index); @@ -777,6 +861,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 if (!strcmp(info->target_name, "aarch64")) { arch_ops =3D aarch64_ops; + } else if (!strcmp(info->target_name, "x86_64")) { + arch_ops =3D x64_ops; } else { fprintf(stderr, "plugin uftrace: %s target is not supported\n", info->target_name); --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893126; cv=none; d=zohomail.com; s=zohoarc; b=PgJZf2OFsfsu+jtO87zFssK2tzJb8/t0Qa5wHJU32oR05ytL7ZrOUE2r9ocdzi5cFg95UKmqoAtiag7IjdZnARqeOC/lZi7eAH3mUBfRulKNFfF/9FMrrwGLGrRskecpPd7LvnKA/Ph/5hFkiuHqEDqKj589PfgAsCsKFei0d48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893126; 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=jGF9SYUysCeSMvohomWtzEmgBAlqEy7LfikuuZCnSE8=; b=UYV2NpohQyKwCB6rMjsabPlFq9+qmjZ41Ym5EEwVnkI+8JccKjhlbUtc646n6GZgQVYu0pPYs1ojJLRHXEkM23z+t0z7zITXOyL7q8m9r0MjdeFErnct0nQqklIe2BVzPZC66uovdX5Z52L+AShqlXX3VgzT7R3Pu/8IXcJMz8A= 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 1758893126512180.34269120370436; Fri, 26 Sep 2025 06:25:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Q9-0006QN-NT; Fri, 26 Sep 2025 09:23:33 -0400 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 1v28Q2-0006NP-OF for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:26 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Pq-0004wW-Vd for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:26 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-46c889b310dso17172595e9.0 for ; Fri, 26 Sep 2025 06:23:12 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e33fede76sm72062665e9.14.2025.09.26.06.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:23:05 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E52535F93D; Fri, 26 Sep 2025 14:17:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892988; x=1759497788; 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=jGF9SYUysCeSMvohomWtzEmgBAlqEy7LfikuuZCnSE8=; b=oVubruQpQzw9miH8k3GsIIFOAFWJXCeh9UgcIqcjupbosRjHDjAGHocnD7xfnTgPXl ERhjnnkpQqPoYVWlrG72UVxrstmExttVhsw7dKjnnC3w91AY6pWr7Hd2eZ6cziFsbct2 wCuE+pANbaRoScZcPcIZSuG+YQdwHTYtVXzMIUzND5stQNgxHoWHRxaYOfKvg1iynT+Q Qtq1V9z+94dqJYv/p7ZPac/jhtqE8r7GI0DS9zJdT3FS7JTQwJwb+jmSAAsTCEgKInvW JDtIYyBaP3zPU2f+/p/dcorMhMIOTSiPwIN9N/YOp7NsbPMjiONxyuHg/atMkp54EWh+ kheg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892988; x=1759497788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jGF9SYUysCeSMvohomWtzEmgBAlqEy7LfikuuZCnSE8=; b=l2H4YKqWFhS73nbtrbKc2tu0VFZGl8IzQzdd6S5uPzQsKtLnGFxX4ogfhz4dHYTiba HNsBfjqoWG8QXZEo0sNs08lmcS8lqzkayz2Mp/jvyNQG2cKzVd0HrxOuQjTdmS7ZL4g4 xFC2FjZvrL/BKNoQLHYNH29A8KnW+70r/hmt2/hTTCk6baT0gc8kEaibaHps+R3SO34m eiLhEu7hsBDpOkOBtWo2GrKoHlISqkVICT/B83dmXqWKqnh9CTzYbukqQXu87Yshv/lj l6CSE87gkrFRzejR2mcol3XKNwMvVomSeWSqkUOzIaXrYMYoUO/v/yFpYjqMKlHvk+/7 JwmQ== X-Gm-Message-State: AOJu0YzdXF8XT9Z1eBMJgRLB3oUbvGWq9KVRsYO/D2ZR98j47EsH/vQX Yg3lb/Ex4TpJAq3qxzyG17vRy08xxfWfnLhCYKHXXmUAI0Nrurg2X1dhZWdthqzaHwU= X-Gm-Gg: ASbGncvTRGGQhqBanHzm2VL4ST89Jq8EmxWf/LCcSCURtpj1cYrPS2fm6hDUzBWC72M k+ejgSRuthkjn5wdz3a3riJOrdkibRSGTHePz89/6h++sfGDVkSYSAd+IfAWH75jzjgyDEfNMZH b9oXAyMgQ1HK5Mca+Av0bGMHAjuq/FBOwvdTQNutsmy05XyvAPm7bRT47AEDhpEt2VcYwzYkqcv MSltKyH2CsA58ShdnAlS/ogIPnDMHUWBwlOQjrVYLta+hFQnj1tk69tNSuDEuzO/3RRPiVENdz+ qvtEtUX9cFdhrTBhZD8OLvfJ4v+A92l5JI93jA9HI631ybLbC6KFuo+cByju/g8bhy1L4luHF8F 5kz6uqLEYmL45laF/UUZUWxy6SVT3/9Wbmg== X-Google-Smtp-Source: AGHT+IEyGyWUW2/wdG0ovr9L6DM5NOfvi5exzft/R9C8jU7JhCsW8WP6MgkbSUZpiAWb1x3F0rYe/w== X-Received: by 2002:a05:600c:c05a:b0:46e:24a4:c247 with SMTP id 5b1f17b1804b1-46e33c37045mr51155205e9.5.1758892988038; Fri, 26 Sep 2025 06:23:08 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 23/24] contrib/plugins/uftrace_symbols.py Date: Fri, 26 Sep 2025 14:17:42 +0100 Message-ID: <20250926131744.432185-24-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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: 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: 1758893129212116600 From: Pierrick Bouvier usage: contrib/plugins/uftrace_symbols.py \ --prefix-symbols \ arm-trusted-firmware/build/qemu/debug/bl1/bl1.elf \ arm-trusted-firmware/build/qemu/debug/bl2/bl2.elf \ arm-trusted-firmware/build/qemu/debug/bl31/bl31.elf \ u-boot/u-boot:0x60000000 \ u-boot/u-boot.relocated:0x000000023f6b6000 \ linux/vmlinux Will generate symbols and memory mapping files for uftrace, allowing to have an enhanced trace, instead of raw addresses. It takes a collection of elf files, and automatically find all their symbols, and generate an ordered memory map based on that. This script uses the python (native) pyelftools module. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Acked-by: Alex Benn=C3=A9e Message-ID: <20250902075042.223990-9-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-25-alex.bennee@linaro.org> diff --git a/contrib/plugins/uftrace_symbols.py b/contrib/plugins/uftrace_s= ymbols.py new file mode 100755 index 00000000000..b49e03203c8 --- /dev/null +++ b/contrib/plugins/uftrace_symbols.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Create symbols and mapping files for uftrace. +# +# Copyright 2025 Linaro Ltd +# Author: Pierrick Bouvier +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import argparse +import elftools # pip install pyelftools +import os + +from elftools.elf.elffile import ELFFile +from elftools.elf.sections import SymbolTableSection + +def elf_func_symbols(elf): + symbol_tables =3D [(idx, s) for idx, s in enumerate(elf.iter_sections(= )) + if isinstance(s, SymbolTableSection)] + symbols =3D [] + for _, section in symbol_tables: + for _, symbol in enumerate(section.iter_symbols()): + if symbol_size(symbol) =3D=3D 0: + continue + type =3D symbol['st_info']['type'] + if type =3D=3D 'STT_FUNC' or type =3D=3D 'STT_NOTYPE': + symbols.append(symbol) + symbols.sort(key =3D lambda x: symbol_addr(x)) + return symbols + +def symbol_size(symbol): + return symbol['st_size'] + +def symbol_addr(symbol): + addr =3D symbol['st_value'] + # clamp addr to 48 bits, like uftrace entries + return addr & 0xffffffffffff + +def symbol_name(symbol): + return symbol.name + +class BinaryFile: + def __init__(self, path, map_offset): + self.fullpath =3D os.path.realpath(path) + self.map_offset =3D map_offset + with open(path, 'rb') as f: + self.elf =3D ELFFile(f) + self.symbols =3D elf_func_symbols(self.elf) + + def path(self): + return self.fullpath + + def addr_start(self): + return self.map_offset + + def addr_end(self): + last_sym =3D self.symbols[-1] + return symbol_addr(last_sym) + symbol_size(last_sym) + self.map_of= fset + + def generate_symbol_file(self, prefix_symbols): + binary_name =3D os.path.basename(self.fullpath) + sym_file_path =3D f'./uftrace.data/{binary_name}.sym' + print(f'{sym_file_path} ({len(self.symbols)} symbols)') + with open(sym_file_path, 'w') as sym_file: + # print hexadecimal addresses on 48 bits + addrx =3D "0>12x" + for s in self.symbols: + addr =3D symbol_addr(s) + addr =3D f'{addr:{addrx}}' + size =3D f'{symbol_size(s):{addrx}}' + name =3D symbol_name(s) + if prefix_symbols: + name =3D f'{binary_name}:{name}' + print(addr, size, 'T', name, file=3Dsym_file) + +def parse_parameter(p): + s =3D p.split(":") + path =3D s[0] + if len(s) =3D=3D 1: + return path, 0 + if len(s) > 2: + raise ValueError('only one offset can be set') + offset =3D s[1] + if not offset.startswith('0x'): + err =3D f'offset "{offset}" is not an hexadecimal constant. ' + err +=3D 'It should starts with "0x".' + raise ValueError(err) + offset =3D int(offset, 16) + return path, offset + +def is_from_user_mode(map_file_path): + if os.path.exists(map_file_path): + with open(map_file_path, 'r') as map_file: + if not map_file.readline().startswith('# map stack on'): + return True + return False + +def generate_map(binaries): + map_file_path =3D './uftrace.data/sid-0.map' + + if is_from_user_mode(map_file_path): + print(f'do not overwrite {map_file_path} generated from qemu-user') + return + + mappings =3D [] + + # print hexadecimal addresses on 48 bits + addrx =3D "0>12x" + + mappings +=3D ['# map stack on highest address possible, to prevent uf= trace'] + mappings +=3D ['# from considering any kernel address'] + mappings +=3D ['ffffffffffff-ffffffffffff rw-p 00000000 00:00 0 [stack= ]'] + + for b in binaries: + m =3D f'{b.addr_start():{addrx}}-{b.addr_end():{addrx}}' + m +=3D f' r--p 00000000 00:00 0 {b.path()}' + mappings.append(m) + + with open(map_file_path, 'w') as map_file: + print('\n'.join(mappings), file=3Dmap_file) + print(f'{map_file_path}') + print('\n'.join(mappings)) + +def main(): + parser =3D argparse.ArgumentParser(description=3D + 'generate symbol files for uftrace') + parser.add_argument('elf_file', nargs=3D'+', + help=3D'path to an ELF file. ' + 'Use /path/to/file:0xdeadbeef to add a mapping off= set.') + parser.add_argument('--prefix-symbols', + help=3D'prepend binary name to symbols', + action=3Dargparse.BooleanOptionalAction) + args =3D parser.parse_args() + + if not os.path.exists('./uftrace.data'): + os.mkdir('./uftrace.data') + + binaries =3D [] + for file in args.elf_file: + path, offset =3D parse_parameter(file) + b =3D BinaryFile(path, offset) + binaries.append(b) + binaries.sort(key =3D lambda b: b.addr_end()); + + for b in binaries: + b.generate_symbol_file(args.prefix_symbols) + + generate_map(binaries) + +if __name__ =3D=3D '__main__': + main() --=20 2.47.3 From nobody Sun Sep 28 14:48:18 2025 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=1758893266; cv=none; d=zohomail.com; s=zohoarc; b=U7qcdAIwLUraYOYPMgqVWYBS6bP2L9vKiWsuzodrDLkDYQj6BLJlp7utb4x3RRojOG9lob/D2e8D6Rt4JvltCJZI5wzinnUI8u1TGaKZqzFtqcSvIdBkn87+w90ezTsOc2NG2g5RO27nc1u3yiqKoVdDvvJj88DxOHYF62ETzb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758893266; 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=ig8MokYIXy0til7GLX4taqlZ5Cp0jTBRcRZcRMKzHJM=; b=cJBv+Q1712pRLsRgt0hSmAODiDgvHfS73rIkP99e2DQY6HgZGztTzjyqu3gY5hHqdAPCWiPl8m/O8n4YKiWS7sQECqs4QK6AKwnxwOr1d/i3u6V1XDD0hPViyLDNPSUlc+s5oiMG6a7d7hRXwSbbsOIQ8kC45WUe1LABATPb2D8= 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 1758893266680770.7924767024617; Fri, 26 Sep 2025 06:27:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28Q6-0006Q3-FI; Fri, 26 Sep 2025 09:23:30 -0400 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 1v28Q2-0006MJ-De for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:27 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Pq-0004vl-62 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:23:25 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-46e2e6a708fso12862995e9.0 for ; Fri, 26 Sep 2025 06:23:08 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e2a7c8531sm117831085e9.0.2025.09.26.06.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:23:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 06CA75F93E; Fri, 26 Sep 2025 14:17:47 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892984; x=1759497784; 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=ig8MokYIXy0til7GLX4taqlZ5Cp0jTBRcRZcRMKzHJM=; b=NpYDYgUyoL6fCBr3y0R5XJSfz+dP8RkR5CJsNSjZzBUuPbKcGtVUSxAB1osfjfXgnV 07n9GjGri3a+ugODN+GM4VlsuXmlp1Nyu5keTsdqC6Qq9oJG1S9uwvS8Vn/jjF+Yphoh uMcalQXYCBcEXmh/vOH8n0mjyuFAx969oRguvux7M45RMz0A3SsshdhPYhK2rNqhnCiD b3GqTD1NvkPgQVUftDCdlbKd2affW5tCL/8q2WM8Z72QfKNTUJnOCxtEJpYr8/Ny5Ov3 zo5I7Oux6J9ijqfUi+f17m2xP4JLYvgGrzJOxCx7JdNiwZHM7ljrfDKz4rS62/Y1BVBg 3Izw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892984; x=1759497784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ig8MokYIXy0til7GLX4taqlZ5Cp0jTBRcRZcRMKzHJM=; b=lQlyutwul0Or5v/IxgErvCjxgIRWhah4fLfhSfTsEw1n9ApU8FYVYzpkpYPIJKfpLY UddkDl1jOyEjKJVI7OzZhLHatkWsaWwnJvLjskPW7XT9bgszAFiuwxejKuLY3EFzVZd5 wnRF2HoLe0BPCjlfbTmFT0JVvHGCbvjQQh0RwDgsC0OW+0aPYhNTp/MSlGKJxiV45NCM TJlJahhyv6RWE3nJy5ikNLWEpQn0K9I60zeg4JR19d9nKFMn3lz6QTmmiQQSE9LEcln8 GWeOpeC+4jeGu5AgAI0IiOB5UOLPpsYNZ8lgO1BBbEofLYt3Ysz2MrGmGaX/MtihS7fu 9/RQ== X-Gm-Message-State: AOJu0YyoY9EhgtvyU6nlNg67VZ5jGThcsXbyThHFfsgAeP7eeUsFo+26 8QaEm2P5ixmW08mxiWcBKCGoA1SSjIVWxHyWO1vvOvdqnoe6chg5njDZTBJSV8apLS0= X-Gm-Gg: ASbGnculsPegeJjwj7IFMM3gLN4RvnPR22MoG5+mMM71jOAivqxM6s1bFj2nzK5Id2G MbWhxwBZw1yj2CWzI+k8Yb81nQ7YE9iyEkpA015Qa5bNfYC7BAG2g8KiGG67+8fnkZJg32U6Z7i jWk5WXeeGBqV49fdg/oHO6eOG9WWEED2VDsPKedbnyV67dfbvqWXHzbzrRXxzbKYnbW6T8ZIQ5J 0JV1vro6XGLz8+lFvk77vwJehNk13wI9DmVnXEFjQC6VaU6H8XFW6DDVy15Hr9OdE2DLq77iCyQ CM/U9z1GZswpbCSN/J9l45gCF8Qi41rGfI/xcSuRh4wCQutERza7UNaasY8fY02AwKzednx9spj YiZdkUspifmcGI8GpcEUz7mScH/H573o7yA== X-Google-Smtp-Source: AGHT+IHJ9+e+ASnXgE/YVTSM+apUUftj1NfzrZ46iuszcBmC8HaH7uPphKpsTpv0crMhFUsIJ33owg== X-Received: by 2002:a7b:c5d9:0:b0:45c:4470:271c with SMTP id 5b1f17b1804b1-46e329eb0cemr55309615e9.18.1758892983892; Fri, 26 Sep 2025 06:23:03 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 24/24] contrib/plugins/uftrace: add documentation Date: Fri, 26 Sep 2025 14:17:43 +0100 Message-ID: <20250926131744.432185-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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, 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: 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: 1758893269084116601 From: Pierrick Bouvier This documentation summarizes how to use the plugin, and present two examples of the possibilities offered by it, in system and user mode. As well, it explains how to rebuild and reproduce those examples. Reviewed-by: Manos Pitsidianakis Signed-off-by: Pierrick Bouvier Message-ID: <20250902075042.223990-10-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-26-alex.bennee@linaro.org> diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index 456d01d5b08..8a5e128f677 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -816,6 +816,205 @@ This plugin can limit the number of Instructions Per = Second that are executed:: The lower the number the more accurate time will be, but the less ef= ficient the plugin. Defaults to ips/10 =20 +Uftrace +....... + +``contrib/plugins/uftrace.c`` + +This plugin generates a binary trace compatible with +`uftrace `_. + +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. + +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, +without any additional step. +In system mode, the default memory mapping is empty, and you can generate +one (and associated symbols) using ``contrib/plugins/uftrace_symbols.py``. +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 +`_. +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 +necessarily for bare metal code. You can read this `section +` to easily build a system with frame pointe= rs. + +When tracing long scenarios (> 1 min), the generated trace can become very= long, +making it hard to extract data from it. In this case, a simple solution is= to +trace execution while generating a timestamped output log using +``qemu-system-aarch64 ... | ts "%s"``. Then, ``uftrace --time-range=3Dstar= t~end`` +can be used to reduce trace for only this part of execution. + +Performance wise, overhead compared to normal tcg execution is around x5-x= 15. + +.. list-table:: Uftrace plugin arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - trace-privilege-level=3D[on|off] + - Generate separate traces for each privilege level (Exception Level + + Security State on aarch64, Rings on x64). + +.. list-table:: uftrace_symbols.py arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - elf_file [elf_file ...] + - path to an ELF file. Use /path/to/file:0xdeadbeef to add a mapping o= ffset. + * - --prefix-symbols + - prepend binary name to symbols + +Example user trace +++++++++++++++++++ + +As an example, we can trace qemu itself running git:: + + $ ./build/qemu-aarch64 -plugin \ + build/contrib/plugins/libuftrace.so \ + ./build/qemu-aarch64 /usr/bin/git --help + + # and generate a chrome trace directly + $ uftrace dump --chrome | gzip > ~/qemu_aarch64_git_help.json.gz + +For convenience, you can download this trace `qemu_aarch64_git_help.json.gz +`_. +Download it and open this trace on https://ui.perfetto.dev/. You can zoom = in/out +using :kbd:`W`, :kbd:`A`, :kbd:`S`, :kbd:`D` keys. +Some sequences taken from this trace: + +- Loading program and its interpreter + +.. image:: https://fileserver.linaro.org/s/fie8JgX76yyL5cq/preview + :height: 200px + +- open syscall + +.. image:: https://fileserver.linaro.org/s/rsXPTeZZPza4PcE/preview + :height: 200px + +- TB creation + +.. image:: https://fileserver.linaro.org/s/GXY6NKMw5EeRCew/preview + :height: 200px + +It's usually better to use ``uftrace record`` directly. However, tracing +binaries through qemu-user can be convenient when you don't want to recomp= ile +them (``uftrace record`` requires instrumentation), as long as symbols are +present. + +Example system trace +++++++++++++++++++++ + +A full trace example (chrome trace, from instructions below) generated fro= m a +system boot can be found `here +`_. +Download it and open this trace on https://ui.perfetto.dev/. You can see c= ode +executed for all privilege levels, and zoom in/out using +:kbd:`W`, :kbd:`A`, :kbd:`S`, :kbd:`D` keys. You can find below some seque= nces +taken from this trace: + +- Two first stages of boot sequence in Arm Trusted Firmware (EL3 and S-EL1) + +.. image:: https://fileserver.linaro.org/s/kkxBS552W7nYESX/preview + :height: 200px + +- U-boot initialization (until code relocation, after which we can't track= it) + +.. image:: https://fileserver.linaro.org/s/LKTgsXNZFi5GFNC/preview + :height: 200px + +- Stat and open syscalls in kernel + +.. image:: https://fileserver.linaro.org/s/dXe4MfraKg2F476/preview + :height: 200px + +- Timer interrupt + +.. image:: https://fileserver.linaro.org/s/TM5yobYzJtP7P3C/preview + :height: 200px + +- Poweroff sequence (from kernel back to firmware, NS-EL2 to EL3) + +.. image:: https://fileserver.linaro.org/s/oR2PtyGKJrqnfRf/preview + :height: 200px + +Build and run system example +++++++++++++++++++++++++++++ + +.. _uftrace_build_system_example: + +Building a full system image with frame pointers is not trivial. + +We provide a `simple way `= _ to +build an aarch64 system, combining Arm Trusted firmware, U-boot, Linux ker= nel +and debian userland. It's based on containers (``podman`` only) and +``qemu-user-static (binfmt)`` to make sure it's easily reproducible and do= es not depend +on machine where you build it. + +You can follow the exact same instructions for a x64 system, combining edk= 2, +Linux, and Ubuntu, simply by switching to +`x86_64 `_ bra= nch. + +To build the system:: + + # Install dependencies + $ sudo apt install -y podman qemu-user-static + + $ git clone https://github.com/pbo-linaro/qemu-linux-stack + $ cd qemu-linux-stack + $ ./build.sh + + # system can be started using: + $ ./run.sh /path/to/qemu-system-aarch64 + +To generate a uftrace for a system boot from that:: + + # run true and poweroff the system + $ env INIT=3Dtrue ./run.sh path/to/qemu-system-aarch64 \ + -plugin path/to/contrib/plugins/libuftrace.so,trace-privilege-level= =3Don + + # generate symbols and memory mapping + $ path/to/contrib/plugins/uftrace_symbols.py \ + --prefix-symbols \ + arm-trusted-firmware/build/qemu/debug/bl1/bl1.elf \ + arm-trusted-firmware/build/qemu/debug/bl2/bl2.elf \ + arm-trusted-firmware/build/qemu/debug/bl31/bl31.elf \ + u-boot/u-boot:0x60000000 \ + linux/vmlinux + + # inspect trace with + $ uftrace replay + +Uftrace allows to filter the trace, and dump flamegraphs, or a chrome trac= e. +This last one is very interesting to see visually the boot process:: + + $ uftrace dump --chrome > boot.json + # Open your browser, and load boot.json on https://ui.perfetto.dev/. + +Long visual chrome traces can't be easily opened, thus, it might be +interesting to generate them around a particular point of execution:: + + # execute qemu and timestamp output log + $ env INIT=3Dtrue ./run.sh path/to/qemu-system-aarch64 \ + -plugin path/to/contrib/plugins/libuftrace.so,trace-privilege-level= =3Don |& + ts "%s" | tee exec.log + + $ cat exec.log | grep 'Run /init' + 1753122320 [ 11.834391] Run /init as init process + # init was launched at 1753122320 + + # generate trace around init execution (2 seconds): + $ uftrace dump --chrome --time-range=3D1753122320~1753122322 > init.js= on + Other emulation features ------------------------ =20 --=20 2.47.3