Skip to contentSkip to conversation

Simple tests for cross memory attach (process_vm_[readv|writev] syscalls)

PATCH In review Christopher Yeoh 4 participants 7 messages May 9, 2012 – Jul 11, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Simple tests for cross memory attach (process_vm_[readv|writev] syscalls)

Hi,

Here are some patches which add testcases for cross memory attach (CMA) functionality which is included in more recent kernels. CMA adds two new syscalls, process_vm_readv and process_vm_writev. Man pages for these two syscalls were added in the man-pages-3.40 release.

The testcases aren't really ready for inclusion as-is, but I thought they could do with some review now. One issue is that the syscall wrappers were not included in glibc until glibc 2.15 which not all distributions have picked up yet. For the testcases to compile I have a header file with some hard coded syscall numbers included (just for x86/powerpc atm, but more could be added). These numbers won't change in the future, but its an obviously ugly workaround.

Is this a show stopper problem? Do I have to wait until more distributions have picked up glibc 2.15 (or at least backported the glibc syscall wrappers) before it can be added to LTP? Or should I use some other workaround - eg detect if the syscalls are defined on the system and just not attempt to build the test if they aren't?

The testcases are not that extensive yet, just coverage of basic functionality.

Regards,

Chris

Signature · 1 line
[email protected]
testcases/kernel/syscalls/process_vm_readv/Makefile new file +23 -0
new file mode 100644
index 0000000..e0806a7
@@ -0,0 +1,23 @@
+#
+#  Copyright (c) International Business Machines  Corp., 2012
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/process_vm_readv/process_vm.h new file +48 -0

48 lines not on this page · raw message

testcases/kernel/syscalls/process_vm_readv/process_vm_readv01.c new file +172 -0

172 lines not on this page · raw message

testcases/kernel/syscalls/process_vm_readv/process_vm_readv02.c new file +258 -0

258 lines not on this page · raw message

testcases/kernel/syscalls/process_vm_writev/Makefile new file +23 -0
new file mode 100644
index 0000000..e0806a7
@@ -0,0 +1,23 @@
+#
+#  Copyright (c) International Business Machines  Corp., 2012
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/process_vm_writev/process_vm.h new file +48 -0

48 lines not on this page · raw message

testcases/kernel/syscalls/process_vm_writev/process_vm_writev01.c new file +196 -0

196 lines not on this page · raw message

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#1 lore raw
Quoted 21 lines · Christopher Yeoh

Hi,

Here are some patches which add testcases for cross memory attach (CMA) functionality which is included in more recent kernels. CMA adds two new syscalls, process_vm_readv and process_vm_writev. Man pages for these two syscalls were added in the man-pages-3.40 release.

The testcases aren't really ready for inclusion as-is, but I thought they could do with some review now. One issue is that the syscall wrappers were not included in glibc until glibc 2.15 which not all distributions have picked up yet. For the testcases to compile I have a header file with some hard coded syscall numbers included (just for x86/powerpc atm, but more could be added). These numbers won't change in the future, but its an obviously ugly workaround.

Is this a show stopper problem? Do I have to wait until more distributions have picked up glibc 2.15 (or at least backported the glibc syscall wrappers) before it can be added to LTP? Or should I use some other workaround - eg detect if the syscalls are defined on the system and just not attempt to build the test if they aren't?

Quoted 7 lines

The testcases are not that extensive yet, just coverage of basic functionality.

Regards,

Chris

Hi Chris, thanks very much for the patch, I tried to backport your testcases in http://ozlabs.org/~cyeoh/cma/ to LTP and composed an unfinished version, then I was busy for other things. I'm happy to see you can backport it by yourself :) There are some more new cma patches (aims on testing retcode and errnos) sent by Jan Stancek (cc-ed) [1], I think we need to discuss the testcase organization..

And I will review the testcases when I get more free time.

Thanks,
Caspar

[1]
http://thread.gmane.org/gmane.linux.ltp/16052
http://thread.gmane.org/gmane.linux.ltp/16053
http://thread.gmane.org/gmane.linux.ltp/16054
http://thread.gmane.org/gmane.linux.ltp/16055

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

----- Original Message -----

Quoted 15 lines

From: "Caspar Zhang" <[email protected]>
To: "Christopher Yeoh" <[email protected]>
Cc: [email protected], "Jan Stancek" <[email protected]>
Sent: Wednesday, 9 May, 2012 3:00:51 PM
Subject: Re: [LTP] [PATCH] Simple tests for cross memory attach (process_vm_[readv|writev] syscalls) Hi Chris, thanks very much for the patch, I tried to backport your
testcases in http://ozlabs.org/~cyeoh/cma/ to LTP and composed an
unfinished version, then I was busy for other things. I'm happy to
see
you can backport it by yourself :) There are some more new cma
patches
(aims on testing retcode and errnos) sent by Jan Stancek (cc-ed) [1],
I
think we need to discuss the testcase organization..

