From: "Cédric Le Goater" <clg@redhat.com>
To: eric.auger@redhat.com, peterx@redhat.com, qemu-devel@nongnu.org
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Alex Williamson <alex.williamson@redhat.com>,
Igor Mammedov <imammedo@redhat.com>
Subject: Re: [PATCH 2/4] reset: Allow multiple stages of system resets
Date: Wed, 17 Jan 2024 14:58:45 +0100 [thread overview]
Message-ID: <00e2dc08-c6a3-4e7c-aba3-187d281b71b0@redhat.com> (raw)
In-Reply-To: <1bc3d59d-41a6-4ca7-9d9b-ee6ba6639bd0@redhat.com>
On 1/17/24 11:28, Eric Auger wrote:
> Hi Peter,
> On 1/17/24 10:15, peterx@redhat.com wrote:
>> From: Peter Xu <peterx@redhat.com>
>>
>> QEMU resets do not have a way to order reset hooks. Add one coarse grained
>> reset stage so that some devices can be reset later than some others.
> I would precise that the lowest stage has the highest priority and is
> handled first.
yes. May be add an enum like we have for migration :
typedef enum {
MIG_PRI_DEFAULT = 0,
MIG_PRI_IOMMU, /* Must happen before PCI devices */
MIG_PRI_PCI_BUS, /* Must happen before IOMMU */
MIG_PRI_VIRTIO_MEM, /* Must happen before IOMMU */
MIG_PRI_GICV3_ITS, /* Must happen before PCI devices */
MIG_PRI_GICV3, /* Must happen before the ITS */
MIG_PRI_MAX,
} MigrationPriority;
I think it would help understand the reset ordering and maintenance
when grepping qemu_register_reset_one().
Thanks,
C.
>>
>> Signed-off-by: Peter Xu <peterx@redhat.com>
>> ---
>> include/sysemu/reset.h | 5 ++++
>> hw/core/reset.c | 60 +++++++++++++++++++++++++++++++-----------
>> 2 files changed, 49 insertions(+), 16 deletions(-)
>>
>> diff --git a/include/sysemu/reset.h b/include/sysemu/reset.h
>> index 609e4d50c2..0de697ce9f 100644
>> --- a/include/sysemu/reset.h
>> +++ b/include/sysemu/reset.h
>> @@ -5,9 +5,14 @@
>>
>> typedef void QEMUResetHandler(void *opaque);
>>
>> +#define QEMU_RESET_STAGES_N 2
>> +
>> void qemu_register_reset(QEMUResetHandler *func, void *opaque);
>> +void qemu_register_reset_one(QEMUResetHandler *func, void *opaque,
>> + bool skip_snap, int stage);
>> void qemu_register_reset_nosnapshotload(QEMUResetHandler *func, void *opaque);
>> void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
>> +void qemu_unregister_reset_one(QEMUResetHandler *func, void *opaque, int stage);
>> void qemu_devices_reset(ShutdownCause reason);
>>
>> #endif
>> diff --git a/hw/core/reset.c b/hw/core/reset.c
>> index 8cf60b2b09..a84c9bee84 100644
>> --- a/hw/core/reset.c
>> +++ b/hw/core/reset.c
>> @@ -36,55 +36,83 @@ typedef struct QEMUResetEntry {
>> bool skip_on_snapshot_load;
>> } QEMUResetEntry;
>>
>> -static QTAILQ_HEAD(, QEMUResetEntry) reset_handlers =
>> - QTAILQ_HEAD_INITIALIZER(reset_handlers);
>> +typedef QTAILQ_HEAD(QEMUResetList, QEMUResetEntry) QEMUResetList;
>> +static QEMUResetList reset_handlers[QEMU_RESET_STAGES_N];
>>
>> -static void qemu_register_reset_one(QEMUResetHandler *func, void *opaque,
>> - bool skip_snap)
>> +static void __attribute__((__constructor__)) qemu_reset_handlers_init(void)
>> +{
>> + QEMUResetList *head;
>> + int i = 0;
> nit: you may put the declarations within the block
>> +
>> + for (i = 0; i < QEMU_RESET_STAGES_N; i++) {
>> + head = &reset_handlers[i];
>> + QTAILQ_INIT(head);
>> + }
>> +}
>> +
>> +void qemu_register_reset_one(QEMUResetHandler *func, void *opaque,
>> + bool skip_snap, int stage)
>> {
>> QEMUResetEntry *re = g_new0(QEMUResetEntry, 1);
>> + QEMUResetList *head;
>> +
>> + assert(stage >= 0 && stage < QEMU_RESET_STAGES_N);
>> + head = &reset_handlers[stage];
>>
>> re->func = func;
>> re->opaque = opaque;
>> re->skip_on_snapshot_load = skip_snap;
>> - QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
>> + QTAILQ_INSERT_TAIL(head, re, entry);
>> }
>>
>> void qemu_register_reset(QEMUResetHandler *func, void *opaque)
>> {
>> - /* By default, do not skip during load of a snapshot */
> Shouldn't the above comment stay since the statement is not affected by
> this patch? Or remove it in previous patch?
>> - qemu_register_reset_one(func, opaque, false);
>> + qemu_register_reset_one(func, opaque, false, 0);
>> }
>>
>> void qemu_register_reset_nosnapshotload(QEMUResetHandler *func, void *opaque)
>> {
>> - qemu_register_reset_one(func, opaque, true);
>> + qemu_register_reset_one(func, opaque, true, 0);
>> }
>>
>> -void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
>> +void qemu_unregister_reset_one(QEMUResetHandler *func, void *opaque, int stage)
>> {
>> + QEMUResetList *head;
>> QEMUResetEntry *re;
>>
>> - QTAILQ_FOREACH(re, &reset_handlers, entry) {
>> + assert(stage >= 0 && stage < QEMU_RESET_STAGES_N);
>> + head = &reset_handlers[stage];
>> +
>> + QTAILQ_FOREACH(re, head, entry) {
>> if (re->func == func && re->opaque == opaque) {
>> - QTAILQ_REMOVE(&reset_handlers, re, entry);
>> + QTAILQ_REMOVE(head, re, entry);
>> g_free(re);
>> return;
>> }
>> }
>> }
>>
>> +void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
>> +{
>> + qemu_unregister_reset_one(func, opaque, 0);
>> +}
>> +
>> void qemu_devices_reset(ShutdownCause reason)
>> {
>> QEMUResetEntry *re, *nre;
>> + QEMUResetList *head;
>> + int stage;
>>
>> /* reset all devices */
>> - QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
>> - if (reason == SHUTDOWN_CAUSE_SNAPSHOT_LOAD &&
>> - re->skip_on_snapshot_load) {
>> - continue;
>> + for (stage = 0; stage < QEMU_RESET_STAGES_N; stage++) {
>> + head = &reset_handlers[stage];
>> + QTAILQ_FOREACH_SAFE(re, head, entry, nre) {
>> + if (reason == SHUTDOWN_CAUSE_SNAPSHOT_LOAD &&
>> + re->skip_on_snapshot_load) {
>> + continue;
>> + }
>> + re->func(re->opaque);
>> }
>> - re->func(re->opaque);
>> }
>> }
>>
> Thanks
>
> Eric
>
>
next prev parent reply other threads:[~2024-01-17 13:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-17 9:15 [PATCH 0/4] intel_iommu: Reset vIOMMU after all the rest of devices peterx
2024-01-17 9:15 ` [PATCH 1/4] reset: qemu_register_reset_one() peterx
2024-01-17 10:29 ` Eric Auger
2024-01-17 9:15 ` [PATCH 2/4] reset: Allow multiple stages of system resets peterx
2024-01-17 10:28 ` Eric Auger
2024-01-17 13:58 ` Cédric Le Goater [this message]
2024-01-17 17:46 ` Peter Maydell
2024-01-18 15:53 ` Philippe Mathieu-Daudé
2024-01-18 16:15 ` Peter Maydell
2024-01-19 11:10 ` Peter Xu
2024-01-17 9:15 ` [PATCH 3/4] intel_iommu: Tear down address spaces before IOMMU reset peterx
2024-01-17 10:29 ` Eric Auger
2024-01-18 8:09 ` Philippe Mathieu-Daudé
2024-01-17 9:15 ` [PATCH 4/4] intel_iommu: Reset vIOMMU at the last stage of system reset peterx
2024-01-17 10:38 ` Eric Auger
2024-01-17 10:29 ` [PATCH 0/4] intel_iommu: Reset vIOMMU after all the rest of devices Eric Auger
2024-01-19 10:46 ` Peter Xu
2025-01-23 9:16 ` Eric Auger
2025-01-23 17:57 ` Peter Xu
2025-01-23 18:02 ` Eric Auger
2025-01-29 18:22 ` Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=00e2dc08-c6a3-4e7c-aba3-187d281b71b0@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=eric.auger@redhat.com \
--cc=imammedo@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).