All of lore.kernel.org
 help / color / mirror / Atom feed
* Failing property setters + hardwired devices + -global = a bad day
@ 2020-04-29 15:28 Markus Armbruster
  2020-04-29 15:39 ` Paolo Bonzini
  2020-04-29 15:57 ` Daniel P. Berrangé
  0 siblings, 2 replies; 21+ messages in thread
From: Markus Armbruster @ 2020-04-29 15:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, Max Reitz, Marc-André Lureau,
	Paolo Bonzini

Here's how we represent QOM properties:

    struct ObjectProperty
    {
        gchar *name;
        [...]
        ObjectPropertyAccessor *get;
        ObjectPropertyAccessor *set;
        ObjectPropertyInit *init;
        void *opaque;
        QObject *defval;
    };

= The setter =

A ->set() method looks like this:

    void TYPE_set_PROP(Object *obj, Visitor *v,
                       const char *name, void *opaque, Error **errp)

The bit to remember for later is that it can fail.

= Default defaults =

When an object gets created, its memory is zeroed, and then any class
properties with an ->init() are initialized with

    obj->init(obj, prop);

We have just one ->init():

    void object_property_init_defval(Object *obj, ObjectProperty *prop)

It initializes from ->defval using ->set().

Aside: feels overengineered, but let's move on.

For TYPE_DEVICE objects, "static" properties get initialized the same.

Aside: if I know what "static" means, I'll be hanged.

The bit to remember for later is that properties start at zero, and some
have their zero overwritten with ->set().

= "Compat" defaults =

TYPE_DEVICE objects and the accelerator (the thing you configure with
-accel) next undergo object_apply_compat_props().

TYPE_DEVICE objects do this from ->instance_post_init().

For the accelerator, we do it where we create it, in
do_configure_accelerator().

