Message ID | 1491054836-30488-12-git-send-email-yi.y.sun@linux.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
>>> On 01.04.17 at 15:53, <yi.y.sun@linux.intel.com> wrote: > --- a/xen/arch/x86/psr.c > +++ b/xen/arch/x86/psr.c > @@ -720,8 +720,83 @@ static int find_cos(const uint32_t val[], unsigned int array_len, > const struct psr_socket_info *info, > spinlock_t *ref_lock) > { > + unsigned int cos, i; > + const unsigned int *ref = info->cos_ref; > + const struct feat_node *feat; > + unsigned int cos_max; > + > ASSERT(spin_is_locked(ref_lock)); > > + /* cos_max is the one of the feature which is being set. */ > + feat = info->features[feat_type]; > + if ( !feat ) > + return -ENOENT; > + > + cos_max = feat->props->cos_max; > + > + for ( cos = 0; cos <= cos_max; cos++ ) > + { > + const uint32_t *val_ptr = val; > + bool found = false; > + > + if ( cos && !ref[cos] ) > + continue; > + > + /* > + * If fail to find cos in below loop, need find whole feature array > + * again from beginning. > + */ This comment is unrelated to any of the immediately surrounding code. Either move it, or get rid of it altogether. > + for ( i = 0; i < PSR_SOCKET_MAX_FEAT; i++ ) > + { > + uint32_t default_val = 0; Pointless initializer as it seems. > + feat = info->features[i]; > + if ( !feat ) > + continue; > + > + /* > + * COS ID 0 always stores the default value so input 0 to get > + * default value. > + */ > + feat->props->get_val(feat, 0, &default_val); > + > + /* > + * Compare value according to feature array order. > + * We must follow this order because value array is assembled > + * as this order. > + */ > + if ( cos > feat->props->cos_max ) > + { > + /* > + * If cos is bigger than feature's cos_max, the val should be > + * default value. Otherwise, it fails to find a COS ID. So we > + * have to exit find flow. > + */ > + if ( val[0] != default_val ) > + return -EINVAL; > + > + found = true; > + } > + else > + { > + if ( val[0] == feat->cos_reg_val[cos] ) > + found = true; > + } Same question as on previous patch- why val[0] twice above, despite cos_num possibly being larger than 1? And wouldn't this need to be val_ptr anyway? > + /* If fail to match, go to next cos to compare. */ > + if ( !found ) > + break; > + > + val_ptr += feat->props->cos_num; > + if ( val_ptr - val > array_len ) > + return -ENOSPC; This again looks suspicious - the check should once again be done before accessing the respective array element(s). Jan
diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index c912478..a6c6f18 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -720,8 +720,83 @@ static int find_cos(const uint32_t val[], unsigned int array_len, const struct psr_socket_info *info, spinlock_t *ref_lock) { + unsigned int cos, i; + const unsigned int *ref = info->cos_ref; + const struct feat_node *feat; + unsigned int cos_max; + ASSERT(spin_is_locked(ref_lock)); + /* cos_max is the one of the feature which is being set. */ + feat = info->features[feat_type]; + if ( !feat ) + return -ENOENT; + + cos_max = feat->props->cos_max; + + for ( cos = 0; cos <= cos_max; cos++ ) + { + const uint32_t *val_ptr = val; + bool found = false; + + if ( cos && !ref[cos] ) + continue; + + /* + * If fail to find cos in below loop, need find whole feature array + * again from beginning. + */ + for ( i = 0; i < PSR_SOCKET_MAX_FEAT; i++ ) + { + uint32_t default_val = 0; + + feat = info->features[i]; + if ( !feat ) + continue; + + /* + * COS ID 0 always stores the default value so input 0 to get + * default value. + */ + feat->props->get_val(feat, 0, &default_val); + + /* + * Compare value according to feature array order. + * We must follow this order because value array is assembled + * as this order. + */ + if ( cos > feat->props->cos_max ) + { + /* + * If cos is bigger than feature's cos_max, the val should be + * default value. Otherwise, it fails to find a COS ID. So we + * have to exit find flow. + */ + if ( val[0] != default_val ) + return -EINVAL; + + found = true; + } + else + { + if ( val[0] == feat->cos_reg_val[cos] ) + found = true; + } + + /* If fail to match, go to next cos to compare. */ + if ( !found ) + break; + + val_ptr += feat->props->cos_num; + if ( val_ptr - val > array_len ) + return -ENOSPC; + } + + /* For this COS ID all entries in the values array do match. Use it. */ + if ( found ) + return cos; + } + return -ENOENT; }
Continue from patch: 'x86: refactor psr: L3 CAT: set value: assemble features value array' We can try to find if there is a COS ID on which all features' COS registers values are same as the array assembled before. Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com> --- v10: - remove 'compare_val' hook and its CAT implementation. Make its functionality be generic in 'find_cos' flow. (suggested by Jan Beulich) - changes related to 'props'. (suggested by Jan Beulich) - rename 'val_array' to 'val_ptr'. (suggested by Jan Beulich) - rename 'find' to 'found'. (suggested by Jan Beulich) - move some variables declaration and initialization into loop. (suggested by Jan Beulich) - adjust codes positions. (suggested by Jan Beulich) v9: - modify comments of 'compare_val' to be same as current implementation. (suggested by Wei Liu) - fix indentation issue. (suggested by Wei Liu) - rename 'l3_cat_compare_val' to 'cat_compare_val' to cover all L3/L2 CAT features. (suggested by Roger Pau) - remove parameter 'found' from 'cat_compare_val' and modify the return values to let caller know if the id is found or not. (suggested by Roger Pau) - replace feature list handling to feature array handling. (suggested by Roger Pau) - replace 'get_cos_num' to 'feat->cos_num'. (suggested by Jan Beulich) - directly use 'cos_reg_val[0]' as default value. (suggested by Jan Beulich) - modify patch title to indicate 'L3 CAT'. (suggested by Jan Beulich) - changes about 'uint64_t' to 'uint32_t'. (suggested by Jan Beulich) v5: - modify commit message to provide exact patch name to continue from. (suggested by Jan Beulich) - remove 'get_cos_max_from_type' because it can be replaced by 'get_cos_max'. - move type check out from callback functions to caller. (suggested by Jan Beulich) - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'. (suggested by Jan Beulich) - modify comments according to changes of codes. (suggested by Jan Beulich) v4: - create this patch to make codes easier to understand. (suggested by Jan Beulich) --- xen/arch/x86/psr.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)