#include "bpf_misc.h"
 #include "bpf_experimental.h"
 
+extern void bpf_rcu_read_lock(void) __ksym;
+extern void bpf_rcu_read_unlock(void) __ksym;
+
 struct node_data {
        long key;
        long list_data;
        return 0;
 }
 
+SEC("?fentry.s/bpf_testmod_test_read")
+__success
+int BPF_PROG(rbtree_sleepable_rcu,
+            struct file *file, struct kobject *kobj,
+            struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
+{
+       struct bpf_rb_node *rb;
+       struct node_data *n, *m = NULL;
+
+       n = bpf_obj_new(typeof(*n));
+       if (!n)
+               return 0;
+
+       bpf_rcu_read_lock();
+       bpf_spin_lock(&lock);
+       bpf_rbtree_add(&root, &n->r, less);
+       rb = bpf_rbtree_first(&root);
+       if (!rb)
+               goto err_out;
+
+       rb = bpf_rbtree_remove(&root, rb);
+       if (!rb)
+               goto err_out;
+
+       m = container_of(rb, struct node_data, r);
+
+err_out:
+       bpf_spin_unlock(&lock);
+       bpf_rcu_read_unlock();
+       if (m)
+               bpf_obj_drop(m);
+       return 0;
+}
+
+SEC("?fentry.s/bpf_testmod_test_read")
+__success
+int BPF_PROG(rbtree_sleepable_rcu_no_explicit_rcu_lock,
+            struct file *file, struct kobject *kobj,
+            struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
+{
+       struct bpf_rb_node *rb;
+       struct node_data *n, *m = NULL;
+
+       n = bpf_obj_new(typeof(*n));
+       if (!n)
+               return 0;
+
+       /* No explicit bpf_rcu_read_lock */
+       bpf_spin_lock(&lock);
+       bpf_rbtree_add(&root, &n->r, less);
+       rb = bpf_rbtree_first(&root);
+       if (!rb)
+               goto err_out;
+
+       rb = bpf_rbtree_remove(&root, rb);
+       if (!rb)
+               goto err_out;
+
+       m = container_of(rb, struct node_data, r);
+
+err_out:
+       bpf_spin_unlock(&lock);
+       /* No explicit bpf_rcu_read_unlock */
+       if (m)
+               bpf_obj_drop(m);
+       return 0;
+}
+
 char _license[] SEC("license") = "GPL";
 
        struct bpf_refcount refcount;
 };
 
+extern void bpf_rcu_read_lock(void) __ksym;
+extern void bpf_rcu_read_unlock(void) __ksym;
+
 #define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8)))
 private(A) struct bpf_spin_lock glock;
 private(A) struct bpf_rb_root groot __contains(node_acquire, node);
        return 0;
 }
 
+SEC("?fentry.s/bpf_testmod_test_read")
+__failure __msg("function calls are not allowed while holding a lock")
+int BPF_PROG(rbtree_fail_sleepable_lock_across_rcu,
+            struct file *file, struct kobject *kobj,
+            struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
+{
+       struct node_acquire *n;
+
+       n = bpf_obj_new(typeof(*n));
+       if (!n)
+               return 0;
+
+       /* spin_{lock,unlock} are in different RCU CS */
+       bpf_rcu_read_lock();
+       bpf_spin_lock(&glock);
+       bpf_rbtree_add(&groot, &n->node, less);
+       bpf_rcu_read_unlock();
+
+       bpf_rcu_read_lock();
+       bpf_spin_unlock(&glock);
+       bpf_rcu_read_unlock();
+
+       return 0;
+}
+
 char _license[] SEC("license") = "GPL";