This provides for defaults that depend on the accelerator, the machine
type, or certain legacy command line option desugaring (don't ask).

These default values are stored as strings, and applied with
object_property_parse(), which uses ->set().

The bit to remember for later is that some properties have their default
default overwritten with ->set() one or more times.

= -global defaults =

TYPE_DEVICE objects next undergo qdev_prop_set_globals(), still from
->instance_post_init().  This applies the user's -global options.

These default values are also stored as strings, and also applied with
object_property_parse(), which uses ->set().

The bit to remember for later is that some properties have their
built-in default overwritten with ->set() one more time.

= Configuration =

Now we come to a fork in the road: devices created with configuration
taken from -device / device_add, and devices the code creates by itself.

== -device / device_add ==

This is qdev_device_add().  Works as follows:

    1. create object (this applies the various defaults)
    2. Pass the users KEY=VALUE,... to object_property_parse() one by
       one
    3. realize

The bit to remember for later is that properties of user-creatable
devices get overwritten with ->set one final time.

== Hardwired devices ==

Common pattern:

    1. create object (this applies the various defaults)
    2. set properties with qdev_prop_set_FOO() one by one
    3. realize

= Handling ->set() failure =

Here's how the uses of ->set() we've seen so far handle failure:

* Default defaults

  An ->init() method cannot fail; object_property_init_defval() passes
  &error_abort.

  Rationale: if the defaults we bake into QEMU don't work, it's a
  programming error.

* "Compat" defaults

  do_configure_accelerator() can fail, but an ->instance_post_init()
  method can't; object_apply_compat_props() uses &error_abort, except
  for the legacy command line option desugaring, where it uses
  &error_fatal.

  Rationale: if the defaults we bake into QEMU don't work, it's a
  programming error.  If legacy CLI options can't be applied, it's a
  fatal error.

* -global defaults

  An ->instance_post_init() method can't fail; qdev_prop_set_globals()
  uses &error_fatal.

  Rationale: if the user's -global can't be applied, it's a fatal error.

  Except it *ignores* errors afterward initial configuration (after
  qdev_machine_creation_done()).

  Rationale: silently ignoring the user's -global for hot-plugged
  devices is bad, killing the VM is worse.  We suck.

* -device / device_add

  qdev_device_add() fails cleanly.

  Rationale: sometimes we manage not to suck.

* Hardwired devices

  The qdev_prop_set_FOO() can't fail; they pass &error_abort.

  Rationale: if the configuration we bake into QEMU doesn't work, it's a
  programming error.

  Except qdev_prop_set_drive() can fail.  Of its 43 callers, 9 pass
  &error_abort, 27 pass &error_fatal, and 7 try to handle failure.
  Of these seven, several are obviously wrong.

  Rationale: uh, we like exceptions?

= Can this get more depressing? =

Yes!

->set() can run many times, yet I found three ->set() methods that can't
handle overwriting non-zero:

* set_netdev() fails with "Property NETDEV doesn't take value VALUE"

  Reproducer:

    $ upstream-qemu -nodefaults -S -monitor stdio -display none -nic user -netdev user,id=foo -global e1000.netdev=foo
    QEMU 5.0.0 monitor - type 'help' for more information
    (qemu) Unexpected error in error_set_from_qdev_prop_error() at /work/armbru/qemu/hw/core/qdev-properties.c:1105:
    upstream-qemu: Property 'e1000.netdev' doesn't take value '__org.qemu.nic0
    '
    Aborted (core dumped)

  The abort is courtesy qdev_prop_set_net().

* set_drive() leaves the old value attached to the device, which is wrong

  Reproducer:

    $ upstream-qemu -S -monitor stdio -display none -fda tmp.qcow2 -drive if=none,file=test.qcow2 -global isa-fdc.driveA=none0
    QEMU 5.0.0 monitor - type 'help' for more information
    (qemu) info block
    floppy0 (#block162): tmp.qcow2 (qcow2)
  --->  Attached to:      /machine/unattached/device[16]
        Removable device: not locked, tray closed
        Cache mode:       writeback
        Backing file:     tmp.img (chain depth: 1)

    none0 (#block535): test.qcow2 (qcow2)
  --->  Attached to:      /machine/unattached/device[15]
        Cache mode:       writeback
        Backing file:     f29.raw (chain depth: 1)

    ide1-cd0: [not inserted]
        Attached to:      /machine/unattached/device[23]
        Removable device: not locked, tray closed

    sd0: [not inserted]
        Removable device: not locked, tray closed

  device[15] is "isa-fdc".

  device[16] is the "floppy" hanging of "isa-fdc".  Magic in fdc.c moved
  it from "isa-fdc" (don't ask).

* set_chr() calls qemu_chr_fe_init() again without qemu_chr_fe_deinit(),
  which is wrong

  Reproducer:

    $ upstream-qemu -nodefaults -S -monitor stdio -display none -chardev null,id=foo -chardev null,id=bar -serial chardev:foo -global isa-serial.chardev=bar

The "if the configuration we bake into QEMU doesn't work, it's a
programming error" idea needs amending: "doesn't work with any -global
shenanigans users may come up with".

I guess these ->set() flaws are fixable.

The knee-jerk fix is to have ->set() fail rather than screw up.  This is
what set_netdev() does.  It founders on the amended "if the
configuration we bake into QEMU don't work, it's a programming error"
idea: ->set() can then fail there because -global set it up for failure.

Making all the qdev_prop_set_FOO() users handle errors would be a lot of
work: in addition to the 43 users of qdev_prop_set_drive(), we have more
than 50 of qdev_prop_set_chr() and almost 40 of
qdev_set_nic_properties().  Infeasible for me.  Bye, bye knee-jerk fix.

Is there any sane use for configuring backends via any of the default
mechanisms?

I'm aware of one, but it's outdated: -global isa-fdc.driveA=...  Use
-device floppy instead.

I'd love to deprecate -global wholesale, but we can't as long as we
don't have better means to configure onboard devices.  Can we deprecate
its use with backend properties at least?

While we're talking about deprecation: what about use of -global with
hot-plugged devices?  Remember, bad -global gets silently ignored there.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Failing property setters + hardwired devices + -global = a bad day
  2020-04-29 15:28 Failing property setters + hardwired devices + -global = a bad day Markus Armbruster
@ 2020-04-29 15:39 ` Paolo Bonzini
  2020-04-29 16:23   ` Eduardo Habkost
  2020-04-29 15:57 ` Daniel P. Berrangé
  1 sibling, 1 reply; 21+ messages in thread
From: Paolo Bonzini @ 2020-04-29 15:39 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, Max Reitz, Marc-André Lureau

On 29/04/20 17:28, Markus Armbruster wrote:
> When an object gets created, its memory is zeroed, and then any class
> properties with an ->init() are initialized with
> 
>     obj->init(obj, prop);
> 
> We have just one ->init():
> 
>     void object_property_init_defval(Object *obj, ObjectProperty *prop)
> 
> It initializes from ->defval using ->set().
> 
> Aside: feels overengineered, but let's move on.
> 
> For TYPE_DEVICE objects, "static" properties get initialized the same.
> 
> Aside: if I know what "static" means, I'll be hanged.

Originally these were the only properties that were part of the class
rather than the object (so, not dynamic --> static).

> I'd love to deprecate -global wholesale, but we can't as long as we
> don't have better means to configure onboard devices.  Can we deprecate
> its use with backend properties at least?

I wouldn't mind deprecating -global wholesale, leaving the global/compat
props code only for internal usage.

Paolo



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Failing property setters + hardwired devices + -global = a bad day
  2020-04-29 15:28 Failing property setters + hardwired devices + -global = a bad day Markus Armbruster
  2020-04-29 15:39 ` Paolo Bonzini
@ 2020-04-29 15:57 ` Daniel P. Berrangé
  2020-04-30  7:09   ` Markus Armbruster
  1 sibling, 1 reply; 21+ messages in thread
From: Daniel P. Berrangé @ 2020-04-29 15:57 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Peter Maydell, Eduardo Habkost, Jason Wang,
	qemu-devel, Max Reitz, Marc-André Lureau, Paolo Bonzini

On Wed, Apr 29, 2020 at 05:28:25PM +0200, Markus Armbruster wrote:
> Is there any sane use for configuring backends via any of the default
> mechanisms?
> 
> I'm aware of one, but it's outdated: -global isa-fdc.driveA=...  Use
> -device floppy instead.
> 
> I'd love to deprecate -global wholesale, but we can't as long as we
> don't have better means to configure onboard devices.  Can we deprecate
> its use with backend properties at least?

Currently libvirt has code using the following


* Floppy

  -global isa-fdc.driveA=ID
  -global isa-fdc.driveB=ID
  -global isa-fdc.bootindexA=NN
  -global isa-fdc.bootindexB=NN

  Only used when the machine type is pc-q35-2.4 or earlier

* NVRAM

  -global spapr-nvram.reg=0xnnnn

* Video primary display adapter

  -global qxl-vga.ram_size=NN
  -global qxl-vga.vram_size=NN
  -global qxl-vga.vram64_size=NN
  -global qxl-vga.vgamem_mb=NN
  -global qxl-vga.max_outputs=NN
  -global VGA.vgamem_mb=MM
  -global vmware-svga.vgamem_mb=MM

  Only used for old qemu lacking -device support where we must use -vga
  instead


* PIT policy

   -global kvm-pit.lost_tick_policy=XXX


* S3/S4

   -global PIIX4_PM.disable_s3=NNN
   -global PIIX4_PM.disable_s4=NNN
   -global ICH9-LPC.disable_s3=NNN
   -global ICH9-LPC.disable_s4=NNN

* PCI hole

   -global i440FX-pcihost.pci-hole64-size=NNN
   -global q35-pcihost.pci-hole64-size=NNN

* SMM TSeg

   -global mch.extended-tseg-mbytes=NNN

* pflash

   -global driver=cfi.pflash01,property=secure,value=on

  Used for EFI secure boot


I'm unclear which of these can be replaced with a different QEMU cli
option....

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Failing property setters + hardwired devices + -global = a bad day
  2020-04-29 15:39 ` Paolo Bonzini
@ 2020-04-29 16:23   ` Eduardo Habkost
  0 siblings, 0 replies; 21+ messages in thread
From: Eduardo Habkost @ 2020-04-29 16:23 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	qemu-devel, Jason Wang, Markus Armbruster, Max Reitz,
	Marc-André Lureau

On Wed, Apr 29, 2020 at 05:39:20PM +0200, Paolo Bonzini wrote:
> On 29/04/20 17:28, Markus Armbruster wrote:
> > When an object gets created, its memory is zeroed, and then any class
> > properties with an ->init() are initialized with
> > 
> >     obj->init(obj, prop);
> > 
> > We have just one ->init():
> > 
> >     void object_property_init_defval(Object *obj, ObjectProperty *prop)
> > 
> > It initializes from ->defval using ->set().
> > 
> > Aside: feels overengineered, but let's move on.
> > 
> > For TYPE_DEVICE objects, "static" properties get initialized the same.
> > 
> > Aside: if I know what "static" means, I'll be hanged.
> 
> Originally these were the only properties that were part of the class
> rather than the object (so, not dynamic --> static).
> 
> > I'd love to deprecate -global wholesale, but we can't as long as we
> > don't have better means to configure onboard devices.  Can we deprecate
> > its use with backend properties at least?
> 
> I wouldn't mind deprecating -global wholesale, leaving the global/compat
> props code only for internal usage.

I would absolutely love to get rid of -global, but we need to
provide an alternative for users that rely on it.

libvirt, for example, has at least 15 virCommandAddArg*(...,
"-global", ...) calls in src/qemu/qemu_command.c:

src/qemu/qemu_command.c:2344:                virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-2345-                virCommandAddArgFormat(cmd, "isa-fdc.%s", backendStr);
src/qemu/qemu_command.c-2346-            }
src/qemu/qemu_command.c-2347-
src/qemu/qemu_command.c-2348-            if (bootindexStr) {
src/qemu/qemu_command.c:2349:                virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-2350-                virCommandAddArgFormat(cmd, "isa-fdc.%s", bootindexStr);
src/qemu/qemu_command.c-2351-            }
src/qemu/qemu_command.c-2352-        } else {
src/qemu/qemu_command.c-2353-            virBufferStrcat(&fdc_opts, backendStr, ",", NULL);
--
src/qemu/qemu_command.c:4174:    virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-4175-    optstr = qemuBuildNVRAMDevStr(def->nvram);
src/qemu/qemu_command.c-4176-    if (!optstr)
src/qemu/qemu_command.c-4177-        return -1;
src/qemu/qemu_command.c-4178-
--
src/qemu/qemu_command.c:4568:     * --global option and for that we need to specify the device
src/qemu/qemu_command.c-4569-     * name the same as for --device option and for that we need to
src/qemu/qemu_command.c-4570-     * use 'qemuDeviceVideo'.
src/qemu/qemu_command.c-4571-     *
src/qemu/qemu_command.c-4572-     * See 'Graphics Devices' section in docs/qdev-device-use.txt in
--
src/qemu/qemu_command.c:4586:            virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-4587-            virCommandAddArgFormat(cmd, "%s.ram_size=%u",
src/qemu/qemu_command.c-4588-                                   dev, ram * 1024);
src/qemu/qemu_command.c-4589-        }
src/qemu/qemu_command.c-4590-        if (vram) {
src/qemu/qemu_command.c:4591:            virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-4592-            virCommandAddArgFormat(cmd, "%s.vram_size=%u",
src/qemu/qemu_command.c-4593-                                   dev, vram * 1024);
src/qemu/qemu_command.c-4594-        }
src/qemu/qemu_command.c-4595-        if (vram64 &&
--
src/qemu/qemu_command.c:4597:            virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-4598-            virCommandAddArgFormat(cmd, "%s.vram64_size_mb=%u",
src/qemu/qemu_command.c-4599-                                   dev, vram64 / 1024);
src/qemu/qemu_command.c-4600-        }
src/qemu/qemu_command.c-4601-        if (vgamem &&
--
src/qemu/qemu_command.c:4603:            virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-4604-            virCommandAddArgFormat(cmd, "%s.vgamem_mb=%u",
src/qemu/qemu_command.c-4605-                                   dev, vgamem / 1024);
src/qemu/qemu_command.c-4606-        }
src/qemu/qemu_command.c-4607-        if (heads &&
--
src/qemu/qemu_command.c:4609:            virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-4610-            virCommandAddArgFormat(cmd, "%s.max_outputs=%u",
src/qemu/qemu_command.c-4611-                                   dev, heads);
src/qemu/qemu_command.c-4612-        }
src/qemu/qemu_command.c-4613-    }
--
src/qemu/qemu_command.c:4622:        virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-4623-        virCommandAddArgFormat(cmd, "%s.vgamem_mb=%u",
src/qemu/qemu_command.c-4624-                               dev, vram / 1024);
src/qemu/qemu_command.c-4625-    }
src/qemu/qemu_command.c-4626-
--
src/qemu/qemu_command.c:6278:                    virCommandAddArgList(cmd, "-global",
src/qemu/qemu_command.c-6279-                                         "kvm-pit.lost_tick_policy=delay", NULL);
src/qemu/qemu_command.c-6280-                break;
src/qemu/qemu_command.c-6281-            case VIR_DOMAIN_TIMER_TICKPOLICY_CATCHUP:
src/qemu/qemu_command.c-6282-                /* Do nothing - qemuDomainDefValidateClockTimers handled
--
src/qemu/qemu_command.c:6287:                    virCommandAddArgList(cmd, "-global",
src/qemu/qemu_command.c-6288-                                         "kvm-pit.lost_tick_policy=discard", NULL);
src/qemu/qemu_command.c-6289-                break;
src/qemu/qemu_command.c-6290-            case VIR_DOMAIN_TIMER_TICKPOLICY_MERGE:
src/qemu/qemu_command.c-6291-                /* no way to support this mode for pit in qemu */
--
src/qemu/qemu_command.c:6346:        virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-6347-        virCommandAddArgFormat(cmd, "%s.disable_s3=%d",
src/qemu/qemu_command.c-6348-                               pm_object, def->pm.s3 == VIR_TRISTATE_BOOL_NO);
src/qemu/qemu_command.c-6349-    }
src/qemu/qemu_command.c-6350-
--
src/qemu/qemu_command.c:6358:        virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-6359-        virCommandAddArgFormat(cmd, "%s.disable_s4=%d",
src/qemu/qemu_command.c-6360-                               pm_object, def->pm.s4 == VIR_TRISTATE_BOOL_NO);
src/qemu/qemu_command.c-6361-    }
src/qemu/qemu_command.c-6362-
--
src/qemu/qemu_command.c:6508:            virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-6509-            virCommandAddArgFormat(cmd, "%s.pci-hole64-size=%luK", hoststr,
src/qemu/qemu_command.c-6510-                                   cont->opts.pciopts.pcihole64size);
src/qemu/qemu_command.c-6511-        }
src/qemu/qemu_command.c-6512-    }
--
src/qemu/qemu_command.c:7191:    virCommandAddArg(cmd, "-global");
src/qemu/qemu_command.c-7192-
src/qemu/qemu_command.c-7193-    /* PostParse callback guarantees that the size is divisible by 1 MiB */
src/qemu/qemu_command.c-7194-    virCommandAddArgFormat(cmd, "mch.extended-tseg-mbytes=%llu",
src/qemu/qemu_command.c-7195-                           def->tseg_size >> 20);
--
src/qemu/qemu_command.c:9109:                             "-global",
src/qemu/qemu_command.c-9110-                             "driver=cfi.pflash01,property=secure,value=on",
src/qemu/qemu_command.c-9111-                             NULL);
src/qemu/qemu_command.c-9112-    }
src/qemu/qemu_command.c-9113-

