All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Eduardo Habkost <ehabkost@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-ppc@nongnu.org, Pankaj Gupta <pagupta@redhat.com>,
	Alexander Graf <agraf@suse.de>, Cornelia Huck <cohuck@redhat.com>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 12/14] memory-device: factor out pre-plug into hotplug handler
Date: Thu, 7 Jun 2018 17:00:12 +0200	[thread overview]
Message-ID: <20180607170012.65ddd90b@redhat.com> (raw)
In-Reply-To: <5f80f3a1-2d40-c197-ebea-636944366d4d@redhat.com>

On Mon, 4 Jun 2018 13:45:38 +0200
David Hildenbrand <david@redhat.com> wrote:

> On 01.06.2018 13:17, Igor Mammedov wrote:
> > On Thu, 17 May 2018 10:15:25 +0200
> > David Hildenbrand <david@redhat.com> wrote:
> >   
> >> Let's move all pre-plug checks we can do without the device being
> >> realized into the applicable hotplug handler for pc and spapr.
> >>
> >> Signed-off-by: David Hildenbrand <david@redhat.com>
> >> ---
> >>  hw/i386/pc.c                   | 11 +++++++
> >>  hw/mem/memory-device.c         | 72 +++++++++++++++++++-----------------------
> >>  hw/ppc/spapr.c                 | 11 +++++++
> >>  include/hw/mem/memory-device.h |  2 ++
> >>  4 files changed, 57 insertions(+), 39 deletions(-)
> >>
> >> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> >> index 8bc41ef24b..61f1537e14 100644
> >> --- a/hw/i386/pc.c
> >> +++ b/hw/i386/pc.c
> >> @@ -2010,6 +2010,16 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
> >>  {
> >>      Error *local_err = NULL;
> >>  
> >> +    /* first stage hotplug handler */
> >> +    if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) {
> >> +        memory_device_pre_plug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev),
> >> +                               &local_err);
> >> +    }
> >> +
> >> +    if (local_err) {
> >> +        goto out;
> >> +    }
> >> +
> >>      /* final stage hotplug handler */
> >>      if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
> >>          pc_cpu_pre_plug(hotplug_dev, dev, &local_err);
> >> @@ -2017,6 +2027,7 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
> >>          hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev,
> >>                                   &local_err);
> >>      }
> >> +out:
> >>      error_propagate(errp, local_err);
> >>  }
> >>  
> >> diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
> >> index 361d38bfc5..d22c91993f 100644
> >> --- a/hw/mem/memory-device.c
> >> +++ b/hw/mem/memory-device.c
> >> @@ -68,58 +68,26 @@ static int memory_device_used_region_size(Object *obj, void *opaque)
> >>      return 0;
> >>  }
> >>  
> >> -static void memory_device_check_addable(MachineState *ms, uint64_t size,
> >> -                                        Error **errp)
> >> -{
> >> -    uint64_t used_region_size = 0;
> >> -
> >> -    /* we will need a new memory slot for kvm and vhost */
> >> -    if (kvm_enabled() && !kvm_has_free_slot(ms)) {
> >> -        error_setg(errp, "hypervisor has no free memory slots left");
> >> -        return;
> >> -    }
> >> -    if (!vhost_has_free_slot()) {
> >> -        error_setg(errp, "a used vhost backend has no free memory slots left");
> >> -        return;
> >> -    }
> >> -
> >> -    /* will we exceed the total amount of memory specified */
> >> -    memory_device_used_region_size(OBJECT(ms), &used_region_size);
> >> -    if (used_region_size + size > ms->maxram_size - ms->ram_size) {
> >> -        error_setg(errp, "not enough space, currently 0x%" PRIx64
> >> -                   " in use of total hot pluggable 0x" RAM_ADDR_FMT,
> >> -                   used_region_size, ms->maxram_size - ms->ram_size);
> >> -        return;
> >> -    }
> >> -
> >> -}
> >> -
> >>  uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
> >>                                       uint64_t align, uint64_t size,
> >>                                       Error **errp)
> >>  {
> >>      uint64_t address_space_start, address_space_end;
> >> +    uint64_t used_region_size = 0;
> >>      GSList *list = NULL, *item;
> >>      uint64_t new_addr = 0;
> >>  
> >> -    if (!ms->device_memory) {
> >> -        error_setg(errp, "memory devices (e.g. for memory hotplug) are not "
> >> -                         "supported by the machine");
> >> -        return 0;
> >> -    }
> >> -
> >> -    if (!memory_region_size(&ms->device_memory->mr)) {
> >> -        error_setg(errp, "memory devices (e.g. for memory hotplug) are not "
> >> -                         "enabled, please specify the maxmem option");
> >> -        return 0;
> >> -    }
> >>      address_space_start = ms->device_memory->base;
> >>      address_space_end = address_space_start +
> >>                          memory_region_size(&ms->device_memory->mr);
> >>      g_assert(address_space_end >= address_space_start);
> >>  
> >> -    memory_device_check_addable(ms, size, errp);
> >> -    if (*errp) {
> >> +    /* will we exceed the total amount of memory specified */
> >> +    memory_device_used_region_size(OBJECT(ms), &used_region_size);
> >> +    if (used_region_size + size > ms->maxram_size - ms->ram_size) {
> >> +        error_setg(errp, "not enough space, currently 0x%" PRIx64
> >> +                   " in use of total hot pluggable 0x" RAM_ADDR_FMT,
> >> +                   used_region_size, ms->maxram_size - ms->ram_size);
> >>          return 0;
> >>      }
> >>  
> >> @@ -242,6 +210,32 @@ uint64_t get_plugged_memory_size(void)
> >>      return size;
> >>  }
> >>  
> >> +void memory_device_pre_plug(MachineState *ms, const MemoryDeviceState *md,
> >> +                            Error **errp)
> >> +{
> >> +    if (!ms->device_memory) {
> >> +        error_setg(errp, "memory devices (e.g. for memory hotplug) are not "
> >> +                         "supported by the machine");
> >> +        return;
> >> +    }
> >> +
> >> +    if (!memory_region_size(&ms->device_memory->mr)) {
> >> +        error_setg(errp, "memory devices (e.g. for memory hotplug) are not "
> >> +                         "enabled, please specify the maxmem option");
> >> +        return;
> >> +    }
> >> +
> >> +    /* we will need a new memory slot for kvm and vhost */
> >> +    if (kvm_enabled() && !kvm_has_free_slot(ms)) {
> >> +        error_setg(errp, "hypervisor has no free memory slots left");
> >> +        return;
> >> +    }
> >> +    if (!vhost_has_free_slot()) {
> >> +        error_setg(errp, "a used vhost backend has no free memory slots left");
> >> +        return;
> >> +    }  
> > thanks for extracting preparations steps into the right callback.
> > 
> > on top of this _preplug() handler should also set being plugged
> > device properties if they weren't set by user.
> >  memory_device_get_free_addr() should be here to.
> > 
> > general rule for _preplug() would be to check and prepare device
> > for being plugged but not touch anything beside the device (it's _plug handler job)  
> 
> I disagree. Or at least I disagree as part of this patch series because
> it over-complicates things :)
"Welcome to rewrite QEMU first before you do your thing" club :)

That's why I've suggested to split series in several small ones
tackling concrete goals /1st: unplug cleanups, 2nd: preplug refactoring/
instead of intermixing loosely related patches.

It should help to review and merge prerequisite work fast as it doesn't
related to virtio-mem. The rest of refactoring (which is not much once
you split out the 2 first series) that's is done directly for virtio-mem
sake should be posted as part of that series.
It probably would be biger series but posting them separately doesn't
make sense either as reviewer would have to jump between them anyways
to make sensible review.

> preplug() can do basic checks but I don't think it should be used to
> change actual properties. And I give you the main reason for this:
> 
> We have to do quite some amount of unnecessary error handling (please
> remember the pc_dimm plug code madness before I refactored it - 80%
> consisted of error handling) if we want to work on device properties
> before a device is realized. And we even have duplicate checks both in
> the realize() and the preplug() code then (again, what we had in the
> pc_dimm plug code - do we have a memdev already or not).
> 
> Right now, I assume, that all MemoryDevice functions can be safely
> called after the device has been realized without error handling. This
> is nice. It e.g. guarantees that we have a memdev assigned. Otherwise,
> every time we access some MemoryDevice property (e.g. region size), we
> have to handle possible uninitialized properties (e.g. memdev) -
> something I don't like.
> 
> So I want to avoid this by any means. And I don't really see a benefit
> for this additional error handling that will be necessary: We don't care
> about the performance in case something went wrong.
> 
error checks are not really important here.
Here I care about keeping QOM model work as it supposed to, i.e.
 object_new() -> set properties -> realize()
set properties should happen before realize() is called and
that's preplug callback.

Currently setting properties is still in plug() handler
because preplug handler was introduced later and nobody was
rewriting that code to the extent you do.

  reply	other threads:[~2018-06-07 15:00 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-17  8:15 [Qemu-devel] [PATCH v4 00/14] MemoryDevice: use multi stage hotplug handlers David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 01/14] memory-device: drop assert related to align and start of address space David Hildenbrand
2018-05-29 13:27   ` Igor Mammedov
2018-05-29 16:02     ` David Hildenbrand
2018-05-30 12:57       ` Igor Mammedov
2018-05-30 14:06         ` David Hildenbrand
2018-05-31 13:54           ` Igor Mammedov
2018-06-04 10:53             ` David Hildenbrand
2018-06-07 13:26               ` Igor Mammedov
2018-06-07 14:12                 ` David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 02/14] memory-device: introduce separate config option David Hildenbrand
2018-05-30 12:58   ` Igor Mammedov
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 03/14] qdev: let machine hotplug handler to override bus hotplug handler David Hildenbrand
2018-06-05  1:02   ` David Gibson
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 04/14] pc: prepare for multi stage hotplug handlers David Hildenbrand
2018-05-30 13:08   ` Igor Mammedov
2018-05-30 14:13     ` David Hildenbrand
2018-05-31 14:13       ` Igor Mammedov
2018-06-04 11:27         ` David Hildenbrand
2018-06-07 13:44           ` Igor Mammedov
2018-06-07 14:00             ` David Hildenbrand
2018-06-08 12:24               ` Igor Mammedov
2018-06-08 12:32                 ` David Hildenbrand
2018-06-08 12:55                   ` Michael S. Tsirkin
2018-06-08 13:07                     ` David Hildenbrand
2018-06-08 15:12                       ` Michael S. Tsirkin
2018-06-13 10:58                         ` David Hildenbrand
2018-06-13 15:48                           ` Igor Mammedov
2018-06-13 15:51                             ` David Hildenbrand
2018-06-13 18:32                               ` Michael S. Tsirkin
2018-06-13 19:37                                 ` David Hildenbrand
2018-06-13 22:05                                   ` Michael S. Tsirkin
2018-06-14  6:14                                     ` David Hildenbrand
2018-06-14  9:16                                       ` Igor Mammedov
2018-06-14  9:20                               ` Igor Mammedov
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 05/14] pc: route all memory devices through the machine hotplug handler David Hildenbrand
2018-05-30 13:12   ` Igor Mammedov
2018-05-30 14:08     ` David Hildenbrand
2018-05-30 14:27       ` Paolo Bonzini
2018-05-30 14:31         ` David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 06/14] spapr: prepare for multi stage hotplug handlers David Hildenbrand
2018-05-17 12:43   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2018-06-01 10:33   ` [Qemu-devel] " Igor Mammedov
2018-06-05  1:08   ` David Gibson
2018-06-05  7:51     ` David Hildenbrand
2018-06-07 14:26       ` Igor Mammedov
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 07/14] spapr: route all memory devices through the machine hotplug handler David Hildenbrand
2018-06-05  1:09   ` David Gibson
2018-06-05  7:51     ` David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 08/14] spapr: handle pc-dimm unplug via hotplug handler chain David Hildenbrand
2018-06-01 10:53   ` Igor Mammedov
2018-06-05  1:12   ` David Gibson
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 09/14] spapr: handle cpu core " David Hildenbrand
2018-06-01 10:57   ` Igor Mammedov
2018-06-05  1:13   ` David Gibson
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 10/14] memory-device: new functions to handle plug/unplug David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 11/14] pc-dimm: implement new memory device functions David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 12/14] memory-device: factor out pre-plug into hotplug handler David Hildenbrand
2018-06-01 11:17   ` Igor Mammedov
2018-06-04 11:45     ` David Hildenbrand
2018-06-07 15:00       ` Igor Mammedov [this message]
2018-06-07 15:10         ` David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 13/14] memory-device: factor out unplug " David Hildenbrand
2018-06-01 11:31   ` Igor Mammedov
2018-06-04 15:54     ` David Hildenbrand
2018-05-17  8:15 ` [Qemu-devel] [PATCH v4 14/14] memory-device: factor out plug " David Hildenbrand
2018-06-01 11:39   ` Igor Mammedov
2018-06-04 11:47     ` David Hildenbrand
2018-06-07 10:44       ` [Qemu-devel] [qemu-s390x] " David Hildenbrand
2018-05-25 12:43 ` [Qemu-devel] [qemu-s390x] [PATCH v4 00/14] MemoryDevice: use multi stage hotplug handlers David Hildenbrand
2018-05-30 14:03   ` Paolo Bonzini
2018-05-31 11:47     ` Igor Mammedov
2018-05-31 11:50       ` Paolo Bonzini
2018-06-01 12:13   ` Igor Mammedov
2018-06-04 10:03     ` David Hildenbrand
2018-06-08  9:57     ` David Hildenbrand

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=20180607170012.65ddd90b@redhat.com \
    --to=imammedo@redhat.com \
    --cc=agraf@suse.de \
    --cc=armbru@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=pagupta@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@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.