From nobody Tue Dec 2 02:49:43 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 4D3F4312800 for ; Tue, 18 Nov 2025 02:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763432876; cv=none; b=kSmFbTMc5iHpmJFk+5Z60I3TPbx9izRvTbGHgBKLtHlXl9SrYTRogyodSRkH/fyQbpF0UzFgwaq/5Oo1Jskqtwp9ni1LXY6qN7qMX3Mh7/BP0bJpRRaTgTQYAqMfCjOlH1wtpbPZZluvZx3PlQ3CFLe0M7msMTqr2yAWP+rNRIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763432876; c=relaxed/simple; bh=Pypc31j7e6WzTBARjBckj9L4hLk7f5FPu0IKuFpsR6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nat+++mjZY65ERIMUfLThki1rbva6aY+14nA6b7Ic5RhqHzRoLv2LiODO25oMErzK+Fj5SzGoy5qf+Sd02fhrhc2cBX3EOevwgRX4AvpiZZG163+RfwmGlZXH6+FrPUaFW1qyfIUbg8T2SWVl0ra+h7qM3ufkXTAGLqdHmpFbYs= 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=XEZ0FG4I; arc=none smtp.client-ip=209.85.214.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XEZ0FG4I" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-29555b384acso51023415ad.1 for ; Mon, 17 Nov 2025 18:27:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763432875; x=1764037675; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eUeRTgtvZX5xIfYESgNI5CfhH9TmmJjF3mJVIzLoI7M=; b=XEZ0FG4I4s+zynMyUVhmidOOzu+lvj2IRjBnjR2Kg6wjxsrMtevPWiPTJL94dDvo98 vM9EYBLcfpcF1Xa1mmyrlsbzmwEP0nSvmA4kXDnYcnj0aD7ywo7bsOdMMIGR+VKMpsMP VoRelZX9kPczIRJLJrAFFQWK1MvN243xbN95FCZg8V9hAC+OISqK9CFjNq7aNmKCEBCk p8spcOt6mkn2qZiX070xDPluIcFzDmROTuOtlhGvgLm3Z6UoGqREriiG2SPBaa6SxV37 iqUk+PqnH9SkRBxSGjtVU9zhcUsfSrtlnXXWz4UxzJAML9YB8N55bYN5TRbPdTC9mynN u90g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763432875; x=1764037675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=eUeRTgtvZX5xIfYESgNI5CfhH9TmmJjF3mJVIzLoI7M=; b=HqKECxtmal3k1MT9X72p1TP7a2Ese9HKf4DxrP/E2o9uicfwlK28IMQnrUcHPfo0X3 VLSQTj1tRU4l14PMTT6BvrMAY+ryoxzyAK7lTh3XA3WqD1iUQpj17nGpBEhI4bmkao0K ems1ts/JERtEKdhMBOOAlHS76LcfU3a0kpnE7jxb3F9QeCB87qr/LRDPFz/aQIIeFJ15 i9TPopOIG4wZBCZ4XoJgjvbTu4g9isdmF5fj5uQf2fx6pO0goO4PrL21J/dc1mnrE8dB ywHUfFLSXlG4lpkRirQZnfJOxqS6YIKZEtnuSk3XZ49xoSrwuCZFa43KLQfQh8ypxg7X tRaw== X-Forwarded-Encrypted: i=1; AJvYcCXjNv9S89p5QUqfJsMMYfSxnIlCa3LP672nAmEWUjtODTUfw/xUULXPUX0iffl7NtrOgHfQs3AlrCrA9j8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywpu84bKe2alrYPuPNhgbYGnsyTPEDaUGtJD8SpbYkFPY7PTzem mbnIgAVO1Gkn1OWMNnYqoqVugI8fiyo1ckltP7e7p5G6Y7NvRgeD5wlD X-Gm-Gg: ASbGncug5fbzj1jJ6yTmRDlNMSgH4HWoHgBmYACN+FcNGY2yEEW1OIiuGMlUeCVGOM2 GrLDMqbR6dmyjuNZgDVymuky9p8muP08zwMwwve5UzJI3FIXW5GusHg26wssyB4MB4qysVR/Aje 1lWwhW4ueRzdbu4SIVuA4sbp7NvplPSfLPcAcY+PeOj3olmYwympSDSbbQ/7AL40e+yOnkndLuh 0lpLe/4dfFzd2STkTeYWCbMQB7T/onHwToLpx266jMHtthkrtX93mClB+uB0Wh9uSF4p/x0Jixa WV9xr8ztULHy6jQ+bYtxGMQN6Vf4pLEXz/L9XkBu6bTAp5ETZ9inNc6pLaR8qnxV6K3M1PKiRGS Fcn7xuiSV/DaVS18G1fIXmTaYvA2R4QIJCe+RHKCb+Kkq9esgcP1nB11c1VFA/+NjU2uEzTj0sh chNdijhQJDKR1CEnapXujcMYSunM5AUq31iB+MBDA6rwRRn3iuYecvgsUKciKj8+rBxDxb48uE1 LDt1OI= X-Google-Smtp-Source: AGHT+IF4kSAjfwknCVM4USZhMERLBGdwXplWAHKQAlRqecUdLezqzo6LAYFe/hkB2X7tS7mhxTfn9w== X-Received: by 2002:a17:902:cf03:b0:298:46a9:df01 with SMTP id d9443c01a7336-2986a6b8911mr202325475ad.3.1763432874583; Mon, 17 Nov 2025 18:27:54 -0800 (PST) Received: from linuxbackup1-rm.hzz4ddxqtfeetjrh00qlbgyytb.rx.internal.cloudapp.net ([4.247.136.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c23849esm153170975ad.5.2025.11.17.18.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Nov 2025 18:27:54 -0800 (PST) From: Rajasi Mandal To: sfrench@samba.org, linux-cifs@vger.kernel.org Cc: pc@manguebit.org, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, Rajasi Mandal Subject: [PATCH] cifs: client: enforce consistent handling of multichannel and max_channels Date: Tue, 18 Nov 2025 02:26:55 +0000 Message-ID: <20251118022655.126994-2-rajasimandalos@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251118022655.126994-1-rajasimandalos@gmail.com> References: <20251118022655.126994-1-rajasimandalos@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Rajasi Mandal Previously, the behavior of the multichannel and max_channels mount options was inconsistent and order-dependent. For example, specifying "multichannel,max_channels=3D1" would result in 2 channels, while "max_channels=3D1,multichannel" would result in 1 channel. Additionally, conflicting combinations such as "nomultichannel,max_channels=3D3" or "multichannel,max_channels=3D1" did not produce errors and could lead to unexpected channel counts. This commit introduces two new fields in smb3_fs_context to explicitly track whether multichannel and max_channels were specified during mount. The option parsing and validation logic is updated to ensure: - The outcome is no longer dependent on the order of options. - Conflicting combinations (e.g., "nomultichannel,max_channels=3D3" or "multichannel,max_channels=3D1") are detected and result in an error. - The number of channels created is consistent with the specified options. This improves the reliability and predictability of mount option handling for SMB3 multichannel support. Reviewed-by: Shyam Prasad N Signed-off-by: Rajasi Mandal --- fs/smb/client/cifsfs.c | 1 - fs/smb/client/fs_context.c | 65 ++++++++++++++++++++++++++++---------- fs/smb/client/fs_context.h | 2 ++ 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index 185ac41bd7e9..4d53ec53d8db 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1016,7 +1016,6 @@ cifs_smb3_do_mount(struct file_system_type *fs_type, } else { cifs_info("Attempting to mount %s\n", old_ctx->source); } - cifs_sb =3D kzalloc(sizeof(*cifs_sb), GFP_KERNEL); if (!cifs_sb) return ERR_PTR(-ENOMEM); diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c index 46d1eaae62da..1794a31541fe 100644 --- a/fs/smb/client/fs_context.c +++ b/fs/smb/client/fs_context.c @@ -711,6 +711,47 @@ smb3_parse_devname(const char *devname, struct smb3_fs= _context *ctx) return 0; } =20 +static int smb3_handle_conflicting_options(struct fs_context *fc) +{ + struct smb3_fs_context *ctx =3D smb3_fc2context(fc); + + if (ctx->multichannel_specified) { + if (ctx->multichannel) { + if (!ctx->max_channels_specified) { + ctx->max_channels =3D 2; + } else if (ctx->max_channels =3D=3D 1) { + cifs_errorf(fc, + "max_channels must be greater than 1 when multichannel is enabled= \n"); + return -EINVAL; + } + } else { + if (!ctx->max_channels_specified) { + ctx->max_channels =3D 1; + } else if (ctx->max_channels > 1) { + cifs_errorf(fc, + "max_channels must be equal to 1 when multichannel is disabled\n"= ); + return -EINVAL; + } + } + } else { + if (ctx->max_channels_specified) { + if (ctx->max_channels > 1) + ctx->multichannel =3D true; + else + ctx->multichannel =3D false; + } else { + ctx->multichannel =3D false; + ctx->max_channels =3D 1; + } + } + + //resetting default values as remount doesn't initialize fs_context again + ctx->multichannel_specified =3D false; + ctx->max_channels_specified =3D false; + + return 0; +} + static void smb3_fs_context_free(struct fs_context *fc); static int smb3_fs_context_parse_param(struct fs_context *fc, struct fs_parameter *param); @@ -785,6 +826,7 @@ static int smb3_fs_context_parse_monolithic(struct fs_c= ontext *fc, if (ret < 0) break; } + ret =3D smb3_handle_conflicting_options(fc); =20 return ret; } @@ -1296,15 +1338,11 @@ static int smb3_fs_context_parse_param(struct fs_co= ntext *fc, ctx->nodelete =3D 1; break; case Opt_multichannel: - if (result.negated) { + ctx->multichannel_specified =3D true; + if (result.negated) ctx->multichannel =3D false; - ctx->max_channels =3D 1; - } else { + else ctx->multichannel =3D true; - /* if number of channels not specified, default to 2 */ - if (ctx->max_channels < 2) - ctx->max_channels =3D 2; - } break; case Opt_uid: ctx->linux_uid =3D result.uid; @@ -1440,15 +1478,13 @@ static int smb3_fs_context_parse_param(struct fs_co= ntext *fc, ctx->max_credits =3D result.uint_32; break; case Opt_max_channels: + ctx->max_channels_specified =3D true; if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) { cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n", __func__, CIFS_MAX_CHANNELS); goto cifs_parse_mount_err; } ctx->max_channels =3D result.uint_32; - /* If more than one channel requested ... they want multichan */ - if (result.uint_32 > 1) - ctx->multichannel =3D true; break; case Opt_max_cached_dirs: if (result.uint_32 < 1) { @@ -1866,13 +1902,6 @@ static int smb3_fs_context_parse_param(struct fs_con= text *fc, goto cifs_parse_mount_err; } =20 - /* - * Multichannel is not meaningful if max_channels is 1. - * Force multichannel to false to ensure consistent configuration. - */ - if (ctx->multichannel && ctx->max_channels =3D=3D 1) - ctx->multichannel =3D false; - return 0; =20 cifs_parse_mount_err: @@ -1955,6 +1984,8 @@ int smb3_init_fs_context(struct fs_context *fc) =20 /* default to no multichannel (single server connection) */ ctx->multichannel =3D false; + ctx->multichannel_specified =3D false; + ctx->max_channels_specified =3D false; ctx->max_channels =3D 1; =20 ctx->backupuid_specified =3D false; /* no backup intent for a user */ diff --git a/fs/smb/client/fs_context.h b/fs/smb/client/fs_context.h index b0fec6b9a23b..7af7cbbe4208 100644 --- a/fs/smb/client/fs_context.h +++ b/fs/smb/client/fs_context.h @@ -294,6 +294,8 @@ struct smb3_fs_context { bool domainauto:1; bool rdma:1; bool multichannel:1; + bool multichannel_specified:1; /* true if user specified multichannel or = nomultichannel */ + bool max_channels_specified:1; /* true if user specified max_channels */ bool use_client_guid:1; /* reuse existing guid for multichannel */ u8 client_guid[SMB2_CLIENT_GUID_SIZE]; --=20 2.43.0