[v2,2/2] hw/acpi/vmgenid: prevent more than one vmgenid device

Submitted by Laszlo Ersek on March 20, 2017, 5:05 p.m.

Details

Message ID 20170320170557.15645-3-lersek@redhat.com
State New
Headers show

Commit Message

Laszlo Ersek March 20, 2017, 5:05 p.m.
A system with multiple VMGENID devices is undefined in the VMGENID spec by
omission.

Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Ben Warren <ben@skyportsystems.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    v2:
    - use find_vmgenid_dev() rather than open-code
      object_resolve_path_type() [Michael]
    - add comments to both the definition of find_vmgenid_dev() and its call
      site in vmgenid_realize() [Michael]

 include/hw/acpi/vmgenid.h | 1 +
 hw/acpi/vmgenid.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

Comments

ben@skyportsystems.com March 20, 2017, 11:41 p.m.
Thanks Laszlo!

> On Mar 20, 2017, at 10:05 AM, Laszlo Ersek <lersek@redhat.com> wrote:
> 
> A system with multiple VMGENID devices is undefined in the VMGENID spec by
> omission.
> 
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Ben Warren <ben@skyportsystems.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Ben Warren <ben@skyportsystems.com>

> ---
> 
> Notes:
>    v2:
>    - use find_vmgenid_dev() rather than open-code
>      object_resolve_path_type() [Michael]
>    - add comments to both the definition of find_vmgenid_dev() and its call
>      site in vmgenid_realize() [Michael]
> 
> include/hw/acpi/vmgenid.h | 1 +
> hw/acpi/vmgenid.c         | 8 ++++++++
> 2 files changed, 9 insertions(+)
> 
> diff --git a/include/hw/acpi/vmgenid.h b/include/hw/acpi/vmgenid.h
> index 8578476baebe..7beb9592fb01 100644
> --- a/include/hw/acpi/vmgenid.h
> +++ b/include/hw/acpi/vmgenid.h
> @@ -24,6 +24,7 @@ typedef struct VmGenIdState {
>     bool write_pointer_available;
> } VmGenIdState;
> 
> +/* returns NULL unless there is exactly one device */
> static inline Object *find_vmgenid_dev(void)
> {
>     return object_resolve_path_type("", VMGENID_DEVICE, NULL);
> diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
> index c3ddcc8e7cb0..a32b847fe0df 100644
> --- a/hw/acpi/vmgenid.c
> +++ b/hw/acpi/vmgenid.c
> @@ -221,6 +221,14 @@ static void vmgenid_realize(DeviceState *dev, Error **errp)
>         return;
>     }
> 
> +    /* Given that this function is executing, there is at least one VMGENID
> +     * device. Check if there are several.
> +     */
> +    if (!find_vmgenid_dev()) {
> +        error_setg(errp, "at most one %s device is permitted", VMGENID_DEVICE);
> +        return;
> +    }
> +
>     qemu_register_reset(vmgenid_handle_reset, vms);
> }
> 
> -- 
> 2.9.3
>
Igor Mammedov March 21, 2017, 12:14 p.m.
On Mon, 20 Mar 2017 18:05:57 +0100
Laszlo Ersek <lersek@redhat.com> wrote:

> A system with multiple VMGENID devices is undefined in the VMGENID spec by
> omission.
> 
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Ben Warren <ben@skyportsystems.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
> 
> Notes:
>     v2:
>     - use find_vmgenid_dev() rather than open-code
>       object_resolve_path_type() [Michael]
>     - add comments to both the definition of find_vmgenid_dev() and its call
>       site in vmgenid_realize() [Michael]
> 
>  include/hw/acpi/vmgenid.h | 1 +
>  hw/acpi/vmgenid.c         | 8 ++++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/include/hw/acpi/vmgenid.h b/include/hw/acpi/vmgenid.h
> index 8578476baebe..7beb9592fb01 100644
> --- a/include/hw/acpi/vmgenid.h
> +++ b/include/hw/acpi/vmgenid.h
> @@ -24,6 +24,7 @@ typedef struct VmGenIdState {
>      bool write_pointer_available;
>  } VmGenIdState;
>  
> +/* returns NULL unless there is exactly one device */
>  static inline Object *find_vmgenid_dev(void)
>  {
>      return object_resolve_path_type("", VMGENID_DEVICE, NULL);
> diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
> index c3ddcc8e7cb0..a32b847fe0df 100644
> --- a/hw/acpi/vmgenid.c
> +++ b/hw/acpi/vmgenid.c
> @@ -221,6 +221,14 @@ static void vmgenid_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> +    /* Given that this function is executing, there is at least one VMGENID
> +     * device. Check if there are several.
> +     */
> +    if (!find_vmgenid_dev()) {
> +        error_setg(errp, "at most one %s device is permitted", VMGENID_DEVICE);
> +        return;
> +    }
> +
>      qemu_register_reset(vmgenid_handle_reset, vms);
>  }
>

Patch hide | download patch | download mbox

diff --git a/include/hw/acpi/vmgenid.h b/include/hw/acpi/vmgenid.h
index 8578476baebe..7beb9592fb01 100644
--- a/include/hw/acpi/vmgenid.h
+++ b/include/hw/acpi/vmgenid.h
@@ -24,6 +24,7 @@  typedef struct VmGenIdState {
     bool write_pointer_available;
 } VmGenIdState;
 
+/* returns NULL unless there is exactly one device */
 static inline Object *find_vmgenid_dev(void)
 {
     return object_resolve_path_type("", VMGENID_DEVICE, NULL);
diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
index c3ddcc8e7cb0..a32b847fe0df 100644
--- a/hw/acpi/vmgenid.c
+++ b/hw/acpi/vmgenid.c
@@ -221,6 +221,14 @@  static void vmgenid_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    /* Given that this function is executing, there is at least one VMGENID
+     * device. Check if there are several.
+     */
+    if (!find_vmgenid_dev()) {
+        error_setg(errp, "at most one %s device is permitted", VMGENID_DEVICE);
+        return;
+    }
+
     qemu_register_reset(vmgenid_handle_reset, vms);
 }