mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
xfrm: replace rwlock on xfrm_km_list with rcu
Cc: Steffen Klassert <steffen.klassert@secunet.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: "David S. Miller" <davem@davemloft.net> Signed-off-by: Cong Wang <amwang@redhat.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Change-Id: I207eef84335bf53a262f7836044d9c6d35223f95
This commit is contained in:
parent
efb0f84146
commit
dc08fd9591
1 changed files with 31 additions and 29 deletions
|
@ -1631,27 +1631,26 @@ static void xfrm_replay_timer_handler(unsigned long data)
|
|||
}
|
||||
|
||||
static LIST_HEAD(xfrm_km_list);
|
||||
static DEFINE_RWLOCK(xfrm_km_lock);
|
||||
|
||||
void km_policy_notify(struct xfrm_policy *xp, int dir, const struct km_event *c)
|
||||
{
|
||||
struct xfrm_mgr *km;
|
||||
|
||||
read_lock(&xfrm_km_lock);
|
||||
list_for_each_entry(km, &xfrm_km_list, list)
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(km, &xfrm_km_list, list)
|
||||
if (km->notify_policy)
|
||||
km->notify_policy(xp, dir, c);
|
||||
read_unlock(&xfrm_km_lock);
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
void km_state_notify(struct xfrm_state *x, const struct km_event *c)
|
||||
{
|
||||
struct xfrm_mgr *km;
|
||||
read_lock(&xfrm_km_lock);
|
||||
list_for_each_entry(km, &xfrm_km_list, list)
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(km, &xfrm_km_list, list)
|
||||
if (km->notify)
|
||||
km->notify(x, c);
|
||||
read_unlock(&xfrm_km_lock);
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(km_policy_notify);
|
||||
|
@ -1681,13 +1680,13 @@ int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol)
|
|||
int err = -EINVAL, acqret;
|
||||
struct xfrm_mgr *km;
|
||||
|
||||
read_lock(&xfrm_km_lock);
|
||||
list_for_each_entry(km, &xfrm_km_list, list) {
|
||||
acqret = km->acquire(x, t, pol, XFRM_POLICY_OUT);
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(km, &xfrm_km_list, list) {
|
||||
acqret = km->acquire(x, t, pol);
|
||||
if (!acqret)
|
||||
err = acqret;
|
||||
}
|
||||
read_unlock(&xfrm_km_lock);
|
||||
rcu_read_unlock();
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(km_query);
|
||||
|
@ -1697,14 +1696,14 @@ int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport)
|
|||
int err = -EINVAL;
|
||||
struct xfrm_mgr *km;
|
||||
|
||||
read_lock(&xfrm_km_lock);
|
||||
list_for_each_entry(km, &xfrm_km_list, list) {
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(km, &xfrm_km_list, list) {
|
||||
if (km->new_mapping)
|
||||
err = km->new_mapping(x, ipaddr, sport);
|
||||
if (!err)
|
||||
break;
|
||||
}
|
||||
read_unlock(&xfrm_km_lock);
|
||||
rcu_read_unlock();
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(km_new_mapping);
|
||||
|
@ -1733,15 +1732,15 @@ int km_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
|||
int ret;
|
||||
struct xfrm_mgr *km;
|
||||
|
||||
read_lock(&xfrm_km_lock);
|
||||
list_for_each_entry(km, &xfrm_km_list, list) {
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(km, &xfrm_km_list, list) {
|
||||
if (km->migrate) {
|
||||
ret = km->migrate(sel, dir, type, m, num_migrate, k);
|
||||
if (!ret)
|
||||
err = ret;
|
||||
}
|
||||
}
|
||||
read_unlock(&xfrm_km_lock);
|
||||
rcu_read_unlock();
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(km_migrate);
|
||||
|
@ -1753,15 +1752,15 @@ int km_report(struct net *net, u8 proto, struct xfrm_selector *sel, xfrm_address
|
|||
int ret;
|
||||
struct xfrm_mgr *km;
|
||||
|
||||
read_lock(&xfrm_km_lock);
|
||||
list_for_each_entry(km, &xfrm_km_list, list) {
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(km, &xfrm_km_list, list) {
|
||||
if (km->report) {
|
||||
ret = km->report(net, proto, sel, addr);
|
||||
if (!ret)
|
||||
err = ret;
|
||||
}
|
||||
}
|
||||
read_unlock(&xfrm_km_lock);
|
||||
rcu_read_unlock();
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(km_report);
|
||||
|
@ -1785,14 +1784,14 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
|
|||
goto out;
|
||||
|
||||
err = -EINVAL;
|
||||
read_lock(&xfrm_km_lock);
|
||||
list_for_each_entry(km, &xfrm_km_list, list) {
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(km, &xfrm_km_list, list) {
|
||||
pol = km->compile_policy(sk, optname, data,
|
||||
optlen, &err);
|
||||
if (err >= 0)
|
||||
break;
|
||||
}
|
||||
read_unlock(&xfrm_km_lock);
|
||||
rcu_read_unlock();
|
||||
|
||||
if (err >= 0) {
|
||||
xfrm_sk_policy_insert(sk, err, pol);
|
||||
|
@ -1806,20 +1805,23 @@ out:
|
|||
}
|
||||
EXPORT_SYMBOL(xfrm_user_policy);
|
||||
|
||||
static DEFINE_SPINLOCK(xfrm_km_lock);
|
||||
|
||||
int xfrm_register_km(struct xfrm_mgr *km)
|
||||
{
|
||||
write_lock_bh(&xfrm_km_lock);
|
||||
list_add_tail(&km->list, &xfrm_km_list);
|
||||
write_unlock_bh(&xfrm_km_lock);
|
||||
spin_lock_bh(&xfrm_km_lock);
|
||||
list_add_tail_rcu(&km->list, &xfrm_km_list);
|
||||
spin_unlock_bh(&xfrm_km_lock);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(xfrm_register_km);
|
||||
|
||||
int xfrm_unregister_km(struct xfrm_mgr *km)
|
||||
{
|
||||
write_lock_bh(&xfrm_km_lock);
|
||||
list_del(&km->list);
|
||||
write_unlock_bh(&xfrm_km_lock);
|
||||
spin_lock_bh(&xfrm_km_lock);
|
||||
list_del_rcu(&km->list);
|
||||
spin_unlock_bh(&xfrm_km_lock);
|
||||
synchronize_rcu();
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(xfrm_unregister_km);
|
||||
|
|
Loading…
Reference in a new issue