lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <65451ca3-3770-b679-6569-a2d3b90f4b44@intel.com>
Date:   Fri, 15 Oct 2021 15:29:20 -0700
From:   Reinette Chatre <reinette.chatre@...el.com>
To:     James Morse <james.morse@....com>, <x86@...nel.org>,
        <linux-kernel@...r.kernel.org>
CC:     Fenghua Yu <fenghua.yu@...el.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        H Peter Anvin <hpa@...or.com>,
        Babu Moger <Babu.Moger@....com>,
        <shameerali.kolothum.thodi@...wei.com>,
        Jamie Iles <jamie@...iainc.com>,
        "D Scott Phillips OS" <scott@...amperecomputing.com>,
        <lcherian@...vell.com>, <bobo.shaobowang@...wei.com>,
        <tan.shaopeng@...itsu.com>
Subject: Re: [PATCH v2 15/23] x86/recstrl: Add per-rmid arch private storage
 for overflow and chunks

Hi James,

On 10/1/2021 9:02 AM, James Morse wrote:
> resctrl_arch_rmid_read() is intended as the function that an
> architecture agnostic resctrl filesystem driver can use to
> read a value in bytes from a counter. Currently the function returns

resctrl_arch_rmid_read() does not exist at this point and is also not 
introduced in this patch.

> the mbm values in chunks directly from hardware. For bandwidth

Could you please replace mbm with MBM throughout the series?

> counters the resctrl filesystem uses this to calculate the number of
> bytes ever seen.
> 
> MPAM's scaling of counters can be changed at runtime, reducing the
> resolution but increasing the range. When this is changed the prev_msr
> values need to be converted by the architecture code.
> 
> Add an array for per-rmid private storage. The prev_msr and chunks
> values will move here to allow resctrl_arch_rmid_read() to always
> return the number of bytes read by this counter without assistance
> from the filesystem. The values are moved in later patches when
> the overflow and correction calls are moved into
> resctrl_arch_rmid_read().
> 
> Signed-off-by: James Morse <james.morse@....com>
> ---
>   arch/x86/kernel/cpu/resctrl/core.c     | 34 ++++++++++++++++++++++++++
>   arch/x86/kernel/cpu/resctrl/internal.h | 13 ++++++++++
>   2 files changed, 47 insertions(+)
> 
> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index 583fb41db06d..f527489a607a 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -413,6 +413,8 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
>   
>   void domain_free(struct rdt_hw_domain *hw_dom)
>   {
> +	kfree(hw_dom->arch_mbm_total);
> +	kfree(hw_dom->arch_mbm_local);
>   	kfree(hw_dom->ctrl_val);
>   	kfree(hw_dom);
>   }
> @@ -438,6 +440,33 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
>   	return 0;
>   }
>   
> +/**
> + * arch_domain_mbm_alloc() - Allocate arch private storage for the mbm counters

mbm -> MBM in comments also please .

> + * @num_rmid:	The size of the mbm counter array
> + * @hw_dom:	The domain that owns the allocated the arrays

the allocated the -> the allocated

> + *
> + * On error, call domain_free()

When following kerneldoc please use "Return:" to indicate the return 
section. It will help to run scripts/kernel-doc on these changes to make 
sure no new kernel-doc issues are introduced.

> + */
> +static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)
> +{
> +	size_t tsize;
> +
> +	if (is_mbm_total_enabled()) {
> +		tsize = sizeof(*hw_dom->arch_mbm_total);
> +		hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL);
> +		if (!hw_dom->arch_mbm_total)
> +			return -ENOMEM;
> +	}
> +	if (is_mbm_local_enabled()) {
> +		tsize = sizeof(*hw_dom->arch_mbm_local);
> +		hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL);
> +		if (!hw_dom->arch_mbm_local)
> +			return -ENOMEM;
> +	}
> +

Proper cleanup on error should be done in this function. Please do not 
use domain_free() as cleanup for what can be done in this function. I 
see domain_free() as the higher level error control ... like when a 
wrapper function calls arch_domain_mbm_alloc() and then something else 
fails after that ... then domain_free() would be that higher level error 
handling.

> +	return 0;
> +}
> +
>   /*
>    * domain_add_cpu - Add a cpu to a resource's domain list.
>    *
> @@ -487,6 +516,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
>   		return;
>   	}
>   
> +	if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) {
> +		domain_free(hw_dom);
> +		return;
> +	}
> +
>   	list_add_tail(&d->list, add_pos);
>   
>   	err = resctrl_online_domain(r, d);
> diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
> index 0a5721e1cc07..aaae900a8ef3 100644
> --- a/arch/x86/kernel/cpu/resctrl/internal.h
> +++ b/arch/x86/kernel/cpu/resctrl/internal.h
> @@ -303,17 +303,30 @@ struct mbm_state {
>   	bool	delta_comp;
>   };
>   
> +/**
> + * struct arch_mbm_state - values used to compute resctrl_arch_rmid_read()s
> + *			   return value.
> + * @prev_msr	Value of IA32_QM_CTR for this RMID last time we read it

Missing a ":"?
Please do not use "we".

This is a description of a struct ... can the doc elaborate on what 
"this RMID" means?

> + */
> +struct arch_mbm_state {
> +	u64	prev_msr;
> +};
> +
>   /**
>    * struct rdt_hw_domain - Arch private attributes of a set of CPUs that share
>    *			  a resource
>    * @d_resctrl:	Properties exposed to the resctrl file system
>    * @ctrl_val:	array of cache or mem ctrl values (indexed by CLOSID)
> + * @arch_mbm_total:	arch private state for MBM total bandwidth
> + * @arch_mbm_local:	arch private state for MBM local bandwidth
>    *
>    * Members of this structure are accessed via helpers that provide abstraction.
>    */
>   struct rdt_hw_domain {
>   	struct rdt_domain		d_resctrl;
>   	u32				*ctrl_val;
> +	struct arch_mbm_state		*arch_mbm_total;
> +	struct arch_mbm_state		*arch_mbm_local;
>   };
>   
>   static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r)
> 

Reinette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