Quoted 1 line

And I will review the testcases when I get more free time.

Hi,

I looked at testcases sent by Chris. Good news is, they do not overlap (in terms of functionality) with mine :-).

The patch need some polishing to match the style guide:
- indentation
- I think output should be TINFO, rather than plain printf
- single statement if without { }
- I would split some code to more functions, for example process_vm_writev01.c main function seems complex

As for test organization, I think we need to decide 2 issues:
1. directory structure
a)
testcases/kernel/syscalls/cma/ testcases/kernel/syscalls/cma/process_vm_readv testcases/kernel/syscalls/cma/process_vm_writev
b)
testcases/kernel/syscalls/process_vm_readv testcases/kernel/syscalls/process_vm_writev

I'm preferring a) as these 2 syscalls are closely related, and we already have need to share code.

2. how to invoke new syscalls
a)
Patch from Chris is defining new syscall numbers in test and using syscall(2).

b)
My patch adds configure check for glibc wrappers process_vm_readv/writev and if those does not exists it checks for __NR_process_vm_readv.

I think we should not define syscall numbers in tests directly, but I'm relying on LTP maintainers to provide guidance here. In any case, if you run it on older kernel it should end with TCONF.

I would go with using Chris' process_vm.h, but remove syscall number defines and use names that wont conflict with glibc wrappers:
test_process_vm_readv
test_process_vm_writev

These could be function pointers, that would get initialized with function using glibc wrapper
function using syscall(__NR_process_vm_readv,..)
or NULL

each testcase could check in setup for NULL, and end with TCONF, if there is no way invoke that syscall.

There was question from Caspar, if we should check for both glibc wrapper and syscall number (http://thread.gmane.org/gmane.linux.ltp/16055).
I think we should, as we use glibc wrappers by default.

Any thoughts?

Regards,
Jan

Quoted 10 lines

Thanks,
Caspar

[1]
http://thread.gmane.org/gmane.linux.ltp/16052
http://thread.gmane.org/gmane.linux.ltp/16053
http://thread.gmane.org/gmane.linux.ltp/16054
http://thread.gmane.org/gmane.linux.ltp/16055

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw
Quoted 68 lines · Jan Stancek

----- Original Message -----

Quoted 15 lines

From: "Caspar Zhang" <[email protected]>
To: "Christopher Yeoh" <[email protected]>
Cc: [email protected], "Jan Stancek" <[email protected]>
Sent: Wednesday, 9 May, 2012 3:00:51 PM
Subject: Re: [LTP] [PATCH] Simple tests for cross memory attach (process_vm_[readv|writev] syscalls) Hi Chris, thanks very much for the patch, I tried to backport your
testcases in http://ozlabs.org/~cyeoh/cma/ to LTP and composed an
unfinished version, then I was busy for other things. I'm happy to
see
you can backport it by yourself :) There are some more new cma
patches
(aims on testing retcode and errnos) sent by Jan Stancek (cc-ed) [1],
I
think we need to discuss the testcase organization..

Quoted 1 line

And I will review the testcases when I get more free time.

Hi,

I looked at testcases sent by Chris. Good news is, they do not overlap (in terms of functionality) with mine :-).

The patch need some polishing to match the style guide:
- indentation
- I think output should be TINFO, rather than plain printf
- single statement if without { }
- I would split some code to more functions, for example process_vm_writev01.c main function seems complex

As for test organization, I think we need to decide 2 issues:
1. directory structure
a)
testcases/kernel/syscalls/cma/ testcases/kernel/syscalls/cma/process_vm_readv testcases/kernel/syscalls/cma/process_vm_writev
b)
testcases/kernel/syscalls/process_vm_readv testcases/kernel/syscalls/process_vm_writev

I'm preferring a) as these 2 syscalls are closely related, and we already have need to share code.

2. how to invoke new syscalls
a)
Patch from Chris is defining new syscall numbers in test and using syscall(2).

b)
My patch adds configure check for glibc wrappers process_vm_readv/writev and if those does not exists it checks for __NR_process_vm_readv.

I think we should not define syscall numbers in tests directly, but I'm relying on LTP maintainers to provide guidance here. In any case, if you run it on older kernel it should end with TCONF.

I would go with using Chris' process_vm.h, but remove syscall number defines and use names that wont conflict with glibc wrappers:
test_process_vm_readv
test_process_vm_writev

These could be function pointers, that would get initialized with function using glibc wrapper
function using syscall(__NR_process_vm_readv,..)
or NULL

Quoted 8 lines

each testcase could check in setup for NULL, and end with TCONF, if there is no way invoke that syscall.

