Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6098955rwn; Mon, 12 Sep 2022 21:26:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR6vY1LAZvp+NvBDeAFMt3cJjTBEor6+edCBFtK2GjvqG1gymgLnRPSBxsPFewCnMQE6DIlH X-Received: by 2002:a05:6a00:2382:b0:542:8738:c103 with SMTP id f2-20020a056a00238200b005428738c103mr11177601pfc.17.1663043203655; Mon, 12 Sep 2022 21:26:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663043203; cv=none; d=google.com; s=arc-20160816; b=HwTGOsN/3mOfC8oYLYfuURhNygswVok3ZFc7GJ6pQMBgtER4fRI7nVZqjPyPgkyyRv H+XnJQ4TELOp7469lWE5Jnsjn9Sd6f2BONrxGBIwZYf12w6pvzzuVFK3UgEdBxtAT02u BcRxH4okm/zHmMAHFWd2xtbueY1Cy2Dk7M42FBCSIr7IKkKMx0N/nLdNEqOp4SQfgsKV 6qU6eZHvtKgN2HPI1/N9fcNI4I1dz6zbflfrzyDqnxpCT20HaAX8V4mRY86HOQmh1TFW 4tOx7VXtiVCIcaGnMauaM1ek6aeFDJ+raa20d4whRbF2bKSQLlxGVOLSZ9ikrAdEhr5k pzSw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VUZHas3HzWtP/GQxGSmQozTHiX9AEFLKITV3F2aFPNA=; b=H3hOJoXLfGUxDxmr8GnphFlCUPrBIJbqnNMuivEXLaiILJkwluo7sOutRIfcPtf2EG b4V8zHCq/FoRiOYeOTy08zyPxACZSGx9a/OfxGjwL2NnIFJkOvwoYRCmnZvCePXipw/x bt3Woe+qdX7lNc1jOQicjXtrt4qMHrBhgkai9y6iLvw40TybGk1a0YaM5XNpZL3qYK4c 9aVKlz9Oc8wpntco2MvL+ctatU6KIYrgCvXBEpN/m2cvrzkpkIPRe5kINB9CpndzIzPV RsVeaEwIjgZMVGs7zLuU5b6hLYzUo6Qr3uTnWPAMATSSmAcSQoUAGzp0pzTnt5fGGdfd 9xlw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a170902d54800b0016eeafbe7e7si10108513plf.34.2022.09.12.21.26.31; Mon, 12 Sep 2022 21:26:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbiIMES6 (ORCPT + 99 others); Tue, 13 Sep 2022 00:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbiIMESv (ORCPT ); Tue, 13 Sep 2022 00:18:51 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41B0453D2B; Mon, 12 Sep 2022 21:18:47 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=ziyangzhang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VPccy7U_1663042709; Received: from localhost.localdomain(mailfrom:ZiyangZhang@linux.alibaba.com fp:SMTPD_---0VPccy7U_1663042709) by smtp.aliyun-inc.com; Tue, 13 Sep 2022 12:18:44 +0800 From: ZiyangZhang To: ming.lei@redhat.com Cc: axboe@kernel.dk, xiaoguang.wang@linux.alibaba.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, joseph.qi@linux.alibaba.com, ZiyangZhang Subject: [PATCH V3 1/7] ublk_drv: check 'current' instead of 'ubq_daemon' Date: Tue, 13 Sep 2022 12:17:01 +0800 Message-Id: <20220913041707.197334-2-ZiyangZhang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220913041707.197334-1-ZiyangZhang@linux.alibaba.com> References: <20220913041707.197334-1-ZiyangZhang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This check is not atomic. So with recovery feature, ubq_daemon may be modified simultaneously by recovery task. Instead, check 'current' is safe here because 'current' never changes. Also add comment explaining this check, which is really important for understanding recovery feature. Signed-off-by: ZiyangZhang Reviewed-by: Ming Lei --- drivers/block/ublk_drv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 6a4a94b4cdf4..c39b67d7133d 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -645,14 +645,22 @@ static inline void __ublk_rq_task_work(struct request *req) struct ublk_device *ub = ubq->dev; int tag = req->tag; struct ublk_io *io = &ubq->ios[tag]; - bool task_exiting = current != ubq->ubq_daemon || ubq_daemon_is_dying(ubq); unsigned int mapped_bytes; pr_devel("%s: complete: op %d, qid %d tag %d io_flags %x addr %llx\n", __func__, io->cmd->cmd_op, ubq->q_id, req->tag, io->flags, ublk_get_iod(ubq, req->tag)->addr); - if (unlikely(task_exiting)) { + /* + * Task is exiting if either: + * + * (1) current != ubq_daemon. + * io_uring_cmd_complete_in_task() tries to run task_work + * in a workqueue if ubq_daemon(cmd's task) is PF_EXITING. + * + * (2) current->flags & PF_EXITING. + */ + if (unlikely(current != ubq->ubq_daemon || current->flags & PF_EXITING)) { blk_mq_end_request(req, BLK_STS_IOERR); mod_delayed_work(system_wq, &ub->monitor_work, 0); return; -- 2.27.0