From patchwork Mon Dec 9 23:43:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900502 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8706C19CC33 for ; Mon, 9 Dec 2024 23:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787815; cv=none; b=mhWd3MnIJVR3++2OcgbBNBwtUZkbCdaGC5UkiExUsIwsQNlrEtRK2J/sK46/e4UepRNtJbYN51rGvWd9DwiPbF6gXPsWV2X3BQ3O/2X87AzRUqTIJ5iNh3AaoFassz4jI3J7Zf1Cg7fPoSaCcN6IS4W29X5x6bGR9l5Cz4iYHZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787815; c=relaxed/simple; bh=kRDBxwz+6YveQEeqSLq+C9Fv2dd2d16OGfWYfGvoqDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S2KmSgrjUmGOV7uRMu1HjvQH0HgzGJknQFGExKelPv5O9SF66bC0ql5R/Vpk7fJ6Fa6LIWLDaSJcrgA0GrPwOKD0z2uXO/5szltIsTgbdAZkp4dBcgAcctuXRWIFa1+ERcOg87/VmHkr/KOBF2Z3fi+//8cWyheUirv8P3dG3UA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=bWkOht73; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=zejb8964; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=bWkOht73; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=zejb8964; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="bWkOht73"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="zejb8964"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="bWkOht73"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="zejb8964" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CA8FC1F44F; Mon, 9 Dec 2024 23:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787811; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=25eEZurrVZ82xZwHvea2HsSxglpjw6qEO7CU7KTegLE=; b=bWkOht7338fwZ+jZAaBq8gs4f1qRr+d9BFYy1hrCVhLoy0KAwFm7JwfQOyFyBDsqF2pRmM N/YwNWAXhL9jfBKko6jrIBI2jRo8GU2z31JANIt+k0dI4OzOp8Plq8z4hL59Shm2xq7LSh mausjP3NmXBhC3K2LZvjHUK4rgE5qnA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787811; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=25eEZurrVZ82xZwHvea2HsSxglpjw6qEO7CU7KTegLE=; b=zejb89647WRMFLdnkCOkuOipozmA9Taow1sXeQVq8oG3chRLf3/cMdC658r6Ny8fausOId YLfxAjtzzpJA6sBg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787811; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=25eEZurrVZ82xZwHvea2HsSxglpjw6qEO7CU7KTegLE=; b=bWkOht7338fwZ+jZAaBq8gs4f1qRr+d9BFYy1hrCVhLoy0KAwFm7JwfQOyFyBDsqF2pRmM N/YwNWAXhL9jfBKko6jrIBI2jRo8GU2z31JANIt+k0dI4OzOp8Plq8z4hL59Shm2xq7LSh mausjP3NmXBhC3K2LZvjHUK4rgE5qnA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787811; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=25eEZurrVZ82xZwHvea2HsSxglpjw6qEO7CU7KTegLE=; b=zejb89647WRMFLdnkCOkuOipozmA9Taow1sXeQVq8oG3chRLf3/cMdC658r6Ny8fausOId YLfxAjtzzpJA6sBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8E17D138A5; Mon, 9 Dec 2024 23:43:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id XVVnFqOAV2fsHAAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:31 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 1/9] io_uring: Drop __io_req_find_next_prep Date: Mon, 9 Dec 2024 18:43:03 -0500 Message-ID: <20241209234316.4132786-2-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Score: -1.30 X-Spam-Flag: NO This is only used inside io_req_find_next. Inline it and drop the helper. Signed-off-by: Gabriel Krisman Bertazi --- io_uring/io_uring.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index a8cbe674e5d6..57d8947ae69e 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -989,15 +989,6 @@ __cold void io_free_req(struct io_kiocb *req) io_req_task_work_add(req); } -static void __io_req_find_next_prep(struct io_kiocb *req) -{ - struct io_ring_ctx *ctx = req->ctx; - - spin_lock(&ctx->completion_lock); - io_disarm_next(req); - spin_unlock(&ctx->completion_lock); -} - static inline struct io_kiocb *io_req_find_next(struct io_kiocb *req) { struct io_kiocb *nxt; @@ -1008,8 +999,11 @@ static inline struct io_kiocb *io_req_find_next(struct io_kiocb *req) * dependencies to the next request. In case of failure, fail the rest * of the chain. */ - if (unlikely(req->flags & IO_DISARM_MASK)) - __io_req_find_next_prep(req); + if (unlikely(req->flags & IO_DISARM_MASK)) { + spin_lock(&req->ctx->completion_lock); + io_disarm_next(req); + spin_unlock(&req->ctx->completion_lock); + } nxt = req->link; req->link = NULL; return nxt; From patchwork Mon Dec 9 23:43:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900503 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D96C82248AF for ; Mon, 9 Dec 2024 23:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787817; cv=none; b=Bm/+T8OSD3otW5UxoLVn+k44jtNHg3oS++/6JbZ7f5PzhHx6gebvrgN+j3hJNUe9RbsPzfDoA7DQIsRMppOR0IMAVNscQ+DrKEkanRuTaXBeobZddhyQjHHkaarfQLHRSJvceIZLxB1p2b8Aym1SrK7rdE1A0ZSxWkzvtyFCWL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787817; c=relaxed/simple; bh=+gJ3v1ULc7lVJuiS1T1ZgjOtqR4/tpvamuoXJw59FiY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XbpeLOVF/ouIHM3abJuwEZ5m5af4F8CGBG1yobS1TOxA47FiU3qmGBd4vpV7WIMr2wumqBKHWaAq/iUbRV6LRiK0BSoaHU6Jp+6T8dn/l7KflDHBPG03iSFit646Z7HwlTw/OZz78uyIokSAyae8tkLU2pWT60fosSAaEcJ2Aag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=O272HWtu; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=9l5EfZRl; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=O272HWtu; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=9l5EfZRl; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="O272HWtu"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="9l5EfZRl"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="O272HWtu"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="9l5EfZRl" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 105011F451; Mon, 9 Dec 2024 23:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X9CA77SOuPnWZ3xnV7R7T3AEVu338QN1dDtteijQVt4=; b=O272HWtuGRilkDveaQIB+o65z8XeRzGMBvg7d7BApUhfWk37BSUJm/DlPQaCKfC3U0kkCh dGKMuEsGeAksBXzqurV89r2Jfcml8cl9WnooaW49QpPudixqy6pjY2227lfbi0NPodmX2S sFELe8VD/W+5nzHAZlzSieQAY4YqT/I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X9CA77SOuPnWZ3xnV7R7T3AEVu338QN1dDtteijQVt4=; b=9l5EfZRlSwhccLPyziiTG1SYYg9XPoVx5n9GAKsXdT0V+Y3vlHbIEox3o9SXrUFTZsxeX6 OnRUhq5d3wUMkLAA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=O272HWtu; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9l5EfZRl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X9CA77SOuPnWZ3xnV7R7T3AEVu338QN1dDtteijQVt4=; b=O272HWtuGRilkDveaQIB+o65z8XeRzGMBvg7d7BApUhfWk37BSUJm/DlPQaCKfC3U0kkCh dGKMuEsGeAksBXzqurV89r2Jfcml8cl9WnooaW49QpPudixqy6pjY2227lfbi0NPodmX2S sFELe8VD/W+5nzHAZlzSieQAY4YqT/I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X9CA77SOuPnWZ3xnV7R7T3AEVu338QN1dDtteijQVt4=; b=9l5EfZRlSwhccLPyziiTG1SYYg9XPoVx5n9GAKsXdT0V+Y3vlHbIEox3o9SXrUFTZsxeX6 OnRUhq5d3wUMkLAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B2C2B138A5; Mon, 9 Dec 2024 23:43:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id lW1sH6WAV2fwHAAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:33 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 2/9] io_uring: Expose failed request helper in internal header Date: Mon, 9 Dec 2024 18:43:04 -0500 Message-ID: <20241209234316.4132786-3-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 105011F451 X-Spam-Level: X-Spamd-Result: default: False [-1.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -1.51 X-Spam-Flag: NO In preparation to calling it from the clone command, expose this helper in io_uring.h. Signed-off-by: Gabriel Krisman Bertazi --- io_uring/io_uring.c | 6 ------ io_uring/io_uring.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 57d8947ae69e..a19f72755eaa 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -224,12 +224,6 @@ bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx, return matched; } -static inline void req_fail_link_node(struct io_kiocb *req, int res) -{ - req_set_fail(req); - io_req_set_res(req, res, 0); -} - static inline void io_req_add_to_cache(struct io_kiocb *req, struct io_ring_ctx *ctx) { wq_stack_add_head(&req->comp_list, &ctx->submit_state.free_list); diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 12abee607e4a..4dd051d29cb0 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -222,6 +222,12 @@ static inline void io_req_set_res(struct io_kiocb *req, s32 res, u32 cflags) req->cqe.flags = cflags; } +static inline void req_fail_link_node(struct io_kiocb *req, int res) +{ + req_set_fail(req); + io_req_set_res(req, res, 0); +} + static inline bool req_has_async_data(struct io_kiocb *req) { return req->flags & REQ_F_ASYNC_DATA; From patchwork Mon Dec 9 23:43:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900504 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9144319CC33 for ; Mon, 9 Dec 2024 23:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787825; cv=none; b=PgHW+ylBVFUMd2UB+J/MxdMmk1IfNZwSiUsyqTikbsTHo9vn1Vi9k6OEGmdVP9lvHLvcohKbzq+cymdAiddhUv3xW/0scIK4fiXcLf/hJo/f30ckhN9RJbZufAXgLonJqlUu2KLX5MPeRdSPmNn5Ru1wJTyqrCdTyIGd+No3tuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787825; c=relaxed/simple; bh=7WiAwSMqn6f2YhAW5KClFtBpFySRM5IPd0y9KRJ+Bl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D7DQzbHaEdgvdEHY/BF9jpfOX0zvRy2k+JeEHGYU+cpuXnMozoIwqMp5H/XGtqjPpI9abg4Q5vLGyCPDEkPWCkQrvaXEt7pkf6UB0wmKuMsquo7oqHzYc7OjqM7pgOvUBe+XMN1wOxtx1RFIeb/E9/9ZyWq0LDadwj+HDpLDox4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OjxvoOXz; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=5jjwGkpz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OjxvoOXz; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=5jjwGkpz; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OjxvoOXz"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="5jjwGkpz"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OjxvoOXz"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="5jjwGkpz" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3600821167; Mon, 9 Dec 2024 23:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787816; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmwiFgfEKmj5mgLbJsV7RDzLy8r1bxL8DEoPgRwrGNM=; b=OjxvoOXzLDUjaXRza2epQx3dU6N7/BPuYYiQwVJY4Z2/tGcKqxV7K0r8CzGse6TJXAGIjk N8684bJC+71fkaAr6k+yiMn3SB5M41R2kag5vqhRo1va+jmo/qieUo+jVLEY03ESA2d4F0 crdkrjysuom2agFj5QCN66nUwBta6vE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787816; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmwiFgfEKmj5mgLbJsV7RDzLy8r1bxL8DEoPgRwrGNM=; b=5jjwGkpzuiRU7iicJ8fleqMLo47KDKBpw8LGxYovv6Mg0CIqRHf5UwfTpPtk5XmAkCVqv1 HihIXc1r8jTrbLCQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787816; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmwiFgfEKmj5mgLbJsV7RDzLy8r1bxL8DEoPgRwrGNM=; b=OjxvoOXzLDUjaXRza2epQx3dU6N7/BPuYYiQwVJY4Z2/tGcKqxV7K0r8CzGse6TJXAGIjk N8684bJC+71fkaAr6k+yiMn3SB5M41R2kag5vqhRo1va+jmo/qieUo+jVLEY03ESA2d4F0 crdkrjysuom2agFj5QCN66nUwBta6vE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787816; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmwiFgfEKmj5mgLbJsV7RDzLy8r1bxL8DEoPgRwrGNM=; b=5jjwGkpzuiRU7iicJ8fleqMLo47KDKBpw8LGxYovv6Mg0CIqRHf5UwfTpPtk5XmAkCVqv1 HihIXc1r8jTrbLCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id F1946138A5; Mon, 9 Dec 2024 23:43:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MALALqeAV2cAHQAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:35 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 3/9] kernel/fork: Don't inherit PF_USER_WORKER from parent Date: Mon, 9 Dec 2024 18:43:05 -0500 Message-ID: <20241209234316.4132786-4-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.30 / 50.00]; BAYES_HAM(-3.00)[99.99%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Score: -1.30 X-Spam-Flag: NO Clear the PF_USER_WORKER bit of new tasks, instead of inheriting it from the parent. This allows PF_USER_WORKER tasks to fork regular tasks. Signed-off-by: Gabriel Krisman Bertazi --- kernel/fork.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index 1450b461d196..56baa320a720 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2228,6 +2228,8 @@ __latent_entropy struct task_struct *copy_process( p->flags &= ~PF_KTHREAD; if (args->kthread) p->flags |= PF_KTHREAD; + + p->flags &= ~PF_USER_WORKER; if (args->user_worker) { /* * Mark us a user worker, and block any signal that isn't From patchwork Mon Dec 9 23:43:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900505 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C112F19CC33 for ; Mon, 9 Dec 2024 23:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787827; cv=none; b=GiSiGKOoVcRLdhkGlEvswMdHUv/jCIVsv6ISAWSMrrJY1KFWUbIPkXsntdf76D3Iw4BbNBGrIC8VebjkbNQSBcdh336TzxNSdaY2xJyUM3Q6HAzWnq/LITmKc1+TGYaPiJyJQwitv2q7tzWNIlIQXnsnX1EKMUAgenswtjohPYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787827; c=relaxed/simple; bh=yNCefphhrCJUgjWR1/w4gUZj4xy6wrr7e65axKubdtc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jR4lAnHUuTn4BsgJm9LZ4k7qyYrMtCISkY3/iqJt/XqQWbzyV+djw062Efuf/b7KDgVuAHQHT6X3aptvaiPokwJ0ayA5KGl0l2l6Rr/c4LKVy5aBIcIuiG2KnwCUJpChdYNROLFDvmdPnjmalDOLg5CUBt+WnVWpIlT/FlfQVmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=rpQ8OQq4; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=QPmhPkeh; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=rpQ8OQq4; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=QPmhPkeh; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="rpQ8OQq4"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="QPmhPkeh"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="rpQ8OQq4"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="QPmhPkeh" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 40AB321169; Mon, 9 Dec 2024 23:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787818; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S5NZRMfY90YeRXV2eif4+vXPKFkifHojq7doQsTfdpE=; b=rpQ8OQq4Cc3umeYJLpRc6IRcuX8sWtFckbaFRpWW7YYPwT44NUQzFXsIF2Y+iEEL2fIdn/ s75YlRypp/MtFT9+7SACeSG8nRh8rdX+n3f+8eVykk5m8B39nGj78sFnSoaSqqmPzsQYE7 Q86zELYRNlsiuTDnZrpk7shvwPfn5+U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787818; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S5NZRMfY90YeRXV2eif4+vXPKFkifHojq7doQsTfdpE=; b=QPmhPkehg6EU4A+XkcmzvxvbbR4Ot7g4vLGrDSiRz2yH83sCwuAEkqzzNlGKj/idqhQRbK 7JfonM12a+qPOyBA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787818; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S5NZRMfY90YeRXV2eif4+vXPKFkifHojq7doQsTfdpE=; b=rpQ8OQq4Cc3umeYJLpRc6IRcuX8sWtFckbaFRpWW7YYPwT44NUQzFXsIF2Y+iEEL2fIdn/ s75YlRypp/MtFT9+7SACeSG8nRh8rdX+n3f+8eVykk5m8B39nGj78sFnSoaSqqmPzsQYE7 Q86zELYRNlsiuTDnZrpk7shvwPfn5+U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787818; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S5NZRMfY90YeRXV2eif4+vXPKFkifHojq7doQsTfdpE=; b=QPmhPkehg6EU4A+XkcmzvxvbbR4Ot7g4vLGrDSiRz2yH83sCwuAEkqzzNlGKj/idqhQRbK 7JfonM12a+qPOyBA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0649E138A5; Mon, 9 Dec 2024 23:43:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id dvvCNqmAV2cHHQAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:37 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 4/9] fs/exec: Expose do_execveat symbol Date: Mon, 9 Dec 2024 18:43:06 -0500 Message-ID: <20241209234316.4132786-5-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.30 / 50.00]; BAYES_HAM(-3.00)[99.99%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Score: -1.30 X-Spam-Flag: NO In order to allow it to be called by io_uring code, expose do_execveat in the header file. Signed-off-by: Gabriel Krisman Bertazi --- fs/exec.c | 2 +- include/linux/binfmts.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index 98cb7ba9983c..1a03ae5b9941 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -2023,7 +2023,7 @@ static int do_execve(struct filename *filename, return do_execveat_common(AT_FDCWD, filename, argv, envp, 0); } -static int do_execveat(int fd, struct filename *filename, +int do_execveat(int fd, struct filename *filename, const char __user *const __user *__argv, const char __user *const __user *__envp, int flags) diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h index e6c00e860951..baec14dfb7ca 100644 --- a/include/linux/binfmts.h +++ b/include/linux/binfmts.h @@ -141,4 +141,9 @@ extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t); int kernel_execve(const char *filename, const char *const *argv, const char *const *envp); +int do_execveat(int dfd, struct filename *filename, + const char __user *const __user *__argv, + const char __user *const __user *__envp, + int flags); + #endif /* _LINUX_BINFMTS_H */ From patchwork Mon Dec 9 23:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900506 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93E26224884 for ; Mon, 9 Dec 2024 23:43:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787828; cv=none; b=J0sTDR5DruziyFoO8MERm0NsSJXau6lHv2UUm0BlXhLtD2trYAULPAJ710rOKbV1VfpM8xDf1VJH2e2050O8l+qFOrK5BVN+o2y/9UPpa0Df1DhzLHm4LGOrD4lZtTnHnZdwe7mr5harPuB/RY2PZkYTKBqZJLoTiC5U6gYJRck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787828; c=relaxed/simple; bh=1jYQPV9ra2EM/MhroklMXILykTrmQpioT10qh6BvbBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NvPZ3QOX2NnvCQej67l3y8c1/Wu5Z1CBXi5/BGSuWtLk4zZo+rnBOYZMvhp3YXroxDpuLpk7TTDkcb7qxEwpBU3L6ha9/GsRXJWZclMVkvUny/TG+O2s4i9bGK0/NG+htfDJ3CqUGVn9uY5pO8yiHN4XMrC2WV9jzDIgYOPc3dA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Mc/fg45i; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=CrGI6lmT; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Mc/fg45i; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=CrGI6lmT; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Mc/fg45i"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="CrGI6lmT"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Mc/fg45i"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="CrGI6lmT" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C88DB2116A; Mon, 9 Dec 2024 23:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4DQQpBobIu3LkkIaHLFXR6ZvazdJk388nx1TFnhoSI=; b=Mc/fg45i5II871hQDDhIyN+HCHLjh8i0hr0RGe1jYT9CPJTjOsPLT5YSNPtzDPc6mqdOOq SiMMjMIvlK4UWNF5CHNiSP7L9ZrsGtn3BcwvbiNP3bgXVX14Ol4J2p0VB+WnGULgjBH5hL xOuBX5rS8N7u4kCRc+VMjuwGaxOxsVo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4DQQpBobIu3LkkIaHLFXR6ZvazdJk388nx1TFnhoSI=; b=CrGI6lmT698Nr8yOhbaZNg5gDCigONAIPcOwbE4kTkG9UxQmwSc8gpdzz/CcOHruTSX0lq olaqv8OFU0hJLbAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4DQQpBobIu3LkkIaHLFXR6ZvazdJk388nx1TFnhoSI=; b=Mc/fg45i5II871hQDDhIyN+HCHLjh8i0hr0RGe1jYT9CPJTjOsPLT5YSNPtzDPc6mqdOOq SiMMjMIvlK4UWNF5CHNiSP7L9ZrsGtn3BcwvbiNP3bgXVX14Ol4J2p0VB+WnGULgjBH5hL xOuBX5rS8N7u4kCRc+VMjuwGaxOxsVo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4DQQpBobIu3LkkIaHLFXR6ZvazdJk388nx1TFnhoSI=; b=CrGI6lmT698Nr8yOhbaZNg5gDCigONAIPcOwbE4kTkG9UxQmwSc8gpdzz/CcOHruTSX0lq olaqv8OFU0hJLbAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 786B3138A5; Mon, 9 Dec 2024 23:43:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qLsSEbCAV2cNHQAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:44 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 5/9] kernel/fork: Add helper to fork from io_uring Date: Mon, 9 Dec 2024 18:43:07 -0500 Message-ID: <20241209234316.4132786-6-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Score: -1.30 X-Spam-Flag: NO From: Josh Triplett Introduce a helper to fork a new process from io_uring. This is different from the io_uring io_worker in multiple ways: First, it can return to userspace following a execve, doesn't have PF_USER_WORKER set, and doesn't share most process structures with the the parent. It shares the MM though, allowing the helper to do limited io_uring operations. The sole use of this is the io_uring OP_CLONE command, which prepares the ground for EXECVE from io_uring. Signed-off-by: Josh Triplett Co-developed-by: Gabriel Krisman Bertazi Signed-off-by: Gabriel Krisman Bertazi --- include/linux/sched/task.h | 1 + kernel/fork.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 0f2aeb37bbb0..a76f05a886ad 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -98,6 +98,7 @@ extern pid_t kernel_clone(struct kernel_clone_args *kargs); struct task_struct *copy_process(struct pid *pid, int trace, int node, struct kernel_clone_args *args); struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node); +struct task_struct *create_io_uring_spawn_task(int (*fn)(void *), void *arg); struct task_struct *fork_idle(int); extern pid_t kernel_thread(int (*fn)(void *), void *arg, const char *name, unsigned long flags); diff --git a/kernel/fork.c b/kernel/fork.c index 56baa320a720..fa983a0614ce 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2757,6 +2757,25 @@ struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node) return copy_process(NULL, 0, node, &args); } +/* + * This is like kernel_clone(), but shaved down and tailored for io_uring_spawn. + * It returns a created task, or an error pointer. The returned task is + * inactive, and the caller must fire it up through wake_up_new_task(p). + */ +struct task_struct *create_io_uring_spawn_task(int (*fn)(void *), void *arg) +{ + unsigned long flags = CLONE_CLEAR_SIGHAND; + struct kernel_clone_args args = { + .flags = ((lower_32_bits(flags) | CLONE_VM | + CLONE_UNTRACED) & ~CSIGNAL), + .exit_signal = (lower_32_bits(flags) & CSIGNAL), + .fn = fn, + .fn_arg = arg, + }; + + return copy_process(NULL, 0, NUMA_NO_NODE, &args); +} + /* * Ok, this is the main fork-routine. * From patchwork Mon Dec 9 23:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900507 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 974582248A8 for ; Mon, 9 Dec 2024 23:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787830; cv=none; b=EVuTqfLxh3DvmU5YFUGhhzejFsMRbuLDGfudWk5FE+cS21NOjnfC92QLX7ZObO0G3YpYJG5Vg/zcQNrSJr33LeTaDjKgyDojHASfu7L5fHpTjn6V6cuhFkzypWdFtb9MDrMsrPAZkBnQnRyO81/yv4RXT8dwskAeOvlOrJjLEMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787830; c=relaxed/simple; bh=ChCq7AgI1WmET1HKvBX+pXk5Z39d7W+i+jnobySWB1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nSUldL/vqOUVJfw9qtjgwuK7+vypDQBFtF4M5mOBPy61TMTblocDVlrr/dfxr0sxxo+FhN2hEkF+7oVx7mQwjrAizyF1iahuHKLFFXtOzm/Fo2cxlPvIXqcEengaKrbUf5iqfzKRYeoMcnsNZ9iedNySSCaoFzDNPTSsKvgAyRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=mdHnYImS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=0ogimlF/; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=mdHnYImS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=0ogimlF/; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mdHnYImS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0ogimlF/"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mdHnYImS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0ogimlF/" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B14F421167; Mon, 9 Dec 2024 23:43:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787826; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P5jtNFPHgv7pxQLtSwya0fKmdBGWs4Xejv9/SA4pnDQ=; b=mdHnYImS/GuTSskplHqilg6xlQ1uw/lNw6oX+rtVXFe8cnUjAgV5tk16nKfk318pV9KgsS lhalKKXaRPNu0ajWmeaBXh8LCZ0hJ/lYVmVxuK4mmXJgwFQhyippKYn2qS4xNdbsrQutqN 0zb9qHB7aWXeTDwiJ1r5KJJEzDFtE0w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787826; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P5jtNFPHgv7pxQLtSwya0fKmdBGWs4Xejv9/SA4pnDQ=; b=0ogimlF/ORVdV/I4jc3Zx+kiEDd11YOODVPrptUR3OgR5r+n/9jFbPqqZqi0H5FZBLyCx2 WHiDdLFyqxIzn6Bw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=mdHnYImS; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="0ogimlF/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787826; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P5jtNFPHgv7pxQLtSwya0fKmdBGWs4Xejv9/SA4pnDQ=; b=mdHnYImS/GuTSskplHqilg6xlQ1uw/lNw6oX+rtVXFe8cnUjAgV5tk16nKfk318pV9KgsS lhalKKXaRPNu0ajWmeaBXh8LCZ0hJ/lYVmVxuK4mmXJgwFQhyippKYn2qS4xNdbsrQutqN 0zb9qHB7aWXeTDwiJ1r5KJJEzDFtE0w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787826; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P5jtNFPHgv7pxQLtSwya0fKmdBGWs4Xejv9/SA4pnDQ=; b=0ogimlF/ORVdV/I4jc3Zx+kiEDd11YOODVPrptUR3OgR5r+n/9jFbPqqZqi0H5FZBLyCx2 WHiDdLFyqxIzn6Bw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6B9B9138A5; Mon, 9 Dec 2024 23:43:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id OpYMDbKAV2cRHQAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:46 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 6/9] io_uring: Let commands run with current credentials Date: Mon, 9 Dec 2024 18:43:08 -0500 Message-ID: <20241209234316.4132786-7-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: B14F421167 X-Spam-Level: X-Spamd-Result: default: False [-1.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -1.51 X-Spam-Flag: NO IORING_OP_EXEC runs only from a custom handler and cannot rely on overloaded credentials. This commit adds infrastructure to allow running operations without overloading the credentials, i.e. not enabling the REQ_F_CREDS flag. Signed-off-by: Gabriel Krisman Bertazi --- io_uring/io_uring.c | 2 +- io_uring/opdef.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index a19f72755eaa..0fd8709401fc 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -457,7 +457,7 @@ static void io_prep_async_work(struct io_kiocb *req) const struct io_issue_def *def = &io_issue_defs[req->opcode]; struct io_ring_ctx *ctx = req->ctx; - if (!(req->flags & REQ_F_CREDS)) { + if (!(req->flags & REQ_F_CREDS) && !def->ignore_creds) { req->flags |= REQ_F_CREDS; req->creds = get_current_cred(); } diff --git a/io_uring/opdef.h b/io_uring/opdef.h index 14456436ff74..94e9a2e3c028 100644 --- a/io_uring/opdef.h +++ b/io_uring/opdef.h @@ -27,6 +27,8 @@ struct io_issue_def { unsigned iopoll_queue : 1; /* vectored opcode, set if 1) vectored, and 2) handler needs to know */ unsigned vectored : 1; + /* io_uring must not overload credentials on async context. */ + unsigned ignore_creds : 1; /* size of async data needed, if any */ unsigned short async_size; From patchwork Mon Dec 9 23:43:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900508 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8899A2248A3 for ; Mon, 9 Dec 2024 23:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787832; cv=none; b=XR2vwBnz03EzZbIC28B9myLPJ4espsPNa+K9JC9EJ4aVgezfuXqgqtDMMFthR1Hv0BuxxMWeS4f5RCxJ/9yy2cfsmBtuBBOrl9e8efqBxK0qf98x/kct6wri8LN57sg2ErIcnxNu+X5EVTouq+YCjB4GjIc9PQkjXElMQXXf5Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787832; c=relaxed/simple; bh=loAJJs7OumA/oMAvExcGKHWEbIpOm898MnZK9JnOI9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eJInnLfJFRhfDpSeulDVh8D+0pz2DHPimlCQXjvIZi8iu+WLt+PaRu3+haZyttbctxlnh72YQujxxuSOPXWOHrkPGqFM62E2qWkS6+EWZMPpBVUGQNEbPOuUPhCepuCnTX7pZ4mATPcOnzUFKA6XvkAxS5WrLcYk2J5lZUHP2zU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=WC5PNoyc; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ggxi3pgX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=WC5PNoyc; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ggxi3pgX; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WC5PNoyc"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ggxi3pgX"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WC5PNoyc"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ggxi3pgX" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CB38321169; Mon, 9 Dec 2024 23:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787828; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cvMPdj61XsjV2PYeWyD9EAQyCRDLmYOY/LtbA4cB5o=; b=WC5PNoyc4cSWz011qHysQ3wgrJw99tvQU0ysVlHmP1zATLGK4JJsknrS2BjV+WZmJhee1R M3ZRxjTO0zOt+niyvmxJgg398ZZOGBQ+zyoB/gtULXP6GCkSLDjYYeDFnUufhzyuk28Q9z XSYTHIAISDKhPLnxHm7O6fj+ATiXmP8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787828; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cvMPdj61XsjV2PYeWyD9EAQyCRDLmYOY/LtbA4cB5o=; b=ggxi3pgXFECOYdKwR9CXe/tcVecO7uc84yO4QDROZf83mToKVyhs4HUCBvF6XKM5YtSgJu yLNTLxaWVbiBA+CQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787828; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cvMPdj61XsjV2PYeWyD9EAQyCRDLmYOY/LtbA4cB5o=; b=WC5PNoyc4cSWz011qHysQ3wgrJw99tvQU0ysVlHmP1zATLGK4JJsknrS2BjV+WZmJhee1R M3ZRxjTO0zOt+niyvmxJgg398ZZOGBQ+zyoB/gtULXP6GCkSLDjYYeDFnUufhzyuk28Q9z XSYTHIAISDKhPLnxHm7O6fj+ATiXmP8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787828; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cvMPdj61XsjV2PYeWyD9EAQyCRDLmYOY/LtbA4cB5o=; b=ggxi3pgXFECOYdKwR9CXe/tcVecO7uc84yO4QDROZf83mToKVyhs4HUCBvF6XKM5YtSgJu yLNTLxaWVbiBA+CQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8FC6C138A5; Mon, 9 Dec 2024 23:43:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4TUIF7SAV2cUHQAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:48 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 7/9] io_uring: Introduce IORING_OP_CLONE Date: Mon, 9 Dec 2024 18:43:09 -0500 Message-ID: <20241209234316.4132786-8-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; TAGGED_RCPT(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid] X-Spam-Score: -1.80 X-Spam-Flag: NO From: Josh Triplett This command spawns a short lived asynchronous context to execute following linked operations. Once the link is completed, the task terminates. This is specially useful to create new processes, by linking an IORING_OP_EXEC at the end of the chain. In this case, the task doesn't terminate, but returns to userspace, starting the new process. This is different from the existing io workqueues in a few ways: First, it is completely separated from the io-wq code, and the task cannot be reused by a future link; Second, the task doesn't share the FDT, and other process structures with the rest of io_uring (except for the memory map); Finally, because of the limited context, it doesn't support executing requests asynchronously and requeing them. Every request must complete at ->issue time, or fail. It also doesn't support task_work execution, for a similar reason. The goal of this design allowing the user to close file descriptors, release locks and do other cleanups right before switching to a new process. A big pitfall here, in my (Gabriel) opinion, is how this duplicates the logic of io_uring linked request dispatching. I'd suggest I merge this into the io-wq code, as a special case of workqueue. But I'd like to get feedback on this idea from the maintainers before moving further with the implementation. Signed-off-by: Josh Triplett Co-developed-by: Gabriel Krisman Bertazi Signed-off-by: Gabriel Krisman Bertazi --- include/uapi/linux/io_uring.h | 1 + io_uring/Makefile | 2 +- io_uring/io_uring.c | 3 +- io_uring/io_uring.h | 2 + io_uring/opdef.c | 9 +++ io_uring/spawn.c | 140 ++++++++++++++++++++++++++++++++++ io_uring/spawn.h | 10 +++ 7 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 io_uring/spawn.c create mode 100644 io_uring/spawn.h diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 38f0d6b10eaf..82d8dae49645 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -278,6 +278,7 @@ enum io_uring_op { IORING_OP_FTRUNCATE, IORING_OP_BIND, IORING_OP_LISTEN, + IORING_OP_CLONE, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/io_uring/Makefile b/io_uring/Makefile index 53167bef37d7..06ad15c07c57 100644 --- a/io_uring/Makefile +++ b/io_uring/Makefile @@ -12,7 +12,7 @@ obj-$(CONFIG_IO_URING) += io_uring.o opdef.o kbuf.o rsrc.o notif.o \ sqpoll.o xattr.o nop.o fs.o splice.o \ sync.o msg_ring.o advise.o openclose.o \ epoll.o statx.o timeout.o fdinfo.o \ - cancel.o waitid.o register.o \ + cancel.o waitid.o register.o spawn.o \ truncate.o memmap.o obj-$(CONFIG_IO_WQ) += io-wq.o obj-$(CONFIG_FUTEX) += futex.o diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 0fd8709401fc..b82ea1cc393f 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -97,6 +97,7 @@ #include "uring_cmd.h" #include "msg_ring.h" #include "memmap.h" +#include "spawn.h" #include "timeout.h" #include "poll.h" @@ -1706,7 +1707,7 @@ static bool io_assign_file(struct io_kiocb *req, const struct io_issue_def *def, return !!req->file; } -static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) +int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) { const struct io_issue_def *def = &io_issue_defs[req->opcode]; const struct cred *creds = NULL; diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 4dd051d29cb0..302c8f92b812 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -497,4 +497,6 @@ static inline bool io_has_work(struct io_ring_ctx *ctx) return test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq) || io_local_work_pending(ctx); } + +int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags); #endif diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 3de75eca1c92..1bab2e517e55 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -36,6 +36,7 @@ #include "waitid.h" #include "futex.h" #include "truncate.h" +#include "spawn.h" static int io_no_issue(struct io_kiocb *req, unsigned int issue_flags) { @@ -515,6 +516,11 @@ const struct io_issue_def io_issue_defs[] = { .prep = io_eopnotsupp_prep, #endif }, + [IORING_OP_CLONE] = { + .audit_skip = 1, + .prep = io_clone_prep, + .issue = io_clone, + }, }; const struct io_cold_def io_cold_defs[] = { @@ -744,6 +750,9 @@ const struct io_cold_def io_cold_defs[] = { [IORING_OP_LISTEN] = { .name = "LISTEN", }, + [IORING_OP_CLONE] = { + .name = "CLONE", + }, }; const char *io_uring_get_opcode(u8 opcode) diff --git a/io_uring/spawn.c b/io_uring/spawn.c new file mode 100644 index 000000000000..1cd069bb6f59 --- /dev/null +++ b/io_uring/spawn.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Spawning a linked series of operations onto a dedicated task. + * + * Copyright (C) 2022 Josh Triplett + */ + +#include +#include +#include + +#include "io_uring.h" +#include "rsrc.h" +#include "spawn.h" + +struct io_clone { + struct file *file_unused; + struct io_kiocb *link; +}; + +static void fail_link(struct io_kiocb *req) +{ + struct io_kiocb *nxt; + + while (req) { + req_fail_link_node(req, -ECANCELED); + io_req_complete_defer(req); + + nxt = req->link; + req->link = NULL; + req = nxt; + } +} + +static int io_uring_spawn_task(void *data) +{ + struct io_kiocb *head = data; + struct io_clone *c = io_kiocb_to_cmd(head, struct io_clone); + struct io_ring_ctx *ctx = head->ctx; + struct io_kiocb *req, *next; + int err; + + set_task_comm(current, "iou-spawn"); + + mutex_lock(&ctx->uring_lock); + + for (req = c->link; req; req = next) { + int hardlink = req->flags & REQ_F_HARDLINK; + + next = req->link; + req->link = NULL; + req->flags &= ~(REQ_F_HARDLINK | REQ_F_LINK); + + if (!(req->flags & REQ_F_FAIL)) { + err = io_issue_sqe(req, IO_URING_F_COMPLETE_DEFER); + /* + * We can't requeue a request from the spawn + * context. Fail the whole chain. + */ + if (err) { + req_fail_link_node(req, -ECANCELED); + io_req_complete_defer(req); + } + } + if (req->flags & REQ_F_FAIL) { + if (!hardlink) { + fail_link(next); + break; + } + } + } + + io_submit_flush_completions(ctx); + percpu_ref_put(&ctx->refs); + + mutex_unlock(&ctx->uring_lock); + + force_exit_sig(SIGKILL); + return 0; +} + +int io_clone_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + if (unlikely(sqe->fd || sqe->ioprio || sqe->addr2 || sqe->addr + || sqe->len || sqe->rw_flags || sqe->buf_index + || sqe->optlen || sqe->addr3)) + return -EINVAL; + + if (unlikely(!(req->flags & (REQ_F_HARDLINK|REQ_F_LINK)))) + return -EINVAL; + + if (unlikely(req->ctx->submit_state.link.head)) + return -EINVAL; + + return 0; +} + +int io_clone(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_clone *c = io_kiocb_to_cmd(req, struct io_clone); + struct task_struct *tsk; + + /* It is possible that we don't have any linked requests, depite + * checking during ->prep(). It would be harmless to continue, + * but we don't need even to create the worker thread in this + * case. + */ + if (!req->link) + return IOU_OK; + + /* + * Prevent the context from going away before the spawned task + * has had a chance to execute. Dropped by io_uring_spawn_task. + */ + percpu_ref_get(&req->ctx->refs); + + tsk = create_io_uring_spawn_task(io_uring_spawn_task, req); + if (IS_ERR(tsk)) { + percpu_ref_put(&req->ctx->refs); + + req_set_fail(req); + io_req_set_res(req, PTR_ERR(tsk), 0); + return PTR_ERR(tsk); + } + + /* + * Steal the link from the io_uring dispatcher to have them + * submitted through the new thread. Note we can no longer fail + * the clone, so the spawned task is responsible for completing + * these requests. + */ + c->link = req->link; + req->flags &= ~(REQ_F_HARDLINK | REQ_F_LINK); + req->link = NULL; + + wake_up_new_task(tsk); + + return IOU_OK; + +} diff --git a/io_uring/spawn.h b/io_uring/spawn.h new file mode 100644 index 000000000000..9b7ddb776d1e --- /dev/null +++ b/io_uring/spawn.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * Spawning a linked series of operations onto a dedicated task. + * + * Copyright © 2022 Josh Triplett + */ + +int io_clone_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); +int io_clone(struct io_kiocb *req, unsigned int issue_flags); From patchwork Mon Dec 9 23:43:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900509 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79E9619F489 for ; Mon, 9 Dec 2024 23:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787838; cv=none; b=aznx2/YPrGzVTaAIyOmkbE5XXHkyA/wQKCxxfo3AzTEZkW6uKpJCEuWzBoY3hP/xuvQHCYTT1mByB53U+1eGhNfkFZ6VzlyiW4C4WapCmqbAQFpYTAaPlaZwvLbGb89Va/ScX3v78koPwyqw+k7BLuqGDalcb79GJAR0VFBqSew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787838; c=relaxed/simple; bh=scEKmaGxi657XGNenKsYFdKGUY57N3w6Qa6m7C+H5gQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gTd03NC/VzboFS2Mq5SgpMU4MdizzOmR9bpBk90jQTIAKqBqA4OWV1BSdB9cXZkCc1IyvsFJR3nY+Z/1ViZxqEfkL1anMSHqOgmDMka9DgHLF9rVuSXP8Y5feARdF4v7Vj4P0HmAlQC/4jEXibD7QJXqK7iMxZ/2Lu1gSJgj2uY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=wGeQB70L; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jpola4jS; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=wGeQB70L; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jpola4jS; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="wGeQB70L"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jpola4jS"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="wGeQB70L"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jpola4jS" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B61291F441; Mon, 9 Dec 2024 23:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YcqAmNjyH/UH/uoc+/N1aN7cUyorhNWqXFxf2TcooWQ=; b=wGeQB70LNaEfcAzt0g3tfYP2P/IDmdNSohn22X/ThaEJ+h9eU9hrTHVkwszQxlAk+I0C1d vhHHFsPKB25cBU2P9jPIVrUQg+vgf6TG2dUx+FfKL4E0qoCNrilq1LMso2whdc+l82hYbO /IOiFV7ltQcwlsmine4NfBgODbY5OW8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YcqAmNjyH/UH/uoc+/N1aN7cUyorhNWqXFxf2TcooWQ=; b=jpola4jSFybti1MbUZgPy82FnQ7zrPmvJ6X5f6CN43UHtZGu4NK0AoeYbuYvj+dfYQU5Rt n5pGe7hH0U3B1cDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YcqAmNjyH/UH/uoc+/N1aN7cUyorhNWqXFxf2TcooWQ=; b=wGeQB70LNaEfcAzt0g3tfYP2P/IDmdNSohn22X/ThaEJ+h9eU9hrTHVkwszQxlAk+I0C1d vhHHFsPKB25cBU2P9jPIVrUQg+vgf6TG2dUx+FfKL4E0qoCNrilq1LMso2whdc+l82hYbO /IOiFV7ltQcwlsmine4NfBgODbY5OW8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YcqAmNjyH/UH/uoc+/N1aN7cUyorhNWqXFxf2TcooWQ=; b=jpola4jSFybti1MbUZgPy82FnQ7zrPmvJ6X5f6CN43UHtZGu4NK0AoeYbuYvj+dfYQU5Rt n5pGe7hH0U3B1cDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7E9F0138A5; Mon, 9 Dec 2024 23:43:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id vfUMGbqAV2cdHQAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:54 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 8/9] io_uring: Let ->issue know if it was called from spawn thread Date: Mon, 9 Dec 2024 18:43:10 -0500 Message-ID: <20241209234316.4132786-9-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -1.30 X-Spamd-Result: default: False [-1.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Level: IORING_OP_EXEC can only be called from the spawn task context. Pass that information via the issue_flags to let it be verified by the IORING_OP_EXEC handler. Signed-off-by: Gabriel Krisman Bertazi --- include/linux/io_uring_types.h | 3 +++ io_uring/spawn.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index c141ffec81fe..8717259ba715 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -38,6 +38,9 @@ enum io_uring_cmd_flags { IO_URING_F_CANCEL = (1 << 11), IO_URING_F_COMPAT = (1 << 12), IO_URING_F_TASK_DEAD = (1 << 13), + + /* Set when issuing from spawn thread */ + IO_URING_F_SPAWN = (1 << 14), }; struct io_wq_work_node { diff --git a/io_uring/spawn.c b/io_uring/spawn.c index 1cd069bb6f59..59d6ccf96f45 100644 --- a/io_uring/spawn.c +++ b/io_uring/spawn.c @@ -52,7 +52,7 @@ static int io_uring_spawn_task(void *data) req->flags &= ~(REQ_F_HARDLINK | REQ_F_LINK); if (!(req->flags & REQ_F_FAIL)) { - err = io_issue_sqe(req, IO_URING_F_COMPLETE_DEFER); + err = io_issue_sqe(req, IO_URING_F_COMPLETE_DEFER|IO_URING_F_SPAWN); /* * We can't requeue a request from the spawn * context. Fail the whole chain. From patchwork Mon Dec 9 23:43:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13900510 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70B63223C6B for ; Mon, 9 Dec 2024 23:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787840; cv=none; b=pBS6c55EVwJyDqgg3OuYF/fTlOFi5xzHPD/YsfqkVG1E7L7TADKhBTIkzAKT8ePF1VtK99vu6Q07Be/pCEuwD4a8DbQS+XrPbks417FK6SNOqrHjV7XXbD4saeatAQcOtOIMhbCan+Gi2i6FA/Mit9aGPcelRqv2Wj1zVWRJRZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733787840; c=relaxed/simple; bh=c6r6SgHO2yPFJ8di4Ia0OkS7OPY0CJmNb/LdKyabWBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gfHJamF4wfogVKb55N5PxtfZd0cW35QbybdeHudvgPUa0XgrDWdgjkFLA44jWzrxNPunRC371rna1tXptG4EwJfwxdPCeD8XalqaFkA63u3kIms7OJvX3aHdUwfg8zSTpqNRgq0LPoeM3DKFpWqtIWRd5LugkEFv5nbE8aonjPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=yhrSH15v; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+8eRL7iD; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=yhrSH15v; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+8eRL7iD; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="yhrSH15v"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+8eRL7iD"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="yhrSH15v"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+8eRL7iD" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 913C91F44F; Mon, 9 Dec 2024 23:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787836; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4vKWu3lX6cgt031RV91VF6tDX+5ssZxtk3ymo9j/qy8=; b=yhrSH15vSyS4BNQ79i5C7R4YWEF7dTHrBOCnLeXrrsDW/hmPs0YkMme6JE7BmTCKHNKNvu JG4HDZyyNB2AzP4mdtP8Zl6KFdBECOslprsj5fTncY+ma/BkzPqxNHnGOReCuq+ugoaa5Q jahT+exFJBHFwpvrMLYhuTfdx4mGHW0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787836; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4vKWu3lX6cgt031RV91VF6tDX+5ssZxtk3ymo9j/qy8=; b=+8eRL7iDKaBOHeT5KXwkD9lipFppK0L2Kwja/KUpAFebMHWGRwQ8DpQ4btlYtHuhNcF2G2 aRtEdAH94jYJ6sAw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=yhrSH15v; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=+8eRL7iD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733787836; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4vKWu3lX6cgt031RV91VF6tDX+5ssZxtk3ymo9j/qy8=; b=yhrSH15vSyS4BNQ79i5C7R4YWEF7dTHrBOCnLeXrrsDW/hmPs0YkMme6JE7BmTCKHNKNvu JG4HDZyyNB2AzP4mdtP8Zl6KFdBECOslprsj5fTncY+ma/BkzPqxNHnGOReCuq+ugoaa5Q jahT+exFJBHFwpvrMLYhuTfdx4mGHW0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733787836; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4vKWu3lX6cgt031RV91VF6tDX+5ssZxtk3ymo9j/qy8=; b=+8eRL7iDKaBOHeT5KXwkD9lipFppK0L2Kwja/KUpAFebMHWGRwQ8DpQ4btlYtHuhNcF2G2 aRtEdAH94jYJ6sAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 405F7138A5; Mon, 9 Dec 2024 23:43:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Lj96A7yAV2cgHQAAD6G6ig (envelope-from ); Mon, 09 Dec 2024 23:43:56 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, josh@joshtriplett.org, Gabriel Krisman Bertazi Subject: [PATCH RFC 9/9] io_uring: Introduce IORING_OP_EXEC command Date: Mon, 9 Dec 2024 18:43:11 -0500 Message-ID: <20241209234316.4132786-10-krisman@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209234316.4132786-1-krisman@suse.de> References: <20241209234316.4132786-1-krisman@suse.de> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 913C91F44F X-Spam-Level: X-Spamd-Result: default: False [-1.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_TO(0.00)[kernel.dk,gmail.com]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -1.51 X-Spam-Flag: NO From: Josh Triplett This command executes the equivalent of an execveat(2) in a previously spawned io_uring context, causing the execution to return to a new program indicated by the SQE. As an io_uring command, it is special in a few ways, requiring some quirks. First, it can only be executed from the spawned context linked after the IORING_OP_CLONE command; In addition, the first successful IORING_OP_EXEC command will terminate the link chain, causing further operations to fail with -ECANCELED. There are a few reason for the first limitation: First, it wouldn't make much sense to execute IORING_OP_EXEC in an io-wq, as it would simply mean "stealing" the worker thread from io_uring; It would also be questionable to execute inline or in a task work, as it would terminate the execution of the ring. Another technical reason is that we'd immediately deadlock (fixable), because we'd need to complete the command and release the reference after returning from the execve, but the context has already been invalidated by terminating the process. All in all, considering io_uring's purpose to provide an asynchronous interface, I'd (Gabriel) like to focus on the simple use-case first, limiting it to the cloned context for now. The second limitation is obvious. We reject further operations on the link after a successful exec because that is the boundary of the new program. There is a very interesting usecase that Josh mentioned for this feature. One can issue a series of hardlinked IORING_OP_EXEC using the different $PATH components to search for the binary and try them in sequence without returning to userspace. This is exemplified in the liburing testcase accompanying the patchset. Signed-off-by: Josh Triplett Co-developed-by: Gabriel Krisman Bertazi Signed-off-by: Gabriel Krisman Bertazi --- include/uapi/linux/io_uring.h | 2 ++ io_uring/opdef.c | 9 ++++++ io_uring/spawn.c | 57 ++++++++++++++++++++++++++++++++++- io_uring/spawn.h | 3 ++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 82d8dae49645..1116ff8b5018 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -73,6 +73,7 @@ struct io_uring_sqe { __u32 futex_flags; __u32 install_fd_flags; __u32 nop_flags; + __u32 execve_flags; }; __u64 user_data; /* data to be passed back at completion time */ /* pack this to avoid bogus arm OABI complaints */ @@ -279,6 +280,7 @@ enum io_uring_op { IORING_OP_BIND, IORING_OP_LISTEN, IORING_OP_CLONE, + IORING_OP_EXEC, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 1bab2e517e55..8cca077641d5 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -521,6 +521,12 @@ const struct io_issue_def io_issue_defs[] = { .prep = io_clone_prep, .issue = io_clone, }, + [IORING_OP_EXEC] = { + .audit_skip = 1, + .ignore_creds = 1, + .prep = io_exec_prep, + .issue = io_exec, + }, }; const struct io_cold_def io_cold_defs[] = { @@ -753,6 +759,9 @@ const struct io_cold_def io_cold_defs[] = { [IORING_OP_CLONE] = { .name = "CLONE", }, + [IORING_OP_EXEC] = { + .name = "EXEC", + }, }; const char *io_uring_get_opcode(u8 opcode) diff --git a/io_uring/spawn.c b/io_uring/spawn.c index 59d6ccf96f45..d6d649f78906 100644 --- a/io_uring/spawn.c +++ b/io_uring/spawn.c @@ -18,6 +18,16 @@ struct io_clone { struct io_kiocb *link; }; +struct io_exec { + struct file *file_unused; + const char __user *filename; + const char __user *const __user *argv; + const char __user *const __user *envp; + + int dfd; + u32 flags; +}; + static void fail_link(struct io_kiocb *req) { struct io_kiocb *nxt; @@ -38,6 +48,7 @@ static int io_uring_spawn_task(void *data) struct io_clone *c = io_kiocb_to_cmd(head, struct io_clone); struct io_ring_ctx *ctx = head->ctx; struct io_kiocb *req, *next; + bool return_to_user = false; int err; set_task_comm(current, "iou-spawn"); @@ -67,6 +78,15 @@ static int io_uring_spawn_task(void *data) fail_link(next); break; } + } else if (req->opcode == IORING_OP_EXEC) { + /* + * Don't execute anything after the first + * successful IORING_OP_EXEC. Cancel the rest + * of the link and allow userspace to return + */ + fail_link(next); + return_to_user = true; + break; } } @@ -75,7 +95,9 @@ static int io_uring_spawn_task(void *data) mutex_unlock(&ctx->uring_lock); - force_exit_sig(SIGKILL); + /* If there wasn't a successful exec, terminate the thread. */ + if (!return_to_user) + force_exit_sig(SIGKILL); return 0; } @@ -138,3 +160,36 @@ int io_clone(struct io_kiocb *req, unsigned int issue_flags) return IOU_OK; } + +int io_exec_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + struct io_exec *e = io_kiocb_to_cmd(req, typeof(*e)); + + if (unlikely(sqe->buf_index || sqe->len || sqe->file_index)) + return -EINVAL; + + e->dfd = READ_ONCE(sqe->fd); + e->filename = u64_to_user_ptr(READ_ONCE(sqe->addr)); + e->argv = u64_to_user_ptr(READ_ONCE(sqe->addr2)); + e->envp = u64_to_user_ptr(READ_ONCE(sqe->addr3)); + e->flags = READ_ONCE(sqe->execve_flags); + return 0; +} + +int io_exec(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_exec *e = io_kiocb_to_cmd(req, typeof(*e)); + int ret; + + if (!(issue_flags & IO_URING_F_SPAWN)) + return -EINVAL; + + ret = do_execveat(e->dfd, getname(e->filename), + e->argv, e->envp, e->flags); + if (ret < 0) { + req_set_fail(req); + io_req_set_res(req, ret, 0); + } + return IOU_OK; + +} diff --git a/io_uring/spawn.h b/io_uring/spawn.h index 9b7ddb776d1e..93d9f0ae378c 100644 --- a/io_uring/spawn.h +++ b/io_uring/spawn.h @@ -8,3 +8,6 @@ int io_clone_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); int io_clone(struct io_kiocb *req, unsigned int issue_flags); + +int io_exec_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); +int io_exec(struct io_kiocb *req, unsigned int issue_flags);