There was question from Caspar, if we should check for both glibc wrapper and syscall number (http://thread.gmane.org/gmane.linux.ltp/16055).
I think we should, as we use glibc wrappers by default.

Any thoughts?

I'm attaching sample process_vm.h for illustration. This would go on top of:
http://thread.gmane.org/gmane.linux.ltp/16053
http://thread.gmane.org/gmane.linux.ltp/16054

each test would include that, check ltp_process_vm_readv/writev for NULL and optionally end with TCONF or continue.

Regards,
Jan

Quoted 14 lines

Regards,
Jan

Quoted 10 lines

Thanks,
Caspar

[1]
http://thread.gmane.org/gmane.linux.ltp/16052
http://thread.gmane.org/gmane.linux.ltp/16053
http://thread.gmane.org/gmane.linux.ltp/16054
http://thread.gmane.org/gmane.linux.ltp/16055

/*
* Copyright (C) 2012 Linux Test Project, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Further, this software is distributed without any warranty that it
* is free of the rightful claim of any third person regarding
* infringement or the like. Any license provided herein, whether
* implied or otherwise, applies only to this software file. Patent
* licenses, if any, provided herein do not apply to combinations of
* this program with other software, or any other product whatsoever. *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

#ifndef _PROCESS_VM_H_
#define _PROCESS_VM_H_

#include <sys/syscall.h>
#include <sys/uio.h>
#include <unistd.h>

#define CMA_PARAMS pid, lvec, liovcnt, rvec, riovcnt, flags
#define CMA_PARAMS_TYPES pid_t pid, const struct iovec *lvec, unsigned long liovcnt,\
const struct iovec *rvec, unsigned long riovcnt, unsigned long flags
#define CMA_FUNC_PROTO(func_name) ssize_t func_name(CMA_PARAMS_TYPES) #define CMA_FUNCP_PROTO(func_name) ssize_t (*func_name)(CMA_PARAMS_TYPES)

/*
* process_vm_readv
*/
#if (HAVE_PROCESS_VM_READV==1)
static inline CMA_FUNC_PROTO(ltp_process_vm_readv)

{
    return process_vm_readv(CMA_PARAMS);
}
#elif defined(__NR_process_vm_readv)
static inline CMA_FUNC_PROTO(ltp_process_vm_readv)
{
    return syscall(__NR_process_vm_readv, CMA_PARAMS);
}

#else
CMA_FUNCP_PROTO(ltp_process_vm_readv) = NULL;
#endif

/*
* process_vm_writev
*/
#if (HAVE_PROCESS_VM_WRITEV==1)
static inline CMA_FUNC_PROTO(ltp_process_vm_writev)

{
    return process_vm_writev(CMA_PARAMS);
}
#elif defined(__NR_process_vm_writev)
static inline CMA_FUNC_PROTO(ltp_process_vm_writev)
{
    return syscall(__NR_process_vm_writev, CMA_PARAMS);
}

#else
CMA_FUNCP_PROTO(ltp_process_vm_writev) = NULL;
#endif

#endif /* _PROCESS_VM_H_ */

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw
In reply to Jan Stancek
Quoted 6 lines · On Tue, 15 May 2012 10:56:17 -0400 (EDT) Jan Stancek <[email protected]>…

Hi,

I looked at testcases sent by Chris. Good news is, they do not overlap (in terms of functionality) with mine :-).

Quoted 6 lines

The patch need some polishing to match the style guide:
- indentation
- I think output should be TINFO, rather than plain printf
- single statement if without { }
- I would split some code to more functions, for example process_vm_writev01.c main function seems complex

Thanks for the feedback. I'll have a go at reworking them.

Quoted 10 lines

As for test organization, I think we need to decide 2 issues:
1. directory structure
a)
testcases/kernel/syscalls/cma/ testcases/kernel/syscalls/cma/process_vm_readv testcases/kernel/syscalls/cma/process_vm_writev
b)
testcases/kernel/syscalls/process_vm_readv testcases/kernel/syscalls/process_vm_writev

Quoted 2 lines

I'm preferring a) as these 2 syscalls are closely related, and we already have need to share code.

that would be fine with me.

Quoted 5 lines

2. how to invoke new syscalls
a)
Patch from Chris is defining new syscall numbers in test and using syscall(2).

Quoted 7 lines

b)
My patch adds configure check for glibc wrappers process_vm_readv/writev and if those does not exists it checks for __NR_process_vm_readv.

I think we should not define syscall numbers in tests directly, but I'm relying on LTP maintainers to provide guidance here.

I agree - the configure check is much better. I was just trying to get something working :-)

Regards,

Chris

Signature · 16 lines
[email protected]

-- 
[email protected]


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#6 lore raw
In reply to Jan Stancek

Hi!

Quoted 20 lines

I looked at testcases sent by Chris. Good news is, they do not overlap (in terms of functionality) with mine :-).

