From patchwork Thu Nov 16 19:09:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 13458181 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EvjxfPrW" Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD0D3B8 for ; Thu, 16 Nov 2023 11:09:22 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-50a6ff9881fso1734966e87.1 for ; Thu, 16 Nov 2023 11:09:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700161760; x=1700766560; darn=vger.kernel.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Dn04mRqD381J0knM3vu5fALJ+ePstcD8oihEcanhTwM=; b=EvjxfPrWJvebZ1SgNDgkY20512h6G4L3cW/5WT6VsSq4D9Jgj4VA4h820vk8k67cTY 1j4u/XmCFym5WOYOxRpU97YCdZ61wirKAzDydb6nn7x5I+wHSz+QEmIlY6kzdLHp3may jzyyv5vjiq3LHeYDI1cPvbe7WUkAt46OuZR5lJism7/qYQbuT48GRSR6aILE50ptkcPa Blmo0VNY6ga0W+hYkuoFrqf9IfyhWN1eOjK8b6d7Q/qL1mCZXhwYRgNBidRVuuOS527t nZvRmM2Kro5pffbPnaNA/rQ+QPpnEzs4NrA84vnYD95k3KMJZi3K3LZFc7BUIyXHRkEA 9VQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700161760; x=1700766560; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Dn04mRqD381J0knM3vu5fALJ+ePstcD8oihEcanhTwM=; b=HYp/qRP7q1q0TiXkcwYzXZTzvnp14PFIEcRv8u0+gdYtYV/9cy6mFpg25xw/s+I/SX bsvdtHNdaZeAaY8/4aoSMjrMXYQmQ4DREdItrYQ0tJzs69mVl9hGzb3nUUnQadGJlLrt Etgkt3TaBSx05En/S5i8DuS/wnCRfFDe8nKvdm6NX+SHmsu5NYq6jEobcmY5yrD7V7ST G65qzXLyMglMlnifejoLIxqCzzpqdnJNWF3hYK74TkrixP8nIzW6x0txBaHJl9SO9Bsd xhXgLI5ZjSPHZnLXsIG3NhcpGEPoVS+UgoUnjkNGBm7ATdEraA7CUdj54uzwrrFCmwjI 2Svw== X-Gm-Message-State: AOJu0YwAUVmvqshf1LgmXRXO+H/p5QIbB+oxayEu8MhMT3RDlSVViHHh cLeod/K49nC3ZuojpNETHXK3gRXvRZ5R2QP6enITrlmTeShqkw== X-Google-Smtp-Source: AGHT+IF1F+EubZIXeGExd5+TESvIhpKbU4PqgysTlfOId+BT+ooMNX3ywZHQS4ThhqWc1R1JaQsKEuzn1Zy++AhioaI= X-Received: by 2002:a05:6512:398a:b0:509:145c:6a49 with SMTP id j10-20020a056512398a00b00509145c6a49mr16599331lfu.42.1700161760232; Thu, 16 Nov 2023 11:09:20 -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:09:09 -0600 Message-ID: Subject: [PATCH][SMB client] two multichannel patches To: CIFS , samba-technical 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