diff mbox series

[22/26] cgroup/misc: Add private per cgroup data to struct misc_cg

Message ID 20221111183532.3676646-23-kristen@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series Add Cgroup support for SGX EPC memory | expand

Commit Message

Kristen Carlson Accardi Nov. 11, 2022, 6:35 p.m. UTC
The SGX driver needs to be able to store additional per cgroup data
specific to SGX along with the misc_cg struct. Add the ability to get
and set this data in struct misc_cg.

Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>
---
 include/linux/misc_cgroup.h | 12 ++++++++++++
 kernel/cgroup/misc.c        | 39 +++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

Comments

Tejun Heo Nov. 14, 2022, 10:34 p.m. UTC | #1
On Fri, Nov 11, 2022 at 10:35:27AM -0800, Kristen Carlson Accardi wrote:
> +void *misc_cg_get_priv(enum misc_res_type type, struct misc_cg *cg)
> +{
> +	if (!(valid_type(type) && cg))
> +		return NULL;
> +
> +	return cg->res[type].priv;
> +}
> +EXPORT_SYMBOL_GPL(misc_cg_get_priv);

Yeah, just deref it. I'm not sure what all these accessors are contributing.

Thanks.
diff mbox series

Patch

diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index c00deae4d2df..7fbf3efb0f62 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -43,6 +43,7 @@  struct misc_res {
 	unsigned long max;
 	atomic_long_t usage;
 	atomic_long_t events;
+	void *priv;
 };
 
 /**
@@ -63,6 +64,8 @@  struct misc_cg *root_misc(void);
 struct misc_cg *parent_misc(struct misc_cg *cg);
 unsigned long misc_cg_read(enum misc_res_type type, struct misc_cg *cg);
 unsigned long misc_cg_max(enum misc_res_type type, struct misc_cg *cg);
+void *misc_cg_get_priv(enum misc_res_type type, struct misc_cg *cg);
+void misc_cg_set_priv(enum misc_res_type type, struct misc_cg *cg, void *priv);
 unsigned long misc_cg_res_total_usage(enum misc_res_type type);
 int misc_cg_set_capacity(enum misc_res_type type, unsigned long capacity);
 int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
@@ -130,6 +133,15 @@  static inline unsigned long misc_cg_max(enum misc_res_type type, struct misc_cg
 	return 0;
 }
 
+static void *misc_cg_get_priv(enum misc_res_type type, struct misc_cg *cg)
+{
+	return NULL;
+}
+
+static void misc_cg_set_priv(enum misc_res_type type, struct misc_cg *cg, void *priv)
+{
+}
+
 static inline unsigned long misc_cg_res_total_usage(enum misc_res_type type)
 {
 	return 0;
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index 18d0bec7d609..642879ad136f 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -251,6 +251,45 @@  unsigned long misc_cg_max(enum misc_res_type type, struct misc_cg *cg)
 }
 EXPORT_SYMBOL_GPL(misc_cg_max);
 
+/**
+ * misc_cg_get_priv() - Return the priv value of the misc cgroup res.
+ * @type: Type of the misc res.
+ * @cg: Misc cgroup whose priv will be read
+ *
+ * Context: Any context.
+ * Return:
+ * 	The value of the priv field for the specified misc cgroup.
+ * 	If an invalid misc_res_type is given, NULL will be returned.
+ */
+void *misc_cg_get_priv(enum misc_res_type type, struct misc_cg *cg)
+{
+	if (!(valid_type(type) && cg))
+		return NULL;
+
+	return cg->res[type].priv;
+}
+EXPORT_SYMBOL_GPL(misc_cg_get_priv);
+
+/**
+ * misc_cg_set_priv() - Set the priv value of the misc cgroup res.
+ * @type: Type of the misc res.
+ * @cg: Misc cgroup whose priv will be written
+ * @priv: Value to store in the priv field of the struct misc_cg
+ *
+ * If an invalid misc_res_type is given, the priv data will not be
+ * stored.
+ *
+ * Context: Any context.
+ */
+void misc_cg_set_priv(enum misc_res_type type, struct misc_cg *cg, void *priv)
+{
+	if (!(valid_type(type) && cg))
+		return;
+
+	cg->res[type].priv = priv;
+}
+EXPORT_SYMBOL_GPL(misc_cg_set_priv);
+
 /**
  * misc_cg_max_show() - Show the misc cgroup max limit.
  * @sf: Interface file