-- 
Eduardo



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Failing property setters + hardwired devices + -global = a bad day
  2020-04-29 15:57 ` Daniel P. Berrangé
@ 2020-04-30  7:09   ` Markus Armbruster
  2020-04-30  9:27     ` Peter Maydell
  0 siblings, 1 reply; 21+ messages in thread
From: Markus Armbruster @ 2020-04-30  7:09 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Kevin Wolf, Peter Maydell, Eduardo Habkost, Jason Wang,
	qemu-devel, Max Reitz, Paolo Bonzini, Marc-André Lureau

Daniel P. Berrangé <berrange@redhat.com> writes:

> On Wed, Apr 29, 2020 at 05:28:25PM +0200, Markus Armbruster wrote:
>> Is there any sane use for configuring backends via any of the default
>> mechanisms?
>> 
>> I'm aware of one, but it's outdated: -global isa-fdc.driveA=...  Use
>> -device floppy instead.
>> 
>> I'd love to deprecate -global wholesale, but we can't as long as we
>> don't have better means to configure onboard devices.  Can we deprecate
>> its use with backend properties at least?
>
> Currently libvirt has code using the following

Useful, thanks!

> * Floppy
>
>   -global isa-fdc.driveA=ID
>   -global isa-fdc.driveB=ID
>   -global isa-fdc.bootindexA=NN
>   -global isa-fdc.bootindexB=NN
>
>   Only used when the machine type is pc-q35-2.4 or earlier

This is qemuBuildFloppyCommandLineControllerOptions().  I'm not sure I
follow the logic there.

Two compatibility issues are relevant to floppies:

* Onboard isa-fdc

  We dropped the onboard isa-fdc for certain machine types (commit
  ea96bc629c "i386: drop FDC in pc-q35-2.4+ if neither it nor floppy
  drives are wanted", v2.4.0).  To get one, use -device isa-fdc of
  -drive if=floppy,...

  The upstream machine types are pc-q35-2.4 or later.  Downstreams are
  free to do the same for their machine types.

  qemuDomainMachineNeedsFDC() returns true for x86 machine types other
  than pc-q35-{1.,2.0,2.1,2.2,2.3}*

  Your "when the machine type is pc-q35-2.4 or earlier" appears to be
  off by one.

  When libvirt decides to use -device isa-fdc, it sensibly puts the
  driveA=... and driveB=... bits there rather than in -global isa-fdc...

  Libvirt still uses -global for machine types with an onboard isa-fdc.

* -device floppy

  We support configuring floppy drives with -device (commit a92bd191a4
  "fdc: Move qdev properties to FloppyDrive", v2.8.0).

  This permits

    -device isa-fdc,FDC-OPTS...
    -device floppy unit=0,drive=BACKEND,FLOPPY-OPTS...

  in addition to the old

    -device isa-fdc,driveA=BACKEND,FDC_OPTS...

  or the even older

    -global isa-fdc.driveA=BACKEND,FDC_OPTS...

  which both rely on black magic in device isa-fdc to automatically
  create the floppy device.

  Same for driveB / unit=0, of course.

  I expect us to deprecate isa-fdc's driveA and driveB some day.

  Its replacement lets you avoid -global even for machine types with an
  onboard isa-fdc.

  To detect it, check whether device "floppy" exists.

> * NVRAM
>
>   -global spapr-nvram.reg=0xnnnn

Onboard device of the pseries-* machine type family.

Our means to configure onboard devices are weak.  We sidestepped this
for isa-fdc by taking it off the board, and thus make -device work.

I investigated doing the same for onboard flash memory, but Paolo
convinced me to do something else instead: add machine properties that
alias the onboard devices' properties.  Commit ebc29e1beab explains all
this, if you're curious.

If we do the same here, we can replace -global spapr-nvram.reg=... by
something like -machine nvram-reg=...

> * Video primary display adapter
>
>   -global qxl-vga.ram_size=NN
>   -global qxl-vga.vram_size=NN
>   -global qxl-vga.vram64_size=NN
>   -global qxl-vga.vgamem_mb=NN
>   -global qxl-vga.max_outputs=NN
>   -global VGA.vgamem_mb=MM
>   -global vmware-svga.vgamem_mb=MM
>
>   Only used for old qemu lacking -device support where we must use -vga
>   instead

Solution: wait for libvirt to notice QEMU lacking -device is long dead
and buried.

> * PIT policy
>
>    -global kvm-pit.lost_tick_policy=XXX

Onboard device, same solution as for NVRAM.

Note that the board uses either isa-pit or kvm-pit, depending on
configuration.  Might complicate things a bit.

> * S3/S4
>
>    -global PIIX4_PM.disable_s3=NNN
>    -global PIIX4_PM.disable_s4=NNN
>    -global ICH9-LPC.disable_s3=NNN
>    -global ICH9-LPC.disable_s4=NNN
>
> * PCI hole
>
>    -global i440FX-pcihost.pci-hole64-size=NNN
>    -global q35-pcihost.pci-hole64-size=NNN
>
> * SMM TSeg
>
>    -global mch.extended-tseg-mbytes=NNN
>
> * pflash
>
>    -global driver=cfi.pflash01,property=secure,value=on
>
>   Used for EFI secure boot

Onboard devices, same solution as for NVRAM, I guess.

> I'm unclear which of these can be replaced with a different QEMU cli
> option....

Mostly "not yet", I think.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Failing property setters + hardwired devices + -global = a bad day
  2020-04-30  7:09   ` Markus Armbruster
@ 2020-04-30  9:27     ` Peter Maydell
  2020-04-30 10:03       ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Markus Armbruster
  0 siblings, 1 reply; 21+ messages in thread
From: Peter Maydell @ 2020-04-30  9:27 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Paolo Bonzini, Marc-André Lureau

On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
> Our means to configure onboard devices are weak.  We sidestepped this
> for isa-fdc by taking it off the board, and thus make -device work.

This seems to be a general dynamic: the x86 pc machine works
via -device options (or is changed so it can work that way);
and then people propose dropping/deprecating/etc the config
options that work with onboard devices, without providing
clear solutions/instructions on how the command line needs
to change/etc for the mass of boards which are not the x86
pc machine and which do have a lot of onboard devices which
can't be handled via -device.

So my gut reaction to the "we should deprecate -global"
suggestions in this thread was a bit "here we go again"...
What works for x86 or even "what is sufficient for libvirt"
doesn't necessarily cover all the cases.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day)
  2020-04-30  9:27     ` Peter Maydell
@ 2020-04-30 10:03       ` Markus Armbruster
  2020-04-30 10:29         ` Mark Cave-Ayland
  2020-04-30 10:34         ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Daniel P. Berrangé
  0 siblings, 2 replies; 21+ messages in thread
From: Markus Armbruster @ 2020-04-30 10:03 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Marc-André Lureau, Paolo Bonzini

Peter Maydell <peter.maydell@linaro.org> writes:

> On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
>> Our means to configure onboard devices are weak.  We sidestepped this
>> for isa-fdc by taking it off the board, and thus make -device work.
>
> This seems to be a general dynamic: the x86 pc machine works
> via -device options (or is changed so it can work that way);
> and then people propose dropping/deprecating/etc the config
> options that work with onboard devices, without providing
> clear solutions/instructions on how the command line needs
> to change/etc for the mass of boards which are not the x86
> pc machine and which do have a lot of onboard devices which
> can't be handled via -device.
>
> So my gut reaction to the "we should deprecate -global"
> suggestions in this thread was a bit "here we go again"...
> What works for x86 or even "what is sufficient for libvirt"
> doesn't necessarily cover all the cases.

Such shortsighted proposals have been made, but don't think it's what
we're doing here.

You're 100% right in that we do need to configure onboard devices.
-global is a terrible way to do it, though: it applies to *all* devices
of a kind.  What if the board has more than one?  What if the can add
more?

Taking onboard devices off the board can occasionally sidestep the
issue.  For isa-fdc, we genuinely *wanted* to take the damn thing off,
because all it did for most users was provide them with VENOM.  Not
needing -global for it anymore was just a nice bonus.

Taking onboard devices off just to reduce the device configuration
problem to a solved one, namely -device, may be tempting (it was to me),
but it's too intrusive to be practical at scale.

Adding machine properties that alias onboard device properties is less
intrusive.  The ones I added were still a lot of work.

Configuring onboard devices via machine properties restricts property
access to the ones we added to the machine.  This differs from pluggable
devices, where users can access all properties.

Any better ideas for letting users configure onboard devices?



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day)
  2020-04-30 10:03       ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Markus Armbruster
@ 2020-04-30 10:29         ` Mark Cave-Ayland
  2020-04-30 14:11           ` Configuring onboard devices Markus Armbruster
  2020-04-30 10:34         ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Daniel P. Berrangé
  1 sibling, 1 reply; 21+ messages in thread
From: Mark Cave-Ayland @ 2020-04-30 10:29 UTC (permalink / raw)
  To: Markus Armbruster, Peter Maydell
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Paolo Bonzini, Marc-André Lureau

On 30/04/2020 11:03, Markus Armbruster wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
> 
>> On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
>>> Our means to configure onboard devices are weak.  We sidestepped this
>>> for isa-fdc by taking it off the board, and thus make -device work.
>>
>> This seems to be a general dynamic: the x86 pc machine works
>> via -device options (or is changed so it can work that way);
>> and then people propose dropping/deprecating/etc the config
>> options that work with onboard devices, without providing
>> clear solutions/instructions on how the command line needs
>> to change/etc for the mass of boards which are not the x86
>> pc machine and which do have a lot of onboard devices which
>> can't be handled via -device.
>>
>> So my gut reaction to the "we should deprecate -global"
>> suggestions in this thread was a bit "here we go again"...
>> What works for x86 or even "what is sufficient for libvirt"
>> doesn't necessarily cover all the cases.
> 
> Such shortsighted proposals have been made, but don't think it's what
> we're doing here.
> 
> You're 100% right in that we do need to configure onboard devices.
> -global is a terrible way to do it, though: it applies to *all* devices
> of a kind.  What if the board has more than one?  What if the can add
> more?
> 
> Taking onboard devices off the board can occasionally sidestep the
> issue.  For isa-fdc, we genuinely *wanted* to take the damn thing off,
> because all it did for most users was provide them with VENOM.  Not
> needing -global for it anymore was just a nice bonus.
> 
> Taking onboard devices off just to reduce the device configuration
> problem to a solved one, namely -device, may be tempting (it was to me),
> but it's too intrusive to be practical at scale.
> 
> Adding machine properties that alias onboard device properties is less
> intrusive.  The ones I added were still a lot of work.
> 
> Configuring onboard devices via machine properties restricts property
> access to the ones we added to the machine.  This differs from pluggable
> devices, where users can access all properties.
> 
> Any better ideas for letting users configure onboard devices?

Is it possible to let machine owners add alias properties to the machine object
referencing in-built devices? I could then instantiate my on-board nic in the machine
init() function, and then use object_property_add_alias() to add a "nic0" alias on
the machine that can be used to wire it up to a netdev using the command line.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day)
  2020-04-30 10:03       ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Markus Armbruster
  2020-04-30 10:29         ` Mark Cave-Ayland
@ 2020-04-30 10:34         ` Daniel P. Berrangé
  2020-04-30 10:45           ` Peter Maydell
  2020-04-30 14:27           ` Configuring onboard devices Markus Armbruster
  1 sibling, 2 replies; 21+ messages in thread
