From patchwork Wed Dec 30 21:34:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 355519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF28DC433E0 for ; Wed, 30 Dec 2020 21:38:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BED4320771 for ; Wed, 30 Dec 2020 21:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726317AbgL3Vif (ORCPT ); Wed, 30 Dec 2020 16:38:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726197AbgL3Vie (ORCPT ); Wed, 30 Dec 2020 16:38:34 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51B08C061575; Wed, 30 Dec 2020 13:37:54 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id g185so5872167wmf.3; Wed, 30 Dec 2020 13:37:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7+SMm2iKQGITJSuVgJmlWHkODg8DnWAlieYuuZCnEEw=; b=A4DU6IU+SW2/8+RRLgJ9GzfI2VDqCbRF1AmKMedgt4MWMSsKQAX8HHhzWcWPxHL5kk nGMEW+AowP37h/ePP9CTbjm82ii7ZjyTkTLiCHUtd7IKZdVSAVjLQHRX+Cj91xpE7zAZ FNiGQyOrpIhNm06EuLmsDGIFRzn/8xhyz97C6mMg4HiHjAJk5ITk1tq5SgNgfWs1uNld g8hHZfBRSMQKDv27xKmIRw0A4qaeQA9dBjF6QwEL+aP+IP7cf9Y3GtM2qa3niJyDNJQA OeNVGl2o6bM/ezMtUtwHl6mj2d1l0poNmD4SC+CGWtzw8Bbm/3jqUujrM6SJ/9Z5Uq9+ 22nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7+SMm2iKQGITJSuVgJmlWHkODg8DnWAlieYuuZCnEEw=; b=J0/rNTQP1pkh30zQKNrXNcj2YoOdYU/KS3/Vvwnq3HxEi0UO5UvCLlWSX7/VKwsiUo XhISa/O7+vod7IKK/lsChmXK7kzeIimpBlNpTgDPxmdf7Di+2By529abZmhPVBnerTqS kCS+ipSjq41WfoUAHP/3Zm3nhc2lONHzr3axtXf3oN4JQmWU4f1TyYDQt4rV4jyDZmvu It9t0gdfAMpeUcqNWlezcGMBk5Q22CkgYKy6N8jDRonr+9fxUzLfwnIo7E8tv2PawiI4 FM11Q5AhCmHUU8PVwGb439o/iOvrSEkcNyBzzfn4wary/LzFmMjpGNujnuC8yh9mILBf J66w== X-Gm-Message-State: AOAM533SbyPZBv28/5Ve8/fPAqhcqhn/CtL5+wPnVfRLaTXkglErpgf6 YMD+MRKunZCtkzG1ga3vbpoWw9teUQw= X-Google-Smtp-Source: ABdhPJxOqBwH4sNBfZxX3rp6+qbg0rqynhrm7ze6FaFmdXlKdyA8MfIELKwiwYNTXAp3VT7lZhcFeg== X-Received: by 2002:a1c:61c3:: with SMTP id v186mr9115093wmb.146.1609364272314; Wed, 30 Dec 2020 13:37:52 -0800 (PST) Received: from localhost.localdomain ([148.252.128.61]) by smtp.gmail.com with ESMTPSA id 125sm8823626wmc.27.2020.12.30.13.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 13:37:51 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH 1/4] io_uring: add a helper for setting a ref node Date: Wed, 30 Dec 2020 21:34:14 +0000 Message-Id: <2fecebc9ab028ca5ea52198b615c30fab6151114.1609361865.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Setting a new reference node to a file data is not trivial, don't repeat it, add and use a helper. Cc: stable@vger.kernel.org # 5.6+ Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index eb4620ff638e..6372aba8d0c2 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7231,6 +7231,16 @@ static void io_file_ref_kill(struct percpu_ref *ref) complete(&data->done); } +static void io_sqe_files_set_node(struct fixed_file_data *file_data, + struct fixed_file_ref_node *ref_node) +{ + spin_lock_bh(&file_data->lock); + file_data->node = ref_node; + list_add_tail(&ref_node->node, &file_data->ref_list); + spin_unlock_bh(&file_data->lock); + percpu_ref_get(&file_data->refs); +} + static int io_sqe_files_unregister(struct io_ring_ctx *ctx) { struct fixed_file_data *data = ctx->file_data; @@ -7758,11 +7768,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, return PTR_ERR(ref_node); } - file_data->node = ref_node; - spin_lock_bh(&file_data->lock); - list_add_tail(&ref_node->node, &file_data->ref_list); - spin_unlock_bh(&file_data->lock); - percpu_ref_get(&file_data->refs); + io_sqe_files_set_node(file_data, ref_node); return ret; out_fput: for (i = 0; i < ctx->nr_user_files; i++) { @@ -7918,11 +7924,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, if (needs_switch) { percpu_ref_kill(&data->node->refs); - spin_lock_bh(&data->lock); - list_add_tail(&ref_node->node, &data->ref_list); - data->node = ref_node; - spin_unlock_bh(&data->lock); - percpu_ref_get(&ctx->file_data->refs); + io_sqe_files_set_node(data, ref_node); } else destroy_fixed_file_ref_node(ref_node); From patchwork Wed Dec 30 21:34:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 355518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55B2EC4332B for ; Wed, 30 Dec 2020 21:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B350207A3 for ; Wed, 30 Dec 2020 21:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726564AbgL3Vig (ORCPT ); Wed, 30 Dec 2020 16:38:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726305AbgL3Vig (ORCPT ); Wed, 30 Dec 2020 16:38:36 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A39B1C06179B; Wed, 30 Dec 2020 13:37:55 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id q18so18679980wrn.1; Wed, 30 Dec 2020 13:37:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bcMAp6tVywjSvwwt6sm+3F0M10rsmbInlCvk86yuFG4=; b=BfY/hxclbsS/QJDWGx7INU0FiWM6XcDywWWV2MWs3rOZEUb4+PwPL5tfjonaZ4PRIr FGvn5lcX9H1n2c7WpPWI/PNB9whivR2kxT1pizDp39nzUznkZN+VlAerOrf7kLSqk84+ VO4dzE8JG753HHeVHitx49CbKdNzAaRIisgtO8DWVTzJ6L9nZVavQvsg3Y1YJjIvPYHd JSacP1wvPHn3uJ0wdf+xjF1eXb1j98SVJQ5mrNTCFoLWF0l3+AtLqifPIt3fBJcskNXM r/xnv4HmhkYbd8wITVvSFbSL66BYj8COtkABcB8vR/oXi2o8Z1h/V+VqDh85ZUfJaIAY /O1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bcMAp6tVywjSvwwt6sm+3F0M10rsmbInlCvk86yuFG4=; b=aF219iVdboP/rHyM4bNEGuPsrBHTS/Q6pEn5WGXajZMGKjhIrNCLzlXURqvzftelom 7ZjXB3k91LIbAtMNx3K86m62TsHqKNhisioIjxZRUoEge5mP1RAqFMCVjka3xw4Dveki PoaYVpjO2rqlzdz7bz1LWDX7v9FdXZUhHTg9ZvvFs5WK2BbdbRuYpJFT94ksHOUpeAU+ z3Qho3TTGEiuPcws0CGvqhDiBvWQCzyQ3eb26TDdtq9sQxncqxpIEssUw9Ng+7/HYWYx TlKKQ9ujLkKPt3ekbwshDN+pCFHIiIhb/Bz8XdAF90zU3j7jpl5FdP0NbsDCtgernpt0 6ycg== X-Gm-Message-State: AOAM531Q6s5GuKXKsjVOhtJYkUkyrPn/tAyfqsrn/ZtVaa5T4T6dVrZI sksz+rOmJDgDD0HMAx8fyBw= X-Google-Smtp-Source: ABdhPJyxuOgGIOHOikCdsz8oWx4I/QAZaKnS9rLyE34F7zX3to9nyovgqTE4+/+mEB7eTWkl6FYP5g== X-Received: by 2002:adf:90e3:: with SMTP id i90mr36804489wri.248.1609364274465; Wed, 30 Dec 2020 13:37:54 -0800 (PST) Received: from localhost.localdomain ([148.252.128.61]) by smtp.gmail.com with ESMTPSA id 125sm8823626wmc.27.2020.12.30.13.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 13:37:54 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH 3/4] kernel/io_uring: cancel io_uring before task works Date: Wed, 30 Dec 2020 21:34:16 +0000 Message-Id: <12a143ea8f841801b36ccd1cca3558543eab7683.1609361865.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org For cancelling io_uring requests it needs either to be able to run currently enqueued task_wokrs or having it shut down by that moment. Otherwise io_uring_cancel_files() may be waiting for requests that won't ever complete. Go with the first way and do cancellations before setting PF_EXITING and so before putting the task_work infrastructure into a transition state where task_work_run() would better not be called. Cc: stable@vger.kernel.org # 5.5+ Signed-off-by: Pavel Begunkov --- fs/file.c | 2 -- kernel/exit.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/file.c b/fs/file.c index c0b60961c672..dab120b71e44 100644 --- a/fs/file.c +++ b/fs/file.c @@ -21,7 +21,6 @@ #include #include #include -#include unsigned int sysctl_nr_open __read_mostly = 1024*1024; unsigned int sysctl_nr_open_min = BITS_PER_LONG; @@ -428,7 +427,6 @@ void exit_files(struct task_struct *tsk) struct files_struct * files = tsk->files; if (files) { - io_uring_files_cancel(files); task_lock(tsk); tsk->files = NULL; task_unlock(tsk); diff --git a/kernel/exit.c b/kernel/exit.c index 3594291a8542..04029e35e69a 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -776,6 +777,7 @@ void __noreturn do_exit(long code) schedule(); } + io_uring_files_cancel(tsk->files); exit_signals(tsk); /* sets PF_EXITING */ /* sync mm's RSS info before statistics gathering */