Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2351728pxb; Mon, 20 Sep 2021 19:48:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKOS/Uay67wHyK75jQoXmi9sfb6mHfJVwD2GG+HLrBEBDdZBMsP7UEzrTobfPVOlaDPRTy X-Received: by 2002:a50:9b17:: with SMTP id o23mr33486106edi.341.1632192484655; Mon, 20 Sep 2021 19:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192484; cv=none; d=google.com; s=arc-20160816; b=E/newGfObo5I4yUKFrq2g0leoQa7Zv29QaACeDyFrVeUMMJypkkih3wxh2lhDPZpz+ noTGF7tPtpLk2L1kzNkZW6QmPy+JefI1S5HRkgiPcsA4rWbSbelWxpJgK80f/ND7c17V 9ENbEKvKf5Y+TyokEPF5bVzUiq8Ws9tPNtGAPnEYmEbrAuSrWBevvj/vjQOIhb29dlVi TJeLX0bEd0PHD3LIiHUFn60lwuevs/Z3dFkGYzSl+WEVVh6xpPFCmN5X//ob/4m7hS1r DM2Egrdn1dtD4ryQNi1G7yhB+7ml2RIZHe62BifU1ZQ0l50TI2gn/tyWQWzz2Q1ZviBs VeFg== 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=DcO4eK1mQxva8V1BpsVHz2GxpiDGdjzLBFLJR4mjFY0=; b=Foc9nFjYIlgmh8zVbFAmRJLtKA2xjprrjC7aua5IGTWy0V/nX3ysHDkaBurXHPPB/u Pz7S8olGwqs/FZBJLoj01tiXed80u7OKi/zJF7ia/+5lEToNMaKCbGZnhUM96yDSD3Ja mKCM9qSMkT4+QzXhWIHO+SN+chqZo5DT7z6ejEEx2jgXqXipWAgiG7/ANSqemqv7Chic OCUgrdHLpC4n4B9OswnpoucsgUimCDkj/TH62YJoDMATSDgMuraPUS/ZSoIn62icT5hy kzKVT/2Vv9nguYGDR/bJcrUnSoB6P62ziSZthf+vUF8grH9Njm96vhoWzt6g4qgneGfQ TYKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gXXkIoa6; 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 i4si17805181ejj.165.2021.09.20.19.47.40; Mon, 20 Sep 2021 19:48:04 -0700 (PDT) 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=gXXkIoa6; 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 S1380032AbhITScA (ORCPT + 99 others); Mon, 20 Sep 2021 14:32:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:44428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378761AbhITS0W (ORCPT ); Mon, 20 Sep 2021 14:26:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 59D4C632DD; Mon, 20 Sep 2021 17:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158738; bh=bWFyB2GCQjZchfq8B6SsuD9LGSGlwgPReH0hiIu473g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gXXkIoa619v9m9UrtkSO4IrE+2PmPXfS/nu+EEEsvyXb998zbDAceLYtfpx0cPTPB UmknDSr1TKn6v3IPsq3JifrS9bieHd/5UnwiguIW+m0wAyLkLHfnczyBpF/JgIAicR gQW921aHHgVIwgOAG9YSmDnpuVCMBPw5uQ5QK2hM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Jones , Keith Busch , Sagi Grimberg , Christoph Hellwig Subject: [PATCH 5.10 034/122] nvme-tcp: fix io_work priority inversion Date: Mon, 20 Sep 2021 18:43:26 +0200 Message-Id: <20210920163916.915224696@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163915.757887582@linuxfoundation.org> References: <20210920163915.757887582@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: Keith Busch commit 70f437fb4395ad4d1d16fab9a1ad9fbc9fc0579b upstream. Dispatching requests inline with the .queue_rq() call may block while holding the send_mutex. If the tcp io_work also happens to schedule, it may see the req_list is non-empty, leaving "pending" true and remaining in TASK_RUNNING. Since io_work is of higher scheduling priority, the .queue_rq task may not get a chance to run, blocking forward progress and leading to io timeouts. Instead of checking for pending requests within io_work, let the queueing restart io_work outside the send_mutex lock if there is more work to be done. Fixes: a0fdd1418007f ("nvme-tcp: rerun io_work if req_list is not empty") Reported-by: Samuel Jones Signed-off-by: Keith Busch Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/tcp.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -273,6 +273,12 @@ static inline void nvme_tcp_send_all(str } while (ret > 0); } +static inline bool nvme_tcp_queue_more(struct nvme_tcp_queue *queue) +{ + return !list_empty(&queue->send_list) || + !llist_empty(&queue->req_list) || queue->more_requests; +} + static inline void nvme_tcp_queue_request(struct nvme_tcp_request *req, bool sync, bool last) { @@ -293,9 +299,10 @@ static inline void nvme_tcp_queue_reques nvme_tcp_send_all(queue); queue->more_requests = false; mutex_unlock(&queue->send_mutex); - } else if (last) { - queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); } + + if (last && nvme_tcp_queue_more(queue)) + queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); } static void nvme_tcp_process_req_list(struct nvme_tcp_queue *queue) @@ -890,12 +897,6 @@ done: read_unlock_bh(&sk->sk_callback_lock); } -static inline bool nvme_tcp_queue_more(struct nvme_tcp_queue *queue) -{ - return !list_empty(&queue->send_list) || - !llist_empty(&queue->req_list) || queue->more_requests; -} - static inline void nvme_tcp_done_send_req(struct nvme_tcp_queue *queue) { queue->request = NULL; @@ -1132,8 +1133,7 @@ static void nvme_tcp_io_work(struct work pending = true; else if (unlikely(result < 0)) break; - } else - pending = !llist_empty(&queue->req_list); + } result = nvme_tcp_try_recv(queue); if (result > 0)