From: Daniel P. Berrangé @ 2020-04-30 10:34 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Peter Maydell, Eduardo Habkost, Jason Wang,
	QEMU Developers, Max Reitz, Marc-André Lureau,
	Paolo Bonzini

On Thu, Apr 30, 2020 at 12:03:12PM +0200, Markus Armbruster wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
> 
> > On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
> >> Our means to configure onboard devices are weak.  We sidestepped this
> >> for isa-fdc by taking it off the board, and thus make -device work.
> >
> > This seems to be a general dynamic: the x86 pc machine works
> > via -device options (or is changed so it can work that way);
> > and then people propose dropping/deprecating/etc the config
> > options that work with onboard devices, without providing
> > clear solutions/instructions on how the command line needs
> > to change/etc for the mass of boards which are not the x86
> > pc machine and which do have a lot of onboard devices which
> > can't be handled via -device.
> >
> > So my gut reaction to the "we should deprecate -global"
> > suggestions in this thread was a bit "here we go again"...
> > What works for x86 or even "what is sufficient for libvirt"
> > doesn't necessarily cover all the cases.
> 
> Such shortsighted proposals have been made, but don't think it's what
> we're doing here.
> 
> You're 100% right in that we do need to configure onboard devices.
> -global is a terrible way to do it, though: it applies to *all* devices
> of a kind.  What if the board has more than one?  What if the can add
> more?


> Any better ideas for letting users configure onboard devices?

All the devices in QEMU form a tree, as reported by "info qtree".
So, IIUC, the challenge is to provide a way to uniquely identify
any node in the tree.

Devices configured by the user/mgmt app will have an "id" property
but most built-in devices will not have any "id". In addition even
user configured devices may create multiple sub-nodes in the tree
without "id" parameters.

Uniquely referencing nodes in a tee is a solved problem though,
even without "id" parameters. The XPath query languages shows
this for XML.

-global defines a query language based on the object type, and
property name which is insufficiently flexible

-set defines a query language based on the object type and ID
value and property name(s) which is again insufficiently flexible.


We "merely" need a new query language targetted to QEMU's qtree
structure, which we can expose in the CLI that gives unique access
to every possible property.

Here is the truncated 'info qtree' for a running guest of mine:

bus: main-system-bus
  type System
  dev: kvm-ioapic, id ""
    gpio-in "" 24
    gsi_base = 0 (0x0)
    mmio 00000000fec00000/0000000000001000
  dev: i440FX-pcihost, id ""
    pci-hole64-size = 2147483648 (2 GiB)
    short_root_bus = 0 (0x0)
    x-pci-hole64-fix = false
    bus: pci.0
      type PCI
      dev: virtio-balloon-pci, id "balloon0"
        disable-legacy = "off"
        disable-modern = true
        class = 255 (0xff)
        virtio-pci-bus-master-bug-migration = false
        migrate-extra = false
        modern-pio-notify = false
        x-disable-pcie = true
        page-per-vq = true
        x-ignore-backend-features = true
        ats = false
        x-pcie-deverr-init = false
        x-pcie-lnkctl-init = false
        x-pcie-pm-init = false
        addr = 08.0
        romfile = ""
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        x-pcie-lnksta-dllla = true
        x-pcie-extcap-init = false
        class Class 00ff, addr 00:08.0, pci id 1af4:1002 (sub 1af4:0005)
        bar 0: i/o at 0xc100 [0xc11f]
        bus: virtio-bus
          type virtio-pci-bus
          dev: virtio-balloon-device, id ""
            deflate-on-oom = false
            free-page-hint = false
            qemu-4-0-config-size = false
            iothread = ""
            indirect_desc = true
            event_idx = true
            notify_on_empty = true
            any_layout = true
            iommu_platform = false
            use-started = false


Consider the problem is to set the "deflate-on-oom" property on
the balloon device.

To uniquely identify this we can have a string:

 /dev[1]/bus[pci/0]/dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true

If we consider that "id" values are unique, we can allow a simplication
by omitting everything before that part of the match - "//" could indicate
an omitted part like XPath allows, so we'd get

 //dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true

There's only one bus, and one dev on that bus, so knowing this we can
simplify a bit more and still be a unique query, to get this:

 //dev[id=balloon0]/bus/dev/deflate-on-oom=true

Or even allow use of "//" in the middle too:

 //dev[id=balloon0]//deflate-on-oom=true

Which conceptually says

   "find the device with id balloon0 and set the property 'deflate-on-oom'
   on the first child node in the qtree that hsa such a property name"

I didn't say this would be pretty, and of course no one would seriously
use this syntax for the virtio-balloon device, as you'd just set the
property with -device. It should work for the many built-in devices
though.

Now just provide a new CLI arg

 $QEMU -qtree //dev[id=balloon0]//deflate-on-oom=true

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day)
  2020-04-30 10:34         ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Daniel P. Berrangé
@ 2020-04-30 10:45           ` Peter Maydell
  2020-04-30 10:53             ` Daniel P. Berrangé
  2020-04-30 10:54             ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Mark Cave-Ayland
  2020-04-30 14:27           ` Configuring onboard devices Markus Armbruster
  1 sibling, 2 replies; 21+ messages in thread
From: Peter Maydell @ 2020-04-30 10:45 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Kevin Wolf, Eduardo Habkost, Jason Wang, QEMU Developers,
	Markus Armbruster, Marc-André Lureau, Paolo Bonzini,
	Max Reitz

On Thu, 30 Apr 2020 at 11:34, Daniel P. Berrangé <berrange@redhat.com> wrote:
> We "merely" need a new query language targetted to QEMU's qtree
> structure, which we can expose in the CLI that gives unique access
> to every possible property.

Past resistance to this has been grounded in not wanting to
expose the exact arrangement of the qtree as a user-facing
thing that needs to be maintained for back-compat reasons.

Eg in your example the i440fx-pcihost sits directly on the
'system bus', but this is an odd artefact of the old qbus/qdev
system and doesn't really reflect the way the system is built
up in terms of QOM components; we might one day want to
restructure things there, which would AIUI break a
command line like

> To uniquely identify this we can have a string:
>
>  /dev[1]/bus[pci/0]/dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true

thanks
-- PMM


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day)
  2020-04-30 10:45           ` Peter Maydell
@ 2020-04-30 10:53             ` Daniel P. Berrangé
  2020-04-30 14:38               ` Configuring onboard devices Markus Armbruster
  2020-04-30 10:54             ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Mark Cave-Ayland
  1 sibling, 1 reply; 21+ messages in thread
From: Daniel P. Berrangé @ 2020-04-30 10:53 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Kevin Wolf, Eduardo Habkost, Jason Wang, QEMU Developers,
	Markus Armbruster, Marc-André Lureau, Paolo Bonzini,
	Max Reitz

On Thu, Apr 30, 2020 at 11:45:40AM +0100, Peter Maydell wrote:
> On Thu, 30 Apr 2020 at 11:34, Daniel P. Berrangé <berrange@redhat.com> wrote:
> > We "merely" need a new query language targetted to QEMU's qtree
> > structure, which we can expose in the CLI that gives unique access
> > to every possible property.
> 
> Past resistance to this has been grounded in not wanting to
> expose the exact arrangement of the qtree as a user-facing
> thing that needs to be maintained for back-compat reasons.

I could be missing a key difference, but I thought we already exposed
the qtree in QMP  via qom-list, qom-get, qom-set ?  Libvirt uses
these commands for reading various properties.  I guess 'qom-set' is
really defining the kind of query string language I was illustrating
already. So mapping qom-set to the CLI as-is would not be worse than
what we already support in QMP

> Eg in your example the i440fx-pcihost sits directly on the
> 'system bus', but this is an odd artefact of the old qbus/qdev
> system and doesn't really reflect the way the system is built
> up in terms of QOM components; we might one day want to
> restructure things there, which would AIUI break a
> command line like

> > To uniquely identify this we can have a string:
> >
> >  /dev[1]/bus[pci/0]/dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day)
  2020-04-30 10:45           ` Peter Maydell
  2020-04-30 10:53             ` Daniel P. Berrangé
@ 2020-04-30 10:54             ` Mark Cave-Ayland
  1 sibling, 0 replies; 21+ messages in thread
From: Mark Cave-Ayland @ 2020-04-30 10:54 UTC (permalink / raw)
  To: Peter Maydell, Daniel P. Berrangé
  Cc: Kevin Wolf, Eduardo Habkost, Jason Wang, Markus Armbruster,
	QEMU Developers, Paolo Bonzini, Marc-André Lureau,
	Max Reitz

On 30/04/2020 11:45, Peter Maydell wrote:

> On Thu, 30 Apr 2020 at 11:34, Daniel P. Berrangé <berrange@redhat.com> wrote:
>> We "merely" need a new query language targetted to QEMU's qtree
>> structure, which we can expose in the CLI that gives unique access
>> to every possible property.
> 
> Past resistance to this has been grounded in not wanting to
> expose the exact arrangement of the qtree as a user-facing
> thing that needs to be maintained for back-compat reasons.
> 
> Eg in your example the i440fx-pcihost sits directly on the
> 'system bus', but this is an odd artefact of the old qbus/qdev
> system and doesn't really reflect the way the system is built
> up in terms of QOM components; we might one day want to
> restructure things there, which would AIUI break a
> command line like
> 
>> To uniquely identify this we can have a string:
>>
>>  /dev[1]/bus[pci/0]/dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true

Certainly with the machines that I work on the QOM paths can't be guaranteed to be
stable: a good example would be how over time people have fixed up the macio device
child devices with refactoring.

So if I had a command line that used a QOM path to connect a chardev to the on-board
serial port then this change would have caused all of the previously documented
examples out on the internet to fail :/

That's why I'm more keen to go with using aliases as per my previous email since then
it doesn't matter if the QOM tree structure (accidentally) changes.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-04-30 10:29         ` Mark Cave-Ayland
@ 2020-04-30 14:11           ` Markus Armbruster
  2020-04-30 14:32             ` Mark Cave-Ayland
  0 siblings, 1 reply; 21+ messages in thread
