From patchwork Sun Jul 18 23:54:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 479797 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.7 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, URIBL_BLOCKED, 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 566FAC636C8 for ; Sun, 18 Jul 2021 23:55:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 370C76117A for ; Sun, 18 Jul 2021 23:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233722AbhGRX56 (ORCPT ); Sun, 18 Jul 2021 19:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233713AbhGRX54 (ORCPT ); Sun, 18 Jul 2021 19:57:56 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 355FDC061762 for ; Sun, 18 Jul 2021 16:54:56 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id i94so19623299wri.4 for ; Sun, 18 Jul 2021 16:54:56 -0700 (PDT) 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=UszeBgxH2DDSwH8vZaJMkXZPARX31U5GtujpEGVSoi4=; b=fUyJGGhELRbPZIlpMeA7DSsV5kuWKwoU+9FqLiL4rt6xgzQiU+n/fb+yvKFDObdgeq 8PnUQHB0HkUXI1boZB7rZisw2P0YLNCWzIz73Jb5NSUpyiiKYVrtuGeqvV6T18IZztCX U+LYfYqZ7X6iWiaBYjSal3QT4MbIQfKuhEZfBmH8dSEB0oX5cr+Gnskim//KwhPGzoGH MHAzJB2mujEGyk72tCnFeX1LzfJwBz7bovX6XJWeFYqNoGXlFSxPXRXrNL4+TpuOzOJQ cpViajV+XnRjFZVl2q9AtsPF0ogq5bKEvh78ORLEdUQBa+xYlZ7aHiLUl7ZbDzlTalH+ q1kg== 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=UszeBgxH2DDSwH8vZaJMkXZPARX31U5GtujpEGVSoi4=; b=SLdvA37cRokDGXiF7DBMFpZgBGiu6LWdt0ck3Ejm1Sj74yfyW5gpwRjpjPPKfZv4FV VU/Vos25Uu0zu31JEyG91tnPGYrZp+2rx/wHlh062ObAe1FVRXt8M0m1TMEPEve3m0CU ZnCM5Vl56Kl0okjuAmiEPxp0//F6uz0KGWC3Ql3FVcmDICHwIRZ1sYdL4ZdRpOv1NDs5 qXVMKRKLeC9I7wCCKf/Kl6WY3zbbjpNyx7k2L5M9uSVsF6oO5Y3JGaWpbm0WbbzSMK4/ BLyoZCz78pBQGoRyjh3H47MVnDIyot2/w/keukR343QYGH6Fo2iuAeSWdQWuI1Vwli9b GTPA== X-Gm-Message-State: AOAM533WPmDaSfez8OyTfWHJLVkjZ6hjrv0bxPsEupGqaCu+vpaeb91U QM2GCbwUw4GkUqmjHq5jS2qqc1A8fTAUHA== X-Google-Smtp-Source: ABdhPJypvHj6+RT8cauaPpoYNLa10uytCmxY6gGOuV2c6zd+PoZ+0B0EuSJeGYlO/S526DJCjDQI7w== X-Received: by 2002:a5d:464b:: with SMTP id j11mr26746132wrs.356.1626652494659; Sun, 18 Jul 2021 16:54:54 -0700 (PDT) Received: from localhost.localdomain ([148.252.129.101]) by smtp.gmail.com with ESMTPSA id p18sm18098200wmg.46.2021.07.18.16.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 16:54:54 -0700 (PDT) From: Pavel Begunkov To: stable@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/2] io_uring: put link timeout req consistently Date: Mon, 19 Jul 2021 00:54:22 +0100 Message-Id: <6122708161f73ad0027ee2accd755cd848742dc8.1626651114.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit df9727affa058f4f18e388b30247650f8ae13cd8 ] Don't put linked timeout req in io_async_find_and_cancel() but do it in io_link_timeout_fn(), so we have only one point for that and won't have to do it differently as it's now (put vs put_deferred). Btw, improve a bit io_async_find_and_cancel()'s locking. Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/d75b70957f245275ab7cba83e0ac9c1b86aae78a.1617287883.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- fs/io_uring.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 58ac04cca587..930c5d5a2b0b 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5727,12 +5727,9 @@ static void io_async_find_and_cancel(struct io_ring_ctx *ctx, int ret; ret = io_async_cancel_one(req->task->io_uring, sqe_addr, ctx); - if (ret != -ENOENT) { - spin_lock_irqsave(&ctx->completion_lock, flags); - goto done; - } - spin_lock_irqsave(&ctx->completion_lock, flags); + if (ret != -ENOENT) + goto done; ret = io_timeout_cancel(ctx, sqe_addr); if (ret != -ENOENT) goto done; @@ -5747,7 +5744,6 @@ static void io_async_find_and_cancel(struct io_ring_ctx *ctx, if (ret < 0) req_set_fail_links(req); - io_put_req(req); } static int io_async_cancel_prep(struct io_kiocb *req, @@ -6310,8 +6306,8 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) io_put_req_deferred(req, 1); } else { io_req_complete_post(req, -ETIME, 0); - io_put_req_deferred(req, 1); } + io_put_req_deferred(req, 1); return HRTIMER_NORESTART; } From patchwork Sun Jul 18 23:54:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 479796 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.7 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, URIBL_BLOCKED, 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 05BF4C636CD for ; Sun, 18 Jul 2021 23:55:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E009260FF4 for ; Sun, 18 Jul 2021 23:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232582AbhGRX57 (ORCPT ); Sun, 18 Jul 2021 19:57:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233720AbhGRX55 (ORCPT ); Sun, 18 Jul 2021 19:57:57 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CD2EC061766 for ; Sun, 18 Jul 2021 16:54:57 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id t5so19586703wrw.12 for ; Sun, 18 Jul 2021 16:54:57 -0700 (PDT) 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=qJ6V7XxGp7X7Mk2Vc/vNO+J77JgrLdzNPnbxMVMNpcc=; b=fAV4bG5A9Wvc8k2UEtyCZ/wJCWn4758px82p1DZm2ysVXypHrdHL96ISxsDHPJ/DRx yR8f9pT57YtP9T9H2mgPV8ctTGai74YzxnbgBsh9P9f0K8tH5mW3ivbuH8K68zH1nR4i JWSo15kPUyqxJb+DumpzNS/sicOwDUwa3GLV2Y7O57dptzSj6oleWqs3G5xMDKezS57p pOG2cb0dSfhBgSPDY9yyyKwRmA/CtNY6Y2wFTEPERJqz4u52fGhYKzbkeJYYP1Ki4Ded dEDlRsFOVTuUHRYo/UD+MKW7eGBmIozcJGJgFtKVqmYJ7g2QCq6ygYQZ5T5aA/fwKkUq ScnQ== 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=qJ6V7XxGp7X7Mk2Vc/vNO+J77JgrLdzNPnbxMVMNpcc=; b=KVh8qqQ2ko6qH9T+scn6agt+Qmcl3DopnUxqeobYyU5qunx1YeC8aqTeCF4mKajQUh CDJgugLfMfAy/PLs2O0DT+8kQFlD0YIc3QCkabCJ4GaZou1gDXqk4xdSJB8iD+vqMHXL aIBmCK8BMK+KTiwQeqfI9n8k9LoPRLgQ2mqmDi7W0Oqbbod6Q6pGQ2Azsl8bOBWpSMoE //r4qh0bO4IcN+LLsZ+RQLrIjPWEa5YLR1XsJXDtEsRWrjhtrseUO7O2VWSjZmZgG3I6 KIqxd8ceX6Rx7kKYonwF21PMFkYYdRxCJxgcsAwS95Gm3AUOHql2EE7+A2kkeMjkQJa1 dQZQ== X-Gm-Message-State: AOAM530Dfvej/zQJtfGtG1A+PlmE/nbavl3ZRH2AJaqRdMgSoKSA7DHT 8SnNoKs4k06eeYt2iwEPO2GNuxbA4EsjVg== X-Google-Smtp-Source: ABdhPJyeO5lkQZD1S6WILaE4epAIagZdUMDwWf5NTtuBX1yxUN9gsrvSjjPINjxLb3npoGOXIA2Y3Q== X-Received: by 2002:a5d:5985:: with SMTP id n5mr27224413wri.63.1626652495584; Sun, 18 Jul 2021 16:54:55 -0700 (PDT) Received: from localhost.localdomain ([148.252.129.101]) by smtp.gmail.com with ESMTPSA id p18sm18098200wmg.46.2021.07.18.16.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 16:54:55 -0700 (PDT) From: Pavel Begunkov To: stable@vger.kernel.org Cc: Jens Axboe , syzbot+a2910119328ce8e7996f@syzkaller.appspotmail.com Subject: [PATCH 2/2] io_uring: fix link timeout refs Date: Mon, 19 Jul 2021 00:54:23 +0100 Message-Id: <07d1e4a10988b2ffb0b4bad641b46ce05626a494.1626651114.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit a298232ee6b9a1d5d732aa497ff8be0d45b5bd82 ] WARNING: CPU: 0 PID: 10242 at lib/refcount.c:28 refcount_warn_saturate+0x15b/0x1a0 lib/refcount.c:28 RIP: 0010:refcount_warn_saturate+0x15b/0x1a0 lib/refcount.c:28 Call Trace: __refcount_sub_and_test include/linux/refcount.h:283 [inline] __refcount_dec_and_test include/linux/refcount.h:315 [inline] refcount_dec_and_test include/linux/refcount.h:333 [inline] io_put_req fs/io_uring.c:2140 [inline] io_queue_linked_timeout fs/io_uring.c:6300 [inline] __io_queue_sqe+0xbef/0xec0 fs/io_uring.c:6354 io_submit_sqe fs/io_uring.c:6534 [inline] io_submit_sqes+0x2bbd/0x7c50 fs/io_uring.c:6660 __do_sys_io_uring_enter fs/io_uring.c:9240 [inline] __se_sys_io_uring_enter+0x256/0x1d60 fs/io_uring.c:9182 io_link_timeout_fn() should put only one reference of the linked timeout request, however in case of racing with the master request's completion first io_req_complete() puts one and then io_put_req_deferred() is called. Cc: stable@vger.kernel.org # 5.12+ Fixes: 9ae1f8dd372e0 ("io_uring: fix inconsistent lock state") Reported-by: syzbot+a2910119328ce8e7996f@syzkaller.appspotmail.com Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/ff51018ff29de5ffa76f09273ef48cb24c720368.1620417627.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- fs/io_uring.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 930c5d5a2b0b..29a0af50a439 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6307,7 +6307,6 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) } else { io_req_complete_post(req, -ETIME, 0); } - io_put_req_deferred(req, 1); return HRTIMER_NORESTART; }