From patchwork Sat Jan 21 14:47:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1729949 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=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=ePgCDBKd; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzfNP1drtz23gL for ; Sun, 22 Jan 2023 01:47:33 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pJF9S-0000En-RA; Sat, 21 Jan 2023 14:47:26 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pJF9N-0000A2-Lm for kernel-team@lists.ubuntu.com; Sat, 21 Jan 2023 14:47:21 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 61A56418E4 for ; Sat, 21 Jan 2023 14:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674312441; bh=R+MJbrG/B8IFBibVzML+G64akNZ8g7DkQpoULrR9sDA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ePgCDBKdAagq6jsLFnqwulKCwjy3BpUnlVfG/4EBdFMPQCgZQEsn6AVEDg9rQdj3K UpJK7O+f4kNZBzvoAYds8wkawsOM0ib7nHiEL+qSJr+Fms1XuCnv8m+o5UaF8EDnMX DBoGWABnY/5bHQCXOg9O6qtDJR3Dtdp6hCY4q5IAkVsLK/hrFMOWQnpj8a5PWVapX5 6HlJgl835KlIyAp/GhuIU3WiWP9+hhPlNuAuhoDzoxMk9wCYlGa3kNozpoF3oUCYVV 0zkztz/6FDetoXOiDQuVPJe22EwnlrbjoMEMPWiYTS4BFpcvT9mzgY//ARE1wMLHGH Q0oG2Rhag/kvg== Received: by mail-pj1-f69.google.com with SMTP id pa16-20020a17090b265000b0020a71040b4cso3516738pjb.6 for ; Sat, 21 Jan 2023 06:47:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R+MJbrG/B8IFBibVzML+G64akNZ8g7DkQpoULrR9sDA=; b=KgERAx9uv/SPKFWxPunCsrW7hkaji9spHv3yEAxYCkXHR14OHvVe8AeAJ4CZ8UQfE/ H4bKHFc/lFICerbNjhI2GQ3NHGAI9iU6FmVLgl15U/eGyOXCfUUeQAHrpz5Hp7OpBW7f 3dkXfxdGv0lZyDjfBm8k9C9x+xv4WesdCUuvW/MP29+MKsiFfvIe3dA6sff78VWg5PAM xG4kpsaZQwvvfmf02u7hCWXhW91FDW12+6ZWVM2V91TNKxARowXvqch7hk172rZx/TDm U9kznkStNd+VDTSG4kE6JQ8+f78keCOAHhnS/PGEDOb1VtmXZ/RZYPIf/HohK88dsLhh Rlow== X-Gm-Message-State: AFqh2kpqthnwSum1B6sdCTMjVHc2UrxY4mGwhzvUF3eaCUf4HRh/FiCm b75CjIPfpdRI56f2FFkky3loXVgwwlkcqJ0WEyOMhzj/vHj23PySVzDAxrqRVxHADRWByeN8v8B 6pb7r7NX6ks7yHJ4qil1MX/DJWO4KfxuUUocUa/Cf3w== X-Received: by 2002:a17:902:db01:b0:195:efb2:6c6d with SMTP id m1-20020a170902db0100b00195efb26c6dmr5752173plx.45.1674312439894; Sat, 21 Jan 2023 06:47:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXvfy0wg1ng0VrL9soxIx6zPVTE/ysDTZPKhgV+BgMCDhG7cGE+eQz8PrHf5+JvF8XtVny0r6g== X-Received: by 2002:a17:902:db01:b0:195:efb2:6c6d with SMTP id m1-20020a170902db0100b00195efb26c6dmr5752158plx.45.1674312439558; Sat, 21 Jan 2023 06:47:19 -0800 (PST) Received: from chengendu.. (111-248-116-144.dynamic-ip.hinet.net. [111.248.116.144]) by smtp.gmail.com with ESMTPSA id p5-20020a170902bd0500b001932a9e4f2csm25656235pls.255.2023.01.21.06.47.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 06:47:19 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][Bionic][PATCH 3/4] (upstream) NFS: Judge the file access cache's timestamp in rcu path Date: Sat, 21 Jan 2023 22:47:12 +0800 Message-Id: <20230121144713.39111-4-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230121144713.39111-1-chengen.du@canonical.com> References: <20230121144713.39111-1-chengen.du@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2003053 If the user's login time is newer than the cache's timestamp, we expect the cache may be stale and need to clear. The stale cache will remain in the list's tail if no other users operate on that inode. Once the user accesses the inode, the stale cache will be returned in rcu path. Signed-off-by: Chengen Du Signed-off-by: Trond Myklebust (backported from commit 029085b8949f5d269ae2bbd14915407dd0c7f902) [chengen - use current_cred() as the argument to get login time] Signed-off-by: Chengen Du --- fs/nfs/dir.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 3ff938164381..9a39bb94d5d8 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2366,6 +2366,8 @@ static int nfs_access_get_cached_rcu(struct inode *inode, struct rpc_cred *cred, * but do it without locking. */ struct nfs_inode *nfsi = NFS_I(inode); + const struct cred *cur_cred = current_cred(); + u64 login_time = nfs_access_login_time(current, cur_cred); struct nfs_access_entry *cache; int err = -ECHILD; struct list_head *lh; @@ -2380,6 +2382,8 @@ static int nfs_access_get_cached_rcu(struct inode *inode, struct rpc_cred *cred, cache = NULL; if (cache == NULL) goto out; + if ((s64)(login_time - cache->timestamp) > 0) + goto out; if (nfs_check_cache_invalid(inode, NFS_INO_INVALID_ACCESS)) goto out; res->cred = cache->cred;