{"id":2229709,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229709/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-19-sprasad@microsoft.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.1/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260428160804.281745-19-sprasad@microsoft.com>","date":"2026-04-28T16:08:04","name":"[v3,19/19] cifs: invalidate cached_dirents if population aborted","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"558aed8c1aba3817b237da0cd0632a7712a019b5","submitter":{"id":79368,"url":"http://patchwork.ozlabs.org/api/1.1/people/79368/?format=json","name":"Shyam Prasad N","email":"nspmangalore@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-19-sprasad@microsoft.com/mbox/","series":[{"id":501896,"url":"http://patchwork.ozlabs.org/api/1.1/series/501896/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501896","date":"2026-04-28T16:07:57","name":"[v3,01/19] cifs: change_conf needs to be called for session setup","version":3,"mbox":"http://patchwork.ozlabs.org/series/501896/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229709/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229709/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-11255-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=QbVsCVCs;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11255-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"QbVsCVCs\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.214.180","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4m1K2Dsfz1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 02:22:29 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id 2C5C630471C2\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 16:14:48 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 4590E44D6B8;\n\tTue, 28 Apr 2026 16:08:40 +0000 (UTC)","from mail-pl1-f180.google.com (mail-pl1-f180.google.com\n [209.85.214.180])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 093A044D001\n\tfor <linux-cifs@vger.kernel.org>; Tue, 28 Apr 2026 16:08:37 +0000 (UTC)","by mail-pl1-f180.google.com with SMTP id\n d9443c01a7336-2b2589c26e3so107632255ad.1\n        for <linux-cifs@vger.kernel.org>;\n Tue, 28 Apr 2026 09:08:37 -0700 (PDT)","from sprasad-dev1.corp.microsoft.com ([167.220.110.216])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b97ac7894csm30864465ad.50.2026.04.28.09.08.36\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 28 Apr 2026 09:08:36 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777392520; cv=none;\n b=hKwjzah16jooDvREQtAW25hZUthaqgbdsKdKpwhzB3g1WA3ytiirDZoO8Cn/FGyFNf7eG6ad8QeYWjvPwirEg0Q+PMGV9uS9GRAwxrG3HZ2kHrkEuKjuy1EYiNrhJkkk7OvZv+QETrgXRQUtlWxfoU9/LUDgyk4RQuVcRAtCSvk=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777392520; c=relaxed/simple;\n\tbh=7A6DXbfDYsk+dYivDPkWaiojfYnlGKNJsQIOvSDlQls=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=Tk0w7WwJaT50ODjt5OJd65Y79OQb4QO773GBVzPCUE/KpTnIc0b4C59RfLII08UaG99tHgOSjkqLtGZt9Rg8u+C5E8DfhVn7GKacPjQyYXttHNDC06c5uCQG99Za6xydYGwjdatHHxvTp8AxPrcmEBwCZ057ji1jLfg+NeUFoBA=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=QbVsCVCs; arc=none smtp.client-ip=209.85.214.180","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777392517; x=1777997317;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=8BY/5y7bF/G0XpGQs/QcZVj1G4/LwsLHtt7BxAwjhkg=;\n        b=QbVsCVCsoSMEZx5Pwdom2SqLAaHGD6edX79tJQZkzLXjZKl79PmxvjkssUcDeIkhKl\n         zmmMPdXLi/Kp5N6G6dxeortB+xGyoLISykrctkxPstfs8hrpaMtHk6quR6gEusdEoPqH\n         P2ViXRIDELubebsjJCfci4aZzoflqt0WOmBRu9pBphHa/am+DWHyIDZblek3iHC9+k0o\n         OpSzrLNJM4Y5ZG+vHFYkMrKDmSZFgppClyfw32MVKSAuEwc9/HAe0AXw8+DwUg7xYgPb\n         sb7ev5XFSZAv74dnW7ewOpd5AamOuM4dNEaSMUTzygJpWiddr9bYTRwWqAWMW3tJ8SER\n         WDmA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777392517; x=1777997317;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=8BY/5y7bF/G0XpGQs/QcZVj1G4/LwsLHtt7BxAwjhkg=;\n        b=KlIftQmqPWYWurU1d+uHeBiZ+dCrpiMPEV5m0+VOTd3cc7Zor0QWmKYUdo9Ke5lXhw\n         XR345NG0RxVG72QcZs3vstIpkppGNPTxejQKQd5lvowsQZEHFJyY4aZWWZG8WkZsuaPE\n         Uv02BCxIth4bHb2QHebal6sqYylAuRhW21AGKf070infgmo5eUNxCJjm3/63hYBsnrDb\n         MIKKbmmqjXT66otV7aPQJIzXHMWkJSfoI3xOgHc6hnl90ERwcJckbU6kNpTf5KpVYnby\n         20z1Nso7d6+OhQiErbHm7e6g5EVqhtPas+cI1K9txCz5x/mhmpzqj2DsvoxxqNFvWOLo\n         AM4Q==","X-Gm-Message-State":"AOJu0YwW6rQZUuYGp/lWoaiBBZh+iBqrggJMBye1VQ0ZMZSbcihhxFod\n\tIcGJqTKj9JkMu7M8NhKJQxCji2zGFUWDrEcQm1e5ctzhyXnyB7nKCP5y6gTX4IRkDhs=","X-Gm-Gg":"AeBDiev0IiVm+iURYZfw0mqY5cK5ToVQ3PZgibREGEiWQv5kqd0iRAN0hmEjFlAFUGG\n\tLJUWmPfYv2ZyCGesMv3Mb1TWj3X0AZl/HFgTuMplfqvwDifsMTAx2SL9NLj2oFt6i0SFAsvR3SX\n\tGE5msySUfgYkmIbJxTm0r67h7Eatk2JVirk28BC+jak7BhoK/weCY2wC2XV5xwhixBYIP6Ridap\n\ttUJTg1wy72G6ADbdOsh5T75ezMPgCMil/t6fDQwHAjfKtIILYMVxgGOQdFV8LXOH8H5KIaMqus5\n\t6rH4S4234DaCogcM/cXAq/LhciWHzvY/CK/vvOUbTQ3D0pHjP8PqnMW22QsTvwgB5xfsLGHzbIb\n\tev/rA3MbVxGSn+jdXjLxuE7/LD6id72PSx1NE1p2y3npU0J0kRkK5x3qpA4Ti63LHV9n1DnYTyd\n\trlnIKNQzsQvBEosJyp4+z7CF35ZlXhkZ7vNkN1DHYpEsCWDgSwoDakM/wgeSTUN1+m","X-Received":"by 2002:a17:902:f70e:b0:2b0:ac1e:9720 with SMTP id\n d9443c01a7336-2b98744708fmr423335ad.23.1777392516916;\n        Tue, 28 Apr 2026 09:08:36 -0700 (PDT)","From":"nspmangalore@gmail.com","X-Google-Original-From":"sprasad@microsoft.com","To":"linux-cifs@vger.kernel.org,\n\tsmfrench@gmail.com,\n\tpc@manguebit.org,\n\tbharathsm@microsoft.com,\n\tdhowells@redhat.com,\n\thenrique.carvalho@suse.com,\n\tematsumiya@suse.de","Cc":"Shyam Prasad N <sprasad@microsoft.com>","Subject":"[PATCH v3 19/19] cifs: invalidate cached_dirents if population\n aborted","Date":"Tue, 28 Apr 2026 21:38:04 +0530","Message-ID":"<20260428160804.281745-19-sprasad@microsoft.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260428160804.281745-1-sprasad@microsoft.com>","References":"<20260428160804.281745-1-sprasad@microsoft.com>","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"From: Shyam Prasad N <sprasad@microsoft.com>\n\nIn order to make sure that parallel readdirs do not populate\nthe cfid->cached_dirents, only the first readdir is given\n\"ownership\" of populating cached_dirents. However, if the\nnext readdir on the same FD never arrives, we will always\nmiss the dirent cache.\n\nThis change introduces a 10-second timeout which will be used\nby laundromat thread to check if the cached_dirents can be\ninvalidated. Ten seconds is a long enough interval between\nsuccessive readdir calls.\n\nSigned-off-by: Shyam Prasad N <sprasad@microsoft.com>\n---\n fs/smb/client/cached_dir.c | 65 ++++++++++++++++++++++++++++++++++----\n fs/smb/client/cached_dir.h |  1 +\n 2 files changed, 60 insertions(+), 6 deletions(-)","diff":"diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c\nindex 14c87ac1a4ad4..b626045745ca2 100644\n--- a/fs/smb/client/cached_dir.c\n+++ b/fs/smb/client/cached_dir.c\n@@ -23,12 +23,18 @@ static void cfids_laundromat_worker(struct work_struct *work);\n \n #define CACHED_DIRENT_HASH_BITS\t7\n #define CACHED_DIR_DENTRY_HT_BITS\t8\n+#define CACHED_DIR_POPULATE_TIMEOUT\t10\n \n struct cached_dir_dentry {\n \tstruct list_head entry;\n \tstruct dentry *dentry;\n };\n \n+struct cached_dir_invalidate_entry {\n+\tstruct list_head entry;\n+\tstruct cached_fid *cfid;\n+};\n+\n /* Generic helpers */\n bool cached_dir_is_valid(struct cached_fid *cfid)\n {\n@@ -496,6 +502,7 @@ static void fail_cached_dir_locked(struct cached_dirents *cde)\n \t * can claim this slot and repopulate the cache.\n \t */\n \tcde->file = NULL;\n+\tcde->last_populate_time = 0;\n }\n \n /* insert cached_dirent into lookup hashtable */\n@@ -799,6 +806,7 @@ bool emit_cached_dir_if_valid(struct cached_fid *cfid,\n \t\tcfid->dirents.file = file;\n \t\tcfid->dirents.dir_inode = file_inode(file);\n \t\tcfid->dirents.pos = 2;\n+\t\tcfid->dirents.last_populate_time = jiffies;\n \t\tcached_dir_reset_insert_cursor_locked(&cfid->dirents);\n \t\t/*\n \t\t * A previous population attempt may have failed and left\n@@ -851,6 +859,28 @@ static void finished_cached_dirents_count(struct cached_dirents *cde,\n \t\tcached_mapping->folio_is_eof = 1;\n \n \tcde->is_valid = 1;\n+\tcde->last_populate_time = 0;\n+}\n+\n+static void maybe_invalidate_stale_cached_dirents(struct cached_fid *cfid)\n+{\n+\tstruct cached_dirents *cde = &cfid->dirents;\n+\n+\tmutex_lock(&cde->de_mutex);\n+\tif (cde->last_populate_time && !cde->is_valid && !cde->is_failed &&\n+\t    cde->file &&\n+\t    time_after(jiffies,\n+\t\t       cde->last_populate_time + HZ * CACHED_DIR_POPULATE_TIMEOUT))\n+\t\tfail_cached_dir_locked(cde);\n+\tmutex_unlock(&cde->de_mutex);\n+}\n+\n+static unsigned long cached_dir_laundromat_interval_seconds(void)\n+{\n+\tif (!dir_cache_timeout)\n+\t\treturn CACHED_DIR_POPULATE_TIMEOUT;\n+\n+\treturn min_t(unsigned int, dir_cache_timeout, CACHED_DIR_POPULATE_TIMEOUT);\n }\n \n /* update the cached_dirent for a given name in list */\n@@ -992,6 +1022,8 @@ bool add_to_cached_dir(struct cached_fid *cfid,\n \told_bytes = cfid->dirents.bytes_used;\n \tadded = add_cached_dirent(&cfid->dirents, ctx, name, namelen,\n \t\t\t\t  fattr, file);\n+\tif (added)\n+\t\tcfid->dirents.last_populate_time = jiffies;\n \tnew_entries = cfid->dirents.entries_count;\n \tnew_bytes = cfid->dirents.bytes_used;\n \tmutex_unlock(&cfid->dirents.de_mutex);\n@@ -2111,7 +2143,9 @@ static void cfids_laundromat_worker(struct work_struct *work)\n {\n \tstruct cached_fids *cfids;\n \tstruct cached_fid *cfid, *q;\n+\tstruct cached_dir_invalidate_entry *inv, *inv_q;\n \tLIST_HEAD(entry);\n+\tLIST_HEAD(invalidate_list);\n \n \tcfids = container_of(work, struct cached_fids, laundromat_work.work);\n \n@@ -2121,6 +2155,9 @@ static void cfids_laundromat_worker(struct work_struct *work)\n \n \tfor (struct rb_node *rb_node = rb_first(&cfids->entries), *next_node;\n \t     rb_node; rb_node = next_node) {\n+\t\tstruct cached_dir_invalidate_entry *inv_ent;\n+\t\tunsigned long last_populate_time;\n+\n \t\tnext_node = rb_next(rb_node);\n \t\tcfid = rb_entry(rb_node, struct cached_fid, node);\n \t\tspin_lock(&cfid->cfid_lock);\n@@ -2144,11 +2181,29 @@ static void cfids_laundromat_worker(struct work_struct *work)\n \t\t\t\tkref_get(&cfid->refcount);\n \t\t\t}\n \t\t} else {\n+\t\t\tlast_populate_time = READ_ONCE(cfid->dirents.last_populate_time);\n+\t\t\tif (last_populate_time &&\n+\t\t\t    time_after(jiffies,\n+\t\t\t\t       last_populate_time + HZ * CACHED_DIR_POPULATE_TIMEOUT)) {\n+\t\t\t\tinv_ent = kmalloc_obj(*inv_ent, GFP_ATOMIC);\n+\t\t\t\tif (inv_ent) {\n+\t\t\t\t\tkref_get(&cfid->refcount);\n+\t\t\t\t\tinv_ent->cfid = cfid;\n+\t\t\t\t\tlist_add_tail(&inv_ent->entry, &invalidate_list);\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tspin_unlock(&cfid->cfid_lock);\n \t\t}\n \t}\n \tspin_unlock(&cfids->cfid_list_lock);\n \n+\tlist_for_each_entry_safe(inv, inv_q, &invalidate_list, entry) {\n+\t\tlist_del(&inv->entry);\n+\t\tmaybe_invalidate_stale_cached_dirents(inv->cfid);\n+\t\tclose_cached_dir(inv->cfid);\n+\t\tkfree(inv);\n+\t}\n+\n \tlist_for_each_entry_safe(cfid, q, &entry, dying_entry) {\n \t\tlist_del(&cfid->dying_entry);\n \n@@ -2169,9 +2224,8 @@ static void cfids_laundromat_worker(struct work_struct *work)\n \t\t\t */\n \t\t\tclose_cached_dir(cfid);\n \t}\n-\tif (dir_cache_timeout)\n-\t\tqueue_delayed_work(cfid_put_wq, &cfids->laundromat_work,\n-\t\t\t\t   dir_cache_timeout * HZ);\n+\tqueue_delayed_work(cfid_put_wq, &cfids->laundromat_work,\n+\t\t\t   cached_dir_laundromat_interval_seconds() * HZ);\n }\n \n struct cached_fids *init_cached_dirs(void)\n@@ -2192,9 +2246,8 @@ struct cached_fids *init_cached_dirs(void)\n \tINIT_LIST_HEAD(&cfids->dying);\n \n \tINIT_DELAYED_WORK(&cfids->laundromat_work, cfids_laundromat_worker);\n-\tif (dir_cache_timeout)\n-\t\tqueue_delayed_work(cfid_put_wq, &cfids->laundromat_work,\n-\t\t\t\t   dir_cache_timeout * HZ);\n+\tqueue_delayed_work(cfid_put_wq, &cfids->laundromat_work,\n+\t\t\t   cached_dir_laundromat_interval_seconds() * HZ);\n \n \tatomic_long_set(&cfids->total_dirents_entries, 0);\n \tatomic64_set(&cfids->total_dirents_bytes, 0);\ndiff --git a/fs/smb/client/cached_dir.h b/fs/smb/client/cached_dir.h\nindex 58dde9452ec9b..eca0a0ca3674c 100644\n--- a/fs/smb/client/cached_dir.h\n+++ b/fs/smb/client/cached_dir.h\n@@ -120,6 +120,7 @@ struct cached_dirents {\n \tstruct inode *dir_inode;\n \tstruct mutex de_mutex;\n \tloff_t pos;\t\t /* Expected ctx->pos */\n+\tunsigned long last_populate_time; /* jiffies of last successful populate progress */\n \tstruct folio_queue *folioq;\n \tstruct list_head entry_list;\n \tunsigned int entry_list_count;\n","prefixes":["v3","19/19"]}