STATIC int xfs_reclaim_inode_grab( struct xfs_inode *ip, int flags) { ASSERT(rcu_read_lock_held()); if (!ip->i_ino) return 1; if ((flags & SYNC_TRYLOCK) && __xfs_iflags_test(ip, XFS_IFLOCK | XFS_IRECLAIM)) return 1; spin_lock(&ip->i_flags_lock); if (!__xfs_iflags_test(ip, XFS_IRECLAIMABLE) || __xfs_iflags_test(ip, XFS_IRECLAIM)) { spin_unlock(&ip->i_flags_lock); return 1; } __xfs_iflags_set(ip, XFS_IRECLAIM); spin_unlock(&ip->i_flags_lock); return 0; }
static void mesh_sync_offset_adjust_tsf(struct ieee80211_sub_if_data *sdata, struct beacon_data *beacon) { struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; WARN_ON(ifmsh->mesh_sp_id != IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET); WARN_ON(!rcu_read_lock_held()); spin_lock_bh(&ifmsh->sync_offset_lock); if (ifmsh->sync_offset_clockdrift_max > TOFFSET_MINIMUM_ADJUSTMENT) { /* Since ajusting the tsf here would * require a possibly blocking call * to the driver tsf setter, we punt * the tsf adjustment to the mesh tasklet */ msync_dbg(sdata, "TSF : kicking off TSF adjustment with clockdrift_max=%lld\n", ifmsh->sync_offset_clockdrift_max); set_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags); } else { msync_dbg(sdata, "TSF : max clockdrift=%lld; too small to adjust\n", (long long)ifmsh->sync_offset_clockdrift_max); ifmsh->sync_offset_clockdrift_max = 0; } spin_unlock_bh(&ifmsh->sync_offset_lock); }
static int stack_map_get_next_key(struct bpf_map *map, void *key, void *next_key) { struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map); u32 id; WARN_ON_ONCE(!rcu_read_lock_held()); if (!key) { id = 0; } else { id = *(u32 *)key; if (id >= smap->n_buckets || !smap->buckets[id]) id = 0; else id++; } while (id < smap->n_buckets && !smap->buckets[id]) id++; if (id >= smap->n_buckets) return -ENOENT; *(u32 *)next_key = id; return 0; }
/* assumes rcu_read_lock() held at entry */ struct dev_pagemap *find_dev_pagemap(resource_size_t phys) { struct page_map *page_map; WARN_ON_ONCE(!rcu_read_lock_held()); page_map = radix_tree_lookup(&pgmap_radix, phys >> PA_SECTION_SHIFT); return page_map ? &page_map->pgmap : NULL; }
static u64 bpf_map_delete_elem(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) { struct bpf_map *map = (struct bpf_map *) (unsigned long) r1; void *key = (void *) (unsigned long) r2; WARN_ON_ONCE(!rcu_read_lock_held()); return map->ops->map_delete_elem(map, key); }
/** * skb_dst_set_noref - sets skb dst, without a reference * @skb: buffer * @dst: dst entry * * Sets skb dst, assuming a reference was not taken on dst * skb_dst_drop() should not dst_release() this dst */ void skb_dst_set_noref(struct sk_buff *skb, struct dst_entry *dst) { WARN_ON(!rcu_read_lock_held() && !rcu_read_lock_bh_held()); /* If dst not in cache, we must take a reference, because * dst_release() will destroy dst as soon as its refcount becomes zero */ if (unlikely(dst->flags & DST_NOCACHE)) { dst_hold(dst); skb_dst_set(skb, dst); } else { skb->_skb_refdst = (unsigned long)dst | SKB_DST_NOREF; } }
STATIC int xfs_inode_ag_walk_grab( struct xfs_inode *ip) { struct inode *inode = VFS_I(ip); ASSERT(rcu_read_lock_held()); /* * check for stale RCU freed inode * * If the inode has been reallocated, it doesn't matter if it's not in * the AG we are walking - we are walking for writeback, so if it * passes all the "valid inode" checks and is dirty, then we'll write * it back anyway. If it has been reallocated and still being * initialised, the XFS_INEW check below will catch it. */ spin_lock(&ip->i_flags_lock); if (!ip->i_ino) goto out_unlock_noent; /* avoid new or reclaimable inodes. Leave for reclaim code to flush */ if (__xfs_iflags_test(ip, XFS_INEW | XFS_IRECLAIMABLE | XFS_IRECLAIM)) goto out_unlock_noent; spin_unlock(&ip->i_flags_lock); /* nothing to sync during shutdown */ if (XFS_FORCED_SHUTDOWN(ip->i_mount)) return EFSCORRUPTED; /* If we can't grab the inode, it must on it's way to reclaim. */ if (!igrab(inode)) return ENOENT; if (is_bad_inode(inode)) { IRELE(ip); return ENOENT; } /* inode is valid */ return 0; out_unlock_noent: spin_unlock(&ip->i_flags_lock); return ENOENT; }
/* Must be called with rcu_read_lock. */ static struct plum_replicator_elem *replicator_lookup_port(const struct plum *plum, u32 replicator_id, u32 port_id) { struct hlist_head *head; struct plum_replicator_elem *elem; WARN_ON_ONCE(!rcu_read_lock_held()); head = replicator_hash_bucket(plum, replicator_id); hlist_for_each_entry_rcu(elem, head, hash_node) { if (elem->replicator_id == replicator_id && elem->port_id == port_id) return elem; } return NULL; }
/* If kernel subsystem is allowing eBPF programs to call this function, * inside its own verifier_ops->get_func_proto() callback it should return * bpf_map_lookup_elem_proto, so that verifier can properly check the arguments * * Different map implementations will rely on rcu in map methods * lookup/update/delete, therefore eBPF programs must run under rcu lock * if program is allowed to access maps, so check rcu_read_lock_held in * all three functions. */ static u64 bpf_map_lookup_elem(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) { /* verifier checked that R1 contains a valid pointer to bpf_map * and R2 points to a program stack and map->key_size bytes were * initialized */ struct bpf_map *map = (struct bpf_map *) (unsigned long) r1; void *key = (void *) (unsigned long) r2; void *value; WARN_ON_ONCE(!rcu_read_lock_held()); value = map->ops->map_lookup_elem(map, key); /* lookup() returns either pointer to element value or NULL * which is the meaning of PTR_TO_MAP_VALUE_OR_NULL type */ return (unsigned long) value; }
/* * Grab the inode for reclaim exclusively. * Return 0 if we grabbed it, non-zero otherwise. */ STATIC int xfs_reclaim_inode_grab( struct xfs_inode *ip, int flags) { ASSERT(rcu_read_lock_held()); /* quick check for stale RCU freed inode */ if (!ip->i_ino) return 1; /* * do some unlocked checks first to avoid unnecessary lock traffic. * The first is a flush lock check, the second is a already in reclaim * check. Only do these checks if we are not going to block on locks. */ if ((flags & SYNC_TRYLOCK) && (!ip->i_flush.done || __xfs_iflags_test(ip, XFS_IRECLAIM))) { return 1; } /* * The radix tree lock here protects a thread in xfs_iget from racing * with us starting reclaim on the inode. Once we have the * XFS_IRECLAIM flag set it will not touch us. * * Due to RCU lookup, we may find inodes that have been freed and only * have XFS_IRECLAIM set. Indeed, we may see reallocated inodes that * aren't candidates for reclaim at all, so we must check the * XFS_IRECLAIMABLE is set first before proceeding to reclaim. */ spin_lock(&ip->i_flags_lock); if (!__xfs_iflags_test(ip, XFS_IRECLAIMABLE) || __xfs_iflags_test(ip, XFS_IRECLAIM)) { /* not a reclaim candidate. */ spin_unlock(&ip->i_flags_lock); return 1; } __xfs_iflags_set(ip, XFS_IRECLAIM); spin_unlock(&ip->i_flags_lock); return 0; }
/* * Grab the inode for reclaim exclusively. * Return 0 if we grabbed it, non-zero otherwise. */ STATIC int xfs_reclaim_inode_grab( struct xfs_inode *ip, int flags) { ASSERT(rcu_read_lock_held()); /* quick check for stale RCU freed inode */ if (!ip->i_ino) return 1; /* * If we are asked for non-blocking operation, do unlocked checks to * see if the inode already is being flushed or in reclaim to avoid * lock traffic. */ if ((flags & SYNC_TRYLOCK) && __xfs_iflags_test(ip, XFS_IFLOCK | XFS_IRECLAIM)) return 1; /* * The radix tree lock here protects a thread in xfs_iget from racing * with us starting reclaim on the inode. Once we have the * XFS_IRECLAIM flag set it will not touch us. * * Due to RCU lookup, we may find inodes that have been freed and only * have XFS_IRECLAIM set. Indeed, we may see reallocated inodes that * aren't candidates for reclaim at all, so we must check the * XFS_IRECLAIMABLE is set first before proceeding to reclaim. */ spin_lock(&ip->i_flags_lock); if (!__xfs_iflags_test(ip, XFS_IRECLAIMABLE) || __xfs_iflags_test(ip, XFS_IRECLAIM)) { /* not a reclaim candidate. */ spin_unlock(&ip->i_flags_lock); return 1; } __xfs_iflags_set(ip, XFS_IRECLAIM); spin_unlock(&ip->i_flags_lock); return 0; }
STATIC int xfs_inode_ag_walk_grab( struct xfs_inode *ip) { struct inode *inode = VFS_I(ip); ASSERT(rcu_read_lock_held()); spin_lock(&ip->i_flags_lock); if (!ip->i_ino) goto out_unlock_noent; if (__xfs_iflags_test(ip, XFS_INEW | XFS_IRECLAIMABLE | XFS_IRECLAIM)) goto out_unlock_noent; spin_unlock(&ip->i_flags_lock); if (XFS_FORCED_SHUTDOWN(ip->i_mount)) return EFSCORRUPTED; if (!igrab(inode)) return ENOENT; if (is_bad_inode(inode)) { IRELE(ip); return ENOENT; } return 0; out_unlock_noent: spin_unlock(&ip->i_flags_lock); return ENOENT; }
BPF_CALL_2(bpf_map_delete_elem, struct bpf_map *, map, void *, key) { WARN_ON_ONCE(!rcu_read_lock_held()); return map->ops->map_delete_elem(map, key); }
BPF_CALL_4(bpf_map_update_elem, struct bpf_map *, map, void *, key, void *, value, u64, flags) { WARN_ON_ONCE(!rcu_read_lock_held()); return map->ops->map_update_elem(map, key, value, flags); }
/* If kernel subsystem is allowing eBPF programs to call this function, * inside its own verifier_ops->get_func_proto() callback it should return * bpf_map_lookup_elem_proto, so that verifier can properly check the arguments * * Different map implementations will rely on rcu in map methods * lookup/update/delete, therefore eBPF programs must run under rcu lock * if program is allowed to access maps, so check rcu_read_lock_held in * all three functions. */ BPF_CALL_2(bpf_map_lookup_elem, struct bpf_map *, map, void *, key) { WARN_ON_ONCE(!rcu_read_lock_held()); return (unsigned long) map->ops->map_lookup_elem(map, key); }
/** * xprt_iter_xprt - Returns the rpc_xprt pointed to by the cursor * @xpi: pointer to rpc_xprt_iter * * Returns a pointer to the struct rpc_xprt that is currently * pointed to by the cursor. * Caller must be holding rcu_read_lock(). */ struct rpc_xprt *xprt_iter_xprt(struct rpc_xprt_iter *xpi) { WARN_ON_ONCE(!rcu_read_lock_held()); return xprt_iter_ops(xpi)->xpi_xprt(xpi); }