2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-25 11:27:40 +00:00

48 Commits

Author SHA1 Message Date
Andrei Vagin
b2ec837f72 bitops: use a gcc builtin function instead of our __ffs
Our __ffs implementation is straightforward and non-optimal,
__builtin_ffsl should be faster.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-06-18 21:09:39 +03:00
Andrei Vagin
80a4d3cf8c bitops: use the UL literal for constants
We operate by long variables in out bit arithmetics, so our constants
should be marked as long too.

Cc: Adrian Reber <areber@redhat.com>
Reported-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Tested-by: Adrian Reber <areber@redhat.com>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-06-18 20:09:39 +03:00
Cyrill Gorcunov
89c9ec7f2f arch, ppc64: Add missing atomic_dec_and_test helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-05-16 21:53:34 +03:00
Dmitry Safonov
c37583942c ppc64/aarch64: Dynamically define PAGE_SIZE
On ppc64/aarch64 Linux can be set to use Large pages, so the PAGE_SIZE
isn't build-time constant anymore. Define it through _SC_PAGESIZE.

There are different sizes for a page on ppc64:
: #if defined(CONFIG_PPC_256K_PAGES)
: #define PAGE_SHIFT              18
: #elif defined(CONFIG_PPC_64K_PAGES)
: #define PAGE_SHIFT              16
: #elif defined(CONFIG_PPC_16K_PAGES)
: #define PAGE_SHIFT              14
: #else
: #define PAGE_SHIFT              12
: #endif

And on aarch64 there are default sizes and possibly someone can set his
own PAGE_SHIFT:
: config ARM64_PAGE_SHIFT
:         int
:         default 16 if ARM64_64K_PAGES
:         default 14 if ARM64_16K_PAGES
:         default 12

On the downside - each time we need PAGE_SIZE, we're doing libc
function call on aarch64/ppc64.

Fixes: #415

Tested-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-05-15 03:03:01 +03:00
Dmitry Safonov
0f98ee4641 compel/criu: Add ARCH_HAS_LONG_PAGES to PIE binaries
For architectures like aarch64/ppc64 it's needed to propagate the size
of page inside PIEs. For the parasite page size will be defined during
seizing, and for restorer during early initialization.
Afterward we can use PAGE_SIZE in PIEs like we did before.

Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-05-15 03:03:01 +03:00
Kirill Tkhai
bfbd7bbacb utils: Introduce SWAP() helper to exchange two variables
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Michael Holzheu
a04dc883cb s390: Replace flogr instruction with __builtin_clzl()
The flogr instruction not supported by debian jessie (z900).
So replace it by the gcc built-in.

Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-08-09 18:51:41 +03:00
Michael Holzheu
7ce8f56be2 s390:compel/arch/s390: Add architecture support to compel tool and libraries
This patch only adds the support but does not enable it for building.

Reviewed-by: Alice Frosi <alice@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-08-09 18:51:41 +03:00
Dmitry Safonov
8c1d8b74d0 x86/asm: move user code selector values to common
I'll need them in parasite head and in exit.

