IPC: message queue checkpoint/restore - requested updates
v2 cover IPC: message queue checkpoint/restore - requested updates
Comparing to previous version:
1) single patch for all changes related to the feature (i.e. this patch is the replacement for c-r-ipc-message-queue-stealing-feature-introduced.patch).
2) Added self-test for MSG_PEEK_ALL feature.
The following series consists of:
---
Stanislav Kinsbursky (2):
IPC: message queue stealing feature introduced
IPC: selftest tor new MSG_PEEK_ALL flag for msgrcv()
include/linux/msg.h | 8 + ipc/compat.c | 42 ++++++ ipc/msg.c | 65 +++++++++- tools/testing/selftests/ipc/Makefile | 31 +++++ tools/testing/selftests/ipc/msgque_peek_all.c | 170 +++++++++++++++++++++++++ 5 files changed, 313 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/ipc/Makefile create mode 100644 tools/testing/selftests/ipc/msgque_peek_all.c
PATCH v2 1/2 IPC: message queue stealing feature introduced
v3:
1) MSG_PEEK_ALL looks familiar because MSG_PEEK for one socket message is used already.
2) All new checkpoint/restore code parts are now covered with CONFIG_CHECKPOINT_RESTORE macro. So it would be easy to remove them, in case the whole project fails.
3) return -ENOSYS, if user called sys_msgrcv() with MSG_PEEK_ALL flag set and checkpoint/restore code wasn't compiled.
v2:
1) compat functions added.
2) message slot size in array is now aligned by struct msgbuf_a.
3) check for enough free space in buffer before message copying added.
4) if MSG_STEAL flag is set, then do_msgrcv() returns number of bytes written to buffer.
5) flag MSG_NOERROR is ignored if MSG_STEAL flag is set.
This patch is required for checkpoint/restore in userspace.
IOW, c/r requires some way to get all pending IPC messages without deleting them for the queue (checkpoint can fail and in this case tasks will be resumed, so queue have to be valid).
To achive this, new operation flag MSG_STEAL for sys_msgrcv() system call introduced.
If this flag is set, then passed struct msgbuf pointer will be used for storing array of structures:
struct msgbuf_a {
long mtype; /* type of message */ int msize; /* size of message */ char mtext[0]; /* message text */
};
each of which will be followed by corresponding message data.
--- include/linux/msg.h | 8 ++++++ ipc/compat.c | 42 +++++++++++++++++++++++++++++++-- ipc/msg.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 112 insertions(+), 3 deletions(-)
include/linux/msg.h +8 -0
@@ -11,6 +11,7 @@/* msgrcv options */ #define MSG_NOERROR 010000/* no error if message is too big */ #define MSG_EXCEPT 020000/* recv any msg except of specified type.*/ +#define MSG_PEEK_ALL 040000/* copy (not remove) all queue messages */ /* Obsolete, used only for backwards compatibility and libc5 compiles */ struct msqid_ds {
@@ -38,6 +39,13 @@ struct msgbuf {char mtext[1 ];/* message text */ }; +/* message buffer for msgrcv in case of array calls */ +struct msgbuf_a { +long mtype;/* type of message */ +int msize;/* size of message */ +char mtext[0 ];/* message text */ +}; +/* buffer for msgctl calls IPC_INFO, MSG_INFO */ struct msginfo {int msgpool;
ipc/compat.c +40 -2
66 lines not on this page · raw message
ipc/msg.c +64 -1
104 lines not on this page · raw message
PATCH v2 2/2 IPC: selftest tor new MSG_PEEK_ALL flag for msgrcv()
In reply to Stanislav KinsburskyThis test send two messages, then peek them and check, that they are equal to original messages. Then it receives messages and check once more to make sure, that messages are not corrupted or lost after peek operation.
--- tools/testing/selftests/ipc/Makefile | 31 +++++ tools/testing/selftests/ipc/msgque_peek_all.c | 170 +++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 0 deletions(-) create mode 100644 tools/testing/selftests/ipc/Makefile create mode 100644 tools/testing/selftests/ipc/msgque_peek_all.c
tools/testing/selftests/ipc/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +ifeq ($(strip $(V)),) + E = @echo + Q = @ +else + E = @\# + Q = +endif +export E Q + +uname_M := $(shell uname -m 2>/dev/null || echo not) +ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) +ifeq ($(ARCH),i386) + ARCH := X86 + CFLAGS := -DCONFIG_X86_32 -D__i386__ +endif +ifeq ($(ARCH),x86_64) + ARCH := X86 + CFLAGS := -DCONFIG_X86_64 -D__x86_64__ +endif + +all: +ifeq ($(ARCH),X86) + $(E) " CC run_test" + $(Q) gcc msgque_peek_all.c -o run_test +else + $(E) "Not an x86 target, can't build kcmp selftest" +endif + +clean: + $(E) " CLEAN" + $(Q) rm -fr ./run_test
tools/testing/selftests/ipc/msgque_peek_all.c new file +170 -0
170 lines not on this page · raw message
Re: [PATCH v2 2/2] IPC: selftest tor new MSG_PEEK_ALL flag for msgrcv()
Quoted 5 lines · On Mon, 16 Apr 2012 18:06:13 +0400 Stanislav Kinsbursky…
This test send two messages, then peek them and check, that they are equal to original messages. Then it receives messages and check once more to make sure, that messages are not corrupted or lost after peek operation.
---
Missing signed-off-by. I added your s-o-b to my copy of the changelog.
Re: [PATCH v2 2/2] IPC: selftest tor new MSG_PEEK_ALL flag for msgrcv()
17.04.2012 02:11, Andrew Morton пишет:
Quoted 10 lines
Quoted 5 lines · On Mon, 16 Apr 2012 18:06:13 +0400 Stanislav…
This test send two messages, then peek them and check, that they are equal to original messages. Then it receives messages and check once more to make sure, that messages are not corrupted or lost after peek operation.
---
Missing signed-off-by. I added your s-o-b to my copy of the changelog.
Sorry. Thanks.
Signature · 2 lines
Best regards, Stanislav Kinsbursky
Hello, Andrew.
I'm very sorry, but a critical flaw has been found in this feature: copying of kernel data to user is done under spinlock. Since message queue size can be increased up to INT_MAX, then copying to temporary kernel buffer while passing message queue in not a solution. So, please, drop both patches (feature implementation and test).
Most probably Ill replace them with MSG_PEEK feature (the same logic, but only for one message - like it's done for sockets).
Signature · 2 lines
Best regards, Stanislav Kinsbursky