Bug 405394 - Add support for sched_setattr and sched_getattr system call.
Summary: Add support for sched_setattr and sched_getattr system call.
Status: RESOLVED DUPLICATE of bug 369029
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-12 14:56 UTC by Daniel Wagner
Modified: 2020-04-15 06:57 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Add support for sched_setattr and sched_getattr system calls (6.14 KB, patch)
2019-03-12 14:56 UTC, Daniel Wagner
Details
Add support for sched_setattr and sched_getattr v2 (7.12 KB, patch)
2019-03-13 10:18 UTC, Daniel Wagner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Wagner 2019-03-12 14:56:28 UTC
Created attachment 118743 [details]
Add support for sched_setattr and sched_getattr system calls

Subject: [PATCH] Add support for sched_setattr and sched_getattr system call.

Based on the sched_setparam and sched_getparam syscall wrapper.
Comment 1 Tom Hughes 2019-03-12 15:49:51 UTC
Those system calls should take a vki_sched_getattr as their second argument, not a vki_sched_getparam so as written then will be checking the wrong amount of memory.

Also setattr should presumably do PRE_MEM_READ and drop the write hooks as it presumably reads the structure rather than writing it.
Comment 2 Daniel Wagner 2019-03-12 17:29:07 UTC
Thanks for the feedback.

Okay, sorry for those obvious bugs. I was in a too fast copy&past mode. I'll update the patch accordingly, tomorrow.
Comment 3 Daniel Wagner 2019-03-13 09:16:05 UTC
With PRE_MEM_READ valgrind will complain for code like this (which should be fine, right?):

void run_deadline() {                                                                              
        struct sched_attr attr;                                                                    
                                                                                                   
        ret = sched_getattr(0, &attr, sizeof(attr), 0);                                            
}                                                                                                  
                                                                                                   
==11537== Thread 2:                                                                                
==11537== Syscall param sched_getattr(p) points to uninitialised byte(s)                           
==11537==    at 0x49A1EFD: syscall (in /usr/lib64/libc-2.28.so)                                    
==11537==    by 0x403E68: run_deadline (cyclicdeadline.c:784)                                      
==11537==    by 0x489058D: start_thread (in /usr/lib64/libpthread-2.28.so)                         
==11537==    by 0x49A76A2: clone (in /usr/lib64/libc-2.28.so)                                      
==11537==  Address 0x5671ea0 is on thread 2's stack                                                
==11537==  in frame #1, created by run_deadline (cyclicdeadline.c:772)                             
==11537==    

No complains with PRE_MEM_WRITE.
Comment 4 Tom Hughes 2019-03-13 09:28:04 UTC
Well that one doesn't need a PRE_MEM_READ so the fact that it would complain isn't really relevant.

You should use PRE_MEM_READ before the system call for any memory which will be read by the system call and PRE_MEM_WRITE for any memory which will be written by the system call (unless it is also read - you don't need to do both).

After the system call completes you should use POST_MEM_WRITE on any memory that the system call has written.

Basically PRE_MEM_READ checks that the memory is both addressable (that there is actual accessible memory at that address) and defined (that it has been initialised with known contents) while PRE_MEM_WRITE just does the first check. Then POST_MEM_WRITE marks the memory as defined if it has been filled in by the system call.
Comment 5 Daniel Wagner 2019-03-13 10:18:48 UTC
Created attachment 118767 [details]
Add support for sched_setattr and sched_getattr v2
Comment 6 Daniel Wagner 2019-03-13 10:23:14 UTC
I am not sure if I handle the size argument correctly. Here the snipped from the man pages:


       size   This field should be set  to  the  size  of  the  structure  in  bytes,  as  in
              sizeof(struct  sched_attr).  If the provided structure is smaller than the ker‐
              nel structure, any additional fields are assumed to be '0'.   If  the  provided
              structure  is  larger  than  the kernel structure, the kernel verifies that all
              additional fields are 0; if they are not, sched_setattr() fails with the  error
              E2BIG and updates size to contain the size of the kernel structure.

              The  above  behavior  when the size of the user-space sched_attr structure does
              not match the size of the kernel structure allows for future  extensibility  of
              the  interface.   Malformed  applications  that  pass oversize structures won't
              break in the  future  if  the  size  of  the  kernel  sched_attr  structure  is
              increased.   In  the future, it could also allow applications that know about a
              larger user-space sched_attr structure to determine whether they are running on
              an older kernel that does not support the larger structure.
Comment 7 zephyrus00jp 2020-04-14 23:26:52 UTC
Sorry, I did not notice there is a newer bugzilla and posted a patch to support sched_setattr and sched_getattr in bug 369029.
I wonder if someone can take a look at it.

https://bugs.kde.org/show_bug.cgi?id=369029

TIA
Comment 8 Daniel Wagner 2020-04-15 06:57:59 UTC
Let's close this report if it's already tracked in 369029.

*** This bug has been marked as a duplicate of bug 369029 ***