travis-ci: success for Rectify 32-bit compatible C/R on x86
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-15 00:06:17 +03:00
Cyrill Gorcunov
a0810481e5 compel: Include compel headers as system ones
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-15 00:06:02 +03:00
Cyrill Gorcunov
35726a7667 compel: criu -- Start using uapi/std syscalls stubs
Real syscalls generation is inside criu for a while
but will be moved out in the next patch.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-14 23:58:20 +03:00
Kirill Tkhai
b20780d6a0 files: Fix test and set endianess problem
Andrew Vagin reported the problem found by a checker:

    CID 174702 (#1 of 1): Out-of-bounds access (INCOMPATIBLE_CAST)
    incompatible_cast: Pointer &f->raw.counter points to an object whose
    effective type is int (32 bits, signed) but is dereferenced as a wider
    unsigned long (64 bits, unsigned). This may lead to memory corruption.

It looks like, this points to real problem, which may happen on big-endian
platforms. In the code I relay on the fact, that FDS_EVENT_BIT has a small
number and the value, it determines, fits into int type without problems.
But it's correct only for little-endian.

In case of big-endian, if the word size is 8 bytes, then FDS_EVENT value
is in the last bytes, so there is an access to wrong memory.

To fix the problem, I suggest to use little-endian byte order to work
with task_st futex. Then, the bits from 0 to 31 will be in the low adresses,
i.e. in task_st futex. There is new primitives test_and_set_bit_le() and
set_bit_le() borrowed from the linux kernel for that.

This fixes the problem, but I suppose, the checker does not see the problem
so deep, and just compares the types size, so it will fail again.
So, let's enlarge the bit field size to silence it.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-06 14:09:15 +03:00
Kirill Tkhai
735461e1bf files: Implement {set,clear,wait}_fds_event()
The idea is symilar to kernel's wake_up() and wait_event().
One task needs some event. It checks the event has not
happened yet (fle hasn't received, unix peer hasn't bound, etc)
and calls get_fds_event(). Other task makes the event
(sends a fle, binds the peer to a name, etc) and calls set_fds_event().

So, while there is no an event, the first task is sleeping,
and the second wakes it up later:

Task A:      clear_fds_event();
             if (!socket_bound)
                     wait_fds_event(); /* sleep */

Task B:      bind_socket();
             set_fds_event();         /* wake up */

For the details of using see next patches.

v5: Use bit operations.
    Split clear_fds_event from wait function.

v2: Do not wait for foreign transport sock is ready,
as it's guarantied by we create it before CR_STATE_FORKING.

travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-06 14:09:13 +03:00
Kirill Tkhai
919df37c25 bits: Add test_and_set_bit()
Borrowed from Linux Kernel

v5: New

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-06 14:09:13 +03:00
Kirill Tkhai
06552fa3a2 locks: Mask futexes aligned
System call sys_futex() requires that (from futex(2)):

    "On all platforms, futexes are four-byte integers
     that must be aligned on a four-byte boundary".

travis-ci: success for locks: Mask futexes aligned
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-06 13:48:49 +03:00
Cyrill Gorcunov
6a0ed5e128 common: lock -- Sync function proto with syscalls
They are the same in meaning and may collide on building.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2017-02-06 13:48:49 +03:00
Cyrill Gorcunov
d82b621f97 headers: Move lock.h into include/common/
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2017-02-06 13:48:47 +03:00
Andrei Vagin
a6ae38f71b util: zero msghdr structures
musl-libc fixed inconsistency between posix and kernl msghdr structures
by adding pad-s.

It initializes all pad-s before calling recvmsg and sendmsg syscalls.
CRIU calls raw system calls from pie code, so we need to intialize pads too.

In addition, we don't initialize msg_flags and iov_len.

https://github.com/xemul/criu/issues/276

https://travis-ci.org/kolyshkin/criu/builds/198415449
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-06 13:29:55 +03:00
Kir Kolyshkin
0367a1f6fe Drop prefix from own memcpy/memset/memcmp
C compiler might generate calls to memcpy, memset, memcmp, and memmove
as it seem fit (so far we haven't seen memmove being required). That
means we need to provide our own versions of it for code which is not
linked to a libc.

We already have a solution for that in commit bdf6051
("pie: provide memcpy/memcmp/memset for noglibc case")
but we faced another problem of compiler trying to optimize
our builtin_memset() by inserting calls to memset() which
is just an alias in our case and so it lead to infinite recursion.
This was workarounded in commit 8ea0ba7 ("string.h: fix memset
over-optimization with clang") but it's not clear that was a proper
fix.

This patch is considered to be the real solution. As we don't have
any other implementations of memset/memcpy/memcmp in non-libc case,
we can call ours without any prefixes and avoid using weak aliases.

Implementation notes:

1. mem*() functions code had to be moved from .h to .c for the functions
to be compatible with their prototypes declared in /usr/include/string.h
(i.e. "extern").

2. FORTIFY_SOURCE needed to be disabled for code not linked to libc,
because otherwise memcpy() may be replaced with a macro that expands
to __memcpy_chk() which of course can't be resolved during linking.

https://travis-ci.org/kolyshkin/criu/builds/198415449
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-06 13:29:54 +03:00
Kirill Tkhai
d3ea14a125 scm: Allow to pass flags argument to recv_fds()
This will be used to pass MSG_DONTWAIT in next patch.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-03 18:04:22 +03:00
Kirill Tkhai
6a3cfcd550 scm: Return sensible error codes in recv_fds()
Replace "-1" return with errno codes.

ENOMSG and EBADFD were choosen to do not cross with
standard recvmsg() errors (described in its man page).

This patch is need as preparation to making recv_msg()
be able to be non-block, and return EAGAIN and EWOULDBLOCK
in case of no data.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-03 18:04:22 +03:00
Pavel Emelyanov
60738eaa78 files: Rework send/recv-fds to be more generic
Remove getting opts from descriptors out from scm engine,
this stuff is pure criu thing, so make it collect the data.

The tricky change here is that parasite code needs memory
to keep fd_opts on. The memory is taken from parasite args
region, which is now bigger than it used to be. But that's
not a big deal, as previously this space was allocated on
the parasite stack (!, but with smaller chunks).

On the other hand, now we have one memcpy less, as opts are
put directly into the destination buffer.

travis-ci: success for files: Rework send/recv-fds to be more generic
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:22:19 +03:00
Cyrill Gorcunov
ed4a4b7507 scm: Unweave fds mess
Currently criu built with criu/pie-util-fd (which
is a symlink to criu/pie/util-fd) with same flags
as we use in general compel infection code. Moreover
the criu link with libcompel.a, so we get a problem
where send_fds/recv_fds are multiple defined. Lets
rather unweave this mess:

 - drop criu/pie-util-fd.c completely
 - move send_fd/recv_fd inliners into scm.h

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:22:19 +03:00
Cyrill Gorcunov
3c98261730 compel: plugins,fds -- Unify prototypes
- Declare send_fds, recv_fds in sch.h, these
   are prototypes used in both compel and criu
 - Drop old protos from plugin-fds.h uapi file
 - Drop old code from fds.c source

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:11:58 +03:00
Cyrill Gorcunov
a1f674e34b scm: common -- Hide struct fd_opts argument
When SCM_FDSET_HAS_OPTS is not set the scm-code.c
can't be built because it declares struct fd_opts
in parameters. Lets rather hide this type and
allow to build without SCM_FDSET_HAS_OPTS definition.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:07:50 +03:00
Cyrill Gorcunov
187377a526 scm: scm_fdset_init -- Drop unused @with_flags argument
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:07:41 +03:00
Pavel Emelyanov
165203b3c6 scm: Move scm_fdset structure into include/common
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:07:26 +03:00
Pavel Emelyanov
7279c0e7b4 scm: Compile out opts management
In pure-compel library messing with opts is not required,
only criu and criu's pie will need it, so make it possible
to compile out common/scm-code's opts management.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:07:15 +03:00
Pavel Emelyanov
bc102ea1bf scm: Define __memcpy
Depending on the code using it, memcpy will be different.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:07:06 +03:00
Pavel Emelyanov
554d0f0ab4 scm: Move fd-sending core code AS IS into include/common/
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-12 16:06:50 +03:00
Cyrill Gorcunov
b89ee40bc4 headers: Switch to common linkage.h
travis-ci: success for headers: Switch to common linkage.h
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-21 23:15:19 +03:00
Kirill Tkhai
97a4d49376 arm, aarm64: Add atomic_dec_return()
travis-ci: success for series starting with [1/2] ppc: Add atomic_dec_return()
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-12 11:05:59 +03:00
Kirill Tkhai
994d9d4ea6 ppc: Add atomic_dec_return()
Borrowed from Linux kernel.

travis-ci: success for series starting with [1/2] ppc: Add atomic_dec_return()
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-12 11:05:59 +03:00
Kir Kolyshkin
70e3b465e8 arm: rm -Wa from CFLAGS
Somehow clang doesn't always like -Wa flags, for example when making
dependencies (see commit 9303ed3 ("Makefiles: move -Wa,--noexecstack
out of CFLAGS"), which causes build break, scary error messages, and
even hair loss.

There are many ways to solve this. This patch employs the one
that is simple and clean.

The -Wa,-mimplicit-it=always flag was added by commit 79c4b74
("arm: fix compilation on ARMv7"). The reason is, ARM needs an IT
instruction before certain conditionals. Those IT instructions are
almost always automatically generated by assembler itself, but in some
cases a special assembler flag (like the one above) is needed.

As there is only one place in the code that need IT, it's easy to patch
it (add explicit IT) and remove the flag. Note that "IT" generates
no machine code per se, so there should not be any functional change
(although I haven't checked it).

For more info on IT, see http://tinyurl.com/z3ldsdr

Hope for a review from our ARM experts.

travis-ci: success for Fixes to compile on arm with clang
Cc: Christopher Covington <cov@codeaurora.org>
Cc: Dmitry Safonov <dsafonov@virtuozzo.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-12 11:04:38 +03:00
Kir Kolyshkin
19f7f130ae ppc asm/bitops.h: fix for clang
clang-3.8 fails to compile inline asm having ldarx with 4 args.

Quoting [1]:
'''
Recent versions of the PowerPC architecture added a hint bit to the larx
instructions to differentiate between an atomic operation and a lock
operation:

> 0 Other programs might attempt to modify the word in storage addressed by EA
> even if the subsequent Store Conditional succeeds.
>
> 1 Other programs will not attempt to modify the word in storage addressed by
> EA until the program that has acquired the lock performs a subsequent
> store releasing the lock.
'''

I also found some more info about this in [2].

Anyway, we could either construct some preprocessor logic to omit this
argument for clang, or just drop it. This patch does the latter.

[1] https://patchwork.ozlabs.org/patch/45008/
[2] https://sourceware.org/ml/libc-alpha/2015-03/msg00085.html

travis-ci: success for PPC+clang compile fixes
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 01:32:55 +03:00
Pavel Emelyanov
41aa20ab7e headers: Move xmalloc to common
travis-ci: success for headers: Finalize include/common/
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Pavel Emelyanov
d65e4cf9a8 headers: Move err.h to common
travis-ci: success for headers: Finalize include/common/
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Pavel Emelyanov
eedb53a1d2 headers: Fix iquote for include/common
travis-ci: success for headers: Finalize include/common/
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
c50ea54853 common: bitsperlong -- Specify complete path
travis-ci: success for common: bitsperlong -- Specify complete path
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
e216512e6a common: Use complete path in inclusion
Subprojects usually have own "asm" directory,
so to eliminate collision specify complete path.

travis-ci: success for common: Use complete path in inclusion
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
ab4a1bae1f common: Move page.h in
travis-ci: success for Common headers
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
49883d681f common: Move in bit operation helpers
travis-ci: success for Common headers
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
4485723f80 common: Move atomic.h in
Since in criu we can't choose proper
arch inside include statements (well,
it will simply require more ifdefs),
I generate include/common/asm symlink
to point proper architecture.

travis-ci: success for Common headers
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
8fa72cf711 common: Move processor.h in
travis-ci: success for Common headers
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
263061d923 common: Move cmpxchng.h in
travis-ci: success for Common headers
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:04 +03:00
Cyrill Gorcunov
3564a4d0ed include/common: Move bug.h in
travis-ci: success for Common headers
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:03 +03:00
Cyrill Gorcunov
9e2c8fae92 common: Move compiler.h into
travis-ci: success for Common headers
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-03 00:13:03 +03:00
Cyrill Gorcunov
912cc2d16f Add directory for common headers
The idea is to have one place for headers which
are shared between subprojects (zdtm, criu, compel).

travis-ci: success for Add directory for common headers (rev3)
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-10-24 16:00:15 +03:00