From 6ada84ab5241819d9e866d3c4223f5f31b503876 Mon Sep 17 00:00:00 2001
From: Xie XiuQi <xiexiuqi@huawei.com>
Date: Sun, 28 Apr 2019 22:18:17 +0800
Subject: [PATCH 2862/2944] openEuler: arm64/mpam: remove unnecessary debug
 message and dead code

commit 7f8eab4775417d705a8076fa243457a1427ae5b4 openEuler-1.0

hulk inclusion
category: bugfix
bugzilla: 14212
CVE: NA

Clean up unnecessary debug message, warnings and unused
functions.

Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Xin Hao <haoxing990@gmail.com>
Reviewed-by: Baolin Wang <baolin.wang@openanolis.org>
---
 arch/arm64/include/asm/mpam.h     |   2 -
 arch/arm64/kernel/Makefile        |   2 +-
 arch/arm64/kernel/mpam.c          | 101 +++-----------------------------------
 arch/arm64/kernel/mpam_ctrlmon.c  |  26 ----------
 arch/arm64/kernel/mpam_mon.c      |   2 -
 arch/arm64/kernel/mpam_resource.c |  14 ------
 6 files changed, 7 insertions(+), 140 deletions(-)
 delete mode 100644 arch/arm64/kernel/mpam_resource.c

diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h
index 9f6b94e..102bdc6b 100644
--- a/arch/arm64/include/asm/mpam.h
+++ b/arch/arm64/include/asm/mpam.h
@@ -227,8 +227,6 @@ enum {
 int resctrl_group_mondata_show(struct seq_file *m, void *arg);
 void rmdir_mondata_subdir_allrdtgrp(struct resctrl_resource *r,
 				    unsigned int dom_id);
-void mkdir_mondata_subdir_allrdtgrp(struct resctrl_resource *r,
-				    struct rdt_domain *d);
 
 void closid_init(void);
 int closid_alloc(void);
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 96a9cfe..c6b1ed9 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -58,7 +58,7 @@ arm64-obj-$(CONFIG_CRASH_CORE)		+= crash_core.o
 arm64-obj-$(CONFIG_ARM_SDE_INTERFACE)	+= sdei.o
 arm64-obj-$(CONFIG_ARM64_SSBD)		+= ssbd.o
 arm64-obj-$(CONFIG_SDEI_WATCHDOG) 	+= watchdog_sdei.o
-arm64-obj-$(CONFIG_MPAM)		+= mpam.o mpam_ctrlmon.o mpam_mon.o mpam_resource.o
+arm64-obj-$(CONFIG_MPAM)		+= mpam.o mpam_ctrlmon.o mpam_mon.o
 
 obj-y					+= $(arm64-obj-y) vdso/ probes/
 obj-m					+= $(arm64-obj-m)
diff --git a/arch/arm64/kernel/mpam.c b/arch/arm64/kernel/mpam.c
index 96284aa..b886282 100644
--- a/arch/arm64/kernel/mpam.c
+++ b/arch/arm64/kernel/mpam.c
@@ -135,26 +135,6 @@ int mpam_nodes_init(void)
 	return ret;
 }
 
-void mpam_nodes_show(void)
-{
-	int i, cpu;
-	size_t num_nodes = ARRAY_SIZE(mpam_node_all);
-	struct mpam_node *n;
-
-	char *types[] = {"MPAM_RESOURCE_SMMU", "MPAM_RESOURCE_CACHE", "MPAM_RESOURCE_MC"};
-
-	for (i = 0; i < num_nodes; i++) {
-		n = &mpam_node_all[i];
-		pr_cont("%s: type: %s; addr = %016llx; base = %016llx; cpus_list = %s; cpus: ",
-			__func__, types[n->type], n->addr, (u64)n->base, n->cpus_list);
-
-		for_each_cpu(cpu, &n->cpu_mask) {
-			pr_cont("%d, ", cpu);
-		}
-		pr_cont("\n");
-	}
-}
-
 static void
 cat_wrmsr(struct rdt_domain *d, int partid);
 static void
@@ -364,7 +344,6 @@ static int mpam_online_cpu(unsigned int cpu)
 /* [FIXME] remove related resource when cpu offline */
 static int mpam_offline_cpu(unsigned int cpu)
 {
-	pr_info("offline cpu\n");
 	return 0;
 }
 
@@ -404,7 +383,6 @@ void post_resctrl_mount(void)
 
 static int reset_all_ctrls(struct resctrl_resource *r)
 {
-	pr_info("%s\n", __func__);
 	return 0;
 }
 
