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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230421141723.2405942-10-peternewman@google.com>
Date:   Fri, 21 Apr 2023 16:17:23 +0200
From:   Peter Newman <peternewman@...gle.com>
To:     Fenghua Yu <fenghua.yu@...el.com>,
        Reinette Chatre <reinette.chatre@...el.com>
Cc:     Babu Moger <babu.moger@....com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
        "H. Peter Anvin" <hpa@...or.com>,
        Stephane Eranian <eranian@...gle.com>,
        James Morse <james.morse@....com>,
        linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
        Peter Newman <peternewman@...gle.com>
Subject: [PATCH v1 9/9] x86/resctrl: Add mount option to enable soft RMID

Add the 'mbm_soft_rmid' mount option to enable soft RMIDs.

This requires adding a mechanism for disabling a monitoring event at
mount time to prevent the llc_occupancy event from being presented to
the user.

Signed-off-by: Peter Newman <peternewman@...gle.com>
---
 arch/x86/kernel/cpu/resctrl/internal.h |  3 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 51 ++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index e6ff31a4dbc4..604e3d550601 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -59,6 +59,7 @@ struct rdt_fs_context {
 	bool				enable_cdpl2;
 	bool				enable_cdpl3;
 	bool				enable_mba_mbps;
+	bool				enable_mbm_soft_rmid;
 };
 
 static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
@@ -76,12 +77,14 @@ DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
  * @evtid:		event id
  * @name:		name of the event
  * @configurable:	true if the event is configurable
+ * @enabled:		true if event is disabled
  * @list:		entry in &rdt_resource->evt_list
  */
 struct mon_evt {
 	enum resctrl_event_id	evtid;
 	char			*name;
 	bool			configurable;
+	bool			disabled;
 	struct list_head	list;
 };
 
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index c10f4798156a..c2abf69c2dcf 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -1013,6 +1013,8 @@ static int rdt_mon_features_show(struct kernfs_open_file *of,
 	struct mon_evt *mevt;
 
 	list_for_each_entry(mevt, &r->evt_list, list) {
+		if (mevt->disabled)
+			continue;
 		seq_printf(seq, "%s\n", mevt->name);
 		if (mevt->configurable)
 			seq_printf(seq, "%s_config\n", mevt->name);
@@ -2204,6 +2206,37 @@ static bool supports_mba_mbps(void)
 		r->alloc_capable && is_mba_linear());
 }
 
+static bool supports_mbm_soft_rmid(void)
+{
+	return is_mbm_enabled();
+}
+
+int set_mbm_soft_rmid(bool mbm_soft_rmid)
+{
+	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	struct mon_evt *mevt = NULL;
+
+	/*
+	 * is_llc_occupancy_enabled() will always return false when disabling,
+	 * so search for the llc_occupancy event unconditionally.
+	 */
+	list_for_each_entry(mevt, &r->evt_list, list) {
+		if (strcmp(mevt->name, "llc_occupancy") == 0) {
+			mevt->disabled = mbm_soft_rmid;
+			break;
+		}
+	}
+
+	rdt_mon_soft_rmid = mbm_soft_rmid;
+
+	if (mbm_soft_rmid)
+		static_branch_enable_cpuslocked(&rdt_soft_rmid_enable_key);
+	else
+		static_branch_disable_cpuslocked(&rdt_soft_rmid_enable_key);
+
+	return 0;
+}
+
 /*
  * Enable or disable the MBA software controller
  * which helps user specify bandwidth in MBps.
@@ -2359,6 +2392,9 @@ static int rdt_enable_ctx(struct rdt_fs_context *ctx)
 	if (!ret && ctx->enable_mba_mbps)
 		ret = set_mba_sc(true);
 
+	if (!ret && ctx->enable_mbm_soft_rmid)
+		ret = set_mbm_soft_rmid(true);
+
 	return ret;
 }
 
@@ -2534,6 +2570,8 @@ static int rdt_get_tree(struct fs_context *fc)
 out_mba:
 	if (ctx->enable_mba_mbps)
 		set_mba_sc(false);
+	if (ctx->enable_mbm_soft_rmid)
+		set_mbm_soft_rmid(false);
 out_cdp:
 	cdp_disable_all();
 out:
@@ -2547,6 +2585,7 @@ enum rdt_param {
 	Opt_cdp,
 	Opt_cdpl2,
 	Opt_mba_mbps,
+	Opt_mbm_soft_rmid,
 	nr__rdt_params
 };
 
@@ -2554,6 +2593,7 @@ static const struct fs_parameter_spec rdt_fs_parameters[] = {
 	fsparam_flag("cdp",		Opt_cdp),
 	fsparam_flag("cdpl2",		Opt_cdpl2),
 	fsparam_flag("mba_MBps",	Opt_mba_mbps),
+	fsparam_flag("mbm_soft_rmid",	Opt_mbm_soft_rmid),
 	{}
 };
 
@@ -2579,6 +2619,11 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			return -EINVAL;
 		ctx->enable_mba_mbps = true;
 		return 0;
+	case Opt_mbm_soft_rmid:
+		if (!supports_mbm_soft_rmid())
+			return -EINVAL;
+		ctx->enable_mbm_soft_rmid = true;
+		return 0;
 	}
 
 	return -EINVAL;
@@ -2767,6 +2812,7 @@ static void rdt_kill_sb(struct super_block *sb)
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
+	set_mbm_soft_rmid(false);
 	set_mba_sc(false);
 
 	/*Put everything back to default values. */
@@ -2861,6 +2907,8 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
 	priv.u.rid = r->rid;
 	priv.u.domid = d->id;
 	list_for_each_entry(mevt, &r->evt_list, list) {
+		if (mevt->disabled)
+			continue;
 		priv.u.evtid = mevt->evtid;
 		ret = mon_addfile(kn, mevt->name, priv.priv);
 		if (ret)
@@ -3517,6 +3565,9 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
 	if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))
 		seq_puts(seq, ",mba_MBps");
 
+	if (static_branch_likely(&rdt_soft_rmid_enable_key))
+		seq_puts(seq, ",mbm_soft_rmid");
+
 	return 0;
 }
 
-- 
2.40.0.634.g4ca3ef3211-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