From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, Eduardo Habkost <ehabkost@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>,
David Gibson <david@gibson.dropbear.id.au>,
Alexander Graf <agraf@suse.de>,
David Hildenbrand <david@redhat.com>
Subject: [Qemu-devel] [PATCH v1 4/4] pc-dimm: assign and verify the "addr" property during pre_plug
Date: Mon, 18 Jun 2018 16:48:00 +0200 [thread overview]
Message-ID: <20180618144800.555-5-david@redhat.com> (raw)
In-Reply-To: <20180618144800.555-1-david@redhat.com>
We can assign and verify the slot before realizing and trying to plug.
reading/writing the address property should never fail, so let's reduce
error handling a bit by using &error_abort. Getting access to the memory
region now might however fail. So forward errors from
get_memory_region() properly.
Keep tracing the assigned address for now in the plug code, as that's the
point we are sure plugging succeeded and the address willa ctually be
used.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/mem/pc-dimm.c | 43 ++++++++++++++++++++++---------------------
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 9198104d34..42c4d0b750 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -31,7 +31,11 @@ static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, Error **errp)
{
+ PCDIMMDevice *dimm = PC_DIMM(dev);
+ PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
Error *local_err = NULL;
+ uint64_t align, addr;
+ MemoryRegion *mr;
int slot;
slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
@@ -43,6 +47,22 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, Error **errp)
}
object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_abort);
trace_mhp_pc_dimm_assigned_slot(slot);
+
+ mr = ddc->get_memory_region(dimm, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ align = memory_device_get_align(machine, mr);
+
+ addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
+ &error_abort);
+ addr = memory_device_get_free_addr(machine, !addr ? NULL : &addr, align,
+ memory_region_size(mr), &local_err);
+ if (local_err) {
+ goto out;
+ }
+ object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP,
+ &error_abort);
out:
error_propagate(errp, local_err);
}
@@ -54,33 +74,14 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp)
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
&error_abort);
MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
- const uint64_t align = memory_device_get_align(machine, mr);
- Error *local_err = NULL;
uint64_t addr;
- addr = object_property_get_uint(OBJECT(dimm),
- PC_DIMM_ADDR_PROP, &local_err);
- if (local_err) {
- goto out;
- }
-
- addr = memory_device_get_free_addr(machine, !addr ? NULL : &addr, align,
- memory_region_size(mr), &local_err);
- if (local_err) {
- goto out;
- }
-
- object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err);
- if (local_err) {
- goto out;
- }
+ addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
+ &error_abort);
trace_mhp_pc_dimm_assigned_address(addr);
memory_device_plug_region(machine, mr, addr);
vmstate_register_ram(vmstate_mr, dev);
-
-out:
- error_propagate(errp, local_err);
}
void pc_dimm_unplug(DeviceState *dev, MachineState *machine)
--
2.17.1
prev parent reply other threads:[~2018-06-18 14:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-18 14:47 [Qemu-devel] [PATCH v1 0/4] pc-dimm: pre_plug "slot" and "addr" assignment David Hildenbrand
2018-06-18 14:47 ` [Qemu-devel] [PATCH v1 1/4] pc-dimm: assign and verify the "slot" property during pre_plug David Hildenbrand
2018-06-19 0:14 ` David Gibson
2018-06-19 15:48 ` Igor Mammedov
2018-06-18 14:47 ` [Qemu-devel] [PATCH v1 2/4] machine: factor out enforce_aligned_dimm into memory_device_align David Hildenbrand
2018-06-19 15:59 ` Igor Mammedov
2018-06-19 17:06 ` David Hildenbrand
2018-06-20 14:58 ` David Hildenbrand
2018-06-26 15:03 ` Igor Mammedov
2018-06-28 10:41 ` David Hildenbrand
2018-06-18 14:47 ` [Qemu-devel] [PATCH v1 3/4] pc-dimm/memory-device: detect alignment internally David Hildenbrand
2018-06-18 14:48 ` David Hildenbrand [this message]
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=20180618144800.555-5-david@redhat.com \
--to=david@redhat.com \
--cc=agraf@suse.de \
--cc=david@gibson.dropbear.id.au \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=rth@twiddle.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.