From patchwork Thu Nov 16 19:10:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 13458182 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bPTzU4/q" Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2CFE1A8; Thu, 16 Nov 2023 11:11:12 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50970c2115eso1787835e87.1; Thu, 16 Nov 2023 11:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700161870; x=1700766670; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=HvqoSmET7AGneC0DU+9vvXM7mU+Afpt1Gl2P+52o3jI=; b=bPTzU4/q8JqrgXJ+fQZSq/aWqpH7hf1mh4lavpeNeHyaLOUoihyjLoQI0aY2re5rBu eSWMw/KZUNvJO9GQGXHFbX+2AdPWmiUsLmsKbf7qrEAxZy+ysFyzrjnw83bZwgekQUZW dRTSAXsORz1SKPPXH5QBys6mewE7V+H+iEfDvHGlIohP30CrlIwLzxm4BjYSuNOiEZOj 8awYKaThax7T5n7vUa1l1lPQ3VlTrtgiPIC3JkPegZz82D3mvg62VDfZiRN004yDvTFu bkDbWkgy/Nt06VKmtEH3ucPcr0KQoermMZhPOkv01xfgp7lXumunb20L6z/2/yhPGOvm MRqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700161870; x=1700766670; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HvqoSmET7AGneC0DU+9vvXM7mU+Afpt1Gl2P+52o3jI=; b=xB98dfGwm8D2ixC2nmswiROsSaxbKnHWaWAe3sagW363+lQlco02msD321z0ICJfu/ 7GyXU9BRnJCOe0zKLTwhaQdcRQtEq9aaYuqCr/apUvqLG2XRXXiPmtXx8N6+cfbLF1+y Cki1srSu5ceWP6Yi0GAbAM3IoTQNFq/NpLcXv5eUlNpN6lu8br5OF2mNu6mmW/zFOHQ1 CKV12SADlBeOQGA2R6FmVziNnnUoYAxyqBkeSizl4W8CpU6iQlS+7cP39dIEeBXObFbd VJJ8fpU5/stMro6bnNtpQCQwqwQ5TnLn4vjKnt+K2D2WytT8utQ3HcEycP0Esp+2xdrk 7gZg== X-Gm-Message-State: AOJu0Yw7U4vW6NOoHHhBAIFKvMXcCbRNLK41h1fcs9IYkVdDEv7e8bpl sytRC5vd9BRkqTY7qG0G4O2AdzFPjcVlqerZdFvU08H4SEPphQ== X-Google-Smtp-Source: AGHT+IFRVCxgaf/Z3tqusQJxhVAgc3v+PKDVWuF/KqBZYrhhWCHzv/pxlMIixAMYXwSLHgQOvnmQmNNwffletgg3BXU= X-Received: by 2002:a19:6409:0:b0:509:4e4f:65ac with SMTP id y9-20020a196409000000b005094e4f65acmr10428397lfb.63.1700161870144; Thu, 16 Nov 2023 11:11:10 -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: Thu, 16 Nov 2023 13:10:58 -0600 Message-ID: Subject: [PATCH][SMB client] two multichannel patches To: CIFS , samba-technical Cc: LKML Any thoughts on these two multichannel patches from Shyam (attached)? The first fixes: "cifs: account for primary channel in the interface list" which fixes a refcounting issue in channel deallocation. The second fixes a lock ordering problem in the recent patch: "cifs: handle when server stops supporting multichannel" The code to handle the case of server disabling multichannel was picking iface_lock with chan_lock held. This goes against the lock ordering rules, as iface_lock is a higher order lock (even if it isn't so obvious). This change fixes the lock ordering by doing the following in that order for each secondary channel: 1. store iface and server pointers in local variable 2. remove references to iface and server in channels 3. unlock chan_lock 4. lock iface_lock 5. dec ref count for iface 6. unlock iface_lock 7. dec ref count for server 8. lock chan_lock again Let me know if any test feedback or reviews From 5eef12c4e3230f2025dc46ad8c4a3bc19978e5d7 Mon Sep 17 00:00:00 2001 From: Shyam Prasad N Date: Tue, 14 Nov 2023 04:58:23 +0000 Subject: [PATCH 2/2] cifs: fix lock ordering while disabling multichannel The code to handle the case of server disabling multichannel was picking iface_lock with chan_lock held. This goes against the lock ordering rules, as iface_lock is a higher order lock (even if it isn't so obvious). This change fixes the lock ordering by doing the following in that order for each secondary channel: 1. store iface and server pointers in local variable 2. remove references to iface and server in channels 3. unlock chan_lock 4. lock iface_lock 5. dec ref count for iface 6. unlock iface_lock 7. dec ref count for server 8. lock chan_lock again Since this function can only be called in smb2_reconnect, and that cannot be called by two parallel processes, we should not have races due to dropping chan_lock between steps 3 and 8. Fixes: ee1d21794e55 ("cifs: handle when server stops supporting multichannel") Reported-by: Paulo Alcantara Signed-off-by: Shyam Prasad N Signed-off-by: Steve French --- fs/smb/client/sess.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/smb/client/sess.c b/fs/smb/client/sess.c index 0bb2ac929061..8b2d7c1ca428 100644 --- a/fs/smb/client/sess.c +++ b/fs/smb/client/sess.c @@ -322,28 +322,32 @@ cifs_disable_secondary_channels(struct cifs_ses *ses) iface = ses->chans[i].iface; server = ses->chans[i].server; + /* + * remove these references first, since we need to unlock + * the chan_lock here, since iface_lock is a higher lock + */ + ses->chans[i].iface = NULL; + ses->chans[i].server = NULL; + spin_unlock(&ses->chan_lock); + if (iface) { spin_lock(&ses->iface_lock); kref_put(&iface->refcount, release_iface); - ses->chans[i].iface = NULL; iface->num_channels--; if (iface->weight_fulfilled) iface->weight_fulfilled--; spin_unlock(&ses->iface_lock); } - spin_unlock(&ses->chan_lock); - if (server && !server->terminate) { - server->terminate = true; - cifs_signal_cifsd_for_reconnect(server, false); - } - spin_lock(&ses->chan_lock); - if (server) { - ses->chans[i].server = NULL; + if (!server->terminate) { + server->terminate = true; + cifs_signal_cifsd_for_reconnect(server, false); + } cifs_put_tcp_session(server, false); } + spin_lock(&ses->chan_lock); } done: -- 2.39.2