Commit bfe3911a authored by Chris Wilson's avatar Chris Wilson Committed by Daniel Vetter

kcmp: Support selection of SYS_kcmp without CHECKPOINT_RESTORE

Userspace has discovered the functionality offered by SYS_kcmp and has
started to depend upon it. In particular, Mesa uses SYS_kcmp for
os_same_file_description() in order to identify when two fd (e.g. device
or dmabuf) point to the same struct file. Since they depend on it for
core functionality, lift SYS_kcmp out of the non-default
CONFIG_CHECKPOINT_RESTORE into the selectable syscall category.

Rasmus Villemoes also pointed out that systemd uses SYS_kcmp to
deduplicate the per-service file descriptor store.

Note that some distributions such as Ubuntu are already enabling
CHECKPOINT_RESTORE in their configs and so, by extension, SYS_kcmp.

References: https://gitlab.freedesktop.org/drm/intel/-/issues/3046Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Will Drewry <wad@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Dave Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: stable@vger.kernel.org
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> # DRM depends on kcmp
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> # systemd uses kcmp
Reviewed-by: default avatarCyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Acked-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210205220012.1983-1-chris@chris-wilson.co.uk
parent f40ddce8
...@@ -15,6 +15,9 @@ menuconfig DRM ...@@ -15,6 +15,9 @@ menuconfig DRM
select I2C_ALGOBIT select I2C_ALGOBIT
select DMA_SHARED_BUFFER select DMA_SHARED_BUFFER
select SYNC_FILE select SYNC_FILE
# gallium uses SYS_kcmp for os_same_file_description() to de-duplicate
# device and dmabuf fd. Let's make sure that is available for our userspace.
select KCMP
help help
Kernel-level support for the Direct Rendering Infrastructure (DRI) Kernel-level support for the Direct Rendering Infrastructure (DRI)
introduced in XFree86 4.0. If you say Y here, you need to select introduced in XFree86 4.0. If you say Y here, you need to select
......
...@@ -979,7 +979,7 @@ static struct epitem *ep_find(struct eventpoll *ep, struct file *file, int fd) ...@@ -979,7 +979,7 @@ static struct epitem *ep_find(struct eventpoll *ep, struct file *file, int fd)
return epir; return epir;
} }
#ifdef CONFIG_CHECKPOINT_RESTORE #ifdef CONFIG_KCMP
static struct epitem *ep_find_tfd(struct eventpoll *ep, int tfd, unsigned long toff) static struct epitem *ep_find_tfd(struct eventpoll *ep, int tfd, unsigned long toff)
{ {
struct rb_node *rbp; struct rb_node *rbp;
...@@ -1021,7 +1021,7 @@ struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, ...@@ -1021,7 +1021,7 @@ struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd,
return file_raw; return file_raw;
} }
#endif /* CONFIG_CHECKPOINT_RESTORE */ #endif /* CONFIG_KCMP */
/** /**
* Adds a new entry to the tail of the list in a lockless way, i.e. * Adds a new entry to the tail of the list in a lockless way, i.e.
......
...@@ -18,7 +18,7 @@ struct file; ...@@ -18,7 +18,7 @@ struct file;
#ifdef CONFIG_EPOLL #ifdef CONFIG_EPOLL
#ifdef CONFIG_CHECKPOINT_RESTORE #ifdef CONFIG_KCMP
struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long toff); struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long toff);
#endif #endif
......
...@@ -1193,6 +1193,7 @@ endif # NAMESPACES ...@@ -1193,6 +1193,7 @@ endif # NAMESPACES
config CHECKPOINT_RESTORE config CHECKPOINT_RESTORE
bool "Checkpoint/restore support" bool "Checkpoint/restore support"
select PROC_CHILDREN select PROC_CHILDREN
select KCMP
default n default n
help help
Enables additional kernel features in a sake of checkpoint/restore. Enables additional kernel features in a sake of checkpoint/restore.
...@@ -1736,6 +1737,16 @@ config ARCH_HAS_MEMBARRIER_CALLBACKS ...@@ -1736,6 +1737,16 @@ config ARCH_HAS_MEMBARRIER_CALLBACKS
config ARCH_HAS_MEMBARRIER_SYNC_CORE config ARCH_HAS_MEMBARRIER_SYNC_CORE
bool bool
config KCMP
bool "Enable kcmp() system call" if EXPERT
help
Enable the kernel resource comparison system call. It provides
user-space with the ability to compare two processes to see if they
share a common resource, such as a file descriptor or even virtual
memory space.
If unsure, say N.
config RSEQ config RSEQ
bool "Enable rseq() system call" if EXPERT bool "Enable rseq() system call" if EXPERT
default y default y
......
...@@ -51,7 +51,7 @@ obj-y += livepatch/ ...@@ -51,7 +51,7 @@ obj-y += livepatch/
obj-y += dma/ obj-y += dma/
obj-y += entry/ obj-y += entry/
obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o obj-$(CONFIG_KCMP) += kcmp.o
obj-$(CONFIG_FREEZER) += freezer.o obj-$(CONFIG_FREEZER) += freezer.o
obj-$(CONFIG_PROFILING) += profile.o obj-$(CONFIG_PROFILING) += profile.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_STACKTRACE) += stacktrace.o
......
...@@ -315,7 +315,7 @@ TEST(kcmp) ...@@ -315,7 +315,7 @@ TEST(kcmp)
ret = __filecmp(getpid(), getpid(), 1, 1); ret = __filecmp(getpid(), getpid(), 1, 1);
EXPECT_EQ(ret, 0); EXPECT_EQ(ret, 0);
if (ret != 0 && errno == ENOSYS) if (ret != 0 && errno == ENOSYS)
SKIP(return, "Kernel does not support kcmp() (missing CONFIG_CHECKPOINT_RESTORE?)"); SKIP(return, "Kernel does not support kcmp() (missing CONFIG_KCMP?)");
} }
TEST(mode_strict_support) TEST(mode_strict_support)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment