mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
xfrm: delay initialization of offload path till its actually requested
XFRM offload path is probed even if offload isn't needed at all. Let's
make sure that x->type_offload pointer stays NULL for such path to
reduce ambiguity.
Fixes: 9d389d7f84
("xfrm: Add a xfrm type offload.")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
This commit is contained in:
parent
e3aa43a50a
commit
585b64f5a6
4 changed files with 33 additions and 25 deletions
|
@ -464,6 +464,15 @@ struct xfrm_type_offload {
|
||||||
|
|
||||||
int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
|
int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
|
||||||
void xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
|
void xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
|
||||||
|
void xfrm_set_type_offload(struct xfrm_state *x);
|
||||||
|
static inline void xfrm_unset_type_offload(struct xfrm_state *x)
|
||||||
|
{
|
||||||
|
if (!x->type_offload)
|
||||||
|
return;
|
||||||
|
|
||||||
|
module_put(x->type_offload->owner);
|
||||||
|
x->type_offload = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct xfrm_mode_cbs - XFRM mode callbacks
|
* struct xfrm_mode_cbs - XFRM mode callbacks
|
||||||
|
@ -1760,7 +1769,7 @@ void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si);
|
||||||
u32 xfrm_replay_seqhi(struct xfrm_state *x, __be32 net_seq);
|
u32 xfrm_replay_seqhi(struct xfrm_state *x, __be32 net_seq);
|
||||||
int xfrm_init_replay(struct xfrm_state *x, struct netlink_ext_ack *extack);
|
int xfrm_init_replay(struct xfrm_state *x, struct netlink_ext_ack *extack);
|
||||||
u32 xfrm_state_mtu(struct xfrm_state *x, int mtu);
|
u32 xfrm_state_mtu(struct xfrm_state *x, int mtu);
|
||||||
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload,
|
int __xfrm_init_state(struct xfrm_state *x, bool init_replay,
|
||||||
struct netlink_ext_ack *extack);
|
struct netlink_ext_ack *extack);
|
||||||
int xfrm_init_state(struct xfrm_state *x);
|
int xfrm_init_state(struct xfrm_state *x);
|
||||||
int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type);
|
int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type);
|
||||||
|
|
|
@ -244,11 +244,6 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
|
||||||
xfrm_address_t *daddr;
|
xfrm_address_t *daddr;
|
||||||
bool is_packet_offload;
|
bool is_packet_offload;
|
||||||
|
|
||||||
if (!x->type_offload) {
|
|
||||||
NL_SET_ERR_MSG(extack, "Type doesn't support offload");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xuo->flags &
|
if (xuo->flags &
|
||||||
~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND | XFRM_OFFLOAD_PACKET)) {
|
~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND | XFRM_OFFLOAD_PACKET)) {
|
||||||
NL_SET_ERR_MSG(extack, "Unrecognized flags in offload request");
|
NL_SET_ERR_MSG(extack, "Unrecognized flags in offload request");
|
||||||
|
@ -310,6 +305,13 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfrm_set_type_offload(x);
|
||||||
|
if (!x->type_offload) {
|
||||||
|
NL_SET_ERR_MSG(extack, "Type doesn't support offload");
|
||||||
|
dev_put(dev);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
xso->dev = dev;
|
xso->dev = dev;
|
||||||
netdev_tracker_alloc(dev, &xso->dev_tracker, GFP_ATOMIC);
|
netdev_tracker_alloc(dev, &xso->dev_tracker, GFP_ATOMIC);
|
||||||
xso->real_dev = dev;
|
xso->real_dev = dev;
|
||||||
|
@ -332,6 +334,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
|
||||||
netdev_put(dev, &xso->dev_tracker);
|
netdev_put(dev, &xso->dev_tracker);
|
||||||
xso->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
|
xso->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
|
||||||
|
|
||||||
|
xfrm_unset_type_offload(x);
|
||||||
/* User explicitly requested packet offload mode and configured
|
/* User explicitly requested packet offload mode and configured
|
||||||
* policy in addition to the XFRM state. So be civil to users,
|
* policy in addition to the XFRM state. So be civil to users,
|
||||||
* and return an error instead of taking fallback path.
|
* and return an error instead of taking fallback path.
|
||||||
|
|
|
@ -424,18 +424,18 @@ void xfrm_unregister_type_offload(const struct xfrm_type_offload *type,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(xfrm_unregister_type_offload);
|
EXPORT_SYMBOL(xfrm_unregister_type_offload);
|
||||||
|
|
||||||
static const struct xfrm_type_offload *
|
void xfrm_set_type_offload(struct xfrm_state *x)
|
||||||
xfrm_get_type_offload(u8 proto, unsigned short family, bool try_load)
|
|
||||||
{
|
{
|
||||||
const struct xfrm_type_offload *type = NULL;
|
const struct xfrm_type_offload *type = NULL;
|
||||||
struct xfrm_state_afinfo *afinfo;
|
struct xfrm_state_afinfo *afinfo;
|
||||||
|
bool try_load = true;
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
afinfo = xfrm_state_get_afinfo(family);
|
afinfo = xfrm_state_get_afinfo(x->props.family);
|
||||||
if (unlikely(afinfo == NULL))
|
if (unlikely(afinfo == NULL))
|
||||||
return NULL;
|
goto out;
|
||||||
|
|
||||||
switch (proto) {
|
switch (x->id.proto) {
|
||||||
case IPPROTO_ESP:
|
case IPPROTO_ESP:
|
||||||
type = afinfo->type_offload_esp;
|
type = afinfo->type_offload_esp;
|
||||||
break;
|
break;
|
||||||
|
@ -449,18 +449,16 @@ retry:
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
|
|
||||||
if (!type && try_load) {
|
if (!type && try_load) {
|
||||||
request_module("xfrm-offload-%d-%d", family, proto);
|
request_module("xfrm-offload-%d-%d", x->props.family,
|
||||||
|
x->id.proto);
|
||||||
try_load = false;
|
try_load = false;
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
|
||||||
return type;
|
out:
|
||||||
}
|
x->type_offload = type;
|
||||||
|
|
||||||
static void xfrm_put_type_offload(const struct xfrm_type_offload *type)
|
|
||||||
{
|
|
||||||
module_put(type->owner);
|
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(xfrm_set_type_offload);
|
||||||
|
|
||||||
static const struct xfrm_mode xfrm4_mode_map[XFRM_MODE_MAX] = {
|
static const struct xfrm_mode xfrm4_mode_map[XFRM_MODE_MAX] = {
|
||||||
[XFRM_MODE_BEET] = {
|
[XFRM_MODE_BEET] = {
|
||||||
|
@ -609,8 +607,6 @@ static void ___xfrm_state_destroy(struct xfrm_state *x)
|
||||||
kfree(x->coaddr);
|
kfree(x->coaddr);
|
||||||
kfree(x->replay_esn);
|
kfree(x->replay_esn);
|
||||||
kfree(x->preplay_esn);
|
kfree(x->preplay_esn);
|
||||||
if (x->type_offload)
|
|
||||||
xfrm_put_type_offload(x->type_offload);
|
|
||||||
if (x->type) {
|
if (x->type) {
|
||||||
x->type->destructor(x);
|
x->type->destructor(x);
|
||||||
xfrm_put_type(x->type);
|
xfrm_put_type(x->type);
|
||||||
|
@ -784,6 +780,8 @@ void xfrm_dev_state_free(struct xfrm_state *x)
|
||||||
struct xfrm_dev_offload *xso = &x->xso;
|
struct xfrm_dev_offload *xso = &x->xso;
|
||||||
struct net_device *dev = READ_ONCE(xso->dev);
|
struct net_device *dev = READ_ONCE(xso->dev);
|
||||||
|
|
||||||
|
xfrm_unset_type_offload(x);
|
||||||
|
|
||||||
if (dev && dev->xfrmdev_ops) {
|
if (dev && dev->xfrmdev_ops) {
|
||||||
spin_lock_bh(&xfrm_state_dev_gc_lock);
|
spin_lock_bh(&xfrm_state_dev_gc_lock);
|
||||||
if (!hlist_unhashed(&x->dev_gclist))
|
if (!hlist_unhashed(&x->dev_gclist))
|
||||||
|
@ -3122,7 +3120,7 @@ u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(xfrm_state_mtu);
|
EXPORT_SYMBOL_GPL(xfrm_state_mtu);
|
||||||
|
|
||||||
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload,
|
int __xfrm_init_state(struct xfrm_state *x, bool init_replay,
|
||||||
struct netlink_ext_ack *extack)
|
struct netlink_ext_ack *extack)
|
||||||
{
|
{
|
||||||
const struct xfrm_mode *inner_mode;
|
const struct xfrm_mode *inner_mode;
|
||||||
|
@ -3178,8 +3176,6 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
x->type_offload = xfrm_get_type_offload(x->id.proto, family, offload);
|
|
||||||
|
|
||||||
err = x->type->init_state(x, extack);
|
err = x->type->init_state(x, extack);
|
||||||
if (err)
|
if (err)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -3229,7 +3225,7 @@ int xfrm_init_state(struct xfrm_state *x)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = __xfrm_init_state(x, true, false, NULL);
|
err = __xfrm_init_state(x, true, NULL);
|
||||||
if (!err)
|
if (!err)
|
||||||
x->km.state = XFRM_STATE_VALID;
|
x->km.state = XFRM_STATE_VALID;
|
||||||
|
|
||||||
|
|
|
@ -919,7 +919,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV], extack);
|
err = __xfrm_init_state(x, false, extack);
|
||||||
if (err)
|
if (err)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue