Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp788405ybj; Thu, 7 May 2020 07:40:23 -0700 (PDT) X-Google-Smtp-Source: APiQypJre/2RPTDfoe2ymBhOFWJ8sj/knGnFUmnfuIDbjprMr1nz0OOVGU+Xc46TM2haL1C7mLIz X-Received: by 2002:a50:b961:: with SMTP id m88mr12312343ede.4.1588862423564; Thu, 07 May 2020 07:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588862423; cv=none; d=google.com; s=arc-20160816; b=hZs1wV0Zw3hh3n5fLa9DxYojEXbFpHxquy4VvGjaZvt4x/ymaFZusk0wWVB8QrQpma 3pwKo643Iw4FNSYQCE3BiIRPX2/64IXiPbjdo64dQEsBCjbF1SD73kHkhHPgeH3/mmHq bwOEjLAUpCxxrDefjW7MmaANvQdII6TxOFrADdae4tiYa29yisGmUUyWiS375MlzmEbP DUK4shrMdUMqXjH7O1Hp51ngcBSNRnyi93XughofCYMuDB+hFXf2y5k0oCELA8HAQTUf uJegblpBPWw+WSaDHHaIIl2Vt6SK3432Evj9UN4t08YX/A9E/PWD+OI/URGYv19c64kc 6c6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AnDz4UZbduvevpXHoX7uag8da5lBsvV/WUceLZHH9a8=; b=eaRZT9IfRDIZsu8MQxi31nLoIJnJ+RQPnKZ/siF0A0fuxk5lsRqZH0ll5JASnbNPa+ ZVzMQ0ibHj2YehThAlK6c76J52ZvrEpDgOMfmow59gV7p17ckLm6YCd/GRooruahzjA8 VClAbM4qVq5g+l+SOF8laE2cT805f9ce2T4UV0jZ+pk075574XzaEdjMDTUHCX/mzl+d lAFF5ywAj42wGborh0/MaoZkiAIs5Nlj+LNCAdhBPtd9MN7GCbQysIN5s3a+644THehK 7KfUMdvhYD4B9CX0/oAw38n7VBG6sZsmbw6KLc+zrCbrlBbjEGFDdd0LcxNj8oyf0YsE l+GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xRz9wuoO; 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 d11si3041200edy.477.2020.05.07.07.40.00; Thu, 07 May 2020 07:40:23 -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=xRz9wuoO; 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 S1728781AbgEGOfx (ORCPT + 99 others); Thu, 7 May 2020 10:35:53 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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