Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2018184ybb; Thu, 26 Mar 2020 19:42:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvY5XEWmTyQedmdHd9PXqD7hD3l7SOoY6uAN8AEudQ+JNzmnSRxIgQOqcvMN2STTUehMQ7/ X-Received: by 2002:a05:6830:20d5:: with SMTP id z21mr8509505otq.237.1585276978726; Thu, 26 Mar 2020 19:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585276978; cv=none; d=google.com; s=arc-20160816; b=XyRJf9DPM1n2Sh0ckHiA8YKe/d+3XVGXLSqKM49jYdV6yFtsHj1hArjuVtjoRjcwqp MJhjJDSeFKsUAcE0jtFWQZ8DJylKfgOpYSyXZtl3ykiWmE6PA4swyhCSAAqAINtgb6t6 lI6VATbrSNdHVHfEyodbxK4+R11uQ2k1qL3pv48gbnQ44/PYyJOQg/DLIoL0JjLeLtPy GnyX7GrBYSv50U4PIO/edRafIVRddU6JLcF7tYpZAiUoQdEPt8tke0QUeMWz5wscyxjh gbWmdjpROnUe9ssjW6/j1oFd1wViOyjVFOX/WZmMd3u2WuhsuUZTJ6zdO6w+4RnPwF0Y g07w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=zvffKctMIj2SFnhEj55/AzFnvDRhG2tE5Rzn8kutAEA=; b=Pp3jkYg+tNOXXx7FKVmjD6errOTPVLf2LuU/hL49JAwmBtgGFCpwkbb7fPzhi92Djx fF1YVWjN1+DHQ8ea1SajocBgLqiQO3vlpVN+Amo4gsywO6khF0jsgVPaukH+yNYzpKNU FEs3pyx8rKea05vkNe4VGRKhL+GsdkEQvzFobZ5wcNrLQjBlmk1/BDhTn2qeqBnoTDrm BGEEofLv9ov6DV7E/Yjurd6LAnNJ8MhYyeea0JufiO+gGyMEb4yWegzIuc8aghCfHnrf jqCvqHlXqfRpnn0Z63J6mFAerE93h8efttPUTuftWhD4Lq7Z9ppkpMHwV7/CerT3GeFM 0alw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b=YFR8QAmQ; 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 s12si1839104otd.288.2020.03.26.19.42.46; Thu, 26 Mar 2020 19:42:58 -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=YFR8QAmQ; 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 S1727738AbgC0Cm2 (ORCPT + 99 others); Thu, 26 Mar 2020 22:42:28 -0400 Received: from linux.microsoft.com ([13.77.154.182]:34314 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbgC0Cm2 (ORCPT ); Thu, 26 Mar 2020 22:42:28 -0400 Received: by linux.microsoft.com (Postfix, from userid 1004) id 976F620B4737; Thu, 26 Mar 2020 19:42:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 976F620B4737 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1585276946; bh=zvffKctMIj2SFnhEj55/AzFnvDRhG2tE5Rzn8kutAEA=; h=From:To:Cc:Subject:Date:Reply-To:From; b=YFR8QAmQvBbsrDSG95KLNjrojPASe8E68C6aEhrFpr5LuqKVUydN5R2l2eOiec2Cj Y0DYwIzY/RBeF+ZnB3GcRdJ+LMBZrGnb+du5p2PbI75az+UcDBVBP5EXLQLlmXx/St t5YV8EFSnXPjlvLYgH0zYjOtGYpWIc2NEgzgvbIU= 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 v2] cifs: smbd: Calculate the correct maximum packet size for segmented SMBDirect send/receive Date: Thu, 26 Mar 2020 19:42:24 -0700 Message-Id: <1585276944-5332-1-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 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 The packet size needs to take account of SMB2 header size and possible encryption header size. This is only done when signing is used and it is for RDMA send/receive, not read/write. Also remove the dead SMBD code in smb2_negotiate_r(w)size. Signed-off-by: Long Li --- Change since v1: defined SMB2_READWRITE_PDU_HEADER_SIZE for header size and corrected miscalculation fs/cifs/smb2ops.c | 38 ++++++++++++++++---------------------- fs/cifs/smb2pdu.h | 3 +++ fs/cifs/smbdirect.c | 3 +-- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 9c9258fc8756..b36c46f48705 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -328,16 +328,6 @@ smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) /* start with specified wsize, or default */ wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; wsize = min_t(unsigned int, wsize, server->max_write); -#ifdef CONFIG_CIFS_SMB_DIRECT - if (server->rdma) { - if (server->sign) - wsize = min_t(unsigned int, - wsize, server->smbd_conn->max_fragmented_send_size); - else - wsize = min_t(unsigned int, - wsize, server->smbd_conn->max_readwrite_size); - } -#endif if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); @@ -356,8 +346,15 @@ smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) #ifdef CONFIG_CIFS_SMB_DIRECT if (server->rdma) { if (server->sign) + /* + * Account for SMB2 data transfer packet header and + * possible encryption header + */ wsize = min_t(unsigned int, - wsize, server->smbd_conn->max_fragmented_send_size); + wsize, + server->smbd_conn->max_fragmented_send_size - + SMB2_READWRITE_PDU_HEADER_SIZE - + sizeof(struct smb2_transform_hdr)); else wsize = min_t(unsigned int, wsize, server->smbd_conn->max_readwrite_size); @@ -378,16 +375,6 @@ smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) /* start with specified rsize, or default */ rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; rsize = min_t(unsigned int, rsize, server->max_read); -#ifdef CONFIG_CIFS_SMB_DIRECT - if (server->rdma) { - if (server->sign) - rsize = min_t(unsigned int, - rsize, server->smbd_conn->max_fragmented_recv_size); - else - rsize = min_t(unsigned int, - rsize, server->smbd_conn->max_readwrite_size); - } -#endif if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); @@ -407,8 +394,15 @@ smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) #ifdef CONFIG_CIFS_SMB_DIRECT if (server->rdma) { if (server->sign) + /* + * Account for SMB2 data transfer packet header and + * possible encryption header + */ rsize = min_t(unsigned int, - rsize, server->smbd_conn->max_fragmented_recv_size); + rsize, + server->smbd_conn->max_fragmented_recv_size - + SMB2_READWRITE_PDU_HEADER_SIZE - + sizeof(struct smb2_transform_hdr)); else rsize = min_t(unsigned int, rsize, server->smbd_conn->max_readwrite_size); diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index dda928d05c13..10acf90f858d 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h @@ -120,6 +120,9 @@ struct smb2_sync_hdr { __u8 Signature[16]; } __packed; +/* The total header size for SMB2 read and write */ +#define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_sync_hdr)) + struct smb2_sync_pdu { struct smb2_sync_hdr sync_hdr; __le16 StructureSize2; /* size of wct area (varies, request specific) */ diff --git a/fs/cifs/smbdirect.c b/fs/cifs/smbdirect.c index 5b1b97e9e0c9..a6ae29b3c4e7 100644 --- a/fs/cifs/smbdirect.c +++ b/fs/cifs/smbdirect.c @@ -2097,8 +2097,7 @@ int smbd_send(struct TCP_Server_Info *server, for (i = 0; i < num_rqst; i++) remaining_data_length += smb_rqst_len(server, &rqst_array[i]); - if (remaining_data_length + sizeof(struct smbd_data_transfer) > - info->max_fragmented_send_size) { + if (remaining_data_length > info->max_fragmented_send_size) { log_write(ERR, "payload size %d > max size %d\n", remaining_data_length, info->max_fragmented_send_size); rc = -EINVAL; -- 2.17.1