Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4160017pxb; Mon, 27 Sep 2021 10:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdwRCz1d4VZ+th6UxzlS8kBvRcKeZ8pm8iPWVAHBlGP9Y/xAZmPPbKRAV6RR9C+srCGaCP X-Received: by 2002:a17:902:db11:b0:13c:7a6e:4b57 with SMTP id m17-20020a170902db1100b0013c7a6e4b57mr914088plx.43.1632764194901; Mon, 27 Sep 2021 10:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632764194; cv=none; d=google.com; s=arc-20160816; b=G3xnoz4xdmmkdX9Kpd7Vd+TbRAqePrEjhyR6sIBCM01N7rr5jB/fNh2jnquaC6hfDd B4tMbetMT8pJNc9rh6xicVJH9hQ8g2r1B/RPwzjUA1wJmF8HCOD1JE0iB16NQ8MZz+07 0/wYjqetxFotrmE0ilvjHyyT24OsT4Bqmx0YTj8QEmAXB/9oqAAn8JLHIZb4zNmA+3xK w2kqtqyoWSbIRSPN0M6K2wpahfoV86frV9QwzXgA4H8NrTx6L4b41XOBy25squ0arN/b +PX7rs081WFlpD51mmOq/7LtTMBBs53JTpLgM9Fsu+ROJdKxLMYGUwzTAu3e0bnQvKMz DO+Q== 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=yd8u/+I6LOUJlXscY1mgEYCtMih25atD8JkL6iVb3gg=; b=GgXwQ9608UGTQGgbhxCxcYqMb9qa3Dwf3vYDM5/fO4FibYNqDpIg52dhdW8fpYKXrC muc3rNOQI9cfdHN97L+wHOH4s5Uo9V3Qt4mHeNQ6yCzIm6ol65hX3s23rajs404FF9PO 6YSRu7DZVujqHhvWEdvB8O6jBImlFIO5ORMr0WqbCBw2mGkaFUkAywiijTlzXO8Lur0t KepslBP8S/o0kvQ3AZ+R0ugO9+sHUrKJbQ5IT8tBHra5IqJzSf3rOtpFuONENThyR50U iT3wexyO5/T9aBfhUV/oFKKwKi//qvq9L29ypdAMM2/DLvXNLNBuPXUhTF1X6tN7QGMc La4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WRxEHycx; 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 y28si21369405pgl.452.2021.09.27.10.36.20; Mon, 27 Sep 2021 10:36:34 -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=WRxEHycx; 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 S237989AbhI0Rga (ORCPT + 99 others); Mon, 27 Sep 2021 13:36:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:46358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237943AbhI0Raz (ORCPT ); Mon, 27 Sep 2021 13:30:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CBA76113D; Mon, 27 Sep 2021 17:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632763387; bh=FyIoA/F2sgzljwJzCSywgfeR1zCGkXO2Y7KRzjjcGko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WRxEHycxt+KiBoUxBeDfhdayiaPXHol1BYx9+OGQhxKRBhRtliDy2zyfyj63KjTpH Vx5IgBSa0wIdtyTy06Hq6JfIqwlrg52fklw/gSRdGRQXDeqjwD12B6xW3I2sPF8xsa c2/E+BsswQJmbzlSEEcNvpTkwqG+gJcikNkkcA9I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Nowak, Lukasz" , Sagi Grimberg , Keith Busch , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.14 098/162] nvme-tcp: fix incorrect h2cdata pdu offset accounting Date: Mon, 27 Sep 2021 19:02:24 +0200 Message-Id: <20210927170236.838116698@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170233.453060397@linuxfoundation.org> References: <20210927170233.453060397@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: Sagi Grimberg [ Upstream commit e371af033c560b9dd1e861f8f0b503142bf0a06c ] When the controller sends us multiple r2t PDUs in a single request we need to account for it correctly as our send/recv context run concurrently (i.e. we get a new r2t with r2t_offset before we updated our iterator and req->data_sent marker). This can cause wrong offsets to be sent to the controller. To fix that, we will first know that this may happen only in the send sequence of the last page, hence we will take the r2t_offset to the h2c PDU data_offset, and in nvme_tcp_try_send_data loop, we make sure to increment the request markers also when we completed a PDU but we are expecting more r2t PDUs as we still did not send the entire data of the request. Fixes: 825619b09ad3 ("nvme-tcp: fix possible use-after-completion") Reported-by: Nowak, Lukasz Tested-by: Nowak, Lukasz Signed-off-by: Sagi Grimberg Reviewed-by: Keith Busch Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/tcp.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 19a711395cdc..fd28a23d45ed 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -614,7 +614,7 @@ static int nvme_tcp_setup_h2c_data_pdu(struct nvme_tcp_request *req, cpu_to_le32(data->hdr.hlen + hdgst + req->pdu_len + ddgst); data->ttag = pdu->ttag; data->command_id = nvme_cid(rq); - data->data_offset = cpu_to_le32(req->data_sent); + data->data_offset = pdu->r2t_offset; data->data_length = cpu_to_le32(req->pdu_len); return 0; } @@ -940,7 +940,15 @@ static int nvme_tcp_try_send_data(struct nvme_tcp_request *req) nvme_tcp_ddgst_update(queue->snd_hash, page, offset, ret); - /* fully successful last write*/ + /* + * update the request iterator except for the last payload send + * in the request where we don't want to modify it as we may + * compete with the RX path completing the request. + */ + if (req->data_sent + ret < req->data_len) + nvme_tcp_advance_req(req, ret); + + /* fully successful last send in current PDU */ if (last && ret == len) { if (queue->data_digest) { nvme_tcp_ddgst_final(queue->snd_hash, @@ -952,7 +960,6 @@ static int nvme_tcp_try_send_data(struct nvme_tcp_request *req) } return 1; } - nvme_tcp_advance_req(req, ret); } return -EAGAIN; } -- 2.33.0