From 54ac471c83aff6b1e068eb8029c797dc68a76e89 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Wed, 23 May 2012 13:26:10 -0400 Subject: [PATCH] NFS: Add memory barriers to the nfs_client->cl_cons_state initialisation Ensure that a process that uses the nfs_client->cl_cons_state test for whether the initialisation process is finished does not read stale data. Signed-off-by: Trond Myklebust --- fs/nfs/client.c | 5 +++++ fs/nfs/idmap.c | 1 + fs/nfs/nfs4proc.c | 1 + 3 files changed, 7 insertions(+) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index d35664287e14..a50bdfbbc429 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -459,6 +459,8 @@ static bool nfs4_cb_match_client(const struct sockaddr *addr, clp->cl_cons_state == NFS_CS_SESSION_INITING)) return false; + smp_rmb(); + /* Match the version and minorversion */ if (clp->rpc_ops->version != 4 || clp->cl_minorversion != minorversion) @@ -539,6 +541,8 @@ nfs_found_client(const struct nfs_client_initdata *cl_init, return ERR_PTR(error); } + smp_rmb(); + BUG_ON(clp->cl_cons_state != NFS_CS_READY); dprintk("<-- %s found nfs_client %p for %s\n", @@ -597,6 +601,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init, */ void nfs_mark_client_ready(struct nfs_client *clp, int state) { + smp_wmb(); clp->cl_cons_state = state; wake_up_all(&nfs_client_active_wq); } diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c index 861be75eb165..b5b86a05059c 100644 --- a/fs/nfs/idmap.c +++ b/fs/nfs/idmap.c @@ -548,6 +548,7 @@ static struct nfs_client *nfs_get_client_for_event(struct net *net, int event) /* Skip nfs_clients that failed to initialise */ if (clp->cl_cons_state < 0) continue; + smp_rmb(); if (clp->rpc_ops != &nfs_v4_clientops) continue; cl_dentry = clp->cl_idmap->idmap_pipe->dentry; diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index c856298def7d..8f39bb3ca1b3 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -5621,6 +5621,7 @@ static int nfs41_check_session_ready(struct nfs_client *clp) } if (clp->cl_cons_state < NFS_CS_READY) return -EPROTONOSUPPORT; + smp_rmb(); return 0; } -- GitLab