From patchwork Mon Mar 11 00:59:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 1910271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=k1Y65Bow; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-cifs+bounces-1433-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TtJMr1pT7z1yX8 for ; Mon, 11 Mar 2024 11:59:52 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 958A828151C for ; Mon, 11 Mar 2024 00:59:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F40CE631; Mon, 11 Mar 2024 00:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k1Y65Bow" X-Original-To: linux-cifs@vger.kernel.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C127E622 for ; Mon, 11 Mar 2024 00:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710118787; cv=none; b=FBo/oI1zD/2Xj46LQNPAM8eImIyhbvopd7XCmNwAVsQ6WhrTzjJRHbxiw77I4hrnv923QRJS970IrLpnAxTOEstlt52DS2qSoSQ14u1lL13IZLp5y84yws6eOmw57yWSZB3JGu/fFj08KYCdDtZeSGqU5r2GK+xl6YQnDV7+MLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710118787; c=relaxed/simple; bh=iweLrZqAwnEvJN1mG/w7+u1JGtyX5Bs57K9ZO1in57M=; h=MIME-Version:From:Date:Message-ID:Subject:To:Cc:Content-Type; b=ooyHDh73GmKzEKf34xOOnC+/qGfIZenEdp3t3CaBReclAqzS7KYSExzxkuNBTBN7kNwF62IOZeewjm2xg8othJv9hRswJcEYnjjLQ+tpKFHgszJRu9RmurfIYY75WO2nPeoo+aTTzUBRb2LXhWG7CktqnpOg7dGL8nDE2l/KMIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k1Y65Bow; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5135e8262e4so4206012e87.0 for ; Sun, 10 Mar 2024 17:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710118784; x=1710723584; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=zLiHanYCcPyFUhgUX/mu0tiE0+ER9b3OLSJaJagyzSM=; b=k1Y65Bowxtzs9vR7/BpXrA1U2Dzg0gXn93Jg1aDC9XEojog1Ji0sbryWkk6O1pdmYb qkOBocmsATgn30L3Unsr9WFAOoCkhP/d3fR+KBz7aCZrB5OiuODZWKhfIJt69/8LGVgh B6aOYqiRCerxoumGz4V7zXU4vlnvACrX8nb3CD9CkwmZcjnVKZ49VoB3kMQQVVvhYKdN BGqXBhNvuxGJmwvL8zRDVNT4v7lMyMJyiixuftVmelTbHLfhfXRI509h0HqGiQVvrqXN Lue159IFE9svGgBV1/A7Ur6oV/pamWyTgyGE571jKgm+fvmEi2yhMTTj8210PEmcjtX4 XEoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710118784; x=1710723584; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zLiHanYCcPyFUhgUX/mu0tiE0+ER9b3OLSJaJagyzSM=; b=mugSIe686xE/04j0PJ0pM4KwSqPqjfoZRQ/R6mi80sYcl9k2g28faYovg0JCfthTUd HkFGxJHYyxrRLpD+K8FadQ2GmmX98BTPCKNx8fxt+OofJATJpQb7mXSD+8dd4AH2Ym63 gl0lV/sD4SqT2k5Ypv95Kfzn6DbeotxEakdkXzlq7Dv/RTUX64b6FD7aA0YfKbbI3Fkw 3qnedBGNScwGDV0tkfk04HzLLV2g71zv3avkhGWjWSonOb5+kohIzMFJn+O33oBfwKIy s0GmQuZPm1V4PghC50CXON0CWQTzPsgERO5sNAqxMQwdRzRumrcj/gtehkO3wGBtO4f3 0zOQ== X-Gm-Message-State: AOJu0YzkvV8x9s42PJAjHrryjnXJJLMbgjvOKdBndtnKFxC1xRNYz2QG HtVaijErRVHQy3xiVJH655eHlOpVkfGNuk4SWEKtkf5hJEVIImu132B4G+zsD0cL7vPh9+cSH5Q 6JgKR0y1DApUbFXO4yYS8ifLeOl8= X-Google-Smtp-Source: AGHT+IEK/Ono1WtERrQ+7hlPMTBsEB9VKpy04mn69PwidqW3Od9rfc3BN7nuJDV1KgdYbUHD94bM7lD0zJqs4eLe8iE= X-Received: by 2002:a05:6512:3133:b0:513:5ec6:348b with SMTP id p19-20020a056512313300b005135ec6348bmr3088202lfd.6.1710118783767; Sun, 10 Mar 2024 17:59:43 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steve French Date: Sun, 10 Mar 2024 19:59:32 -0500 Message-ID: Subject: [SMB3 client] patches to prep for SMB3.1.1 compression support To: Enzo Matsumiya Cc: CIFS , samba-technical Enzo, I have lightly updated your patches. See attached. 1) smb: client: negotiate compression algorithms Fixed a minor endian issue (with "arg" being le16 and being used to compare vs. an int) and a few minor warnings spotted by checkpatch (seq_puts is preferred instead of seq_printf for warning messages without arguments) 2) smb: common: fix fields sizes in compression_pattern_payload_v1 added a brief description 3) smb: common: simplify compression headers fixed a typo that checkpatch script caught (misaligned statement which had extra space preceding it) From 8fea3473a1785a9fc2e6795f5785dd2ae3693bee Mon Sep 17 00:00:00 2001 From: Enzo Matsumiya Date: Fri, 23 Feb 2024 11:58:57 -0300 Subject: [PATCH 1/4] smb: client: negotiate compression algorithms Change "compress=" mount option to a boolean flag, that, if set, will enable negotiating compression algorithms with the server. Do not de/compress anything for now. Signed-off-by: Enzo Matsumiya Signed-off-by: Steve French --- fs/smb/client/cifs_debug.c | 32 ++++++++++++++++++++++++++------ fs/smb/client/cifsglob.h | 6 +++++- fs/smb/client/connect.c | 2 +- fs/smb/client/fs_context.c | 2 +- fs/smb/client/fs_context.h | 2 +- fs/smb/client/smb2pdu.c | 20 +++++++++++++++----- 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/fs/smb/client/cifs_debug.c b/fs/smb/client/cifs_debug.c index 23d2622b969f..226d4835c92d 100644 --- a/fs/smb/client/cifs_debug.c +++ b/fs/smb/client/cifs_debug.c @@ -278,6 +278,24 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v) return 0; } +static __always_inline const char *compression_alg_str(__le16 alg) +{ + switch (alg) { + case SMB3_COMPRESS_NONE: + return "NONE"; + case SMB3_COMPRESS_LZNT1: + return "LZNT1"; + case SMB3_COMPRESS_LZ77: + return "LZ77"; + case SMB3_COMPRESS_LZ77_HUFF: + return "LZ77-Huffman"; + case SMB3_COMPRESS_PATTERN: + return "Pattern_V1"; + default: + return "invalid"; + } +} + static int cifs_debug_data_proc_show(struct seq_file *m, void *v) { struct mid_q_entry *mid_entry; @@ -423,12 +441,6 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) server->echo_credits, server->oplock_credits, server->dialect); - if (server->compress_algorithm == SMB3_COMPRESS_LZNT1) - seq_printf(m, " COMPRESS_LZNT1"); - else if (server->compress_algorithm == SMB3_COMPRESS_LZ77) - seq_printf(m, " COMPRESS_LZ77"); - else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF) - seq_printf(m, " COMPRESS_LZ77_HUFF"); if (server->sign) seq_printf(m, " signed"); if (server->posix_ext_supported) @@ -460,6 +472,14 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) server->leaf_fullpath); } + seq_puts(m, "\nCompression: "); + if (!server->compression.requested) + seq_puts(m, "disabled on mount"); + else if (server->compression.enabled) + seq_printf(m, "enabled (%s)", compression_alg_str(server->compression.alg)); + else + seq_puts(m, "disabled (not supported by this server)"); + seq_printf(m, "\n\n\tSessions: "); i = 0; list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index a0506a45eae3..8be62ed053a2 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -769,7 +769,11 @@ struct TCP_Server_Info { unsigned int max_write; unsigned int min_offload; unsigned int retrans; - __le16 compress_algorithm; + struct { + bool requested; /* "compress" mount option set*/ + bool enabled; /* actually negotiated with server */ + __le16 alg; /* preferred alg negotiated with server */ + } compression; __u16 signing_algorithm; __le16 cipher_type; /* save initital negprot hash */ diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 5d82921d63d1..86ae578904a2 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -1736,7 +1736,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx, tcp_ses->channel_sequence_num = 0; /* only tracked for primary channel */ tcp_ses->reconnect_instance = 1; tcp_ses->lstrp = jiffies; - tcp_ses->compress_algorithm = cpu_to_le16(ctx->compression); + tcp_ses->compression.requested = ctx->compress; spin_lock_init(&tcp_ses->req_lock); spin_lock_init(&tcp_ses->srv_lock); spin_lock_init(&tcp_ses->mid_lock); diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c index 4b767efa47f1..bdcbe6ff2739 100644 --- a/fs/smb/client/fs_context.c +++ b/fs/smb/client/fs_context.c @@ -963,7 +963,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, switch (opt) { case Opt_compress: - ctx->compression = UNKNOWN_TYPE; + ctx->compress = true; cifs_dbg(VFS, "SMB3 compression support is experimental\n"); break; diff --git a/fs/smb/client/fs_context.h b/fs/smb/client/fs_context.h index 1f09754977e7..7863f2248c4d 100644 --- a/fs/smb/client/fs_context.h +++ b/fs/smb/client/fs_context.h @@ -273,7 +273,7 @@ struct smb3_fs_context { unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */ unsigned int max_channels; unsigned int max_cached_dirs; - __u16 compression; /* compression algorithm 0xFFFF default 0=disabled */ + bool compress; /* enable SMB2 messages (READ/WRITE) de/compression */ bool rootfs:1; /* if it's a SMB root file system */ bool witness:1; /* use witness protocol */ char *leaf_fullpath; diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 7d0157e0061e..60b3f8e41aa2 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -731,7 +731,7 @@ assemble_neg_contexts(struct smb2_negotiate_req *req, pneg_ctxt += sizeof(struct smb2_posix_neg_context); neg_context_count++; - if (server->compress_algorithm) { + if (server->compression.requested) { build_compression_ctxt((struct smb2_compression_capabilities_context *) pneg_ctxt); ctxt_len = ALIGN(sizeof(struct smb2_compression_capabilities_context), 8); @@ -779,6 +779,9 @@ static void decode_compress_ctx(struct TCP_Server_Info *server, struct smb2_compression_capabilities_context *ctxt) { unsigned int len = le16_to_cpu(ctxt->DataLength); + __le16 alg; + + server->compression.enabled = false; /* * Caller checked that DataLength remains within SMB boundary. We still @@ -789,15 +792,22 @@ static void decode_compress_ctx(struct TCP_Server_Info *server, pr_warn_once("server sent bad compression cntxt\n"); return; } + if (le16_to_cpu(ctxt->CompressionAlgorithmCount) != 1) { - pr_warn_once("Invalid SMB3 compress algorithm count\n"); + pr_warn_once("invalid SMB3 compress algorithm count\n"); return; } - if (le16_to_cpu(ctxt->CompressionAlgorithms[0]) > 3) { - pr_warn_once("unknown compression algorithm\n"); + + alg = ctxt->CompressionAlgorithms[0]; + + /* 'NONE' (0) compressor type is never negotiated */ + if (alg == 0 || le16_to_cpu(alg) > 3) { + pr_warn_once("invalid compression algorithm '%u'\n", alg); return; } - server->compress_algorithm = ctxt->CompressionAlgorithms[0]; + + server->compression.alg = alg; + server->compression.enabled = true; } static int decode_encrypt_ctx(struct TCP_Server_Info *server, -- 2.40.1