From: Markus Armbruster @ 2020-04-30 14:11 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Marc-André Lureau, Paolo Bonzini

Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:

> On 30/04/2020 11:03, Markus Armbruster wrote:
>> Peter Maydell <peter.maydell@linaro.org> writes:
>> 
>>> On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
>>>> Our means to configure onboard devices are weak.  We sidestepped this
>>>> for isa-fdc by taking it off the board, and thus make -device work.
>>>
>>> This seems to be a general dynamic: the x86 pc machine works
>>> via -device options (or is changed so it can work that way);
>>> and then people propose dropping/deprecating/etc the config
>>> options that work with onboard devices, without providing
>>> clear solutions/instructions on how the command line needs
>>> to change/etc for the mass of boards which are not the x86
>>> pc machine and which do have a lot of onboard devices which
>>> can't be handled via -device.
>>>
>>> So my gut reaction to the "we should deprecate -global"
>>> suggestions in this thread was a bit "here we go again"...
>>> What works for x86 or even "what is sufficient for libvirt"
>>> doesn't necessarily cover all the cases.
>> 
>> Such shortsighted proposals have been made, but don't think it's what
>> we're doing here.
>> 
>> You're 100% right in that we do need to configure onboard devices.
>> -global is a terrible way to do it, though: it applies to *all* devices
>> of a kind.  What if the board has more than one?  What if the can add
>> more?
>> 
>> Taking onboard devices off the board can occasionally sidestep the
>> issue.  For isa-fdc, we genuinely *wanted* to take the damn thing off,
>> because all it did for most users was provide them with VENOM.  Not
>> needing -global for it anymore was just a nice bonus.
>> 
>> Taking onboard devices off just to reduce the device configuration
>> problem to a solved one, namely -device, may be tempting (it was to me),
>> but it's too intrusive to be practical at scale.
>> 
>> Adding machine properties that alias onboard device properties is less
>> intrusive.  The ones I added were still a lot of work.
>> 
>> Configuring onboard devices via machine properties restricts property
>> access to the ones we added to the machine.  This differs from pluggable
>> devices, where users can access all properties.
>> 
>> Any better ideas for letting users configure onboard devices?
>
> Is it possible to let machine owners add alias properties to the machine object
> referencing in-built devices? I could then instantiate my on-board nic in the machine
> init() function, and then use object_property_add_alias() to add a "nic0" alias on
> the machine that can be used to wire it up to a netdev using the command line.

Have a look at hw/arm/virt.c's virt_flash_create(), from commit
e0561e60f1 "hw/arm/virt: Support firmware configuration with -blockdev".
It adds machine properties "pflash0" and "pflash1" as aliases for the
onboard flash memory devices' property "drive".

Does this answer your question?



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-04-30 10:34         ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Daniel P. Berrangé
  2020-04-30 10:45           ` Peter Maydell
@ 2020-04-30 14:27           ` Markus Armbruster
  1 sibling, 0 replies; 21+ messages in thread
From: Markus Armbruster @ 2020-04-30 14:27 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Kevin Wolf, Peter Maydell, Eduardo Habkost, Jason Wang,
	QEMU Developers, Max Reitz, Paolo Bonzini,
	Marc-André Lureau

Daniel P. Berrangé <berrange@redhat.com> writes:

> On Thu, Apr 30, 2020 at 12:03:12PM +0200, Markus Armbruster wrote:
>> Peter Maydell <peter.maydell@linaro.org> writes:
>> 
>> > On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
>> >> Our means to configure onboard devices are weak.  We sidestepped this
>> >> for isa-fdc by taking it off the board, and thus make -device work.
>> >
>> > This seems to be a general dynamic: the x86 pc machine works
>> > via -device options (or is changed so it can work that way);
>> > and then people propose dropping/deprecating/etc the config
>> > options that work with onboard devices, without providing
>> > clear solutions/instructions on how the command line needs
>> > to change/etc for the mass of boards which are not the x86
>> > pc machine and which do have a lot of onboard devices which
>> > can't be handled via -device.
>> >
>> > So my gut reaction to the "we should deprecate -global"
>> > suggestions in this thread was a bit "here we go again"...
>> > What works for x86 or even "what is sufficient for libvirt"
>> > doesn't necessarily cover all the cases.
>> 
>> Such shortsighted proposals have been made, but don't think it's what
>> we're doing here.
>> 
>> You're 100% right in that we do need to configure onboard devices.
>> -global is a terrible way to do it, though: it applies to *all* devices
>> of a kind.  What if the board has more than one?  What if the can add
>> more?
>
>
>> Any better ideas for letting users configure onboard devices?
>
> All the devices in QEMU form a tree, as reported by "info qtree".
> So, IIUC, the challenge is to provide a way to uniquely identify
> any node in the tree.
>
> Devices configured by the user/mgmt app will have an "id" property
> but most built-in devices will not have any "id". In addition even
> user configured devices may create multiple sub-nodes in the tree
> without "id" parameters.
>
> Uniquely referencing nodes in a tee is a solved problem though,
> even without "id" parameters. The XPath query languages shows
> this for XML.
>
> -global defines a query language based on the object type, and
> property name which is insufficiently flexible

Yes.

> -set defines a query language based on the object type and ID
> value and property name(s) which is again insufficiently flexible.

-set is even more obscure than -global.  It modifies existing QemuOpts.
You could use it to monkey-patch a -device to the left, or a [device]
from a -readconfig file to the left, which is a bit more useful.  You
can't use it to configure onboard devices, because there is no QemuOpts
to monkey-patch for them.

> We "merely" need a new query language targetted to QEMU's qtree
> structure, which we can expose in the CLI that gives unique access
> to every possible property.
>
> Here is the truncated 'info qtree' for a running guest of mine:
>
> bus: main-system-bus
>   type System
>   dev: kvm-ioapic, id ""
>     gpio-in "" 24
>     gsi_base = 0 (0x0)
>     mmio 00000000fec00000/0000000000001000
>   dev: i440FX-pcihost, id ""
>     pci-hole64-size = 2147483648 (2 GiB)
>     short_root_bus = 0 (0x0)
>     x-pci-hole64-fix = false
>     bus: pci.0
>       type PCI
>       dev: virtio-balloon-pci, id "balloon0"
>         disable-legacy = "off"
>         disable-modern = true
>         class = 255 (0xff)
>         virtio-pci-bus-master-bug-migration = false
>         migrate-extra = false
>         modern-pio-notify = false
>         x-disable-pcie = true
>         page-per-vq = true
>         x-ignore-backend-features = true
>         ats = false
>         x-pcie-deverr-init = false
>         x-pcie-lnkctl-init = false
>         x-pcie-pm-init = false
>         addr = 08.0
>         romfile = ""
>         rombar = 1 (0x1)
>         multifunction = false
>         command_serr_enable = true
>         x-pcie-lnksta-dllla = true
>         x-pcie-extcap-init = false
>         class Class 00ff, addr 00:08.0, pci id 1af4:1002 (sub 1af4:0005)
>         bar 0: i/o at 0xc100 [0xc11f]
>         bus: virtio-bus
>           type virtio-pci-bus
>           dev: virtio-balloon-device, id ""
>             deflate-on-oom = false
>             free-page-hint = false
>             qemu-4-0-config-size = false
>             iothread = ""
>             indirect_desc = true
>             event_idx = true
>             notify_on_empty = true
>             any_layout = true
>             iommu_platform = false
>             use-started = false
>
>
> Consider the problem is to set the "deflate-on-oom" property on
> the balloon device.
>
> To uniquely identify this we can have a string:
>
>  /dev[1]/bus[pci/0]/dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true

qdev already supports identifying a node in this tree by its path, but
these qdev paths are FUBAR.

Moreover, the qtree misses "busless" devices.

The QOM tree should be as complete as possible, i.e. lack only non-qdev
devices[*].  It also has sane paths.  Have a look at "info qom-tree",
please.

> If we consider that "id" values are unique, we can allow a simplication
> by omitting everything before that part of the match - "//" could indicate
> an omitted part like XPath allows, so we'd get
>
>  //dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true
>
> There's only one bus, and one dev on that bus, so knowing this we can
> simplify a bit more and still be a unique query, to get this:
>
>  //dev[id=balloon0]/bus/dev/deflate-on-oom=true
>
> Or even allow use of "//" in the middle too:
>
>  //dev[id=balloon0]//deflate-on-oom=true
>
> Which conceptually says
>
>    "find the device with id balloon0 and set the property 'deflate-on-oom'
>    on the first child node in the qtree that hsa such a property name"
>
> I didn't say this would be pretty, and of course no one would seriously
> use this syntax for the virtio-balloon device, as you'd just set the
> property with -device. It should work for the many built-in devices
> though.
>
> Now just provide a new CLI arg
>
>  $QEMU -qtree //dev[id=balloon0]//deflate-on-oom=true



