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>,
Xiao Guangrong <xiaoguangrong.eric@gmail.com>,
David Gibson <david@gibson.dropbear.id.au>,
Alexander Graf <agraf@suse.de>, Stefan Weil <sw@weilnetz.de>,
Eric Auger <eric.auger@redhat.com>,
David Hildenbrand <david@redhat.com>
Subject: [Qemu-devel] [PATCH v4 1/4] pc-dimm: assign and verify the "slot" property during pre_plug
Date: Wed, 1 Aug 2018 15:34:41 +0200 [thread overview]
Message-ID: <20180801133444.11269-2-david@redhat.com> (raw)
In-Reply-To: <20180801133444.11269-1-david@redhat.com>
We can assign and verify the slot before realizing and trying to plug.
reading/writing the slot property should never fail, so let's reduce
error handling a bit by using &error_abort.
To do this during pre_plug, add and use (x86, ppc) pc_dimm_pre_plug().
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/i386/pc.c | 2 ++
hw/mem/pc-dimm.c | 35 ++++++++++++++++++-----------------
hw/ppc/spapr.c | 9 ++++++++-
include/hw/mem/pc-dimm.h | 1 +
4 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 83a444472b..96be77f0dd 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1696,6 +1696,8 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
return;
}
+
+ pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), errp);
}
static void pc_memory_plug(HotplugHandler *hotplug_dev,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 65843bc52a..e56c4daef2 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -29,10 +29,27 @@
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)
+{
+ Error *local_err = NULL;
+ int slot;
+
+ slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+ &error_abort);
+ slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot,
+ machine->ram_slots, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_abort);
+ trace_mhp_pc_dimm_assigned_slot(slot);
+out:
+ error_propagate(errp, local_err);
+}
+
void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,
Error **errp)
{
- int slot;
PCDIMMDevice *dimm = PC_DIMM(dev);
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
@@ -59,22 +76,6 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,
}
trace_mhp_pc_dimm_assigned_address(addr);
- slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err);
- if (local_err) {
- goto out;
- }
-
- slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot,
- machine->ram_slots, &local_err);
- if (local_err) {
- goto out;
- }
- object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &local_err);
- if (local_err) {
- goto out;
- }
- trace_mhp_pc_dimm_assigned_slot(slot);
-
memory_device_plug_region(machine, mr, addr);
vmstate_register_ram(vmstate_mr, dev);
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 421b2dd09b..4b33e9a08e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3191,6 +3191,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_dev);
PCDIMMDevice *dimm = PC_DIMM(dev);
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+ Error *local_err = NULL;
MemoryRegion *mr;
uint64_t size;
Object *memdev;
@@ -3216,7 +3217,13 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
memdev = object_property_get_link(OBJECT(dimm), PC_DIMM_MEMDEV_PROP,
&error_abort);
pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(memdev));
- spapr_check_pagesize(spapr, pagesize, errp);
+ spapr_check_pagesize(spapr, pagesize, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), errp);
}
struct sPAPRDIMMState {
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 26ebb7d5e9..7b120416d1 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -79,6 +79,7 @@ typedef struct PCDIMMDeviceClass {
Error **errp);
} PCDIMMDeviceClass;
+void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, Error **errp);
void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,
Error **errp);
void pc_dimm_unplug(DeviceState *dev, MachineState *machine);
--
2.17.1
next prev parent reply other threads:[~2018-08-01 13:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-01 13:34 [Qemu-devel] [PATCH v4 0/4] pc-dimm: pre_plug "slot" and "addr" assignment David Hildenbrand
2018-08-01 13:34 ` David Hildenbrand [this message]
2018-08-01 13:34 ` [Qemu-devel] [PATCH v4 2/4] util/oslib-win32: indicate alignment for qemu_anon_ram_alloc() David Hildenbrand
2018-08-02 10:18 ` Igor Mammedov
2018-08-01 13:34 ` [Qemu-devel] [PATCH v4 3/4] pc: drop memory region alignment check for 0 David Hildenbrand
2018-08-01 13:34 ` [Qemu-devel] [PATCH v4 4/4] pc-dimm: assign and verify the "addr" property during pre_plug David Hildenbrand
2018-08-02 10:17 ` [Qemu-devel] [PATCH v4 0/4] pc-dimm: pre_plug "slot" and "addr" assignment Igor Mammedov
2018-08-02 10:30 ` David Hildenbrand
2018-08-20 16:15 ` David Hildenbrand
2018-08-21 11:01 ` Paolo Bonzini
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=20180801133444.11269-2-david@redhat.com \
--to=david@redhat.com \
--cc=agraf@suse.de \
--cc=david@gibson.dropbear.id.au \
--cc=ehabkost@redhat.com \
--cc=eric.auger@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 \
--cc=sw@weilnetz.de \
--cc=xiaoguangrong.eric@gmail.com \
/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).