@@ -425,11 +403,7 @@ void release_rdtgroupfs_options(void)
 
 int parse_rdtgroupfs_options(char *data)
 {
-	int ret = 0;
-
-	pr_err("Invalid mount option\n");
-
-	return ret;
+	return 0;
 }
 
 /*
@@ -706,7 +680,8 @@ static int resctrl_num_mon_show(struct kernfs_open_file *of,
 int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
 		   cpumask_var_t tmpmask)
 {
-	return 0;
+	pr_info("unsupported on mon_groups, please use ctrlmon groups\n");
+	return -EINVAL;
 }
 
 static ssize_t resctrl_group_cpus_write(struct kernfs_open_file *of,
@@ -925,8 +900,6 @@ int resctrl_ctrlmon_enable(struct kernfs_node *parent_kn,
 {
 	int ret;
 
-	pr_info("%s: out of monitors: ret %d, MON_GROUP %d\n",
-		__func__, prgrp->type, RDTMON_GROUP);
 	/* only for RDTCTRL_GROUP */
 	if (prgrp->type == RDTMON_GROUP)
 		return 0;
@@ -940,20 +913,12 @@ int resctrl_ctrlmon_enable(struct kernfs_node *parent_kn,
 	prgrp->mon.mon = ret;
 	prgrp->mon.rmid = 0;
 
-	pr_info("%s: prev dest_kn %016llx, closid %d, flags %d, type %d, rmid %d, mon %d\n",
-		__func__, (u64)*dest_kn, prgrp->closid, prgrp->flags, prgrp->type,
-		prgrp->mon.rmid, prgrp->mon.mon);
-
 	ret = mkdir_mondata_all(parent_kn, prgrp, dest_kn);
 	if (ret) {
 		rdt_last_cmd_puts("kernfs subdir error\n");
 		free_mon(ret);
 	}
 
-	pr_info("%s: post dest_kn %016llx, closid %d, flags %d, type %d, rmid %d, mon %d\n",
-		__func__, (u64)*dest_kn, prgrp->closid, prgrp->flags, prgrp->type,
-		prgrp->mon.rmid, prgrp->mon.mon);
-
 	return ret;
 }
 
@@ -981,17 +946,8 @@ void resctrl_ctrlmon_disable(struct kernfs_node *kn_mondata,
 	}
 
 	free_mon(mon);
-
-	pr_info("%s: prev kn_mondta %016llx, closid %d, flags %d, type %d, rmid %d, mon %d\n",
-		__func__, (u64)kn_mondata, prgrp->closid, prgrp->flags, prgrp->type,
-		prgrp->mon.rmid, prgrp->mon.mon);
-
 	kernfs_remove(kn_mondata);
 
-	pr_info("%s: post kn_mondta %016llx, closid %d, flags %d, type %d, rmid %d, mon %d\n",
-		__func__, (u64)kn_mondata, prgrp->closid, prgrp->flags, prgrp->type,
-		prgrp->mon.rmid, prgrp->mon.mon);
-
 	return;
 }
 
@@ -1012,10 +968,6 @@ static ssize_t resctrl_group_ctrlmon_write(struct kernfs_open_file *of,
 		goto unlock;
 	}
 
-	pr_info("%s: prev of->kn %016llx, closid %d, flags %d, type %d, rmid %d, mon %d\n",
-		__func__, (u64)of->kn, rdtgrp->closid, rdtgrp->flags, rdtgrp->type,
-		rdtgrp->mon.rmid, rdtgrp->mon.mon);
-
 	if ((rdtgrp->flags & RDT_CTRLMON) && !ctrlmon) {
 		/* [FIXME] disable & remove mon_data dir */
 		rdtgrp->flags &= ~RDT_CTRLMON;
@@ -1029,10 +981,6 @@ static ssize_t resctrl_group_ctrlmon_write(struct kernfs_open_file *of,
 		ret = -ENOENT;
 	}
 
-	pr_info("%s: post of->kn %016llx, closid %d, flags %d, type %d, rmid %d, mon %d\n",
-		__func__, (u64)of->kn, rdtgrp->closid, rdtgrp->flags, rdtgrp->type,
-		rdtgrp->mon.rmid, rdtgrp->mon.mon);
-
 unlock:
 	resctrl_group_kn_unlock(of->kn);
 	return ret ?: nbytes;
@@ -1169,33 +1117,23 @@ static void mpam_domains_destroy(struct resctrl_resource *r)
 
 static void mpam_domains_init(struct resctrl_resource *r)
 {
-	int i, cpu, id = 0;
+	int i, id = 0;
 	size_t num_nodes = ARRAY_SIZE(mpam_node_all);
 	struct mpam_node *n;
-	struct list_head *add_pos = NULL, *l;
+	struct list_head *add_pos = NULL;
 	struct rdt_domain *d;
 	struct raw_resctrl_resource *rr = (struct raw_resctrl_resource *)r->res;
 	u32 val;
 
-	char *types[] = {"MPAM_RESOURCE_SMMU", "MPAM_RESOURCE_CACHE", "MPAM_RESOURCE_MC"};
-
 	for (i = 0; i < num_nodes; i++) {
 		n = &mpam_node_all[i];
 		if (r->rid != n->type)
 			continue;
 
-		pr_cont("%s: type: %s; addr = %016llx; base = %016llx; cpus_list = %s; cpus: ",
-			__func__, types[n->type], n->addr, (u64)n->base, n->cpus_list);
-
-		for_each_cpu(cpu, &n->cpu_mask) {
-			pr_cont("%d, ", cpu);
-		}
-		pr_cont("\n");
-
 		d = mpam_find_domain(r, id, &add_pos);
 		if (IS_ERR(d)) {
 			mpam_domains_destroy(r);
-			pr_warn("Could't find cache id for cpu %d\n", cpu);
+			pr_warn("Could't find cache id %d\n", id);
 			return;
 		}
 
@@ -1235,14 +1173,6 @@ static void mpam_domains_init(struct resctrl_resource *r)
 			rr->num_mon = MPAMF_IDR_NUM_MON(val);
 		}
 
-		pr_info("%s: type: %s; alloc = %d %d; mon = %d %d\n",
-			__func__, types[n->type],
-			r->alloc_capable,
-			r->alloc_enabled,
-			r->mon_capable,
-			r->mon_enabled
-			);
-
 		r->alloc_capable = 1;
 		r->alloc_enabled = 1;
 		r->mon_capable = 1;
@@ -1263,25 +1193,9 @@ static void mpam_domains_init(struct resctrl_resource *r)
 
 		id++;
 	}
-
-	/*
-	 * for debug
-	 */
-	list_for_each(l, &r->domains) {
-		d = list_entry(l, struct rdt_domain, list);
-
-		pr_cont("domain: %d; type: %s; base = %016llx; cpus_list = %s; cpus: ",
-			d->id, types[r->rid], (u64)d->base, d->cpus_list);
-
-		for_each_cpu(cpu, &d->cpu_mask) {
-			pr_cont("%d, ", cpu);
-		}
-		pr_cont("\n");
-	}
 }
 
 int __read_mostly mpam_enabled;