[*] It's been eleven years.  Device models that still ignore qdev need
to be taken out and shot, along with the machine types using them.  Any
machine types we actually miss then need to be revived and fixed up.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-04-30 14:11           ` Configuring onboard devices Markus Armbruster
@ 2020-04-30 14:32             ` Mark Cave-Ayland
  2020-04-30 15:20               ` Markus Armbruster
  0 siblings, 1 reply; 21+ messages in thread
From: Mark Cave-Ayland @ 2020-04-30 14:32 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Marc-André Lureau, Paolo Bonzini

On 30/04/2020 15:11, Markus Armbruster wrote:

> Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:
> 
>> On 30/04/2020 11:03, Markus Armbruster wrote:
>>> Peter Maydell <peter.maydell@linaro.org> writes:
>>>
>>>> On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
>>>>> Our means to configure onboard devices are weak.  We sidestepped this
>>>>> for isa-fdc by taking it off the board, and thus make -device work.
>>>>
>>>> This seems to be a general dynamic: the x86 pc machine works
>>>> via -device options (or is changed so it can work that way);
>>>> and then people propose dropping/deprecating/etc the config
>>>> options that work with onboard devices, without providing
>>>> clear solutions/instructions on how the command line needs
>>>> to change/etc for the mass of boards which are not the x86
>>>> pc machine and which do have a lot of onboard devices which
>>>> can't be handled via -device.
>>>>
>>>> So my gut reaction to the "we should deprecate -global"
>>>> suggestions in this thread was a bit "here we go again"...
>>>> What works for x86 or even "what is sufficient for libvirt"
>>>> doesn't necessarily cover all the cases.
>>>
>>> Such shortsighted proposals have been made, but don't think it's what
>>> we're doing here.
>>>
>>> You're 100% right in that we do need to configure onboard devices.
>>> -global is a terrible way to do it, though: it applies to *all* devices
>>> of a kind.  What if the board has more than one?  What if the can add
>>> more?
>>>
>>> Taking onboard devices off the board can occasionally sidestep the
>>> issue.  For isa-fdc, we genuinely *wanted* to take the damn thing off,
>>> because all it did for most users was provide them with VENOM.  Not
>>> needing -global for it anymore was just a nice bonus.
>>>
>>> Taking onboard devices off just to reduce the device configuration
>>> problem to a solved one, namely -device, may be tempting (it was to me),
>>> but it's too intrusive to be practical at scale.
>>>
>>> Adding machine properties that alias onboard device properties is less
>>> intrusive.  The ones I added were still a lot of work.
>>>
>>> Configuring onboard devices via machine properties restricts property
>>> access to the ones we added to the machine.  This differs from pluggable
>>> devices, where users can access all properties.
>>>
>>> Any better ideas for letting users configure onboard devices?
>>
>> Is it possible to let machine owners add alias properties to the machine object
>> referencing in-built devices? I could then instantiate my on-board nic in the machine
>> init() function, and then use object_property_add_alias() to add a "nic0" alias on
>> the machine that can be used to wire it up to a netdev using the command line.
> 
> Have a look at hw/arm/virt.c's virt_flash_create(), from commit
> e0561e60f1 "hw/arm/virt: Support firmware configuration with -blockdev".
> It adds machine properties "pflash0" and "pflash1" as aliases for the
> onboard flash memory devices' property "drive".
> 
> Does this answer your question?

Ah I see now, these aliases are for individual properties rather than objects. What I
was trying to ask was if it were possible to have something like this:

/machine (SS-5-machine)
  /builtin
    /nic0 -> link to "lance" device

Here nic0 is an alias "published" by the maintainer of the SS-5 machine which is
configured in the machine init() function using object_property_add_link() or a
suitable wrapper. Users can then configure these builtin devices from the command
line using your -machine nic0.netdev=my-netdev-id syntax or similar.

Having the default devices under /builtin or other known QOM path would enable
builtin devices to be easily enumerated programatically and/or from the command line
as required.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-04-30 10:53             ` Daniel P. Berrangé
@ 2020-04-30 14:38               ` Markus Armbruster
  0 siblings, 0 replies; 21+ messages in thread
From: Markus Armbruster @ 2020-04-30 14:38 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Kevin Wolf, Peter Maydell, Eduardo Habkost, Jason Wang,
	Markus Armbruster, QEMU Developers, Paolo Bonzini,
	Marc-André Lureau, Max Reitz

Daniel P. Berrangé <berrange@redhat.com> writes:

> On Thu, Apr 30, 2020 at 11:45:40AM +0100, Peter Maydell wrote:
>> On Thu, 30 Apr 2020 at 11:34, Daniel P. Berrangé <berrange@redhat.com> wrote:
>> > We "merely" need a new query language targetted to QEMU's qtree
>> > structure, which we can expose in the CLI that gives unique access
>> > to every possible property.
>> 
>> Past resistance to this has been grounded in not wanting to
>> expose the exact arrangement of the qtree as a user-facing
>> thing that needs to be maintained for back-compat reasons.
>
> I could be missing a key difference, but I thought we already exposed
> the qtree in QMP  via qom-list, qom-get, qom-set ?  Libvirt uses
> these commands for reading various properties.  I guess 'qom-set' is
> really defining the kind of query string language I was illustrating
> already. So mapping qom-set to the CLI as-is would not be worse than
> what we already support in QMP

We like to pretend QOM introspection is not a stable interface.  Except
for the parts that have to be, because they're the only way to probe for
certain things.  We're not telling you which parts, because we have no
idea ourselves.

>> Eg in your example the i440fx-pcihost sits directly on the
>> 'system bus', but this is an odd artefact of the old qbus/qdev
>> system and doesn't really reflect the way the system is built
>> up in terms of QOM components; we might one day want to
>> restructure things there, which would AIUI break a
>> command line like

If we replace qdev paths by QOM paths, the "doesn't really reflect the
way the system is built up in terms of QOM components" goes away.

However, the "we might one day want to restructure things" argument also
applies to QOM.

At some point we need to decide which part of the cake to feed to users,
and which part to keep for developers to mess with.

>> > To uniquely identify this we can have a string:
>> >
>> >  /dev[1]/bus[pci/0]/dev[id=balloon0]/bus[virtio-bus]/dev[0]/deflate-on-oom=true
>
> Regards,
> Daniel



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-04-30 14:32             ` Mark Cave-Ayland
@ 2020-04-30 15:20               ` Markus Armbruster
  2020-04-30 16:56                 ` Mark Cave-Ayland
  0 siblings, 1 reply; 21+ messages in thread
From: Markus Armbruster @ 2020-04-30 15:20 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Paolo Bonzini, Marc-André Lureau

Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:

> On 30/04/2020 15:11, Markus Armbruster wrote:
>
>> Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:
>> 
>>> On 30/04/2020 11:03, Markus Armbruster wrote:
>>>> Peter Maydell <peter.maydell@linaro.org> writes:
>>>>
>>>>> On Thu, 30 Apr 2020 at 08:09, Markus Armbruster <armbru@redhat.com> wrote:
>>>>>> Our means to configure onboard devices are weak.  We sidestepped this
>>>>>> for isa-fdc by taking it off the board, and thus make -device work.
>>>>>
>>>>> This seems to be a general dynamic: the x86 pc machine works
>>>>> via -device options (or is changed so it can work that way);
>>>>> and then people propose dropping/deprecating/etc the config
>>>>> options that work with onboard devices, without providing
>>>>> clear solutions/instructions on how the command line needs
>>>>> to change/etc for the mass of boards which are not the x86
>>>>> pc machine and which do have a lot of onboard devices which
>>>>> can't be handled via -device.
>>>>>
>>>>> So my gut reaction to the "we should deprecate -global"
>>>>> suggestions in this thread was a bit "here we go again"...
>>>>> What works for x86 or even "what is sufficient for libvirt"
>>>>> doesn't necessarily cover all the cases.
>>>>
>>>> Such shortsighted proposals have been made, but don't think it's what
>>>> we're doing here.
>>>>
>>>> You're 100% right in that we do need to configure onboard devices.
>>>> -global is a terrible way to do it, though: it applies to *all* devices
>>>> of a kind.  What if the board has more than one?  What if the can add
>>>> more?
>>>>
>>>> Taking onboard devices off the board can occasionally sidestep the
>>>> issue.  For isa-fdc, we genuinely *wanted* to take the damn thing off,
>>>> because all it did for most users was provide them with VENOM.  Not
>>>> needing -global for it anymore was just a nice bonus.
>>>>
>>>> Taking onboard devices off just to reduce the device configuration
>>>> problem to a solved one, namely -device, may be tempting (it was to me),
>>>> but it's too intrusive to be practical at scale.
>>>>
>>>> Adding machine properties that alias onboard device properties is less
>>>> intrusive.  The ones I added were still a lot of work.
>>>>
>>>> Configuring onboard devices via machine properties restricts property
>>>> access to the ones we added to the machine.  This differs from pluggable
>>>> devices, where users can access all properties.
>>>>
>>>> Any better ideas for letting users configure onboard devices?
>>>
>>> Is it possible to let machine owners add alias properties to the machine object
>>> referencing in-built devices? I could then instantiate my on-board nic in the machine
>>> init() function, and then use object_property_add_alias() to add a "nic0" alias on
>>> the machine that can be used to wire it up to a netdev using the command line.
>> 
>> Have a look at hw/arm/virt.c's virt_flash_create(), from commit
>> e0561e60f1 "hw/arm/virt: Support firmware configuration with -blockdev".
>> It adds machine properties "pflash0" and "pflash1" as aliases for the
>> onboard flash memory devices' property "drive".
>> 
>> Does this answer your question?
>
> Ah I see now, these aliases are for individual properties rather than objects. What I
> was trying to ask was if it were possible to have something like this:
>
> /machine (SS-5-machine)
>   /builtin
>     /nic0 -> link to "lance" device
>
> Here nic0 is an alias "published" by the maintainer of the SS-5 machine which is
> configured in the machine init() function using object_property_add_link() or a
> suitable wrapper. Users can then configure these builtin devices from the command
> line using your -machine nic0.netdev=my-netdev-id syntax or similar.

Got it now, thanks!

> Having the default devices under /builtin or other known QOM path would enable
> builtin devices to be easily enumerated programatically and/or from the command line
> as required.

There are three standard containers under /machine/:

* /machine/peripheral/

  Devices with a user-specified ID go here, as /machine/peripheral/ID.
  User-specified means -device or device_add.

  /machine/peripheral/ID is effectively a stable interface.  It's just
  underdocumented (undocumented?).

  To be useful, the stuff below ID/ needed to be stable and documented,
  too.

* /machine/peripheral-anon/

  Same, but user elected not to give an ID.
  /machine/peripheral-anon/device[N], where N counts up from zero in
  creation order.

  N is obviously not stable, but this is a problem of the user's making.
  If you want to refer to a device, give it an ID.

