Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2698231ybb; Mon, 30 Mar 2020 11:08:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv+3cs29nLcYUn4GVbHHkYqxPcXyeoN05wyJgQdo3RZWTOCyx1ZkjyysKGzuWXcicfkckw8 X-Received: by 2002:a9d:68d0:: with SMTP id i16mr9882071oto.291.1585591687092; Mon, 30 Mar 2020 11:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585591687; cv=none; d=google.com; s=arc-20160816; b=Cs6752aLfAKY1BbaclOp7hhgZJ3Y7hpnoupUoidAUMSREbBWjAR0XqsL0N+HgWur15 lSto3u33ykkwmwXOMKFscjfBGxKWcvhHNVHnUlJsTdpQ6ifJe5wNvfkaKIP9sOVWOHg+ ZTlwFpFMqsh30vhu7OJxEXQwz+0q34Xb9W9mKxLCfntHBtLpkv+gdhPtXiYaG7qi5eun mjPNkoseBrE3ckwpCcDV3zbxyEH3keQ15oKB9AAxadcu1QkC/PaL/sBKoVAW1yJ+L4ea wF2NxIbeMkX0JrCZqTm91cgrtcpPlEyecUQzlBaWNw8iX92qOiAAvbD3WE/fCC6pEEfB RN2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=f6uuZ8AQmEmQPNxvCDcaE9ajAQMzpT8US7URBUmbX+0=; b=UjhDhxb94u3pkosWcIqdnBaPlG7JYLxoNgflRp73x2NcdxOrigVtl/N3H1L4SmxATH rauHjBAr7DAD6cQpugo2cdc6RITW/1qzyfjYhLlvCKkdQszNsuptF6rS4CXr2YWeQ401 C3UYOSj1W/+NKh/UNOuuoba1kHDVbZ/vXNKeU6OtsFpyqqI9bylZpNeb2Aam7TxeSPiN 5R5+N5K6bqsBVLXQgzSkLctUMqH9uG4g+I0qeYsh6HFgE3Ro6B3hxdVUEJNpJBXcbaME gry4wwZAWXrdYrEMWkULl47uDo1w2vybBQxQhqKz1GfgPfAKX8yZcmO7AK4pduuQ9yCS +UTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b=OJ2fuHRD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d145si6171604oob.68.2020.03.30.11.07.54; Mon, 30 Mar 2020 11:08:07 -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; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b=OJ2fuHRD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbgC3SET (ORCPT + 99 others); Mon, 30 Mar 2020 14:04:19 -0400 Received: from linux.microsoft.com ([13.77.154.182]:42362 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727815AbgC3SES (ORCPT ); Mon, 30 Mar 2020 14:04:18 -0400 Received: by linux.microsoft.com (Postfix, from userid 1004) id 6B38020B46F0; Mon, 30 Mar 2020 11:04:17 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6B38020B46F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1585591457; bh=f6uuZ8AQmEmQPNxvCDcaE9ajAQMzpT8US7URBUmbX+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To:From; b=OJ2fuHRDWI1KPvCxE2Rjw286mDUXEhZI+eImjVbM2bUtOENhxgueC+bFCcAF3CaVC 5HjEOZo7M5UdrYfaxfntwnfeeQTekV4fLCxlMFWxKLaqx1JSB2d6pLS1udk5QncUSi QBNr6NXbXfer42QDESpKDpRZgx4CXIfiJ0mxn6fc= From: longli@linuxonhyperv.com To: Steve French , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org Cc: Long Li Subject: [PATCH 2/2] cifs: smbd: Check send queue size before posting a send Date: Mon, 30 Mar 2020 11:04:07 -0700 Message-Id: <1585591447-11741-2-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1585591447-11741-1-git-send-email-longli@linuxonhyperv.com> References: <1585591447-11741-1-git-send-email-longli@linuxonhyperv.com> Reply-To: longli@microsoft.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Long Li Sometimes the remote peer may return more send credits than the send queue depth. If all the send credits are used to post senasd, we may overflow the send queue. Fix this by checking the send queue size before posting a send. Signed-off-by: Long Li --- fs/cifs/smbdirect.c | 11 ++++++++++- fs/cifs/smbdirect.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/cifs/smbdirect.c b/fs/cifs/smbdirect.c index 79d8dcbd0034..c7ef2d7ce0ef 100644 --- a/fs/cifs/smbdirect.c +++ b/fs/cifs/smbdirect.c @@ -287,6 +287,7 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc) if (atomic_dec_and_test(&request->info->send_pending)) wake_up(&request->info->wait_send_pending); + wake_up(&request->info->wait_post_send); mempool_free(request, request->info->request_mempool); } @@ -939,7 +940,14 @@ static int smbd_post_send(struct smbd_connection *info, send_wr.opcode = IB_WR_SEND; send_wr.send_flags = IB_SEND_SIGNALED; - atomic_inc(&info->send_pending); +wait_sq: + wait_event(info->wait_post_send, + atomic_read(&info->send_pending) < info->send_credit_target); + if (unlikely(atomic_inc_return(&info->send_pending) > + info->send_credit_target)) { + atomic_dec(&info->send_pending); + goto wait_sq; + } rc = ib_post_send(info->id->qp, &send_wr, NULL); if (rc) { @@ -1733,6 +1741,7 @@ static struct smbd_connection *_smbd_get_connection( init_waitqueue_head(&info->wait_send_pending); atomic_set(&info->send_pending, 0); + init_waitqueue_head(&info->wait_post_send); INIT_WORK(&info->disconnect_work, smbd_disconnect_rdma_work); INIT_WORK(&info->post_send_credits_work, smbd_post_send_credits); diff --git a/fs/cifs/smbdirect.h b/fs/cifs/smbdirect.h index f70c7119a456..07c8f5638c39 100644 --- a/fs/cifs/smbdirect.h +++ b/fs/cifs/smbdirect.h @@ -114,6 +114,7 @@ struct smbd_connection { /* Activity accoutning */ atomic_t send_pending; wait_queue_head_t wait_send_pending; + wait_queue_head_t wait_post_send; /* Receive queue */ struct list_head receive_queue; -- 2.17.1