pagg
[Top] [All Lists]

Re: New pagg/job patches available

To: Erik Jacobson <erikj@xxxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: New pagg/job patches available
From: Peter Williams <pwil3058@xxxxxxxxxxxxxx>
Date: Thu, 06 May 2004 12:48:04 +1000
Cc: pagg@xxxxxxxxxxx
In-reply-to: <Pine.SGI.4.53.0405050711310.50361@subway.americas.sgi.com>
References: <Pine.SGI.4.53.0405041443560.8140@efs.americas.sgi.com> <40989065.4080905@bigpond.net.au> <Pine.SGI.4.53.0405050711310.50361@subway.americas.sgi.com>
Sender: pagg-bounce@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1
Erik Jacobson wrote:
Thanks.

Let me digest this and perhaps have some time to discuss it with a couple
of my co-workers.  I did get this and will get back to you.

Erik

On Wed, 5 May 2004, Peter Williams wrote:


Erik Jacobson wrote:

There are new pagg and job patches available for 2.4.26 and 2.6.5
kernels.

I went through a couple sets of changes based on suggestions from LMKL
with most of the suggestions coming from Christoph Hellwig.

Because changes include removing and renaming macros and functions, the
new job patch requires the new pagg patch.  In other words, if you wish
to use the job patch, be sure you match it with the proper version of
the PAGG.

I updated the README to show the pairs.

I have one more batch of changes to implement yet.

Thanks!

You can find the new patches on oss.sgi.com/projects/pagg
Click on 'download' on the left.

--
Erik Jacobson - Linux System Software - Silicon Graphics - Eagan, Minnesota



Please find attached a patch which is a first pass at a "safe to block" method for calling the init() function during client registration. The way in which this patch handles kmalloc() failures needs to be improved but I think this could benefit from input from someone more familiar with PAGG than I am.


OK. In addition to execve, I think that events such as changes to real uid, real gid and cpu affinity would be of (potential) interest to PAGG clients. To that end I enclose a set of patches that adds that functionality. This patch assumes that my init patch has already been applied but should patch successfully (with offsets) if it has not.


Enjoy
Peter
Index: Linux-2.6.5/Documentation/pagg.txt
diff -c Linux-2.6.5/Documentation/pagg.txt:1.1.4.1 
Linux-2.6.5/Documentation/pagg.txt:1.1.4.1.4.1
*** Linux-2.6.5/Documentation/pagg.txt:1.1.4.1  Wed May  5 15:36:45 2004
--- Linux-2.6.5/Documentation/pagg.txt  Thu May  6 12:33:18 2004
***************
*** 32,37 ****
--- 32,48 ----
  used, for example, by other kernel modules that wish to do advanced CPU
  placement on multi-processor systems (just one example).
  
+ The set_user function has been modified to support an optional callout
+ that can be run when a process in a pagg list changes its real uid.
+ 
+ The sys_setresgid, sy_setregid and sys_setgid functions have been modified
+ to support optional callouts that can be run when a process in a pagg list 
changes
+ its real gid.
+ 
+ The set_cpus_allowed function has been modified to support an optional callout
+ that can be run when a process in a pagg list changes its cpu affinity.  It 
could be
+ used, for example, to implement CPU sets.
+ 
  Additional details concerning this implementation of the process aggregates
  infrastructure are described in the sections that follow.
  
***************
*** 51,56 ****
--- 62,69 ----
  -  kernel/Makefile
  -  kernel/exit.c
  -  kernel/fork.c
+ -  kernel/sched.c
+ -  kernel/sys.c
  -  fs/exec.c
  -  init/Kconfig
  
***************
*** 96,101 ****
--- 109,117 ----
       void  *data;                            /* Module specific data */
       struct list_head entry;               /* List connection */
       void    (*exec)(struct task_struct *, struct pagg *); /* exec func ptr */
+     void    (*setruid)(struct task_struct *, struct pagg *); /* setruid func 
ptr */
+     void    (*setrgid)(struct task_struct *, struct pagg *); /* setrgid func 
ptr */
+     void    (*setcpuaffinity)(struct task_struct *, struct pagg *); /* 
setcpuaffinity func ptr */
  
  The pagg structure provides the process' reference to the PAGG
  containers provided by the PAGG modules.  The attach function pointer
***************
*** 104,110 ****
  the referenced PAGG container that the process is exiting or otherwise
  detaching from the container.  The exec function pointer is used when a
  process in the pagg container exec's a new process.  This is optional and
