Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1821090imm; Mon, 3 Sep 2018 10:17:27 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb+NxYROjbuWLACWiPUqmXEpYgBYSvUMeOGwBiXN5paLqaMO1ooQuc276f+F/RxHFkqw69A X-Received: by 2002:aa7:831b:: with SMTP id t27-v6mr30417065pfm.81.1535995047368; Mon, 03 Sep 2018 10:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995047; cv=none; d=google.com; s=arc-20160816; b=Dwwct5+5l63a86iG4ARApuXeTdwq6oX79HRwUOC0G2GRAmtmfRvrPlY3Vkv3t1Z9ze MpnJYBtc3FBB9uIoyNVLjEgsM75+gBxmEysKFM3iFVRipa0CxC1a14KS+zTR0fmPz4Be Vsb+LLxvucfrRl1Mna/3aflDcuv5Z7oXOTBC0Eg5I7RaXWkFfMwxgo7LxbT+K56Rk8mb /DGCnRe6QFSNbI4HSjxCjt0ishnWqWS/6U0q9vKaIkQOHsgqTXxulavrh8lBbfEN3dh4 Jj5C982bOpMBPIIkcvgtdvKa38FlKyKir/D2tJbqGGcctAbCYwhgj9vZUEbINkEnclTM Tv0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=V9mOKxHvc5LG/BouDCeuVXXNy0Wuh3rDloLS+CIESzY=; b=rhNG/+ZpZvN+8EcQ/kTi1VMpI7eYd4Fda9AbLDrNLGrto1aNifxjSf9mVjVgjl0Buc e4FUElkLLR717cH/csI1idMWrJXuZE9H7jTOW3CtBG/D+Zo9233YD8xtQCebhLLZGFna UfuK2qgLec+jK9S+Sk+nBTrOhwWv7BcU6TDkZuKxEUCWtkZumrfnVXKkUlrNOuXlSuU5 +OqNpDPJXpqIk4rHNyf80A9xCGL6D6xmYljcU38y7Ido998Hp/6raZNVFmk45WGOOVJc 4yAxQN9PseTOZc/Nksd7RmBtgWLWJAK2V9oAhvh73m2HEU0QNsvw4TR6L04r8q0pkt0F 04QQ== ARC-Authentication-Results: i=1; mx.google.com; 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 h62-v6si18268828pge.298.2018.09.03.10.17.12; Mon, 03 Sep 2018 10:17:27 -0700 (PDT) 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; 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 S1729719AbeICVgp (ORCPT + 99 others); Mon, 3 Sep 2018 17:36:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42424 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727944AbeICVgo (ORCPT ); Mon, 3 Sep 2018 17:36:44 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 79D9AD02; Mon, 3 Sep 2018 17:15:40 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 014/165] nbd: dont requeue the same request twice. Date: Mon, 3 Sep 2018 18:55:00 +0200 Message-Id: <20180903165655.718803447@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit d7d94d48a272fd7583dc3c83acb8f5ed4ef456a4 ] We can race with the snd timeout and the per-request timeout and end up requeuing the same request twice. We can't use the send_complete completion to tell if everything is ok because we hold the tx_lock during send, so the timeout stuff will block waiting to mark the socket dead, and we could be marked complete and still requeue. Instead add a flag to the socket so we know whether we've been requeued yet. Signed-off-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/block/nbd.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -112,12 +112,15 @@ struct nbd_device { struct task_struct *task_setup; }; +#define NBD_CMD_REQUEUED 1 + struct nbd_cmd { struct nbd_device *nbd; int index; int cookie; struct completion send_complete; blk_status_t status; + unsigned long flags; }; #if IS_ENABLED(CONFIG_DEBUG_FS) @@ -146,6 +149,14 @@ static inline struct device *nbd_to_dev( return disk_to_dev(nbd->disk); } +static void nbd_requeue_cmd(struct nbd_cmd *cmd) +{ + struct request *req = blk_mq_rq_from_pdu(cmd); + + if (!test_and_set_bit(NBD_CMD_REQUEUED, &cmd->flags)) + blk_mq_requeue_request(req, true); +} + static const char *nbdcmd_to_ascii(int cmd) { switch (cmd) { @@ -328,7 +339,7 @@ static enum blk_eh_timer_return nbd_xmit nbd_mark_nsock_dead(nbd, nsock, 1); mutex_unlock(&nsock->tx_lock); } - blk_mq_requeue_request(req, true); + nbd_requeue_cmd(cmd); nbd_config_put(nbd); return BLK_EH_NOT_HANDLED; } @@ -484,6 +495,7 @@ static int nbd_send_cmd(struct nbd_devic nsock->pending = req; nsock->sent = sent; } + set_bit(NBD_CMD_REQUEUED, &cmd->flags); return BLK_STS_RESOURCE; } dev_err_ratelimited(disk_to_dev(nbd->disk), @@ -525,6 +537,7 @@ send_pages: */ nsock->pending = req; nsock->sent = sent; + set_bit(NBD_CMD_REQUEUED, &cmd->flags); return BLK_STS_RESOURCE; } dev_err(disk_to_dev(nbd->disk), @@ -793,7 +806,7 @@ again: */ blk_mq_start_request(req); if (unlikely(nsock->pending && nsock->pending != req)) { - blk_mq_requeue_request(req, true); + nbd_requeue_cmd(cmd); ret = 0; goto out; } @@ -806,7 +819,7 @@ again: dev_err_ratelimited(disk_to_dev(nbd->disk), "Request send failed, requeueing\n"); nbd_mark_nsock_dead(nbd, nsock, 1); - blk_mq_requeue_request(req, true); + nbd_requeue_cmd(cmd); ret = 0; } out: @@ -831,6 +844,7 @@ static blk_status_t nbd_queue_rq(struct * done sending everything over the wire. */ init_completion(&cmd->send_complete); + clear_bit(NBD_CMD_REQUEUED, &cmd->flags); /* We can be called directly from the user space process, which means we * could possibly have signals pending so our sendmsg will fail. In @@ -1446,6 +1460,7 @@ static int nbd_init_request(struct blk_m { struct nbd_cmd *cmd = blk_mq_rq_to_pdu(rq); cmd->nbd = set->driver_data; + cmd->flags = 0; return 0; }