* /machine/unattached/

  The orphanage.  When a device has no parent when its realized, it gets
  put here, as /machine/unattached/device[N], where N counts up from
  zero in realization order.

  N is obviously not stable, and this time we can't blame the
  victim^Wuser.  You can search for devices of a certain type.
  Sometimes that's good enough.

  All the onboard devices are here, and much more.  We've fathered a lot
  of unloved red-headed children, it seems...

  Some of the "much more" is due to sloppy modelling, i.e. neglecting to
  set the proper parent.

  I figure we could put onboard devices in a nicer place, with nicer
  names.  Need a convention for the place and the names, then make board
  code conform to it.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-04-30 15:20               ` Markus Armbruster
@ 2020-04-30 16:56                 ` Mark Cave-Ayland
  2020-05-02  5:47                   ` Markus Armbruster
  0 siblings, 1 reply; 21+ messages in thread
From: Mark Cave-Ayland @ 2020-04-30 16:56 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Marc-André Lureau, Paolo Bonzini

On 30/04/2020 16:20, Markus Armbruster wrote:

>> Ah I see now, these aliases are for individual properties rather than objects. What I
>> was trying to ask was if it were possible to have something like this:
>>
>> /machine (SS-5-machine)
>>   /builtin
>>     /nic0 -> link to "lance" device
>>
>> Here nic0 is an alias "published" by the maintainer of the SS-5 machine which is
>> configured in the machine init() function using object_property_add_link() or a
>> suitable wrapper. Users can then configure these builtin devices from the command
>> line using your -machine nic0.netdev=my-netdev-id syntax or similar.
> 
> Got it now, thanks!
> 
>> Having the default devices under /builtin or other known QOM path would enable
>> builtin devices to be easily enumerated programatically and/or from the command line
>> as required.
> 
> There are three standard containers under /machine/:
> 
> * /machine/peripheral/
> 
>   Devices with a user-specified ID go here, as /machine/peripheral/ID.
>   User-specified means -device or device_add.
> 
>   /machine/peripheral/ID is effectively a stable interface.  It's just
>   underdocumented (undocumented?).
> 
>   To be useful, the stuff below ID/ needed to be stable and documented,
>   too.
> 
> * /machine/peripheral-anon/
> 
>   Same, but user elected not to give an ID.
>   /machine/peripheral-anon/device[N], where N counts up from zero in
>   creation order.
> 
>   N is obviously not stable, but this is a problem of the user's making.
>   If you want to refer to a device, give it an ID.
> 
> * /machine/unattached/
> 
>   The orphanage.  When a device has no parent when its realized, it gets
>   put here, as /machine/unattached/device[N], where N counts up from
>   zero in realization order.
> 
>   N is obviously not stable, and this time we can't blame the
>   victim^Wuser.  You can search for devices of a certain type.
>   Sometimes that's good enough.
> 
>   All the onboard devices are here, and much more.  We've fathered a lot
>   of unloved red-headed children, it seems...
> 
>   Some of the "much more" is due to sloppy modelling, i.e. neglecting to
>   set the proper parent.
> 
>   I figure we could put onboard devices in a nicer place, with nicer
>   names.  Need a convention for the place and the names, then make board
>   code conform to it.

That's good, it seems that this is already fairly close to how it works for -device
at the moment.

I don't think that it is possible to come up a single place for on-board devices to
live directly though. Going back to one of my first examples: wiring up a chardev to
a serial port on the macio device. To me it makes sense for that to exist in QOM
under /machine/pci-bus/mac-io/escc. In contrast an in-built NIC could live under
/machine/pci-bus/in-built/nic, and placing one or both of these devices directly
under /machine/foo doesn't feel intuitive.

AFAIK as per your ARM virt example I believe it is only possible to register an alias
for a property rather than for an Object? The ultimate aim would be for
object_resolve_path("/machine/builtin/nic0") and
object_resolve_path("/machine/pci-bus/in-built/nic") to return the same Object, and
for the aliases on built-in devices to be children of /machine/builtin to allow easy
iteration and introspection.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-04-30 16:56                 ` Mark Cave-Ayland
@ 2020-05-02  5:47                   ` Markus Armbruster
  2020-05-03 22:13                     ` Mark Cave-Ayland
  0 siblings, 1 reply; 21+ messages in thread
From: Markus Armbruster @ 2020-05-02  5:47 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Paolo Bonzini, Marc-André Lureau

Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:

> On 30/04/2020 16:20, Markus Armbruster wrote:
>
>>> Ah I see now, these aliases are for individual properties rather than objects. What I
>>> was trying to ask was if it were possible to have something like this:
>>>
>>> /machine (SS-5-machine)
>>>   /builtin
>>>     /nic0 -> link to "lance" device
>>>
>>> Here nic0 is an alias "published" by the maintainer of the SS-5 machine which is
>>> configured in the machine init() function using object_property_add_link() or a
>>> suitable wrapper. Users can then configure these builtin devices from the command
>>> line using your -machine nic0.netdev=my-netdev-id syntax or similar.
>> 
>> Got it now, thanks!
>> 
>>> Having the default devices under /builtin or other known QOM path would enable
>>> builtin devices to be easily enumerated programatically and/or from the command line
>>> as required.
>> 
>> There are three standard containers under /machine/:
>> 
>> * /machine/peripheral/
>> 
>>   Devices with a user-specified ID go here, as /machine/peripheral/ID.
>>   User-specified means -device or device_add.
>> 
>>   /machine/peripheral/ID is effectively a stable interface.  It's just
>>   underdocumented (undocumented?).
>> 
>>   To be useful, the stuff below ID/ needed to be stable and documented,
>>   too.
>> 
>> * /machine/peripheral-anon/
>> 
>>   Same, but user elected not to give an ID.
>>   /machine/peripheral-anon/device[N], where N counts up from zero in
>>   creation order.
>> 
>>   N is obviously not stable, but this is a problem of the user's making.
>>   If you want to refer to a device, give it an ID.
>> 
>> * /machine/unattached/
>> 
>>   The orphanage.  When a device has no parent when its realized, it gets
>>   put here, as /machine/unattached/device[N], where N counts up from
>>   zero in realization order.
>> 
>>   N is obviously not stable, and this time we can't blame the
>>   victim^Wuser.  You can search for devices of a certain type.
>>   Sometimes that's good enough.
>> 
>>   All the onboard devices are here, and much more.  We've fathered a lot
>>   of unloved red-headed children, it seems...
>> 
>>   Some of the "much more" is due to sloppy modelling, i.e. neglecting to
>>   set the proper parent.
>> 
>>   I figure we could put onboard devices in a nicer place, with nicer
>>   names.  Need a convention for the place and the names, then make board
>>   code conform to it.
>
> That's good, it seems that this is already fairly close to how it works for -device
> at the moment.
>
> I don't think that it is possible to come up a single place for on-board devices to
> live directly though. Going back to one of my first examples: wiring up a chardev to
> a serial port on the macio device. To me it makes sense for that to exist in QOM
> under /machine/pci-bus/mac-io/escc. In contrast an in-built NIC could live under
> /machine/pci-bus/in-built/nic, and placing one or both of these devices directly
> under /machine/foo doesn't feel intuitive.

I'm not familiar with this machine.  You make me suspect the serial
thingy is a component of a larger device.

Properly modelled, a composite device has its components as children.
These appear below their parent in the QOM composition tree.

Example: a "serial-isa" device has a "serial" component.  When the
former is at /machine/unattached/device[28]/, the latter is at
/machine/unattached/device[28]/serial/.

I guess that's what you want for macio's serial port.

Counter-example: a "isa-super-io" device has compoenents of type
"isa-parallel", "isa-serial", "isa-fdc", "i8042", "isa-ide".
Nevertheless, these appear next to their parent in /machine/unattached/.
I'm still too much of a QOM ignoramus to explain why that's so.  Paolo,
can you?

> AFAIK as per your ARM virt example I believe it is only possible to register an alias
> for a property rather than for an Object? The ultimate aim would be for
> object_resolve_path("/machine/builtin/nic0") and
> object_resolve_path("/machine/pci-bus/in-built/nic") to return the same Object, and
> for the aliases on built-in devices to be children of /machine/builtin to allow easy
> iteration and introspection.

Paolo, could link properties achieve that?

Mark, I guess you want the alias / link from builtin/nic0 to the actual
place to simplify configuration: the user then needs to know less about
the board.  Correct?



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-05-02  5:47                   ` Markus Armbruster
@ 2020-05-03 22:13                     ` Mark Cave-Ayland
  2020-05-04 16:30                       ` Eduardo Habkost
  0 siblings, 1 reply; 21+ messages in thread
From: Mark Cave-Ayland @ 2020-05-03 22:13 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Jason Wang, QEMU Developers, Max Reitz,
	Marc-André Lureau, Paolo Bonzini

On 02/05/2020 06:47, Markus Armbruster wrote:

> Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:
> 
>> On 30/04/2020 16:20, Markus Armbruster wrote:
>>
>>>> Ah I see now, these aliases are for individual properties rather than objects. What I
>>>> was trying to ask was if it were possible to have something like this:
>>>>
>>>> /machine (SS-5-machine)
>>>>   /builtin
>>>>     /nic0 -> link to "lance" device
>>>>
>>>> Here nic0 is an alias "published" by the maintainer of the SS-5 machine which is
>>>> configured in the machine init() function using object_property_add_link() or a
>>>> suitable wrapper. Users can then configure these builtin devices from the command
>>>> line using your -machine nic0.netdev=my-netdev-id syntax or similar.
>>>
>>> Got it now, thanks!
>>>
>>>> Having the default devices under /builtin or other known QOM path would enable
>>>> builtin devices to be easily enumerated programatically and/or from the command line
>>>> as required.
>>>
>>> There are three standard containers under /machine/:
>>>
>>> * /machine/peripheral/
>>>
>>>   Devices with a user-specified ID go here, as /machine/peripheral/ID.
>>>   User-specified means -device or device_add.
>>>
>>>   /machine/peripheral/ID is effectively a stable interface.  It's just
>>>   underdocumented (undocumented?).
>>>
>>>   To be useful, the stuff below ID/ needed to be stable and documented,
>>>   too.
>>>
>>> * /machine/peripheral-anon/
>>>
>>>   Same, but user elected not to give an ID.
>>>   /machine/peripheral-anon/device[N], where N counts up from zero in
>>>   creation order.
>>>
>>>   N is obviously not stable, but this is a problem of the user's making.
>>>   If you want to refer to a device, give it an ID.
>>>
>>> * /machine/unattached/
>>>
>>>   The orphanage.  When a device has no parent when its realized, it gets
>>>   put here, as /machine/unattached/device[N], where N counts up from
>>>   zero in realization order.
>>>
>>>   N is obviously not stable, and this time we can't blame the
>>>   victim^Wuser.  You can search for devices of a certain type.
>>>   Sometimes that's good enough.
>>>
>>>   All the onboard devices are here, and much more.  We've fathered a lot
>>>   of unloved red-headed children, it seems...
>>>
>>>   Some of the "much more" is due to sloppy modelling, i.e. neglecting to
>>>   set the proper parent.
>>>
>>>   I figure we could put onboard devices in a nicer place, with nicer
>>>   names.  Need a convention for the place and the names, then make board
>>>   code conform to it.
>>
>> That's good, it seems that this is already fairly close to how it works for -device
>> at the moment.
>>
>> I don't think that it is possible to come up a single place for on-board devices to
>> live directly though. Going back to one of my first examples: wiring up a chardev to
>> a serial port on the macio device. To me it makes sense for that to exist in QOM
>> under /machine/pci-bus/mac-io/escc. In contrast an in-built NIC could live under
>> /machine/pci-bus/in-built/nic, and placing one or both of these devices directly
>> under /machine/foo doesn't feel intuitive.
> 
> I'm not familiar with this machine.  You make me suspect the serial
> thingy is a component of a larger device.
> 
> Properly modelled, a composite device has its components as children.
> These appear below their parent in the QOM composition tree.
> 
> Example: a "serial-isa" device has a "serial" component.  When the
> former is at /machine/unattached/device[28]/, the latter is at
> /machine/unattached/device[28]/serial/.
> 
> I guess that's what you want for macio's serial port.
> 
> Counter-example: a "isa-super-io" device has compoenents of type
> "isa-parallel", "isa-serial", "isa-fdc", "i8042", "isa-ide".
> Nevertheless, these appear next to their parent in /machine/unattached/.
> I'm still too much of a QOM ignoramus to explain why that's so.  Paolo,
> can you?

FWIW the older machines have a lot of calls to qdev_create(NULL, TYPE_FOO) for
devices that are part of the machine because they live within the machine address
space but are not specifically attached to a qbus.

>> AFAIK as per your ARM virt example I believe it is only possible to register an alias
>> for a property rather than for an Object? The ultimate aim would be for
>> object_resolve_path("/machine/builtin/nic0") and
>> object_resolve_path("/machine/pci-bus/in-built/nic") to return the same Object, and
>> for the aliases on built-in devices to be children of /machine/builtin to allow easy
>> iteration and introspection.
> 
> Paolo, could link properties achieve that?
> 
> Mark, I guess you want the alias / link from builtin/nic0 to the actual
> place to simplify configuration: the user then needs to know less about
> the board.  Correct?

Correct. In a perfect world I'd love to say that Daniel's suggestion to use QOM paths
would work, however from my experience they change far too much. This is one of the
reasons that the TYPE_FW_PATH_PROVIDER interface exists so that the generation of
(boot) paths for the firmware is separate from the QOM/qdev paths.

I don't feel too strongly whether it's a link property, some kind of alias, or
perhaps like OpenFirmware just a string property containing the QOM path to the
device, since ultimately I imagine there would be wrapper functions for machine
init() to call which hide away the implementation details.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Configuring onboard devices
  2020-05-03 22:13                     ` Mark Cave-Ayland
