From patchwork Fri Oct 28 06:23:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 1695841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) 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=20210112 header.b=hOfcXUyz; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MzCDJ06lXz23kl for ; Fri, 28 Oct 2022 17:23:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229522AbiJ1GXl (ORCPT ); Fri, 28 Oct 2022 02:23:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbiJ1GXk (ORCPT ); Fri, 28 Oct 2022 02:23:40 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 264631B8668 for ; Thu, 27 Oct 2022 23:23:39 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id be13so6719557lfb.4 for ; Thu, 27 Oct 2022 23:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=f9OiZf7F2j2QujXK3pTSIi/FwLbrbracjDzDGTQPcmo=; b=hOfcXUyzl7gzaMxppNWqTMBQ9lPwYiOP9cB+m5FFh/cfECgh9ar34K8Fu+SmW3eudK bM5xQzUnVPkieQeUhI61h3Y94vpoEw6ALBvW15PDfda5jlAFit5fuSpY6effYGkjVTnx reaLOLO4TIItqw+RuV+Kw0STPqw+6VYDT4aEeV9IVS4iDf9cO3E8/hJbgfHtTRXvTdie r0/wY24tOq4VLdMY4POg/O3FUPzjP6kaKn7ZOb+iJmNvjl2GaFx7km6lQJ7YYI7NxJmx UI1CnB0I0bhH2A0iXxmO560l6aJo+jBkbJkbSh4xPbQ13UDhnkFqi1Y6mHH2lVh5GOVc 7oSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=f9OiZf7F2j2QujXK3pTSIi/FwLbrbracjDzDGTQPcmo=; b=Jti85dN97dY58pL20dzySUn8Epic2MreixRbCDcNw9oATz9b8neW7M/0EJ5c45SddP l1VhBh2/iApIk3fCANZ8ZeCk+Lz0HpWCNvOcRO/8un0tscCiwLf0a8xdLve6hg4PlkBZ xknUBEjUmR1MdOKeLpoj/2wbE1RlmGpCp+y6FoyW/8IT/IKJJuWNTj+QqjvDaSe3CoPu N99tUprmjYulV2IpJVKnv8Q7FVgbiJqMGR4/xKMOJX2bDsxpKwqt20adJgYtTq3d8iKo 26EhbIYb9wi6W46nu8Ce7adxccipDIvuxMFgaOcbXxokPn+XW3/EacDTkIJCvTV4PpzW IV0w== X-Gm-Message-State: ACrzQf1ULLD1CbYgU9J73ekRavMv1jHLp+Q4MsC58iDyqx4iNC/oYO8F E1w7GDfp4cex8SnCqMipcFRM7ozgNBCFRlfI/ULo3M99sfA= X-Google-Smtp-Source: AMsMyM76A1LnqxDTnfYKXqr2lSRi5XYSUATAwrNEMpeIJRxHykdbVKKb4MMQSwJum7clX/8S9zf1k3yTi6lurA332Uo= X-Received: by 2002:a05:6512:6d4:b0:4a2:5045:db6a with SMTP id u20-20020a05651206d400b004a25045db6amr21735425lff.199.1666938216855; Thu, 27 Oct 2022 23:23:36 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Fri, 28 Oct 2022 01:23:25 -0500 Message-ID: Subject: [PATCH][SMB3 client] fix oplock breaks when using multichannel To: CIFS Cc: Namjae Jeon , Shyam Prasad N , =?utf-8?q?Aur=C3=A9lien_Aptel?= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org If a mount to a server is using multichannel, an oplock break arriving on a secondary channel won't find the open file (since it won't find the tcon for it), and this will cause each oplock break on secondary channels to time out, slowing performance drastically. Fix smb2_is_valid_oplock_break so that if it is a secondary channel and an oplock break was not found, check for tcons (and the files hanging off the tcons) on the primary channel. Fixes xfstest generic/013 to ksmbd Cc: From 0186c0d4c418251f066cc8c8d80f16783f9ded00 Mon Sep 17 00:00:00 2001 From: Steve French Date: Fri, 28 Oct 2022 01:13:16 -0500 Subject: [PATCH] smb3: fix oplock break when using multichannel If a mount to a server is using multichannel, an oplock break arriving on a secondary channel won't find the open file (since it won't find the tcon for it). Fix smb2_is_valid_oplock_break so that if it is a secondary channel and an oplock break was not found, check for tcons (and the files hanging off the tcons) on the primary chanel. Fixes xfstest generic/013 to ksmbd Cc: Signed-off-by: Steve French --- fs/cifs/smb2misc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c index a38720477966..ccd294e6c9d9 100644 --- a/fs/cifs/smb2misc.c +++ b/fs/cifs/smb2misc.c @@ -689,13 +689,56 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server) return false; } - cifs_dbg(FYI, "oplock level 0x%x\n", rsp->OplockLevel); + cifs_dbg(FYI, "oplock level 0x%x fid 0x%llx\n", + rsp->OplockLevel, rsp->PersistentFid); /* look up tcon based on tid & uid */ spin_lock(&cifs_tcp_ses_lock); list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { + spin_lock(&tcon->open_file_lock); + list_for_each_entry(cfile, &tcon->openFileList, tlist) { + if (rsp->PersistentFid != + cfile->fid.persistent_fid || + rsp->VolatileFid != + cfile->fid.volatile_fid) + continue; + + cifs_dbg(FYI, "file id match, oplock break\n"); + cifs_stats_inc( + &tcon->stats.cifs_stats.num_oplock_brks); + cinode = CIFS_I(d_inode(cfile->dentry)); + spin_lock(&cfile->file_info_lock); + if (!CIFS_CACHE_WRITE(cinode) && + rsp->OplockLevel == SMB2_OPLOCK_LEVEL_NONE) + cfile->oplock_break_cancelled = true; + else + cfile->oplock_break_cancelled = false; + set_bit(CIFS_INODE_PENDING_OPLOCK_BREAK, + &cinode->flags); + + cfile->oplock_epoch = 0; + cfile->oplock_level = rsp->OplockLevel; + + spin_unlock(&cfile->file_info_lock); + + cifs_queue_oplock_break(cfile); + + spin_unlock(&tcon->open_file_lock); + spin_unlock(&cifs_tcp_ses_lock); + return true; + } + spin_unlock(&tcon->open_file_lock); + } + } + + /* if file not found and secondary, check primary channel */ + if (server->primary_server == NULL) + goto valid_oplock_not_found; + + list_for_each_entry(ses, &server->primary_server->smb_ses_list, smb_ses_list) { + list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { spin_lock(&tcon->open_file_lock); list_for_each_entry(cfile, &tcon->openFileList, tlist) { if (rsp->PersistentFid != @@ -732,6 +775,8 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server) spin_unlock(&tcon->open_file_lock); } } + +valid_oplock_not_found: spin_unlock(&cifs_tcp_ses_lock); cifs_dbg(FYI, "No file id matched, oplock break ignored\n"); trace_smb3_oplock_not_found(0 /* no xid */, rsp->PersistentFid, -- 2.34.1