[PATCH 3/8] sched: Define and initialize a flag to identify valid PASID in the task

From: Fenghua Yu
Date: Mon Sep 20 2021 - 16:04:24 EST


From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>

Add a new field to the task structure to track whether this task
has initialized the IA32_PASID MSR (and thus holds a reference
count on the PASID for this process).

Initialize the field to zero when creating a new task with fork/clone.

Signed-off-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Co-developed-by: Fenghua Yu <fenghua.yu@xxxxxxxxx>
Signed-off-by: Fenghua Yu <fenghua.yu@xxxxxxxxx>
Reviewed-by: Tony Luck <tony.luck@xxxxxxxxx>
---
include/linux/sched.h | 4 ++++
kernel/fork.c | 4 ++++
2 files changed, 8 insertions(+)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 39039ce8ac4c..21a8cff9155c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -936,6 +936,10 @@ struct task_struct {
unsigned in_eventfd_signal:1;
#endif

+#ifdef CONFIG_IOMMU_SUPPORT
+ unsigned has_valid_pasid:1;
+#endif
+
unsigned long atomic_flags; /* Flags requiring atomic access. */

struct restart_block restart_block;
diff --git a/kernel/fork.c b/kernel/fork.c
index 38681ad44c76..e379f88260eb 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -967,6 +967,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
tsk->use_memdelay = 0;
#endif

+#ifdef CONFIG_IOMMU_SUPPORT
+ tsk->has_valid_pasid = 0;
+#endif
+
#ifdef CONFIG_MEMCG
tsk->active_memcg = NULL;
#endif
--
2.33.0