Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1181235ybf; Thu, 27 Feb 2020 06:25:57 -0800 (PST) X-Google-Smtp-Source: APXvYqzIyvyZ1ZWSA3iS75t7X2yzxAGGA9HVRiN6NL/ztfDqR6OH7kn3jwoqi09CCGTnDwyxxZ0t X-Received: by 2002:a9d:1c9c:: with SMTP id l28mr3541180ota.210.1582813557183; Thu, 27 Feb 2020 06:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582813557; cv=none; d=google.com; s=arc-20160816; b=E6PCPD7N3UKi241pzuGeqZXHcWwe5JxBNnwIwuHE/hvnAUiy1Dmydg/y+Ahg8gRIgl yv3AhL46pPs+pe0PkOmxoX4ROVzZ0zzGzIlzrwq5/v2xq2BtXXIKiBubQcpG7DGb4P5z Zo5x5PxeIjsGQHW/BU2w9Z1Tr0MeHCQchChkTOcmiGluZUpgKj7XFCcuFagI6YIYfakL ai87raqN3CthjYJ7Cf0PQqYpPxONVVmIIVODXVh0eqVPqZQ2cDqCtK0/YAGE9NP8mvjz eKJNamem37LLADA+IEPSfjk2WDPi8zL5x1kpw+r8WbmCgg5pBpbldSFr5HB4aOV1WNq/ ZusQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xhc2jKxNzm0wPom5ctZ5ZzptCf0Ni5j6jbT7ycF6KJI=; b=LiMoI/F4NrGEwTOIQlwYj/ALyJdAa4nYmRCz4Ut3GOZ/Ibn5VU33IPCfAbOJUOkG1Y MmyNjvjLU46J64ikqIbw0NBFr1LeDwJ/shSAzhEbY/Fft3njvmwioFZQH0FmAr/QQJTG rECkJ2+geCuszqgaDzmKYTfUkoO24xt+eMnB0Lll9UqyDc4T3oMp5TWHHk8e6Z/x53QF R4fG4njz4D81jfqzCIph8g4ggL1SRtEdnAU1RBEX+CzKTaJctCwruRCT5UHcSdD4hd5b wdKNjPIXt3v+/Aip8KGRmaNnnIP8icY/KBrw9k7QxOxDoYa3JTjt6pn6GkaZ2NUZ8Yd4 I0PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kqm2AP8E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g25si1430089otj.198.2020.02.27.06.25.45; Thu, 27 Feb 2020 06:25:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kqm2AP8E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388755AbgB0OLu (ORCPT + 99 others); Thu, 27 Feb 2020 09:11:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:50336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388318AbgB0OLs (ORCPT ); Thu, 27 Feb 2020 09:11:48 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA22F246AD; Thu, 27 Feb 2020 14:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812706; bh=P6ve4YLl/tTD98oyYfZFuy1vti5trftE7wEQ/bg91sA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kqm2AP8E6hZWN4XnbDjdGcwnmXh7MezjwSz5ueseccNovLggDpwfIEy1z2dBfu87A JKqoZvWsWcfTOf5qs+awd9EvChpy/aejkn3NTKki/LuTdF/HOxt4/H1M/jErs85gkG 5BzzAiPBXpaT3m1WvffXjX74GicYxjhofeFX84jY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoguang Wang , Jens Axboe Subject: [PATCH 5.4 121/135] io_uring: fix __io_iopoll_check deadlock in io_sq_thread Date: Thu, 27 Feb 2020 14:37:41 +0100 Message-Id: <20200227132247.269204084@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 commit c7849be9cc2dd2754c48ddbaca27c2de6d80a95d upstream. Since commit a3a0e43fd770 ("io_uring: don't enter poll loop if we have CQEs pending"), if we already events pending, we won't enter poll loop. In case SETUP_IOPOLL and SETUP_SQPOLL are both enabled, if app has been terminated and don't reap pending events which are already in cq ring, and there are some reqs in poll_list, io_sq_thread will enter __io_iopoll_check(), and find pending events, then return, this loop will never have a chance to exit. I have seen this issue in fio stress tests, to fix this issue, let io_sq_thread call io_iopoll_getevents() with argument 'min' being zero, and remove __io_iopoll_check(). Fixes: a3a0e43fd770 ("io_uring: don't enter poll loop if we have CQEs pending") Signed-off-by: Xiaoguang Wang Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -882,11 +882,17 @@ static void io_iopoll_reap_events(struct mutex_unlock(&ctx->uring_lock); } -static int __io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events, - long min) +static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events, + long min) { int iters = 0, ret = 0; + /* + * We disallow the app entering submit/complete with polling, but we + * still need to lock the ring to prevent racing with polled issue + * that got punted to a workqueue. + */ + mutex_lock(&ctx->uring_lock); do { int tmin = 0; @@ -922,21 +928,6 @@ static int __io_iopoll_check(struct io_r ret = 0; } while (min && !*nr_events && !need_resched()); - return ret; -} - -static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events, - long min) -{ - int ret; - - /* - * We disallow the app entering submit/complete with polling, but we - * still need to lock the ring to prevent racing with polled issue - * that got punted to a workqueue. - */ - mutex_lock(&ctx->uring_lock); - ret = __io_iopoll_check(ctx, nr_events, min); mutex_unlock(&ctx->uring_lock); return ret; } @@ -2721,7 +2712,7 @@ static int io_sq_thread(void *data) */ mutex_lock(&ctx->uring_lock); if (!list_empty(&ctx->poll_list)) - __io_iopoll_check(ctx, &nr_events, 0); + io_iopoll_getevents(ctx, &nr_events, 0); else inflight = 0; mutex_unlock(&ctx->uring_lock);