[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v3 10/14 RESEND] xen: Add SET_CPUFREQ_HWP xen_sysctl_pm_op
On 22.05.2023 14:45, Jason Andryuk wrote: > On Mon, May 8, 2023 at 7:27 AM Jan Beulich <jbeulich@xxxxxxxx> wrote: >> >> On 01.05.2023 21:30, Jason Andryuk wrote: >>> @@ -531,6 +533,100 @@ int get_hwp_para(const struct cpufreq_policy *policy, >>> return 0; >>> } >>> >>> +int set_hwp_para(struct cpufreq_policy *policy, >>> + struct xen_set_hwp_para *set_hwp) >> >> const? > > set_hwp can be const. policy is passed to hwp_cpufreq_target() & > on_selected_cpus(), so it cannot readily be made const. I was only meaning the 2nd parameter, yes. >>> +{ >>> + unsigned int cpu = policy->cpu; >>> + struct hwp_drv_data *data = per_cpu(hwp_drv_data, cpu); >>> + >>> + if ( data == NULL ) >>> + return -EINVAL; >>> + >>> + /* Validate all parameters first */ >>> + if ( set_hwp->set_params & ~XEN_SYSCTL_HWP_SET_PARAM_MASK ) >>> + return -EINVAL; >>> + >>> + if ( set_hwp->activity_window & ~XEN_SYSCTL_HWP_ACT_WINDOW_MASK ) >>> + return -EINVAL; >> >> Below you limit checks to when the respective control bit is set. I >> think you want the same here. > > Not sure if you mean feature_hwp_activity_window or the bit in > set_params as control bit. But, yes, they can both use some > additional checking. IIRC, I wanted to always check > ~XEN_SYSCTL_HWP_ACT_WINDOW_MASK, because bits should never be set > whether or not the activity window is supported by hardware. I took ... >>> + if ( !feature_hwp_energy_perf && >>> + (set_hwp->set_params & XEN_SYSCTL_HWP_SET_ENERGY_PERF) && >>> + set_hwp->energy_perf > IA32_ENERGY_BIAS_MAX_POWERSAVE ) >>> + return -EINVAL; >>> + >>> + if ( (set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED) && >>> + set_hwp->desired != 0 && >>> + (set_hwp->desired < data->hw.lowest || >>> + set_hwp->desired > data->hw.highest) ) >>> + return -EINVAL; ... e.g. this for comparison, where you apply the range check only when the XEN_SYSCTL_HWP_* bit is set. I think you want to be consistent in such checking: Either you always allow the caller to not care about fields that aren't going to be consumed when their controlling bit is off, or you always check validity. Both approaches have their pros and cons, I think. Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |