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:
 <TYCPR01MB88047C83A1CE49648667437B8B8DA@TYCPR01MB8804.jpnprd01.prod.outlook.com>
Date: Fri, 16 Jan 2026 10:34:27 +0000
From: "Shaopeng Tan (Fujitsu)" <tan.shaopeng@...itsu.com>
To: Ben Horgan <ben.horgan@....com>
CC: "amitsinght@...vell.com" <amitsinght@...vell.com>,
	"baisheng.gao@...soc.com" <baisheng.gao@...soc.com>,
	"baolin.wang@...ux.alibaba.com" <baolin.wang@...ux.alibaba.com>,
	"carl@...amperecomputing.com" <carl@...amperecomputing.com>,
	"dave.martin@....com" <dave.martin@....com>, "david@...nel.org"
	<david@...nel.org>, "dfustini@...libre.com" <dfustini@...libre.com>,
	"fenghuay@...dia.com" <fenghuay@...dia.com>, "gshan@...hat.com"
	<gshan@...hat.com>, "james.morse@....com" <james.morse@....com>,
	"jonathan.cameron@...wei.com" <jonathan.cameron@...wei.com>,
	"kobak@...dia.com" <kobak@...dia.com>, "lcherian@...vell.com"
	<lcherian@...vell.com>, "linux-arm-kernel@...ts.infradead.org"
	<linux-arm-kernel@...ts.infradead.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, "peternewman@...gle.com"
	<peternewman@...gle.com>, "punit.agrawal@....qualcomm.com"
	<punit.agrawal@....qualcomm.com>, "quic_jiles@...cinc.com"
	<quic_jiles@...cinc.com>, "reinette.chatre@...el.com"
	<reinette.chatre@...el.com>, "rohit.mathew@....com" <rohit.mathew@....com>,
	"scott@...amperecomputing.com" <scott@...amperecomputing.com>,
	"sdonthineni@...dia.com" <sdonthineni@...dia.com>, "xhao@...ux.alibaba.com"
	<xhao@...ux.alibaba.com>, "catalin.marinas@....com"
	<catalin.marinas@....com>, "will@...nel.org" <will@...nel.org>,
	"corbet@....net" <corbet@....net>, "maz@...nel.org" <maz@...nel.org>,
	"oupton@...nel.org" <oupton@...nel.org>, "joey.gouly@....com"
	<joey.gouly@....com>, "suzuki.poulose@....com" <suzuki.poulose@....com>,
	"kvmarm@...ts.linux.dev" <kvmarm@...ts.linux.dev>
Subject: Re: [PATCH v3 31/47] arm_mpam: resctrl: Pre-allocate assignable
 monitors

Hello Ben,

