From patchwork Mon Apr 1 17:56:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13612922 Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) (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 5C28C4D5A0 for ; Mon, 1 Apr 2024 17:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994284; cv=none; b=J7CHs59ITynpOe1gwCi4ZDK6g/hkUje5Qwrkpa9JoQgX2+tFrcZqGT+gxzwWRw64RZg0Mnpn3zhymK9NIsSoZGrWwZmhH/baOkq4zmPr9yWj8lrtw7iEDw3MYcqoBRMUGj7FMuiexT5RelOq0/v6gOMq3yZzAnPN+heeG0XjJ6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994284; c=relaxed/simple; bh=0dlb5Uv64P4r6ph5NGQK7SoDKDCUoEbzqHnGGTKzLxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rp9NQGLXtHBPms/sFOvKqHODNQY3G8m3CP5tZ3/pFSso46sQba3X9g/PU/A2hYPfvBg+0Z/WRzGI2jusnwYFMZ586Sqz5A4BTEefYmEx2KGH3jUAuZxjpRhS/rWzxPlJfrxj30tLqnFdIAyixpAXyaeMNu/r3bhTRAUoOZQ/OGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=tKnu4VW4; arc=none smtp.client-ip=209.85.166.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="tKnu4VW4" Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-3688dcc5055so1652445ab.1 for ; Mon, 01 Apr 2024 10:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711994281; x=1712599081; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cp6tb70QFmVP8n5qDgYVvaom2mmSERZ5XsLDZh6LdM8=; b=tKnu4VW4HE9Or8TnWqosBgQaLU15OgW29k7w4zEZCdVouoqZTWZi3TESlU/ohdkMgS 8I4/n4vV3fRUJSfjK2Iil37tmx835sJnNpOfQD605QXkgBr598T9HRFqM8iyJ1qYJXiT M3+ae98qDABA14wp6ki6EfGcGlPFi3Zl9J9cDLzdJssaRnTQ210DbdMaqUvH9WSMYwsL 4u7RruPgl8O9aHDOW+IVPJb2eF/p10EjzmxghddZIieSgZDq10cOiby7c2+992Fhgh/o mVUe4QbIx/yAB1QYkeuxeTFZwMajpnqOO7s6/NTP8HnEJEwOSa/96WT3HppPY61V2vSy 1T0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711994281; x=1712599081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cp6tb70QFmVP8n5qDgYVvaom2mmSERZ5XsLDZh6LdM8=; b=nshhNSp6NlfckdZMP36NnIIVxtD3bK8hIg/on7grlRHzJ+jI80j3sEqk2I8yjauXcI rbehx9Id0l7hKmpYTuYRN1dNtTijjDAajbzhIjFET66ge1GbeA91tgzZq5PQBbZw7umk fSFd8VikLmN15G/AsAWCUcw9vdsvNrjuB7D5dmxYmvUBwU8ERuMlUJV1BAoLMUbEyBWk d7TMwiIlGNCq83rqmlX69i3b7ICx/2FtnvdtvOmz7jjPk5qr9GSJl/Z7xfurDW7vI5fS /02igFQCw9JS/5HDe+r1aEgjRt1yT9tlfZdLY5DDnoqS2mwzEwc1c2+kts2y4BfKAByW Rk2A== X-Gm-Message-State: AOJu0Yx3rlR/HQ5P/WxHa3fxgOSDmKUz0WZaBs6VaDYXCkrhvsG8mXVO cY2FwmViyKgzsK5MNViBXry/71xkIuPaAG0sT9PU9DuiYhUvEFNuA6dpWMSTb/fDBSS3+zzHurT j X-Google-Smtp-Source: AGHT+IFawOtf5PX3/tyg6qDQmMEG+D6uKZmOe/72Y9mQtpW7ir+qL2vcSL/7Qn/jhgJXx6cwEoHnfw== X-Received: by 2002:a05:6e02:350c:b0:365:224b:e5f7 with SMTP id bu12-20020a056e02350c00b00365224be5f7mr10762961ilb.1.1711994281077; Mon, 01 Apr 2024 10:58:01 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id ge9-20020a056638680900b0047730da740dsm2685669jab.49.2024.04.01.10.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 10:57:59 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/4] io_uring: add remote task_work execution helper Date: Mon, 1 Apr 2024 11:56:26 -0600 Message-ID: <20240401175757.1054072-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240401175757.1054072-1-axboe@kernel.dk> References: <20240401175757.1054072-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 All our task_work handling is targeted at the state in the io_kiocb itself, which is what it is being used for. However, MSG_RING rolls its own task_work handling, ignoring how that is usually done. In preparation for switching MSG_RING to be able to use the normal task_work handling, add io_req_task_work_add_remote() which allows the caller to pass in the target io_ring_ctx. Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 30 ++++++++++++++++++++++-------- io_uring/io_uring.h | 2 ++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 9986e9bb825a..df4d9c9aeeab 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1232,9 +1232,10 @@ void tctx_task_work(struct callback_head *cb) WARN_ON_ONCE(ret); } -static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags) +static inline void io_req_local_work_add(struct io_kiocb *req, + struct io_ring_ctx *ctx, + unsigned flags) { - struct io_ring_ctx *ctx = req->ctx; unsigned nr_wait, nr_tw, nr_tw_prev; struct llist_node *head; @@ -1300,9 +1301,10 @@ static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags) wake_up_state(ctx->submitter_task, TASK_INTERRUPTIBLE); } -static void io_req_normal_work_add(struct io_kiocb *req) +static void io_req_normal_work_add(struct io_kiocb *req, + struct task_struct *task) { - struct io_uring_task *tctx = req->task->io_uring; + struct io_uring_task *tctx = task->io_uring; struct io_ring_ctx *ctx = req->ctx; /* task_work already pending, we're done */ @@ -1321,7 +1323,7 @@ static void io_req_normal_work_add(struct io_kiocb *req) return; } - if (likely(!task_work_add(req->task, &tctx->task_work, ctx->notify_method))) + if (likely(!task_work_add(task, &tctx->task_work, ctx->notify_method))) return; io_fallback_tw(tctx, false); @@ -1331,10 +1333,22 @@ void __io_req_task_work_add(struct io_kiocb *req, unsigned flags) { if (req->ctx->flags & IORING_SETUP_DEFER_TASKRUN) { rcu_read_lock(); - io_req_local_work_add(req, flags); + io_req_local_work_add(req, req->ctx, flags); + rcu_read_unlock(); + } else { + io_req_normal_work_add(req, req->task); + } +} + +void io_req_task_work_add_remote(struct io_kiocb *req, struct io_ring_ctx *ctx, + unsigned flags) +{ + if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) { + rcu_read_lock(); + io_req_local_work_add(req, ctx, flags); rcu_read_unlock(); } else { - io_req_normal_work_add(req); + io_req_normal_work_add(req, READ_ONCE(ctx->submitter_task)); } } @@ -1348,7 +1362,7 @@ static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx) io_task_work.node); node = node->next; - io_req_normal_work_add(req); + io_req_normal_work_add(req, req->task); } } diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 1eb65324792a..4155379ee586 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -74,6 +74,8 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags); void __io_req_task_work_add(struct io_kiocb *req, unsigned flags); +void io_req_task_work_add_remote(struct io_kiocb *req, struct io_ring_ctx *ctx, + unsigned flags); bool io_alloc_async_data(struct io_kiocb *req); void io_req_task_queue(struct io_kiocb *req); void io_req_task_complete(struct io_kiocb *req, struct io_tw_state *ts); From patchwork Mon Apr 1 17:56:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13612923 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (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 344B91DFF4 for ; Mon, 1 Apr 2024 17:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994285; cv=none; b=o7p6Gx4dklIXxpLYVybsSlaLtEYMOuTLBG4ht5kvzaZjZV5Ph9OEJUSGss3YH07KanoyA7np6eiWdR02hcSqF8mRkqErTXgZRGZYq9n7ndR/kvDWoqrBXTu/fLmLN7afay8Df6KKCfDBnhOz3uJKKjIps9ntqoLwqh+ZVu59IsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994285; c=relaxed/simple; bh=ZOc31Chv9GMzFMptACL4IWPv63UmYAghUAlkMAAqqNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IZFQVeRkVG6uj3vfz/luohOKAUzubtp5qWdvj8bfapRehRKEXUCgYd2EWBtF2hC0JHMWJAbOkswsg5Re2EPnNCq/Wl2bU/bcEvfBSaJj8rA/IMt2/CR9ZVfNT9FHSm6kSJ2oGcN4vN3lttYGS3Pr8/CyJK+iV03KaSMiyI/TMYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=XY4Uw3ck; arc=none smtp.client-ip=209.85.166.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="XY4Uw3ck" Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-3685acaa878so6181275ab.1 for ; Mon, 01 Apr 2024 10:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711994283; x=1712599083; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D1mvpGKi0DP7HNfgie+1LU8g3Dn3YtdBR+/r1RYG5X0=; b=XY4Uw3ck45wucMSm1S05HK4Ah+XNJPMLie9ze4iaggLzfR+4mrGhmf73rrqgvzbwAe 17EEb5AOTYTFg5VY69BIhJV0e9FTN2j5x3KUjR0f6tlN0XwPahTUoCS4EuJ/4UJiFXTx ZJPc/i2LoWKpqzCsfIUncpz6APT4ZaXCm8oBh32aHLO5a8H4JsEpdLq3w6ZyRmcye+6G Y5+NEIZXFebhmLqOp1UiQ3LJ0/7nOFTFEwBEJKtc3Um8tBdwmhFT7BevuASNqLRPc1R1 2PVIEdioXTx9zL8a9REsl69zuGVs1qE1muPQYIr99KXli3H948TFSfxux4kxWAdUj6NE JmsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711994283; x=1712599083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D1mvpGKi0DP7HNfgie+1LU8g3Dn3YtdBR+/r1RYG5X0=; b=AoE+UVYGm4F1uvcymTGHW/TCLCz6P9oV+r2W+ybIqz8ySF0nckDgOpKQHscgUEOA6t 2cg3n2KY3FnQgU8Yt1e8CRhu4XdZ7rXtF/MXq2uNOxHoYRYQOVOXoXcHxlbn2ioNxL/Y fx1yvTr1mNnCd3WhlTti23YON9DybfvfrWS03A5pMW1VNFOk1IjfWhtfH7a0CI2TvOqb lJl2J6agKk8kI4HaJ/cwagejvYBSLVCT3nuympIArk5bPg6u3s//4AmV1igx4ctg3hTG zbnbk2rokcjjCcoY8Hkese7lQOG8pidizM7KB2ttv9dYlVgo6RqvtzJt+8yxsx57Tfau 6SJw== X-Gm-Message-State: AOJu0Yycxe8MzOo8jQLFgnG3w4ol2ep2Dg8CVpY/skZZmEuCWBgjmir5 1Mq0K40XHBQmQgZOnI8w1LgR2jigRmGp+V/5tNOsS/pzsItoRb2xt0dlIjxvtwFjU1nh1J6UM2B h X-Google-Smtp-Source: AGHT+IEFCf68NrzAn0Lm5+x36u49Bfjw/AX2Dh6WQLwlm7zkoAnJd2Kay/fyAtHb0qptljoo6uX8zg== X-Received: by 2002:a92:cf42:0:b0:368:a917:168f with SMTP id c2-20020a92cf42000000b00368a917168fmr9271325ilr.3.1711994282939; Mon, 01 Apr 2024 10:58:02 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id ge9-20020a056638680900b0047730da740dsm2685669jab.49.2024.04.01.10.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 10:58:01 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/4] io_uring/msg_ring: cleanup posting to IOPOLL vs !IOPOLL ring Date: Mon, 1 Apr 2024 11:56:27 -0600 Message-ID: <20240401175757.1054072-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240401175757.1054072-1-axboe@kernel.dk> References: <20240401175757.1054072-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the posting outside the checking and locking, it's cleaner that way. Signed-off-by: Jens Axboe --- io_uring/msg_ring.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index cd6dcf634ba3..d1f66a40b4b4 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -147,13 +147,11 @@ static int io_msg_ring_data(struct io_kiocb *req, unsigned int issue_flags) if (target_ctx->flags & IORING_SETUP_IOPOLL) { if (unlikely(io_double_lock_ctx(target_ctx, issue_flags))) return -EAGAIN; - if (io_post_aux_cqe(target_ctx, msg->user_data, msg->len, flags)) - ret = 0; - io_double_unlock_ctx(target_ctx); - } else { - if (io_post_aux_cqe(target_ctx, msg->user_data, msg->len, flags)) - ret = 0; } + if (io_post_aux_cqe(target_ctx, msg->user_data, msg->len, flags)) + ret = 0; + if (target_ctx->flags & IORING_SETUP_IOPOLL) + io_double_unlock_ctx(target_ctx); return ret; } From patchwork Mon Apr 1 17:56:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13612924 Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) (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 39DD91DFF4 for ; Mon, 1 Apr 2024 17:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994287; cv=none; b=b/b+YDwXdusl3E+z5942Uy1CaHjeOszN00IBC8lGRLOY2u+yzh2f034mLkIBkdz/in8/SOU2VrgBWyFy/q3ef2jhiCYxxHBK8W9rKcHglzqRivZtadMDiBPeLuCKPHHQytCSqId2n3HAbHTsJLHtmkkHjlBfnGdisG1uaieN+BA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994287; c=relaxed/simple; bh=p+by8qnt3vRwSfJkn/Rx2UAomMYo5ZJkoY72IusQtuc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hb90qq8W/pLGdM1JD6E9EaPntk5HmR6MWJt7VLtGTMTaFskIp/SateVFlPjeQIE5yGkcNxG4HZH1UX6IIyG2V45Fe7Jx8kNWKjc3PU7XR4z3fbqsyQXaalEiUn2fGe8VTMtdm2jRfQrbiyffUbINjECP+zI9+VaTPreOc5rXO88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=CLR7+q86; arc=none smtp.client-ip=209.85.166.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="CLR7+q86" Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-3688f1b7848so2659585ab.0 for ; Mon, 01 Apr 2024 10:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711994285; x=1712599085; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pxrSNfhsIJIJZKE+A4tpFbWe3kLSB5byX5X0AqK8SPI=; b=CLR7+q86o9SMrZw4QZFgo6Gc2Hh2kX0PHsgjDE3psnS7Ny3OvEmCQbzC4e0hlkXPQU OaFzeYYbTWb/YGil02OqztnjrtFo78jD6ol4Q70WGOx4mUeTi/idlxqfQvSc9wBKIIPB EptaNgn7sh58xA8WY2gAkSRo4hbmZYkJA+HRPwKKtdZC+oiv+HVBbYneF+q4BbWgg1Eg phca1HMv9yXjUiOIt6Co35ukk5aw/yDozlP0jtC7M7Qsk9aDk1fXbuMFaaZ7vN3VptcO Jhd+cz0hweqOb+QHxhOP/Req/juj+SOnKpH74wtvHRJwyB15qo3C+hAfgyZjfvdLk+Jt undg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711994285; x=1712599085; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pxrSNfhsIJIJZKE+A4tpFbWe3kLSB5byX5X0AqK8SPI=; b=A09AbUjcTLr3AJyVQETbPaq/VtKoExYJZGmepzddrpZ+OZC1lsZatYUXIzP94zhunB vSNsAJUTWxUpo/TAgNFMVAE/sk3WC9v3udvu3bFtqxggPabmmkq2tUDebO3WvFTD0fc5 Z0+VlCStk6eUPcRKM91aPR9MEhDRDPKcSrVdiVWAXAgVWSI7RxKPAXxDnx7chSRIUX8V WocXuRHRa59byKmtvafbEx0JdErBZgZFKqJSKwFwr8H6YoiQsqsmhpusUyc9kYtJ71da CaTer2xU6S2rlQA2RqKJHhAEq2/7WT/6z9LocqIC8/znHwhWptcGILBlR698GEAcvwgf R8Iw== X-Gm-Message-State: AOJu0YxZuF6hOjRhjDW0yJK7QUL8uLF1kpeNYHd+IA81KqWCuqXvxUlm jdf/m5ZwOlU7aCS+iru9GonclztSWSevFtuzu18bG9bsEvHtC4OaG9P1IhgBbs38mtvH+i+ZYOd 8 X-Google-Smtp-Source: AGHT+IFk7h5riHCabBxlvon1g3aJvyLDA3V4/A6avvM1sCi3tD9rn2Vzn2WYBUD/8CaBvHiTt7zkVw== X-Received: by 2002:a6b:7d0c:0:b0:7d0:3f6b:6af9 with SMTP id c12-20020a6b7d0c000000b007d03f6b6af9mr9639907ioq.0.1711994284850; Mon, 01 Apr 2024 10:58:04 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id ge9-20020a056638680900b0047730da740dsm2685669jab.49.2024.04.01.10.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 10:58:03 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/4] io_uring/msg_ring: split fd installing into a helper Date: Mon, 1 Apr 2024 11:56:28 -0600 Message-ID: <20240401175757.1054072-4-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240401175757.1054072-1-axboe@kernel.dk> References: <20240401175757.1054072-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 No functional changes in this patch, just in preparation for needing to complete the fd install with the ctx lock already held. Signed-off-by: Jens Axboe --- io_uring/msg_ring.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index d1f66a40b4b4..9023b39fecef 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -173,25 +173,23 @@ static struct file *io_msg_grab_file(struct io_kiocb *req, unsigned int issue_fl return file; } -static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flags) +static int __io_msg_install_complete(struct io_kiocb *req) { struct io_ring_ctx *target_ctx = req->file->private_data; struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); struct file *src_file = msg->src_file; int ret; - if (unlikely(io_double_lock_ctx(target_ctx, issue_flags))) - return -EAGAIN; - ret = __io_fixed_fd_install(target_ctx, src_file, msg->dst_fd); if (ret < 0) - goto out_unlock; + return ret; msg->src_file = NULL; req->flags &= ~REQ_F_NEED_CLEANUP; if (msg->flags & IORING_MSG_RING_CQE_SKIP) - goto out_unlock; + return ret; + /* * If this fails, the target still received the file descriptor but * wasn't notified of the fact. This means that if this request @@ -199,8 +197,20 @@ static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flag * later IORING_OP_MSG_RING delivers the message. */ if (!io_post_aux_cqe(target_ctx, msg->user_data, ret, 0)) - ret = -EOVERFLOW; -out_unlock: + return -EOVERFLOW; + + return ret; +} + +static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_ring_ctx *target_ctx = req->file->private_data; + int ret; + + if (unlikely(io_double_lock_ctx(target_ctx, issue_flags))) + return -EAGAIN; + + ret = __io_msg_install_complete(req); io_double_unlock_ctx(target_ctx); return ret; } From patchwork Mon Apr 1 17:56:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13612925 Received: from mail-io1-f46.google.com (mail-io1-f46.google.com [209.85.166.46]) (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 E51844DA0F for ; Mon, 1 Apr 2024 17:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994289; cv=none; b=MrAqGBbPJTSDnxgzsArG/gw7HARUVCSUMZft1wyKr+FBVFtvieLg/2DQyv756Q9hiXgue/TOOO3smvN1yAoU/eWVUg1MawjU4K6Vl2ttObtejcwvn2GTXzynHimsnvJ2y2fnhzFI8fOO54BYPjyno8POq2RrRv33rf9I5iXhJEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711994289; c=relaxed/simple; bh=+yy1hOVoA103+Gt61MTSfug2WDHcdLrCwUQT1ysOojk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IMzQ2GrRx4/sy0hkgLp7fiad6kPx2nH6wxy7S9EdSdS/vVt5aKjW8txpmVh6WeONEWKw128dj3O897E3N4WCPQDOSnlvZSvCXZbH/d2gacWzI8iGuEeZOfSD6nPPOXZr96lFA4Rg2BjDNJb16iC+UKkY8Xxr0vT4fwd2smo87+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=mukxvEVn; arc=none smtp.client-ip=209.85.166.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="mukxvEVn" Received: by mail-io1-f46.google.com with SMTP id ca18e2360f4ac-7cc67249181so32161839f.1 for ; Mon, 01 Apr 2024 10:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711994286; x=1712599086; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1okOPpSEoy3//u3IibMnbSt4+ARwzohEO+aaT3jjxyo=; b=mukxvEVnM6ErxxL3KuaKoxbIpP4RIKMIlsLTojli9kNMKda6Gg22iXNFScLQ1VXoLa 0e8NEC73UAlkMV/gLfJKZgOvhBvZlQnnzX5aHLnuG1rnCBAuFrrxR5SdarTTJn5tHN4l JIyt1ZgXRhMpTExyCyt/6IN+dvfzwoIk5AeqfFBStZACFO+C28n8WwuROCXz4GDlh66D 2zX14QAcM249AAHqPicjDeMyTdP+wGK2NyVYUV2zvX6Bl+y475lFl1LI5GXZaFgG7dtc iTrWc4pWxROFbxHAdtEVNHGdFXsCCd09sXO6c14acx0eC4Wc44BeXk9g5bgmcCakho6V PXcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711994286; x=1712599086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1okOPpSEoy3//u3IibMnbSt4+ARwzohEO+aaT3jjxyo=; b=uwVt79sLrtrJ/qkxH/iT/Ij4dmGrPzRhiiH8wj75ysYX2vidGFlTfZxzBBMSvC6380 uCoce1SXoaTFEEcbyYM0j59CYOnwEbu938vsrrDaNh7Y0ya/a5fsMC+8CXcilyh19nW9 Cw872p+8iHwNVbfKV1Kfhkkkzy55hC4Bj22O9ZVlAhM9HFTKoYWxmlWveUObc4ge3dof tyjYNcB9CBVM+UKqYieG5Nwtm2RI76gKyj0r165jc1b0FTyH55fiRHfrs4YsGef7wPcl t5AMkVQaLS/w7gg7IrTO8jeFqFJYWwpgBuXmnPAy5qZheiAJrhpWETAQpSzTepujc8Yy vKKg== X-Gm-Message-State: AOJu0Ywfum3PqRj63zJxkGYHiR9L+tf+71Syhrcz735XBP09FjP6EKMx swY40xf4tX7PfJBH5EYr21Z7QyJKG4Bz//mttpgINgQvjORC6drXygoj1DRVeiggZ3vJmY/FBoC l X-Google-Smtp-Source: AGHT+IHwKk1MMdmvy6uBJgbJ7X+/3CqR613ZHVEk9fpQsCoaFCRutpdyDj8YLkVDpZy9ctb/XA4+/A== X-Received: by 2002:a5d:9b1a:0:b0:7d0:8461:7819 with SMTP id y26-20020a5d9b1a000000b007d084617819mr9806402ion.1.1711994286645; Mon, 01 Apr 2024 10:58:06 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id ge9-20020a056638680900b0047730da740dsm2685669jab.49.2024.04.01.10.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 10:58:05 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/4] io_uring/msg_ring: improve handling of target CQE posting Date: Mon, 1 Apr 2024 11:56:29 -0600 Message-ID: <20240401175757.1054072-5-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240401175757.1054072-1-axboe@kernel.dk> References: <20240401175757.1054072-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the exported helper for queueing task_work, rather than rolling our own. This improves peak performance of message passing by about 5x in some basic testing, with 2 threads just sending messages to each other. Before this change, it was capped at around 700K/sec, with the change it's at over 4M/sec. Signed-off-by: Jens Axboe --- io_uring/msg_ring.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index 9023b39fecef..3e1b9158798e 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -13,7 +13,6 @@ #include "filetable.h" #include "msg_ring.h" - /* All valid masks for MSG_RING */ #define IORING_MSG_RING_MASK (IORING_MSG_RING_CQE_SKIP | \ IORING_MSG_RING_FLAGS_PASS) @@ -21,7 +20,6 @@ struct io_msg { struct file *file; struct file *src_file; - struct callback_head tw; u64 user_data; u32 len; u32 cmd; @@ -73,26 +71,18 @@ static inline bool io_msg_need_remote(struct io_ring_ctx *target_ctx) return current != target_ctx->submitter_task; } -static int io_msg_exec_remote(struct io_kiocb *req, task_work_func_t func) +static int io_msg_exec_remote(struct io_kiocb *req, io_req_tw_func_t func) { struct io_ring_ctx *ctx = req->file->private_data; - struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); - struct task_struct *task = READ_ONCE(ctx->submitter_task); - - if (unlikely(!task)) - return -EOWNERDEAD; - - init_task_work(&msg->tw, func); - if (task_work_add(ctx->submitter_task, &msg->tw, TWA_SIGNAL)) - return -EOWNERDEAD; + req->io_task_work.func = func; + io_req_task_work_add_remote(req, ctx, IOU_F_TWQ_LAZY_WAKE); return IOU_ISSUE_SKIP_COMPLETE; } -static void io_msg_tw_complete(struct callback_head *head) +static void io_msg_tw_complete(struct io_kiocb *req, struct io_tw_state *ts) { - struct io_msg *msg = container_of(head, struct io_msg, tw); - struct io_kiocb *req = cmd_to_io_kiocb(msg); + struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); struct io_ring_ctx *target_ctx = req->file->private_data; int ret = 0; @@ -215,14 +205,12 @@ static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flag return ret; } -static void io_msg_tw_fd_complete(struct callback_head *head) +static void io_msg_tw_fd_complete(struct io_kiocb *req, struct io_tw_state *ts) { - struct io_msg *msg = container_of(head, struct io_msg, tw); - struct io_kiocb *req = cmd_to_io_kiocb(msg); int ret = -EOWNERDEAD; if (!(current->flags & PF_EXITING)) - ret = io_msg_install_complete(req, IO_URING_F_UNLOCKED); + ret = __io_msg_install_complete(req); if (ret < 0) req_set_fail(req); io_req_queue_tw_complete(req, ret);