! may be set to NULL if it is not needed by the pagg module.
  
  The pagg_hook structure provides the reference to the module that
  implements a type of PAGG container.  In addition to the function pointers
--- 120,134 ----
  the referenced PAGG container that the process is exiting or otherwise
  detaching from the container.  The exec function pointer is used when a
  process in the pagg container exec's a new process.  This is optional and
! may be set to NULL if it is not needed by the pagg module. The setruid
! function pointer is used when a process in the pagg container changes its
! real uid.  This is optional and may be set to NULL if it is not needed by the
! pagg module. The setrgid function pointer is used when a process in the
! pagg container changes its real gid.  This is optional and may be set to
! NULL if it is not needed by the pagg module. The setcpuaffinity function
! pointer is used when a process in the pagg container changes its cpu
! affinity.  This is optional and may be set to NULL if it is not needed by the
! pagg module.
  
  The pagg_hook structure provides the reference to the module that
  implements a type of PAGG container.  In addition to the function pointers
***************
*** 129,134 ****
--- 153,167 ----
                 Call detach_pagg_list function with current task_struct 
  -  sys_execve:  (fs/exec.c)
       /* When a process in a pagg exec's, an optional callout can be run.  This
+         is implemented with an optional function pointer in the pagg_hook.  */
+ -  set_user:  (kernel/sys.c)
+      /* When a process in a pagg sets its real uid, an optional callout can 
be run.  This
+         is implemented with an optional function pointer in the pagg_hook.  */
+ -  sys_setresgid, sy_setregid and sys_setgid:  (kernel/sys.c)
+      /* When a process in a pagg sets its real gid, an optional callout can 
be run.  This
+         is implemented with an optional function pointer in the pagg_hook.  */
+ -  set_cpus_allowed:  (kernel/sched.c)
+      /* When a process in a pagg changes cpu affinity, an optional callout 
can be run.  This
          is implemented with an optional function pointer in the pagg_hook.  */
  
  2.6 New Functions
Index: Linux-2.6.5/include/linux/pagg.h
diff -c Linux-2.6.5/include/linux/pagg.h:1.1.4.1 
Linux-2.6.5/include/linux/pagg.h:1.1.4.1.4.1
*** Linux-2.6.5/include/linux/pagg.h:1.1.4.1    Wed May  5 15:36:45 2004
--- Linux-2.6.5/include/linux/pagg.h    Thu May  6 12:33:18 2004
***************
*** 121,126 ****
--- 121,138 ----
   *                     in the pagg container exec's a new process. This
   *                     is optional and may be set to NULL if it is not 
   *                     needed by the pagg module.
+  *     setruid:        Function pointer to function used when a process
+  *                     in the pagg container changes its real uid. This
+  *                     is optional and may be set to NULL if it is not 
+  *                     needed by the pagg module.
+  *     setrgid:        Function pointer to function used when a process
+  *                     in the pagg container changes its real gid. This
+  *                     is optional and may be set to NULL if it is not 
+  *                     needed by the pagg module.
+  *     setcpuaffinity: Function pointer to function used when a process
+  *                     in the pagg container changes its cpu affinity. This
+  *                     is optional and may be set to NULL if it is not 
+  *                     needed by the pagg module.
   */
  struct pagg_hook {
         struct module  *module;
***************
*** 131,136 ****
--- 143,151 ----
         int            (*attach)(struct task_struct *, struct pagg *, void*);
         int            (*detach)(struct task_struct *, struct pagg *);
         void           (*exec)(struct task_struct *, struct pagg *);
+        void           (*setruid)(struct task_struct *, struct pagg *);
+        void           (*setrgid)(struct task_struct *, struct pagg *);
+        void           (*setcpuaffinity)(struct task_struct *, struct pagg *);
  };
  
  
***************
*** 145,150 ****
--- 160,168 ----
                         struct task_struct *from_task);
  extern int __pagg_detach(struct task_struct *task);
  extern int __pagg_exec(struct task_struct *task);
