scs: Add page accounting for shadow call stack allocations
[linux-2.6-microblaze.git] / kernel / scs.c
index 38f8f31..6d2f983 100644 (file)
@@ -6,8 +6,10 @@
  */
 
 #include <linux/kasan.h>
+#include <linux/mm.h>
 #include <linux/scs.h>
 #include <linux/slab.h>
+#include <linux/vmstat.h>
 #include <asm/scs.h>
 
 static struct kmem_cache *scs_cache;
@@ -40,6 +42,17 @@ void __init scs_init(void)
        scs_cache = kmem_cache_create("scs_cache", SCS_SIZE, 0, 0, NULL);
 }
 
+static struct page *__scs_page(struct task_struct *tsk)
+{
+       return virt_to_page(task_scs(tsk));
+}
+
+static void scs_account(struct task_struct *tsk, int account)
+{
+       mod_zone_page_state(page_zone(__scs_page(tsk)), NR_KERNEL_SCS_KB,
+               account * (SCS_SIZE / 1024));
+}
+
 int scs_prepare(struct task_struct *tsk, int node)
 {
        void *s = scs_alloc(node);
@@ -49,6 +62,7 @@ int scs_prepare(struct task_struct *tsk, int node)
 
        task_scs(tsk) = s;
        task_scs_offset(tsk) = 0;
+       scs_account(tsk, 1);
 
        return 0;
 }
@@ -61,5 +75,6 @@ void scs_release(struct task_struct *tsk)
                return;
 
        WARN(scs_corrupted(tsk), "corrupted shadow stack detected when freeing task\n");
+       scs_account(tsk, -1);
        scs_free(s);
 }