From patchwork Wed Jan 31 22:43:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 13540079 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 A605A210FE for ; Wed, 31 Jan 2024 22:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741017; cv=none; b=b+HhyN7gAK1kNXn5zWFP2vsuEyIJjqHrfJNvge4PsAsUGk3ycmMWVe+qHMalmPzqeqNjs+3C95PAODgeGZuw9JoWJZRO6CoNn95hcSZyUEGH2uYb0XkDYBqw3RVNVqDe9KbCBhAyjGZynY+Fvvis5lWyF67mlf4eJ/ypRTBBVHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741017; c=relaxed/simple; bh=fiJoFrX4gVKbkETth2esSrlFUbIXiJFxvcyZwlZcOpc=; h=MIME-Version:From:Date:Message-ID:Subject:To:Cc:Content-Type; b=iGltWsDZ9A1hlIU3yd31xJGi++z5wVudypX6RM8OtCxlA1M4ZnWAe+V+x4+Z575NqSN4dVmyDWcmJjavfFOYbV9+qJ2ctkwMtme4Rn++S0t9bRgX9ND9BdYcLmfqPIwvwXhxjTP/eQGFllFsDv3aOkn8XIEfmghxLVOixpduaqg= 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=KitZcBTV; arc=none smtp.client-ip=209.85.167.42 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="KitZcBTV" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5112d5ab492so146997e87.0 for ; Wed, 31 Jan 2024 14:43:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706741013; x=1707345813; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=8awvc388LrZO6gitjm0sq2JpByAHzsbT5JbnyIhTYFk=; b=KitZcBTVM6Xjh8DFFWNk9t/tO2wkfgP7e61gmMFqjpylOfr/Hm66mu1xTywxjsOB3v GfoHp2hfCz6bHzoIeBjeRL8F6IA8z981XOPsQVxuvu022jWFtx7Y2YCfhjif6voD9OOt ttoEV8N/PGdbG8Gj38na35d4MJmnxPG201Z1eV1g5FaZWLsiNQAOBcEGeEx7KlwfEBAN aeA3BUMFxPkyxSv06LyeEILLnQnKzozP+COHeM2bRFhof8jCIScW5Ewy8kja+gh+muD1 ufG7jdCwR8JZADUlTZ0CCmO88bDD4pWtgh9kzegWiMdbWRlJMalXVbXGA5Dk7uHo1d8r xhYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741013; x=1707345813; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8awvc388LrZO6gitjm0sq2JpByAHzsbT5JbnyIhTYFk=; b=K5cSM0SM/GjesKAfG3XAol8C+WRISrAnLxI9JJdA1MabothPiXo0Whowk0gLiz2+i/ hllzVvRZBOmXaai6PBKyOICKcecXhMht32/RBg+g7JidHkFpTp3aokHyyzEzB863NTts Th7DbiamZwxKJ9ahHF0yjnflbNGwbpbu+BPIBgnI+86/sY+dq3biggthJ0g9VLe3eyXE NNoYTX1Pw+/ckp/NkHQGrCwi4LfG4XU3SADfjL3K07ixcej/rAlfkMJXkRRAv4zRTwUs Ov5OYSHnxg3u5o2ehY1lCFBPal2yD5T9uxeXUvxwAMWWOTm4+uFHpyaKghUini3sGOkG ingg== X-Gm-Message-State: AOJu0YxBbgxiKmS+dgaiIZ/2XZQiZi7wPNGvrl9yKKYzUv6Ti2PMegPZ dPiFFW/kQGt/7ZoA27sdF4bCbjjq5F33P0U9HUGPxJbYOVqtCSMYVLaruRqOGGLZ7ibov74E+Pi gDSUmLqzYMnSSSCXpxyj8Q39xFcg= X-Google-Smtp-Source: AGHT+IFSOQf07R1WhLlunXCCQ4tqRo8vA41KoA0B4OB64wtXNPGQqSnofYixmpexkFtLeUNfwBTBefEwFPRz+3uarj4= X-Received: by 2002:ac2:5ec6:0:b0:510:694:13e6 with SMTP id d6-20020ac25ec6000000b00510069413e6mr342488lfq.15.1706741013228; Wed, 31 Jan 2024 14:43:33 -0800 (PST) Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steve French Date: Wed, 31 Jan 2024 16:43:21 -0600 Message-ID: Subject: fix for patch "cifs" make sure that channel scaling is done only once" To: Shyam Prasad N Cc: Bharath S M , CIFS Looks like the patch in for-next "cifs: make sure that channel scaling is done only once" (see attached) was missing some unlocks that were noticed by compile with C=1 and/or sparse. See below. --- Thanks, Steve From 17525952fa834a75751f51726eb3cd683948b148 Mon Sep 17 00:00:00 2001 From: Shyam Prasad N Date: Mon, 29 Jan 2024 13:58:13 +0000 Subject: [PATCH] cifs: make sure that channel scaling is done only once Following a successful cifs_tree_connect, we have the code to scale up/down the number of channels in the session. However, it is not protected by a lock today. As a result, this code can be executed by several processes that select the same channel. The core functions handle this well, as they pick chan_lock. However, we've seen cases where smb2_reconnect throws some warnings. To fix that, this change introduces a flags bitmap inside the cifs_ses structure. A new flag type is used to ensure that only one process enters this section at any time. Signed-off-by: Shyam Prasad N Signed-off-by: Steve French --- fs/smb/client/cifsglob.h | 3 +++ fs/smb/client/smb2pdu.c | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 16befff4cbb4..9093c507042f 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1032,6 +1032,8 @@ struct cifs_chan { __u8 signkey[SMB3_SIGN_KEY_SIZE]; }; +#define CIFS_SES_FLAG_SCALE_CHANNELS (0x1) + /* * Session structure. One of these for each uid session with a particular host */ @@ -1064,6 +1066,7 @@ struct cifs_ses { enum securityEnum sectype; /* what security flavor was specified? */ bool sign; /* is signing required? */ bool domainAuto:1; + unsigned int flags; __u16 session_flags; __u8 smb3signingkey[SMB3_SIGN_KEY_SIZE]; __u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE]; diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 86f6f35b7f32..273e24f9da13 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -399,6 +399,12 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, goto out; } + spin_lock(&ses->ses_lock); + if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) + goto skip_add_channels; + ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS; + spin_unlock(&ses->ses_lock); + if (!rc && (server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) { mutex_unlock(&ses->session_mutex); @@ -428,17 +434,22 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, if (ses->chan_max > ses->chan_count && ses->iface_count && !SERVER_IS_CHAN(server)) { - if (ses->chan_count == 1) + if (ses->chan_count == 1) { cifs_server_dbg(VFS, "supports multichannel now\n"); + queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, + (SMB_INTERFACE_POLL_INTERVAL * HZ)); + } cifs_try_adding_channels(ses); - queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, - (SMB_INTERFACE_POLL_INTERVAL * HZ)); } } else { mutex_unlock(&ses->session_mutex); } + skip_add_channels: + spin_lock(&ses->ses_lock); + ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS; + spin_unlock(&ses->ses_lock); if (smb2_command != SMB2_INTERNAL_CMD) mod_delayed_work(cifsiod_wq, &server->reconnect, 0); -- 2.40.1