target/riscv/kvm: add riscv-aia bool props
cover target/riscv/kvm: add riscv-aia bool props
Hi,
Boolean properties are easier to deal with in the protocol side (e.g. QMP) since they don't require string parsing. We should always use them when applicable.
This series adds 3 new riscv-aia bool options for the KVM accel driver, each one representing the possible values (emul, hwaccel and auto). We're also deprecating the existing 'riscv-aia' string option.
The idea is to use the new properties to enable AIA support in libvirt.
Patches based on riscv-to-apply.next.
Daniel Henrique Barboza (4):
target/riscv/kvm: set 'aia_mode' to default in error path target/riscv/kvm: clarify how 'riscv-aia' default works target/riscv/kvm: add kvm-aia bools props target/riscv/kvm: deprecate riscv-aia string prop
docs/about/deprecated.rst | 8 +++ target/riscv/kvm/kvm-cpu.c | 100 +++++++++++++++++++++++++++++++++---- 2 files changed, 98 insertions(+), 10 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/4 target/riscv/kvm: set 'aia_mode' to default in error path
When failing to set the selected AIA mode, 'aia_mode' is left untouched. This means that 'aia_mode' will not reflect the actual AIA mode, retrieved in 'default_aia_mode',
This is benign for now, but it will impact QMP query commands that will expose the 'aia_mode' value, retrieving the wrong value.
Set 'aia_mode' to 'default_aia_mode' if we fail to change the AIA mode in KVM.
While we're at it, rework the log/warning messages to be a bit less verbose. Instead of:
KVM AIA: default mode is emul
qemu-system-riscv64: warning: KVM AIA: failed to set KVM AIA mode
We can use a single warning message:
qemu-system-riscv64: warning: KVM AIA: failed to set KVM AIA mode 'auto', using default host mode 'emul'
--- target/riscv/kvm/kvm-cpu.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
target/riscv/kvm/kvm-cpu.c +15 -7
@@ -1711,18 +1711,26 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,error_report ("KVM AIA: failed to get current KVM AIA mode" );exit (1 ); } -qemu_log ("KVM AIA: default mode is %s\n" , -kvm_aia_mode_str (default_aia_mode)); -if (default_aia_mode != aia_mode) { +if (default_aia_mode == aia_mode) { +qemu_log ("KVM AIA: using default host mode '%s'\n" , +kvm_aia_mode_str (default_aia_mode)); + }else { ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG ,KVM_DEV_RISCV_AIA_CONFIG_MODE , &aia_mode, true,NULL ); -if (ret <0 ) -warn_report ("KVM AIA: failed to set KVM AIA mode" ); -else -qemu_log ("KVM AIA: set current mode to %s\n" , +if (ret <0 ) { +warn_report ("KVM AIA: failed to set KVM AIA mode '%s', using " +"default host mode '%s'" , +kvm_aia_mode_str (aia_mode), +kvm_aia_mode_str (default_aia_mode)); + +/* failed to change AIA mode, use default */ + aia_mode = default_aia_mode; + }else { +qemu_log ("KVM AIA: setting current mode to %s\n" ,kvm_aia_mode_str (aia_mode)); + } } ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
Signature · 1 line
2.45.2
Re: [PATCH 1/4] target/riscv/kvm: set 'aia_mode' to default in error path
Quoted 14 lines · Daniel Henrique Barboza
When failing to set the selected AIA mode, '
aia_mode' is left untouched. This means that 'aia_mode' will not reflect the actual AIA mode, retrieved in 'default_aia_mode',This is benign for now, but it will impact QMP query commands that will expose the '
aia_mode' value, retrieving the wrong value.Set '
aia_mode' to 'default_aia_mode' if we fail to change the AIA mode in KVM.While we're at it, rework the log/warning messages to be a bit less verbose. Instead of:
Quoted 8 lines
KVM AIA: default mode is emul
qemu-system-riscv64: warning: KVM AIA: failed to set KVM AIA modeWe can use a single warning message:
qemu-system-riscv64: warning: KVM AIA: failed to set KVM AIA mode 'auto', using default host mode 'emul'
Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 46 lines
--- target/riscv/kvm/kvm-cpu.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)target/riscv/kvm/kvm-cpu.c +15
-8@@ -1711,18 +1711,26 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,error_report ("KVM AIA: failed to get current KVM AIA mode" );exit (1 ); } -qemu_log ("KVM AIA: default mode is %s\n" , -kvm_aia_mode_str (default_aia_mode)); -if (default_aia_mode != aia_mode) { +if (default_aia_mode == aia_mode) { +qemu_log ("KVM AIA: using default host mode '%s'\n" , +kvm_aia_mode_str (default_aia_mode)); + }else { ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG ,KVM_DEV_RISCV_AIA_CONFIG_MODE , &aia_mode, true,NULL ); -if (ret <0 ) -warn_report ("KVM AIA: failed to set KVM AIA mode" ); -else -qemu_log ("KVM AIA: set current mode to %s\n" , +if (ret <0 ) { +warn_report ("KVM AIA: failed to set KVM AIA mode '%s', using " +"default host mode '%s'" , +kvm_aia_mode_str (aia_mode), +kvm_aia_mode_str (default_aia_mode)); + +/* failed to change AIA mode, use default */ + aia_mode = default_aia_mode; + }else { +qemu_log ("KVM AIA: setting current mode to %s\n" ,kvm_aia_mode_str (aia_mode)); + } } ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, --2.45.2
PATCH 2/4 target/riscv/kvm: clarify how 'riscv-aia' default works
In reply to Daniel Henrique BarbozaWe do not have control in the default 'riscv-aia' default value. We can try to set it to a specific value, in this case 'auto', but there's no guarantee that the host will accept it.
Couple with this we're always doing a 'qemu_log' to inform whether we're ended up using the host default or if we managed to set the AIA mode to the QEMU default we wanted to set.
Change the 'riscv-aia' description to better reflect how the option works, and remove the two informative 'qemu_log' that are now unneeded:
if no message shows, riscv-aia was set to the default or uset-set value.
--- target/riscv/kvm/kvm-cpu.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
target/riscv/kvm/kvm-cpu.c +4 -10
@@ -1676,9 +1676,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc)object_class_property_add_str (oc,"riscv-aia" , riscv_get_kvm_aia, riscv_set_kvm_aia);object_class_property_set_description (oc,"riscv-aia" , -"Set KVM AIA mode. Valid values are " -"emul, hwaccel, and auto. Default " -"is auto." ); +"Set KVM AIA mode. Valid values are 'emul', 'hwaccel' and 'auto'. " +"Changing KVM AIA modes relies on host support. Defaults to 'auto' " +"if the host supports it" );object_property_set_default_str (object_class_property_find (oc,"riscv-aia" ),"auto" ); }
@@ -1712,10 +1712,7 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,exit (1 ); } -if (default_aia_mode == aia_mode) { -qemu_log ("KVM AIA: using default host mode '%s'\n" , -kvm_aia_mode_str (default_aia_mode)); - }else { +if (default_aia_mode != aia_mode) { ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG ,KVM_DEV_RISCV_AIA_CONFIG_MODE , &aia_mode, true,NULL );
@@ -1727,9 +1724,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,/* failed to change AIA mode, use default */ aia_mode = default_aia_mode; - }else { -qemu_log ("KVM AIA: setting current mode to %s\n" , -kvm_aia_mode_str (aia_mode)); } }
Signature · 1 line
2.45.2
Re: [PATCH 2/4] target/riscv/kvm: clarify how 'riscv-aia' default works
Quoted 9 lines · Daniel Henrique Barboza
We do not have control in the default 'riscv-aia' default value. We can try to set it to a specific value, in this case 'auto', but there's no guarantee that the host will accept it.
Couple with this we're always doing a '
qemu_log' to inform whether we're ended up using the host default or if we managed to set the AIA mode to the QEMU default we wanted to set.
Quoted 5 lines
Change the 'riscv-aia' description to better reflect how the option works, and remove the two informative '
qemu_log' that are now unneeded:
if no message shows, riscv-aia was set to the default or uset-set value.Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 47 lines
--- target/riscv/kvm/kvm-cpu.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)target/riscv/kvm/kvm-cpu.c +4
-11@@ -1676,9 +1676,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc)object_class_property_add_str (oc,"riscv-aia" , riscv_get_kvm_aia, riscv_set_kvm_aia);object_class_property_set_description (oc,"riscv-aia" , -"Set KVM AIA mode. Valid values are " -"emul, hwaccel, and auto. Default " -"is auto." ); +"Set KVM AIA mode. Valid values are 'emul', 'hwaccel' and 'auto'. " +"Changing KVM AIA modes relies on host support. Defaults to 'auto' " +"if the host supports it" );object_property_set_default_str (object_class_property_find (oc,"riscv-aia" ),"auto" ); }@@ -1712,10 +1712,7 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,exit (1 ); } -if (default_aia_mode == aia_mode) { -qemu_log ("KVM AIA: using default host mode '%s'\n" , -kvm_aia_mode_str (default_aia_mode)); - }else { +if (default_aia_mode != aia_mode) { ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG ,KVM_DEV_RISCV_AIA_CONFIG_MODE , &aia_mode, true,NULL );@@ -1727,9 +1724,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,/* failed to change AIA mode, use default */ aia_mode = default_aia_mode; - }else { -qemu_log ("KVM AIA: setting current mode to %s\n" , -kvm_aia_mode_str (aia_mode)); } } --2.45.2
PATCH 3/4 target/riscv/kvm: add kvm-aia bools props
In reply to Daniel Henrique BarbozaBoolean properties are preferrable in comparision to string properties since they don't require a string parsing.
Add three bools that represents the available kvm-aia mode:
riscv-aia-emul, riscv-aia-hwaccel, riscv-aia-auto. They work like the existing riscv-aia string property, i.e. if no bool is set we'll default to riscv-aia-auto, if the host supports it.
--- target/riscv/kvm/kvm-cpu.c | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
target/riscv/kvm/kvm-cpu.c +77 -0
@@ -1671,6 +1671,62 @@ static void riscv_set_kvm_aia(Object *obj, const char *val, Error **errp) } } +static void riscv_set_kvm_aia_bool (uint32_t aia_bool,bool val) +{ +bool default_aia_mode =KVM_DEV_RISCV_AIA_MODE_AUTO ; + +g_assert (aia_bool <=KVM_DEV_RISCV_AIA_MODE_AUTO ); + +if (val) { + aia_mode = aia_bool; +return ; + } + +/* +* Setting an aia_bool to 'false' does nothing if +* aia_mode isn't set to aia_bool. +*/ +if (aia_mode != aia_bool) { +return ; + } + +/* +* Return to default value if we're disabling the +* current set aia_mode. +*/ + aia_mode = default_aia_mode; +} + +static bool riscv_get_kvm_aia_emul (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_EMUL ; +} + +static void riscv_set_kvm_aia_emul (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_EMUL , val); +} + +static bool riscv_get_kvm_aia_hwaccel (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_HWACCEL ; +} + +static void riscv_set_kvm_aia_hwaccel (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_HWACCEL , val); +} + +static bool riscv_get_kvm_aia_auto (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_AUTO ; +} + +static void riscv_set_kvm_aia_auto (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_AUTO , val); +} +void kvm_arch_accel_class_init (ObjectClass *oc) { object_class_property_add_str(oc, "riscv-aia", riscv_get_kvm_aia,
@@ -1681,6 +1737,27 @@ void kvm_arch_accel_class_init(ObjectClass *oc) "if the host supports it");object_property_set_default_str (object_class_property_find (oc,"riscv-aia" ),"auto" ); + +object_class_property_add_bool (oc,"riscv-aia-emul" , + riscv_get_kvm_aia_emul, + riscv_set_kvm_aia_emul); +object_class_property_set_description (oc,"riscv-aia-emul" , +"Set KVM AIA mode to 'emul'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); + +object_class_property_add_bool (oc,"riscv-aia-hwaccel" , + riscv_get_kvm_aia_hwaccel, + riscv_set_kvm_aia_hwaccel); +object_class_property_set_description (oc,"riscv-aia-hwaccel" , +"Set KVM AIA mode to 'hwaccel'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); + +object_class_property_add_bool (oc,"riscv-aia-auto" , + riscv_get_kvm_aia_auto, + riscv_set_kvm_aia_auto); +object_class_property_set_description (oc,"riscv-aia-auto" , +"Set KVM AIA mode to 'auto'. Changing KVM AIA modes " +"relies on host support" ); } void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
Signature · 1 line
2.45.2
Re: [PATCH 3/4] target/riscv/kvm: add kvm-aia bools props
Quoted 96 lines · Daniel Henrique Barboza
Boolean properties are preferrable in comparision to string properties since they don't require a string parsing.
Add three bools that represents the available kvm-aia mode:
riscv-aia-emul, riscv-aia-hwaccel, riscv-aia-auto. They work like the existing riscv-aia string property, i.e. if no bool is set we'll default to riscv-aia-auto, if the host supports it.Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/kvm/kvm-cpu.c | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)target/riscv/kvm/kvm-cpu.c +67
-0@@ -1671,6 +1671,62 @@ static void riscv_set_kvm_aia(Object *obj, const char *val, Error **errp) } } +static void riscv_set_kvm_aia_bool (uint32_t aia_bool,bool val) +{ +bool default_aia_mode =KVM_DEV_RISCV_AIA_MODE_AUTO ; + +g_assert (aia_bool <=KVM_DEV_RISCV_AIA_MODE_AUTO ); + +if (val) { + aia_mode = aia_bool; +return ; + } + +/* +* Setting an aia_bool to 'false' does nothing if +* aia_mode isn't set to aia_bool. +*/ +if (aia_mode != aia_bool) { +return ; + } + +/* +* Return to default value if we're disabling the +* current set aia_mode. +*/ + aia_mode = default_aia_mode; +} + +static bool riscv_get_kvm_aia_emul (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_EMUL ; +} + +static void riscv_set_kvm_aia_emul (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_EMUL , val); +} + +static bool riscv_get_kvm_aia_hwaccel (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_HWACCEL ; +} + +static void riscv_set_kvm_aia_hwaccel (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_HWACCEL , val); +} + +static bool riscv_get_kvm_aia_auto (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_AUTO ; +} + +static void riscv_set_kvm_aia_auto (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_AUTO , val); +} +void kvm_arch_accel_class_init (ObjectClass *oc) { object_class_property_add_str(oc, "riscv-aia", riscv_get_kvm_aia,@@ -1681,6 +1737,27 @@ void kvm_arch_accel_class_init(ObjectClass *oc) "if the host supports it");object_property_set_default_str (object_class_property_find (oc,"riscv-aia" ),"auto" ); + +object_class_property_add_bool (oc,"riscv-aia-emul" , + riscv_get_kvm_aia_emul, + riscv_set_kvm_aia_emul); +object_class_property_set_description (oc,"riscv-aia-emul" , +"Set KVM AIA mode to 'emul'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); + +object_class_property_add_bool (oc,"riscv-aia-hwaccel" , + riscv_get_kvm_aia_hwaccel, + riscv_set_kvm_aia_hwaccel);
target/riscv/kvm/kvm-cpu.c void kvm_arch_accel_class_init(ObjectClass *oc) · line 1760
Quoted 10 lines
target/riscv/kvm/kvm-cpu.c +10
-0+object_class_property_set_description (oc,"riscv-aia-hwaccel" , +"Set KVM AIA mode to 'hwaccel'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); + +object_class_property_add_bool (oc,"riscv-aia-auto" , + riscv_get_kvm_aia_auto, + riscv_set_kvm_aia_auto); +object_class_property_set_description (oc,"riscv-aia-auto" , +"Set KVM AIA mode to 'auto'. Changing KVM AIA modes " +"relies on host support" );
This seems more confusing. What should happen if a user sets multiple to true?
Alistair
Quoted 7 lines
target/riscv/kvm/kvm-cpu.c +0
-1} void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, --2.45.2
Re: [PATCH 3/4] target/riscv/kvm: add kvm-aia bools props
Quoted 102 lines · Alistair Francis
Quoted 100 lines · Daniel Henrique Barboza
Boolean properties are preferrable in comparision to string properties since they don't require a string parsing.
Add three bools that represents the available kvm-aia mode:
riscv-aia-emul, riscv-aia-hwaccel, riscv-aia-auto. They work like the existing riscv-aia string property, i.e. if no bool is set we'll default to riscv-aia-auto, if the host supports it.Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/kvm/kvm-cpu.c | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)target/riscv/kvm/kvm-cpu.c +71
-0@@ -1671,6 +1671,62 @@ static void riscv_set_kvm_aia(Object *obj, const char *val, Error **errp) } } +static void riscv_set_kvm_aia_bool (uint32_t aia_bool,bool val) +{ +bool default_aia_mode =KVM_DEV_RISCV_AIA_MODE_AUTO ; + +g_assert (aia_bool <=KVM_DEV_RISCV_AIA_MODE_AUTO ); + +if (val) { + aia_mode = aia_bool; +return ; + } + +/* +* Setting an aia_bool to 'false' does nothing if +* aia_mode isn't set to aia_bool. +*/ +if (aia_mode != aia_bool) { +return ; + } + +/* +* Return to default value if we're disabling the +* current set aia_mode. +*/ + aia_mode = default_aia_mode; +} + +static bool riscv_get_kvm_aia_emul (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_EMUL ; +} + +static void riscv_set_kvm_aia_emul (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_EMUL , val); +} + +static bool riscv_get_kvm_aia_hwaccel (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_HWACCEL ; +} + +static void riscv_set_kvm_aia_hwaccel (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_HWACCEL , val); +} + +static bool riscv_get_kvm_aia_auto (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_AUTO ; +} + +static void riscv_set_kvm_aia_auto (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_AUTO , val); +} +void kvm_arch_accel_class_init (ObjectClass *oc) { object_class_property_add_str(oc, "riscv-aia", riscv_get_kvm_aia,@@ -1681,6 +1737,27 @@ void kvm_arch_accel_class_init(ObjectClass *oc) "if the host supports it");object_property_set_default_str (object_class_property_find (oc,"riscv-aia" ),"auto" ); + +object_class_property_add_bool (oc,"riscv-aia-emul" , + riscv_get_kvm_aia_emul, + riscv_set_kvm_aia_emul); +object_class_property_set_description (oc,"riscv-aia-emul" , +"Set KVM AIA mode to 'emul'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); + +object_class_property_add_bool (oc,"riscv-aia-hwaccel" , + riscv_get_kvm_aia_hwaccel, + riscv_set_kvm_aia_hwaccel); +object_class_property_set_description (oc,"riscv-aia-hwaccel" , +"Set KVM AIA mode to 'hwaccel'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); +
Quoted 8 lines
target/riscv/kvm/kvm-cpu.c void kvm_arch_accel_class_init(ObjectClass *oc) · line 1760
Quoted 6 lines
target/riscv/kvm/kvm-cpu.c +6
-0+object_class_property_add_bool (oc,"riscv-aia-auto" , + riscv_get_kvm_aia_auto, + riscv_set_kvm_aia_auto); +object_class_property_set_description (oc,"riscv-aia-auto" , +"Set KVM AIA mode to 'auto'. Changing KVM AIA modes " +"relies on host support" );This seems more confusing. What should happen if a user sets multiple to true?
It'll work like most options in QEMU: the last setting will overwrite the previous ones. "-accel kvm,riscv-aia-hwaccel=true,riscv-aia-emul=true" will set the mode to 'emul'. This is the same behavior that we have with the existing 'riscv-aia' string option.
In case someone tries it out with multiple -accel options, this doesn't work. Only the first '-accel <type>' are parsed. This happens due to a known command line parsing/accel globals issue that I tried to fix in [1] and [2].
For now, using the existing 'riscv-aia' string option:
-accel kvm,riscv-aia=emul -accel kvm,riscv-aia=hwaccel -accel kvm,riscv-aia=auto
This will set riscv-aia to "emul" because all other "-accel kvm" options aren't being parsed. You can do silly stuff like:
-accel kvm,riscv-aia=emul -accel kvm,riscv-aia=this_is_not_an_option
And the guest will boot normally, setting riscv-aia to 'emul'.
Thanks,
Daniel
[1] "[PATCH 0/2] system/vl.c: parse all '-accel' opts"
https://lore.kernel.org/qemu-devel/[email protected]/ [2] "[PATCH v2 0/2] object,accel-system: allow Accel type globals" https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 10 lines
Alistair
Quoted 7 lines
target/riscv/kvm/kvm-cpu.c +0
-1} void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, --2.45.2
Re: [PATCH 3/4] target/riscv/kvm: add kvm-aia bools props
Quoted 115 lines · Daniel Henrique Barboza
Quoted 102 lines · Alistair Francis
Quoted 100 lines · Daniel Henrique Barboza
Boolean properties are preferrable in comparision to string properties since they don't require a string parsing.
Add three bools that represents the available kvm-aia mode:
riscv-aia-emul, riscv-aia-hwaccel, riscv-aia-auto. They work like the existing riscv-aia string property, i.e. if no bool is set we'll default to riscv-aia-auto, if the host supports it.Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/kvm/kvm-cpu.c | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)target/riscv/kvm/kvm-cpu.c +71
-0@@ -1671,6 +1671,62 @@ static void riscv_set_kvm_aia(Object *obj, const char *val, Error **errp) } } +static void riscv_set_kvm_aia_bool (uint32_t aia_bool,bool val) +{ +bool default_aia_mode =KVM_DEV_RISCV_AIA_MODE_AUTO ; + +g_assert (aia_bool <=KVM_DEV_RISCV_AIA_MODE_AUTO ); + +if (val) { + aia_mode = aia_bool; +return ; + } + +/* +* Setting an aia_bool to 'false' does nothing if +* aia_mode isn't set to aia_bool. +*/ +if (aia_mode != aia_bool) { +return ; + } + +/* +* Return to default value if we're disabling the +* current set aia_mode. +*/ + aia_mode = default_aia_mode; +} + +static bool riscv_get_kvm_aia_emul (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_EMUL ; +} + +static void riscv_set_kvm_aia_emul (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_EMUL , val); +} + +static bool riscv_get_kvm_aia_hwaccel (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_HWACCEL ; +} + +static void riscv_set_kvm_aia_hwaccel (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_HWACCEL , val); +} + +static bool riscv_get_kvm_aia_auto (Object *obj,Error **errp) +{ +return aia_mode ==KVM_DEV_RISCV_AIA_MODE_AUTO ; +} + +static void riscv_set_kvm_aia_auto (Object *obj,bool val,Error **errp) +{ +riscv_set_kvm_aia_bool (KVM_DEV_RISCV_AIA_MODE_AUTO , val); +} +void kvm_arch_accel_class_init (ObjectClass *oc) { object_class_property_add_str(oc, "riscv-aia", riscv_get_kvm_aia,@@ -1681,6 +1737,27 @@ void kvm_arch_accel_class_init(ObjectClass *oc) "if the host supports it");object_property_set_default_str (object_class_property_find (oc,"riscv-aia" ),"auto" ); + +object_class_property_add_bool (oc,"riscv-aia-emul" , + riscv_get_kvm_aia_emul, + riscv_set_kvm_aia_emul); +object_class_property_set_description (oc,"riscv-aia-emul" , +"Set KVM AIA mode to 'emul'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); + +object_class_property_add_bool (oc,"riscv-aia-hwaccel" , + riscv_get_kvm_aia_hwaccel, + riscv_set_kvm_aia_hwaccel); +object_class_property_set_description (oc,"riscv-aia-hwaccel" , +"Set KVM AIA mode to 'hwaccel'. Changing KVM AIA modes relies on host " +"support. Default mode is 'auto' if the host supports it" ); +Quoted 8 lines
target/riscv/kvm/kvm-cpu.c void kvm_arch_accel_class_init(ObjectClass *oc) · line 1760
Quoted 6 lines
target/riscv/kvm/kvm-cpu.c +6
-0+object_class_property_add_bool (oc,"riscv-aia-auto" , + riscv_get_kvm_aia_auto, + riscv_set_kvm_aia_auto); +object_class_property_set_description (oc,"riscv-aia-auto" , +"Set KVM AIA mode to 'auto'. Changing KVM AIA modes " +"relies on host support" );This seems more confusing. What should happen if a user sets multiple to true?
Quoted 4 lines
It'll work like most options in QEMU: the last setting will overwrite the previous ones. "-accel kvm,riscv-aia-hwaccel=true,riscv-aia-emul=true" will set the mode to 'emul'. This is the same behavior that we have with the existing 'riscv-aia' string option.
To me, reading "-accel kvm,riscv-aia-hwaccel=true,riscv-aia-emul=true" means that the riscv-aia-hwaccel and the riscv-aia-emul features are enabled.
Converting a single multi-option property to a range of bools just feels strange. It seems more confusing to users.
I agree that not requiring string parsing is nice, but this doesn't really seem worth it
Quoted 7 lines
In case someone tries it out with multiple -accel options, this doesn't work. Only the first '-accel <type>' are parsed. This happens due to a known command line parsing/accel globals issue that I tried to fix in [1] and [2].
For now, using the existing 'riscv-aia' string option:
Quoted 8 lines
-accel kvm,riscv-aia=emul -accel kvm,riscv-aia=hwaccel -accel kvm,riscv-aia=auto
This will set riscv-aia to "emul" because all other "-accel kvm" options aren't being parsed. You can do silly stuff like:
-accel kvm,riscv-aia=emul -accel kvm,riscv-aia=this_is_not_an_option
And the guest will boot normally, setting riscv-aia to 'emul'.
Both of those are unfortunate, but I do at least feel that reading them it's clear that something is wrong as the user has listed -accel kvm... multiple times.
Alistair
Re: [PATCH 3/4] target/riscv/kvm: add kvm-aia bools props
Quoted 1 line · Alistair Francis
On Fri, Oct 11, 2024 at 9:19 PM Daniel Henrique Barboza
...
Quoted 11 lines
Quoted 11 lines
In case someone tries it out with multiple -accel options, this doesn't work. Only the first '-accel <type>' are parsed. This happens due to a known command line parsing/accel globals issue that I tried to fix in [1] and [2].
For now, using the existing 'riscv-aia' string option:
-accel kvm,riscv-aia=emul -accel kvm,riscv-aia=hwaccel -accel kvm,riscv-aia=auto
This will set riscv-aia to "emul" because all other "-accel kvm" options aren't being parsed. You can do silly stuff like:
Quoted 8 lines
Quoted 3 lines
-accel kvm,riscv-aia=emul -accel kvm,riscv-aia=this_is_not_an_option
And the guest will boot normally, setting riscv-aia to 'emul'.
Both of those are unfortunate, but I do at least feel that reading them it's clear that something is wrong as the user has listed
-accel kvm...multiple times.
I wish that multiple '-accel kvm...' would work since scripts can be written to set reasonable defaults, e.g.
qemu-script.sh:
qemu-system-riscv64 -cpu max -accel kvm,riscv-aia=auto ... $@
but then anything the user tacks on through $@ would override those defaults. For example, 'qemu-script.sh -cpu max,some-ext=off' overrides the '-cpu max' in the script, disabling an extension. However, 'qemu-script.sh -accel kvm,riscv-aia=emul' will not force KVM to use use AIA=emul mode since the tacked on '-accel' is ignored.
Thanks,
drew
PATCH 4/4 target/riscv/kvm: deprecate riscv-aia string prop
In reply to Daniel Henrique BarbozaWe want to use the new boolean properties instead: riscv-aia-emul, riscv-aia-hwaccel and riscv-aia-auto.
Mark the string prop 'riscv-aia' for deprecation.
--- docs/about/deprecated.rst | 8 ++++++++ target/riscv/kvm/kvm-cpu.c | 1 + 2 files changed, 9 insertions(+)
docs/about/deprecated.rst +8 -0
@@ -463,6 +463,14 @@ available firmwares that are using the current (wrong) name. The property is kept as is in 9.1, together with "riscv,delegation", to give more time for firmware developers to change their code. +RISC-V "riscv-aia" KVM property (since 9.2) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +This property was deprecated in favor of using the boolean properties +'riscv-aia-emul', 'riscv-aia-hwaccel' and 'riscv-aia-auto'. The +motivation behind it is to make it easier to expose the internal +state of the KVM accelerator in APIs such as query-cpu-model-expansion. + Migration ---------
target/riscv/kvm/kvm-cpu.c +1 -0
@@ -1732,6 +1732,7 @@ void kvm_arch_accel_class_init(ObjectClass *oc)object_class_property_add_str (oc,"riscv-aia" , riscv_get_kvm_aia, riscv_set_kvm_aia);object_class_property_set_description (oc,"riscv-aia" , +"DEPRECATED: use riscv-aia-<mode> properties instead. " "Set KVM AIA mode. Valid values are 'emul', 'hwaccel' and 'auto'. " "Changing KVM AIA modes relies on host support. Defaults to 'auto' " "if the host supports it" );
Signature · 1 line
2.45.2
Hi,
I had a change of heart w.r.t this work. I still believe that the boolean properties are better to deal with since we don't have to deal with string parsing, and that we should avoid creating new string props in the future.
But as far as the user API goes it doesn't matter that much. Having to do
-accel kvm,riscv-aia=emul
or
-accel kvm,riscv-aia-emul=on
is basically the same thing. Deprecate properties always creates some form of hassle for existing scripts and whatnot and we should avoid it.
String properties aren't that great to report to APIs though, so what we can do is to create internal bools to track the string value and then use it for QMP.
Long story short, I'll re-send this series with only patches 1 and 2. Thanks,
Daniel
Quoted 24 lines · Daniel Henrique Barboza
Hi,
Boolean properties are easier to deal with in the protocol side (e.g. QMP) since they don't require string parsing. We should always use them when applicable.
This series adds 3 new riscv-aia bool options for the KVM accel driver, each one representing the possible values (emul, hwaccel and auto). We're also deprecating the existing 'riscv-aia' string option.
The idea is to use the new properties to enable AIA support in libvirt.
Patches based on riscv-to-apply.next.
Daniel Henrique Barboza (4):
target/riscv/kvm: set 'aia_mode' to default in error path target/riscv/kvm: clarify how 'riscv-aia' default works target/riscv/kvm: add kvm-aia bools props target/riscv/kvm: deprecate riscv-aia string propdocs/about/deprecated.rst | 8 +++ target/riscv/kvm/kvm-cpu.c | 100 +++++++++++++++++++++++++++++++++---- 2 files changed, 98 insertions(+), 10 deletions(-)
Quoted 15 lines · Daniel Henrique Barboza
Hi,
I had a change of heart w.r.t this work. I still believe that the boolean properties are better to deal with since we don't have to deal with string parsing, and that we should avoid creating new string props in the future.
But as far as the user API goes it doesn't matter that much. Having to do
-accel kvm,riscv-aia=emul
or
-accel kvm,riscv-aia-emul=on
Quoted 8 lines
is basically the same thing. Deprecate properties always creates some form of hassle for existing scripts and whatnot and we should avoid it.
String properties aren't that great to report to APIs though, so what we can do is to create internal bools to track the string value and then use it for QMP.
Long story short, I'll re-send this series with only patches 1 and 2. Thanks,
Ah, I should have read this before responding to your other patch.
Sounds good to me. Although I don't have the same dislike of string properties as you, but I guess I'm also not using APIs :)
Alistair
Quoted 32 lines
Daniel
Quoted 24 lines · Daniel Henrique Barboza
Hi,
Boolean properties are easier to deal with in the protocol side (e.g. QMP) since they don't require string parsing. We should always use them when applicable.
This series adds 3 new riscv-aia bool options for the KVM accel driver, each one representing the possible values (emul, hwaccel and auto). We're also deprecating the existing 'riscv-aia' string option.
The idea is to use the new properties to enable AIA support in libvirt.
Patches based on riscv-to-apply.next.
Daniel Henrique Barboza (4):
target/riscv/kvm: set 'aia_mode' to default in error path target/riscv/kvm: clarify how 'riscv-aia' default works target/riscv/kvm: add kvm-aia bools props target/riscv/kvm: deprecate riscv-aia string propdocs/about/deprecated.rst | 8 +++ target/riscv/kvm/kvm-cpu.c | 100 +++++++++++++++++++++++++++++++++---- 2 files changed, 98 insertions(+), 10 deletions(-)
Quoted 24 lines · Alistair Francis
Quoted 22 lines · Daniel Henrique Barboza
Hi,
I had a change of heart w.r.t this work. I still believe that the boolean properties are better to deal with since we don't have to deal with string parsing, and that we should avoid creating new string props in the future.
But as far as the user API goes it doesn't matter that much. Having to do
-accel kvm,riscv-aia=emul
or
-accel kvm,riscv-aia-emul=on
is basically the same thing. Deprecate properties always creates some form of hassle for existing scripts and whatnot and we should avoid it.
String properties aren't that great to report to APIs though, so what we can do is to create internal bools to track the string value and then use it for QMP.
Quoted 6 lines
Quoted 1 line
Long story short, I'll re-send this series with only patches 1 and 2. Thanks,
Ah, I should have read this before responding to your other patch.
Sounds good to me. Although I don't have the same dislike of string properties as you, but I guess I'm also not using APIs :)
libvirt and other upper layers which use qmp would need to learn about each property's possible values, possibly requiring QEMU to provide different APIs for each different property type. With only boolean properties, all an object's properties can be queried and modified in the same way, which also allows immediately knowing how to enable and disable new properties which QEMU adds without the need to update the upper layers at all.
Thanks,
drew