[PATCH 6/9] hw/ppc/pef: Consolidate OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES

Zhao Liu posted 9 patches 6 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Magnus Damm <magnus.damm@gmail.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Peter Maydell <peter.maydell@linaro.org>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Richard Henderson <richard.henderson@linaro.org>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>
[PATCH 6/9] hw/ppc/pef: Consolidate OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES
Posted by Zhao Liu 6 months ago
The QOM type of PefGuest is declared by OBJECT_DECLARE_SIMPLE_TYPE,
which means it doesn't need the class!

Therefore, use OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES to implement
the type, then there's no need for class definition.

Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
Cc: qemu-ppc@nongnu.org
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 hw/ppc/pef.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/hw/ppc/pef.c b/hw/ppc/pef.c
index 254f5707876f..1832791ee533 100644
--- a/hw/ppc/pef.c
+++ b/hw/ppc/pef.c
@@ -20,11 +20,6 @@
 OBJECT_DECLARE_SIMPLE_TYPE(PefGuest, PEF_GUEST)
 
 typedef struct PefGuest PefGuest;
-typedef struct PefGuestClass PefGuestClass;
-
-struct PefGuestClass {
-    ConfidentialGuestSupportClass parent_class;
-};
 
 /**
  * PefGuest:
@@ -121,12 +116,12 @@ static int pef_kvm_reset(ConfidentialGuestSupport *cgs, Error **errp)
     return kvmppc_svm_off(errp);
 }
 
-OBJECT_DEFINE_TYPE_WITH_INTERFACES(PefGuest,
-                                   pef_guest,
-                                   PEF_GUEST,
-                                   CONFIDENTIAL_GUEST_SUPPORT,
-                                   { TYPE_USER_CREATABLE },
-                                   { NULL })
+OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(PefGuest,
+                                          pef_guest,
+                                          PEF_GUEST,
+                                          CONFIDENTIAL_GUEST_SUPPORT,
+                                          { TYPE_USER_CREATABLE },
+                                          { NULL })
 
 static void pef_guest_class_init(ObjectClass *oc, const void *data)
 {
-- 
2.34.1
Re: [PATCH 6/9] hw/ppc/pef: Consolidate OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES
Posted by BALATON Zoltan 6 months ago
On Wed, 14 May 2025, Zhao Liu wrote:
> The QOM type of PefGuest is declared by OBJECT_DECLARE_SIMPLE_TYPE,
> which means it doesn't need the class!
>
> Therefore, use OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES to implement
> the type, then there's no need for class definition.
>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
> Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Cc: qemu-ppc@nongnu.org
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---
> hw/ppc/pef.c | 17 ++++++-----------
> 1 file changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/hw/ppc/pef.c b/hw/ppc/pef.c
> index 254f5707876f..1832791ee533 100644
> --- a/hw/ppc/pef.c
> +++ b/hw/ppc/pef.c
> @@ -20,11 +20,6 @@
> OBJECT_DECLARE_SIMPLE_TYPE(PefGuest, PEF_GUEST)
>
> typedef struct PefGuest PefGuest;
> -typedef struct PefGuestClass PefGuestClass;
> -
> -struct PefGuestClass {
> -    ConfidentialGuestSupportClass parent_class;
> -};
>
> /**
>  * PefGuest:
> @@ -121,12 +116,12 @@ static int pef_kvm_reset(ConfidentialGuestSupport *cgs, Error **errp)
>     return kvmppc_svm_off(errp);
> }
>
> -OBJECT_DEFINE_TYPE_WITH_INTERFACES(PefGuest,
> -                                   pef_guest,
> -                                   PEF_GUEST,
> -                                   CONFIDENTIAL_GUEST_SUPPORT,
> -                                   { TYPE_USER_CREATABLE },
> -                                   { NULL })
> +OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(PefGuest,
> +                                          pef_guest,
> +                                          PEF_GUEST,
> +                                          CONFIDENTIAL_GUEST_SUPPORT,
> +                                          { TYPE_USER_CREATABLE },
> +                                          { NULL })

Maybe also change the name while at it because the WITH_INTERFACES macros 
usually allow to pass an interfaces list instead of the single hardcoded 
USER_CREATABLE interface here so if such variant is added it would clash. 
Better call this something that shows this is PEF specific or just use the 
appropriate macro from qemu/object.h to define it.

Regards,
BALATON Zoltan

>
> static void pef_guest_class_init(ObjectClass *oc, const void *data)
> {
>
Re: [PATCH 6/9] hw/ppc/pef: Consolidate OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES
Posted by BALATON Zoltan 6 months ago
On Wed, 14 May 2025, BALATON Zoltan wrote:
> On Wed, 14 May 2025, Zhao Liu wrote:
>> The QOM type of PefGuest is declared by OBJECT_DECLARE_SIMPLE_TYPE,
>> which means it doesn't need the class!
>> 
>> Therefore, use OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES to implement
>> the type, then there's no need for class definition.
>> 
>> Cc: Nicholas Piggin <npiggin@gmail.com>
>> Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
>> Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
>> Cc: qemu-ppc@nongnu.org
>> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
>> ---
>> hw/ppc/pef.c | 17 ++++++-----------
>> 1 file changed, 6 insertions(+), 11 deletions(-)
>> 
>> diff --git a/hw/ppc/pef.c b/hw/ppc/pef.c
>> index 254f5707876f..1832791ee533 100644
>> --- a/hw/ppc/pef.c
>> +++ b/hw/ppc/pef.c
>> @@ -20,11 +20,6 @@
>> OBJECT_DECLARE_SIMPLE_TYPE(PefGuest, PEF_GUEST)
>> 
>> typedef struct PefGuest PefGuest;
>> -typedef struct PefGuestClass PefGuestClass;
>> -
>> -struct PefGuestClass {
>> -    ConfidentialGuestSupportClass parent_class;
>> -};
>> 
>> /**
>>  * PefGuest:
>> @@ -121,12 +116,12 @@ static int pef_kvm_reset(ConfidentialGuestSupport 
>> *cgs, Error **errp)
>>     return kvmppc_svm_off(errp);
>> }
>> 
>> -OBJECT_DEFINE_TYPE_WITH_INTERFACES(PefGuest,
>> -                                   pef_guest,
>> -                                   PEF_GUEST,
>> -                                   CONFIDENTIAL_GUEST_SUPPORT,
>> -                                   { TYPE_USER_CREATABLE },
>> -                                   { NULL })
>> +OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(PefGuest,
>> +                                          pef_guest,
>> +                                          PEF_GUEST,
>> +                                          CONFIDENTIAL_GUEST_SUPPORT,
>> +                                          { TYPE_USER_CREATABLE },
>> +                                          { NULL })
>
> Maybe also change the name while at it because the WITH_INTERFACES macros 
> usually allow to pass an interfaces list instead of the single hardcoded 
> USER_CREATABLE interface here so if such variant is added it would clash. 
> Better call this something that shows this is PEF specific or just use the 
> appropriate macro from qemu/object.h to define it.

Ignore this, I've found the rest of the series and now see better what 
it's about. Sorry for the noise.

Regards,
BALATON Zoltan

>> 
>> static void pef_guest_class_init(ObjectClass *oc, const void *data)
>> {
>> 
>
>