device-core: use atomic_set on .realized property
commita23151e8cc8cc08546252dc9c7671171d9c44615
authorMaxim Levitsky <mlevitsk@redhat.com>
Tue, 6 Oct 2020 12:39:00 +0000 (6 15:39 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 12 Oct 2020 15:50:51 +0000 (12 11:50 -0400)
treeccc528af0d0419034c5dfee617f596f0751faf6d
parent42a90a899e70f5fbef2b5a117535acaa0bc1f5ad
device-core: use atomic_set on .realized property

Some code might race with placement of new devices on a bus.
We currently first place a (unrealized) device on the bus
and then realize it.

As a workaround, users that scan the child device list, can
check the realized property to see if it is safe to access such a device.
Use an atomic write here too to aid with this.

A separate discussion is what to do with devices that are unrealized:
It looks like for this case we only call the hotplug handler's unplug
callback and its up to it to unrealize the device.
An atomic operation doesn't cause harm for this code path though.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20200913160259.32145-6-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20201006123904.610658-10-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/core/qdev.c
include/hw/qdev-core.h