LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v4] uapi/linux/prctl: provide macro definitions for the PR_SCHED_CORE type argument
@ 2021-08-25 17:06 Eugene Syromiatnikov
  2021-08-26 10:00 ` Christian Brauner
  0 siblings, 1 reply; 3+ messages in thread
From: Eugene Syromiatnikov @ 2021-08-25 17:06 UTC (permalink / raw)
  To: Peter Zijlstra (Intel),
	Christian Brauner, Joel Fernandes (Google),
	Chris Hyser, Josh Don, Ingo Molnar, Vincent Guittot,
	Valentin Schneider, Mel Gorman
  Cc: linux-kernel, Thomas Gleixner, Dmitry V. Levin, linux-doc,
	linux-api, Jonathan Corbet

Commit 7ac592aa35a684ff ("sched: prctl() core-scheduling interface")
made use of enum pid_type in prctl's arg4; this type and the associated
enumeration definitions are not exposed to userspace.  Christian
has suggested to provide additional macro definitions that convey
the meaning of the type argument more in alignment with its actual
usage, and this patch does exactly that.

Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
Complements: 7ac592aa35a684ff ("sched: prctl() core-scheduling interface")
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
---
v4:
  - Rewritten in accordance with Christian Brauner's suggestion to provide
    macro definitions that are explicitly tailored for the prctl op.

v3: https://lore.kernel.org/lkml/20210807120905.GA14706@asgard.redhat.com/
  - Fixed header guard macro: s/_UAPI_LINUX_PID_H/_UAPI_LINUX_PIDTYPE_H/,
    as noted by Dmitry Levin.

v2: https://lore.kernel.org/lkml/20210807104800.GA22620@asgard.redhat.com/
  - Header file is renamed from pid.h to pidtype.h to avoid collisions
    with include/linux/pid.h when included from uapi headers;
  - The enum type has renamed from __kernel_pid_type to __kernel_pidtype
    to avoid possible confusion with __kernel_pid_t.

v1: https://lore.kernel.org/lkml/20210807010123.GA5174@asgard.redhat.com/
---
 Documentation/admin-guide/hw-vuln/core-scheduling.rst | 5 +++--
 include/uapi/linux/prctl.h                            | 3 +++
 kernel/sched/core_sched.c                             | 4 ++++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/hw-vuln/core-scheduling.rst b/Documentation/admin-guide/hw-vuln/core-scheduling.rst
index 7b410ae..9a65fed 100644
--- a/Documentation/admin-guide/hw-vuln/core-scheduling.rst
+++ b/Documentation/admin-guide/hw-vuln/core-scheduling.rst
@@ -61,8 +61,9 @@ arg3:
     ``pid`` of the task for which the operation applies.
 
 arg4:
-    ``pid_type`` for which the operation applies. It is of type ``enum pid_type``.
-    For example, if arg4 is ``PIDTYPE_TGID``, then the operation of this command
+    ``pid_type`` for which the operation applies. It is one of
+    ``PR_SCHED_CORE_SCOPE_``-prefixed macro constants.  For example, if arg4
+    is ``PR_SCHED_CORE_SCOPE_THREAD_GROUP``, then the operation of this command
     will be performed for all tasks in the task group of ``pid``.
 
 arg5:
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index 967d9c5..644a3b4 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -266,5 +266,8 @@ struct prctl_mm_map {
 # define PR_SCHED_CORE_SHARE_TO		2 /* push core_sched cookie to pid */
 # define PR_SCHED_CORE_SHARE_FROM	3 /* pull core_sched cookie to pid */
 # define PR_SCHED_CORE_MAX		4
+# define PR_SCHED_CORE_SCOPE_THREAD		0
+# define PR_SCHED_CORE_SCOPE_THREAD_GROUP	1
+# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP	2
 
 #endif /* _LINUX_PRCTL_H */
diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
index 9a80e9a..20f6409 100644
--- a/kernel/sched/core_sched.c
+++ b/kernel/sched/core_sched.c
@@ -134,6 +134,10 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
 	if (!static_branch_likely(&sched_smt_present))
 		return -ENODEV;
 
+	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD != PIDTYPE_PID);
+	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD_GROUP != PIDTYPE_TGID);
+	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_PROCESS_GROUP != PIDTYPE_PGID);
+
 	if (type > PIDTYPE_PGID || cmd >= PR_SCHED_CORE_MAX || pid < 0 ||
 	    (cmd != PR_SCHED_CORE_GET && uaddr))
 		return -EINVAL;
-- 
2.1.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] uapi/linux/prctl: provide macro definitions for the PR_SCHED_CORE type argument
  2021-08-25 17:06 [PATCH v4] uapi/linux/prctl: provide macro definitions for the PR_SCHED_CORE type argument Eugene Syromiatnikov
@ 2021-08-26 10:00 ` Christian Brauner
  2021-09-02 13:44   ` Christian Brauner
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2021-08-26 10:00 UTC (permalink / raw)
  To: Eugene Syromiatnikov, Peter Zijlstra (Intel)
  Cc: Joel Fernandes (Google),
	Chris Hyser, Josh Don, Ingo Molnar, Vincent Guittot,
	Valentin Schneider, Mel Gorman, linux-kernel, Thomas Gleixner,
	Dmitry V. Levin, linux-doc, linux-api, Jonathan Corbet

On Wed, Aug 25, 2021 at 07:06:13PM +0200, Eugene Syromiatnikov wrote:
> Commit 7ac592aa35a684ff ("sched: prctl() core-scheduling interface")
> made use of enum pid_type in prctl's arg4; this type and the associated
> enumeration definitions are not exposed to userspace.  Christian
> has suggested to provide additional macro definitions that convey
> the meaning of the type argument more in alignment with its actual
> usage, and this patch does exactly that.
> 
> Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
> Complements: 7ac592aa35a684ff ("sched: prctl() core-scheduling interface")
> Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
> ---

I mean, I proposed the names so I'm ok with them. :)
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>

Peter et al. are you ok with this and do the names make sense to you?

Christian

> v4:
>   - Rewritten in accordance with Christian Brauner's suggestion to provide
>     macro definitions that are explicitly tailored for the prctl op.
> 
> v3: https://lore.kernel.org/lkml/20210807120905.GA14706@asgard.redhat.com/
>   - Fixed header guard macro: s/_UAPI_LINUX_PID_H/_UAPI_LINUX_PIDTYPE_H/,
>     as noted by Dmitry Levin.
> 
> v2: https://lore.kernel.org/lkml/20210807104800.GA22620@asgard.redhat.com/
>   - Header file is renamed from pid.h to pidtype.h to avoid collisions
>     with include/linux/pid.h when included from uapi headers;
>   - The enum type has renamed from __kernel_pid_type to __kernel_pidtype
>     to avoid possible confusion with __kernel_pid_t.
> 
> v1: https://lore.kernel.org/lkml/20210807010123.GA5174@asgard.redhat.com/
> ---
>  Documentation/admin-guide/hw-vuln/core-scheduling.rst | 5 +++--
>  include/uapi/linux/prctl.h                            | 3 +++
>  kernel/sched/core_sched.c                             | 4 ++++
>  3 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/admin-guide/hw-vuln/core-scheduling.rst b/Documentation/admin-guide/hw-vuln/core-scheduling.rst
> index 7b410ae..9a65fed 100644
> --- a/Documentation/admin-guide/hw-vuln/core-scheduling.rst
> +++ b/Documentation/admin-guide/hw-vuln/core-scheduling.rst
> @@ -61,8 +61,9 @@ arg3:
>      ``pid`` of the task for which the operation applies.
>  
>  arg4:
> -    ``pid_type`` for which the operation applies. It is of type ``enum pid_type``.
> -    For example, if arg4 is ``PIDTYPE_TGID``, then the operation of this command
> +    ``pid_type`` for which the operation applies. It is one of
> +    ``PR_SCHED_CORE_SCOPE_``-prefixed macro constants.  For example, if arg4
> +    is ``PR_SCHED_CORE_SCOPE_THREAD_GROUP``, then the operation of this command
>      will be performed for all tasks in the task group of ``pid``.
>  
>  arg5:
> diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
> index 967d9c5..644a3b4 100644
> --- a/include/uapi/linux/prctl.h
> +++ b/include/uapi/linux/prctl.h
> @@ -266,5 +266,8 @@ struct prctl_mm_map {
>  # define PR_SCHED_CORE_SHARE_TO		2 /* push core_sched cookie to pid */
>  # define PR_SCHED_CORE_SHARE_FROM	3 /* pull core_sched cookie to pid */
>  # define PR_SCHED_CORE_MAX		4
> +# define PR_SCHED_CORE_SCOPE_THREAD		0
> +# define PR_SCHED_CORE_SCOPE_THREAD_GROUP	1
> +# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP	2
>  
>  #endif /* _LINUX_PRCTL_H */
> diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
> index 9a80e9a..20f6409 100644
> --- a/kernel/sched/core_sched.c
> +++ b/kernel/sched/core_sched.c
> @@ -134,6 +134,10 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
>  	if (!static_branch_likely(&sched_smt_present))
>  		return -ENODEV;
>  
> +	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD != PIDTYPE_PID);
> +	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD_GROUP != PIDTYPE_TGID);
> +	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_PROCESS_GROUP != PIDTYPE_PGID);
> +
>  	if (type > PIDTYPE_PGID || cmd >= PR_SCHED_CORE_MAX || pid < 0 ||
>  	    (cmd != PR_SCHED_CORE_GET && uaddr))
>  		return -EINVAL;
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] uapi/linux/prctl: provide macro definitions for the PR_SCHED_CORE type argument
  2021-08-26 10:00 ` Christian Brauner
