ANDROID: GKI: net: add vendor hooks for 'struct sock' lifecycle

Some vendors want to add a field when a 'sruct sock' is added so give a
hook to handle this.  Any memory allocated when
trace_android_rvh_sk_alloc() is called needs to be freed when
trace_android_rvh_sk_free() is called.

Note, if trace_android_rvh_sk_alloc() fails, be sure to be able to
handle this in trace_android_rvh_sk_free(), but that should not be an
issue as that needs to be addressed in vendor code that runs for 'struct
sock' objects that have been created before the vendor code is loaded no
matter what.

Bug: 171013716
Signed-off-by: Vignesh Saravanaperumal <vignesh1.s@samsung.com>
Change-Id: I108a2f31d2dcc228f46159816deee6235afafbbd
This commit is contained in:
Vignesh Saravanaperumal
2021-07-08 12:09:18 -07:00
committed by Todd Kjos
parent 4d30956478
commit 0ed7424fa0
3 changed files with 12 additions and 0 deletions

View File

@@ -91,6 +91,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_prepare_prio_fork);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_finish_prio_fork); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_finish_prio_fork);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_user_nice); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_user_nice);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_setscheduler); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_setscheduler);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_sk_alloc);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_sk_free);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_nf_conn_alloc); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_nf_conn_alloc);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_nf_conn_free); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_nf_conn_free);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_arch_set_freq_scale); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_arch_set_freq_scale);

View File

@@ -19,10 +19,15 @@ DECLARE_HOOK(android_vh_kfree_skb,
TP_PROTO(struct sk_buff *skb), TP_ARGS(skb)); TP_PROTO(struct sk_buff *skb), TP_ARGS(skb));
struct nf_conn; struct nf_conn;
struct sock;
DECLARE_RESTRICTED_HOOK(android_rvh_nf_conn_alloc, DECLARE_RESTRICTED_HOOK(android_rvh_nf_conn_alloc,
TP_PROTO(struct nf_conn *nf_conn), TP_ARGS(nf_conn), 1); TP_PROTO(struct nf_conn *nf_conn), TP_ARGS(nf_conn), 1);
DECLARE_RESTRICTED_HOOK(android_rvh_nf_conn_free, DECLARE_RESTRICTED_HOOK(android_rvh_nf_conn_free,
TP_PROTO(struct nf_conn *nf_conn), TP_ARGS(nf_conn), 1); TP_PROTO(struct nf_conn *nf_conn), TP_ARGS(nf_conn), 1);
DECLARE_RESTRICTED_HOOK(android_rvh_sk_alloc,
TP_PROTO(struct sock *sock), TP_ARGS(sock), 1);
DECLARE_RESTRICTED_HOOK(android_rvh_sk_free,
TP_PROTO(struct sock *sock), TP_ARGS(sock), 1);
/* macro versions of hooks are no longer required */ /* macro versions of hooks are no longer required */

View File

@@ -136,6 +136,7 @@
#include <trace/events/sock.h> #include <trace/events/sock.h>
#include <trace/hooks/sched.h> #include <trace/hooks/sched.h>
#include <trace/hooks/net.h>
#include <net/tcp.h> #include <net/tcp.h>
#include <net/busy_poll.h> #include <net/busy_poll.h>
@@ -1678,6 +1679,8 @@ static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,
if (security_sk_alloc(sk, family, priority)) if (security_sk_alloc(sk, family, priority))
goto out_free; goto out_free;
trace_android_rvh_sk_alloc(sk);
if (!try_module_get(prot->owner)) if (!try_module_get(prot->owner))
goto out_free_sec; goto out_free_sec;
sk_tx_queue_clear(sk); sk_tx_queue_clear(sk);
@@ -1687,6 +1690,7 @@ static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,
out_free_sec: out_free_sec:
security_sk_free(sk); security_sk_free(sk);
trace_android_rvh_sk_free(sk);
out_free: out_free:
if (slab != NULL) if (slab != NULL)
kmem_cache_free(slab, sk); kmem_cache_free(slab, sk);
@@ -1706,6 +1710,7 @@ static void sk_prot_free(struct proto *prot, struct sock *sk)
cgroup_sk_free(&sk->sk_cgrp_data); cgroup_sk_free(&sk->sk_cgrp_data);
mem_cgroup_sk_free(sk); mem_cgroup_sk_free(sk);
security_sk_free(sk); security_sk_free(sk);
trace_android_rvh_sk_free(sk);
if (slab != NULL) if (slab != NULL)
kmem_cache_free(slab, sk); kmem_cache_free(slab, sk);
else else