From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386050; b=djm9LeetvvmmplF59wAtbnXtIvfjRCpxZWCllS9apmI2she1HCm5VHCZsaHI/l5ezaGp Vjb7K7/iAedRxjaLoVg0MrGDlCaLUhDDPkC2aC3l+wJOkJwHda2pMeQpvuGgV0tocNoqC C6M9lIhBC1q2W2401qhzou1BON0mlfst0aynsxPptUhhm4XQHivT1xUTcEqToNNvzhoJI EPejr7BnIEcxgVnkzCT0lBcVqjFChW9tFUjGwwxzkt2XgsRmjSBApsa7hN2zPRm8jJZZQ gDDJgEWAowsxSX6UudJRopZvEEQixOU5Qs8mE/i/5+HwxqWlsMikYcaGgoY8YlGpy6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386050; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=sAxnNbUCJlx9Enmbp+oJcogc8FWxz1cFrCphePSiLrg=; b=jGDrC3ydwjmajI+i8XkQMIsUdczoY6oLLKnZXxcOKxV2wB/royJm6G+6oGnAQgaBjOO5 EgLp8xJOch8NQmpJIycHvR9Ur9Kv/UeJ9sjns1Gux+NDVXcalnSvGmhUdF51Race7pQ3O uwLk1oTBe9mReRBdCbnX1KdaRMcuNI1xgEPC8MI0lGWmxrimulj8ZEsNFOTyDdGMgmqKj a/VmIgYOn3XgJjIsn2SJ/fHAfFGe1UsfjszYgINst5nuG6+jr8r1InoujGz5bEGtKj/dg 2j0FRET97HcBtsLko3QR0v3dgR369FYaw8LUGva6j/Mp/0vi0m9VmJM5LpoYVhz3y8g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JwpJ+mnE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4905E606A322; Fri, 4 Dec 2026 12:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JwpJ+mnE Received: by smtp.kernel.org (Postfix) with ESMTPSA id B07E31F000C2; Fri, 4 Dec 2026 12:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386050; bh=sAxnNbUCJlx9Enmbp+oJcogc8FWxz1cFrCphePSiLrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JwpJ+mnEBFVMXT7Wj8hlqAhyotQVtN2OvoLF4YcGYvdGZen1A8lv0MArl/J7BAwqB I2u4Lejxic39tLl0aN33bZ35kSxWbbD3VTwVLfFqdV8PEcR94bOjKqerXbLYjsjXAL oHS+FPXB1znQm23/nnGuWaDhBSxxJeLsi+NNn/ck= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dmitry Bogdanov , Daniel Wagner , Keith Busch , Dickson Wu , Sasha Levin Subject: [PATCH 6.6 0803/1167] nvme-tcp: fix usage of page_frag_cache Date: Fri, 4 Dec 2026 19:03:50 +0900 Message-ID: <20261204100723.042462862@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Bogdanov commit 36ac05f7cfd59d90c597071304b14e98090d5dd1 upstream. nvme uses page_frag_cache to preallocate PDU for each preallocated request of block device. Block devices are created in parallel threads, consequently page_frag_cache is used in not thread-safe manner. That leads to incorrect refcounting of backstore pages and premature free. That can be catched by !sendpage_ok inside network stack: WARNING: CPU: 7 PID: 467 at ../net/core/skbuff.c:6931 skb_splice_from_iter+0xfa/0x310. tcp_sendmsg_locked+0x782/0xce0 tcp_sendmsg+0x27/0x40 sock_sendmsg+0x8b/0xa0 nvme_tcp_try_send_cmd_pdu+0x149/0x2a0 Then random panic may occur. Fix that by serializing the usage of page_frag_cache. Fixes: 4e893ca81170 ("nvme_core: scan namespaces asynchronously") Signed-off-by: Dmitry Bogdanov Signed-off-by: Daniel Wagner Signed-off-by: Keith Busch [ adapted to 6.6.y: no lockdep key cleanup in the queue teardown ] Signed-off-by: Dickson Wu Signed-off-by: Sasha Levin --- drivers/nvme/host/tcp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 9ccf33dc45a38..845a7139c5f78 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -121,6 +121,7 @@ struct nvme_tcp_queue { struct mutex queue_lock; struct mutex send_mutex; + struct mutex pf_cache_lock; struct llist_head req_list; struct list_head send_list; @@ -498,9 +499,11 @@ static int nvme_tcp_init_request(struct blk_mq_tag_set *set, struct nvme_tcp_queue *queue = &ctrl->queues[queue_idx]; u8 hdgst = nvme_tcp_hdgst_len(queue); + mutex_lock(&queue->pf_cache_lock); req->pdu = page_frag_alloc(&queue->pf_cache, sizeof(struct nvme_tcp_cmd_pdu) + hdgst, GFP_KERNEL | __GFP_ZERO); + mutex_unlock(&queue->pf_cache_lock); if (!req->pdu) return -ENOMEM; @@ -1438,9 +1441,11 @@ static int nvme_tcp_alloc_async_req(struct nvme_tcp_ctrl *ctrl) struct nvme_tcp_request *async = &ctrl->async_req; u8 hdgst = nvme_tcp_hdgst_len(queue); + mutex_lock(&queue->pf_cache_lock); async->pdu = page_frag_alloc(&queue->pf_cache, sizeof(struct nvme_tcp_cmd_pdu) + hdgst, GFP_KERNEL | __GFP_ZERO); + mutex_unlock(&queue->pf_cache_lock); if (!async->pdu) return -ENOMEM; @@ -1469,6 +1474,7 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid) kfree(queue->pdu); mutex_destroy(&queue->send_mutex); mutex_destroy(&queue->queue_lock); + mutex_destroy(&queue->pf_cache_lock); } static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) @@ -1644,6 +1650,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid) INIT_LIST_HEAD(&queue->send_list); mutex_init(&queue->send_mutex); INIT_WORK(&queue->io_work, nvme_tcp_io_work); + mutex_init(&queue->pf_cache_lock); if (qid > 0) queue->cmnd_capsule_len = nctrl->ioccsz * 16; @@ -1771,6 +1778,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid) err_destroy_mutex: mutex_destroy(&queue->send_mutex); mutex_destroy(&queue->queue_lock); + mutex_destroy(&queue->pf_cache_lock); return ret; } -- 2.53.0