From patchwork Mon Oct 12 13:26:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 11832711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25B4A92C for ; Mon, 12 Oct 2020 13:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 037A822203 for ; Mon, 12 Oct 2020 13:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510094; bh=cgclcrr2e0E/7dM2J/0jeypp1l2od/DQDTj+zsTO3sI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=m38UkvmfopsUizkJ4SLrCJrfLWkVPUJOIZIbnxLSzblgkIqO9exY+M9ftEoBjIbBn HZwUYpGj8xZAdCNMsUzUNdksy2/8LFHWljeF3/jnHNitosu5N47pSm2G+ysT8rLVkk a3/1CifQdtD3HVyqlugOaw1bjjAZidpM40Lf6ZSQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389003AbgJLNk7 (ORCPT ); Mon, 12 Oct 2020 09:40:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:43514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731463AbgJLNk5 (ORCPT ); Mon, 12 Oct 2020 09:40:57 -0400 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 5D70B22258; Mon, 12 Oct 2020 13:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510036; bh=cgclcrr2e0E/7dM2J/0jeypp1l2od/DQDTj+zsTO3sI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oyr7UMlFi/QUnfp3vJSa9SCXjvDCBLKULNq9bAvyXQjQJCJ3AES47xLusBqD3BddE 0Z4KbZ8fQKPQqSvdKzztVUcWQYW1MW2V0HNx8o5xhWd55BnI93I1/FbQDZwFaL8q2D 7hSLRAflEQ7ofJ+P2iyKgbC2HC5bykxwRgynlIGA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhuyinyin@bytedance.com, Muchun Song" , Jens Axboe , Muchun Song Subject: [PATCH 5.4 06/85] io_uring: Fix missing smp_mb() in io_cancel_async_work() Date: Mon, 12 Oct 2020 15:26:29 +0200 Message-Id: <20201012132633.159735629@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132632.846779148@linuxfoundation.org> References: <20201012132632.846779148@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Muchun Song The store to req->flags and load req->work_task should not be reordering in io_cancel_async_work(). We should make sure that either we store REQ_F_CANCE flag to req->flags or we see the req->work_task setted in io_sq_wq_submit_work(). Fixes: 1c4404efcf2c ("io_uring: make sure async workqueue is canceled on exit") Signed-off-by: Muchun Song Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2247,6 +2247,12 @@ restart: if (!ret) { req->work_task = current; + + /* + * Pairs with the smp_store_mb() (B) in + * io_cancel_async_work(). + */ + smp_mb(); /* A */ if (req->flags & REQ_F_CANCEL) { ret = -ECANCELED; goto end_req; @@ -3725,7 +3731,15 @@ static void io_cancel_async_work(struct req = list_first_entry(&ctx->task_list, struct io_kiocb, task_list); list_del_init(&req->task_list); - req->flags |= REQ_F_CANCEL; + + /* + * The below executes an smp_mb(), which matches with the + * smp_mb() (A) in io_sq_wq_submit_work() such that either + * we store REQ_F_CANCEL flag to req->flags or we see the + * req->work_task setted in io_sq_wq_submit_work(). + */ + smp_store_mb(req->flags, req->flags | REQ_F_CANCEL); /* B */ + if (req->work_task && (!files || req->files == files)) send_sig(SIGINT, req->work_task, 1); }