@ 2020-05-04 16:30                       ` Eduardo Habkost
  0 siblings, 0 replies; 21+ messages in thread
From: Eduardo Habkost @ 2020-05-04 16:30 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: Kevin Wolf, Peter Maydell, Daniel P. Berrangé,
	Jason Wang, Markus Armbruster, QEMU Developers,
	Marc-André Lureau, Paolo Bonzini, Max Reitz

On Sun, May 03, 2020 at 11:13:41PM +0100, Mark Cave-Ayland wrote:
> On 02/05/2020 06:47, Markus Armbruster wrote:
> 
> > Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:
> > 
> >> On 30/04/2020 16:20, Markus Armbruster wrote:
> >>
> >>>> Ah I see now, these aliases are for individual properties rather than objects. What I
> >>>> was trying to ask was if it were possible to have something like this:
> >>>>
> >>>> /machine (SS-5-machine)
> >>>>   /builtin
> >>>>     /nic0 -> link to "lance" device
> >>>>
> >>>> Here nic0 is an alias "published" by the maintainer of the SS-5 machine which is
> >>>> configured in the machine init() function using object_property_add_link() or a
> >>>> suitable wrapper. Users can then configure these builtin devices from the command
> >>>> line using your -machine nic0.netdev=my-netdev-id syntax or similar.
> >>>
> >>> Got it now, thanks!
> >>>
> >>>> Having the default devices under /builtin or other known QOM path would enable
> >>>> builtin devices to be easily enumerated programatically and/or from the command line
> >>>> as required.
> >>>
> >>> There are three standard containers under /machine/:
> >>>
> >>> * /machine/peripheral/
> >>>
> >>>   Devices with a user-specified ID go here, as /machine/peripheral/ID.
> >>>   User-specified means -device or device_add.
> >>>
> >>>   /machine/peripheral/ID is effectively a stable interface.  It's just
> >>>   underdocumented (undocumented?).
> >>>
> >>>   To be useful, the stuff below ID/ needed to be stable and documented,
> >>>   too.
> >>>
> >>> * /machine/peripheral-anon/
> >>>
> >>>   Same, but user elected not to give an ID.
> >>>   /machine/peripheral-anon/device[N], where N counts up from zero in
> >>>   creation order.
> >>>
> >>>   N is obviously not stable, but this is a problem of the user's making.
> >>>   If you want to refer to a device, give it an ID.
> >>>
> >>> * /machine/unattached/
> >>>
> >>>   The orphanage.  When a device has no parent when its realized, it gets
> >>>   put here, as /machine/unattached/device[N], where N counts up from
> >>>   zero in realization order.
> >>>
> >>>   N is obviously not stable, and this time we can't blame the
> >>>   victim^Wuser.  You can search for devices of a certain type.
> >>>   Sometimes that's good enough.
> >>>
> >>>   All the onboard devices are here, and much more.  We've fathered a lot
> >>>   of unloved red-headed children, it seems...
> >>>
> >>>   Some of the "much more" is due to sloppy modelling, i.e. neglecting to
> >>>   set the proper parent.
> >>>
> >>>   I figure we could put onboard devices in a nicer place, with nicer
> >>>   names.  Need a convention for the place and the names, then make board
> >>>   code conform to it.
> >>
> >> That's good, it seems that this is already fairly close to how it works for -device
> >> at the moment.
> >>
> >> I don't think that it is possible to come up a single place for on-board devices to
> >> live directly though. Going back to one of my first examples: wiring up a chardev to
> >> a serial port on the macio device. To me it makes sense for that to exist in QOM
> >> under /machine/pci-bus/mac-io/escc. In contrast an in-built NIC could live under
> >> /machine/pci-bus/in-built/nic, and placing one or both of these devices directly
> >> under /machine/foo doesn't feel intuitive.
> > 
> > I'm not familiar with this machine.  You make me suspect the serial
> > thingy is a component of a larger device.
> > 
> > Properly modelled, a composite device has its components as children.
> > These appear below their parent in the QOM composition tree.
> > 
> > Example: a "serial-isa" device has a "serial" component.  When the
> > former is at /machine/unattached/device[28]/, the latter is at
> > /machine/unattached/device[28]/serial/.
> > 
> > I guess that's what you want for macio's serial port.
> > 
> > Counter-example: a "isa-super-io" device has compoenents of type
> > "isa-parallel", "isa-serial", "isa-fdc", "i8042", "isa-ide".
> > Nevertheless, these appear next to their parent in /machine/unattached/.
> > I'm still too much of a QOM ignoramus to explain why that's so.  Paolo,
> > can you?
> 
> FWIW the older machines have a lot of calls to qdev_create(NULL, TYPE_FOO) for
> devices that are part of the machine because they live within the machine address
> space but are not specifically attached to a qbus.
> 
> >> AFAIK as per your ARM virt example I believe it is only possible to register an alias
> >> for a property rather than for an Object? The ultimate aim would be for
> >> object_resolve_path("/machine/builtin/nic0") and
> >> object_resolve_path("/machine/pci-bus/in-built/nic") to return the same Object, and
> >> for the aliases on built-in devices to be children of /machine/builtin to allow easy
> >> iteration and introspection.
> > 
> > Paolo, could link properties achieve that?
> > 
> > Mark, I guess you want the alias / link from builtin/nic0 to the actual
> > place to simplify configuration: the user then needs to know less about
> > the board.  Correct?
> 
> Correct. In a perfect world I'd love to say that Daniel's suggestion to use QOM paths
> would work, however from my experience they change far too much. This is one of the
> reasons that the TYPE_FW_PATH_PROVIDER interface exists so that the generation of
> (boot) paths for the firmware is separate from the QOM/qdev paths.
> 
> I don't feel too strongly whether it's a link property, some kind of alias, or
> perhaps like OpenFirmware just a string property containing the QOM path to the
> device, since ultimately I imagine there would be wrapper functions for machine
> init() to call which hide away the implementation details.

Whatever solution we use to make sure a new interface is stable,
we must have automated test cases to ensure we don't break it in
the future.  Otherwise we will be creating yet another
compatibility-keeping ritual that we fail to follow because
nobody notices when we break it.

I wouldn't like to move from "2 different object paths that can't
be trusted to be stable" to "3 different object paths that can't
be trusted to be stable".

-- 
Eduardo



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-05-04 16:31 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29 15:28 Failing property setters + hardwired devices + -global = a bad day Markus Armbruster
2020-04-29 15:39 ` Paolo Bonzini
2020-04-29 16:23   ` Eduardo Habkost
2020-04-29 15:57 ` Daniel P. Berrangé
2020-04-30  7:09   ` Markus Armbruster
2020-04-30  9:27     ` Peter Maydell
2020-04-30 10:03       ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Markus Armbruster
2020-04-30 10:29         ` Mark Cave-Ayland
2020-04-30 14:11           ` Configuring onboard devices Markus Armbruster
2020-04-30 14:32             ` Mark Cave-Ayland
2020-04-30 15:20               ` Markus Armbruster
2020-04-30 16:56                 ` Mark Cave-Ayland
2020-05-02  5:47                   ` Markus Armbruster
2020-05-03 22:13                     ` Mark Cave-Ayland
2020-05-04 16:30                       ` Eduardo Habkost
2020-04-30 10:34         ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Daniel P. Berrangé
2020-04-30 10:45           ` Peter Maydell
2020-04-30 10:53             ` Daniel P. Berrangé
2020-04-30 14:38               ` Configuring onboard devices Markus Armbruster
2020-04-30 10:54             ` Configuring onboard devices (was: Failing property setters + hardwired devices + -global = a bad day) Mark Cave-Ayland
2020-04-30 14:27           ` Configuring onboard devices Markus Armbruster

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.