From: Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
Juri Lelli <juri.lelli-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Vincent Guittot
<vincent.guittot-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Dietmar Eggemann <dietmar.eggemann-5wv7dgnIgG8@public.gmane.org>,
Steven Rostedt <rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org>,
Ben Segall <bsegall-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
Mel Gorman <mgorman-l3A5Bk7waGM@public.gmane.org>,
Daniel Bristot de Oliveira
<bristot-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Valentin Schneider
<vschneid-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Zefan Li <lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org>,
Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
Will Deacon <will-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Linus Torvalds
<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH v5 2/3] sched: Provide copy_user_cpus_mask() to copy out user mask
Date: Tue, 16 Aug 2022 15:27:33 -0400 [thread overview]
Message-ID: <20220816192734.67115-3-longman@redhat.com> (raw)
In-Reply-To: <20220816192734.67115-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Since accessing the content of the user_cpus_ptr requires lock protection
to ensure its validity, provide a helper function copy_user_cpus_mask()
to facilitate its reading.
Suggested-by: Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Signed-off-by: Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
include/linux/sched.h | 1 +
kernel/sched/core.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e7b2f8a5c711..f2b0340c094e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1830,6 +1830,7 @@ extern int task_can_attach(struct task_struct *p, const struct cpumask *cs_effec
extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask);
extern int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask);
extern int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src, int node);
+extern struct cpumask *copy_user_cpus_mask(struct task_struct *p, struct cpumask *user_mask);
extern void release_user_cpus_ptr(struct task_struct *p);
extern int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask);
extern void force_compatible_cpus_allowed_ptr(struct task_struct *p);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 03053eebb22e..a0987784913e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2618,6 +2618,25 @@ void release_user_cpus_ptr(struct task_struct *p)
kfree(clear_user_cpus_ptr(p));
}
+/*
+ * Return the copied mask pointer or NULL if user mask not available.
+ * Acquiring pi_lock for read access protection.
+ */
+struct cpumask *copy_user_cpus_mask(struct task_struct *p,
+ struct cpumask *user_mask)
+{
+ struct cpumask *mask = NULL;
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&p->pi_lock, flags);
+ if (p->user_cpus_ptr) {
+ cpumask_copy(user_mask, p->user_cpus_ptr);
+ mask = user_mask;
+ }
+ raw_spin_unlock_irqrestore(&p->pi_lock, flags);
+ return mask;
+}
+
/*
* This function is wildly self concurrent; here be dragons.
*
--
2.31.1
WARNING: multiple messages have this Message-ID (diff)
From: Waiman Long <longman@redhat.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Will Deacon <will@kernel.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Waiman Long <longman@redhat.com>
Subject: [PATCH v5 2/3] sched: Provide copy_user_cpus_mask() to copy out user mask
Date: Tue, 16 Aug 2022 15:27:33 -0400 [thread overview]
Message-ID: <20220816192734.67115-3-longman@redhat.com> (raw)
In-Reply-To: <20220816192734.67115-1-longman@redhat.com>
Since accessing the content of the user_cpus_ptr requires lock protection
to ensure its validity, provide a helper function copy_user_cpus_mask()
to facilitate its reading.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Waiman Long <longman@redhat.com>
---
include/linux/sched.h | 1 +
kernel/sched/core.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e7b2f8a5c711..f2b0340c094e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1830,6 +1830,7 @@ extern int task_can_attach(struct task_struct *p, const struct cpumask *cs_effec
extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask);
extern int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask);
extern int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src, int node);
+extern struct cpumask *copy_user_cpus_mask(struct task_struct *p, struct cpumask *user_mask);
extern void release_user_cpus_ptr(struct task_struct *p);
extern int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask);
extern void force_compatible_cpus_allowed_ptr(struct task_struct *p);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 03053eebb22e..a0987784913e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2618,6 +2618,25 @@ void release_user_cpus_ptr(struct task_struct *p)
kfree(clear_user_cpus_ptr(p));
}
+/*
+ * Return the copied mask pointer or NULL if user mask not available.
+ * Acquiring pi_lock for read access protection.
+ */
+struct cpumask *copy_user_cpus_mask(struct task_struct *p,
+ struct cpumask *user_mask)
+{
+ struct cpumask *mask = NULL;
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&p->pi_lock, flags);
+ if (p->user_cpus_ptr) {
+ cpumask_copy(user_mask, p->user_cpus_ptr);
+ mask = user_mask;
+ }
+ raw_spin_unlock_irqrestore(&p->pi_lock, flags);
+ return mask;
+}
+
/*
* This function is wildly self concurrent; here be dragons.
*
--
2.31.1
next prev parent reply other threads:[~2022-08-16 19:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 19:27 [PATCH v5 0/3] sched, cgroup/cpuset: Keep user set cpus affinity Waiman Long
2022-08-16 19:27 ` Waiman Long
[not found] ` <20220816192734.67115-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-08-16 19:27 ` [PATCH v5 1/3] sched: Use user_cpus_ptr for saving user provided cpumask in sched_setaffinity() Waiman Long
2022-08-16 19:27 ` Waiman Long
[not found] ` <20220816192734.67115-2-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-08-17 8:28 ` Peter Zijlstra
2022-08-17 8:28 ` Peter Zijlstra
[not found] ` <YvymwlTkdsVDtmRB-IIpfhp3q70z/8w/KjCw3T+5/BudmfyzbbVWyRVo5IupeoWH0uzbU5w@public.gmane.org>
2022-08-18 14:37 ` Waiman Long
2022-08-18 14:37 ` Waiman Long
2022-08-17 8:46 ` Peter Zijlstra
2022-08-17 8:46 ` Peter Zijlstra
2022-08-17 8:41 ` Peter Zijlstra
[not found] ` <Yvyp02LLIQQPs5d6-IIpfhp3q70z/8w/KjCw3T+5/BudmfyzbbVWyRVo5IupeoWH0uzbU5w@public.gmane.org>
2022-08-18 15:31 ` Waiman Long
2022-08-18 15:31 ` Waiman Long
2022-08-16 19:27 ` Waiman Long [this message]
2022-08-16 19:27 ` [PATCH v5 2/3] sched: Provide copy_user_cpus_mask() to copy out user mask Waiman Long
2022-08-16 19:27 ` [PATCH v5 3/3] cgroup/cpuset: Keep user set cpus affinity Waiman Long
2022-08-16 19:27 ` Waiman Long
[not found] ` <20220816192734.67115-4-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-08-16 20:15 ` Tejun Heo
2022-08-16 20:15 ` Tejun Heo
[not found] ` <Yvv66EWygCwHUCqy-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-08-16 22:11 ` Waiman Long
2022-08-16 22:11 ` Waiman Long
[not found] ` <c10e4f69-9951-6c38-6e28-fafcaec00d89-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-08-16 22:19 ` Tejun Heo
2022-08-16 22:19 ` Tejun Heo
[not found] ` <YvwX24GXadKQNp6V-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-08-17 0:13 ` Waiman Long
2022-08-17 0:13 ` Waiman Long
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220816192734.67115-3-longman@redhat.com \
--to=longman-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=bristot-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=bsegall-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dietmar.eggemann-5wv7dgnIgG8@public.gmane.org \
--cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
--cc=juri.lelli-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org \
--cc=mgorman-l3A5Bk7waGM@public.gmane.org \
--cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=vincent.guittot-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=vschneid-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=will-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.