Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp404972pxu; Tue, 1 Dec 2020 14:25:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4dJA+60OVAtOXWo+77u/43JSlEM85/aWVdDbzepmx7Fs6HbjBO03F4DX/ngwwGMC+EQxy X-Received: by 2002:a05:6402:895:: with SMTP id e21mr5363243edy.284.1606861539540; Tue, 01 Dec 2020 14:25:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861539; cv=none; d=google.com; s=arc-20160816; b=EMK2UBR6tzK+/hFhCTUYhi/PvlsH3QB/qwt0nIShxLtj7LUfM4O0f53Yf1ko1ERE4w 2JSgfudwrFIg6KO+SiRMGX5DEAC4xmEVsMrWb/ocCj94U+E45h049fj0R92eD2MPjn1B 2ea2d83yIbzFCJNJUVBWnJcaO1q6vPoSeJI44pgD/vrATOlHT57o3z83d/1BEu4Akd9W lJQOF1XYn47BN7DyfKJLwX4EocfyW2aFthAkorxJ2KKbscKdQVfCARAjf1GCHvN2XgX7 T2+kPCNyK8UsjDIOcZ6lkK1ZkYV7F0Vstg5EtZ9dYzSKni1WYqEaYROcyhiRSFT0p4Rp kSTg== 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=iCR3hPs0zfBzEibfblXtKq95WrNngCjs5pKPFaHx7Qg=; b=tWcKPmJAzTU3OGDXyvxxFCtRy+E15xz31f6ufJjUTn+rdUlfa/Kg+HafMSxuo5vt9b mIn/Ni/9p1kFVg7SLqiHLPE6TBxFQezzdcft6DXBYNLeEpks5cf+Hb+6u5sBfSw/50Y+ /Z1M8OlpGkX5TxJRFeoGDTXutcZu9f+Q6V+rqVIqo5jr9NU7QCqRtwyFHqaEg016orC/ KziUCtB/z/qD0cwRSaVDZXGnSSRlw6y8jQHP7eqfXAY8+IA08/Jqcj26SpVUL3GHV5Ts 0UIb4jMTRh4wmjxMqDyg5DcRv7L+gemyRpWtvYoeRR40I3ma4PM8G9Sl6bbX+YLKd9gH nCyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Dzq5dRk+; 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 bt1si789069edb.267.2020.12.01.14.25.17; Tue, 01 Dec 2020 14:25:39 -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=Dzq5dRk+; 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 S2389429AbgLAJJX (ORCPT + 99 others); Tue, 1 Dec 2020 04:09:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:45260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389166AbgLAJIB (ORCPT ); Tue, 1 Dec 2020 04:08:01 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A04D620809; Tue, 1 Dec 2020 09:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813640; bh=9xLDaTi0dTlAzNe8cBS4SZWGr7Ub7YMtIZ7IP9DxpDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dzq5dRk+IICbVOYiYGbQ2oZxj3ywJNP8/qj6m7VJuW28qQ2Hrz/YJq10evI4FyCdJ m+2LkpqIn90sDOZvNWfc8NrlUX+pJSJoZD21yUBGMrHhkd3NP8jp1KUnT1zxbgquS/ jCnRXfqzeiKR8DGr+Tsyawi6BZvoQEzxOuSyH9Gw= 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.9 002/152] io_uring: order refnode recycling Date: Tue, 1 Dec 2020 09:51:57 +0100 Message-Id: <20201201084711.960794113@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@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 e297822b20e7fe683e107aea46e6402adcf99c70 upstream. Don't recycle a refnode until we're done with all requests of nodes ejected before. Signed-off-by: Pavel Begunkov Cc: stable@vger.kernel.org # v5.7+ Signed-off-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -200,6 +200,7 @@ struct fixed_file_ref_node { struct list_head file_list; struct fixed_file_data *file_data; struct llist_node llist; + bool done; }; struct fixed_file_data { @@ -7106,10 +7107,6 @@ static void __io_file_put_work(struct fi kfree(pfile); } - spin_lock(&file_data->lock); - list_del(&ref_node->node); - spin_unlock(&file_data->lock); - percpu_ref_exit(&ref_node->refs); kfree(ref_node); percpu_ref_put(&file_data->refs); @@ -7136,17 +7133,33 @@ static void io_file_put_work(struct work static void io_file_data_ref_zero(struct percpu_ref *ref) { struct fixed_file_ref_node *ref_node; + struct fixed_file_data *data; struct io_ring_ctx *ctx; - bool first_add; + bool first_add = false; int delay = HZ; ref_node = container_of(ref, struct fixed_file_ref_node, refs); - ctx = ref_node->file_data->ctx; + data = ref_node->file_data; + ctx = data->ctx; + + spin_lock(&data->lock); + ref_node->done = true; + + while (!list_empty(&data->ref_list)) { + ref_node = list_first_entry(&data->ref_list, + struct fixed_file_ref_node, node); + /* recycle ref nodes in order */ + if (!ref_node->done) + break; + list_del(&ref_node->node); + first_add |= llist_add(&ref_node->llist, &ctx->file_put_llist); + } + spin_unlock(&data->lock); + - if (percpu_ref_is_dying(&ctx->file_data->refs)) + if (percpu_ref_is_dying(&data->refs)) delay = 0; - first_add = llist_add(&ref_node->llist, &ctx->file_put_llist); if (!delay) mod_delayed_work(system_wq, &ctx->file_put_work, 0); else if (first_add) @@ -7170,6 +7183,7 @@ static struct fixed_file_ref_node *alloc INIT_LIST_HEAD(&ref_node->node); INIT_LIST_HEAD(&ref_node->file_list); ref_node->file_data = ctx->file_data; + ref_node->done = false; return ref_node; } @@ -7297,7 +7311,7 @@ static int io_sqe_files_register(struct ctx->file_data->cur_refs = &ref_node->refs; spin_lock(&ctx->file_data->lock); - list_add(&ref_node->node, &ctx->file_data->ref_list); + list_add_tail(&ref_node->node, &ctx->file_data->ref_list); spin_unlock(&ctx->file_data->lock); percpu_ref_get(&ctx->file_data->refs); return ret; @@ -7442,7 +7456,7 @@ static int __io_sqe_files_update(struct if (needs_switch) { percpu_ref_kill(data->cur_refs); spin_lock(&data->lock); - list_add(&ref_node->node, &data->ref_list); + list_add_tail(&ref_node->node, &data->ref_list); data->cur_refs = &ref_node->refs; spin_unlock(&data->lock); percpu_ref_get(&ctx->file_data->refs);