On 27.02.2025 07:53, Penny, Zheng wrote: >> -----Original Message----- >> From: Jan Beulich <jbeul...@suse.com> >> Sent: Wednesday, February 12, 2025 12:46 AM >> >> On 06.02.2025 09:32, Penny Zheng wrote: >>> --- a/xen/arch/x86/acpi/cpufreq/amd-cppc.c >>> +++ b/xen/arch/x86/acpi/cpufreq/amd-cppc.c >>> +} >>> + >>> +static int cf_check amd_cppc_write_request(int cpu, uint8_t min_perf, >>> + uint8_t des_perf, uint8_t >>> +max_perf) { >>> + struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu); >>> + uint64_t prev = data->req.raw; >>> + >>> + data->req.min_perf = min_perf; >>> + data->req.max_perf = max_perf; >>> + data->req.des_perf = des_perf; >>> + >>> + if ( prev == data->req.raw ) >>> + return 0; >>> + >>> + on_selected_cpus(cpumask_of(cpu), amd_cppc_write_request_msrs, >>> + data, 1); >>> + >>> + return data->err; >>> +} >> >> ... in this function. Then the field would be written to (and the cacheline >> change >> ownership) only in the error case. >> >> As to the function's parameters - why's there a plain int? > > Are you asking why "int cpu" here?
Yes. I don't expect negative values are okay to be passed in? And variables (incl parameters) which can't hold negative values want to be of an unsigned type. >>> + err: >>> + data->err = -EINVAL; >>> +} >> >> At this point you may have set the enable bit already, which you can't undo. >> What effect will this have on the system when the error path is taken here? >> Especially if we then try to fall back to another driver? > > On current code logic, when the error path is taken, amd-cppc cpufreq driver > fails > to initialize. And we will also not fall back to another driver. > As we could register *only one* cpufreq driver. If amd-cppc is registered > properly > before, then legacy P-states will not get registered. > In amd-cppc registration code: > ``` > +int __init amd_cppc_register_driver(void) > +{ > + if ( !cpu_has_cppc ) > + return -ENODEV; > + > + return cpufreq_register_driver(&amd_cppc_cpufreq_driver); > +} > ``` > CPPC feature MSR gets checked before the registration, which is to check > whether the > hardware has CPPC msr support. Yet still there's the possibility of a later error. If it's not an option to gracefully handle such errors, I think you want to put in a code comment explaining the situation and effect. Jan