]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
pnfs/flexfiles: Fix misplaced barrier in nfs4_ff_layout_prepare_ds
authorBaptiste Lepers <baptiste.lepers@gmail.com>
Mon, 6 Sep 2021 01:59:24 +0000 (11:59 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Nov 2021 10:36:14 +0000 (11:36 +0100)
[ Upstream commit a2915fa06227b056a8f9b0d79b61dca08ad5cfc6 ]

_nfs4_pnfs_v3/v4_ds_connect do
   some work
   smp_wmb
   ds->ds_clp = clp;

And nfs4_ff_layout_prepare_ds currently does
   smp_rmb
   if(ds->ds_clp)
      ...

This patch places the smp_rmb after the if. This ensures that following
reads only happen once nfs4_ff_layout_prepare_ds has checked that data
has been properly initialized.

Fixes: d67ae825a59d6 ("pnfs/flexfiles: Add the FlexFile Layout Driver")
Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/flexfilelayout/flexfilelayoutdev.c
fs/nfs/pnfs_nfs.c

index 8da239b6cc16ffb7790015debe6eca4ae505ecd6..f1f0519f1ecef0611e01116ffc1886bba432feb5 100644 (file)
@@ -429,10 +429,10 @@ nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx,
                goto out_fail;
 
        ds = mirror->mirror_ds->ds;
+       if (READ_ONCE(ds->ds_clp))
+               goto out;
        /* matching smp_wmb() in _nfs4_pnfs_v3/4_ds_connect */
        smp_rmb();
-       if (ds->ds_clp)
-               goto out;
 
        /* FIXME: For now we assume the server sent only one version of NFS
         * to use for the DS.
index 3f0c2436254ace24da5bd0f3307844b7e6facbfd..bd6190d794c49e5cf452433cd92a86b202882b27 100644 (file)
@@ -635,7 +635,7 @@ static int _nfs4_pnfs_v3_ds_connect(struct nfs_server *mds_srv,
        }
 
        smp_wmb();
-       ds->ds_clp = clp;
+       WRITE_ONCE(ds->ds_clp, clp);
        dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr);
 out:
        return status;
@@ -708,7 +708,7 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv,
        }
 
        smp_wmb();
-       ds->ds_clp = clp;
+       WRITE_ONCE(ds->ds_clp, clp);
        dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr);
 out:
        return status;