[PATCH RFC v3 25/90] cells: add cell_kill()
From: Josef Bacik
Date: Thu Nov 05 2026 - 11:33:38 EST
cell_kill() kills a cell and everything in it, in whatever state the cell
is. A cell that has not run anything yet is torn down immediately.
Otherwise every task in the budget is killed, and the teardown happens
when the init of the cell exits. cell_kill() does not wait for that. The
cellfd becomes readable once the cell is dead.
This is a separate system call rather than a command of cell_configure(),
which only applies to a cell that is being built. It also means that a
seccomp filter can allow or deny killing by system call number, the same
way cell_info() separates looking from changing.
Holding the cellfd is the only requirement.
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
---
kernel/cell/core.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/kernel/cell/core.c b/kernel/cell/core.c
index d0243779af19..b9494b5fd7b9 100644
--- a/kernel/cell/core.c
+++ b/kernel/cell/core.c
@@ -310,3 +310,31 @@ SYSCALL_DEFINE2(cell_create, int, parent, unsigned int, flags)
cell_put(cell);
return ret;
}
+
+/**
+ * sys_cell_kill - kill a cell and everything in it
+ * @cfd: the cell, in whatever state
+ * @flags: none yet, must be 0
+ *
+ * Kills every task in the budget. A cell that has run nothing yet is torn down
+ * on the spot. For one that has, that is for the exit of its init to set off, so
+ * this does not wait: the cellfd polls readable once the cell is dead. Killing a
+ * cell that is dying or dead already changes nothing.
+ *
+ * Return: 0, -EINVAL for a flag or a file that is no cellfd, -EBADF.
+ */
+SYSCALL_DEFINE2(cell_kill, int, cfd, unsigned int, flags)
+{
+ struct cell *cell;
+
+ if (flags)
+ return -EINVAL;
+
+ CLASS(fd, f)(cfd);
+ cell = cell_from_fd(&f);
+ if (IS_ERR(cell))
+ return PTR_ERR(cell);
+
+ cell_kill(cell);
+ return 0;
+}
--
2.55.0