Skip to content
  • Chris Hyser's avatar
    7ac592aa
    sched: prctl() core-scheduling interface · 7ac592aa
    Chris Hyser authored
    
    
    This patch provides support for setting and copying core scheduling
    'task cookies' between threads (PID), processes (TGID), and process
    groups (PGID).
    
    The value of core scheduling isn't that tasks don't share a core,
    'nosmt' can do that. The value lies in exploiting all the sharing
    opportunities that exist to recover possible lost performance and that
    requires a degree of flexibility in the API.
    
    From a security perspective (and there are others), the thread,
    process and process group distinction is an existent hierarchal
    categorization of tasks that reflects many of the security concerns
    about 'data sharing'. For example, protecting against cache-snooping
    by a thread that can just read the memory directly isn't all that
    useful.
    
    With this in mind, subcommands to CREATE/SHARE (TO/FROM) provide a
    mechanism to create and share cookies. CREATE/SHARE_TO specify a
    target pid with enum pidtype used to specify the scope of the targeted
    tasks. For example, PIDTYPE_TGID will share the cookie with the
    process and all of it's threads as typically desired in a security
    scenario.
    
    API:
    
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, tgtpid, pidtype, &cookie)
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, tgtpid, pidtype, NULL)
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, tgtpid, pidtype, NULL)
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, srcpid, pidtype, NULL)
    
    where 'tgtpid/srcpid == 0' implies the current process and pidtype is
    kernel enum pid_type {PIDTYPE_PID, PIDTYPE_TGID, PIDTYPE_PGID, ...}.
    
    For return values, EINVAL, ENOMEM are what they say. ESRCH means the
    tgtpid/srcpid was not found. EPERM indicates lack of PTRACE permission
    access to tgtpid/srcpid. ENODEV indicates your machines lacks SMT.
    
    [peterz: complete rewrite]
    Signed-off-by: default avatarChris Hyser <chris.hyser@oracle.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Tested-by: default avatarDon Hiatt <dhiatt@digitalocean.com>
    Tested-by: default avatarHongyu Ning <hongyu.ning@linux.intel.com>
    Tested-by: default avatarVincent Guittot <vincent.guittot@linaro.org>
    Link: https://lkml.kernel.org/r/20210422123309.039845339@infradead.org
    7ac592aa
    sched: prctl() core-scheduling interface
    Chris Hyser authored
    
    
    This patch provides support for setting and copying core scheduling
    'task cookies' between threads (PID), processes (TGID), and process
    groups (PGID).
    
    The value of core scheduling isn't that tasks don't share a core,
    'nosmt' can do that. The value lies in exploiting all the sharing
    opportunities that exist to recover possible lost performance and that
    requires a degree of flexibility in the API.
    
    From a security perspective (and there are others), the thread,
    process and process group distinction is an existent hierarchal
    categorization of tasks that reflects many of the security concerns
    about 'data sharing'. For example, protecting against cache-snooping
    by a thread that can just read the memory directly isn't all that
    useful.
    
    With this in mind, subcommands to CREATE/SHARE (TO/FROM) provide a
    mechanism to create and share cookies. CREATE/SHARE_TO specify a
    target pid with enum pidtype used to specify the scope of the targeted
    tasks. For example, PIDTYPE_TGID will share the cookie with the
    process and all of it's threads as typically desired in a security
    scenario.
    
    API:
    
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, tgtpid, pidtype, &cookie)
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, tgtpid, pidtype, NULL)
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, tgtpid, pidtype, NULL)
      prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, srcpid, pidtype, NULL)
    
    where 'tgtpid/srcpid == 0' implies the current process and pidtype is
    kernel enum pid_type {PIDTYPE_PID, PIDTYPE_TGID, PIDTYPE_PGID, ...}.
    
    For return values, EINVAL, ENOMEM are what they say. ESRCH means the
    tgtpid/srcpid was not found. EPERM indicates lack of PTRACE permission
    access to tgtpid/srcpid. ENODEV indicates your machines lacks SMT.
    
    [peterz: complete rewrite]
    Signed-off-by: default avatarChris Hyser <chris.hyser@oracle.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Tested-by: default avatarDon Hiatt <dhiatt@digitalocean.com>
    Tested-by: default avatarHongyu Ning <hongyu.ning@linux.intel.com>
    Tested-by: default avatarVincent Guittot <vincent.guittot@linaro.org>
    Link: https://lkml.kernel.org/r/20210422123309.039845339@infradead.org
Loading