> From: James Morse <james.morse@....com>
> 
> When there are not enough monitors, MPAM is able to emulate ABMC by making
> a smaller number of monitors assignable. These monitors still need to be
> allocated from the driver, and mapped to whichever control/monitor group
> resctrl wants to use them with.
> 
> Add a second array to hold the monitor values indexed by resctrl's cntr_id.
> 
> When CDP is in use, two monitors are needed so the available number of
> counters halves. Platforms with one monitor will have zero monitors when
> CDP is in use.
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@...wei.com>
> Signed-off-by: James Morse <james.morse@....com>
> Signed-off-by: Ben Horgan <ben.horgan@....com>
> ---
> Changes since rfc:
> Move __free
> kmalloc -> kcalloc
> 
> Changes since v2:
> kcalloc -> kmalloc_array
> sizeof(*rmid_array)
> Return error from resctrl_arch_mbm_cntr_assign_set()
> ---
>  drivers/resctrl/mpam_internal.h |  7 +++
>  drivers/resctrl/mpam_resctrl.c  | 97 +++++++++++++++++++++++++++++++++
>  2 files changed, 104 insertions(+)
> 
> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
> index 89f9d374ded0..58076abd5de3 100644
> --- a/drivers/resctrl/mpam_internal.h
> +++ b/drivers/resctrl/mpam_internal.h
> @@ -367,6 +367,13 @@ struct mpam_resctrl_mon {
>           * un-assigned (closid, rmid) are -1.
>           */
>          int                     *mbwu_idx_to_mon;
> +
> +       /*
> +        * Array of assigned MBWU monitors, indexed by idx argument.
> +        * When ABMC is not in use, this array can be NULL. Otherwise
> +        * it maps idx to the allocated monitor.
> +        */
> +       int                     *assigned_counters;
>  };
>  
>  static inline int mpam_alloc_csu_mon(struct mpam_class *class)
> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
> index 3af12ad77fba..2a9efc6c6fae 100644
> --- a/drivers/resctrl/mpam_resctrl.c
> +++ b/drivers/resctrl/mpam_resctrl.c
> @@ -68,6 +68,12 @@ static bool cdp_enabled;
>  static bool cacheinfo_ready;
>  static DECLARE_WAIT_QUEUE_HEAD(wait_cacheinfo_ready);
>  
> +/*
> + * L3 local/total may come from different classes - what is the number of MBWU
> + * 'on L3'?
> + */
> +static unsigned int l3_num_allocated_mbwu = ~0;
> +
>  /* Whether this num_mbw_mon could result in a free_running system */
>  static int __mpam_monitors_free_running(u16 num_mbwu_mon)
>  {
> @@ -76,6 +82,15 @@ static int __mpam_monitors_free_running(u16 num_mbwu_mon)
>          return 0;
>  }
>  
> +/*
> + * If l3_num_allocated_mbwu is forced below PARTID * PMG, then the counters
> + * are not free running, and ABMC's user-interface must be used to assign them.
> + */
> +static bool mpam_resctrl_abmc_enabled(void)
> +{
> +       return l3_num_allocated_mbwu < resctrl_arch_system_num_rmid_idx();
> +}
> +
>  bool resctrl_arch_alloc_capable(void)
>  {
>          return exposed_alloc_capable;
> @@ -120,9 +135,26 @@ static void resctrl_reset_task_closids(void)
>          read_unlock(&tasklist_lock);
>  }
>  
> +static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *l3)
> +{
> +       l3->mon.num_mbm_cntrs = l3_num_allocated_mbwu;
> +       if (cdp_enabled)
> +               l3->mon.num_mbm_cntrs /= 2;
> +
> +       if (l3->mon.num_mbm_cntrs) {
> +               l3->mon.mbm_cntr_assignable = mpam_resctrl_abmc_enabled();
> +               l3->mon.mbm_assign_on_mkdir = mpam_resctrl_abmc_enabled();
> +       } else {
> +               l3->mon.mbm_cntr_assignable = false;
> +               l3->mon.mbm_assign_on_mkdir = false;
> +       }
> +}
> +
>  int resctrl_arch_set_cdp_enabled(enum resctrl_res_level ignored, bool enable)
>  {
>          u32 partid_i = RESCTRL_RESERVED_CLOSID, partid_d = RESCTRL_RESERVED_CLOSID;
> +       struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
> +       struct rdt_resource *l3 = &res->resctrl_res;
>  
>          cdp_enabled = enable;
>  
> @@ -138,6 +170,7 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level ignored, bool enable)
>          WRITE_ONCE(arm64_mpam_global_default, mpam_get_regval(current));
>  
>          resctrl_reset_task_closids();
> +       mpam_resctrl_monitor_sync_abmc_vals(l3);
>  
>          return 0;
>  }
> @@ -321,6 +354,11 @@ static bool class_has_usable_mbwu(struct mpam_class *class)
>                  return true;
>          }
>  
> +       if (cprops->num_mbwu_mon) {
> +               pr_debug("monitors usable via ABMC assignment\n");
> +               return true;
> +       }
> +
>          return false;
>  }
>  
> @@ -597,6 +635,8 @@ static int __alloc_mbwu_mon(struct mpam_class *class, int *array,
>                  array[i] = mbwu_mon;
>          }
>  
> +       l3_num_allocated_mbwu = min(l3_num_allocated_mbwu, num_mbwu_mon);
> +
>          return 0;
>  }
>  
> @@ -736,6 +776,19 @@ static void mpam_resctrl_pick_counters(void)
>                               mpam_resctrl_counters[QOS_L3_MBM_TOTAL_EVENT_ID].class);
>  }
>  
> +bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r)
> +{
> +       if (r != &mpam_resctrl_controls[RDT_RESOURCE_L3].resctrl_res)
> +               return false;
> +
> +       return mpam_resctrl_abmc_enabled();
> +}
> +
> +int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable)
> +{
> +       return -EINVAL;
> +}

$ echo "default" | sudo tee /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
default
tee: /sys/fs/resctrl/info/L3_MON/mbm_assign_mode:Invalid argument
"return  -EOPNOTSUPP;" might be better.

Best regards,
Shaopeng TAN


>  static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
>  {
>          struct mpam_class *class = res->class;
> @@ -811,6 +864,42 @@ static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp)
>          return comp->comp_id;
>  }
>  
> +/*
> + * This must run after all event counters have been picked so that any free
> + * running counters have already been allocated.
> + */
> +static int mpam_resctrl_monitor_init_abmc(struct mpam_resctrl_mon *mon)
> +{
> +       struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
> +       struct rdt_resource *l3 = &res->resctrl_res;
> +       struct mpam_class *class = mon->class;
> +       u16 num_mbwu_mon;
> +
> +       if (mon->mbwu_idx_to_mon) {
> +               pr_debug("monitors free running\n");
> +               return 0;
> +       }
> +
> +       int *rmid_array __free(kfree) =
> +               kmalloc_array(resctrl_arch_system_num_rmid_idx(), sizeof(*rmid_array), GFP_KERNEL);
> +
> +       if (!rmid_array) {
> +               pr_debug("Failed to allocate RMID array\n");
> +               return -ENOMEM;
> +       }
> +       memset(rmid_array, -1, resctrl_arch_system_num_rmid_idx() * sizeof(int));
> +
> +       num_mbwu_mon = class->props.num_mbwu_mon;
> +       mon->assigned_counters = __alloc_mbwu_array(mon->class, num_mbwu_mon);
> +       if (IS_ERR(mon->assigned_counters))
> +               return PTR_ERR(mon->assigned_counters);
> +       mon->mbwu_idx_to_mon = no_free_ptr(rmid_array);
> +
> +       mpam_resctrl_monitor_sync_abmc_vals(l3);
> +
> +       return 0;
> +}
> +
>  static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
>                                       enum resctrl_event_id type)
>  {
> @@ -857,6 +946,14 @@ static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
>                   * group can be allocated freely:
>                   */
>                  l3->mon.num_rmid = mpam_pmg_max + 1;
> +
> +               switch (type) {
> +               case QOS_L3_MBM_LOCAL_EVENT_ID:
> +               case QOS_L3_MBM_TOTAL_EVENT_ID:
> +                       return mpam_resctrl_monitor_init_abmc(mon);
> +               default:
> +                       return 0;
> +               }
>          }
>  
>          return 0;
> --
> 2.43.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