From nobody Mon Feb 9 18:44:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1680533230; cv=none; d=zohomail.com; s=zohoarc; b=Lr5USG+a37LKopwLrvcT4gzZXBkBPAMfSSNthnAsAISOcIdAXvNZMV6ApQ5yDC44ER+qIIjCxs8d43O8OXr2nWaIvTw9vViNtkgalSgvYjM9KwkOGWCXtKmVdttyx/66+y/doIIeVLvdpP4KuhZtYnAAThdLNJ5CdKjguW1PlLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680533230; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UJID9GmOx2jzlUGH47d3z9T6Y9jGm7kH5S4i27q1feA=; b=O239ChviUDsOnbCSh8VVhMroD4Ij6ODH3JyYR316Cm7sfqZvT4CSZIKjkQz6+/52Z7E8uUAu5jVnJasdDdpEQlM8y+QR1+wduiEg7jozaqnQwuaBVo/RkG0KHtJYqcklY/fdMr6M50pUOL+KW2WAeYiGhD+tegvKOHMhzDyo9DI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1680533230591897.0971762995138; Mon, 3 Apr 2023 07:47:10 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-182-EfZXjZ5WNkSTLCjcz-Rh8A-1; Mon, 03 Apr 2023 10:47:06 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8D4DB185A7B3; Mon, 3 Apr 2023 14:47:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4D13C15E62; Mon, 3 Apr 2023 14:47:02 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 59D001946A4C; Mon, 3 Apr 2023 14:46:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1BDB319465A8 for ; Mon, 3 Apr 2023 14:46:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0F024440D8; Mon, 3 Apr 2023 14:46:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0702F35453 for ; Mon, 3 Apr 2023 14:46:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D6A242A5957F for ; Mon, 3 Apr 2023 14:46:45 +0000 (UTC) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-EavZx-YVOTqqlm6tL5N4ow-1; Mon, 03 Apr 2023 10:46:41 -0400 Received: by mail-wm1-f45.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so20010523wmq.4 for ; Mon, 03 Apr 2023 07:46:41 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id p4-20020a056000018400b002c56013c07fsm9786747wrx.109.2023.04.03.07.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 07:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680533229; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UJID9GmOx2jzlUGH47d3z9T6Y9jGm7kH5S4i27q1feA=; b=a6eb3cRx1QMvsikOuuwk0NdjxbKyxDGVrFSUtRLY6ZAGuea/ufGsysopBJVXVjkYEeYQ6Z nnLexSEZEk8IHP7NVCZ1u4fEW/+thx7Mjjy90Oah7QKjpHRatAqCT/0+jxQbgxYbwxQy2V AjrREjzs6oU/vKwR8QHRMKXy44xSYJk= X-MC-Unique: EfZXjZ5WNkSTLCjcz-Rh8A-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: EavZx-YVOTqqlm6tL5N4ow-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680533200; 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=UJID9GmOx2jzlUGH47d3z9T6Y9jGm7kH5S4i27q1feA=; b=5R4Ind7BAmXY4hOnZab8xmP/W7MeL+paJ4rM+Lm4E5iLiivABgXnk+PA0RRwuj697C n8r4jfhXpbkWLWNYgtnMz7vMOKPNTsyHhZ1BJNyFqhfAXeGwmZF81ifhqOblh1lXDgtx pDlSEQWf/+4Z5TJNUsDazZJYjOjgq6KVu8mHAVb4Nfgfn8cEQQLzHsGbd0pPXYx5Kob6 QqffInjHfrYCtNLLis9tJ5sEqm7Yo5XUddH5tGpfpFjVPyMbEsdYXWj+J4uIvEBLMd/E 712PNxQBAs2lY3DxUpk571Z5uHNqmYIhlC1YJHtVKANJ0W+R9owweeKwP9HoDKMjND5t 73TQ== X-Gm-Message-State: AO0yUKXxHPSpJZvTSs1CQTUSoczHnweBs2uMFOHSFuS6Ndi4vSnDHGG8 Yaonw6+fVIKAkrscHdsLa9Itvw== X-Google-Smtp-Source: AK7set9KDD8tN1VBsX/GUzDuTxJfCdcywmrMsdFsnzsPimP6m/hpnsw3K0e99ZsORsT75JS0/vLKcg== X-Received: by 2002:a1c:7303:0:b0:3ed:e715:1784 with SMTP id d3-20020a1c7303000000b003ede7151784mr28264824wmb.15.1680533200013; Mon, 03 Apr 2023 07:46:40 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 01/10] make one-insn-per-tb an accel option Date: Mon, 3 Apr 2023 15:46:28 +0100 Message-Id: <20230403144637.2949366-2-peter.maydell@linaro.org> In-Reply-To: <20230403144637.2949366-1-peter.maydell@linaro.org> References: <20230403144637.2949366-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: libvir-list@redhat.com, Kyle Evans , Richard Henderson , Markus Armbruster , "Dr. David Alan Gilbert" , Eric Blake , Warner Losh , Laurent Vivier Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: linaro.org Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1680533231967100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This commit adds 'one-insn-per-tb' as a property on the TCG accelerator object, so you can enable it with -accel tcg,one-insn-per-tb=3Don It has the same behaviour as the existing '-singlestep' command line option. We use a different name because 'singlestep' has always been a confusing choice, because it doesn't have anything to do with single-stepping the CPU. What it does do is force TCG emulation to put one guest instruction in each TB, which can be useful in some situations (such as analysing debug logs). The existing '-singlestep' commandline options are decoupled from the global 'singlestep' variable and instead now are syntactic sugar for setting the accel property. (These can then go away after a deprecation period.) The global variable remains for the moment as: * what the TCG code looks at to change its behaviour * what HMP and QMP use to query and set the behaviour In the following commits we'll clean those up to not directly look at the global variable. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- accel/tcg/tcg-all.c | 21 +++++++++++++++++++++ bsd-user/main.c | 8 ++++++-- linux-user/main.c | 8 ++++++-- softmmu/vl.c | 17 +++++++++++++++-- qemu-options.hx | 7 +++++++ 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 5dab1ae9dd3..fcf361c8db6 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -42,6 +42,7 @@ struct TCGState { AccelState parent_obj; =20 bool mttcg_enabled; + bool one_insn_per_tb; int splitwx_enabled; unsigned long tb_size; }; @@ -208,6 +209,20 @@ static void tcg_set_splitwx(Object *obj, bool value, E= rror **errp) s->splitwx_enabled =3D value; } =20 +static bool tcg_get_one_insn_per_tb(Object *obj, Error **errp) +{ + TCGState *s =3D TCG_STATE(obj); + return s->one_insn_per_tb; +} + +static void tcg_set_one_insn_per_tb(Object *obj, bool value, Error **errp) +{ + TCGState *s =3D TCG_STATE(obj); + s->one_insn_per_tb =3D value; + /* For the moment, set the global also: this changes the behaviour */ + singlestep =3D value; +} + static int tcg_gdbstub_supported_sstep_flags(void) { /* @@ -245,6 +260,12 @@ static void tcg_accel_class_init(ObjectClass *oc, void= *data) tcg_get_splitwx, tcg_set_splitwx); object_class_property_set_description(oc, "split-wx", "Map jit pages into separate RW and RX regions"); + + object_class_property_add_bool(oc, "one-insn-per-tb", + tcg_get_one_insn_per_tb, + tcg_set_one_insn_per_tb); + object_class_property_set_description(oc, "one-insn-per-tb", + "Only put one guest insn in each translation block"); } =20 static const TypeInfo tcg_accel_type =3D { diff --git a/bsd-user/main.c b/bsd-user/main.c index babc3b009b6..09b84da190c 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -50,6 +50,7 @@ #include "target_arch_cpu.h" =20 int singlestep; +static bool opt_one_insn_per_tb; uintptr_t guest_base; bool have_guest_base; /* @@ -386,7 +387,7 @@ int main(int argc, char **argv) } else if (!strcmp(r, "seed")) { seed_optarg =3D optarg; } else if (!strcmp(r, "singlestep")) { - singlestep =3D 1; + opt_one_insn_per_tb =3D true; } else if (!strcmp(r, "strace")) { do_strace =3D 1; } else if (!strcmp(r, "trace")) { @@ -444,9 +445,12 @@ int main(int argc, char **argv) =20 /* init tcg before creating CPUs and to get qemu_host_page_size */ { - AccelClass *ac =3D ACCEL_GET_CLASS(current_accel()); + AccelState *accel =3D current_accel(); + AccelClass *ac =3D ACCEL_GET_CLASS(accel); =20 accel_init_interfaces(ac); + object_property_set_bool(OBJECT(accel), "one-insn-per-tb", + opt_one_insn_per_tb, &error_abort); ac->init_machine(NULL); } cpu =3D cpu_create(cpu_type); diff --git a/linux-user/main.c b/linux-user/main.c index fe03293516a..489694ad654 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -69,6 +69,7 @@ char *exec_path; char real_exec_path[PATH_MAX]; =20 int singlestep; +static bool opt_one_insn_per_tb; static const char *argv0; static const char *gdbstub; static envlist_t *envlist; @@ -411,7 +412,7 @@ static void handle_arg_reserved_va(const char *arg) =20 static void handle_arg_singlestep(const char *arg) { - singlestep =3D 1; + opt_one_insn_per_tb =3D true; } =20 static void handle_arg_strace(const char *arg) @@ -777,9 +778,12 @@ int main(int argc, char **argv, char **envp) =20 /* init tcg before creating CPUs and to get qemu_host_page_size */ { - AccelClass *ac =3D ACCEL_GET_CLASS(current_accel()); + AccelState *accel =3D current_accel(); + AccelClass *ac =3D ACCEL_GET_CLASS(accel); =20 accel_init_interfaces(ac); + object_property_set_bool(OBJECT(accel), "one-insn-per-tb", + opt_one_insn_per_tb, &error_abort); ac->init_machine(NULL); } cpu =3D cpu_create(cpu_type); diff --git a/softmmu/vl.c b/softmmu/vl.c index ea20b23e4c8..492b5fe65e6 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -182,6 +182,7 @@ static const char *log_file; static bool list_data_dirs; static const char *qtest_chrdev; static const char *qtest_log; +static bool opt_one_insn_per_tb; =20 static int has_defaults =3D 1; static int default_serial =3D 1; @@ -2220,7 +2221,19 @@ static int do_configure_accelerator(void *opaque, Qe= muOpts *opts, Error **errp) qemu_opt_foreach(opts, accelerator_set_property, accel, &error_fatal); - + /* + * If legacy -singlestep option is set, honour it for TCG and + * silently ignore for any other accelerator (which is how this + * option has always behaved). + */ + if (opt_one_insn_per_tb) { + /* + * This will always succeed for TCG, and we want to ignore + * the error from trying to set a nonexistent property + * on any other accelerator. + */ + object_property_set_bool(OBJECT(accel), "one-insn-per-tb", true, N= ULL); + } ret =3D accel_init_machine(accel, current_machine); if (ret < 0) { if (!qtest_with_kvm || ret !=3D -ENOENT) { @@ -2955,7 +2968,7 @@ void qemu_init(int argc, char **argv) qdict_put_str(machine_opts_dict, "firmware", optarg); break; case QEMU_OPTION_singlestep: - singlestep =3D 1; + opt_one_insn_per_tb =3D true; break; case QEMU_OPTION_S: autostart =3D 0; diff --git a/qemu-options.hx b/qemu-options.hx index 59bdf67a2c5..1dffd36884e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -182,6 +182,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, " igd-passthru=3Don|off (enable Xen integrated Intel gr= aphics passthrough, default=3Doff)\n" " kernel-irqchip=3Don|off|split controls accelerated ir= qchip support (default=3Don)\n" " kvm-shadow-mem=3Dsize of KVM shadow MMU in bytes\n" + " one-insn-per-tb=3Don|off (one guest instruction per T= CG translation block)\n" " split-wx=3Don|off (enable TCG split w^x mapping)\n" " tb-size=3Dn (TCG translation block cache size)\n" " dirty-ring-size=3Dn (KVM dirty ring GFN count, defaul= t 0)\n" @@ -210,6 +211,12 @@ SRST ``kvm-shadow-mem=3Dsize`` Defines the size of the KVM shadow MMU. =20 + ``one-insn-per-tb=3Don|off`` + Makes the TCG accelerator put only one guest instruction into + each translation block. This slows down emulation a lot, but + can be useful in some situations, such as when trying to analyse + the logs produced by the ``-d`` option. + ``split-wx=3Don|off`` Controls the use of split w^x mapping for the TCG code generation buffer. Some operating systems require this to be enabled, and in --=20 2.34.1