The patch need some polishing to match the style guide:
- indentation
- I think output should be TINFO, rather than plain printf
- single statement if without { }
- I would split some code to more functions, for example process_vm_writev01.c main function seems complex

As for test organization, I think we need to decide 2 issues:
1. directory structure
a)
testcases/kernel/syscalls/cma/ testcases/kernel/syscalls/cma/process_vm_readv testcases/kernel/syscalls/cma/process_vm_writev
b)
testcases/kernel/syscalls/process_vm_readv testcases/kernel/syscalls/process_vm_writev

Quoted 2 lines

I'm preferring a) as these 2 syscalls are closely related, and we already have need to share code.

Also please omit meaningless comments like:

/******************************************************
* main ******************************************************/

I'm also not a friend of keeping the HISTORY, FILENAME and others inside of the file. We do have git that keeps this information in more structured and useful manner. So this is a relict from a times developers were distributing source code in tarballs. Simple credits with your name in the top comment should be enough ;).

We use LKML coding style for LTP so you can use checkpatch.pl[1] to check that your platches are okay.

1. https://github.com/torvalds/linux/blob/master/scripts/checkpatch.pl

Quoted 4 lines

2. how to invoke new syscalls
a)
Patch from Chris is defining new syscall numbers in test and using syscall(2).

Don't do that, use testcases/kernel/include/linux_syscall_numbers.h instead (note that this file is generated and doesn't exists in the git repo).

Quoted 3 lines

b)
My patch adds configure check for glibc wrappers process_vm_readv/writev and if those does not exists it checks for __NR_process_vm_readv.

That is generally what we should do, although sometimes there is a difference between the libc wrapper and doing the syscall manually. In some of the cases you can't get EFAULT because the pointer is dereferenced in the userspace before it's passed to the kernel... Just keep that in mind.

Quoted 3 lines

I think we should not define syscall numbers in tests directly, but I'm relying on LTP maintainers to provide guidance here. In any case, if you run it on older kernel it should end with TCONF.

Yes, please use the generated header. ;)

Quoted 5 lines

I would go with using Chris' process_vm.h, but remove syscall number defines and use names that wont conflict with glibc wrappers:
test_process_vm_readv
test_process_vm_writev

Quoted 7 lines

These could be function pointers, that would get initialized with function using glibc wrapper
function using syscall(__NR_process_vm_readv,..)
or NULL

each testcase could check in setup for NULL, and end with TCONF, if there is no way invoke that syscall.

Once you actually _did_ the configure check, this complications aren't really needed. Or have I missed something?

Quoted 5 lines

There was question from Caspar, if we should check for both glibc wrapper and syscall number (http://thread.gmane.org/gmane.linux.ltp/16055).
I think we should, as we use glibc wrappers by default.

Any thoughts?

As I said, once you are sure that glibc wrapper and bare syscall do the same in your case preffering glibc wrapper is good idea as this covers the codepath as whole. Otherwise just do the syscall and it either works or you get ENOSYS.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw
In reply to Christopher Yeoh
Quoted 45 lines · Christopher Yeoh
Quoted 6 lines · On Tue, 15 May 2012 10:56:17 -0400 (EDT) Jan Stancek <[email protected]>…

Hi,

I looked at testcases sent by Chris. Good news is, they do not overlap (in terms of functionality) with mine :-).

Quoted 6 lines

The patch need some polishing to match the style guide:
- indentation
- I think output should be TINFO, rather than plain printf
- single statement if without { }
- I would split some code to more functions, for example process_vm_writev01.c main function seems complex

Thanks for the feedback. I'll have a go at reworking them.

Quoted 10 lines

As for test organization, I think we need to decide 2 issues:
1. directory structure
a)
testcases/kernel/syscalls/cma/ testcases/kernel/syscalls/cma/process_vm_readv testcases/kernel/syscalls/cma/process_vm_writev
b)
testcases/kernel/syscalls/process_vm_readv testcases/kernel/syscalls/process_vm_writev

Quoted 2 lines

I'm preferring a) as these 2 syscalls are closely related, and we already have need to share code.

that would be fine with me.

Quoted 5 lines

2. how to invoke new syscalls
a)
Patch from Chris is defining new syscall numbers in test and using syscall(2).

Quoted 7 lines

b)
My patch adds configure check for glibc wrappers process_vm_readv/writev and if those does not exists it checks for __NR_process_vm_readv.

I think we should not define syscall numbers in tests directly, but I'm relying on LTP maintainers to provide guidance here.

Quoted 7 lines

I agree - the configure check is much better. I was just trying to get something working :-)

Regards,

Chris

Hi Chris, not sure if you're working on a v2 to these CMA simple tests, if not, mind /me doing some update based on your version?

Thanks,
Caspar

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list