@ 2021-09-02 13:44   ` Christian Brauner
  0 siblings, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2021-09-02 13:44 UTC (permalink / raw)
  To: Eugene Syromiatnikov, Peter Zijlstra (Intel)
  Cc: Joel Fernandes (Google),
	Chris Hyser, Josh Don, Ingo Molnar, Vincent Guittot,
	Valentin Schneider, Mel Gorman, linux-kernel, Thomas Gleixner,
	Dmitry V. Levin, linux-doc, linux-api, Jonathan Corbet

On Thu, Aug 26, 2021 at 12:00:25PM +0200, Christian Brauner wrote:
> On Wed, Aug 25, 2021 at 07:06:13PM +0200, Eugene Syromiatnikov wrote:
> > Commit 7ac592aa35a684ff ("sched: prctl() core-scheduling interface")
> > made use of enum pid_type in prctl's arg4; this type and the associated
> > enumeration definitions are not exposed to userspace.  Christian
> > has suggested to provide additional macro definitions that convey
> > the meaning of the type argument more in alignment with its actual
> > usage, and this patch does exactly that.
> > 
> > Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
> > Complements: 7ac592aa35a684ff ("sched: prctl() core-scheduling interface")
> > Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
> > ---
> 
> I mean, I proposed the names so I'm ok with them. :)
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
> 
> Peter et al. are you ok with this and do the names make sense to you?

I'll pick this up once the merge window closes then.

Thanks!
Christian

> 
> Christian
> 
> > v4:
> >   - Rewritten in accordance with Christian Brauner's suggestion to provide
> >     macro definitions that are explicitly tailored for the prctl op.
> > 
> > v3: https://lore.kernel.org/lkml/20210807120905.GA14706@asgard.redhat.com/
> >   - Fixed header guard macro: s/_UAPI_LINUX_PID_H/_UAPI_LINUX_PIDTYPE_H/,
> >     as noted by Dmitry Levin.
> > 
> > v2: https://lore.kernel.org/lkml/20210807104800.GA22620@asgard.redhat.com/
> >   - Header file is renamed from pid.h to pidtype.h to avoid collisions
> >     with include/linux/pid.h when included from uapi headers;
> >   - The enum type has renamed from __kernel_pid_type to __kernel_pidtype
> >     to avoid possible confusion with __kernel_pid_t.
> > 
> > v1: https://lore.kernel.org/lkml/20210807010123.GA5174@asgard.redhat.com/
> > ---
> >  Documentation/admin-guide/hw-vuln/core-scheduling.rst | 5 +++--
> >  include/uapi/linux/prctl.h                            | 3 +++
> >  kernel/sched/core_sched.c                             | 4 ++++
> >  3 files changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/Documentation/admin-guide/hw-vuln/core-scheduling.rst b/Documentation/admin-guide/hw-vuln/core-scheduling.rst
> > index 7b410ae..9a65fed 100644
> > --- a/Documentation/admin-guide/hw-vuln/core-scheduling.rst
> > +++ b/Documentation/admin-guide/hw-vuln/core-scheduling.rst
> > @@ -61,8 +61,9 @@ arg3:
> >      ``pid`` of the task for which the operation applies.
> >  
> >  arg4:
> > -    ``pid_type`` for which the operation applies. It is of type ``enum pid_type``.
> > -    For example, if arg4 is ``PIDTYPE_TGID``, then the operation of this command
> > +    ``pid_type`` for which the operation applies. It is one of
> > +    ``PR_SCHED_CORE_SCOPE_``-prefixed macro constants.  For example, if arg4
> > +    is ``PR_SCHED_CORE_SCOPE_THREAD_GROUP``, then the operation of this command
> >      will be performed for all tasks in the task group of ``pid``.
> >  
> >  arg5:
> > diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
> > index 967d9c5..644a3b4 100644
> > --- a/include/uapi/linux/prctl.h
> > +++ b/include/uapi/linux/prctl.h
> > @@ -266,5 +266,8 @@ struct prctl_mm_map {
> >  # define PR_SCHED_CORE_SHARE_TO		2 /* push core_sched cookie to pid */
> >  # define PR_SCHED_CORE_SHARE_FROM	3 /* pull core_sched cookie to pid */
> >  # define PR_SCHED_CORE_MAX		4
> > +# define PR_SCHED_CORE_SCOPE_THREAD		0
> > +# define PR_SCHED_CORE_SCOPE_THREAD_GROUP	1
> > +# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP	2
> >  
> >  #endif /* _LINUX_PRCTL_H */
> > diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
> > index 9a80e9a..20f6409 100644
> > --- a/kernel/sched/core_sched.c
> > +++ b/kernel/sched/core_sched.c
> > @@ -134,6 +134,10 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
> >  	if (!static_branch_likely(&sched_smt_present))
> >  		return -ENODEV;
> >  
> > +	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD != PIDTYPE_PID);
> > +	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD_GROUP != PIDTYPE_TGID);
> > +	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_PROCESS_GROUP != PIDTYPE_PGID);
> > +
> >  	if (type > PIDTYPE_PGID || cmd >= PR_SCHED_CORE_MAX || pid < 0 ||
> >  	    (cmd != PR_SCHED_CORE_GET && uaddr))
> >  		return -EINVAL;
> > -- 
> > 2.1.4
> > 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-02 13:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25 17:06 [PATCH v4] uapi/linux/prctl: provide macro definitions for the PR_SCHED_CORE type argument Eugene Syromiatnikov
2021-08-26 10:00 ` Christian Brauner
2021-09-02 13:44   ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).