+ extern int __pagg_setruid(struct task_struct *task);
+ extern int __pagg_setrgid(struct task_struct *task);
+ extern int __pagg_setcpuaffinity(struct task_struct *task);
  
  /* macros used when a child process must inherit attachment to pagg
   * containers from the parent.
***************
*** 182,187 ****
--- 200,235 ----
                __pagg_exec(task);                                      \
  } while(0)
  
+ /* 
+  * macro used when a process changes real uid.
+  *
+  */
+ #define pagg_setruid(task)                                            \
+ do {                                                                  \
+       if (!list_empty(&task->pagg_list.head))                         \
+               __pagg_setruid(task);                                   \
+ } while(0)
+ 
+ /* 
+  * macro used when a process changes real gid.
+  *
+  */
+ #define pagg_setrgid(task)                                            \
+ do {                                                                  \
+       if (!list_empty(&task->pagg_list.head))                         \
+               __pagg_setrgid(task);                                   \
+ } while(0)
+ 
+ /* 
+  * macro used when a process changes cpu affinity.
+  *
+  */
+ #define pagg_setrcpuaffinity(task)                                    \
+ do {                                                                  \
+       if (!list_empty(&task->pagg_list.head))                         \
+               __pagg_setrcpuaffinity(task);                           \
+ } while(0)
+ 
  /* The static inlines commented out for now with the ifdef below */
  #ifdef NOTDEFINED
  
***************
*** 217,222 ****
--- 265,300 ----
        if (!list_empty(&task->pagg_list.head))
                __pagg_exec(task);
  }
+ 
+ /* 
+  * function used when a process changes real uid.
+  *
+  */
+ static inline void pagg_setruid(struct task_struct *task)
+ {
+       if (!list_empty(&task->pagg_list.head))
+               __pagg_setruid(task);
+ }
+ 
+ /* 
+  * function used when a process changes real gid.
+  *
+  */
+ static inline void pagg_setrgid(struct task_struct *task)
+ {
+       if (!list_empty(&task->pagg_list.head))
+               __pagg_setrgid(task);
+ }
+ 
+ /* 
+  * function used when a process changes cpu affinity.
+  *
+  */
+ static inline void pagg_setcpuaffinity(struct task_struct *task)
+ {
+       if (!list_empty(&task->pagg_list.head))
+               __pagg_setcpuaffinity(task);
+ }
  #endif /* NOT-DEFINED just comment out the block above for now */
  
  /*
***************
*** 240,245 ****
--- 318,326 ----
  #define pagg_attach(ct, pt)  do { } while(0)
  #define pagg_detach(t)  do {  } while(0)     
  #define pagg_exec(t)  do {  } while(0)     
+ #define pagg_setruid(t)  do {  } while(0)     
+ #define pagg_setrgid(t)  do {  } while(0)     
+ #define pagg_setcpuaffinity(t)  do {  } while(0)     
  
  #endif /* CONFIG_PAGG */
  
Index: Linux-2.6.5/kernel/pagg.c
diff -c Linux-2.6.5/kernel/pagg.c:1.1.4.1.2.1 
Linux-2.6.5/kernel/pagg.c:1.1.4.1.2.1.2.1
*** Linux-2.6.5/kernel/pagg.c:1.1.4.1.2.1       Thu May  6 10:41:14 2004
--- Linux-2.6.5/kernel/pagg.c   Thu May  6 12:33:18 2004
***************
*** 497,502 ****
--- 497,568 ----
  }
  
  
+ /*
+  * __pagg_setruid
+  *
+  * Used to process a task's pagg list when changes real user id.
+  *
+  */
+ int __pagg_setruid(struct task_struct *task) 
+ {
+       struct pagg     *pagg;
+ 
+       down_read(&task->pagg_list.sem); /* lock the pagg list */
+ 
+       list_for_each_entry(pagg, &task->pagg_list.head, entry) {
+               if (pagg->hook->setruid) /* conditional because it's optional */
+                       pagg->hook->setruid(task, pagg);
+       }
+ 
+       up_read(&task->pagg_list.sem); /* unlock the pagg list */
+       return 0;
+ }
+ 
+ 
+ /*
+  * __pagg_setrgid
+  *
+  * Used to process a task's pagg list when it changes real group id.
+  *
+  */
+ int __pagg_setrgid(struct task_struct *task) 
+ {
+       struct pagg     *pagg;
+ 
+       down_read(&task->pagg_list.sem); /* lock the pagg list */
+ 
+       list_for_each_entry(pagg, &task->pagg_list.head, entry) {
+               if (pagg->hook->setrgid) /* conditional because it's optional */
+                       pagg->hook->setrgid(task, pagg);
+       }
+ 
+       up_read(&task->pagg_list.sem); /* unlock the pagg list */
+       return 0;
+ }
+ 
+ 
+ /*
+  * __pagg_setcpuaffinity
+  *
+  * Used to process a task's pagg list when it changes its cpu affinity.
+  *
+  */
+ int __pagg_setcpuaffinity(struct task_struct *task) 
+ {
+       struct pagg     *pagg;
+ 
+       down_read(&task->pagg_list.sem); /* lock the pagg list */
+ 
+       list_for_each_entry(pagg, &task->pagg_list.head, entry) {
+               if (pagg->hook->setcpuaffinity) /* conditional because it's 
optional */
+                       pagg->hook->setcpuaffinity(task, pagg);
+       }
+ 
+       up_read(&task->pagg_list.sem); /* unlock the pagg list */
+       return 0;
+ }
+ 
+ 
  EXPORT_SYMBOL(pagg_get);
  EXPORT_SYMBOL(pagg_alloc);
  EXPORT_SYMBOL(pagg_free);
