]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
afs: Mark afs_net::ws_cell as __rcu and set using rcu functions
authorDavid Howells <dhowells@redhat.com>
Wed, 23 May 2018 10:51:29 +0000 (11:51 +0100)
committerDavid Howells <dhowells@redhat.com>
Wed, 23 May 2018 10:51:29 +0000 (11:51 +0100)
The afs_net::ws_cell member is sometimes used under RCU conditions from
within an seq-readlock.  It isn't, however, marked __rcu and it isn't set
using the proper RCU barrier-imposing functions.

Fix this by annotating it with __rcu and using appropriate barriers to
make sure accesses are correctly ordered.

Without this, the code can produce the following warning:

>> fs/afs/proc.c:151:24: sparse: incompatible types in comparison expression (different address spaces)

Fixes: f044c8847bb6 ("afs: Lay the groundwork for supporting network namespaces")
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: David Howells <dhowells@redhat.com>
fs/afs/cell.c
fs/afs/internal.h
fs/afs/proc.c

index fdf4c36cff79ead65acf11a36b99614db924fe9b..80fd127239ce5e232c7eb923ebd625d436efa0a1 100644 (file)
@@ -341,8 +341,8 @@ int afs_cell_init(struct afs_net *net, const char *rootcell)
 
        /* install the new cell */
        write_seqlock(&net->cells_lock);
-       old_root = net->ws_cell;
-       net->ws_cell = new_root;
+       old_root = rcu_access_pointer(net->ws_cell);
+       rcu_assign_pointer(net->ws_cell, new_root);
        write_sequnlock(&net->cells_lock);
 
        afs_put_cell(net, old_root);
@@ -755,8 +755,8 @@ void afs_cell_purge(struct afs_net *net)
        _enter("");
 
        write_seqlock(&net->cells_lock);
-       ws = net->ws_cell;
-       net->ws_cell = NULL;
+       ws = rcu_access_pointer(net->ws_cell);
+       RCU_INIT_POINTER(net->ws_cell, NULL);
        write_sequnlock(&net->cells_lock);
        afs_put_cell(net, ws);
 
index f8086ec95e24161eb9b9900745275e1cc4c1cfc6..5d922ad148a8c1d17279270a7684a0625447a95d 100644 (file)
@@ -231,7 +231,7 @@ struct afs_net {
 
        /* Cell database */
        struct rb_root          cells;
-       struct afs_cell         *ws_cell;
+       struct afs_cell __rcu   *ws_cell;
        struct work_struct      cells_manager;
        struct timer_list       cells_timer;
        atomic_t                cells_outstanding;
index b45ee7576aa88c19aaa0d9ee23f5a98558c4b294..362f281b1b165f8aae845684bf754c4f8fb86e46 100644 (file)
@@ -173,7 +173,7 @@ static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
 
        if (*_pos > 0)
                return 0;
-       if (!net->ws_cell)
+       if (!rcu_access_pointer(net->ws_cell))
                return 0;
 
        rcu_read_lock();