-
 static int __init mpam_setup(char *str)
 {
 	mpam_enabled = 1;
@@ -1311,9 +1225,6 @@ static int __init mpam_late_init(void)
 		return ret;
 	}
 
-	/* for debug */
-	mpam_nodes_show();
-
 	mpam_domains_init(&resctrl_resources_all[MPAM_RESOURCE_CACHE]);
 	mpam_domains_init(&resctrl_resources_all[MPAM_RESOURCE_MC]);
 
diff --git a/arch/arm64/kernel/mpam_ctrlmon.c b/arch/arm64/kernel/mpam_ctrlmon.c
index 839bd4d..ae6afc9 100644
--- a/arch/arm64/kernel/mpam_ctrlmon.c
+++ b/arch/arm64/kernel/mpam_ctrlmon.c
@@ -433,32 +433,6 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
 	return ret;
 }
 
-/*
- * Add all subdirectories of mon_data for "ctrl_mon" groups
- * and "monitor" groups with given domain id.
- */
-void mkdir_mondata_subdir_allrdtgrp(struct resctrl_resource *r,
-				    struct rdt_domain *d)
-{
-	struct kernfs_node *parent_kn;
-	struct resctrl_group *prgrp, *crgrp;
-	struct list_head *head;
-
-	if (!r->mon_enabled)
-		return;
-
-	list_for_each_entry(prgrp, &resctrl_all_groups, resctrl_group_list) {
-		parent_kn = prgrp->mon.mon_data_kn;
-		mkdir_mondata_subdir(parent_kn, d, r, prgrp);
-
-		head = &prgrp->mon.crdtgrp_list;
-		list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
-			parent_kn = crgrp->mon.mon_data_kn;
-			mkdir_mondata_subdir(parent_kn, d, r, crgrp);
-		}
-	}
-}
-
 static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,
 				       struct resctrl_resource *r,
 				       struct resctrl_group *prgrp)
diff --git a/arch/arm64/kernel/mpam_mon.c b/arch/arm64/kernel/mpam_mon.c
index 9bc0816..407da95 100644
--- a/arch/arm64/kernel/mpam_mon.c
+++ b/arch/arm64/kernel/mpam_mon.c
@@ -67,8 +67,6 @@ int alloc_pmg(void)
 
 void free_pmg(u32 pmg)
 {
-	WARN_ON(!pmg);
-
 	pmg_free_map |= 1 << pmg;
 }
 
diff --git a/arch/arm64/kernel/mpam_resource.c b/arch/arm64/kernel/mpam_resource.c
deleted file mode 100644
index 9cdda91..0000000
--- a/arch/arm64/kernel/mpam_resource.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <linux/io.h>
-#include <linux/module.h>
-#include <linux/interrupt.h>
-#include <linux/platform_device.h>
-#include <linux/delay.h>
-#include <linux/of.h>
-#include <linux/of_irq.h>
-#include <linux/of_address.h>
-#include <linux/kthread.h>
-#include <linux/resctrlfs.h>
-
-#include <asm/mpam_resource.h>
-#include <asm/mpam.h>
-
-- 
1.8.3.1