Index: Linux-2.6.5/kernel/sched.c
diff -c Linux-2.6.5/kernel/sched.c:1.1.1.2 
Linux-2.6.5/kernel/sched.c:1.1.1.2.16.1
*** Linux-2.6.5/kernel/sched.c:1.1.1.2  Wed Mar 31 13:31:56 2004
--- Linux-2.6.5/kernel/sched.c  Thu May  6 12:33:18 2004
***************
*** 2712,2725 ****
  int set_cpus_allowed(task_t *p, cpumask_t new_mask)
  {
        unsigned long flags;
-       int ret = 0;
        migration_req_t req;
        runqueue_t *rq;
  
        rq = task_rq_lock(p, &flags);
        if (any_online_cpu(new_mask) == NR_CPUS) {
!               ret = -EINVAL;
!               goto out;
        }
  
        if (__set_cpus_allowed(p, new_mask, &req)) {
--- 2712,2724 ----
  int set_cpus_allowed(task_t *p, cpumask_t new_mask)
  {
        unsigned long flags;
        migration_req_t req;
        runqueue_t *rq;
  
        rq = task_rq_lock(p, &flags);
        if (any_online_cpu(new_mask) == NR_CPUS) {
!               task_rq_unlock(rq, &flags);
!               return -EINVAL;
        }
  
        if (__set_cpus_allowed(p, new_mask, &req)) {
***************
*** 2727,2737 ****
                task_rq_unlock(rq, &flags);
                wake_up_process(rq->migration_thread);
                wait_for_completion(&req.done);
                return 0;
        }
- out:
        task_rq_unlock(rq, &flags);
!       return ret;
  }
  
  EXPORT_SYMBOL_GPL(set_cpus_allowed);
--- 2726,2737 ----
                task_rq_unlock(rq, &flags);
                wake_up_process(rq->migration_thread);
                wait_for_completion(&req.done);
+               pagg_setcpuaffinity(p);
                return 0;
        }
        task_rq_unlock(rq, &flags);
!       pagg_setcpuaffinity(p);
!       return 0;
  }
  
  EXPORT_SYMBOL_GPL(set_cpus_allowed);
Index: Linux-2.6.5/kernel/sys.c
diff -c Linux-2.6.5/kernel/sys.c:1.1.1.1 Linux-2.6.5/kernel/sys.c:1.1.1.1.38.1
*** Linux-2.6.5/kernel/sys.c:1.1.1.1    Sun Mar 21 11:09:00 2004
--- Linux-2.6.5/kernel/sys.c    Thu May  6 12:33:18 2004
***************
*** 582,587 ****
--- 582,588 ----
        current->fsgid = new_egid;
        current->egid = new_egid;
        current->gid = new_rgid;
+       pagg_setrgid(current);
        return 0;
  }
  
***************
*** 607,612 ****
--- 608,614 ----
                        wmb();
                }
                current->gid = current->egid = current->sgid = current->fsgid = 
gid;
+               pagg_setrgid(current);
        }
        else if ((gid == current->gid) || (gid == current->sgid))
        {
***************
*** 645,650 ****
--- 647,653 ----
                wmb();
        }
        current->uid = new_ruid;
+       pagg_setruid(current);
        return 0;
  }
  
***************
*** 843,850 ****
                current->egid = egid;
        }
        current->fsgid = current->egid;
!       if (rgid != (gid_t) -1)
                current->gid = rgid;
        if (sgid != (gid_t) -1)
                current->sgid = sgid;
        return 0;
--- 846,855 ----
                current->egid = egid;
        }
        current->fsgid = current->egid;
!       if (rgid != (gid_t) -1) {
                current->gid = rgid;
+               pagg_setrgid(current);
+       }
        if (sgid != (gid_t) -1)
                current->sgid = sgid;
        return 0;
<Prev in Thread] Current Thread [Next in Thread>