Skip to content

Commit 1588def

Browse files
committed
afs: Mark afs_net::ws_cell as __rcu and set using rcu functions
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: f044c88 ("afs: Lay the groundwork for supporting network namespaces") Reported-by: kbuild test robot <[email protected]> Signed-off-by: David Howells <[email protected]>
1 parent c875c76 commit 1588def

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

fs/afs/cell.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ int afs_cell_init(struct afs_net *net, const char *rootcell)
341341

342342
/* install the new cell */
343343
write_seqlock(&net->cells_lock);
344-
old_root = net->ws_cell;
345-
net->ws_cell = new_root;
344+
old_root = rcu_access_pointer(net->ws_cell);
345+
rcu_assign_pointer(net->ws_cell, new_root);
346346
write_sequnlock(&net->cells_lock);
347347

348348
afs_put_cell(net, old_root);
@@ -755,8 +755,8 @@ void afs_cell_purge(struct afs_net *net)
755755
_enter("");
756756

757757
write_seqlock(&net->cells_lock);
758-
ws = net->ws_cell;
759-
net->ws_cell = NULL;
758+
ws = rcu_access_pointer(net->ws_cell);
759+
RCU_INIT_POINTER(net->ws_cell, NULL);
760760
write_sequnlock(&net->cells_lock);
761761
afs_put_cell(net, ws);
762762

fs/afs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct afs_net {
231231

232232
/* Cell database */
233233
struct rb_root cells;
234-
struct afs_cell *ws_cell;
234+
struct afs_cell __rcu *ws_cell;
235235
struct work_struct cells_manager;
236236
struct timer_list cells_timer;
237237
atomic_t cells_outstanding;

fs/afs/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
173173

174174
if (*_pos > 0)
175175
return 0;
176-
if (!net->ws_cell)
176+
if (!rcu_access_pointer(net->ws_cell))
177177
return 0;
178178

179179
rcu_read_lock();

0 commit comments

Comments
 (0)