Re: [RFC PATCH 6/6] cpufreq: add kvm-cpufreq driver

From: David Dai
Date: Wed Apr 05 2023 - 18:42:54 EST


On Wed, Apr 5, 2023 at 1:23 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Thu, Mar 30, 2023 at 03:43:41PM -0700, David Dai wrote:
>
> > +struct remote_data {
> > + int ret;
> > + struct cpufreq_frequency_table *table;
> > +};
> > +
> > +static void remote_get_freqtbl_num_entries(void *data)
> > +{
> > + struct arm_smccc_res hvc_res;
> > + u32 freq = 1UL;
> > + int *idx = data;
> > +
> > + while (freq != CPUFREQ_TABLE_END) {
> > + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_GET_CPUFREQ_TBL_FUNC_ID,
> > + *idx, &hvc_res);
> > + if (hvc_res.a0) {
> > + *idx = -ENODEV;
> > + return;
> > + }
> > + freq = hvc_res.a1;
> > + (*idx)++;
> > + }
> > +}
> > +
> > +static int kvm_cpufreq_get_freqtbl_num_entries(int cpu)
> > +{
> > + int num_entries = 0;
> > +
> > + smp_call_function_single(cpu, remote_get_freqtbl_num_entries, &num_entries, true);
> > + return num_entries;
> > +}
> > +
> > +static void remote_populate_freqtbl(void *data)
> > +{
> > + struct arm_smccc_res hvc_res;
> > + struct remote_data *freq_data = data;
> > + struct cpufreq_frequency_table *pos;
> > + struct cpufreq_frequency_table *table = freq_data->table;
> > + int idx;
> > +
> > + cpufreq_for_each_entry_idx(pos, table, idx) {
> > + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_GET_CPUFREQ_TBL_FUNC_ID,
> > + idx, &hvc_res);
> > + if (hvc_res.a0) {
> > + freq_data->ret = -ENODEV;
> > + return;
> > + }
> > + pos->frequency = hvc_res.a1;
> > + }
> > + freq_data->ret = 0;
> > +}
> > +
> > +static int kvm_cpufreq_populate_freqtbl(struct cpufreq_frequency_table *table, int cpu)
> > +{
> > + struct remote_data freq_data;
> > +
> > + freq_data.table = table;
> > + smp_call_function_single(cpu, remote_populate_freqtbl, &freq_data, true);
> > + return freq_data.ret;
> > +}
>

Hi Peter,

Thanks for taking the time to review!

> *WHY* are you sending IPIs to do a hypercall ?!?
>
> You can simply have the hypercall tell what vCPU you're doing this for.
>

We’ll remove all the code that’s making IPI calls and switch over to
populating the frequency tables in the device tree when we move from
RFC to PATCH. It is here for now to make it easier for others to
cherry-pick and test the series without needing more changes to their
VMM.

Thanks,
David