Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp870755pxx; Tue, 27 Oct 2020 02:31:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzs9J8jxVfjve4TElbY5TeieugOVK1Si5ZDnp0lA1RKZoiAXBIurzTpiPZO2EfkikWpOGOS X-Received: by 2002:a17:906:364f:: with SMTP id r15mr1450763ejb.388.1603791096711; Tue, 27 Oct 2020 02:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603791096; cv=none; d=google.com; s=arc-20160816; b=efhExQ6Nje9ZgOFsF6C4pIxjC63xlATHeFYW0X63gAAcn8FQBQIdkcNBGs51K9PdoD gP4HHx/6ze+jrd2eYha+w5Xb/Fkw0Hj3smRVGJSDCG6xrou+o/1Xmn/YC5jIixFE7Zdo pcQLGOpXOQfKf+mGkDRcxEp2Ot5Sh44zaZpWvoZtrGliDalA7x98o0d7ec5xGSwP6rb5 d7Gj/p9sdBx7AjpIXSUc8wMRx3HVSJQ2EXdULyMooVdi3DzTHzfz2Ji18DNu+OwmwCOy nOwHfDfvvtkQ4EbFTFKoyIliRhq7ll7GnPEX0UVHuYpHCkxQthvgOYowVFCMcHlMr57W Sn+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wrkC2VR7mBL0lMfjYu3xlRuPH7zal3IXw7mMYz+z3rw=; b=nu/uzB9nFHwR3AGyt16jfIOIAFEOb9+Q3x8O+b6VkpNiEwO5GtwKcuhHc+8TbAV597 PP83FwR1Q6v8yetR9VXa7me8/DnHzIky+ek6EYACE1qBOS3SRsZJhjHWGOHo2P0rJQI6 tmHMIJTLnhGk3LBOTGj6CdvQp+RDWLErfmGQ3J4XHSbjox6GaNvCmzYiCLHf/TN7fGT9 dOnSiQxUZLUge6jSHG3ZoW9tfM7QhEeTl4Y9/DY3AQeDksKo7in9n45VNolawWA0uLYu Y20GImMiiNCO70TMT0XD1pVqpvpdwpkFgeCMRzPGMhFDlpewAblVd5KqbWw1DXRkwCLX VPpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Y/gfptYP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l4si465308eds.199.2020.10.27.02.31.02; Tue, 27 Oct 2020 02:31:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Y/gfptYP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409053AbgJZXuN (ORCPT + 99 others); Mon, 26 Oct 2020 19:50:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:47964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408786AbgJZXtm (ORCPT ); Mon, 26 Oct 2020 19:49:42 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 606C921741; Mon, 26 Oct 2020 23:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756182; bh=6DudW/JqqtwV4WRtfvdDoaRR7NIbaoqPJeFKlaMc93I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y/gfptYP3XSBhaRyTH+N6Z5jNDtuE4YPNxTjwOP7Cyy6cmSQZ6Td3GrnjYnSeCkTm hze5VwN425aCc/F7w/UwquL0j3tGiJDA+zKS81sdbig1B+JHpceJGCwDS42IQ83YJy NIq//HYBLXfpcRK0XwlyOAu859Nz0O9MWkvft2xI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Begunkov , Jens Axboe , Sasha Levin , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.9 029/147] io_uring: don't set COMP_LOCKED if won't put Date: Mon, 26 Oct 2020 19:47:07 -0400 Message-Id: <20201026234905.1022767-29-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026234905.1022767-1-sashal@kernel.org> References: <20201026234905.1022767-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov [ Upstream commit 368c5481ae7c6a9719c40984faea35480d9f4872 ] __io_kill_linked_timeout() sets REQ_F_COMP_LOCKED for a linked timeout even if it can't cancel it, e.g. it's already running. It not only races with io_link_timeout_fn() for ->flags field, but also leaves the flag set and so io_link_timeout_fn() may find it and decide that it holds the lock. Hopefully, the second problem is potential. Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index aae0ef2ec34d2..2145cf76a0d6a 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1614,6 +1614,7 @@ static bool io_link_cancel_timeout(struct io_kiocb *req) ret = hrtimer_try_to_cancel(&req->io->timeout.timer); if (ret != -1) { + req->flags |= REQ_F_COMP_LOCKED; io_cqring_fill_event(req, -ECANCELED); io_commit_cqring(ctx); req->flags &= ~REQ_F_LINK_HEAD; @@ -1636,7 +1637,6 @@ static bool __io_kill_linked_timeout(struct io_kiocb *req) return false; list_del_init(&link->link_list); - link->flags |= REQ_F_COMP_LOCKED; wake_ev = io_link_cancel_timeout(link); req->flags &= ~REQ_F_LINK_TIMEOUT; return wake_ev; -- 2.25.1