Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13927686pxu; Mon, 4 Jan 2021 08:10:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQyhM73xC6vvZDdQKDkOhyu1XYGOrVt9eMx3DBd8YaVHMLOWwYVbAGpmYyH3RI9SqxBlHy X-Received: by 2002:a17:906:4bc5:: with SMTP id x5mr67278791ejv.55.1609776637285; Mon, 04 Jan 2021 08:10:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609776637; cv=none; d=google.com; s=arc-20160816; b=Ayvod9iWFILooitMGcEi8MnrSy4JajMn8eu2Juornq7lPRRFbycYgQ8XEVux3gxBDI PgTWCsBvv0VoKgyt014Bu62kvVgC8cOdum4Te8s/kCwRRWpTN+MRKmDJyvOCnwFxp00z dqmpCvABfJWY+MAMHmiwA7EGpOo7xAXOAdf1Cy1ncY8czrdjxDKzNlrtVoP1yo9/NFOc 6pxZ9mBU+3HWqCBqEFrzxMaqz66m7Mq0/N7kWai2knz2U1gEwU9r3svigODsXs2zdbsz 2Byoie49OQtYJt6dquqLYQypBW/xBgseAtFzVQWIdn8cEBlmQAIiY59e0xaT+wH31NnD 8YzA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BmQq8LElaJ2nPNIk/WiMAcEkWQIBpHplela1T6ZPiGI=; b=sfZLUYB2dxX/pMfmc/6me3kHNM4dm498JbFvaPFEzM/QU5ZMUDoTMKylnkeRomTNZf 1vleydbAX/GBb/ppFM1D5uM3ESCyy02rvP9la6ohD5MHUFQLImSDOo8eqxCiL1wRcTgq TfBHsiDQeEkjvKxypHGvhfnfsjgClncjHziyBVOFPa7Ur7gCmyv0i5V+bcZt2PI+vXnU mENq/qvPwmp3Hva167q/fb7XXVao9yq07yuIgYxZ+LVmFsBnz9VyhYc1WNuwV2uKcZ3d fxdkY9syhWzlamq1ou1xJRoP9VeLu04gq0ER2z3KFDi0XBOgHl+r9NYUrvNqkuqVyHEw DrOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HUY6OkQ8; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u22si28451890ejc.544.2021.01.04.08.10.13; Mon, 04 Jan 2021 08:10:37 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=HUY6OkQ8; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729351AbhADQIB (ORCPT + 99 others); Mon, 4 Jan 2021 11:08:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:38872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728691AbhADQBx (ORCPT ); Mon, 4 Jan 2021 11:01:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EB05F224D2; Mon, 4 Jan 2021 16:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609776098; bh=dM5Mv6sIRfVrmAb6P2xDAxq9iPE1eI4jm2Z3Kndta5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUY6OkQ8r2MY7SdAGnCWCVgh8EdA4hArLNZUabPRG/WtmaPPL5z8d+apRxfcVUMqD U4Ehdjm1GEuiB+MMyDtWXqnoH7Ogi+Uue8pUjukP9qwfa2RQDEQV5I9+U3M5+gLnmA n660Cck6WNs2IMuXzBLBC6y2QGdtYCqmQOv0NLX0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe Subject: [PATCH 5.10 20/63] io_uring: fix io_sqe_files_unregister() hangs Date: Mon, 4 Jan 2021 16:57:13 +0100 Message-Id: <20210104155709.797363028@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155708.800470590@linuxfoundation.org> References: <20210104155708.800470590@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov commit 1ffc54220c444774b7f09e6d2121e732f8e19b94 upstream. io_sqe_files_unregister() uninterruptibly waits for enqueued ref nodes, however requests keeping them may never complete, e.g. because of some userspace dependency. Make sure it's interruptible otherwise it would hang forever. Cc: stable@vger.kernel.org # 5.6+ Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -941,6 +941,10 @@ enum io_mem_account { ACCT_PINNED, }; +static void destroy_fixed_file_ref_node(struct fixed_file_ref_node *ref_node); +static struct fixed_file_ref_node *alloc_fixed_file_ref_node( + struct io_ring_ctx *ctx); + static void __io_complete_rw(struct io_kiocb *req, long res, long res2, struct io_comp_state *cs); static void io_cqring_fill_event(struct io_kiocb *req, long res); @@ -7004,11 +7008,15 @@ static void io_sqe_files_set_node(struct static int io_sqe_files_unregister(struct io_ring_ctx *ctx) { struct fixed_file_data *data = ctx->file_data; - struct fixed_file_ref_node *ref_node = NULL; + struct fixed_file_ref_node *backup_node, *ref_node = NULL; unsigned nr_tables, i; + int ret; if (!data) return -ENXIO; + backup_node = alloc_fixed_file_ref_node(ctx); + if (!backup_node) + return -ENOMEM; spin_lock_bh(&data->lock); ref_node = data->node; @@ -7020,7 +7028,18 @@ static int io_sqe_files_unregister(struc /* wait for all refs nodes to complete */ flush_delayed_work(&ctx->file_put_work); - wait_for_completion(&data->done); + do { + ret = wait_for_completion_interruptible(&data->done); + if (!ret) + break; + ret = io_run_task_work_sig(); + if (ret < 0) { + percpu_ref_resurrect(&data->refs); + reinit_completion(&data->done); + io_sqe_files_set_node(data, backup_node); + return ret; + } + } while (1); __io_sqe_files_unregister(ctx); nr_tables = DIV_ROUND_UP(ctx->nr_user_files, IORING_MAX_FILES_TABLE); @@ -7031,6 +7050,7 @@ static int io_sqe_files_unregister(struc kfree(data); ctx->file_data = NULL; ctx->nr_user_files = 0; + destroy_fixed_file_ref_node(backup_node); return 0; }