From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 7E59AC38A24 for ; Thu, 7 May 2020 14:36:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 552C920659 for ; Thu, 7 May 2020 14:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588862170; bh=o6PaR1/R/MRl/FjFPECd7AUCCz6IqqoI0ngS/aGTPEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Mt6fs7uHIn8Ld2TXEa4WaaWCTswSxIIu6EtkAxa5v89zs+NNw7cNsXrv6hfczEJ3e dfz70JBTxCLARMAhyaMGsYe1pVSonqki8XIjWLuj7k3D+3plUCH18BXgplCaTdW/nE 6OO7oyEQxWn0UDukIOM7KXegsq80YUDhqa7Vasgc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728691AbgEGOfu (ORCPT ); Thu, 7 May 2020 10:35:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:55112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728102AbgEGO2Z (ORCPT ); Thu, 7 May 2020 10:28:25 -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 1F3B6218AC; Thu, 7 May 2020 14:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588861704; bh=o6PaR1/R/MRl/FjFPECd7AUCCz6IqqoI0ngS/aGTPEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xRz9wuoOEq8P0Yd4U/uQMToNKjwATxaobLbZP46O4yqR0IYplVS50NxQI1BdvCU0u dFxH6t0C2pKD6beYl13OWLhJ4WdquyTw1on/bjYSEr0Y1SELochzanzUUHyBZ8y3EF CtkIyhU0Ce5RobohesEBQFtS/ICAZnLyKBBf7vQk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiaoguang Wang , Jens Axboe , Sasha Levin , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH AUTOSEL 5.6 45/50] io_uring: use cond_resched() in io_ring_ctx_wait_and_kill() Date: Thu, 7 May 2020 10:27:21 -0400 Message-Id: <20200507142726.25751-45-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200507142726.25751-1-sashal@kernel.org> References: <20200507142726.25751-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Xiaoguang Wang [ Upstream commit 3fd44c86711f71156b586c22b0495c58f69358bb ] While working on to make io_uring sqpoll mode support syscalls that need struct files_struct, I got cpu soft lockup in io_ring_ctx_wait_and_kill(), while (ctx->sqo_thread && !wq_has_sleeper(&ctx->sqo_wait)) cpu_relax(); above loop never has an chance to exit, it's because preempt isn't enabled in the kernel, and the context calling io_ring_ctx_wait_and_kill() and io_sq_thread() run in the same cpu, if io_sq_thread calls a cond_resched() yield cpu and another context enters above loop, then io_sq_thread() will always in runqueue and never exit. Use cond_resched() can fix this issue. Reported-by: syzbot+66243bb7126c410cefe6@syzkaller.appspotmail.com Signed-off-by: Xiaoguang Wang 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 a46de2cfc28e8..b5ade01379029 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6449,7 +6449,7 @@ static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx) * it could cause shutdown to hang. */ while (ctx->sqo_thread && !wq_has_sleeper(&ctx->sqo_wait)) - cpu_relax(); + cond_resched(); io_kill_timeouts(ctx); io_poll_remove_all(ctx); -- 2.20.1