mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-14 15:54:15 +08:00
4a5da47d5c
With recent patch set that removed rtnl lock dependency from cls hardware
offload API rtnl lock is only taken when reading action data and can be
released after action-specific data is parsed into intermediate
representation. However, sample action psample group is passed by pointer
without obtaining reference to it first, which makes it possible to
concurrently overwrite the action and deallocate object pointed by
psample_group pointer after rtnl lock is released but before driver
finished using the pointer.
To prevent such race condition, obtain reference to psample group while it
is used by flow_action infra. Extend psample API with function
psample_group_take() that increments psample group reference counter.
Extend struct tc_action_ops with new get_psample_group() API. Implement the
API for action sample using psample_group_take() and already existing
psample_group_put() as a destructor. Use it in tc_setup_flow_action() to
take reference to psample group pointed to by entry->sample.psample_group
and release it in tc_cleanup_flow_action().
Disable bh when taking psample_groups_lock. The lock is now taken while
holding action tcf_lock that is used by data path and requires bh to be
disabled, so doing the same for psample_groups_lock is necessary to
preserve SOFTIRQ-irq-safety.
Fixes: 918190f50e
("net: sched: flower: don't take rtnl lock for cls hw offloads API")
Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
45 lines
918 B
C
45 lines
918 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __NET_TC_SAMPLE_H
|
|
#define __NET_TC_SAMPLE_H
|
|
|
|
#include <net/act_api.h>
|
|
#include <linux/tc_act/tc_sample.h>
|
|
#include <net/psample.h>
|
|
|
|
struct tcf_sample {
|
|
struct tc_action common;
|
|
u32 rate;
|
|
bool truncate;
|
|
u32 trunc_size;
|
|
struct psample_group __rcu *psample_group;
|
|
u32 psample_group_num;
|
|
struct list_head tcfm_list;
|
|
};
|
|
#define to_sample(a) ((struct tcf_sample *)a)
|
|
|
|
static inline bool is_tcf_sample(const struct tc_action *a)
|
|
{
|
|
#ifdef CONFIG_NET_CLS_ACT
|
|
return a->ops && a->ops->id == TCA_ID_SAMPLE;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
static inline __u32 tcf_sample_rate(const struct tc_action *a)
|
|
{
|
|
return to_sample(a)->rate;
|
|
}
|
|
|
|
static inline bool tcf_sample_truncate(const struct tc_action *a)
|
|
{
|
|
return to_sample(a)->truncate;
|
|
}
|
|
|
|
static inline int tcf_sample_trunc_size(const struct tc_action *a)
|
|
{
|
|
return to_sample(a)->trunc_size;
|
|
}
|
|
|
|
#endif /* __NET_TC_SAMPLE_H */
|